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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* For some reason GAS doesn't know about it, even with .cpu cortex-a57 */
|
|
|
|
#define cpuactlr_el1 s3_1_c15_c2_0
|
|
|
|
#define cpuectlr_el1 s3_1_c15_c2_1
|
|
|
|
|
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-29 00:25:50 +01:00
|
|
|
_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:
|
|
|
|
mov x19, #0
|
|
|
|
_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 00:25:50 +01:00
|
|
|
mrs x20, sctlr_el2
|
|
|
|
// Get core ID
|
|
|
|
mrs x20, mpidr_el1
|
|
|
|
and x20, x20, #0xFF
|
2019-07-18 22:43:49 +01:00
|
|
|
|
2019-07-29 00:25:50 +01:00
|
|
|
// Set tmp stack
|
|
|
|
ldr x8, =__stacks_top__
|
|
|
|
|
|
|
|
/* lsl x9, x20, #10
|
|
|
|
sub x8, x8, x9*/
|
|
|
|
mov sp, x8
|
|
|
|
|
|
|
|
// Set up x18
|
|
|
|
adrp x18, g_coreCtxs
|
|
|
|
add x18, x18, #:lo12:g_coreCtxs
|
|
|
|
add x18, x18, x20, lsl #3
|
|
|
|
stp x18, xzr, [sp, #-0x10]!
|
|
|
|
|
|
|
|
// Store entrypoint if first core
|
|
|
|
cbz x19, _store_arg
|
|
|
|
ldr x8, _initialKernelEntrypoint
|
|
|
|
str x8, [x18, #8]
|
|
|
|
|
|
|
|
_store_arg:
|
|
|
|
str x0, [x18, #0]
|
2019-07-17 22:54:31 +01:00
|
|
|
|
2019-07-17 00:49:47 +01:00
|
|
|
// Set VBAR
|
|
|
|
ldr x8, =__vectors_start__
|
|
|
|
msr vbar_el2, x8
|
|
|
|
|
2019-07-18 22:43:49 +01:00
|
|
|
// Make sure the regs have been set
|
|
|
|
dsb sy
|
|
|
|
isb
|
|
|
|
|
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
|
|
|
|
cbz x20, _jump_to_kernel
|
2019-07-17 00:49:47 +01:00
|
|
|
ldr x0, =__bss_start__
|
|
|
|
mov w1, #0
|
|
|
|
ldr x2, =__end__
|
|
|
|
sub x2, x2, x0
|
|
|
|
bl memset
|
|
|
|
|
2019-07-18 22:43:49 +01:00
|
|
|
bl main
|
2019-07-17 22:54:31 +01:00
|
|
|
|
2019-07-29 00:25:50 +01:00
|
|
|
_jump_to_kernel:
|
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
|