Skip to content

Commit

Permalink
Implemented support for MSR imm. Fixes Apotris
Browse files Browse the repository at this point in the history
  • Loading branch information
Gericom committed Oct 6, 2024
1 parent 3b5f49a commit 8b2c005
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
1 change: 0 additions & 1 deletion code/core/arm9/gbarunner9.ld
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ SECTIONS
KEEP (VMUndefinedMsr.o(.itcm))
KEEP (JitArmUndefinedBx.o(.itcm))
KEEP (JitArmUndefinedLdrPcImm.o(.itcm))
KEEP (EmuIrqs.o(.itcm))
. = 0x3000;
KEEP (ThumbGetRn.o(.itcm))
*(.itcm)
Expand Down
8 changes: 8 additions & 0 deletions code/core/arm9/source/JitPatcher/JitArm.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ bool jit_processArmInstruction(u32* ptr)
// MSR reg
*ptr = 0x1800090 | (instruction & 0xF04F000F) | ((instruction & 0x02000000) >> 5);
}
else if ((instruction & 0x0FB0F000) == 0x0320F000)
{
// MSR imm
*ptr = 0x1900090
| (instruction & 0xF04F000F)
| ((instruction & 0x00000FF0) << 4)
| ((instruction & 0x02000000) >> 5);
}
else if ((instruction & 0x0FFFFFF0) == 0x012FFF10)
{
// BX
Expand Down
4 changes: 2 additions & 2 deletions code/core/arm9/source/VirtualMachine/VMUndefinedArmTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

extern const void* vm_armUndefinedMsrRegSpsrRmTable[16];
extern const void* vm_armUndefinedMsrRegCpsrRmTable[16];
extern const void* vm_armUndefinedMsrImmTable[16];
extern const void* vm_armUndefinedMrsSpsrRmTable[16];
extern const void* vm_armUndefinedMrsCpsrRmTable[16];
extern const void* jit_armUndefinedBxRmTable[16];
Expand Down Expand Up @@ -38,8 +39,7 @@ void vm_initializeUndefinedArmTable()
// MSR
if (h == 1)
{
// setTableEntry(index, vm_armUndefinedMsrImm\f)
setTableEntry(index, nullptr);
setTableEntry(index, vm_armUndefinedMsrImmTable);
}
else
{
Expand Down
28 changes: 27 additions & 1 deletion code/core/arm9/source/VirtualMachine/VMUndefinedMsr.s
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@
.endif
.endm

arm_func vm_armUndefinedMsrImm
and r8, lr, #0xF
and r10, lr, #0xF00
orr r8, r8, r10, lsr #4
and r10, lr, #0xF000
mov r10, r10, lsr #11
mov r8, r8, ror r10
tst lr, #0x400000
beq vm_updateCpsr
b vm_updateSpsr

vm_updateCpsrHiReg:
ldr r8, [sp, #-4]
vm_updateCpsr:
Expand Down Expand Up @@ -60,7 +71,7 @@ vm_finishCpsrWithFlags:
orr r10, r10, r8
msr spsr, r10
movs pc, lr

vm_finishCpsrOnlyControl:
adr lr, vm_cpsrFinish
b emu_updateIrqs
Expand Down Expand Up @@ -89,6 +100,15 @@ generate vm_armUndefinedMsrRegCpsrRm, 16

generate vm_armUndefinedMsrRegSpsrRm, 16

arm_func vm_armUndefinedMsrImmSpsr
and r8, lr, #0xF
and r10, lr, #0xF00
orr r8, r8, r10, lsr #4
and r10, lr, #0xF000
mov r10, r10, lsr #11
mov r8, r8, ror r10
b vm_updateSpsr

vm_updateSpsrHiReg:
ldr r8, [r11]
vm_updateSpsr:
Expand Down Expand Up @@ -149,3 +169,9 @@ vm_armUndefinedMsrRegSpsrRmTable:
.word vm_armUndefinedMsrRegSpsrR13
.word vm_armUndefinedMsrRegSpsrR14
.word vm_armUndefinedMsrRegSpsrR15

.global vm_armUndefinedMsrImmTable
vm_armUndefinedMsrImmTable:
.rept 16
.word vm_armUndefinedMsrImm
.endr

0 comments on commit 8b2c005

Please sign in to comment.