From b6bbc4f3e573b2a9a03ec3b670ff160b3015828e Mon Sep 17 00:00:00 2001 From: TuxSH Date: Fri, 9 Nov 2018 12:33:51 +0100 Subject: [PATCH] arm64.hpp => arch.hpp, add GetCurrentCoreContextInstance --- mesosphere/include/mesosphere/arch/arch.hpp | 11 ++++++ .../arch/arm64/KInterruptMaskGuard.hpp | 16 ++------- .../arch/arm64/{arm64.hpp => arch.hpp} | 36 ++++++++++++++++++- .../common/arm/arm64/timer/KSystemClock.hpp | 2 +- .../include/mesosphere/core/KCoreContext.hpp | 3 +- .../interrupts/KInterruptSpinLock.hpp | 10 +++--- 6 files changed, 56 insertions(+), 22 deletions(-) create mode 100644 mesosphere/include/mesosphere/arch/arch.hpp rename mesosphere/include/mesosphere/arch/arm64/{arm64.hpp => arch.hpp} (61%) diff --git a/mesosphere/include/mesosphere/arch/arch.hpp b/mesosphere/include/mesosphere/arch/arch.hpp new file mode 100644 index 000000000..123212ed9 --- /dev/null +++ b/mesosphere/include/mesosphere/arch/arch.hpp @@ -0,0 +1,11 @@ +#pragma once + +#if 1 //defined MESOSPHERE_ARCH_ARM64 + +#include + +#else + +//#error "No arch defined" + +#endif \ No newline at end of file diff --git a/mesosphere/include/mesosphere/arch/arm64/KInterruptMaskGuard.hpp b/mesosphere/include/mesosphere/arch/arm64/KInterruptMaskGuard.hpp index 716252b26..4bf1d8633 100644 --- a/mesosphere/include/mesosphere/arch/arm64/KInterruptMaskGuard.hpp +++ b/mesosphere/include/mesosphere/arch/arm64/KInterruptMaskGuard.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include +#include namespace mesosphere { @@ -27,25 +27,13 @@ class KInterruptMaskGuard final { RestoreInterrupts(flags); } - static FlagsType MaskInterrupts() - { - FlagsType flags = MESOSPHERE_READ_SYSREG(daif); - MESOSPHERE_WRITE_SYSREG(flags | PSR_I_BIT, daif); - return flags; - } - - static void RestoreInterrupts(FlagsType flags) - { - MESOSPHERE_WRITE_SYSREG(MESOSPHERE_READ_SYSREG(daif) | (flags & PSR_I_BIT), daif); - } - KInterruptMaskGuard(const KInterruptMaskGuard &) = delete; KInterruptMaskGuard(KInterruptMaskGuard &&) = delete; KInterruptMaskGuard &operator=(const KInterruptMaskGuard &) = delete; KInterruptMaskGuard &operator=(KInterruptMaskGuard &&) = delete; private: - FlagsType flags = 0; + u64 flags = 0; }; } diff --git a/mesosphere/include/mesosphere/arch/arm64/arm64.hpp b/mesosphere/include/mesosphere/arch/arm64/arch.hpp similarity index 61% rename from mesosphere/include/mesosphere/arch/arm64/arm64.hpp rename to mesosphere/include/mesosphere/arch/arm64/arch.hpp index 1126ea4b4..c3b45097d 100644 --- a/mesosphere/include/mesosphere/arch/arm64/arm64.hpp +++ b/mesosphere/include/mesosphere/arch/arm64/arch.hpp @@ -12,13 +12,16 @@ #define MESOSPHERE_WRITE_SYSREG(v, r) do { \ u64 __val = (u64)v; \ asm volatile("msr " BOOST_PP_STRINGIZE(r) ", %0" \ - :: "r" (__val)); \ + :: "r" (__val) : "memory"); \ } while (false) #define MESOSPHERE_DAIF_BIT(v) (((u64)(v)) >> 6) namespace mesosphere { + +class KCoreContext; + inline namespace arch { inline namespace arm64 @@ -62,6 +65,37 @@ enum PsrBitGroup { PSR_f = 0xFF000000u, }; +using InterruptFlagsType = u64; + +static inline InterruptFlagsType MaskInterrupts() +{ + InterruptFlagsType flags = MESOSPHERE_READ_SYSREG(daif); + MESOSPHERE_WRITE_SYSREG(flags | PSR_I_BIT, daif); + return flags; +} + +static inline void RestoreInterrupts(InterruptFlagsType flags) +{ + MESOSPHERE_WRITE_SYSREG(MESOSPHERE_READ_SYSREG(daif) | (flags & PSR_I_BIT), daif); +} + +static inline KCoreContext &GetCurrentCoreContextInstance() +{ + register KCoreContext *x18 asm ("x18"); + return *x18; +} + +static inline void ReloadCurrentCoreContextInstance() +{ + asm volatile("mrs x18, tpidr_el1" ::: "x18", "memory"); +} + +static inline void SetCurrentCoreContextInstance(KCoreContext &cctx) +{ + MESOSPHERE_WRITE_SYSREG((uiptr)&cctx, tpidr_el1); + ReloadCurrentCoreContextInstance(); +} + } } } diff --git a/mesosphere/include/mesosphere/board/common/arm/arm64/timer/KSystemClock.hpp b/mesosphere/include/mesosphere/board/common/arm/arm64/timer/KSystemClock.hpp index 587651ed3..88f7e445c 100644 --- a/mesosphere/include/mesosphere/board/common/arm/arm64/timer/KSystemClock.hpp +++ b/mesosphere/include/mesosphere/board/common/arm/arm64/timer/KSystemClock.hpp @@ -2,7 +2,7 @@ #include #include -#include +#include #ifndef MESOSPHERE_SYSTEM_CLOCK_RATE // NEEDS to be defined; depends on cntfreq #define MESOSPHERE_SYSTEM_CLOCK_RATE 192000000ull diff --git a/mesosphere/include/mesosphere/core/KCoreContext.hpp b/mesosphere/include/mesosphere/core/KCoreContext.hpp index b68834d54..e33d9bd59 100644 --- a/mesosphere/include/mesosphere/core/KCoreContext.hpp +++ b/mesosphere/include/mesosphere/core/KCoreContext.hpp @@ -2,6 +2,7 @@ #include #include +#include namespace mesosphere { @@ -14,7 +15,7 @@ class KAlarm; class KCoreContext { public: static KCoreContext &GetInstance(uint coreId) { return instances[coreId]; }; - static KCoreContext &GetCurrentInstance() { return instances[0]; /* FIXME*/ }; + static KCoreContext &GetCurrentInstance() { return GetCurrentCoreContextInstance(); }; KThread *GetCurrentThread() const { return currentThread; } KProcess *GetCurrentProcess() const { return currentProcess; } diff --git a/mesosphere/include/mesosphere/interrupts/KInterruptSpinLock.hpp b/mesosphere/include/mesosphere/interrupts/KInterruptSpinLock.hpp index f22e7755d..e92e0fce6 100644 --- a/mesosphere/include/mesosphere/interrupts/KInterruptSpinLock.hpp +++ b/mesosphere/include/mesosphere/interrupts/KInterruptSpinLock.hpp @@ -53,9 +53,9 @@ class KInterruptSpinLock : public KSpinLock { bool try_lock() { - flags = KInterruptMaskGuard::MaskInterrupts(); + flags = MaskInterrupts(); if (!KSpinLock::try_lock()) { - KInterruptMaskGuard::RestoreInterrupts(flags); + RestoreInterrupts(flags); return false; } return true; @@ -63,14 +63,14 @@ class KInterruptSpinLock : public KSpinLock { void lock() { - flags = KInterruptMaskGuard::MaskInterrupts(); + flags = MaskInterrupts(); KSpinLock::lock(); } void unlock() { KSpinLock::unlock(); - KInterruptMaskGuard::RestoreInterrupts(flags); + RestoreInterrupts(flags); } KInterruptSpinLock() = default; @@ -80,7 +80,7 @@ class KInterruptSpinLock : public KSpinLock { KInterruptSpinLock &operator=(KInterruptSpinLock &&) = delete; private: - typename KInterruptMaskGuard::FlagsType flags = 0; + InterruptFlagsType flags = 0; }; }