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/>.
|
|
|
|
*/
|
|
|
|
|
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
|
2019-07-31 00:23:53 +01:00
|
|
|
.global start2
|
|
|
|
.type start2, %function
|
2019-07-29 00:25:50 +01:00
|
|
|
start2:
|
2019-07-30 20:13:38 +01:00
|
|
|
mov x19, xzr
|
2019-07-29 00:25:50 +01:00
|
|
|
_startCommon:
|
2019-07-22 00:04:53 +01:00
|
|
|
// Disable interrupts, select sp_el2
|
2019-07-17 00:49:47 +01:00
|
|
|
msr daifset, 0b1111
|
2019-07-22 00:04:53 +01:00
|
|
|
msr spsel, #1
|
2019-07-17 00:49:47 +01:00
|
|
|
|
2019-07-29 21:38:44 +01:00
|
|
|
// Set VBAR
|
2019-07-30 20:13:38 +01:00
|
|
|
adrp x8, __vectors_start__
|
|
|
|
add x8, x8, #:lo12:__vectors_start__
|
2019-07-29 21:38:44 +01:00
|
|
|
msr vbar_el2, x8
|
|
|
|
|
|
|
|
// Set system to sane defaults, aarch64 for el1
|
|
|
|
mov x4, #0x0838
|
|
|
|
movk x4, #0xC5, lsl #16
|
|
|
|
orr x1, x4, #0x30000000
|
|
|
|
mov x2, #(1 << 31)
|
|
|
|
mov x3, #0xFFFFFFFF
|
|
|
|
|
|
|
|
msr sctlr_el2, x1
|
|
|
|
msr hcr_el2, x2
|
|
|
|
msr dacr32_el2, x3
|
2019-07-30 20:13:38 +01:00
|
|
|
msr sctlr_el1, x4
|
2019-07-29 21:38:44 +01:00
|
|
|
|
|
|
|
dsb sy
|
|
|
|
isb
|
|
|
|
|
2019-07-31 23:46:16 +01:00
|
|
|
mov x2, x0
|
|
|
|
|
2019-07-29 00:25:50 +01:00
|
|
|
// Get core ID
|
2019-07-31 00:23:53 +01:00
|
|
|
// Ensure Aff0 is 4-1 at most (4 cores), and that Aff1, 2 and 3 are 0 (1 cluster only)
|
2019-07-31 23:46:16 +01:00
|
|
|
mrs x0, mpidr_el1
|
|
|
|
tst x0, #(0xFF << 32)
|
|
|
|
bne .
|
|
|
|
and x0, x0, #0x00FFFFFF // Aff0 to 2
|
|
|
|
cmp x0, #4
|
2019-07-31 00:23:53 +01:00
|
|
|
bhs .
|
2019-07-18 22:43:49 +01:00
|
|
|
|
2019-07-30 20:13:38 +01:00
|
|
|
// Set tmp stack (__stacks_top__ is aligned)
|
|
|
|
adrp x8, __stacks_top__
|
2019-07-31 23:46:16 +01:00
|
|
|
lsl x9, x0, #10
|
2019-07-29 21:38:44 +01:00
|
|
|
sub sp, x8, x9
|
2019-07-29 00:25:50 +01:00
|
|
|
|
|
|
|
// Set up x18
|
2019-07-31 23:46:16 +01:00
|
|
|
mov w1, w19
|
|
|
|
bl coreCtxInit
|
2019-07-29 00:25:50 +01:00
|
|
|
stp x18, xzr, [sp, #-0x10]!
|
|
|
|
|
2019-07-17 00:49:47 +01:00
|
|
|
// Don't call init array to save space?
|
2019-07-29 00:25:50 +01:00
|
|
|
// Clear BSS & call main for the first core executing this code
|
2019-08-01 01:58:16 +01:00
|
|
|
cbz x19, _enable_mmu
|
2019-07-30 20:13:38 +01:00
|
|
|
adrp x0, __bss_start__
|
|
|
|
add x0, x0, #:lo12:__bss_start__
|
|
|
|
mov w1, wzr
|
|
|
|
adrp x2, __end__
|
|
|
|
add x2, x2, #:lo12:__end__
|
2019-07-17 00:49:47 +01:00
|
|
|
sub x2, x2, x0
|
|
|
|
bl memset
|
|
|
|
|
2019-08-01 01:58:16 +01:00
|
|
|
_enable_mmu:
|
|
|
|
|
2019-08-02 04:12:24 +01:00
|
|
|
// Enable EL2 address translation and caches
|
2019-08-01 01:58:16 +01:00
|
|
|
bl configureMemoryMapEnableMmu
|
2019-08-02 04:12:24 +01:00
|
|
|
// Enable EL1 Stage2 intermediate physical address translation
|
|
|
|
bl configureMemoryMapEnableStage2
|
2019-07-30 20:13:38 +01:00
|
|
|
|
2019-07-29 21:38:44 +01:00
|
|
|
dsb sy
|
|
|
|
isb
|
|
|
|
|
2019-07-18 22:43:49 +01:00
|
|
|
bl main
|
2019-07-17 22:54:31 +01:00
|
|
|
|
|
|
|
// Jump to kernel
|
2019-07-29 00:25:50 +01:00
|
|
|
mov x8, #(0b1111 << 6 | 0b0101) // EL1h+DAIF
|
|
|
|
msr spsr_el2, x8
|
|
|
|
|
|
|
|
ldp x0, x1, [x18]
|
|
|
|
msr elr_el2, x1
|
2019-07-18 22:43:49 +01:00
|
|
|
dsb sy
|
|
|
|
isb
|
2019-07-17 22:54:31 +01:00
|
|
|
eret
|
2019-07-17 00:49:47 +01:00
|
|
|
|
|
|
|
.pool
|