ams: support building unit test programs on windows/linux/macos
This commit is contained in:
@@ -14,12 +14,14 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "impl/diag_print_debug_string.hpp"
|
||||
|
||||
namespace ams::diag {
|
||||
|
||||
namespace {
|
||||
|
||||
inline NORETURN void AbortWithValue(u64 debug) {
|
||||
#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;
|
||||
@@ -32,6 +34,10 @@ namespace ams::diag {
|
||||
: "x0"
|
||||
);
|
||||
}
|
||||
#else
|
||||
AMS_UNUSED(debug);
|
||||
std::abort();
|
||||
#endif
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
@@ -46,7 +52,7 @@ namespace ams::diag {
|
||||
|
||||
util::VSNPrintf(g_debug_buffer, sizeof(g_debug_buffer), format, vl);
|
||||
|
||||
svc::OutputDebugString(g_debug_buffer, strlen(g_debug_buffer));
|
||||
diag::impl::PrintDebugString(g_debug_buffer, strlen(g_debug_buffer));
|
||||
}
|
||||
|
||||
void DebugLog(const char *format, ...) {
|
||||
@@ -62,8 +68,12 @@ namespace ams::diag {
|
||||
|
||||
}
|
||||
|
||||
NORETURN WEAK_SYMBOL void AssertionFailureImpl(const char *file, int line, const char *func, const char *expr, u64 value, const char *format, ...) {
|
||||
DebugLog("%016lx: Assertion Failure\n", os::GetCurrentProgramId().value);
|
||||
NORETURN NOINLINE WEAK_SYMBOL void AssertionFailureImpl(const char *file, int line, const char *func, const char *expr, u64 value, const char *format, ...) {
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
DebugLog("%016" PRIx64 ": Assertion Failure\n", os::GetCurrentProgramId().value);
|
||||
#else
|
||||
DebugLog("0100000000000000: Assertion Failure\n");
|
||||
#endif
|
||||
DebugLog(" Location: %s:%d\n", file, line);
|
||||
DebugLog(" Function: %s\n", func);
|
||||
DebugLog(" Expression: %s\n", expr);
|
||||
@@ -84,8 +94,12 @@ namespace ams::diag {
|
||||
AbortWithValue(value);
|
||||
}
|
||||
|
||||
NORETURN WEAK_SYMBOL void AssertionFailureImpl(const char *file, int line, const char *func, const char *expr, u64 value) {
|
||||
DebugLog("%016lx: Assertion Failure\n", os::GetCurrentProgramId().value);
|
||||
NORETURN NOINLINE WEAK_SYMBOL void AssertionFailureImpl(const char *file, int line, const char *func, const char *expr, u64 value) {
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
DebugLog("%016" PRIx64 ": Assertion Failure\n", os::GetCurrentProgramId().value);
|
||||
#else
|
||||
DebugLog("0100000000000000: Assertion Failure\n");
|
||||
#endif
|
||||
DebugLog(" Location: %s:%d\n", file, line);
|
||||
DebugLog(" Function: %s\n", func);
|
||||
DebugLog(" Expression: %s\n", expr);
|
||||
@@ -96,8 +110,12 @@ namespace ams::diag {
|
||||
AbortWithValue(value);
|
||||
}
|
||||
|
||||
NORETURN WEAK_SYMBOL void AbortImpl(const char *file, int line, const char *func, const char *expr, u64 value, const char *format, ...) {
|
||||
DebugLog("%016lx: Abort Called\n", os::GetCurrentProgramId().value);
|
||||
NORETURN NOINLINE WEAK_SYMBOL void AbortImpl(const char *file, int line, const char *func, const char *expr, u64 value, const char *format, ...) {
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
DebugLog("%016" PRIx64 ": Abort Called\n", os::GetCurrentProgramId().value);
|
||||
#else
|
||||
DebugLog("0100000000000000: Abort Called\n");
|
||||
#endif
|
||||
DebugLog(" Location: %s:%d\n", file, line);
|
||||
DebugLog(" Function: %s\n", func);
|
||||
DebugLog(" Expression: %s\n", expr);
|
||||
@@ -118,8 +136,12 @@ namespace ams::diag {
|
||||
AbortWithValue(value);
|
||||
}
|
||||
|
||||
NORETURN WEAK_SYMBOL void AbortImpl(const char *file, int line, const char *func, const char *expr, u64 value) {
|
||||
DebugLog("%016lx: Abort Called\n", os::GetCurrentProgramId().value);
|
||||
NORETURN NOINLINE WEAK_SYMBOL void AbortImpl(const char *file, int line, const char *func, const char *expr, u64 value) {
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
DebugLog("%016" PRIx64 ": Abort Called\n", os::GetCurrentProgramId().value);
|
||||
#else
|
||||
DebugLog("0100000000000000: Abort Called\n");
|
||||
#endif
|
||||
DebugLog(" Location: %s:%d\n", file, line);
|
||||
DebugLog(" Function: %s\n", func);
|
||||
DebugLog(" Expression: %s\n", expr);
|
||||
@@ -130,7 +152,7 @@ namespace ams::diag {
|
||||
AbortWithValue(value);
|
||||
}
|
||||
|
||||
NORETURN WEAK_SYMBOL void AbortImpl() {
|
||||
NORETURN NOINLINE WEAK_SYMBOL void AbortImpl() {
|
||||
AbortWithValue(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* ams::diag::impl::FatalErrorByResultForNx(Result value) */
|
||||
.section .text._ZN3ams4diag4impl23FatalErrorByResultForNxENS_6ResultE, "ax", %progbits
|
||||
.global _ZN3ams4diag4impl23FatalErrorByResultForNxENS_6ResultE
|
||||
.type _ZN3ams4diag4impl23FatalErrorByResultForNxENS_6ResultE, %function
|
||||
.balign 0x10
|
||||
_ZN3ams4diag4impl23FatalErrorByResultForNxENS_6ResultE:
|
||||
/* Save x27/x28. */
|
||||
stp x27, x28, [sp, #0x10]
|
||||
|
||||
/* Put magic std::abort values into x27/x28. */
|
||||
mov x28, #0xcafe
|
||||
movk x28, #0xdead, lsl#16
|
||||
movk x28, #0xf00d, lsl#32
|
||||
movk x28, #0xa55a, lsl#48
|
||||
mov x27, #8
|
||||
|
||||
/* Abort */
|
||||
0:
|
||||
str x28, [x27]
|
||||
nop
|
||||
b 0b
|
||||
@@ -19,6 +19,11 @@
|
||||
namespace ams::diag::impl {
|
||||
|
||||
void PrintDebugString(const char *msg, size_t size);
|
||||
void PrintDebugString(const char *msg);
|
||||
|
||||
inline void PrintDebugString(const char *msg) {
|
||||
AMS_AUDIT(msg != nullptr);
|
||||
|
||||
PrintDebugString(msg, std::strlen(msg));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,10 +26,4 @@ namespace ams::diag::impl {
|
||||
}
|
||||
}
|
||||
|
||||
void PrintDebugString(const char *msg) {
|
||||
AMS_AUDIT(msg != nullptr);
|
||||
|
||||
PrintDebugString(msg, std::strlen(msg));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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>
|
||||
#include "diag_print_debug_string.hpp"
|
||||
|
||||
namespace ams::diag::impl {
|
||||
|
||||
NOINLINE void PrintDebugString(const char *msg, size_t size) {
|
||||
AMS_AUDIT(msg != nullptr || size == 0);
|
||||
|
||||
if (size == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* TODO: Printf? */
|
||||
printf("%s", msg);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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>
|
||||
#include "diag_print_debug_string.hpp"
|
||||
|
||||
namespace ams::diag::impl {
|
||||
|
||||
NOINLINE void PrintDebugString(const char *msg, size_t size) {
|
||||
AMS_AUDIT(msg != nullptr || size == 0);
|
||||
|
||||
if (size == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* TODO: Printf? */
|
||||
printf("%s", msg);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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>
|
||||
#include "diag_print_debug_string.hpp"
|
||||
|
||||
namespace ams::diag::impl {
|
||||
|
||||
NOINLINE void PrintDebugString(const char *msg, size_t size) {
|
||||
AMS_AUDIT(msg != nullptr || size == 0);
|
||||
|
||||
if (size == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* TODO: OutputDebugString? Printf? */
|
||||
printf("%s", msg);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user