From bd5969fc876a10b18613302db7087ef3c40f18e1 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Thu, 7 Mar 2024 17:28:00 -0500 Subject: lib: Add mlibc Signed-off-by: Ian Moffett --- .../internal/aarch64-include/mlibc/arch-defs.hpp | 12 ++++++++++++ .../internal/aarch64-include/mlibc/thread.hpp | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 lib/mlibc/options/internal/aarch64-include/mlibc/arch-defs.hpp create mode 100644 lib/mlibc/options/internal/aarch64-include/mlibc/thread.hpp (limited to 'lib/mlibc/options/internal/aarch64-include') diff --git a/lib/mlibc/options/internal/aarch64-include/mlibc/arch-defs.hpp b/lib/mlibc/options/internal/aarch64-include/mlibc/arch-defs.hpp new file mode 100644 index 0000000..0a4789f --- /dev/null +++ b/lib/mlibc/options/internal/aarch64-include/mlibc/arch-defs.hpp @@ -0,0 +1,12 @@ +#ifndef MLIBC_ARCH_DEFS_HPP +#define MLIBC_ARCH_DEFS_HPP + +#include + +namespace mlibc { + +inline constexpr size_t page_size = 0x1000; + +} // namespace mlibc + +#endif // MLIBC_ARCH_DEFS_HPP diff --git a/lib/mlibc/options/internal/aarch64-include/mlibc/thread.hpp b/lib/mlibc/options/internal/aarch64-include/mlibc/thread.hpp new file mode 100644 index 0000000..b62d832 --- /dev/null +++ b/lib/mlibc/options/internal/aarch64-include/mlibc/thread.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include +#include + +namespace mlibc { + +inline Tcb *get_current_tcb() { + // On AArch64, TPIDR_EL0 points to 0x10 bytes before the first TLS block. + uintptr_t ptr; + asm ("mrs %0, tpidr_el0" : "=r"(ptr)); + return reinterpret_cast(ptr + 0x10 - sizeof(Tcb)); +} + +inline uintptr_t get_sp() { + uintptr_t sp; + asm ("mov %0, sp" : "=r"(sp)); + return sp; +} + +} // namespace mlibc -- cgit v1.2.3