88: crt0.s removed redundant lines, added comments r=Lokathor a=felixjones

The flags of `cpsr_cf` are left untouched, so `cpsr_c` is used instead.

Line 102 was redundant:
```asm
bic r2, r2, #0x1F
orr r2, r2, #0x1F
```
Now it explicitly switches from incoming IRQ mode to system mode.

The same type of explicit switch is done for system mode to IRQ mode (only clearing bits necessary), however the IRQ mode bits are or'd also just-in-case the user has modified `cpsr_c` in their IRQ handler.

The IRQ disable bit is also set, again, just in-case the user changed it.

Hopefully I've managed to communicate the behaviour in the ASM comments.

Co-authored-by: Felix Jones <felix@felixjones.co.uk>
This commit is contained in:
bors[bot] 2019-09-19 02:34:12 +00:00 committed by GitHub
commit 35e9857dcc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

23
crt0.s
View file

@ -51,12 +51,12 @@ __start:
@ set IRQ stack pointer
mov r0, #0x12
msr CPSR_cf, r0
msr CPSR_c, r0
ldr sp, =0x3007fa0
@ set user stack pointer
mov r0, #0x1f
msr CPSR_cf, r0
msr CPSR_c, r0
ldr sp, =0x3007f00
@ copy .data section to IWRAM
@ -89,19 +89,19 @@ MainIrqHandler:
stmdb sp!, {r0-r2,lr}
@ Disable all interrupts by writing to IME
mov r0, #0
strh r0, [r2, #8]
@ r2 (0x4000200) can be used as we only care about bit 0 being unset
strh r2, [r2, #8]
@ Acknowledge all received interrupts that were enabled in IE
ldr r3, [r2, #0]
and r0, r3, r3, lsr #16
strh r0, [r2, #2]
@ Switch to system mode
@ Switch from IRQ mode to system mode
@ cpsr_c = 0b000_10010u8 | 0b000_01101u8
mrs r2, cpsr
bic r2, r2, #0x1F
orr r2, r2, #0x1F
msr cpsr_cf, r2
orr r2, r2, #0xD
msr cpsr_c, r2
@ Jump to user specified IRQ handler
ldr r2, =__IRQ_HANDLER
@ -112,11 +112,12 @@ MainIrqHandler:
.Lreturn:
ldmia sp!, {lr}
@ Switch to IRQ mode
@ Switch from ??? mode to IRQ mode, disable IRQ
@ cpsr_c = ( !0b000_01101u8 & cpsr_c ) | 0b100_10010u8
mrs r2, cpsr
bic r2, r2, #0x1F
bic r2, r2, #0xD
orr r2, r2, #0x92
msr cpsr_cf, r2
msr cpsr_c, r2
@ Restore IRQ stack pointer and IME
ldmia sp!, {r0-r2,lr}