I've decided to add this message as a separate post, since it's not exactly related to gpS2 because it belongs to another one of my emulator development projects, but is related because this same macros were taken from the dynarec MIPS emulator core of gpS2. :/
, where did you get these macro instructions from? Did you come up with them on your own?
I noticed something weird when I used them in my port of Picodrive v1.35b (The recently released v1.85 seems to have a broken PSP port, and I wanted to work with something that is known to work on the host system): The register(s) used don't seem to be getting preserved and restored properly.
The original macros were a bit longer and required more registers, but I'm using $at (which isn't used by Picodrive's MIPS assembly stubs) and I shortened the code a little.
I don't know whether I'm actually hitting the problem, but I've simply changed the macro to reserve space of the stack the usual way, instead of addressing the stack directly:
If I saved the contents of $s0 into the stack like it originally did (with something like "sd $s0, -16($sp)"), it seems like the contents of $s0 gets lost and the emulator crashes in the M68000 emulator core.
.macro ins dest,src,pos,size
addiu $sp, $sp, -16
sd $s0, ($sp)
li $at, ~(((1<<\size)-1)<<\pos)
and \dest, $at
sll $s0, \src, \pos
li $at, ((1<<\size)-1)<<\pos
and $s0, $at
or \dest, $s0
ld $s0, ($sp)
addiu $sp, $sp, 16
.macro ext dest,src,pos,size
srl \dest, \src, \pos
li $at, ((1 << \size) - 1)
and \dest, $at
I don't know how good you are with MIPS assembly coding, but I'll be grateful if somebody can tell me whether the original expression of "sd $s0, -16($sp)" would have actually worked properly.