From: Jon Feldman Date: Sat, 11 Feb 2017 13:31:04 +0000 (-0500) Subject: Partially revert "Put corbenik at 0x24F00000 and use a loader to get it there from... X-Git-Tag: v0.3.1~7 X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=4aab4a5938232c0c935ef513941c7743172d87da;p=corbenik%2Fcorbenik.git Partially revert "Put corbenik at 0x24F00000 and use a loader to get it there from non-elf-based a9lh." This reverts commit 31dc21fdc592d8eed5d99f706ecb856073f2b8f7. This is in retrospect overcomplicated and stupid. --- diff --git a/Makefile.am b/Makefile.am index 05dd191..d9f537f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,11 +1,9 @@ -SUBDIRS = include host external boot patch loader bits bootstub +SUBDIRS = include host external boot patch loader bits ACLOCAL_AMFLAGS = -I m4 boot: include host external patch -bootstub: boot - external: include host loader: external @@ -14,7 +12,7 @@ install: @echo "Please don't call the install target directly, it doesn't work." @exit 1 -all-local: external loader boot bits patch bootstub +all-local: external loader boot bits patch mkdir -p out mkdir -p out@prefix@ mkdir -p out@libdir@/module @@ -29,8 +27,7 @@ all-local: external loader boot bits patch bootstub mkdir -p out@libexecdir@ mkdir -p out@sysconfdir@ mkdir -p out@localstatedir@ - cp bootstub/bootstub.bin out/arm9loaderhax.bin - cp boot/corbenik.bin out@libexecdir@/ + cp boot/corbenik.bin out/arm9loaderhax.bin cp boot/corbenik out/corbenik.elf cp loader/loader.cxi out@libdir@/module/native/loader.cxi cp bits/*.bin out@libexecdir@/ diff --git a/boot/chainloader.c b/boot/chainloader.c index fead361..fdda828 100644 --- a/boot/chainloader.c +++ b/boot/chainloader.c @@ -28,12 +28,26 @@ void chainload_file(void* data) char* chain_file_data = (char*)data; // We copy because it's possible the payload will overwrite us in memory. - FILE* f; char chain_file[256]; strncpy(chain_file, chain_file_data, 255); - uint32_t size = 0; - uint8_t* chain_data = (uint8_t*)0x23F00000; + char code_file[] = PATH_BITS "/chain.bin"; + + uint8_t* bootstrap = (uint8_t*)0x24F00000; + uint32_t size = 0, b_size = 0; + uint8_t* chain_data; + + FILE* f = cropen(code_file, "r"); + if (!f) { + // File missing. + panic("Missing chainloader.\n"); + } + + b_size = crsize(f); + crread(bootstrap, 1, b_size, f); + crclose(f); + + chain_data = bootstrap + b_size; f = cropen(chain_file, "r"); if (!f) { @@ -57,6 +71,12 @@ void chainload_file(void* data) char* arg0 = (char*)&off[1]; memcpy(arg0, chain_file, strlen(chain_file) + 1); + uint32_t* argc_off = (uint32_t*)memfind(bootstrap, b_size, "ARGC", 4); + uint32_t* argv_off = (uint32_t*)memfind(bootstrap, b_size, "ARGV", 4); + + argc_off[0] = 1; + argv_off[0] = (uint32_t)off; + fprintf(stderr, "Changing display mode and chainloading...\n"); screen_mode(1, get_opt_u32(OPTION_BRIGHTNESS)); // Because RGBA8 screeninit is non-standard...ugh @@ -66,9 +86,7 @@ void chainload_file(void* data) // next call, so not my problem memcpy((void*)0x23FFFE00, framebuffers, sizeof(struct framebuffers)); - // TODO - TBH, I should really flush dcache and icache here - - ((void(*)(int, char**))0x23F00000)(1, (char**)off); + ((void(*)(void*, uint32_t))0x24F00000)(chain_data, size + 256 + 8); // Size of payload + argv. while(1); } diff --git a/boot/linker.ld b/boot/linker.ld index 6c0db6b..904e932 100644 --- a/boot/linker.ld +++ b/boot/linker.ld @@ -11,8 +11,8 @@ ENTRY(_start) SECTIONS { /* Read-only sections, merged into text segment: */ - /* Changed default address to 0x24F00000 */ - PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x24F00000)); . = SEGMENT_START("text-segment", 0x24F00000); + /* Changed default address to 0x23F00000 */ + PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x23F00000)); . = SEGMENT_START("text-segment", 0x23F00000); .interp : { *(.interp) } .note.gnu.build-id : { *(.note.gnu.build-id) } .hash : { *(.hash) } diff --git a/bootstub/Makefile.am b/bootstub/Makefile.am deleted file mode 100644 index 9a31de3..0000000 --- a/bootstub/Makefile.am +++ /dev/null @@ -1,23 +0,0 @@ -include $(top_srcdir)/common.mk - -noinst_PROGRAMS = bootstub -bootstub_CFLAGS=$(AM_CFLAGS) -T$(srcdir)/linker.ld -nostartfiles -bootstub_LDFLAGS=$(AM_LDFLAGS) -lctr9 -Wl,-Map,bootstub.map -EXTRA_DIST = linker.ld - -install: - -all-local: bootstub.bin - -clean-local: - rm -f bootstub.bin - -bootstub.bin: bootstub - $(OBJCOPY) $(OCFLAGS) -O binary bootstub bootstub.bin - -bootstubdir = $(top_srcdir)/source - -inc_dir = $(top_srcdir)/include - -bootstub_SOURCES = \ - start.s fs.c memory.c chainloader.c diff --git a/bootstub/chainloader.c b/bootstub/chainloader.c deleted file mode 100644 index c0d921e..0000000 --- a/bootstub/chainloader.c +++ /dev/null @@ -1,53 +0,0 @@ -#include // for uint32_t, uint8_t -#include // for NULL -#include // for memcpy, strlen, strncpy - -#include -#include - -#include -#include -#include - - -__attribute__((noreturn)) -void panic() { - ctr_system_poweroff(); - while(1); -} - -int main() -{ - FILE* f; - char chain_file[] = PATH_BITS "/corbenik.bin"; - - if (crmount()) { - panic(); - } - - uint8_t* bootstrap = (uint8_t*)0x24F00000; - uint32_t size = 0; - uint8_t* chain_data; - - f = cropen(chain_file, "r"); - if (!f) { - // File missing. - panic(); - } - - size = crsize(f); - char* memory = malloc(size); - crread(memory, 1, size, f); - crclose(f); - - crumount(); // It doesn't really matter if we clean up or not, but why not - - memmove(bootstrap, memory, size); // Memory is now clobbered. Any memory allocation is unsafe past this point. - - // Set args = 2, { PATH_BITS "/corbenik.bin", "-native" } - ctr_cache_clean_and_flush_all(); - - ((int(*)(int, char**))bootstrap)(0, NULL); - - panic(); -} diff --git a/bootstub/fs.c b/bootstub/fs.c deleted file mode 120000 index 1c3a7ce..0000000 --- a/bootstub/fs.c +++ /dev/null @@ -1 +0,0 @@ -../boot/std/fs.c \ No newline at end of file diff --git a/bootstub/linker.ld b/bootstub/linker.ld deleted file mode 100644 index f11c43c..0000000 --- a/bootstub/linker.ld +++ /dev/null @@ -1,253 +0,0 @@ -/* Script for -z combreloc: combine and sort reloc sections */ -/* Copyright (C) 2014 Free Software Foundation, Inc. - Copying and distribution of this script, with or without modification, - are permitted in any medium without royalty provided the copyright - notice and this notice are preserved. */ -OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", - "elf32-littlearm") -OUTPUT_ARCH(arm) -ENTRY(_start) -/* SEARCH_DIR("/opt/devkitpro/devkitARM/arm-none-eabi/lib"); */ -SECTIONS -{ - /* Read-only sections, merged into text segment: */ - /* Changed default address to 0x24F00000 */ - PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x23F00000)); . = SEGMENT_START("text-segment", 0x23F00000); - .interp : { *(.interp) } - .note.gnu.build-id : { *(.note.gnu.build-id) } - .hash : { *(.hash) } - .gnu.hash : { *(.gnu.hash) } - .dynsym : { *(.dynsym) } - .dynstr : { *(.dynstr) } - .gnu.version : { *(.gnu.version) } - .gnu.version_d : { *(.gnu.version_d) } - .gnu.version_r : { *(.gnu.version_r) } - .rel.dyn : - { - *(.rel.init) - *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*) - *(.rel.fini) - *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*) - *(.rel.data.rel.ro .rel.data.rel.ro.* .rel.gnu.linkonce.d.rel.ro.*) - *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) - *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*) - *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*) - *(.rel.ctors) - *(.rel.dtors) - *(.rel.got) - *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*) - PROVIDE_HIDDEN (__rel_iplt_start = .); - *(.rel.iplt) - PROVIDE_HIDDEN (__rel_iplt_end = .); - } - .rela.dyn : - { - *(.rela.init) - *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) - *(.rela.fini) - *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) - *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) - *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) - *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) - *(.rela.ctors) - *(.rela.dtors) - *(.rela.got) - *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) - PROVIDE_HIDDEN (__rela_iplt_start = .); - *(.rela.iplt) - PROVIDE_HIDDEN (__rela_iplt_end = .); - } - .rel.plt : - { - *(.rel.plt) - } - .rela.plt : - { - *(.rela.plt) - } - /* Make sure the start.o entry is at the beginning since that's the default alh entry */ - arm9loaderhax_entry : - { - KEEP (*(.text.start)) - } - arm9loaderhax_screeninit (INFO): - { - KEEP (*(screeninit)) - } - .init : - { - KEEP (*(SORT_NONE(.init))) - } - .plt : { *(.plt) } - .iplt : { *(.iplt) } - .text : - { - *(.text.unlikely .text.*_unlikely .text.unlikely.*) - *(.text.exit .text.exit.*) - *(.text.startup .text.startup.*) - *(.text.hot .text.hot.*) - *(.text .stub EXCLUDE_FILE (start.o) .text.* .gnu.linkonce.t.*) - /* .gnu.warning sections are handled specially by elf32.em. */ - *(.gnu.warning) - *(.glue_7t) *(.glue_7) *(.vfp11_veneer) *(.v4_bx) - } - .fini : - { - KEEP (*(SORT_NONE(.fini))) - } - PROVIDE (__etext = .); - PROVIDE (_etext = .); - PROVIDE (etext = .); - .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) } - .rodata1 : { *(.rodata1) } - .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } - PROVIDE_HIDDEN (__exidx_start = .); - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - PROVIDE_HIDDEN (__exidx_end = .); - .eh_frame_hdr : { *(.eh_frame_hdr) } - .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) } - .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table - .gcc_except_table.*) } - /* These sections are generated by the Sun/Oracle C++ compiler. */ - .exception_ranges : ONLY_IF_RO { *(.exception_ranges - .exception_ranges*) } - /* Adjust the address for the data segment. We want to adjust up to - the same address within the page on the next page up. */ - . = ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)); - /* Exception handling */ - .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) } - .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) } - .exception_ranges : ONLY_IF_RW { *(.exception_ranges .exception_ranges*) } - /* Thread Local Storage sections */ - .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) } - .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } - .preinit_array : - { - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP (*(.preinit_array)) - PROVIDE_HIDDEN (__preinit_array_end = .); - } - .init_array : - { - PROVIDE_HIDDEN (__init_array_start = .); - KEEP (*(SORT(.init_array.*))) - KEEP (*(.init_array )) - PROVIDE_HIDDEN (__init_array_end = .); - } - .fini_array : - { - PROVIDE_HIDDEN (__fini_array_start = .); - KEEP (*(SORT(.fini_array.*))) - KEEP (*(.fini_array )) - PROVIDE_HIDDEN (__fini_array_end = .); - } - .ctors : - { - /* 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 (*crtbegin?.o(.ctors)) - /* We don't want to include the .ctor section from - the crtend.o file until after the sorted ctors. - The .ctor section from the crtend file contains the - end of ctors marker and it must be last */ - KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors)) - KEEP (*(SORT(.ctors.*))) - KEEP (*(.ctors)) - } - .dtors : - { - KEEP (*crtbegin.o(.dtors)) - KEEP (*crtbegin?.o(.dtors)) - KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors)) - KEEP (*(SORT(.dtors.*))) - KEEP (*(.dtors)) - } - .jcr : { KEEP (*(.jcr)) } - .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) } - .dynamic : { *(.dynamic) } - .got : { *(.got.plt) *(.igot.plt) *(.got) *(.igot) } - .data : - { - __data_start = . ; - *(.data .data.* .gnu.linkonce.d.*) - SORT(CONSTRUCTORS) - } - .data1 : { *(.data1) } - _edata = .; PROVIDE (edata = .); - . = .; - __bss_start = .; - __bss_start__ = .; - .bss : - { - *(.dynbss) - *(.bss .bss.* .gnu.linkonce.b.*) - *(COMMON) - /* Align here to ensure that the .bss section occupies space up to - _end. Align after .bss to ensure correct alignment even if the - .bss section disappears because there are no input sections. - FIXME: Why do we need it? When there is no .bss section, we don't - pad the .data section. */ - . = ALIGN(. != 0 ? 32 / 8 : 1); - } - _bss_end__ = . ; __bss_end__ = . ; - . = ALIGN(32 / 8); - . = SEGMENT_START("ldata-segment", .); - . = ALIGN(32 / 8); - __end__ = . ; - _end = .; PROVIDE (end = .); - /* 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 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 .gnu.linkonce.wi.*) } - .debug_abbrev 0 : { *(.debug_abbrev) } - .debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end ) } - .debug_frame 0 : { *(.debug_frame) } - .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) } - /* DWARF 3 */ - .debug_pubtypes 0 : { *(.debug_pubtypes) } - .debug_ranges 0 : { *(.debug_ranges) } - /* DWARF Extension. */ - .debug_macro 0 : { *(.debug_macro) } - .stack 0x27F00000 : - { - _stack = .; - *(.stack) - } - .ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) } - .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) } - /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) } -} - diff --git a/bootstub/memory.c b/bootstub/memory.c deleted file mode 120000 index abff954..0000000 --- a/bootstub/memory.c +++ /dev/null @@ -1 +0,0 @@ -../boot/std/memory.c \ No newline at end of file diff --git a/bootstub/start.s b/bootstub/start.s deleted file mode 120000 index a7ba710..0000000 --- a/bootstub/start.s +++ /dev/null @@ -1 +0,0 @@ -../boot/start.s \ No newline at end of file diff --git a/configure.ac b/configure.ac index ae132d7..449a2d2 100644 --- a/configure.ac +++ b/configure.ac @@ -31,7 +31,7 @@ AC_DEFINE_UNQUOTED([COMPILER_ID], [$COMPILER_ID]) AC_DEFINE_UNQUOTED([CONFIGURE_OPTIONS], [$CONFIGURE_OPTIONS]) -AC_CONFIG_FILES([Makefile boot/Makefile external/Makefile include/Makefile bootstub/Makefile]) +AC_CONFIG_FILES([Makefile boot/Makefile external/Makefile include/Makefile]) AC_CONFIG_SUBDIRS([external/libctr9])