2016-03-21 03:20:15 +01:00
|
|
|
.arm.little
|
2016-02-08 03:37:03 +01:00
|
|
|
|
2016-10-14 19:13:33 +02:00
|
|
|
payload_addr equ 0x23F00000 ; Brahma payload address
|
|
|
|
payload_maxsize equ 0x100000 ; Maximum size for the payload (maximum that CakeBrah supports)
|
|
|
|
sd_notmounted equ 0xC8804465 ; Error code returned when SD is not mounted
|
2016-02-08 03:37:03 +01:00
|
|
|
|
2016-05-25 14:34:43 +02:00
|
|
|
.create "build/reboot.bin", 0
|
2016-02-08 03:37:03 +01:00
|
|
|
.arm
|
2016-08-27 18:10:51 +02:00
|
|
|
; Interesting registers and locations to keep in mind, set just before this code is ran:
|
|
|
|
; - r1: FIRM path in exefs.
|
2016-08-28 02:38:30 +02:00
|
|
|
; - r7: pointer to file object
|
2016-08-27 18:10:51 +02:00
|
|
|
; - *r7: vtable
|
|
|
|
; - *(vtable + 0x28): fread function
|
2016-08-28 02:38:30 +02:00
|
|
|
; - *(r7 + 8): file handle
|
2016-08-27 18:10:51 +02:00
|
|
|
|
|
|
|
mov r8, r1
|
2016-04-03 17:56:09 +02:00
|
|
|
|
|
|
|
pxi_wait_recv:
|
|
|
|
ldr r2, =0x44846
|
|
|
|
ldr r0, =0x10008000
|
|
|
|
readPxiLoop1:
|
|
|
|
ldrh r1, [r0, #4]
|
|
|
|
lsls r1, #0x17
|
|
|
|
bmi readPxiLoop1
|
|
|
|
ldr r0, [r0, #0xC]
|
|
|
|
cmp r0, r2
|
|
|
|
bne pxi_wait_recv
|
|
|
|
|
2016-10-07 14:27:30 +02:00
|
|
|
open_payload:
|
|
|
|
; Open file
|
|
|
|
add r0, r7, #8
|
2016-10-15 00:32:00 +02:00
|
|
|
adr r1, fname
|
2016-10-07 14:27:30 +02:00
|
|
|
mov r2, #1
|
|
|
|
ldr r6, [fopen]
|
|
|
|
orr r6, 1
|
|
|
|
blx r6
|
|
|
|
cmp r0, #0
|
2016-10-14 19:13:33 +02:00
|
|
|
beq read_payload
|
|
|
|
ldr r2, =sd_notmounted
|
|
|
|
cmp r0, r2
|
2016-10-22 23:38:26 +02:00
|
|
|
bne panic
|
2016-10-15 00:32:00 +02:00
|
|
|
adr r0, fname
|
|
|
|
adr r1, nand_mount
|
|
|
|
mov r2, #8
|
|
|
|
bl memcpy16
|
2016-10-14 19:13:33 +02:00
|
|
|
b open_payload
|
2016-09-22 14:48:28 +02:00
|
|
|
|
2016-10-14 19:13:33 +02:00
|
|
|
read_payload:
|
|
|
|
; Read file
|
|
|
|
mov r0, r7
|
|
|
|
adr r1, bytes_read
|
|
|
|
ldr r2, =payload_addr
|
|
|
|
ldr r3, =payload_maxsize
|
|
|
|
ldr r6, [r7]
|
|
|
|
ldr r6, [r6, #0x28]
|
|
|
|
blx r6
|
2016-04-11 05:15:44 +02:00
|
|
|
|
2016-08-13 20:49:40 +02:00
|
|
|
; Copy the low TID (in UTF-16) of the wanted firm to the 5th byte of the payload
|
2016-10-15 00:32:00 +02:00
|
|
|
ldr r0, =payload_addr + 4
|
|
|
|
add r1, r8, 0x1A
|
|
|
|
mov r2, #0x10
|
|
|
|
bl memcpy16
|
2016-02-08 03:37:03 +01:00
|
|
|
|
2016-04-03 17:56:09 +02:00
|
|
|
; Set kernel state
|
|
|
|
mov r0, #0
|
|
|
|
mov r1, #0
|
|
|
|
mov r2, #0
|
|
|
|
mov r3, #0
|
|
|
|
swi 0x7C
|
|
|
|
|
|
|
|
goto_reboot:
|
|
|
|
; Jump to reboot code
|
|
|
|
ldr r0, =(kernelcode_start - goto_reboot - 12)
|
2016-08-27 18:10:51 +02:00
|
|
|
add r0, pc ; pc is two instructions ahead of the instruction being executed (12 = 2*4 + 4)
|
2016-04-03 17:56:09 +02:00
|
|
|
swi 0x7B
|
|
|
|
|
|
|
|
die:
|
|
|
|
b die
|
|
|
|
|
2016-10-15 00:32:00 +02:00
|
|
|
memcpy16:
|
|
|
|
add r2, r0, r2
|
|
|
|
copy_loop:
|
|
|
|
ldrh r3, [r1], #2
|
|
|
|
strh r3, [r0], #2
|
|
|
|
cmp r0, r2
|
|
|
|
blo copy_loop
|
|
|
|
bx lr
|
|
|
|
|
2016-10-22 23:38:26 +02:00
|
|
|
panic:
|
|
|
|
mov r1, r0 ; unused register
|
|
|
|
mov r0, #0
|
|
|
|
swi 0x3C ; svcBreak(USERBREAK_PANIC)
|
2016-10-11 16:52:51 +02:00
|
|
|
b die
|
|
|
|
|
2016-04-03 17:56:09 +02:00
|
|
|
bytes_read: .word 0
|
|
|
|
fopen: .ascii "OPEN"
|
2016-02-08 03:37:03 +01:00
|
|
|
.pool
|
2016-10-15 00:32:00 +02:00
|
|
|
fname: .dcw "sdmc:/arm9loaderhax.bin"
|
|
|
|
.word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
2016-10-07 14:27:30 +02:00
|
|
|
.pool
|
2016-10-15 00:32:00 +02:00
|
|
|
nand_mount: .dcw "nand"
|
2016-02-25 20:19:20 +01:00
|
|
|
|
2016-04-03 17:56:09 +02:00
|
|
|
.align 4
|
|
|
|
kernelcode_start:
|
2016-07-01 20:27:28 +02:00
|
|
|
|
|
|
|
; Disable MPU
|
2016-04-03 17:56:09 +02:00
|
|
|
ldr r0, =0x42078 ; alt vector select, enable itcm
|
|
|
|
mcr p15, 0, r0, c1, c0, 0
|
2016-07-01 20:27:28 +02:00
|
|
|
|
|
|
|
; Clean and flush data cache
|
|
|
|
mov r1, #0 ; segment counter
|
|
|
|
outer_loop:
|
|
|
|
mov r0, #0 ; line counter
|
|
|
|
|
|
|
|
inner_loop:
|
|
|
|
orr r2, r1, r0 ; generate segment and line address
|
|
|
|
mcr p15, 0, r2, c7, c14, 2 ; clean and flush the line
|
|
|
|
add r0, #0x20 ; increment to next line
|
|
|
|
cmp r0, #0x400
|
|
|
|
bne inner_loop
|
|
|
|
|
|
|
|
add r1, #0x40000000
|
|
|
|
cmp r1, #0
|
|
|
|
bne outer_loop
|
|
|
|
|
|
|
|
mcr p15, 0, r1, c7, c10, 4 ; drain write buffer
|
|
|
|
|
|
|
|
; Flush instruction cache
|
|
|
|
mcr p15, 0, r1, c7, c5, 0
|
2016-04-03 17:56:09 +02:00
|
|
|
|
2016-04-11 05:15:44 +02:00
|
|
|
; Jump to payload
|
|
|
|
ldr r0, =payload_addr
|
2016-04-03 17:56:09 +02:00
|
|
|
bx r0
|
2016-02-25 20:19:20 +01:00
|
|
|
|
2016-04-11 05:15:44 +02:00
|
|
|
.pool
|
2016-10-22 23:38:26 +02:00
|
|
|
.close
|