# SPDX-License-Identifier: MIT # Contains expected values from the timing table of endrift's mGBA test suite (MIT License, # Copyright (c) 2015 Jeffrey Pfau; reference/src/suite/LICENSE). """Access timing, wait states and the prefetch buffer, against the mGBA suite's timing table (suite src/timing.c, MIT, Jeffrey Pfau; TEST ROM): the same code frame, run in ROM under the eight WAITCNT settings the suite uses. Each expectation is the table's value plus the "Calibration" row (the table subtracts it).""" from __future__ import annotations import pytest from programs import run_timed, timed_arm, timed_thumb MODES = (0x0000, 0x4000, 0x0004, 0x4004, 0x0010, 0x4010, 0x0014, 0x4014) CALIBRATION_ARM = (7, 4, 6, 4, 6, 2, 5, 2) CALIBRATION_THUMB = (4, 1, 3, 1, 4, 0, 3, 0) @pytest.mark.parametrize("index", range(8)) def test_calibration_arm(index): assert run_timed(timed_arm([]), MODES[index]) == CALIBRATION_ARM[index] @pytest.mark.parametrize("index", range(8)) def test_calibration_thumb(index): assert run_timed(timed_thumb([]), MODES[index], thumb=True) == CALIBRATION_THUMB[index] ROWS = { # name: (ARM code, ARM row, Thumb code, Thumb row) "nop": ([0xE1A00000], (6, 6, 6, 6, 4, 4, 4, 4), [0x46C0], (3, 3, 3, 3, 2, 2, 2, 2)), "ldr r2, [sp]": ( [0xE59D2000], (10, 6, 9, 6, 9, 4, 8, 4), [0x9A00], (7, 3, 6, 3, 7, 3, 6, 3), ), "ldr r2, [#0x08000000]": ( [0xE5932000], (17, 17, 15, 15, 15, 15, 13, 13), [0x681A], (14, 14, 12, 12, 13, 13, 11, 11), ), } @pytest.mark.parametrize("name", sorted(ROWS)) @pytest.mark.parametrize("index", range(8)) def test_rows(name, index): arm, arm_row, thumb, thumb_row = ROWS[name] assert run_timed(timed_arm(arm), MODES[index]) == arm_row[index] + CALIBRATION_ARM[index] got = run_timed(timed_thumb(thumb), MODES[index], thumb=True) assert got == thumb_row[index] + CALIBRATION_THUMB[index] @pytest.mark.parametrize("index", range(8)) def test_ldmia_six_registers(index): # "ldmia sp, {r2-r7}" (ARM only in the table): 15, 8, 14, 8, 14, 8, 13, 8. row = (15, 8, 14, 8, 14, 8, 13, 8) assert run_timed(timed_arm([0xE89D00FC]), MODES[index]) == row[index] + CALIBRATION_ARM[index]