Add mesosphere (VERY VERY WIP)

This commit is contained in:
TuxSH
2018-10-31 21:47:31 +01:00
committed by Michael Scire
parent 50e307b4b7
commit 745fa84e5e
56 changed files with 5033 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
#include <mesosphere/interrupts/KAlarm.hpp>
#include <mesosphere/core/KCoreContext.hpp>
#include <mesosphere/threading/KScheduler.hpp>
#include <mesosphere/arch/KInterruptMaskGuard.hpp>
namespace mesosphere
{
void KAlarm::AddAlarmable(IAlarmable &alarmable)
{
std::lock_guard guard{spinlock};
alarmables.insert(alarmable);
KSystemClock::SetAlarm(alarmables.cbegin()->GetAlarmTime());
}
void KAlarm::RemoveAlarmable(const IAlarmable &alarmable)
{
std::lock_guard guard{spinlock};
alarmables.erase(alarmable);
KSystemClock::SetAlarm(alarmables.cbegin()->GetAlarmTime());
}
void KAlarm::HandleAlarm()
{
{
KCriticalSection &critsec = KScheduler::GetCriticalSection();
std::lock_guard criticalSection{critsec};
std::lock_guard guard{spinlock};
KSystemClock::SetInterruptMasked(true); // mask timer interrupt
KSystemClock::time_point currentTime = KSystemClock::now(), maxAlarmTime;
while (alarmables.begin() != alarmables.end()) {
IAlarmable &a = *alarmables.begin();
maxAlarmTime = a.alarmTime;
if (maxAlarmTime > currentTime) {
break;
}
alarmables.erase(a);
a.alarmTime = KSystemClock::time_point{};
a.OnAlarm();
}
if (maxAlarmTime > KSystemClock::time_point{}) {
KSystemClock::SetAlarm(maxAlarmTime);
}
}
{
// TODO Reenable interrupt 30
KInterruptMaskGuard guard{};
}
}
}

View File

@@ -0,0 +1,45 @@
#include <mesosphere/interrupts/KWorkQueue.hpp>
#include <mesosphere/core/KCoreContext.hpp>
#include <mesosphere/threading/KScheduler.hpp>
#include <mesosphere/arch/KInterruptMaskGuard.hpp>
namespace mesosphere
{
void KWorkQueue::AddWork(IWork &work)
{
workQueue.push_back(work);
KCoreContext::GetCurrentInstance().GetScheduler()->SetContextSwitchNeededForWorkQueue();
}
void KWorkQueue::Initialize()
{
//handlerThread.reset(new KThread); //TODO!
kassert(handlerThread == nullptr);
}
void KWorkQueue::HandleWorkQueue()
{
KCoreContext &cctx = KCoreContext::GetCurrentInstance();
while (true) {
IWork *work = nullptr;
do {
KInterruptMaskGuard imguard{};
auto it = workQueue.begin();
if (it != workQueue.end()) {
work = &*it;
workQueue.erase(it);
} else {
{
//TODO: thread usercontext scheduler/bottom hard guard
cctx.GetCurrentThread()->Reschedule(KThread::SchedulingStatus::Paused);
}
cctx.GetScheduler()->ForceContextSwitch();
}
} while (work == nullptr);
work->DoWork();
}
}
}