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)
|
ENTRY(_start)
|
||||||
|
|
||||||
/* Mostly copied from https://github.com/devkitPro/buildscripts/blob/master/dkarm-eabi/crtls/3dsx.ld */
|
/* 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
|
SECTIONS
|
||||||
{
|
{
|
||||||
|
@ -30,7 +36,7 @@ SECTIONS
|
||||||
/* .fini */
|
/* .fini */
|
||||||
KEEP( *(.fini) )
|
KEEP( *(.fini) )
|
||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
}
|
} >main
|
||||||
|
|
||||||
.rodata :
|
.rodata :
|
||||||
{
|
{
|
||||||
|
@ -41,14 +47,14 @@ SECTIONS
|
||||||
*(.gnu.linkonce.r*)
|
*(.gnu.linkonce.r*)
|
||||||
SORT(CONSTRUCTORS)
|
SORT(CONSTRUCTORS)
|
||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
}
|
} >main
|
||||||
|
|
||||||
.preinit_array ALIGN(4) :
|
.preinit_array ALIGN(4) :
|
||||||
{
|
{
|
||||||
PROVIDE (__preinit_array_start = .);
|
PROVIDE (__preinit_array_start = .);
|
||||||
KEEP (*(.preinit_array))
|
KEEP (*(.preinit_array))
|
||||||
PROVIDE (__preinit_array_end = .);
|
PROVIDE (__preinit_array_end = .);
|
||||||
}
|
} >main
|
||||||
|
|
||||||
.init_array ALIGN(4) :
|
.init_array ALIGN(4) :
|
||||||
{
|
{
|
||||||
|
@ -56,7 +62,7 @@ SECTIONS
|
||||||
KEEP (*(SORT(.init_array.*)))
|
KEEP (*(SORT(.init_array.*)))
|
||||||
KEEP (*(.init_array))
|
KEEP (*(.init_array))
|
||||||
PROVIDE (__init_array_end = .);
|
PROVIDE (__init_array_end = .);
|
||||||
}
|
} >main
|
||||||
|
|
||||||
.fini_array ALIGN(4) :
|
.fini_array ALIGN(4) :
|
||||||
{
|
{
|
||||||
|
@ -64,7 +70,7 @@ SECTIONS
|
||||||
KEEP (*(.fini_array))
|
KEEP (*(.fini_array))
|
||||||
KEEP (*(SORT(.fini_array.*)))
|
KEEP (*(SORT(.fini_array.*)))
|
||||||
PROVIDE (__fini_array_end = .);
|
PROVIDE (__fini_array_end = .);
|
||||||
}
|
} >main
|
||||||
|
|
||||||
.ctors ALIGN(4) :
|
.ctors ALIGN(4) :
|
||||||
{
|
{
|
||||||
|
@ -72,7 +78,7 @@ SECTIONS
|
||||||
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
|
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
|
||||||
KEEP (*(SORT(.ctors.*)))
|
KEEP (*(SORT(.ctors.*)))
|
||||||
KEEP (*(.ctors))
|
KEEP (*(.ctors))
|
||||||
}
|
} >main
|
||||||
|
|
||||||
.dtors ALIGN(4) :
|
.dtors ALIGN(4) :
|
||||||
{
|
{
|
||||||
|
@ -80,11 +86,11 @@ SECTIONS
|
||||||
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
|
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
|
||||||
KEEP (*(SORT(.dtors.*)))
|
KEEP (*(SORT(.dtors.*)))
|
||||||
KEEP (*(.dtors))
|
KEEP (*(.dtors))
|
||||||
}
|
} >main
|
||||||
|
|
||||||
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) }
|
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >main
|
||||||
__exidx_start = .;
|
__exidx_start = .;
|
||||||
ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) }
|
ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } >main
|
||||||
__exidx_end = .;
|
__exidx_end = .;
|
||||||
|
|
||||||
.data :
|
.data :
|
||||||
|
@ -94,19 +100,31 @@ SECTIONS
|
||||||
*(.gnu.linkonce.d*)
|
*(.gnu.linkonce.d*)
|
||||||
CONSTRUCTORS
|
CONSTRUCTORS
|
||||||
. = ALIGN(4);
|
. = 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 :
|
||||||
{
|
{
|
||||||
|
__bss_start__ = ALIGN(32);
|
||||||
*(.dynbss)
|
*(.dynbss)
|
||||||
*(.bss)
|
*(.bss)
|
||||||
*(.bss.*)
|
*(.bss.*)
|
||||||
*(.gnu.linkonce.b*)
|
*(.gnu.linkonce.b*)
|
||||||
*(COMMON)
|
*(COMMON)
|
||||||
. = ALIGN(8);
|
. = ALIGN(8);
|
||||||
}
|
__bss_end__ = .;
|
||||||
__bss_end__ = .;
|
} >main
|
||||||
__end__ = ABSOLUTE(.) ;
|
__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
|
mov r\@, #0
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
.section .text.start
|
.section .text.start, "ax", %progbits
|
||||||
.arm
|
.arm
|
||||||
.align 5
|
.align 5
|
||||||
.global _start
|
.global _start
|
||||||
|
.type _start, %function
|
||||||
_start:
|
_start:
|
||||||
/* Insert NOPs for convenience (i.e. to use Nintendo's BCTs, for example) */
|
/* Insert NOPs for convenience (i.e. to use Nintendo's BCTs, for example) */
|
||||||
.rept 16
|
.rept 16
|
||||||
|
@ -57,3 +58,12 @@ _start:
|
||||||
ldmfd sp!, {r0, r1}
|
ldmfd sp!, {r0, r1}
|
||||||
bl main
|
bl main
|
||||||
b .
|
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