nintendoswitch: support outputting .nro files directly

By modifying the linker script a bit and adding the NRO0 header directly
in the assembly, it's possible to craft an ELF file that can be
converted straight to a binary (using objcopy or similar) that is a NRO
file. This avoids custom code for NRO files or an extra build step.

With another change, .nro files are recognized by TinyGo so that this
will create a ready-to-run NRO file:

    tinygo build -o test.nro -target=nintendoswitch examples/serial
This commit is contained in:
Ayke van Laethem
2020-09-08 22:44:05 +02:00
committed by Ron Evans
parent 81e325205f
commit 9e599bac49
4 changed files with 64 additions and 30 deletions
+26
View File
@@ -1,8 +1,34 @@
// For more information on the .nro file format, see:
// https://switchbrew.org/wiki/NRO
.section .text.jmp, "x"
.global _start
_start:
b start
.word _mod_header - _start
.word 0
.word 0
.ascii "NRO0" // magic
.word 0 // version (always 0)
.word __bss_start - _start // total NRO file size
.word 0 // flags (unused)
// segment headers
.word __text_start
.word __text_size
.word __rodata_start
.word __rodata_size
.word __data_start
.word __data_size
.word __bss_size
.word 0
// ModuleId (not supported)
. = 0x50; // skip 32 bytes
.word 0 // DSO Module Offset (unused)
.word 0 // reserved (unused)
.section .data.mod0
.word 0, 8