1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-17 17:36:44 +00:00

fusee_cpp: tweaks, now completes SecureInitialize on hardware

This commit is contained in:
Michael Scire 2021-08-21 22:20:44 -07:00 committed by SciresM
parent c91f95e8f6
commit f2a1c60218
6 changed files with 24 additions and 41 deletions

View file

@ -26,16 +26,11 @@ namespace ams::nxboot::loader {
constexpr size_t ProgramImageSizeMax = ProgramImageEnd - ProgramImageBase;
void CopyBackwards(void *dst, const void *src, size_t size) {
/* We want to copy 32-bits at a time from destination to source. */
const size_t words = util::DivideUp(size, sizeof(u32));
u8 *dst_8 = static_cast<u8 *>(dst) + size;
const u8 *src_8 = static_cast<const u8 *>(src) + size;
/* Convert to 32-bit pointers. */
u32 *dst_32 = static_cast<u32 *>(dst) + words;
const u32 *src_32 = static_cast<const u32 *>(src) + words;
/* Copy data. */
for (size_t i = 0; i < words; ++i) {
*(--dst_32) = *(--src_32);
for (size_t i = 0; i < size; ++i) {
*(--dst_8) = *(--src_8);
}
}
@ -43,7 +38,7 @@ namespace ams::nxboot::loader {
NORETURN void UncompressAndExecute(const void *program, size_t program_size) {
/* Relocate the compressed binary to a place where we can safely decompress it. */
void *relocated_program = reinterpret_cast<void *>(util::AlignDown(ProgramImageEnd - program_size, sizeof(u32)));
void *relocated_program = reinterpret_cast<void *>(ProgramImageEnd - program_size);
if (relocated_program != program) {
CopyBackwards(relocated_program, program, program_size);
}

View file

@ -87,7 +87,9 @@ namespace ams::nxboot::loader {
}
void Copy(size_t size) {
__builtin_memcpy(this->dst + this->dst_offset, this->src + this->src_offset, size);
for (size_t i = 0; i < size; ++i) {
this->dst[this->dst_offset + i] = this->src[this->src_offset + i];
}
this->dst_offset += size;
this->src_offset += size;
}

View file

@ -11,8 +11,10 @@ SECTIONS
.crt0 :
{
FILL(0x00000000)
KEEP (*(.crt0 .crt0.*))
. = ALIGN(8);
. = ORIGIN(main) + 0xC0 - 1;
BYTE(00);
} >main AT>glob
.text :
@ -22,37 +24,31 @@ SECTIONS
*(.text.startup .text.startup.*)
*(.text.hot .text.hot.*)
*(.text .stub .text.* .gnu.linkonce.t.*)
. = ALIGN(8);
} >main AT>glob
.init :
{
KEEP( *(.init) )
. = ALIGN(8);
} >main AT>glob
.plt :
{
*(.plt)
*(.iplt)
. = ALIGN(8);
} >main AT>glob
.fini :
{
KEEP( *(.fini) )
. = ALIGN(8);
} >main AT>glob
/* =========== RODATA section =========== */
. = ALIGN(8);
__rodata_start = . ;
.rodata :
{
*(.rodata .rodata.* .gnu.linkonce.r.*)
. = ALIGN(8);
} >main AT>glob
.eh_frame_hdr : { __eh_frame_hdr_start = .; *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) __eh_frame_hdr_end = .; } >main AT>glob
@ -63,7 +59,6 @@ SECTIONS
.hash : { *(.hash) } >main AT>glob
/* =========== DATA section =========== */
. = ALIGN(8);
__data_start = . ;
.eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) } >main AT>glob
@ -71,14 +66,14 @@ SECTIONS
.gnu_extab : ONLY_IF_RW { *(.gnu_extab*) } >main AT>glob
.exception_ranges : ONLY_IF_RW { *(.exception_ranges .exception_ranges*) } >main AT>glob
.preinit_array ALIGN(8) :
.preinit_array :
{
PROVIDE (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE (__preinit_array_end = .);
} >main AT>glob
.init_array ALIGN(8) :
.init_array :
{
PROVIDE (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
@ -86,7 +81,7 @@ SECTIONS
PROVIDE (__init_array_end = .);
} >main AT>glob
.fini_array ALIGN(8) :
.fini_array :
{
PROVIDE (__fini_array_start = .);
KEEP (*(.fini_array))
@ -94,7 +89,7 @@ SECTIONS
PROVIDE (__fini_array_end = .);
} >main AT>glob
.ctors ALIGN(8) :
.ctors :
{
KEEP (*crtbegin.o(.ctors)) /* MUST be first -- GCC requires it */
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
@ -102,7 +97,7 @@ SECTIONS
KEEP (*(.ctors))
} >main AT>glob
.dtors ALIGN(8) :
.dtors :
{
KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
@ -117,30 +112,26 @@ SECTIONS
__got_end__ = .;
.data ALIGN(8) :
.data :
{
*(.data .data.* .gnu.linkonce.d.*)
SORT(CONSTRUCTORS)
} >main AT>glob
__bss_start__ = .;
.bss ALIGN(8) :
.main.fill :
{
FILL(0x00000000)
*(.dynbss)
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
. = ALIGN(16);
. = ORIGIN(main) + LENGTH(main) - 1;
BYTE(0x00);
} >main AT>glob
__bss_end__ = .;
__main_end__ = ABSOLUTE(.) ;
.main.fill : {
FILL(0x00000000)
. = ORIGIN(main) + LENGTH(main) - 1;
BYTE(0x00);
} >main AT>glob
/* ==================
==== Metadata ====
================== */

View file

@ -28,7 +28,7 @@ namespace ams::nxboot::crt0 {
}
void Initialize(uintptr_t bss_start, uintptr_t bss_end) {
void Initialize() {
/* TODO: Collect timing information? */
/* Setup exception vectors. */
@ -43,9 +43,6 @@ namespace ams::nxboot::crt0 {
SetExceptionVector(7, reinterpret_cast<uintptr_t>(::ams::nxboot::ExceptionHandler7));
}
/* Clear bss. */
std::memset(reinterpret_cast<void *>(bss_start), 0, bss_end - bss_start);
/* Call init array. */
__libc_init_array();
}

View file

@ -62,9 +62,7 @@ _ZN3ams6nxboot5StartEv:
ldr lr, =_ZN3ams6nxboot16ExceptionHandlerEv
/* Perform runtime initialization. */
ldr r0, =__bss_start__
ldr r1, =__bss_end__
bl _ZN3ams6nxboot4crt010InitializeEjj
bl _ZN3ams6nxboot4crt010InitializeEv
/* Perform nx boot procedure. */
bl _ZN3ams6nxboot4MainEv

View file

@ -1,5 +1,5 @@
export ATMOSPHERE_DEFINES += -DATMOSPHERE_CPU_ARM7TDMI
export ATMOSPHERE_SETTINGS += -march=armv4t -mtune=arm7tdmi -mthumb -mthumb-interwork
export ATMOSPHERE_SETTINGS += -march=armv4t -mtune=arm7tdmi -mthumb -mthumb-interwork -fstrict-volatile-bitfields
export ATMOSPHERE_CFLAGS +=
export ATMOSPHERE_CXXFLAGS +=
export ATMOSPHERE_ASFLAGS +=