Kernel: Move common aarch64 asm functions into kernel folder and NS

This commit is contained in:
James Mintram 2021-11-21 01:08:07 +00:00 committed by Brian Gianforcaro
parent 68b5d00f42
commit c2d7e200eb
6 changed files with 45 additions and 18 deletions

View file

@ -0,0 +1,38 @@
/*
* Copyright (c) 2021, James Mintram <me@jamesrm.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <Kernel/Arch/aarch64/Aarch64Registers.h>
namespace Kernel {
[[noreturn]] inline void halt()
{
for (;;) {
asm volatile("wfi");
}
}
enum class ExceptionLevel : u8 {
EL0 = 0,
EL1 = 1,
EL2 = 2,
EL3 = 3,
};
inline ExceptionLevel get_current_exception_level()
{
u64 current_exception_level;
asm("mrs %[value], CurrentEL"
: [value] "=r"(current_exception_level));
current_exception_level = (current_exception_level >> 2) & 0x3;
return static_cast<ExceptionLevel>(current_exception_level);
}
}

View file

@ -5,14 +5,6 @@
* SPDX-License-Identifier: BSD-2-Clause * 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 .global wait_cycles
.type wait_cycles, @function .type wait_cycles, @function
wait_cycles: wait_cycles:

View file

@ -6,14 +6,6 @@
#pragma once #pragma once
enum class ExceptionLevel : u8 {
EL0 = 0,
EL1 = 1,
EL2 = 2,
EL3 = 3,
};
extern "C" ExceptionLevel get_current_exception_level();
extern "C" void wait_cycles(int n); extern "C" void wait_cycles(int n);
// CPU initialization functions // CPU initialization functions

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#include <Kernel/Arch/aarch64/Aarch64Asm.h>
#include <Kernel/Arch/aarch64/Aarch64Registers.h> #include <Kernel/Arch/aarch64/Aarch64Registers.h>
#include <Kernel/Prekernel/Arch/aarch64/Aarch64_asm_utils.h> #include <Kernel/Prekernel/Arch/aarch64/Aarch64_asm_utils.h>
#include <Kernel/Prekernel/Arch/aarch64/Prekernel.h> #include <Kernel/Prekernel/Arch/aarch64/Prekernel.h>
@ -81,7 +82,7 @@ static void set_up_el1()
void drop_to_exception_level_1() void drop_to_exception_level_1()
{ {
switch (get_current_exception_level()) { switch (Kernel::get_current_exception_level()) {
case ExceptionLevel::EL3: case ExceptionLevel::EL3:
drop_to_el2(); drop_to_el2();
[[fallthrough]]; [[fallthrough]];

View file

@ -7,6 +7,7 @@
#include <AK/Types.h> #include <AK/Types.h>
#include <Kernel/Arch/aarch64/Aarch64Asm.h>
#include <Kernel/Prekernel/Arch/aarch64/Aarch64_asm_utils.h> #include <Kernel/Prekernel/Arch/aarch64/Aarch64_asm_utils.h>
#include <Kernel/Prekernel/Arch/aarch64/BootPPMParser.h> #include <Kernel/Prekernel/Arch/aarch64/BootPPMParser.h>
#include <Kernel/Prekernel/Arch/aarch64/Framebuffer.h> #include <Kernel/Prekernel/Arch/aarch64/Framebuffer.h>
@ -36,7 +37,7 @@ extern "C" [[noreturn]] void init()
uart.print_str("\r\n"); uart.print_str("\r\n");
uart.print_str("CPU started in: EL"); uart.print_str("CPU started in: EL");
uart.print_num(static_cast<u64>(get_current_exception_level())); uart.print_num(static_cast<u64>(Kernel::get_current_exception_level()));
uart.print_str("\r\n"); uart.print_str("\r\n");
uart.print_str("Drop CPU to EL1\r\n"); uart.print_str("Drop CPU to EL1\r\n");

View file

@ -23,6 +23,9 @@ if ("${SERENITY_ARCH}" STREQUAL "aarch64")
# Assembly # Assembly
Arch/aarch64/boot.S Arch/aarch64/boot.S
Arch/aarch64/Aarch64_asm_utils.S Arch/aarch64/Aarch64_asm_utils.S
# Shared with kernel
../Arch/aarch64/Aarch64Asm.cpp
) )
else() else()
set(SOURCES set(SOURCES