nintendoswitch: Add experimental Nintendo Switch support without CRT

Bare minimal nintendo switch support using LLD
This commit is contained in:
Lucas Teske
2020-05-09 15:39:19 -03:00
committed by Ayke
parent d4e04e4e49
commit 3650c2c739
19 changed files with 401 additions and 4 deletions
+28
View File
@@ -0,0 +1,28 @@
{
"llvm-target": "aarch64",
"build-tags": ["nintendoswitch", "arm64"],
"goos": "linux",
"goarch": "arm64",
"compiler": "clang",
"linker": "ld.lld",
"rtlib": "compiler-rt",
"libc": "picolibc",
"gc": "conservative",
"relocation-model": "pic",
"cflags": [
"-target", "aarch64-none-linux-gnu",
"-mtune=cortex-a57",
"-fPIE",
"-Werror",
"-Qunused-arguments",
"-fshort-enums",
"-fomit-frame-pointer",
"-fno-exceptions", "-fno-unwind-tables",
"-ffunction-sections", "-fdata-sections"
],
"linkerscript": "targets/nintendoswitch.ld",
"extra-files": [
"targets/nintendoswitch.s",
"src/runtime/runtime_nintendoswitch.s"
]
}
+61
View File
@@ -0,0 +1,61 @@
OUTPUT_FORMAT(elf64-littleaarch64)
OUTPUT_ARCH(aarch64)
ENTRY(_start)
PHDRS
{
text PT_LOAD FLAGS(5);
rodata PT_LOAD FLAGS(4);
data PT_LOAD FLAGS(6);
bss PT_LOAD FLAGS(6);
dynamic PT_DYNAMIC;
}
SECTIONS
{
. = 0;
.text : ALIGN(0x1000) {
HIDDEN(__text_start = .);
KEEP(*(.text.jmp))
. = 0x80;
*(.text .text.*)
}
/* Read-only sections */
. = ALIGN(0x1000);
.rodata : { *(.rodata .rodata.*) } :rodata
.mod0 : {
KEEP(crt0.nso.o(.data.mod0))
KEEP(crt0.nro.o(.data.mod0))
KEEP(crt0.lib.nro.o(.data.mod0))
}
/* Read-write sections */
. = ALIGN(0x1000);
.data : {
*(.data .data.*)
} :data
.dynamic : {
HIDDEN(__dynamic_start = .);
*(.dynamic)
}
/* BSS section */
. = ALIGN(0x1000);
.bss : {
HIDDEN(__bss_start = .);
*(.bss .bss.*)
*(COMMON)
. = ALIGN(8);
HIDDEN(__bss_end = .);
} :bss
}
+51
View File
@@ -0,0 +1,51 @@
.section .text.jmp, "x"
.global _start
_start:
b start
.word _mod_header - _start
.section .data.mod0
.word 0, 8
.global _mod_header
_mod_header:
.ascii "MOD0"
.word __dynamic_start - _mod_header
.word __bss_start - _mod_header
.word __bss_end - _mod_header
.word 0, 0 // eh_frame_hdr start/end
.word 0 // runtime-generated module object offset
.section .text, "x"
.global start
start:
// save lr
mov x7, x30
// get aslr base
bl +4
sub x6, x30, #0x88
// context ptr and main thread handle
mov x5, x0
mov x4, x1
// clear .bss
adrp x5, __bss_start
add x5, x5, #:lo12:__bss_start
adrp x6, __bss_end
add x6, x6, #:lo12:__bss_end
bssloop:
cmp x5, x6
b.eq run
str xzr, [x5]
add x5, x5, 8
b bssloop
run:
// call entrypoint
adrp x30, exit
add x30, x30, #:lo12:exit
b main