fusee-cpp: add basic structural stubs

This commit is contained in:
Michael Scire 2021-08-21 11:10:13 -07:00 committed by SciresM
parent 165c926135
commit 5f60bc7186
21 changed files with 1280 additions and 2 deletions

View file

@ -0,0 +1,32 @@
/*
* 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 <exosphere.hpp>
extern "C" void __libc_init_array();
namespace ams::nxboot::crt0 {
void Initialize(uintptr_t bss_start, uintptr_t bss_end) {
/* TODO: Collect timing information? */
/* Clear bss. */
std::memset(reinterpret_cast<void *>(bss_start), 0, bss_end - bss_start);
/* Call init array. */
__libc_init_array();
}
}

View file

@ -0,0 +1,52 @@
/*
* 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 <exosphere.hpp>
#include "fusee_exception_handler.hpp"
namespace ams::nxboot {
NORETURN void ErrorStop() {
/* Halt ourselves. */
while (true) {
reg::Write(secmon::MemoryRegionPhysicalDeviceFlowController.GetAddress() + FLOW_CTLR_HALT_COP_EVENTS, FLOW_REG_BITS_ENUM(HALT_COP_EVENTS_MODE, FLOW_MODE_STOP),
FLOW_REG_BITS_ENUM(HALT_COP_EVENTS_JTAG, ENABLED));
}
}
NORETURN void ExceptionHandlerImpl(s32 which, u32 lr, u32 svc_lr) {
/* TODO */
ErrorStop();
}
}
namespace ams::diag {
NORETURN void AbortImpl(const char *file, int line, const char *func, const char *expr, u64 value, const char *format, ...) {
AMS_UNUSED(file, line, func, expr, value, format);
ams::nxboot::ErrorStop();
}
NORETURN void AbortImpl(const char *file, int line, const char *func, const char *expr, u64 value) {
AMS_UNUSED(file, line, func, expr, value);
ams::nxboot::ErrorStop();
}
NORETURN void AbortImpl() {
ams::nxboot::ErrorStop();
}
}

View file

@ -0,0 +1,32 @@
/*
* 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 <exosphere.hpp>
#pragma once
namespace ams::nxboot::loader {
NORETURN void ExceptionHandler();
NORETURN void ExceptionHandler0();
NORETURN void ExceptionHandler1();
NORETURN void ExceptionHandler2();
NORETURN void ExceptionHandler3();
NORETURN void ExceptionHandler4();
NORETURN void ExceptionHandler5();
NORETURN void ExceptionHandler6();
NORETURN void ExceptionHandler7();
}

View file

@ -0,0 +1,114 @@
/*
* 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/>.
*/
.section .text._ZN3ams6nxboot17ExceptionHandlerNEl, "ax", %progbits
.arm
.align 5
.global _ZN3ams6nxboot17ExceptionHandlerNEl
.type _ZN3ams6nxboot17ExceptionHandlerNEl, %function
_ZN3ams6nxboot17ExceptionHandlerNEl:
/* Get the normal return address. */
mov r1, lr
/* Get the SVC return address. */
msr cpsr_cf, #0xD3
mov r2, lr
/* Invoke the exception handler in abort mode. */
msr cpsr_cf, #0xD7
b _ZN3ams6nxboot20ExceptionHandlerImplElmm
.section .text._ZN3ams6nxboot16ExceptionHandlerEv, "ax", %progbits
.arm
.align 5
.global _ZN3ams6nxboot16ExceptionHandlerEv
.type _ZN3ams6nxboot16ExceptionHandlerEv, %function
_ZN3ams6nxboot16ExceptionHandlerEv:
mov r0, #-1
b _ZN3ams6nxboot17ExceptionHandlerNEl
.section .text._ZN3ams6nxboot17ExceptionHandler0Ev, "ax", %progbits
.arm
.align 5
.global _ZN3ams6nxboot17ExceptionHandler0Ev
.type _ZN3ams6nxboot17ExceptionHandler0Ev, %function
_ZN3ams6nxboot17ExceptionHandler0Ev:
mov r0, #0
b _ZN3ams6nxboot17ExceptionHandlerNEl
.section .text._ZN3ams6nxboot17ExceptionHandler1Ev, "ax", %progbits
.arm
.align 5
.global _ZN3ams6nxboot17ExceptionHandler1Ev
.type _ZN3ams6nxboot17ExceptionHandler1Ev, %function
_ZN3ams6nxboot17ExceptionHandler1Ev:
mov r0, #1
b _ZN3ams6nxboot17ExceptionHandlerNEl
.section .text._ZN3ams6nxboot17ExceptionHandler2Ev, "ax", %progbits
.arm
.align 5
.global _ZN3ams6nxboot17ExceptionHandler2Ev
.type _ZN3ams6nxboot17ExceptionHandler2Ev, %function
_ZN3ams6nxboot17ExceptionHandler2Ev:
mov r0, #2
b _ZN3ams6nxboot17ExceptionHandlerNEl
.section .text._ZN3ams6nxboot17ExceptionHandler3Ev, "ax", %progbits
.arm
.align 5
.global _ZN3ams6nxboot17ExceptionHandler3Ev
.type _ZN3ams6nxboot17ExceptionHandler3Ev, %function
_ZN3ams6nxboot17ExceptionHandler3Ev:
mov r0, #3
b _ZN3ams6nxboot17ExceptionHandlerNEl
.section .text._ZN3ams6nxboot17ExceptionHandler4Ev, "ax", %progbits
.arm
.align 5
.global _ZN3ams6nxboot17ExceptionHandler4Ev
.type _ZN3ams6nxboot17ExceptionHandler4Ev, %function
_ZN3ams6nxboot17ExceptionHandler4Ev:
mov r0, #4
b _ZN3ams6nxboot17ExceptionHandlerNEl
.section .text._ZN3ams6nxboot17ExceptionHandler5Ev, "ax", %progbits
.arm
.align 5
.global _ZN3ams6nxboot17ExceptionHandler5Ev
.type _ZN3ams6nxboot17ExceptionHandler5Ev, %function
_ZN3ams6nxboot17ExceptionHandler5Ev:
mov r0, #5
b _ZN3ams6nxboot17ExceptionHandlerNEl
.section .text._ZN3ams6nxboot17ExceptionHandler6Ev, "ax", %progbits
.arm
.align 5
.global _ZN3ams6nxboot17ExceptionHandler6Ev
.type _ZN3ams6nxboot17ExceptionHandler6Ev, %function
_ZN3ams6nxboot17ExceptionHandler6Ev:
mov r0, #6
b _ZN3ams6nxboot17ExceptionHandlerNEl
.section .text._ZN3ams6nxboot17ExceptionHandler7Ev, "ax", %progbits
.arm
.align 5
.global _ZN3ams6nxboot17ExceptionHandler7Ev
.type _ZN3ams6nxboot17ExceptionHandler7Ev, %function
_ZN3ams6nxboot17ExceptionHandler7Ev:
mov r0, #7
b _ZN3ams6nxboot17ExceptionHandlerNEl

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 <exosphere.hpp>
namespace ams::nxboot {
void Main() {
/* TODO */
AMS_INFINITE_LOOP();
}
}

View file

@ -0,0 +1,70 @@
/*
* 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/>.
*/
.section .crt0._ZN3ams6nxboot5StartEv, "ax", %progbits
.arm
.align 5
.global _ZN3ams6nxboot5StartEv
.type _ZN3ams6nxboot5StartEv, %function
_ZN3ams6nxboot5StartEv:
/* Setup all registers as = 0. */
msr cpsr_f, #0xC0
mov r0, #0
mov r1, #0
mov r2, #0
mov r3, #0
mov r4, #0
mov r5, #0
mov r6, #0
mov r7, #0
mov r8, #0
mov r9, #0
mov r10, #0
mov r11, #0
mov r12, #0
/* Setup all modes as pointing to our exception handler. */
msr cpsr_cf, #0xDF
ldr sp, =0x40001000
ldr lr, =_ZN3ams6nxboot16ExceptionHandlerEv
msr cpsr_cf, #0xD2
ldr sp, =0x40001000
ldr lr, =_ZN3ams6nxboot16ExceptionHandlerEv
msr cpsr_cf, #0xD1
ldr sp, =0x40001000
ldr lr, =_ZN3ams6nxboot16ExceptionHandlerEv
msr cpsr_cf, #0xD7
ldr sp, =0x40001000
ldr lr, =_ZN3ams6nxboot16ExceptionHandlerEv
msr cpsr_cf, #0xDB
ldr sp, =0x40001000
ldr lr, =_ZN3ams6nxboot16ExceptionHandlerEv
msr cpsr_cf, #0xD3
ldr sp, =0x40001000
ldr lr, =_ZN3ams6nxboot16ExceptionHandlerEv
/* Perform runtime initialization. */
ldr r0, =__bss_start__
ldr r1, =__bss_end__
bl _ZN3ams6nxboot4crt010InitializeEjj
/* Perform nx boot procedure. */
bl _ZN3ams6nxboot4MainEv