2018-09-07 16:00:13 +01:00
|
|
|
/*
|
2020-01-24 10:10:40 +00:00
|
|
|
* Copyright (c) 2018-2020 Atmosphère-NX
|
2018-09-07 16:00:13 +01: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-12-09 11:58:48 +00:00
|
|
|
#include <vapours/ams_version.h>
|
2019-06-19 07:23:31 +01:00
|
|
|
|
2018-03-14 20:14:02 +00:00
|
|
|
.macro CLEAR_GPR_REG_ITER
|
|
|
|
mov r\@, #0
|
|
|
|
.endm
|
|
|
|
|
2018-05-07 00:02:23 +01:00
|
|
|
.section .text.start, "ax", %progbits
|
2018-03-14 20:14:02 +00:00
|
|
|
.arm
|
2019-02-25 04:22:38 +00:00
|
|
|
|
2018-03-14 20:14:02 +00:00
|
|
|
.align 5
|
|
|
|
.global _start
|
2018-05-07 00:02:23 +01:00
|
|
|
.type _start, %function
|
2018-03-14 20:14:02 +00:00
|
|
|
_start:
|
2019-02-25 04:22:38 +00:00
|
|
|
b _crt0
|
2019-06-19 07:23:31 +01:00
|
|
|
|
2019-02-25 04:22:38 +00:00
|
|
|
.word (_metadata - _start)
|
|
|
|
|
2020-10-15 17:41:01 +01:00
|
|
|
_is_experimental:
|
|
|
|
.word 0x00000001 /* is experimental */
|
|
|
|
|
2019-02-25 04:22:38 +00:00
|
|
|
_crt0:
|
2018-05-07 22:32:45 +01:00
|
|
|
/* Switch to system mode, mask all interrupts, clear all flags */
|
2018-03-14 20:14:02 +00:00
|
|
|
msr cpsr_cxsf, #0xDF
|
|
|
|
|
|
|
|
/* Relocate ourselves if necessary */
|
2019-02-25 04:22:38 +00:00
|
|
|
ldr r2, =_start
|
2018-04-08 12:06:04 +01:00
|
|
|
adr r3, _start
|
|
|
|
cmp r2, r3
|
2019-02-25 04:22:38 +00:00
|
|
|
beq _relocation_loop_end
|
2018-03-14 20:14:02 +00:00
|
|
|
|
2018-04-08 12:06:04 +01:00
|
|
|
ldr r4, =__bss_start__
|
2019-02-25 04:22:38 +00:00
|
|
|
sub r4, r4, r2 /* size >= 32, obviously, and weve declared 32-byte-alignment */
|
2018-03-14 20:14:02 +00:00
|
|
|
_relocation_loop:
|
2018-04-08 12:06:04 +01:00
|
|
|
ldmia r3!, {r5-r12}
|
|
|
|
stmia r2!, {r5-r12}
|
|
|
|
subs r4, #0x20
|
2018-03-14 20:14:02 +00:00
|
|
|
bne _relocation_loop
|
|
|
|
|
|
|
|
ldr r12, =_relocation_loop_end
|
|
|
|
bx r12
|
|
|
|
|
|
|
|
_relocation_loop_end:
|
|
|
|
/* Set the stack pointer */
|
2018-05-07 22:32:45 +01:00
|
|
|
ldr sp, =__stack_top__
|
|
|
|
mov fp, #0
|
|
|
|
bl __program_init
|
2018-03-14 20:14:02 +00:00
|
|
|
|
2018-05-07 22:32:45 +01:00
|
|
|
/* Set r0 to r12 to 0 (for debugging) & call main */
|
2018-03-14 20:14:02 +00:00
|
|
|
.rept 13
|
|
|
|
CLEAR_GPR_REG_ITER
|
|
|
|
.endr
|
2018-05-07 22:32:45 +01:00
|
|
|
ldr r0, =__program_argc
|
|
|
|
ldr r1, =__program_argv
|
|
|
|
ldr lr, =__program_exit
|
2018-05-08 13:44:28 +01:00
|
|
|
ldr r0, [r0]
|
|
|
|
ldr r1, [r1]
|
2018-05-07 22:32:45 +01:00
|
|
|
b main
|
2019-06-19 07:23:31 +01:00
|
|
|
|
2020-10-15 17:41:01 +01:00
|
|
|
.arm
|
|
|
|
.global fusee_is_experimental
|
|
|
|
.type fusee_is_experimental, %function
|
|
|
|
fusee_is_experimental:
|
|
|
|
ldr r0, =_is_experimental
|
|
|
|
ldr r0, [r0]
|
|
|
|
bx lr
|
|
|
|
|
2019-02-25 04:22:38 +00:00
|
|
|
/* Fusee-secondary header. */
|
|
|
|
.align 5
|
|
|
|
_metadata:
|
|
|
|
.ascii "FSS0"
|
|
|
|
.word __total_size__
|
|
|
|
.word (_crt0 - _start)
|
|
|
|
.word (_content_headers - _start)
|
|
|
|
.word (_content_headers_end - _content_headers) / 0x20 /* Number of content headers */
|
2019-02-25 04:28:06 +00:00
|
|
|
.word ((ATMOSPHERE_SUPPORTED_HOS_VERSION_MAJOR << 24) | (ATMOSPHERE_SUPPORTED_HOS_VERSION_MINOR << 16) | (ATMOSPHERE_SUPPORTED_HOS_VERSION_MICRO << 8) | (0x0))
|
2019-02-25 04:22:38 +00:00
|
|
|
.word ((ATMOSPHERE_RELEASE_VERSION_MAJOR << 24) | (ATMOSPHERE_RELEASE_VERSION_MINOR << 16) | (ATMOSPHERE_RELEASE_VERSION_MICRO << 8) | (0x0))
|
|
|
|
#define TO_WORD(x) TO_WORD_(x)
|
|
|
|
#define TO_WORD_(x) 0x##x
|
|
|
|
#define AMS_GIT_REV_WORD TO_WORD(ATMOSPHERE_GIT_HASH)
|
|
|
|
.word AMS_GIT_REV_WORD
|
|
|
|
#undef TO_WORD_
|
|
|
|
#undef TO_WORD
|
|
|
|
|
2019-03-05 18:53:17 +00:00
|
|
|
#define CONTENT_TYPE_FSP 0
|
|
|
|
#define CONTENT_TYPE_EXO 1
|
|
|
|
#define CONTENT_TYPE_WBT 2
|
|
|
|
#define CONTENT_TYPE_RBT 3
|
|
|
|
#define CONTENT_TYPE_SP1 4
|
|
|
|
#define CONTENT_TYPE_SP2 5
|
|
|
|
#define CONTENT_TYPE_KIP 6
|
|
|
|
#define CONTENT_TYPE_BMP 7
|
2019-06-15 13:48:04 +01:00
|
|
|
#define CONTENT_TYPE_EMC 8
|
2019-12-17 22:36:42 +00:00
|
|
|
#define CONTENT_TYPE_KLD 9
|
|
|
|
#define CONTENT_TYPE_KRN 10
|
2020-11-21 07:20:48 +00:00
|
|
|
#define CONTENT_TYPE_EXF 11
|
2019-03-05 18:53:17 +00:00
|
|
|
|
2020-03-08 18:50:38 +00:00
|
|
|
#define CONTENT_FLAG_NONE (0 << 0)
|
|
|
|
|
|
|
|
#define CONTENT_FLAG0_EXPERIMENTAL (1 << 0)
|
|
|
|
|
2019-02-25 04:22:38 +00:00
|
|
|
_content_headers:
|
|
|
|
/* ams_mitm content header */
|
|
|
|
.word __ams_mitm_kip_start__
|
|
|
|
.word __ams_mitm_kip_size__
|
2020-03-08 18:50:38 +00:00
|
|
|
.byte CONTENT_TYPE_KIP
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
2019-02-25 04:22:38 +00:00
|
|
|
.word 0xCCCCCCCC
|
|
|
|
.asciz "ams_mitm"
|
|
|
|
.align 5
|
|
|
|
|
2019-04-29 11:25:24 +01:00
|
|
|
/* boot content header */
|
|
|
|
.word __boot_kip_start__
|
|
|
|
.word __boot_kip_size__
|
2020-03-08 18:50:38 +00:00
|
|
|
.byte CONTENT_TYPE_KIP
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
2019-02-25 04:22:38 +00:00
|
|
|
.word 0xCCCCCCCC
|
2019-04-29 11:25:24 +01:00
|
|
|
.asciz "boot"
|
2019-02-25 04:22:38 +00:00
|
|
|
.align 5
|
|
|
|
|
|
|
|
/* exosphere content header */
|
|
|
|
.word __exosphere_bin_start__
|
|
|
|
.word __exosphere_bin_size__
|
2020-03-08 18:50:38 +00:00
|
|
|
.byte CONTENT_TYPE_EXO
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
2019-02-25 04:22:38 +00:00
|
|
|
.word 0xCCCCCCCC
|
|
|
|
.asciz "exosphere"
|
|
|
|
.align 5
|
|
|
|
|
2020-10-15 17:41:01 +01:00
|
|
|
/* mesosphere content header */
|
|
|
|
.word __mesosphere_bin_start__
|
|
|
|
.word __mesosphere_bin_size__
|
|
|
|
.byte CONTENT_TYPE_KRN
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.word 0xCCCCCCCC
|
|
|
|
.asciz "mesosphere"
|
|
|
|
.align 5
|
|
|
|
|
2019-02-25 04:22:38 +00:00
|
|
|
/* fusee_primary content header */
|
|
|
|
.word __fusee_primary_bin_start__
|
|
|
|
.word __fusee_primary_bin_size__
|
2020-03-08 18:50:38 +00:00
|
|
|
.byte CONTENT_TYPE_FSP
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
2019-02-25 04:22:38 +00:00
|
|
|
.word 0xCCCCCCCC
|
|
|
|
.asciz "fusee_primary"
|
|
|
|
.align 5
|
|
|
|
|
|
|
|
/* loader content header */
|
|
|
|
.word __loader_kip_start__
|
|
|
|
.word __loader_kip_size__
|
2020-03-08 18:50:38 +00:00
|
|
|
.byte CONTENT_TYPE_KIP
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
2019-02-25 04:22:38 +00:00
|
|
|
.word 0xCCCCCCCC
|
2020-03-08 18:50:38 +00:00
|
|
|
.asciz "Loader"
|
2019-02-25 04:22:38 +00:00
|
|
|
.align 5
|
|
|
|
|
2020-06-11 09:48:36 +01:00
|
|
|
/* warmboot content header */
|
|
|
|
.word __warmboot_bin_start__
|
|
|
|
.word __warmboot_bin_size__
|
2020-03-08 18:50:38 +00:00
|
|
|
.byte CONTENT_TYPE_WBT
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
2019-02-25 04:22:38 +00:00
|
|
|
.word 0xCCCCCCCC
|
2020-06-11 09:48:36 +01:00
|
|
|
.asciz "warmboot"
|
2019-02-25 04:22:38 +00:00
|
|
|
.align 5
|
|
|
|
|
|
|
|
/* pm content header */
|
|
|
|
.word __pm_kip_start__
|
|
|
|
.word __pm_kip_size__
|
2020-03-08 18:50:38 +00:00
|
|
|
.byte CONTENT_TYPE_KIP
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
2020-03-10 00:58:20 +00:00
|
|
|
.word 0xCCCCCCCC
|
2020-03-08 18:50:38 +00:00
|
|
|
.asciz "ProcessManager"
|
2019-02-25 04:22:38 +00:00
|
|
|
.align 5
|
|
|
|
|
|
|
|
/* rebootstub content header */
|
|
|
|
.word __rebootstub_bin_start__
|
|
|
|
.word __rebootstub_bin_size__
|
2020-03-08 18:50:38 +00:00
|
|
|
.byte CONTENT_TYPE_RBT
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
2019-02-25 04:22:38 +00:00
|
|
|
.word 0xCCCCCCCC
|
|
|
|
.asciz "rebootstub"
|
|
|
|
.align 5
|
|
|
|
|
|
|
|
/* sept_primary content header */
|
|
|
|
.word __sept_primary_bin_start__
|
|
|
|
.word __sept_primary_bin_size__
|
2020-03-08 18:50:38 +00:00
|
|
|
.byte CONTENT_TYPE_SP1
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
2019-02-25 04:22:38 +00:00
|
|
|
.word 0xCCCCCCCC
|
|
|
|
.asciz "sept_primary"
|
|
|
|
.align 5
|
|
|
|
|
2019-06-19 07:23:31 +01:00
|
|
|
/* sept_secondary 00 content header */
|
|
|
|
.word __sept_secondary_00_enc_start__
|
|
|
|
.word __sept_secondary_00_enc_size__
|
2020-03-08 18:50:38 +00:00
|
|
|
.byte CONTENT_TYPE_SP2
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
2019-06-19 07:23:31 +01:00
|
|
|
.word 0xCCCCCCCC
|
2019-06-30 04:13:24 +01:00
|
|
|
.asciz "septsecondary00"
|
2019-06-19 07:23:31 +01:00
|
|
|
.align 5
|
|
|
|
|
|
|
|
/* sept_secondary 01 content header */
|
|
|
|
.word __sept_secondary_01_enc_start__
|
|
|
|
.word __sept_secondary_01_enc_size__
|
2020-03-08 18:50:38 +00:00
|
|
|
.byte CONTENT_TYPE_SP2
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
2019-02-25 04:22:38 +00:00
|
|
|
.word 0xCCCCCCCC
|
2019-06-30 04:13:24 +01:00
|
|
|
.asciz "septsecondary01"
|
2019-02-25 04:22:38 +00:00
|
|
|
.align 5
|
|
|
|
|
|
|
|
/* sm content header */
|
|
|
|
.word __sm_kip_start__
|
|
|
|
.word __sm_kip_size__
|
2020-03-08 18:50:38 +00:00
|
|
|
.byte CONTENT_TYPE_KIP
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
2019-02-25 04:22:38 +00:00
|
|
|
.word 0xCCCCCCCC
|
|
|
|
.asciz "sm"
|
|
|
|
.align 5
|
|
|
|
|
2019-04-25 19:24:25 +01:00
|
|
|
/* spl content header */
|
|
|
|
.word __spl_kip_start__
|
|
|
|
.word __spl_kip_size__
|
2020-03-08 18:50:38 +00:00
|
|
|
.byte CONTENT_TYPE_KIP
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
2019-04-25 19:24:25 +01:00
|
|
|
.word 0xCCCCCCCC
|
|
|
|
.asciz "spl"
|
|
|
|
.align 5
|
|
|
|
|
2020-03-08 18:50:38 +00:00
|
|
|
/* ncm content header */
|
2020-03-08 08:21:01 +00:00
|
|
|
.word __ncm_kip_start__
|
|
|
|
.word __ncm_kip_size__
|
2020-03-08 18:50:38 +00:00
|
|
|
.byte CONTENT_TYPE_KIP
|
2020-09-18 05:04:43 +01:00
|
|
|
.byte CONTENT_FLAG_NONE
|
2020-03-08 18:50:38 +00:00
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
2020-03-08 08:21:01 +00:00
|
|
|
.word 0xCCCCCCCC
|
|
|
|
.asciz "NCM"
|
|
|
|
.align 5
|
|
|
|
|
2019-06-15 13:48:04 +01:00
|
|
|
/* emummc content header */
|
|
|
|
.word __emummc_kip_start__
|
|
|
|
.word __emummc_kip_size__
|
2020-03-08 18:50:38 +00:00
|
|
|
.byte CONTENT_TYPE_EMC
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
2019-06-15 13:48:04 +01:00
|
|
|
.word 0xCCCCCCCC
|
|
|
|
.asciz "emummc"
|
|
|
|
.align 5
|
|
|
|
|
2020-11-21 07:20:48 +00:00
|
|
|
/* exosphere mariko fatal program content header */
|
|
|
|
.word __mariko_fatal_bin_start__
|
|
|
|
.word __mariko_fatal_bin_size__
|
|
|
|
.byte CONTENT_TYPE_EXF
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.byte CONTENT_FLAG_NONE
|
|
|
|
.word 0xCCCCCCCC
|
|
|
|
.asciz "exosphere_fatal"
|
|
|
|
.align 5
|
|
|
|
|
2019-02-25 04:22:38 +00:00
|
|
|
_content_headers_end:
|
2018-05-07 00:02:23 +01:00
|
|
|
|
2018-05-07 22:32:45 +01:00
|
|
|
/* No need to include this in normal programs: */
|
2018-05-07 00:02:23 +01:00
|
|
|
.section .chainloader.text.start, "ax", %progbits
|
|
|
|
.arm
|
|
|
|
.align 5
|
|
|
|
.global relocate_and_chainload
|
|
|
|
.type relocate_and_chainload, %function
|
|
|
|
relocate_and_chainload:
|
2018-05-07 22:32:45 +01:00
|
|
|
ldr sp, =__stack_top__
|
2018-05-07 00:02:23 +01:00
|
|
|
b relocate_and_chainload_main
|
2018-09-15 21:08:58 +01:00
|
|
|
|
|
|
|
.section .nxboot.text.start, "ax", %progbits
|
|
|
|
.arm
|
|
|
|
.align 5
|
|
|
|
.global nxboot
|
|
|
|
.type nxboot, %function
|
|
|
|
nxboot:
|
|
|
|
ldr sp, =__stack_top__
|
|
|
|
b nxboot_finish
|