mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2025-01-03 11:11:14 +00:00
arm64.hpp => arch.hpp, add GetCurrentCoreContextInstance
This commit is contained in:
parent
195da2e599
commit
b6bbc4f3e5
6 changed files with 56 additions and 22 deletions
11
mesosphere/include/mesosphere/arch/arch.hpp
Normal file
11
mesosphere/include/mesosphere/arch/arch.hpp
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if 1 //defined MESOSPHERE_ARCH_ARM64
|
||||||
|
|
||||||
|
#include <mesosphere/arch/arm64/arch.hpp>
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
//#error "No arch defined"
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,7 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <mesosphere/core/util.hpp>
|
#include <mesosphere/core/util.hpp>
|
||||||
#include <mesosphere/arch/arm64/arm64.hpp>
|
#include <mesosphere/arch/arm64/arch.hpp>
|
||||||
|
|
||||||
namespace mesosphere
|
namespace mesosphere
|
||||||
{
|
{
|
||||||
|
@ -27,25 +27,13 @@ class KInterruptMaskGuard final {
|
||||||
RestoreInterrupts(flags);
|
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(const KInterruptMaskGuard &) = delete;
|
||||||
KInterruptMaskGuard(KInterruptMaskGuard &&) = delete;
|
KInterruptMaskGuard(KInterruptMaskGuard &&) = delete;
|
||||||
KInterruptMaskGuard &operator=(const KInterruptMaskGuard &) = delete;
|
KInterruptMaskGuard &operator=(const KInterruptMaskGuard &) = delete;
|
||||||
KInterruptMaskGuard &operator=(KInterruptMaskGuard &&) = delete;
|
KInterruptMaskGuard &operator=(KInterruptMaskGuard &&) = delete;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FlagsType flags = 0;
|
u64 flags = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,13 +12,16 @@
|
||||||
#define MESOSPHERE_WRITE_SYSREG(v, r) do { \
|
#define MESOSPHERE_WRITE_SYSREG(v, r) do { \
|
||||||
u64 __val = (u64)v; \
|
u64 __val = (u64)v; \
|
||||||
asm volatile("msr " BOOST_PP_STRINGIZE(r) ", %0" \
|
asm volatile("msr " BOOST_PP_STRINGIZE(r) ", %0" \
|
||||||
:: "r" (__val)); \
|
:: "r" (__val) : "memory"); \
|
||||||
} while (false)
|
} while (false)
|
||||||
|
|
||||||
#define MESOSPHERE_DAIF_BIT(v) (((u64)(v)) >> 6)
|
#define MESOSPHERE_DAIF_BIT(v) (((u64)(v)) >> 6)
|
||||||
|
|
||||||
namespace mesosphere
|
namespace mesosphere
|
||||||
{
|
{
|
||||||
|
|
||||||
|
class KCoreContext;
|
||||||
|
|
||||||
inline namespace arch
|
inline namespace arch
|
||||||
{
|
{
|
||||||
inline namespace arm64
|
inline namespace arm64
|
||||||
|
@ -62,6 +65,37 @@ enum PsrBitGroup {
|
||||||
PSR_f = 0xFF000000u,
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <mesosphere/core/util.hpp>
|
#include <mesosphere/core/util.hpp>
|
||||||
#include <mesosphere/arch/arm64/arm64.hpp>
|
#include <mesosphere/arch/arm64/arch.hpp>
|
||||||
|
|
||||||
#ifndef MESOSPHERE_SYSTEM_CLOCK_RATE // NEEDS to be defined; depends on cntfreq
|
#ifndef MESOSPHERE_SYSTEM_CLOCK_RATE // NEEDS to be defined; depends on cntfreq
|
||||||
#define MESOSPHERE_SYSTEM_CLOCK_RATE 192000000ull
|
#define MESOSPHERE_SYSTEM_CLOCK_RATE 192000000ull
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <mesosphere/core/util.hpp>
|
#include <mesosphere/core/util.hpp>
|
||||||
|
#include <mesosphere/arch/arch.hpp>
|
||||||
|
|
||||||
namespace mesosphere
|
namespace mesosphere
|
||||||
{
|
{
|
||||||
|
@ -14,7 +15,7 @@ class KAlarm;
|
||||||
class KCoreContext {
|
class KCoreContext {
|
||||||
public:
|
public:
|
||||||
static KCoreContext &GetInstance(uint coreId) { return instances[coreId]; };
|
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; }
|
KThread *GetCurrentThread() const { return currentThread; }
|
||||||
KProcess *GetCurrentProcess() const { return currentProcess; }
|
KProcess *GetCurrentProcess() const { return currentProcess; }
|
||||||
|
|
|
@ -53,9 +53,9 @@ class KInterruptSpinLock<true> : public KSpinLock {
|
||||||
|
|
||||||
bool try_lock()
|
bool try_lock()
|
||||||
{
|
{
|
||||||
flags = KInterruptMaskGuard::MaskInterrupts();
|
flags = MaskInterrupts();
|
||||||
if (!KSpinLock::try_lock()) {
|
if (!KSpinLock::try_lock()) {
|
||||||
KInterruptMaskGuard::RestoreInterrupts(flags);
|
RestoreInterrupts(flags);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -63,14 +63,14 @@ class KInterruptSpinLock<true> : public KSpinLock {
|
||||||
|
|
||||||
void lock()
|
void lock()
|
||||||
{
|
{
|
||||||
flags = KInterruptMaskGuard::MaskInterrupts();
|
flags = MaskInterrupts();
|
||||||
KSpinLock::lock();
|
KSpinLock::lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void unlock()
|
void unlock()
|
||||||
{
|
{
|
||||||
KSpinLock::unlock();
|
KSpinLock::unlock();
|
||||||
KInterruptMaskGuard::RestoreInterrupts(flags);
|
RestoreInterrupts(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
KInterruptSpinLock() = default;
|
KInterruptSpinLock() = default;
|
||||||
|
@ -80,7 +80,7 @@ class KInterruptSpinLock<true> : public KSpinLock {
|
||||||
KInterruptSpinLock &operator=(KInterruptSpinLock &&) = delete;
|
KInterruptSpinLock &operator=(KInterruptSpinLock &&) = delete;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typename KInterruptMaskGuard::FlagsType flags = 0;
|
InterruptFlagsType flags = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue