summaryrefslogtreecommitdiff
path: root/berry_fix/payload/asm
diff options
context:
space:
mode:
authorPikalaxALT <PikalaxALT@users.noreply.github.com>2019-09-03 15:33:11 -0400
committerGitHub <noreply@github.com>2019-09-03 15:33:11 -0400
commit1f4c88c95243e8d75f25d5b7868c837c47aa578d (patch)
tree0ce1dd280b64c7b3677f22a457952746bb1196e9 /berry_fix/payload/asm
parent5d30304f4e9ce26d4061cc3697439588126d6bdc (diff)
Copy Berry Fix MB dism from FR (#777)
* Copy Berry Fix MB dism from FR
Diffstat (limited to 'berry_fix/payload/asm')
-rw-r--r--berry_fix/payload/asm/crt0.s82
-rw-r--r--berry_fix/payload/asm/libagbsyscall.s46
-rw-r--r--berry_fix/payload/asm/macros/function.inc29
3 files changed, 157 insertions, 0 deletions
diff --git a/berry_fix/payload/asm/crt0.s b/berry_fix/payload/asm/crt0.s
new file mode 100644
index 000000000..872a63018
--- /dev/null
+++ b/berry_fix/payload/asm/crt0.s
@@ -0,0 +1,82 @@
+ .include "asm/macros/function.inc"
+ .include "constants/gba_constants.inc"
+
+ .syntax unified
+
+ .text
+
+ .arm
+ .align 2, 0
+ .global Init
+Init:
+ mov r0, PSR_IRQ_MODE
+ msr cpsr_cf, r0
+ ldr sp, sp_irq
+ mov r0, PSR_SYS_MODE
+ msr cpsr_cf, r0
+ ldr sp, sp_sys
+ ldr r1, =INTR_VECTOR
+ ldr r0, =IntrMain
+ str r0, [r1]
+ ldr r1, =AgbMain + 1
+ mov lr, pc
+ bx r1
+ b Init
+
+ .align 2, 0
+sp_sys: .word IWRAM_END - 0x100
+sp_irq: .word IWRAM_END - 0x60
+
+ .pool
+ .size Init, .-Init
+
+ .arm
+ .align 2, 0
+ .global IntrMain
+IntrMain: @ 0x2010048
+ mov ip, REG_BASE
+ add r3, ip, OFFSET_REG_IE
+ ldr r2, [r3]
+ and r1, r2, r2, lsr #16
+ mov r2, #0
+ ands r0, r1, #0x2000
+ strbne r0, [r3, #-0x17c]
+_02010064:
+ bne _02010064
+ ands r0, r1, #0xc0
+ bne _020100DC
+ add r2, r2, #4
+ ands r0, r1, #1
+ strhne r0, [ip, #-8]
+ bne _020100DC
+ add r2, r2, #4
+ ands r0, r1, #2
+ bne _020100DC
+ add r2, r2, #4
+ ands r0, r1, #4
+ bne _020100DC
+ add r2, r2, #4
+ ands r0, r1, #0x100
+ bne _020100DC
+ add r2, r2, #4
+ ands r0, r1, #0x200
+ bne _020100DC
+ add r2, r2, #4
+ ands r0, r1, #0x400
+ bne _020100DC
+ add r2, r2, #4
+ ands r0, r1, #0x800
+ bne _020100DC
+ add r2, r2, #4
+ ands r0, r1, #0x1000
+ bne _020100DC
+ add r2, r2, #4
+ ands r0, r1, #8
+_020100DC:
+ strh r0, [r3, #2]
+ ldr r1, =gIntrTable
+ add r1, r1, r2
+ ldr r0, [r1]
+ bx r0
+ .pool
+ .size IntrMain, .-IntrMain
diff --git a/berry_fix/payload/asm/libagbsyscall.s b/berry_fix/payload/asm/libagbsyscall.s
new file mode 100644
index 000000000..ea8ef3e89
--- /dev/null
+++ b/berry_fix/payload/asm/libagbsyscall.s
@@ -0,0 +1,46 @@
+ .include "asm/macros/function.inc"
+ .include "constants/gba_constants.inc"
+
+ .syntax unified
+
+ .text
+
+ thumb_func_start CpuSet
+CpuSet: @ 81E3B64
+ swi 0xB
+ bx lr
+ thumb_func_end CpuSet
+
+ thumb_func_start Div
+Div: @ 81E3B68
+ swi 0x6
+ bx lr
+ thumb_func_end Div
+
+ thumb_func_start Mod
+Mod:
+ swi 0x6
+ adds r0, r1, 0
+ bx lr
+ thumb_func_end Mod
+
+ thumb_func_start LZ77UnCompVram
+LZ77UnCompVram: @ 81E3B6C
+ swi 0x12
+ bx lr
+ thumb_func_end LZ77UnCompVram
+
+ thumb_func_start RegisterRamReset
+RegisterRamReset: @ 81E3B80
+ swi 0x1
+ bx lr
+ thumb_func_end RegisterRamReset
+
+ thumb_func_start VBlankIntrWait
+VBlankIntrWait: @ 81E3BA0
+ movs r2, 0
+ swi 0x5
+ bx lr
+ thumb_func_end VBlankIntrWait
+
+ .align 2, 0 @ Don't pad with nop.
diff --git a/berry_fix/payload/asm/macros/function.inc b/berry_fix/payload/asm/macros/function.inc
new file mode 100644
index 000000000..67fb373a8
--- /dev/null
+++ b/berry_fix/payload/asm/macros/function.inc
@@ -0,0 +1,29 @@
+ .macro arm_func_start name
+ .align 2, 0
+ .global \name
+ .arm
+ .type \name, function
+ .endm
+
+ .macro arm_func_end name
+ .size \name, .-\name
+ .endm
+
+ .macro thumb_func_start name
+ .align 2, 0
+ .global \name
+ .thumb
+ .thumb_func
+ .type \name, function
+ .endm
+
+ .macro non_word_aligned_thumb_func_start name
+ .global \name
+ .thumb
+ .thumb_func
+ .type \name, function
+ .endm
+
+ .macro thumb_func_end name
+ .size \name, .-\name
+ .endm