From 57afb4058710a978bd7b07a368125d04378c62f1 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 11 Jul 2017 16:37:21 -0400 Subject: started tweaking with stuff --- gba/start/pkjb_crt0.s | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 gba/start/pkjb_crt0.s (limited to 'gba/start') diff --git a/gba/start/pkjb_crt0.s b/gba/start/pkjb_crt0.s new file mode 100644 index 0000000..0d9d657 --- /dev/null +++ b/gba/start/pkjb_crt0.s @@ -0,0 +1,102 @@ + .section ".init" + .global _start + .align + .arm +@--------------------------------------------------------------------------------- +_start: +@--------------------------------------------------------------------------------- + b rom_header_end + + .fill 156,1,0 @ Nintendo Logo Character Data (8000004h) + .fill 16,1,0 @ Game Title + .byte 0x30,0x31 @ Maker Code (80000B0h) + .byte 0x96 @ Fixed Value (80000B2h) + .byte 0x00 @ Main Unit Code (80000B3h) + .byte 0x00 @ Device Type (80000B4h) + .fill 7,1,0 @ unused + .byte 0x00 @ Software Version No (80000BCh) + .byte 0xf0 @ Complement Check (80000BDh) + .byte 0x00,0x00 @ Checksum (80000BEh) + +@--------------------------------------------------------------------------------- +rom_header_end: +@--------------------------------------------------------------------------------- + b start_vector @ This branch must be here for proper + @ positioning of the following header. + + .GLOBAL __boot_method, __slave_number +@--------------------------------------------------------------------------------- +__boot_method: +@--------------------------------------------------------------------------------- + .byte 0 @ boot method (0=ROM boot, 3=Multiplay boot) +@--------------------------------------------------------------------------------- +__slave_number: +@--------------------------------------------------------------------------------- + .byte 0 @ slave # (1=slave#1, 2=slave#2, 3=slave#3) + + .byte 0 @ reserved + .byte 0 @ reserved + .word 0 @ reserved + .word 0 @ reserved + .word 0 @ reserved + .word 0 @ reserved + .word 0 @ reserved + .word 0 @ reserved + + .fill 4096,1,0 @ 4kb of filler so no useful code gets overwritten when flash bytes get copied over the top. + .global start_vector + .align +@--------------------------------------------------------------------------------- +start_vector: +@--------------------------------------------------------------------------------- + +@--------------------------------------------------------------------------------- +@ Enter Thumb mode +@--------------------------------------------------------------------------------- + add r0, pc, #1 + bx r0 + + .thumb +@ Turn off sound + ldr r1, =0x4000084 + eor r0, r0, r0 + strh r0, [r1] + +@--------------------------------------------------------------------------------- +@ set heap end +@--------------------------------------------------------------------------------- + ldr r1, =fake_heap_end + ldr r0, =__eheap_end + str r0, [r1] +@--------------------------------------------------------------------------------- +@ global constructors +@--------------------------------------------------------------------------------- + ldr r3, =__libc_init_array + push {lr} + bl _blx_r3_stub +@--------------------------------------------------------------------------------- +@ Jump to user code +@--------------------------------------------------------------------------------- + mov r0, #0 @ int argc + mov r1, #0 @ char *argv[] + ldr r3, =main + bl _blx_r3_stub +@; If we're here, turn the sound back on before we return + ldr r1, =0x4000084 + mov r0, #0x8F + strh r0, [r1] +@; Also turn interrupts back on + ldr r1, =0x4000208 + mov r0, #1 + str r0, [r1] + pop {pc} + +@--------------------------------------------------------------------------------- +_blx_r3_stub: +@--------------------------------------------------------------------------------- + bx r3 + + .align + .pool + .end + -- cgit 1.4.1