all repos — mgba @ 599537a41b816bce444e47717ec580e9ce3e09be

mGBA Game Boy Advance Emulator

src/gba/hle-bios.s (view raw)

  1#define nop andeq r0, r0
  2
  3.text
  4
  5b resetBase
  6b undefBase
  7b swiBase
  8b pabtBase
  9b dabtBase
 10nop
 11b irqBase
 12b fiqBase
 13
 14resetBase:
 15mov pc, #0x8000000
 16
 17swiBase:
 18cmp    sp, #0
 19moveq  sp, #0x04000000
 20subeq  sp, #0x20
 21stmfd  sp!, {r4-r5, lr}
 22ldrb   r4, [lr, #-2]
 23mov    r5, #swiTable
 24ldr    r4, [r5, r4, lsl #2]
 25cmp    r4, #0
 26mov    lr, pc
 27bxne   r4
 28ldmfd  sp!, {r4-r5, lr}
 29movs   pc, lr
 30
 31swiTable:
 32.word SoftReset
 33.word RegisterRamReset
 34.word Halt
 35.word Stop
 36.word IntrWait
 37.word VBlankIntrWait
 38.word Div
 39.word DivArm
 40.word Sqrt
 41.word ArcTan
 42.word ArcTan2
 43.word CpuSet
 44.word CpuFastSet
 45# ... The rest of this table isn't needed if the rest aren't implemented
 46
 47irqBase:
 48stmfd  sp!, {r0-r3, r12, lr}
 49mov    r0, #0x04000000
 50add    lr, pc, #0
 51ldr    pc, [r0, #-4]
 52ldmfd  sp!, {r0-r3, r12, lr}
 53subs   pc, lr, #4
 54
 55VBlankIntrWait:
 56mov    r0, #1
 57mov    r1, #1
 58IntrWait:
 59stmfd  sp!, {lr}
 60mrs    r5, spsr
 61msr    cpsr, #0x1F
 62# Pull current interrupts enabled and add the ones we need
 63mov    r4, #0x04000000
 64# See if we want to return immediately
 65cmp    r0, #0
 66mov    r0, #0
 67mov    r2, #1
 68beq    1f
 69# Halt
 700:
 71strb   r0, [r4, #0x301]
 721:
 73# Check which interrupts were acknowledged
 74strb   r0, [r4, #0x208]
 75ldrh   r3, [r4, #-8]
 76ands   r3, r1
 77eorne  r3, r1
 78strneh r3, [r4, #-8]
 79strb   r2, [r4, #0x208]
 80beq    0b
 81msr    cpsr, #0x93
 82msr    spsr, r5
 83ldmfd  sp!, {pc}
 84
 85CpuSet:
 86msr    cpsr, #0x1F
 87mov    r3, r2, lsl #12
 88mov    r3, r3, lsr #12
 89tst    r2, #0x01000000
 90beq    0f
 91# Fill
 92tst    r2, #0x04000000
 93beq    1f
 94# Word
 95ldmia  r0!, {r2}
 962:
 97stmia  r1!, {r2}
 98subs   r3, #1
 99bne    2b
100b      3f
101# Halfword
1021:
103bic    r0, #1
104bic    r1, #1
105ldrh   r2, [r0]
1062:
107strh   r2, [r1], #2
108subs   r3, #1
109bne    2b
110b      3f
111# Copy
1120:
113tst    r2, #0x04000000
114beq    1f
115# Word
1162:
117ldmia  r0!, {r2}
118stmia  r1!, {r2}
119subs   r3, #1
120bne    2b
121b      3f
122# Halfword
1231:
124bic    r0, #1
125bic    r1, #1
1262:
127ldrh   r2, [r0], #2
128strh   r2, [r1], #2
129subs   r3, #1
130bne    2b
1313:
132msr    cpsr, #0x93
133bx     lr
134
135CpuFastSet:
136msr    cpsr, #0x1F
137stmfd  sp!, {r4-r10}
138tst    r2, #0x01000000
139mov    r3, r2, lsl #12
140mov    r2, r3, lsr #12
141beq    0f
142# Fill
143ldmia  r0!, {r4}
144mov    r5, r4
145mov    r3, r4
146mov    r6, r4
147mov    r7, r4
148mov    r8, r4
149mov    r9, r4
150mov    r10, r4
1511:
152stmia  r1!, {r3-r10}
153subs   r2, #8
154bgt    1b
155b      2f
156# Copy
1570:
158ldmia  r0!, {r3-r10}
159stmia  r1!, {r3-r10}
160subs   r2, #8
161bgt    0b
1622:
163ldmfd  sp!, {r4-r10}
164msr    cpsr, #0x93
165bx     lr