mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-05 19:51:45 +00:00
Add chainloader (stage2) (need to edit more files)
This commit is contained in:
parent
2c07b5a2fb
commit
75dfcd07a9
4 changed files with 67 additions and 14 deletions
|
@ -3,6 +3,12 @@ OUTPUT_ARCH(arm)
|
|||
ENTRY(_start)
|
||||
|
||||
/* Mostly copied from https://github.com/devkitPro/buildscripts/blob/master/dkarm-eabi/crtls/3dsx.ld */
|
||||
MEMORY
|
||||
{
|
||||
NULL : ORIGIN = 0x00000000, LENGTH = 0x1000
|
||||
main : ORIGIN = 0xFFF00000, LENGTH = 0x00100000
|
||||
low_iram : ORIGIN = 0x40003000, LENGTH = 0x4000
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
|
@ -30,7 +36,7 @@ SECTIONS
|
|||
/* .fini */
|
||||
KEEP( *(.fini) )
|
||||
. = ALIGN(4);
|
||||
}
|
||||
} >main
|
||||
|
||||
.rodata :
|
||||
{
|
||||
|
@ -41,14 +47,14 @@ SECTIONS
|
|||
*(.gnu.linkonce.r*)
|
||||
SORT(CONSTRUCTORS)
|
||||
. = ALIGN(4);
|
||||
}
|
||||
} >main
|
||||
|
||||
.preinit_array ALIGN(4) :
|
||||
{
|
||||
PROVIDE (__preinit_array_start = .);
|
||||
KEEP (*(.preinit_array))
|
||||
PROVIDE (__preinit_array_end = .);
|
||||
}
|
||||
} >main
|
||||
|
||||
.init_array ALIGN(4) :
|
||||
{
|
||||
|
@ -56,7 +62,7 @@ SECTIONS
|
|||
KEEP (*(SORT(.init_array.*)))
|
||||
KEEP (*(.init_array))
|
||||
PROVIDE (__init_array_end = .);
|
||||
}
|
||||
} >main
|
||||
|
||||
.fini_array ALIGN(4) :
|
||||
{
|
||||
|
@ -64,7 +70,7 @@ SECTIONS
|
|||
KEEP (*(.fini_array))
|
||||
KEEP (*(SORT(.fini_array.*)))
|
||||
PROVIDE (__fini_array_end = .);
|
||||
}
|
||||
} >main
|
||||
|
||||
.ctors ALIGN(4) :
|
||||
{
|
||||
|
@ -72,7 +78,7 @@ SECTIONS
|
|||
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
|
||||
KEEP (*(SORT(.ctors.*)))
|
||||
KEEP (*(.ctors))
|
||||
}
|
||||
} >main
|
||||
|
||||
.dtors ALIGN(4) :
|
||||
{
|
||||
|
@ -80,11 +86,11 @@ SECTIONS
|
|||
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
|
||||
KEEP (*(SORT(.dtors.*)))
|
||||
KEEP (*(.dtors))
|
||||
}
|
||||
} >main
|
||||
|
||||
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) }
|
||||
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >main
|
||||
__exidx_start = .;
|
||||
ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) }
|
||||
ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } >main
|
||||
__exidx_end = .;
|
||||
|
||||
.data :
|
||||
|
@ -94,19 +100,31 @@ SECTIONS
|
|||
*(.gnu.linkonce.d*)
|
||||
CONSTRUCTORS
|
||||
. = ALIGN(4);
|
||||
}
|
||||
} >main
|
||||
|
||||
.chainloader :
|
||||
{
|
||||
. = ALIGN(32);
|
||||
KEEP(*(.chainloader.text.start))
|
||||
build/chainloader.o(.text*)
|
||||
build/chainloader.o(.rodata*)
|
||||
build/chainloader.o(.data*)
|
||||
. = ALIGN(8);
|
||||
build/chainloader.o(.bss*)
|
||||
. = ALIGN(32);
|
||||
} >low_iram
|
||||
|
||||
__bss_start__ = ALIGN(32);
|
||||
.bss :
|
||||
{
|
||||
__bss_start__ = ALIGN(32);
|
||||
*(.dynbss)
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
*(.gnu.linkonce.b*)
|
||||
*(COMMON)
|
||||
. = ALIGN(8);
|
||||
}
|
||||
__bss_end__ = .;
|
||||
__bss_end__ = .;
|
||||
} >main
|
||||
__end__ = ABSOLUTE(.) ;
|
||||
|
||||
/* ==================
|
||||
|
|
12
fusee/fusee-secondary/src/chainloader.c
Normal file
12
fusee/fusee-secondary/src/chainloader.c
Normal file
|
@ -0,0 +1,12 @@
|
|||
#include "chainloader.h"
|
||||
|
||||
uint8_t g_payload_arg_data[PAYLOAD_ARG_DATA_MAX_SIZE] = {1};
|
||||
|
||||
#pragma GCC optimize (3)
|
||||
void relocate_and_chainload_main(uintptr_t load_address, uintptr_t src_address, size_t size, int argc) {
|
||||
for(size_t i = 0; i < size; i++) {
|
||||
*(uint8_t *)(load_address + i) = *(uint8_t *)(src_address + i);
|
||||
}
|
||||
|
||||
((void (*)(int, void *))load_address)(argc, g_payload_arg_data);
|
||||
}
|
13
fusee/fusee-secondary/src/chainloader.h
Normal file
13
fusee/fusee-secondary/src/chainloader.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#ifndef FUSEE_CHAINLOADER_H
|
||||
#define FUSEE_CHAINLOADER_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define PAYLOAD_ARG_DATA_MAX_SIZE 0x1000
|
||||
|
||||
extern uint8_t g_payload_arg_data[PAYLOAD_ARG_DATA_MAX_SIZE];
|
||||
|
||||
void relocate_and_chainload(uintptr_t load_address, uintptr_t src_address, size_t size, int argc);
|
||||
|
||||
#endif
|
|
@ -2,10 +2,11 @@
|
|||
mov r\@, #0
|
||||
.endm
|
||||
|
||||
.section .text.start
|
||||
.section .text.start, "ax", %progbits
|
||||
.arm
|
||||
.align 5
|
||||
.global _start
|
||||
.type _start, %function
|
||||
_start:
|
||||
/* Insert NOPs for convenience (i.e. to use Nintendo's BCTs, for example) */
|
||||
.rept 16
|
||||
|
@ -57,3 +58,12 @@ _start:
|
|||
ldmfd sp!, {r0, r1}
|
||||
bl main
|
||||
b .
|
||||
|
||||
.section .chainloader.text.start, "ax", %progbits
|
||||
.arm
|
||||
.align 5
|
||||
.global relocate_and_chainload
|
||||
.type relocate_and_chainload, %function
|
||||
relocate_and_chainload:
|
||||
ldr sp, =0x40010000
|
||||
b relocate_and_chainload_main
|
||||
|
|
Loading…
Reference in a new issue