all repos — mgba @ c41a3a2c0aff64e19cca9f279faaf1a47bf21230

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