diff options
Diffstat (limited to 'Kernel/Arch')
-rw-r--r-- | Kernel/Arch/aarch64/Aarch64Asm.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Kernel/Arch/aarch64/Aarch64Asm.h b/Kernel/Arch/aarch64/Aarch64Asm.h new file mode 100644 index 0000000000..41276949c5 --- /dev/null +++ b/Kernel/Arch/aarch64/Aarch64Asm.h @@ -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); +} + +} |