all repos — mgba @ f6a7fedb2813d070a07cd6da65e8ddd666cd41d1

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 pc, #0x8000000
 21
 22swiBase:
 23cmp    sp, #0
 24moveq  sp, #0x04000000
 25subeq  sp, #0x20
 26stmfd  sp!, {r11-r12, lr}
 27ldrb   r11, [lr, #-2]
 28mov    r12, #swiTable
 29ldr    r11, [r12, r11, lsl #2]
 30cmp    r11, #0
 31mrs    r12, spsr
 32stmfd  sp!, {r12}
 33and    r12, #0x80
 34orr    r12, #0x1F
 35msr    cpsr, r12
 36stmfd  sp!, {lr}
 37mov    lr, pc
 38bxne   r11
 39ldmfd  sp!, {lr}
 40msr    cpsr, #0x93
 41ldmfd  sp!, {r12}
 42msr    spsr, r12
 43ldmfd  sp!, {r11-r12, lr}
 44movs   pc, lr
 45
 46swiTable:
 47.word SoftReset
 48.word RegisterRamReset
 49.word Halt
 50.word Stop
 51.word IntrWait
 52.word VBlankIntrWait
 53.word Div
 54.word DivArm
 55.word Sqrt
 56.word ArcTan
 57.word ArcTan2
 58.word CpuSet
 59.word CpuFastSet
 60# ... The rest of this table isn't needed if the rest aren't implemented
 61
 62irqBase:
 63stmfd  sp!, {r0-r3, r12, lr}
 64mov    r0, #0x04000000
 65add    lr, pc, #0
 66ldr    pc, [r0, #-4]
 67ldmfd  sp!, {r0-r3, r12, lr}
 68subs   pc, lr, #4
 69
 70VBlankIntrWait:
 71mov    r0, #1
 72mov    r1, #1
 73IntrWait:
 74stmfd  sp!, {r2-r3, lr}
 75mov    r12, #0x04000000
 76# See if we want to return immediately
 77cmp    r0, #0
 78mov    r0, #0
 79mov    r2, #1
 80beq    1f
 81ldrh   r3, [r12, #-8]
 82bic    r3, r1
 83strh   r3, [r12, #-8]
 84# Halt
 850:
 86strb   r0, [r12, #0x301]
 871:
 88# Check which interrupts were acknowledged
 89strb   r0, [r12, #0x208]
 90ldrh   r3, [r12, #-8]
 91ands   r3, r1
 92eorne  r3, r1
 93strneh r3, [r12, #-8]
 94strb   r2, [r12, #0x208]
 95beq    0b
 96ldmfd  sp!, {r2-r3, pc}
 97
 98CpuSet:
 99stmfd  sp!, {lr}
100mov    r3, r2, lsl #12
101tst    r2, #0x01000000
102beq    0f
103# Fill
104tst    r2, #0x04000000
105beq    1f
106# Word
107add    r3, r1, r3, lsr #10
108ldmia  r0!, {r2}
1092:
110cmp    r1, r3
111stmltia  r1!, {r2}
112blt    2b
113b      3f
114# Halfword
1151:
116bic    r0, #1
117bic    r1, #1
118add    r3, r1, r3, lsr #11
119ldrh   r2, [r0]
1202:
121cmp    r1, r3
122strlth r2, [r1], #2
123blt    2b
124b      3f
125# Copy
1260:
127tst    r2, #0x04000000
128beq    1f
129# Word
130add    r3, r1, r3, lsr #10
1312:
132cmp    r1, r3
133ldmltia r0!, {r2}
134stmltia r1!, {r2}
135blt    2b
136b      3f
137# Halfword
1381:
139add    r3, r1, r3, lsr #11
140bic    r0, #1
141bic    r1, #1
1422:
143cmp    r1, r3
144ldrlth r2, [r0], #2
145strlth r2, [r1], #2
146blt    2b
1473:
148ldmfd  sp!, {pc}
149
150CpuFastSet:
151stmfd  sp!, {r4-r10, lr}
152tst    r2, #0x01000000
153mov    r3, r2, lsl #12
154add    r2, r1, r3, lsr #10
155beq    0f
156# Fill
157ldr    r3, [r0]
158mov    r4, r3
159mov    r5, r3
160mov    r6, r3
161mov    r7, r3
162mov    r8, r3
163mov    r9, r3
164mov    r10, r3
1651:
166cmp    r1, r2
167stmltia r1!, {r3-r10}
168blt    1b
169b      2f
170# Copy
1710:
172cmp    r1, r2
173ldmltia r0!, {r3-r10}
174stmltia r1!, {r3-r10}
175blt    0b
1762:
177ldmfd  sp!, {r4-r10, pc}