Files
ladybird/Kernel/Prekernel/Arch/aarch64/Aarch64_asm_utils.S
Marcin Undak d14d7ee78b Kernel: Discover initial exception level when booting Aarch64
When booting on RPI3 firmware puts CPU in EL2 mode which is
different from QEMU's default EL3.

I've added logic to discover initial mode at boot
and then act accordingly. This results in Serenity corectly
switching to EL1 on target hardware now.
2021-10-15 17:47:39 +01:00

48 lines
1.0 KiB
ArmAsm

/*
* Copyright (c) 2021, Nico Weber <thakis@chromium.org>
* Copyright (c) 2021, Marcin Undak <mcinek@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
.global get_current_exception_level
.type get_current_exception_level, @function
get_current_exception_level:
mrs x0, CurrentEL
lsr x0, x0, #2
and x0, x0, #0x3
ret
.global wait_cycles
.type wait_cycles, @function
wait_cycles:
Lstart:
// This is probably too fast when caching and branch prediction is turned on.
// FIXME: Make timer-based.
subs x0, x0, #1
bne Lstart
ret
.global return_from_el2
.type return_from_el2, @function
return_from_el2:
adr x0, jump_to_os_start
msr elr_el2, x0
eret
.global return_from_el3
.type return_from_el3, @function
return_from_el3:
adr x0, jump_to_os_start
msr elr_el3, x0
eret
jump_to_os_start:
// Let stack start before .text for now.
// 512 kiB (0x80000) of stack are probably not sufficient, especially once we give the other cores some stack too,
// but for now it's ok.
ldr x14, =start
mov sp, x14
b os_start