all repos — mgba @ f5f1cbf037e94c665a698eaa21be7311a75f3f83

mGBA Game Boy Advance Emulator

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

  1# Copyright (c) 2013-2014 Jeffrey Pfau
  2#
  3# This Source Code Form is subject to the terms of the Mozilla Public
  4# License, v. 2.0. If a copy of the MPL was not distributed with this
  5# file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6#define nop andeq r0, r0
  7
  8.text
  9
 10b resetBase
 11b undefBase
 12b swiBase
 13b pabtBase
 14b dabtBase
 15nop
 16b irqBase
 17b fiqBase
 18
 19resetBase:
 20mov r0, #0x8000000
 21ldrb r1, [r0, #3]
 22cmp r1, #0xEA
 23ldrne r0, =0x20000C0
 24bx r0
 25.word 0
 26.word 0xE129F000
 27
 28swiBase:
 29cmp    sp, #0
 30moveq  sp, #0x04000000
 31subeq  sp, #0x20
 32stmfd  sp!, {r11-r12, lr}
 33ldrb   r11, [lr, #-2]
 34mov    r12, #swiTable
 35ldr    r11, [r12, r11, lsl #2]
 36cmp    r11, #0
 37mrs    r12, spsr
 38stmfd  sp!, {r12}
 39and    r12, #0x80
 40orr    r12, #0x1F
 41msr    cpsr, r12
 42stmfd  sp!, {lr}
 43mov    lr, pc
 44bxne   r11
 45ldmfd  sp!, {lr}
 46msr    cpsr, #0x93
 47ldmfd  sp!, {r12}
 48msr    spsr, r12
 49ldmfd  sp!, {r11-r12, lr}
 50movs   pc, lr
 51.word 0
 52.word 0xE3A02004
 53
 54swiTable:
 55.word SoftReset
 56.word RegisterRamReset
 57.word Halt
 58.word Stop
 59.word IntrWait
 60.word VBlankIntrWait
 61.word Div
 62.word DivArm
 63.word Sqrt
 64.word ArcTan
 65.word ArcTan2
 66.word CpuSet
 67.word CpuFastSet
 68@ ... The rest of this table isn't needed if the rest aren't implemented
 69
 70irqBase:
 71stmfd  sp!, {r0-r3, r12, lr}
 72mov    r0, #0x04000000
 73add    lr, pc, #0
 74ldr    pc, [r0, #-4]
 75ldmfd  sp!, {r0-r3, r12, lr}
 76subs   pc, lr, #4
 77.word 0
 78.word 0xE55EC002
 79
 80VBlankIntrWait:
 81mov    r0, #1
 82mov    r1, #1
 83IntrWait:
 84stmfd  sp!, {r2-r3, lr}
 85mov    r12, #0x04000000
 86@ See if we want to return immediately
 87cmp    r0, #0
 88mov    r0, #0
 89mov    r2, #1
 90beq    1f
 91ldrh   r3, [r12, #-8]
 92bic    r3, r1
 93strh   r3, [r12, #-8]
 94@ Halt
 950:
 96strb   r0, [r12, #0x301]
 971:
 98@ Check which interrupts were acknowledged
 99strb   r0, [r12, #0x208]
100ldrh   r3, [r12, #-8]
101ands   r3, r1
102eorne  r3, r1
103strneh r3, [r12, #-8]
104strb   r2, [r12, #0x208]
105beq    0b
106ldmfd  sp!, {r2-r3, pc}
107
108CpuSet:
109stmfd  sp!, {r4, r5, lr}
110mov    r4, r2, lsl #12
111mov    r12, r0
112mov    r5, r1
113tst    r2, #0x01000000
114beq    0f
115@ Fill
116tst    r2, #0x04000000
117beq    1f
118@ Word
119add    r4, r5, r4, lsr #10
120ldmia  r12!, {r3}
1212:
122cmp    r5, r4
123stmltia  r5!, {r3}
124blt    2b
125b      3f
126@ Halfword
1271:
128bic    r12, #1
129bic    r5, #1
130add    r4, r5, r4, lsr #11
131ldrh   r3, [r12]
1322:
133cmp    r5, r4
134strlth r3, [r5], #2
135blt    2b
136b      3f
137@ Copy
1380:
139tst    r2, #0x04000000
140beq    1f
141@ Word
142add    r4, r5, r4, lsr #10
1432:
144cmp    r5, r4
145ldmltia r12!, {r3}
146stmltia r5!, {r3}
147blt    2b
148b      3f
149@ Halfword
1501:
151add    r4, r5, r4, lsr #11
1522:
153cmp    r5, r4
154ldrlth r3, [r12], #2
155strlth r3, [r5], #2
156blt    2b
1573:
158mov    r3, #0x170  @ Match official BIOS's clobbered r3
159ldmfd  sp!, {r4, r5, pc}
160
161CpuFastSet:
162stmfd  sp!, {r4-r10, lr}
163tst    r2, #0x01000000
164mov    r3, r2, lsl #12
165add    r2, r1, r3, lsr #10
166beq    0f
167@ Fill
168ldr    r3, [r0]
169mov    r4, r3
170mov    r5, r3
171mov    r6, r3
172mov    r7, r3
173mov    r8, r3
174mov    r9, r3
175mov    r10, r3
1761:
177cmp    r1, r2
178stmltia r1!, {r3-r10}
179blt    1b
180b      2f
181@ Copy
1820:
183cmp    r1, r2
184ldmltia r0!, {r3-r10}
185stmltia r1!, {r3-r10}
186blt    0b
1872:
188ldmfd  sp!, {r4-r10, pc}
189
190undefBase:
191subs   pc, lr, #4
192.word 0
193.word 0x03A0E004
194
195.ltorg