2019-10-19 05:06:40 +01:00
|
|
|
/*
|
2021-10-04 20:59:10 +01:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2019-10-19 05:06:40 +01:00
|
|
|
*
|
|
|
|
* 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 <stratosphere.hpp>
|
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
namespace ams {
|
2019-10-19 05:06:40 +01:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
namespace boot2 {
|
2019-10-19 05:06:40 +01:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
namespace {
|
2019-10-19 05:06:40 +01:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
constinit u8 g_fs_heap_memory[2_KB];
|
|
|
|
constinit lmem::HeapHandle g_fs_heap_handle;
|
2021-01-19 01:35:05 +00:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
void *AllocateForFs(size_t size) {
|
|
|
|
return lmem::AllocateFromExpHeap(g_fs_heap_handle, size);
|
|
|
|
}
|
2021-01-19 01:35:05 +00:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
void DeallocateForFs(void *p, size_t size) {
|
|
|
|
AMS_UNUSED(size);
|
|
|
|
return lmem::FreeToExpHeap(g_fs_heap_handle, p);
|
|
|
|
}
|
2021-01-19 01:35:05 +00:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
void InitializeFsHeap() {
|
|
|
|
g_fs_heap_handle = lmem::CreateExpHeap(g_fs_heap_memory, sizeof(g_fs_heap_memory), lmem::CreateOption_None);
|
|
|
|
}
|
2021-01-19 01:35:05 +00:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
}
|
2021-01-19 01:35:05 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
namespace init {
|
2021-01-19 01:35:05 +00:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
void InitializeSystemModule() {
|
|
|
|
/* Initialize heap. */
|
|
|
|
boot2::InitializeFsHeap();
|
2019-10-19 05:06:40 +01:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
/* Initialize our connection to sm. */
|
|
|
|
R_ABORT_UNLESS(sm::Initialize());
|
2021-01-19 01:35:05 +00:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
/* Initialize fs. */
|
|
|
|
fs::InitializeForSystem();
|
|
|
|
fs::SetAllocator(boot2::AllocateForFs, boot2::DeallocateForFs);
|
|
|
|
fs::SetEnabledAutoAbort(false);
|
2021-04-14 07:58:10 +01:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
/* Initialize other services we need. */
|
|
|
|
R_ABORT_UNLESS(pmbmInitialize());
|
|
|
|
R_ABORT_UNLESS(pminfoInitialize());
|
|
|
|
R_ABORT_UNLESS(pmshellInitialize());
|
|
|
|
R_ABORT_UNLESS(setsysInitialize());
|
|
|
|
gpio::Initialize();
|
2019-10-19 05:06:40 +01:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
/* Mount the SD card. */
|
|
|
|
R_ABORT_UNLESS(fs::MountSdCard("sdmc"));
|
2019-10-19 05:06:40 +01:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
/* Verify that we can sanely execute. */
|
|
|
|
ams::CheckApiVersion();
|
|
|
|
}
|
2019-10-19 05:06:40 +01:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
void FinalizeSystemModule() { /* ... */ }
|
2019-10-19 05:06:40 +01:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
void Startup() { /* ... */ }
|
2021-01-19 01:35:05 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
void Main() {
|
|
|
|
/* Set thread name. */
|
|
|
|
os::SetThreadNamePointer(os::GetCurrentThread(), AMS_GET_SYSTEM_THREAD_NAME(boot2, Main));
|
|
|
|
AMS_ASSERT(os::GetThreadPriority(os::GetCurrentThread()) == AMS_GET_SYSTEM_THREAD_PRIORITY(boot2, Main));
|
2021-01-19 01:35:05 +00:00
|
|
|
|
2021-10-08 01:44:54 +01:00
|
|
|
/* Launch all programs off of SYSTEM/the SD. */
|
|
|
|
boot2::LaunchPostSdCardBootPrograms();
|
|
|
|
}
|
2020-05-11 23:02:10 +01:00
|
|
|
|
2019-10-19 05:06:40 +01:00
|
|
|
}
|