2015-05-04 15:32:23 -07:00
|
|
|
.section ".init"
|
|
|
|
.global _start
|
|
|
|
.extern main
|
|
|
|
.align 4
|
|
|
|
.arm
|
2016-06-08 19:48:42 -04:00
|
|
|
.extern fake_heap_end @ used for heap setup by newlib used by devKitARM
|
2015-05-04 15:32:23 -07:00
|
|
|
|
2015-05-13 21:09:17 -07:00
|
|
|
#define SIZE_32KB 0b01110
|
|
|
|
#define SIZE_128KB 0b10000
|
|
|
|
#define SIZE_512KB 0b10010
|
|
|
|
#define SIZE_2MB 0b10100
|
|
|
|
#define SIZE_128MB 0b11010
|
|
|
|
#define SIZE_256MB 0b11011
|
|
|
|
#define SIZE_4GB 0b11111
|
|
|
|
|
|
|
|
@ Makes a MPU partition value
|
|
|
|
#define MAKE_PARTITION(offset, size_enum) \
|
|
|
|
(((offset) >> 12 << 12) | ((size_enum) << 1) | 1)
|
|
|
|
|
2015-05-04 15:32:23 -07:00
|
|
|
|
|
|
|
_start:
|
2015-05-13 21:09:17 -07:00
|
|
|
b _init
|
|
|
|
|
|
|
|
@ required, don't move :)
|
|
|
|
@ will be set to FIRM ARM9 entry point by BRAHMA
|
|
|
|
arm9ep_backup: .long 0xFFFF0000
|
|
|
|
|
|
|
|
_mpu_partition_table:
|
|
|
|
.word MAKE_PARTITION(0x00000000, SIZE_4GB) @ 0: Background region
|
|
|
|
.word MAKE_PARTITION(0x00000000, SIZE_128MB) @ 1: Instruction TCM (mirrored every 32KB)
|
|
|
|
.word MAKE_PARTITION(0x08000000, SIZE_2MB) @ 2: ARM9 internal memory
|
|
|
|
.word MAKE_PARTITION(0x10000000, SIZE_128MB) @ 3: IO region
|
|
|
|
.word MAKE_PARTITION(0x18000000, SIZE_128MB) @ 4: external device memory
|
|
|
|
.word MAKE_PARTITION(0x1FF80000, SIZE_512KB) @ 5: AXI WRAM
|
|
|
|
.word MAKE_PARTITION(0x20000000, SIZE_256MB) @ 6: FCRAM
|
|
|
|
.word 0 @ 7: Unused
|
|
|
|
|
|
|
|
_populate_mpu:
|
|
|
|
push {r4-r5, lr}
|
|
|
|
ldr r4, =_mpu_partition_table
|
|
|
|
|
|
|
|
ldr r5, [r4, #0x0] @ mmu_partition_table[0] load
|
|
|
|
mcr p15, 0, r5, c6, c0, 0 @ mmu_partition_table[0] write
|
|
|
|
ldr r5, [r4, #0x4]
|
|
|
|
mcr p15, 0, r5, c6, c1, 0
|
|
|
|
ldr r5, [r4, #0x8]
|
|
|
|
mcr p15, 0, r5, c6, c2, 0
|
|
|
|
ldr r5, [r4, #0xC]
|
|
|
|
mcr p15, 0, r5, c6, c3, 0
|
|
|
|
ldr r5, [r4, #0x10]
|
|
|
|
mcr p15, 0, r5, c6, c4, 0
|
|
|
|
ldr r5, [r4, #0x14]
|
|
|
|
mcr p15, 0, r5, c6, c5, 0
|
|
|
|
ldr r5, [r4, #0x18]
|
|
|
|
mcr p15, 0, r5, c6, c6, 0
|
2015-05-14 04:23:24 -03:00
|
|
|
ldr r5, [r4, #0x1C]
|
|
|
|
mcr p15, 0, r5, c6, c7, 0
|
2015-05-13 21:09:17 -07:00
|
|
|
|
|
|
|
@ Give read/write access to all the memory regions
|
|
|
|
ldr r5, =0x03333333
|
|
|
|
mcr p15, 0, r5, c5, c0, 2 @ data access
|
|
|
|
ldr r5, =0x03300330
|
|
|
|
mcr p15, 0, r5, c5, c0, 3 @ instruction access
|
|
|
|
|
2015-05-14 04:23:24 -03:00
|
|
|
mov r5, #0x66
|
2015-05-13 21:09:17 -07:00
|
|
|
mcr p15, 0, r5, c2, c0, 0 @ data cachable
|
|
|
|
mcr p15, 0, r5, c2, c0, 1 @ instruction cachable
|
2015-05-04 15:32:23 -07:00
|
|
|
|
2015-05-13 21:09:17 -07:00
|
|
|
mov r5, #0x10
|
|
|
|
mcr p15, 0, r5, c3, c0, 0 @ data bufferable
|
2015-05-04 15:32:23 -07:00
|
|
|
|
2015-05-13 21:09:17 -07:00
|
|
|
pop {r4-r5, pc}
|
|
|
|
|
|
|
|
_enable_caches:
|
|
|
|
push {r4-r5, lr}
|
|
|
|
|
|
|
|
bl _populate_mpu
|
2016-06-22 23:54:19 -04:00
|
|
|
|
|
|
|
@ Make sure to clean and flush/invalidate data, to make sure there does not
|
|
|
|
@ remain any changes that are not in RAM.
|
|
|
|
bl _flush_and_clean_caches
|
2015-05-13 21:09:17 -07:00
|
|
|
|
|
|
|
mrc p15, 0, r4, c1, c0, 0
|
|
|
|
orr r4, r4, #(1<<12) @ instruction cache enable
|
|
|
|
orr r4, r4, #(1<<2) @ data cache enable
|
|
|
|
orr r4, r4, #(1<<0) @ mpu enable
|
|
|
|
mcr p15, 0, r4, c1, c0, 0
|
|
|
|
|
|
|
|
pop {r4-r5, pc}
|
2015-05-04 15:32:23 -07:00
|
|
|
|
2016-06-07 02:34:07 -04:00
|
|
|
_fix_sdmc_mount:
|
|
|
|
@ Fix mounting of SDMC
|
|
|
|
ldr r0, =0x10000020
|
|
|
|
mov r1, #0x340
|
|
|
|
str r1, [r0]
|
|
|
|
mov pc, lr
|
|
|
|
|
2016-06-08 19:48:42 -04:00
|
|
|
_setup_heap:
|
|
|
|
mov r0, #0x2000000 @ Setup a 32MiB heap
|
|
|
|
ldr r1, =__end__ @ grab the location of the end of the binary
|
|
|
|
add r0, r0, r1
|
|
|
|
ldr r1, =fake_heap_end @ heap goes from end of program to this variable
|
2016-06-20 23:22:30 -04:00
|
|
|
str r0, [r1]
|
|
|
|
mov pc, lr
|
2016-06-08 19:48:42 -04:00
|
|
|
|
2016-06-22 23:54:19 -04:00
|
|
|
_flush_and_clean_caches:
|
|
|
|
@ flush instruction cache, it's not flushed by Nintendo's function
|
|
|
|
mov r0, #0
|
|
|
|
mcr p15, 0, r0, c7, c5, 0
|
|
|
|
|
|
|
|
@ Nintendo's function uses r0-r2, r12, all registers that don't need
|
|
|
|
@ to be saved, just be aware that they are changed
|
|
|
|
@ use Nintendo's bx lr to return
|
|
|
|
ldr r0, =0xFFFF0830 @ Nintendo's flush function in unprot. bootrom
|
|
|
|
bx r0
|
|
|
|
|
2015-05-04 15:32:23 -07:00
|
|
|
_init:
|
2015-05-13 21:09:17 -07:00
|
|
|
push {r0-r12, lr}
|
|
|
|
|
2016-06-22 23:54:19 -04:00
|
|
|
@ Explicitly flush and clean caches, so the stack changes, if written to
|
|
|
|
@ cacheable memory, do make it to memory before disabling the MPU for
|
|
|
|
@ configuration changes.
|
|
|
|
bl _flush_and_clean_caches
|
|
|
|
|
|
|
|
@ Disabling the MPU at this point so that changes to caching policies do not
|
|
|
|
@ yield unexpected behavior.
|
2016-06-20 23:22:30 -04:00
|
|
|
mrc p15, 0, r4, c1, c0, 0
|
|
|
|
bic r4, r4, #(1<<0) @ mpu disable
|
|
|
|
mcr p15, 0, r4, c1, c0, 0
|
|
|
|
|
2015-05-13 21:09:17 -07:00
|
|
|
bl _enable_caches
|
2016-06-07 02:34:07 -04:00
|
|
|
|
|
|
|
bl _fix_sdmc_mount
|
2016-06-07 02:30:30 -04:00
|
|
|
|
2016-06-08 19:48:42 -04:00
|
|
|
bl _setup_heap
|
|
|
|
|
2015-05-13 21:09:17 -07:00
|
|
|
bl main
|
|
|
|
|
|
|
|
mrc p15, 0, r4, c1, c0, 0
|
|
|
|
bic r4, r4, #(1<<0) @ mpu disable
|
|
|
|
mcr p15, 0, r4, c1, c0, 0
|
|
|
|
|
|
|
|
pop {r0-r12, lr}
|
2015-05-04 15:32:23 -07:00
|
|
|
|
2015-05-13 21:09:17 -07:00
|
|
|
@ return control to FIRM
|
|
|
|
ldr pc, arm9ep_backup
|