2019-07-17 00:49:47 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 Atmosphère-NX
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2020-01-14 00:58:31 +00:00
|
|
|
#include "asm_macros.s"
|
|
|
|
|
2019-07-18 22:43:49 +01:00
|
|
|
.section .crt0, "ax", %progbits
|
2019-07-17 00:49:47 +01:00
|
|
|
.align 3
|
|
|
|
.global _start
|
|
|
|
.type _start, %function
|
|
|
|
|
|
|
|
_start:
|
2019-07-17 22:54:31 +01:00
|
|
|
b start
|
2019-07-29 00:25:50 +01:00
|
|
|
b start2
|
2019-07-17 22:54:31 +01:00
|
|
|
|
2019-07-31 23:46:16 +01:00
|
|
|
.global g_initialKernelEntrypoint
|
|
|
|
g_initialKernelEntrypoint:
|
2019-07-17 22:54:31 +01:00
|
|
|
.quad 0
|
|
|
|
|
|
|
|
start:
|
2019-07-29 00:25:50 +01:00
|
|
|
mov x19, #1
|
|
|
|
b _startCommon
|
|
|
|
start2:
|
2019-07-30 20:13:38 +01:00
|
|
|
mov x19, xzr
|
2019-07-29 00:25:50 +01:00
|
|
|
_startCommon:
|
2020-01-17 22:10:26 +00:00
|
|
|
// Disable interrupts, select sp_el0 before mmu is enabled
|
2020-01-12 21:51:50 +00:00
|
|
|
mrs x20, cntpct_el0
|
2020-01-17 22:10:26 +00:00
|
|
|
msr daifset, 0b1111
|
|
|
|
msr spsel, #0
|
2020-01-12 21:51:50 +00:00
|
|
|
|
2019-08-06 21:26:28 +01:00
|
|
|
// Set sctlr_el2 ASAP to disable mmu/caching if not already done.
|
|
|
|
mov x1, #0x0838
|
|
|
|
movk x1, #0x30C5,lsl #16
|
2019-07-29 21:38:44 +01:00
|
|
|
msr sctlr_el2, x1
|
|
|
|
dsb sy
|
|
|
|
isb
|
|
|
|
|
2020-01-15 02:42:07 +00:00
|
|
|
bl cacheClearLocalDataCacheOnBoot
|
|
|
|
cbz x19, 1f
|
2020-01-17 22:10:26 +00:00
|
|
|
|
|
|
|
// "Boot core only" stuff:
|
2020-01-15 02:42:07 +00:00
|
|
|
bl cacheClearSharedDataCachesOnBoot
|
2020-01-20 02:24:02 +00:00
|
|
|
ic iallu
|
|
|
|
dsb nsh
|
|
|
|
isb
|
|
|
|
|
2020-01-17 22:10:26 +00:00
|
|
|
// Temporarily use temp end region as stack, then create the translation table
|
|
|
|
// The stack top is also equal to the mmu table address...
|
|
|
|
adr x0, g_loadImageLayout
|
|
|
|
ldp x2, x3, [x0, #0x18]
|
|
|
|
add x1, x2, x3
|
|
|
|
mov sp, x1
|
|
|
|
bl memoryMapSetupMmu
|
2019-07-31 23:46:16 +01:00
|
|
|
|
2020-01-15 02:42:07 +00:00
|
|
|
1:
|
2020-01-17 22:10:26 +00:00
|
|
|
// Enable MMU, note that the function is not allowed to use any stack
|
|
|
|
adr x0, g_loadImageLayout
|
|
|
|
ldr x18, =_postMmuEnableReturnAddr
|
|
|
|
bl memoryMapEnableMmu
|
|
|
|
|
|
|
|
// This is where we will land on exception return after enabling the MMU:
|
|
|
|
_postMmuEnableReturnAddr:
|
|
|
|
// Select sp_el2
|
|
|
|
msr spsel, #1
|
|
|
|
|
2019-07-29 00:25:50 +01:00
|
|
|
// Get core ID
|
2020-01-17 22:10:26 +00:00
|
|
|
mrs x8, mpidr_el1
|
|
|
|
and x8, x8, #0xFF
|
|
|
|
|
|
|
|
mov w0, w8
|
|
|
|
bl memoryMapGetStackTop
|
|
|
|
mov sp, x0
|
|
|
|
|
|
|
|
// Set up x18, other sysregs, BSS, etc.
|
2019-08-06 21:26:28 +01:00
|
|
|
// Don't call init array to save space?
|
2020-01-17 22:10:26 +00:00
|
|
|
mov w0, w8
|
2019-07-31 23:46:16 +01:00
|
|
|
mov w1, w19
|
2019-08-06 21:26:28 +01:00
|
|
|
bl initSystem
|
2019-07-29 00:25:50 +01:00
|
|
|
|
2019-08-06 21:26:28 +01:00
|
|
|
// Save x18, reserve space for exception frame
|
|
|
|
stp x18, xzr, [sp, #-0x10]!
|
2020-01-14 00:58:31 +00:00
|
|
|
sub sp, sp, #EXCEP_STACK_FRAME_SIZE
|
2019-08-05 01:21:18 +01:00
|
|
|
|
|
|
|
mov x0, sp
|
2020-01-12 21:51:50 +00:00
|
|
|
mov x1, x20
|
2020-01-02 18:41:52 +00:00
|
|
|
bl thermosphereMain
|
2019-07-17 22:54:31 +01:00
|
|
|
|
2019-07-18 22:43:49 +01:00
|
|
|
dsb sy
|
|
|
|
isb
|
2019-08-05 01:21:18 +01:00
|
|
|
|
|
|
|
// Jump to kernel
|
2020-01-08 22:18:56 +00:00
|
|
|
b _restoreAllRegisters
|
2019-07-17 00:49:47 +01:00
|
|
|
|
|
|
|
.pool
|
2020-01-17 22:10:26 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
typedef struct LoadImageLayout {
|
|
|
|
uintptr_t startPa;
|
|
|
|
size_t imageSize; // "image" includes "real" BSS but not tempbss
|
|
|
|
size_t maxImageSize;
|
|
|
|
|
|
|
|
uintptr_t tempPa;
|
|
|
|
size_t maxTempSize;
|
|
|
|
size_t tempSize;
|
|
|
|
|
|
|
|
uintptr_t vbar;
|
|
|
|
} LoadImageLayout;
|
|
|
|
*/
|
|
|
|
.global g_loadImageLayout
|
|
|
|
g_loadImageLayout:
|
|
|
|
.quad __start_pa__
|
|
|
|
.quad __max_image_size__
|
|
|
|
.quad __image_size__
|
|
|
|
.quad __temp_pa__
|
|
|
|
.quad __max_temp_size__
|
|
|
|
.quad __temp_size__
|
|
|
|
.quad __vectors_start__
|