kern: Implement KAutoObject, KSlabHeap, KLightLock

This commit is contained in:
Michael Scire 2020-01-29 22:06:25 -08:00
parent bb4ade30e4
commit 2faf3d33b5
16 changed files with 923 additions and 5 deletions

View file

@ -0,0 +1,25 @@
/*
* 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 {
KAutoObject *KAutoObject::Create(KAutoObject *obj) {
obj->ref_count = 1;
return obj;
}
}

View file

@ -0,0 +1,51 @@
/*
* 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 {
Result KAutoObjectWithListContainer::Register(KAutoObjectWithList *obj) {
KScopedLightLock lk(this->lock);
this->object_list.insert(*obj);
return ResultSuccess();
}
Result KAutoObjectWithListContainer::Unregister(KAutoObjectWithList *obj) {
KScopedLightLock lk(this->lock);
this->object_list.erase(this->object_list.iterator_to(*obj));
return ams::svc::ResultNotFound();
}
size_t KAutoObjectWithListContainer::GetOwnedCount(KProcess *owner) {
KScopedLightLock lk(this->lock);
size_t count = 0;
for (auto &obj : this->object_list) {
if (obj.GetOwner() == owner) {
count++;
}
}
return count;
}
}

View file

@ -0,0 +1,28 @@
/*
* 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 KLightLock::LockSlowPath(uintptr_t owner, uintptr_t cur_thread) {
/* TODO: Implement (requires KThread, KScheduler) */
}
void KLightLock::UnlockSlowPath(uintptr_t cur_thread) {
/* TODO: Implement (requires KThread, KScheduler) */
}
}

View file

@ -17,7 +17,7 @@
namespace ams::kern {
NOINLINE void Kernel::Initialize(s32 core_id) {
void Kernel::Initialize(s32 core_id) {
/* Construct the core local region object in place. */
KCoreLocalContext *clc = GetPointer<KCoreLocalContext>(KMemoryLayout::GetCoreLocalRegionAddress());
new (clc) KCoreLocalContext;
@ -46,4 +46,9 @@ namespace ams::kern {
}
}
void Kernel::InitializeCoreThreads(s32 core_id) {
/* TODO: This function wants to setup the main thread and the idle thread. */
/* It also wants to initialize the scheduler/interrupt manager/hardware timer. */
}
}

View file

@ -25,6 +25,15 @@ namespace ams::kern {
/* Ensure that all cores get to this point before proceeding. */
cpu::SynchronizeAllCores();
/* Initialize the main and idle thread for each core. */
/* Synchronize after each init to ensure the cores go in order. */
for (size_t i = 0; i < cpu::NumCores; i++) {
if (static_cast<s32>(i) == core_id) {
Kernel::InitializeCoreThreads(core_id);
}
cpu::SynchronizeAllCores();
}
/* TODO: Implement more of Main() */
while (true) { /* ... */ }
}