diff --git a/Makefile.arm11 b/Makefile.arm11 index e5806b9..cf15fda 100644 --- a/Makefile.arm11 +++ b/Makefile.arm11 @@ -43,7 +43,7 @@ CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=c++11 ASFLAGS := -g $(INCLUDE) $(ARCH) -DARM11 -D_3DS $(DEFINES) -LDFLAGS = -nostartfiles -T../$(LDNAME) $(CFLAGS) -Wl,-Map,$(notdir $*.map),--use-blx,--gc-sections +LDFLAGS = -nostartfiles -T../$(LDNAME) $(CFLAGS) -Wl,-Map,$(notdir $*.map),--use-blx,--gc-sections,--emit-relocs #--------------------------------------------------------------------------------- # any extra libraries we wish to link with the project (order is important) diff --git a/Makefile.arm9 b/Makefile.arm9 index 96f31a2..e4e7d83 100644 --- a/Makefile.arm9 +++ b/Makefile.arm9 @@ -43,7 +43,7 @@ CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=c++11 ASFLAGS := -g $(INCLUDE) $(ARCH) -DARM9 $(DEFINES) -LDFLAGS = -nostartfiles -T../$(LDNAME) $(CFLAGS) -Wl,-Map,$(notdir $*.map),--use-blx,--gc-sections +LDFLAGS = -nostartfiles -T../$(LDNAME) $(CFLAGS) -Wl,-Map,$(notdir $*.map),--use-blx,--gc-sections,--emit-relocs #--------------------------------------------------------------------------------- # any extra libraries we wish to link with the project (order is important) diff --git a/arm11.ld b/arm11.ld index d571b2e..93ac9e7 100644 --- a/arm11.ld +++ b/arm11.ld @@ -2,178 +2,179 @@ OUTPUT_ARCH(arm) ENTRY(_start) -MEMORY { - - memregion : ORIGIN = 0x1FF80000, LENGTH = 100K +PHDRS +{ + code PT_LOAD FLAGS(5) /* Read | Execute */; + rodata PT_LOAD FLAGS(4) /* Read */; + data PT_LOAD FLAGS(6) /* Read | Write */; } -__memregion_start = ORIGIN(memregion); -__memregion_top = ORIGIN(memregion)+ LENGTH(memregion); - SECTIONS { - .init : - { - __text_start = . ; - KEEP (*(.init)) - . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ - } >memregion = 0xff - - .plt : - { - *(.plt) - } >memregion = 0xff + /* =========== CODE section =========== */ - .text : /* ALIGN (4): */ - { + . = 0x1FF80000; + __start__ = . ; - *(.text*) - *(.stub) - /* .gnu.warning sections are handled specially by elf32.em. */ - *(.gnu.warning) - *(.gnu.linkonce.t*) + .text ALIGN(4) : + { + /* .init */ + KEEP( *(.crt0) ) + KEEP( *(.init) ) + . = ALIGN(4); + + /* .text */ + *(.text) + *(.text.*) *(.glue_7) *(.glue_7t) - . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ - } >memregion = 0xff + *(.stub) + *(.gnu.warning) + *(.gnu.linkonce.t*) + . = ALIGN(4); - .fini : - { - KEEP (*(.fini)) - } >memregion =0xff + /* .fini */ + KEEP( *(.fini) ) + . = ALIGN(4); + } : code - __text_end = . ; + /* =========== RODATA section =========== */ - .rodata : + .rodata ALIGN(4) : { *(.rodata) - *all.rodata*(*) *(.roda) *(.rodata.*) + *all.rodata*(*) *(.gnu.linkonce.r*) SORT(CONSTRUCTORS) - . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ - } >memregion = 0xff + . = ALIGN(4); + } : rodata - .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >memregion + .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } : rodata __exidx_start = .; - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } >memregion + ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } : rodata __exidx_end = .; -/* Ensure the __preinit_array_start label is properly aligned. We - could instead move the label definition inside the section, but - the linker would then create the section even if it turns out to - be empty, which isn't pretty. */ - . = ALIGN(32 / 8); - PROVIDE (__preinit_array_start = .); - .preinit_array : { KEEP (*(.preinit_array)) } >memregion = 0xff - PROVIDE (__preinit_array_end = .); - PROVIDE (__init_array_start = .); - .init_array : { KEEP (*(.init_array)) } >memregion = 0xff - PROVIDE (__init_array_end = .); - PROVIDE (__fini_array_start = .); - .fini_array : { KEEP (*(.fini_array)) } >memregion = 0xff - PROVIDE (__fini_array_end = .); + /* =========== DATA section =========== */ - .ctors : + .data ALIGN(4) : { - /* gcc uses crtbegin.o to find the start of the constructors, so - we make sure it is first. Because this is a wildcard, it - doesn't matter if the user does not actually link against - crtbegin.o; the linker won't look for a file to match a - wildcard. The wildcard also means that it doesn't matter which - directory crtbegin.o is in. */ - KEEP (*crtbegin.o(.ctors)) - KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) - KEEP (*(SORT(.ctors.*))) - KEEP (*(.ctors)) - . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ - } >memregion = 0xff - - .dtors : - { - KEEP (*crtbegin.o(.dtors)) - KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) - KEEP (*(SORT(.dtors.*))) - KEEP (*(.dtors)) - . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ - } >memregion = 0xff - - .eh_frame : - { - KEEP (*(.eh_frame)) - . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ - } >memregion = 0xff - - .gcc_except_table : - { - *(.gcc_except_table) - . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ - } >memregion = 0xff - .jcr : { KEEP (*(.jcr)) } >memregion = 0 - .got : { *(.got.plt) *(.got) } >memregion = 0 - - - .memregion ALIGN(4) : - { - __memregion_start = ABSOLUTE(.) ; - *(.memregion) - *memregion.*(.text) - . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ - __memregion_end = ABSOLUTE(.) ; - } >memregion = 0xff - - - .data ALIGN(4) : { - __data_start = ABSOLUTE(.); *(.data) *(.data.*) *(.gnu.linkonce.d*) CONSTRUCTORS . = ALIGN(4); - __data_end = ABSOLUTE(.) ; - } >memregion = 0xff + } : data + .tdata ALIGN(4) : + { + __tdata_lma = .; + *(.tdata) + *(.tdata.*) + *(.gnu.linkonce.td.*) + . = ALIGN(4); + __tdata_lma_end = .; + } : data + .tbss ALIGN(4) : + { + *(.tbss) + *(.tbss.*) + *(.gnu.linkonce.tb.*) + *(.tcommon) + . = ALIGN(4); + } : data + .preinit_array ALIGN(4) : + { + PROVIDE (__preinit_array_start = .); + KEEP (*(.preinit_array)) + PROVIDE (__preinit_array_end = .); + } : data + + .init_array ALIGN(4) : + { + PROVIDE (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array)) + PROVIDE (__init_array_end = .); + } : data + + .fini_array ALIGN(4) : + { + PROVIDE (__fini_array_start = .); + KEEP (*(.fini_array)) + KEEP (*(SORT(.fini_array.*))) + PROVIDE (__fini_array_end = .); + } : data + + .ctors ALIGN(4) : + { + KEEP (*crtbegin.o(.ctors)) /* MUST be first -- GCC requires it */ + KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + } : data + + .dtors ALIGN(4) : + { + KEEP (*crtbegin.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + } : data + + __bss_start__ = .; .bss ALIGN(4) : { - __bss_start = ABSOLUTE(.); - __bss_start__ = ABSOLUTE(.); *(.dynbss) + *(.bss) + *(.bss.*) *(.gnu.linkonce.b*) - *(.bss*) *(COMMON) - . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ - } >memregion + . = ALIGN(4); - __bss_end = . ; - __bss_end__ = . ; + /* Reserve space for the TLS segment of the main thread */ + __tls_start = .; + . += + SIZEOF(.tdata) + SIZEOF(.tbss); + __tls_end = .; + } : data + __bss_end__ = .; - _end = . ; - __end__ = . ; - PROVIDE (end = _end); + __end__ = ABSOLUTE(.) ; - /* Stabs debugging sections. */ - .stab 0 : { *(.stab) } - .stabstr 0 : { *(.stabstr) } - .stab.excl 0 : { *(.stab.excl) } - .stab.exclstr 0 : { *(.stab.exclstr) } - .stab.index 0 : { *(.stab.index) } + /* ================== + ==== Metadata ==== + ================== */ + + /* Discard sections that difficult post-processing */ + /DISCARD/ : { *(.group .comment .note) } + + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } .stab.indexstr 0 : { *(.stab.indexstr) } - .comment 0 : { *(.comment) } - /* DWARF debug sections. - Symbols in the DWARF debugging sections are relative to the beginning - of the section so we begin them at 0. */ + + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ .debug 0 : { *(.debug) } .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ .debug_srcinfo 0 : { *(.debug_srcinfo) } .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ .debug_aranges 0 : { *(.debug_aranges) } .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ .debug_info 0 : { *(.debug_info) } .debug_abbrev 0 : { *(.debug_abbrev) } @@ -182,11 +183,4 @@ .debug_str 0 : { *(.debug_str) } .debug_loc 0 : { *(.debug_loc) } .debug_macinfo 0 : { *(.debug_macinfo) } - /* SGI/MIPS DWARF 2 extensions */ - .debug_weaknames 0 : { *(.debug_weaknames) } - .debug_funcnames 0 : { *(.debug_funcnames) } - .debug_typenames 0 : { *(.debug_typenames) } - .debug_varnames 0 : { *(.debug_varnames) } - .stack 0x80000 : { _stack = .; *(.stack) } - /* These must appear regardless of . */ } diff --git a/arm9.ld b/arm9.ld index 83a9739..c63146c 100644 --- a/arm9.ld +++ b/arm9.ld @@ -2,178 +2,179 @@ OUTPUT_ARCH(arm) ENTRY(_start) -MEMORY { - - memregion : ORIGIN = 0x08000040, LENGTH = 300K +PHDRS +{ + code PT_LOAD FLAGS(5) /* Read | Execute */; + rodata PT_LOAD FLAGS(4) /* Read */; + data PT_LOAD FLAGS(6) /* Read | Write */; } -__memregion_start = ORIGIN(memregion); -__memregion_top = ORIGIN(memregion)+ LENGTH(memregion); - SECTIONS { - .init : - { - __text_start = . ; - KEEP (*(.init)) - . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ - } >memregion = 0xff - - .plt : - { - *(.plt) - } >memregion = 0xff + /* =========== CODE section =========== */ - .text : /* ALIGN (4): */ - { + . = 0x08000040; + __start__ = . ; - *(.text*) - *(.stub) - /* .gnu.warning sections are handled specially by elf32.em. */ - *(.gnu.warning) - *(.gnu.linkonce.t*) + .text ALIGN(4) : + { + /* .init */ + KEEP( *(.crt0) ) + KEEP( *(.init) ) + . = ALIGN(4); + + /* .text */ + *(.text) + *(.text.*) *(.glue_7) *(.glue_7t) - . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ - } >memregion = 0xff + *(.stub) + *(.gnu.warning) + *(.gnu.linkonce.t*) + . = ALIGN(4); - .fini : - { - KEEP (*(.fini)) - } >memregion =0xff + /* .fini */ + KEEP( *(.fini) ) + . = ALIGN(4); + } : code - __text_end = . ; + /* =========== RODATA section =========== */ - .rodata : + .rodata ALIGN(4) : { *(.rodata) - *all.rodata*(*) *(.roda) *(.rodata.*) + *all.rodata*(*) *(.gnu.linkonce.r*) SORT(CONSTRUCTORS) - . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ - } >memregion = 0xff + . = ALIGN(4); + } : rodata - .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >memregion + .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } : rodata __exidx_start = .; - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } >memregion + ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } : rodata __exidx_end = .; -/* Ensure the __preinit_array_start label is properly aligned. We - could instead move the label definition inside the section, but - the linker would then create the section even if it turns out to - be empty, which isn't pretty. */ - . = ALIGN(32 / 8); - PROVIDE (__preinit_array_start = .); - .preinit_array : { KEEP (*(.preinit_array)) } >memregion = 0xff - PROVIDE (__preinit_array_end = .); - PROVIDE (__init_array_start = .); - .init_array : { KEEP (*(.init_array)) } >memregion = 0xff - PROVIDE (__init_array_end = .); - PROVIDE (__fini_array_start = .); - .fini_array : { KEEP (*(.fini_array)) } >memregion = 0xff - PROVIDE (__fini_array_end = .); + /* =========== DATA section =========== */ - .ctors : + .data ALIGN(4) : { - /* gcc uses crtbegin.o to find the start of the constructors, so - we make sure it is first. Because this is a wildcard, it - doesn't matter if the user does not actually link against - crtbegin.o; the linker won't look for a file to match a - wildcard. The wildcard also means that it doesn't matter which - directory crtbegin.o is in. */ - KEEP (*crtbegin.o(.ctors)) - KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) - KEEP (*(SORT(.ctors.*))) - KEEP (*(.ctors)) - . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ - } >memregion = 0xff - - .dtors : - { - KEEP (*crtbegin.o(.dtors)) - KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) - KEEP (*(SORT(.dtors.*))) - KEEP (*(.dtors)) - . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ - } >memregion = 0xff - - .eh_frame : - { - KEEP (*(.eh_frame)) - . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ - } >memregion = 0xff - - .gcc_except_table : - { - *(.gcc_except_table) - . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ - } >memregion = 0xff - .jcr : { KEEP (*(.jcr)) } >memregion = 0 - .got : { *(.got.plt) *(.got) } >memregion = 0 - - - .memregion ALIGN(4) : - { - __memregion_start = ABSOLUTE(.) ; - *(.memregion) - *memregion.*(.text) - . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ - __memregion_end = ABSOLUTE(.) ; - } >memregion = 0xff - - - .data ALIGN(4) : { - __data_start = ABSOLUTE(.); *(.data) *(.data.*) *(.gnu.linkonce.d*) CONSTRUCTORS . = ALIGN(4); - __data_end = ABSOLUTE(.) ; - } >memregion = 0xff + } : data + .tdata ALIGN(4) : + { + __tdata_lma = .; + *(.tdata) + *(.tdata.*) + *(.gnu.linkonce.td.*) + . = ALIGN(4); + __tdata_lma_end = .; + } : data + .tbss ALIGN(4) : + { + *(.tbss) + *(.tbss.*) + *(.gnu.linkonce.tb.*) + *(.tcommon) + . = ALIGN(4); + } : data + .preinit_array ALIGN(4) : + { + PROVIDE (__preinit_array_start = .); + KEEP (*(.preinit_array)) + PROVIDE (__preinit_array_end = .); + } : data + + .init_array ALIGN(4) : + { + PROVIDE (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array)) + PROVIDE (__init_array_end = .); + } : data + + .fini_array ALIGN(4) : + { + PROVIDE (__fini_array_start = .); + KEEP (*(.fini_array)) + KEEP (*(SORT(.fini_array.*))) + PROVIDE (__fini_array_end = .); + } : data + + .ctors ALIGN(4) : + { + KEEP (*crtbegin.o(.ctors)) /* MUST be first -- GCC requires it */ + KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + } : data + + .dtors ALIGN(4) : + { + KEEP (*crtbegin.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + } : data + + __bss_start__ = .; .bss ALIGN(4) : { - __bss_start = ABSOLUTE(.); - __bss_start__ = ABSOLUTE(.); *(.dynbss) + *(.bss) + *(.bss.*) *(.gnu.linkonce.b*) - *(.bss*) *(COMMON) - . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ - } >memregion + . = ALIGN(4); - __bss_end = . ; - __bss_end__ = . ; + /* Reserve space for the TLS segment of the main thread */ + __tls_start = .; + . += + SIZEOF(.tdata) + SIZEOF(.tbss); + __tls_end = .; + } : data + __bss_end__ = .; - _end = . ; - __end__ = . ; - PROVIDE (end = _end); + __end__ = ABSOLUTE(.) ; - /* Stabs debugging sections. */ - .stab 0 : { *(.stab) } - .stabstr 0 : { *(.stabstr) } - .stab.excl 0 : { *(.stab.excl) } - .stab.exclstr 0 : { *(.stab.exclstr) } - .stab.index 0 : { *(.stab.index) } + /* ================== + ==== Metadata ==== + ================== */ + + /* Discard sections that difficult post-processing */ + /DISCARD/ : { *(.group .comment .note) } + + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } .stab.indexstr 0 : { *(.stab.indexstr) } - .comment 0 : { *(.comment) } - /* DWARF debug sections. - Symbols in the DWARF debugging sections are relative to the beginning - of the section so we begin them at 0. */ + + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ .debug 0 : { *(.debug) } .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ .debug_srcinfo 0 : { *(.debug_srcinfo) } .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ .debug_aranges 0 : { *(.debug_aranges) } .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ .debug_info 0 : { *(.debug_info) } .debug_abbrev 0 : { *(.debug_abbrev) } @@ -182,11 +183,4 @@ .debug_str 0 : { *(.debug_str) } .debug_loc 0 : { *(.debug_loc) } .debug_macinfo 0 : { *(.debug_macinfo) } - /* SGI/MIPS DWARF 2 extensions */ - .debug_weaknames 0 : { *(.debug_weaknames) } - .debug_funcnames 0 : { *(.debug_funcnames) } - .debug_typenames 0 : { *(.debug_typenames) } - .debug_varnames 0 : { *(.debug_varnames) } - .stack 0x80000 : { _stack = .; *(.stack) } - /* These must appear regardless of . */ } diff --git a/include/arm9/console.h b/include/arm9/console.h index ce216c6..f71b835 100644 --- a/include/arm9/console.h +++ b/include/arm9/console.h @@ -1,132 +1,170 @@ - - -/*! \file console.h - \brief 3ds stdio support. - -
-PrintConsole defaultConsole =
-{
- //Font:
- {
- (u8*)default_font_bin, //font gfx
- 0, //first ascii character in the set
- 128, //number of characters in the font set
- },
- 0,0, //cursorX cursorY
- 0,0, //prevcursorX prevcursorY
- 40, //console width
- 30, //console height
- 0, //window x
- 0, //window y
- 32, //window width
- 24, //window height
- 3, //tab size
- 0, //font character offset
- false //console initialized
-};
-