kern: skeleton enough types to init KCoreLocalRegion in main()

This commit is contained in:
Michael Scire 2020-01-29 14:26:24 -08:00
parent ad0d2faa6c
commit 981bb1f15d
24 changed files with 1066 additions and 33 deletions

View file

@ -0,0 +1,24 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mesosphere.hpp>
namespace ams::kern::arm64 {
void KHardwareTimer::DoTask() {
/* TODO: Actually implement this. */
}
}

View file

@ -0,0 +1,40 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mesosphere.hpp>
namespace ams::kern {
void KInterruptTaskManager::TaskQueue::Enqueue(KInterruptTask *task) {
/* Insert the task into the queue. */
if (this->tail != nullptr) {
this->tail->SetNextTask(task);
} else {
this->head = task;
}
this->tail = task;
}
void KInterruptTaskManager::TaskQueue::Dequeue() {
if (this->head == this->tail) {
this->head = nullptr;
this->tail = nullptr;
} else {
this->head = this->head->GetNextTask();
}
}
}

View file

@ -17,20 +17,15 @@
namespace ams::kern {
WEAK_SYMBOL KScopedInterruptDisable::KScopedInterruptDisable() {
/* TODO: Disable interrupts. */
}
WEAK_SYMBOL KScopedInterruptDisable::~KScopedInterruptDisable() {
/* TODO: un-disable interrupts. */
}
WEAK_SYMBOL KScopedInterruptEnable::KScopedInterruptEnable() {
/* TODO: Enable interrupts. */
}
WEAK_SYMBOL KScopedInterruptEnable::~KScopedInterruptEnable() {
/* TODO: un-enable interrupts. */
KScheduler::KScheduler()
: is_active(false), core_id(0), prev_thread(nullptr), last_context_switch_time(0), idle_thread(nullptr)
{
this->state.needs_scheduling = true;
this->state.interrupt_task_thread_runnable = false;
this->state.should_count_idle = false;
this->state.idle_count = 0;
this->state.idle_thread_stack = nullptr;
this->state.highest_priority_thread = nullptr;
}
}

View file

@ -0,0 +1,49 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mesosphere.hpp>
namespace ams::kern {
NOINLINE void Kernel::Initialize(s32 core_id) {
/* Construct the core local region object in place. */
KCoreLocalContext *clc = GetPointer<KCoreLocalContext>(KMemoryLayout::GetCoreLocalRegionAddress());
new (clc) KCoreLocalContext;
/* Set the core local region address into the global register. */
cpu::SetCoreLocalRegionAddress(reinterpret_cast<uintptr_t>(clc));
/* Initialize current context. */
clc->current.current_thread = nullptr;
clc->current.current_process = nullptr;
clc->current.scheduler = std::addressof(clc->scheduler);
clc->current.interrupt_task_manager = std::addressof(clc->interrupt_task_manager);
clc->current.core_id = core_id;
clc->current.exception_stack_bottom = GetVoidPointer(KMemoryLayout::GetExceptionStackBottomAddress(core_id));
/* Clear debugging counters. */
clc->num_sw_interrupts = 0;
clc->num_hw_interrupts = 0;
clc->num_svc = 0;
clc->num_process_switches = 0;
clc->num_thread_switches = 0;
clc->num_fpu_switches = 0;
for (size_t i = 0; i < util::size(clc->perf_counters); i++) {
clc->perf_counters[i] = 0;
}
}
}

View file

@ -18,7 +18,14 @@
namespace ams::kern {
NORETURN void HorizonKernelMain(s32 core_id) {
/* Setup the Core Local Region, and note that we're initializing. */
Kernel::Initialize(core_id);
Kernel::SetState(Kernel::State::Initializing);
/* Ensure that all cores get to this point before proceeding. */
cpu::SynchronizeAllCores();
/* TODO: Implement more of Main() */
while (true) { /* ... */ }
}