summaryrefslogtreecommitdiff
path: root/Kernel/Arch
diff options
context:
space:
mode:
authorJames Mintram <me@jamesrm.com>2021-11-21 01:08:07 +0000
committerBrian Gianforcaro <b.gianfo@gmail.com>2021-11-28 22:01:21 -0800
commitc2d7e200eb1cc01567e635b2d84ab59505521feb (patch)
tree245fedf5754c8ddf9ad25f0ce4b4ac56acb6d3b4 /Kernel/Arch
parent68b5d00f422bb05ca7d4ffdc692dd0c38411332e (diff)
downloadserenity-c2d7e200eb1cc01567e635b2d84ab59505521feb.zip
Kernel: Move common aarch64 asm functions into kernel folder and NS
Diffstat (limited to 'Kernel/Arch')
-rw-r--r--Kernel/Arch/aarch64/Aarch64Asm.h38
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);
+}
+
+}