Atmosphere/sept/sept-primary/src/start.s

105 lines
2.3 KiB
ArmAsm
Raw Normal View History

2019-02-20 12:52:11 +00:00
/*
* Copyright (c) 2018-2020 Atmosphère-NX
2019-02-20 12:52:11 +00:00
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2019-02-20 12:52:11 +00:00
.section .text.start, "ax", %progbits
.arm
.align 5
.global _start
.type _start, %function
_start:
/* Set coldboot */
mov r0, #0x0
ldr r1, =0x7000E400
str r0, [r1, #0x50]
2019-02-20 12:52:11 +00:00
/* Tell pk1ldr normal reboot, no error */
str r0, [r1, #0x1B4]
str r0, [r1, #0x840]
2019-02-20 12:52:11 +00:00
/* Cleanup SVC handler address. */
ldr r0, =0x40004C30
ldr r1, =0x6000F208
str r0, [r1]
2019-02-20 12:52:11 +00:00
/* Disable RCM forcefully */
mov r0, #0x4
ldr r1, =0x15DC
ldr r2, =0xE020
bl ipatch_word
2019-02-20 12:52:11 +00:00
/* Patch BCT signature check */
mov r0, #0x5
ldr r1, =0x4AEE
ldr r2, =0xE05B
bl ipatch_word
2019-02-20 12:52:11 +00:00
/* Patch bootloader read */
mov r0, #0x6
ldr r1, =0x4E88
ldr r2, =0xE018
bl ipatch_word
2019-02-20 12:52:11 +00:00
ldr r0, =__main_phys_start__
ldr r1, =__main_start__
mov r2, #0x0
ldr r3, =(__main_size__)
copy_panic_payload:
ldr r4, [r0, r2]
str r4, [r1, r2]
add r2, r2, #0x4
cmp r2, r3
bne copy_panic_payload
2019-02-20 12:52:11 +00:00
/* Jump back to bootrom start. */
ldr r0, =0x101010
bx r0
2019-02-20 12:52:11 +00:00
/* Unused, but forces inclusion in binary. */
b main
2019-02-20 12:52:11 +00:00
.section .text.ipatch_word, "ax", %progbits
.arm
.align 5
.global ipatch_word
.type ipatch_word, %function
ipatch_word:
ldr r3, =0x6001dc00
lsl r0, r0, #0x2
lsr r1, r1, #0x1
lsl r1, r1, #0x10
orr r1, r1, r2
str r1, [r3, r0]
bx lr
2019-02-20 12:52:11 +00:00
.section .text.jump_to_main, "ax", %progbits
.arm
.align 5
.global jump_to_main
.type jump_to_main, %function
jump_to_main:
/* Insert 0x240 of NOPs, for version compatibility. */
.rept (0x240/4)
nop
.endr
2019-02-20 12:52:11 +00:00
/* Just jump to main */
ldr sp, =__stack_top__
b main