From fb041f75e5a78111e6fad4cc6ccd3b2cb38c5dd3 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Tue, 2 Jun 2020 01:50:02 +0100 Subject: [PATCH] DSPSpy: save and restore $sr properly --- Source/DSPSpy/gba.txt | 38 ++++++++++++++++---------------- Source/DSPSpy/tests/dsp_base.inc | 22 +++++++----------- Source/DSPSpy/tests/dsp_test.ds | 3 --- 3 files changed, 27 insertions(+), 36 deletions(-) diff --git a/Source/DSPSpy/gba.txt b/Source/DSPSpy/gba.txt index d4f1a9c333..48c1a13ab6 100644 --- a/Source/DSPSpy/gba.txt +++ b/Source/DSPSpy/gba.txt @@ -33,7 +33,7 @@ m0 clr15 ;step 1: context setup -call send_back_40 +call send_back call 0x807e ; loop until DSP->CPU mailbox is empty si @DMBH, #0xdcd1 @@ -342,44 +342,44 @@ call send_back call send_back set40 -call send_back_40 +call send_back lri $AR2, #0x0015 -call send_back_40 +call send_back lr $AC0.M, @0x0006 -call send_back_40 +call send_back lr $AX0.H, @0x165b -call send_back_40 +call send_back call 0x88e5 -call send_back_40 +call send_back asr $ACC0, #-3 -call send_back_40 +call send_back lsl $ACC0, #3 -call send_back_40 +call send_back srri @$AR2, $AC0.M -call send_back_40 +call send_back srri @$AR2, $AC0.L -call send_back_40 +call send_back lri $AR2, #0x0016 -call send_back_40 +call send_back lr $AC0.M, @0x1723 -call send_back_40 +call send_back asr $ACC0, #-12 -call send_back_40 +call send_back lr $AX0.H, @0x166b -call send_back_40 +call send_back call 0x88e5 -call send_back_40 +call send_back tst $ACC0 -call send_back_40 +call send_back jge Unk_012e -call send_back_40 +call send_back clr $ACC0 -call send_back_40 +call send_back Unk_012e: asr $ACC0, #-3 -call send_back_40 +call send_back set16 ;step 4 call send_back diff --git a/Source/DSPSpy/tests/dsp_base.inc b/Source/DSPSpy/tests/dsp_base.inc index 7fac883311..c890390314 100644 --- a/Source/DSPSpy/tests/dsp_base.inc +++ b/Source/DSPSpy/tests/dsp_base.inc @@ -169,10 +169,9 @@ irq: ; DMA:s the current state of the registers back to the PowerPC. To do this, ; it must write the contents of all regs to DRAM. -; Unfortunately, this loop uses ar0 so it's best to use AR1 and friends for testing -; when messing with indexing. send_back: - ; make state safe. + ; first, store $sr so we can modify it + sr @(REGS_BASE + 19), $sr set16 ; store registers to reg table sr @REGS_BASE, $ar0 @@ -195,7 +194,8 @@ send_back: srri @$ar0, $ac0.h srri @$ar0, $ac1.h srri @$ar0, $cr - srri @$ar0, $sr + ; skip $sr since we already stored and modified it + iar $ar0 srri @$ar0, $prod.l srri @$ar0, $prod.m1 srri @$ar0, $prod.h @@ -257,7 +257,8 @@ dma_copy: lrri $ac0.h, @$ar0 lrri $ac1.h, @$ar0 lrri $cr, @$ar0 - lrri $sr, @$ar0 + ; leave $sr for later + iar $ar0 lrri $prod.l, @$ar0 lrri $prod.m1, @$ar0 lrri $prod.h, @$ar0 @@ -270,17 +271,10 @@ dma_copy: lrri $ac1.l, @$ar0 lrri $ac0.m, @$ar0 lrri $ac1.m, @$ar0 - lr $ar0, @REGS_BASE + lr $ar0, @REGS_BASE + lr $sr, @(REGS_BASE+19) ret ; from send_back -; If you are in set40 mode, use this instead of send_back if you want to stay -; in set40 mode. -send_back_40: - set16 - call send_back - set40 - ret - ; Obviously this must be included directly before your test code start_of_test: diff --git a/Source/DSPSpy/tests/dsp_test.ds b/Source/DSPSpy/tests/dsp_test.ds index 818f681567..3550dd205c 100644 --- a/Source/DSPSpy/tests/dsp_test.ds +++ b/Source/DSPSpy/tests/dsp_test.ds @@ -6,9 +6,6 @@ include "dsp_base.inc" ; We can call send_back at any time to send data back to the PowerPC. -; Calling set40 here seemed to crash the dsp tester in strange ways -; until I added set16 in send_back. Seems clear that it affects something important. - lri $AC0.M, #0x1000 call send_back