Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ endif
@$(MD5SUM) test.hex
$(TINYGO) build -size short -o test.hex -target=pca10040 -opt=1 examples/blinky1
@$(MD5SUM) test.hex
$(TINYGO) build -o test.elf -target=nintendoswitch examples/serial
@$(MD5SUM) test.elf
$(TINYGO) build -o test.nro -target=nintendoswitch examples/serial
@$(MD5SUM) test.nro

wasmtest:
$(GO) test ./tests/wasm
Expand Down
2 changes: 1 addition & 1 deletion compileopts/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func (c *Config) Debug() bool {
// extension and the configured binary format in the target JSON file.
func (c *Config) BinaryFormat(ext string) string {
switch ext {
case ".bin", ".gba":
case ".bin", ".gba", ".nro":
// The simplest format possible: dump everything in a raw binary file.
if c.Target.BinaryFormat != "" {
return c.Target.BinaryFormat
Expand Down
60 changes: 34 additions & 26 deletions targets/nintendoswitch.ld
Original file line number Diff line number Diff line change
@@ -1,61 +1,69 @@
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) {
/* Code and file header */

.text : {
HIDDEN(__text_start = .);
KEEP(*(.text.jmp))

. = 0x80;

*(.text .text.*)

. = ALIGN(0x1000);
HIDDEN(__text_end = .);
HIDDEN(__text_size = . - __text_start);
}

/* Read-only sections */

. = ALIGN(0x1000);
.rodata : {
HIDDEN(__rodata_start = .);

*(.rodata .rodata.*)

*(.got)

.rodata : { *(.rodata .rodata.*) } :rodata
.mod0 : {
KEEP(crt0.nso.o(.data.mod0))
KEEP(crt0.nro.o(.data.mod0))
KEEP(crt0.lib.nro.o(.data.mod0))
KEEP(*(.data.mod0))

HIDDEN(__dynamic_start = .);
*(.dynamic)

. = ALIGN(0x1000);
HIDDEN(__rodata_end = .);
HIDDEN(__rodata_size = . - __rodata_start);
}

/* Read-write sections */
. = ALIGN(0x1000);

.data : {
HIDDEN(__data_start = .);

*(.data .data.*)
} :data

.dynamic : {
HIDDEN(__dynamic_start = .);
*(.dynamic)
HIDDEN(__data_end = .);
HIDDEN(__data_size = . - __data_start);
}

/* BSS section */

. = ALIGN(0x1000);

.bss : {
HIDDEN(__bss_start = .);

*(.bss .bss.*)
*(COMMON)
. = ALIGN(8);

HIDDEN(__bss_end = .);
} :bss
HIDDEN(__bss_size = . - __bss_start);
}

/DISCARD/ :
{
*(.eh_frame) /* This is probably unnecessary and bloats the binary. */
}
}
26 changes: 26 additions & 0 deletions targets/nintendoswitch.s
Original file line number Diff line number Diff line change
@@ -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
Expand Down