ams: support building unit test programs on windows/linux/macos

This commit is contained in:
Michael Scire
2022-03-06 12:08:20 -08:00
committed by SciresM
parent 9a38be201a
commit 64a97576d0
756 changed files with 33359 additions and 9372 deletions

View File

@@ -15,7 +15,7 @@
*/
#define NX_SERVICE_ASSUME_NON_DOMAIN
#include "../service_guard.h"
#include "ams_bpc.h"
#include "ams_bpc.os.horizon.h"
static Service g_amsBpcSrv;

View File

@@ -58,7 +58,7 @@ namespace ams::emummc {
/* Globals. */
constinit os::SdkMutex g_lock;
constinit ExosphereConfig g_exo_config;
constinit ExosphereConfig g_exo_config = {};
constinit bool g_is_emummc;
constinit bool g_has_cached;
@@ -87,15 +87,23 @@ namespace ams::emummc {
g_is_emummc = g_exo_config.base_cfg.magic == StorageMagic && storage != Storage_Emmc;
/* Format paths. */
if (storage == Storage_SdFile) {
util::SNPrintf(g_exo_config.file_cfg.path, sizeof(g_exo_config.file_cfg.path), "/%s", paths->file_path);
}
{
char tmp_path[MaxDirLen + 1];
util::SNPrintf(g_exo_config.emu_dir_path, sizeof(g_exo_config.emu_dir_path), "/%s", paths->nintendo_path);
/* Format paths. */
if (storage == Storage_SdFile) {
util::TSNPrintf(tmp_path, sizeof(tmp_path), "/%s", paths->file_path);
R_ABORT_UNLESS(fs::PathFormatter::Normalize(g_exo_config.file_cfg.path, sizeof(g_exo_config.file_cfg.path), tmp_path, std::strlen(tmp_path) + 1, fs::PathFlags{}));
}
/* If we're emummc, implement default nintendo redirection path. */
if (g_is_emummc && std::strcmp(g_exo_config.emu_dir_path, "/") == 0) {
util::SNPrintf(g_exo_config.emu_dir_path, sizeof(g_exo_config.emu_dir_path), "/emummc/Nintendo_%04x", g_exo_config.base_cfg.id);
util::TSNPrintf(tmp_path, sizeof(tmp_path), "/%s", paths->nintendo_path);
R_ABORT_UNLESS(fs::PathFormatter::Normalize(g_exo_config.emu_dir_path, sizeof(g_exo_config.emu_dir_path), tmp_path, std::strlen(tmp_path) + 1, fs::PathFlags{}));
/* If we're emummc, implement default nintendo redirection path. */
if (g_is_emummc && std::strcmp(g_exo_config.emu_dir_path, "/") == 0) {
util::TSNPrintf(tmp_path, sizeof(tmp_path), "/emummc/Nintendo_%04x", g_exo_config.base_cfg.id);
R_ABORT_UNLESS(fs::PathFormatter::Normalize(g_exo_config.emu_dir_path, sizeof(g_exo_config.emu_dir_path), tmp_path, std::strlen(tmp_path) + 1, fs::PathFlags{}));
}
}
}

View File

@@ -14,12 +14,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stratosphere.hpp>
#include "ams_bpc.h"
#include "ams_bpc.os.horizon.h"
namespace ams {
namespace {
#if defined(ATMOSPHERE_ARCH_ARM64)
inline u64 GetPc() {
u64 pc;
__asm__ __volatile__ ("adr %[pc], ." : [pc]"=&r"(pc) :: );
@@ -30,6 +31,9 @@ namespace ams {
u64 fp;
u64 lr;
};
#else
#error "Unknown architecture for os Horizon"
#endif
}

View File

@@ -45,6 +45,7 @@ namespace ams {
}
NOINLINE NORETURN void AbortImpl() {
#if defined(ATMOSPHERE_BOARD_NINTENDO_NX)
/* Just perform a data abort. */
register u64 addr __asm__("x27") = FatalErrorContext::StdAbortMagicAddress;
register u64 val __asm__("x28") = FatalErrorContext::StdAbortMagicValue;
@@ -55,6 +56,10 @@ namespace ams {
: [val]"r"(val), [addr]"r"(addr)
);
}
#else
/* What should be done here? */
AMS_INFINITE_LOOP();
#endif
__builtin_unreachable();
}

View File

@@ -0,0 +1,59 @@
/*
* Copyright (c) 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 <stratosphere.hpp>
namespace ams {
namespace os {
void Initialize();
}
void *Malloc(size_t size) {
return std::malloc(size);
}
void Free(void *ptr) {
return std::free(ptr);
}
void *MallocForRapidJson(size_t size) {
return std::malloc(size);
}
void *ReallocForRapidJson(void *ptr, size_t size) {
return std::realloc(ptr, size);
}
void FreeForRapidJson(void *ptr) {
return std::free(ptr);
}
NORETURN void AbortImpl() {
std::abort();
}
}
extern "C" {
/* Redefine C++ exception handlers. Requires wrap linker flag. */
#define WRAP_ABORT_FUNC(func) void NORETURN __wrap_##func(void) { std::abort(); __builtin_unreachable(); }
WRAP_ABORT_FUNC(__cxa_pure_virtual)
#undef WRAP_ABORT_FUNC
}

View File

@@ -0,0 +1,59 @@
/*
* Copyright (c) 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 <stratosphere.hpp>
namespace ams {
namespace os {
void Initialize();
}
void *Malloc(size_t size) {
return std::malloc(size);
}
void Free(void *ptr) {
return std::free(ptr);
}
void *MallocForRapidJson(size_t size) {
return std::malloc(size);
}
void *ReallocForRapidJson(void *ptr, size_t size) {
return std::realloc(ptr, size);
}
void FreeForRapidJson(void *ptr) {
return std::free(ptr);
}
NORETURN void AbortImpl() {
std::abort();
}
}
extern "C" {
/* Redefine C++ exception handlers. Requires wrap linker flag. */
#define WRAP_ABORT_FUNC(func) void NORETURN __wrap_##func(void) { std::abort(); __builtin_unreachable(); }
WRAP_ABORT_FUNC(__cxa_pure_virtual)
#undef WRAP_ABORT_FUNC
}

View File

@@ -0,0 +1,68 @@
/*
* Copyright (c) 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 <stratosphere.hpp>
extern "C" char **__real___p__acmdln(void);
namespace ams {
namespace os {
void Initialize();
}
void *Malloc(size_t size) {
return std::malloc(size);
}
void Free(void *ptr) {
return std::free(ptr);
}
void *MallocForRapidJson(size_t size) {
return std::malloc(size);
}
void *ReallocForRapidJson(void *ptr, size_t size) {
return std::realloc(ptr, size);
}
void FreeForRapidJson(void *ptr) {
return std::free(ptr);
}
NORETURN void AbortImpl() {
std::abort();
}
}
extern "C" {
/* Redefine C++ exception handlers. Requires wrap linker flag. */
#define WRAP_ABORT_FUNC(func) void NORETURN __wrap_##func(void) { std::abort(); __builtin_unreachable(); }
WRAP_ABORT_FUNC(__cxa_pure_virtual)
#undef WRAP_ABORT_FUNC
/* On windows, mingw may attempt to call malloc before we've initialized globals to set up the command line. */
/* We perform some critical init here, to make that work. */
char **__wrap___p__acmdln(void) {
::ams::os::Initialize();
return __real___p__acmdln();
}
}

View File

@@ -26,6 +26,7 @@ namespace ams::exosphere {
return ApiInfo{ util::BitPack64{exosphere_cfg} };
}
#if defined(ATMOSPHERE_BOARD_NINTENDO_NX)
void ForceRebootToRcm() {
R_ABORT_UNLESS(spl::impl::SetConfig(spl::ConfigItem::ExosphereNeedsReboot, 1));
}
@@ -81,5 +82,6 @@ namespace ams::exosphere {
R_ABORT_UNLESS(spl::impl::GetConfig(std::addressof(device_id), spl::ConfigItem::DeviceId));
return device_id;
}
#endif
}