From d103461fa9e603f12b6d35ba9d28851c84af3f04 Mon Sep 17 00:00:00 2001 From: "crediar@rypp.net" Date: Fri, 29 Jun 2012 02:52:11 +0000 Subject: [PATCH] Tools: *Added bin2h *Added elfloader *Updated asm/make.cmd git-svn-id: svn://localhost/Users/andi/Downloads/code/trunk@14 be6c1b03-d731-4111-a574-e37d80d43941 --- asm/make.cmd | 6 +- elfloader/.deps/string.d | 7 ++ elfloader/.deps/stub.d | 18 ++++ elfloader/.deps/utils.d | 9 ++ elfloader/Makefile | 23 +++++ elfloader/common.mk | 60 ++++++++++++ elfloader/elf.h | 66 +++++++++++++ elfloader/elfloader.elf.map | 168 ++++++++++++++++++++++++++++++++ elfloader/hollywood.h | 31 ++++++ elfloader/starlet.mk | 12 +++ elfloader/start.S | 113 ++++++++++++++++++++++ elfloader/start.h | 30 ++++++ elfloader/start.o | Bin 0 -> 1304 bytes elfloader/string.c | 1 + elfloader/string.h | 1 + elfloader/string.o | Bin 0 -> 2099 bytes elfloader/stub.c | 86 +++++++++++++++++ elfloader/stub.ld | 117 ++++++++++++++++++++++ elfloader/stub.o | Bin 0 -> 1832 bytes elfloader/types.h | 50 ++++++++++ elfloader/utils.c | 45 +++++++++ elfloader/utils.h | 188 ++++++++++++++++++++++++++++++++++++ elfloader/utils.o | Bin 0 -> 1236 bytes tools/bin2h/bin2h.exe | Bin 0 -> 7680 bytes tools/bin2h/main.cpp | 86 +++++++++++++++++ 25 files changed, 1114 insertions(+), 3 deletions(-) create mode 100644 elfloader/.deps/string.d create mode 100644 elfloader/.deps/stub.d create mode 100644 elfloader/.deps/utils.d create mode 100644 elfloader/Makefile create mode 100644 elfloader/common.mk create mode 100644 elfloader/elf.h create mode 100644 elfloader/elfloader.elf.map create mode 100644 elfloader/hollywood.h create mode 100644 elfloader/starlet.mk create mode 100644 elfloader/start.S create mode 100644 elfloader/start.h create mode 100644 elfloader/start.o create mode 100644 elfloader/string.c create mode 100644 elfloader/string.h create mode 100644 elfloader/string.o create mode 100644 elfloader/stub.c create mode 100644 elfloader/stub.ld create mode 100644 elfloader/stub.o create mode 100644 elfloader/types.h create mode 100644 elfloader/utils.c create mode 100644 elfloader/utils.h create mode 100644 elfloader/utils.o create mode 100644 tools/bin2h/bin2h.exe create mode 100644 tools/bin2h/main.cpp diff --git a/asm/make.cmd b/asm/make.cmd index 0617458..5c53250 100644 --- a/asm/make.cmd +++ b/asm/make.cmd @@ -1,4 +1,4 @@ @echo off -for /R %%i IN (*.S) DO E:\devkitPro\devkitPPC\bin\powerpc-eabi-as.exe %%i -o %%~ni.elf -for /R %%i IN (*.S) DO E:\devkitPro\devkitPPC\bin\powerpc-eabi-strip.exe -s %%~ni.elf -O binary -o %%~ni.bin -for /R %%i in (*.bin) DO "C:\Users\crediar\Documents\Visual Studio 2010\Projects\bin2h\Release\bin2h.exe" %%~ni.bin +for /R %%i IN (*.S) DO %devkitpro:~1,1%:\%devkitpro:~3%\devkitPPC\bin\powerpc-eabi-as.exe %%i -o %%~ni.elf +for /R %%i IN (*.S) DO %devkitpro:~1,1%:\%devkitpro:~3%\devkitPPC\bin\powerpc-eabi-strip.exe -s %%~ni.elf -O binary -o %%~ni.bin +for /R %%i in (*.bin) DO "..\tools\bin2h\bin2h.exe" %%~ni.bin diff --git a/elfloader/.deps/string.d b/elfloader/.deps/string.d new file mode 100644 index 0000000..53b9f7d --- /dev/null +++ b/elfloader/.deps/string.d @@ -0,0 +1,7 @@ +string.o: string.c ../string.c ../string.h ../global.h + +../string.c: + +../string.h: + +../global.h: diff --git a/elfloader/.deps/stub.d b/elfloader/.deps/stub.d new file mode 100644 index 0000000..0f667a5 --- /dev/null +++ b/elfloader/.deps/stub.d @@ -0,0 +1,18 @@ +stub.o: stub.c types.h utils.h start.h hollywood.h string.h ../string.h \ + ../global.h elf.h + +types.h: + +utils.h: + +start.h: + +hollywood.h: + +string.h: + +../string.h: + +../global.h: + +elf.h: diff --git a/elfloader/.deps/utils.d b/elfloader/.deps/utils.d new file mode 100644 index 0000000..87eecaf --- /dev/null +++ b/elfloader/.deps/utils.d @@ -0,0 +1,9 @@ +utils.o: utils.c types.h utils.h hollywood.h start.h + +types.h: + +utils.h: + +hollywood.h: + +start.h: diff --git a/elfloader/Makefile b/elfloader/Makefile new file mode 100644 index 0000000..2199f7f --- /dev/null +++ b/elfloader/Makefile @@ -0,0 +1,23 @@ +include starlet.mk + +CFLAGS += -fpic -fno-builtin-memcpy +LDSCRIPT = stub.ld +LIBS = -lgcc + +TARGET = elfloader.elf +TARGET_BIN = elfloader.bin +OBJS = start.o stub.o string.o utils.o + +include common.mk + +all: $(TARGET_BIN) + +$(TARGET_BIN): $(TARGET) + @echo " OBJCPY $@" + @$(OBJCOPY) -O binary $< $@ + +clean: myclean + +myclean: + -rm -f $(TARGET_BIN) + diff --git a/elfloader/common.mk b/elfloader/common.mk new file mode 100644 index 0000000..cd9fdcb --- /dev/null +++ b/elfloader/common.mk @@ -0,0 +1,60 @@ +AR = $(PREFIX)ar +AS = $(PREFIX)as +CC = $(PREFIX)gcc +CXX = $(PREFIX)g++ +LD = $(PREFIX)ld +OBJCOPY = $(PREFIX)objcopy +RANLIB = $(PREFIX)ranlib +STRIP = $(PREFIX)strip + +BIN2S = $(DEVKITPPC)/bin/bin2s + +ifeq ($(NOMAPFILE),) +LDFLAGS += -Wl,-Map,$(TARGET).map +endif + +ifneq ($(LDSCRIPT),) +LDFLAGS += -Wl,-T$(LDSCRIPT) +endif + +DEPDIR = .deps + +all: $(TARGET) + +$(TARGET): $(OBJS) + @echo " LINK $@" + @$(CC) $(LDFLAGS) $(OBJS) $(LIBS) -o $@ + +ifneq ($(LDSCRIPT),) +$(TARGET): $(LDSCRIPT) +endif + +%.o: %.c + @echo " COMPILE $<" + @mkdir -p $(DEPDIR) + @$(CC) $(CFLAGS) $(DEFINES) -Wp,-MMD,$(DEPDIR)/$(*F).d,-MQ,"$@",-MP -c $< -o $@ + +%.o: %.s + @echo " ASSEMBLE $<" + @$(CC) $(CFLAGS) $(DEFINES) $(ASFLAGS) -c $< -o $@ + +%.o: %.S + @echo " ASSEMBLE $<" + @$(CC) $(CFLAGS) $(DEFINES) $(ASFLAGS) -c $< -o $@ + +clean: + rm -rf $(DEPDIR) + rm -f $(TARGET) $(TARGET).map $(OBJS) + +define bin2o + @echo " BIN2S $(notdir $<)" + @$(BIN2S) -a 32 $< | $(AS) -o $(@) + @echo "extern const u8" `(echo $( `(echo $(> `(echo $(> `(echo $( + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 2. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ +#ifndef __ELF_H__ +#define __ELF_H__ + +#include "types.h" + +#define EI_NIDENT 16 + +typedef struct { + unsigned char e_ident[EI_NIDENT]; + u16 e_type; + u16 e_machine; + u32 e_version; + void *e_entry; + u32 e_phoff; + u32 e_shoff; + u32 e_flags; + u16 e_ehsize; + u16 e_phentsize; + u16 e_phnum; + u16 e_shentsize; + u16 e_shnum; + u16 e_shtrndx; +} Elf32_Ehdr; + +typedef struct { + u32 p_type; + u32 p_offset; + void *p_vaddr; + void *p_paddr; + u32 p_filesz; + u32 p_memsz; + u32 p_flags; + u32 p_align; +} Elf32_Phdr; + +#define PT_NULL 0 +#define PT_LOAD 1 +#define PT_DYNAMIC 2 +#define PT_INTERP 3 +#define PT_NOTE 4 +#define PT_SHLIB 5 +#define PT_PHDR 6 + +#endif + diff --git a/elfloader/elfloader.elf.map b/elfloader/elfloader.elf.map new file mode 100644 index 0000000..6e09c4c --- /dev/null +++ b/elfloader/elfloader.elf.map @@ -0,0 +1,168 @@ +Archive member included because of file (symbol) + +e:/devkitpro/devkitarm/bin/../lib/gcc/arm-eabi/4.6.1/be\libgcc.a(_udivsi3.o) + utils.o (__aeabi_uidiv) +e:/devkitpro/devkitarm/bin/../lib/gcc/arm-eabi/4.6.1/be\libgcc.a(_dvmd_tls.o) + e:/devkitpro/devkitarm/bin/../lib/gcc/arm-eabi/4.6.1/be\libgcc.a(_udivsi3.o) (__aeabi_idiv0) + +Discarded input sections + + .text 0x00000000 0x0 start.o + .data 0x00000000 0x0 start.o + .bss 0x00000000 0x0 start.o + .text 0x00000000 0x0 stub.o + .data 0x00000000 0x0 stub.o + .bss 0x00000000 0x0 stub.o + .text 0x00000000 0x0 string.o + .data 0x00000000 0x0 string.o + .bss 0x00000000 0x0 string.o + .text.strnlen 0x00000000 0x2c string.o + .text.strlen 0x00000000 0x20 string.o + .text.strncpy 0x00000000 0x4c string.o + .text.strcpy 0x00000000 0x18 string.o + .text.strcmp 0x00000000 0x28 string.o + .text.strncmp 0x00000000 0x48 string.o + .text.memset 0x00000000 0x1c string.o + .text.strchr 0x00000000 0x28 string.o + .text 0x00000000 0x0 utils.o + .data 0x00000000 0x0 utils.o + .bss 0x00000000 0x0 utils.o + .data 0x00000000 0x0 e:/devkitpro/devkitarm/bin/../lib/gcc/arm-eabi/4.6.1/be\libgcc.a(_udivsi3.o) + .bss 0x00000000 0x0 e:/devkitpro/devkitarm/bin/../lib/gcc/arm-eabi/4.6.1/be\libgcc.a(_udivsi3.o) + .data 0x00000000 0x0 e:/devkitpro/devkitarm/bin/../lib/gcc/arm-eabi/4.6.1/be\libgcc.a(_dvmd_tls.o) + .bss 0x00000000 0x0 e:/devkitpro/devkitarm/bin/../lib/gcc/arm-eabi/4.6.1/be\libgcc.a(_dvmd_tls.o) + +Memory Configuration + +Name Origin Length Attributes +*default* 0x00000000 0xffffffff + +Linker script and memory map + + 0x00000000 __base_addr = 0x0 + 0x00000000 . = __base_addr + +.header 0x00000000 0x10 + 0x00000000 __header = . + 0x00000000 0x4 LONG 0x10 __code_start + 0x00000004 0x4 LONG 0x4b0 __loader_size + 0x00000008 0x4 LONG 0x0 + 0x0000000c 0x4 LONG 0x0 + 0x00000010 . = ALIGN (0x10) + 0x00000010 __code_start = . + +.init 0x00000010 0xc8 + *(.init) + .init 0x00000010 0xc8 start.o + 0x00000010 _start + 0x000000bc debug_output + 0x000000d8 . = ALIGN (0x4) + +.got 0x000000d8 0x0 + 0x000000d8 __got_start = . + *(.got.*) + *(.got) + 0x000000d8 . = ALIGN (0x4) + 0x000000d8 __got_end = . + +.text 0x000000d8 0x2d4 + *(.text.*) + .text.disable_boot0 + 0x000000d8 0x1c stub.o + .text.mem_setswap + 0x000000f4 0x1c stub.o + .text.loadelf 0x00000110 0x90 stub.o + 0x00000110 loadelf + .text._main 0x000001a0 0x44 stub.o + 0x000001a0 _main + .text.memcmp 0x000001e4 0x48 string.o + 0x000001e4 memcmp + .text.udelay 0x0000022c 0x38 utils.o + 0x0000022c udelay + .text.panic 0x00000264 0x30 utils.o + 0x00000264 panic + *(.gnu.warning) + *(.gnu.linkonce.t*) + *(.glue_7) + .glue_7 0x00000000 0x0 linker stubs + *(.glue_7t) + .glue_7t 0x00000000 0x0 linker stubs + 0x00000294 . = ALIGN (0x4) + .text 0x00000294 0x114 e:/devkitpro/devkitarm/bin/../lib/gcc/arm-eabi/4.6.1/be\libgcc.a(_udivsi3.o) + 0x00000294 __aeabi_uidiv + 0x00000294 __udivsi3 + 0x00000388 __aeabi_uidivmod + .text 0x000003a8 0x4 e:/devkitpro/devkitarm/bin/../lib/gcc/arm-eabi/4.6.1/be\libgcc.a(_dvmd_tls.o) + 0x000003a8 __aeabi_idiv0 + 0x000003a8 __aeabi_ldiv0 + 0x000003ac __text_end = . + +.vfp11_veneer 0x000003ac 0x0 + .vfp11_veneer 0x00000000 0x0 linker stubs + +.v4_bx 0x000003ac 0x0 + .v4_bx 0x00000000 0x0 linker stubs + +.rodata 0x000003ac 0x8 + *(.rodata) + *all.rodata*(*) + *(.roda) + *(.rodata.*) + .rodata.str1.1 + 0x000003ac 0x8 stub.o + *(.gnu.linkonce.r*) + 0x000003b4 . = ALIGN (0x4) + +.data 0x000003b4 0x0 + *(.data) + *(.data.*) + *(.gnu.linkonce.d*) + 0x000003b4 . = ALIGN (0x4) + +.bss 0x000003b4 0xc + 0x000003b4 __bss_start = . + *(.dynbss) + *(.gnu.linkonce.b*) + *(.bss*) + *(.sbss*) + *(COMMON) + 0x000003c0 . = ALIGN (0x20) + *fill* 0x000003b4 0xc 00 + 0x000003c0 __bss_end = . + 0x000003c0 __stack_end = __bss_end + 0x000004c0 __stack_addr = (__bss_end + 0x100) + 0x000004c0 __end = __stack_addr + 0x000004b0 __loader_size = (__end - __code_start) + [0x000003c0] PROVIDE (__stack_end, __stack_end) + [0x000004c0] PROVIDE (__stack_addr, __stack_addr) + [0x000000d8] PROVIDE (__got_start, __got_start) + [0x000000d8] PROVIDE (__got_end, __got_end) + [0x000003b4] PROVIDE (__bss_start, __bss_start) + [0x000003c0] PROVIDE (__bss_end, __bss_end) +LOAD start.o +LOAD stub.o +LOAD string.o +LOAD utils.o +LOAD e:/devkitpro/devkitarm/bin/../lib/gcc/arm-eabi/4.6.1/be\libgcc.a +OUTPUT(elfloader.elf elf32-bigarm) + +.ARM.attributes + 0x00000000 0x30 + .ARM.attributes + 0x00000000 0x24 start.o + .ARM.attributes + 0x00000024 0x34 stub.o + .ARM.attributes + 0x00000058 0x34 string.o + .ARM.attributes + 0x0000008c 0x34 utils.o + .ARM.attributes + 0x000000c0 0x1a e:/devkitpro/devkitarm/bin/../lib/gcc/arm-eabi/4.6.1/be\libgcc.a(_udivsi3.o) + .ARM.attributes + 0x000000da 0x18 e:/devkitpro/devkitarm/bin/../lib/gcc/arm-eabi/4.6.1/be\libgcc.a(_dvmd_tls.o) + +.comment 0x00000000 0x22 + .comment 0x00000000 0x22 stub.o + 0x23 (size before relaxing) + .comment 0x00000000 0x23 string.o + .comment 0x00000000 0x23 utils.o diff --git a/elfloader/hollywood.h b/elfloader/hollywood.h new file mode 100644 index 0000000..ce8e908 --- /dev/null +++ b/elfloader/hollywood.h @@ -0,0 +1,31 @@ +/* + mini - a Free Software replacement for the Nintendo/BroadOn IOS. + + ELF loader: Hollywood register definitions + +Copyright (C) 2008, 2009 Hector Martin "marcan" + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 2. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ +#ifndef __HOLLYWOOD_H__ +#define __HOLLYWOOD_H__ + +#define HW_REG_BASE 0xd800000 +#define HW_TIMER (HW_REG_BASE + 0x010) +#define HW_MEMMIRR (HW_REG_BASE + 0x060) +#define HW_BOOT0 (HW_REG_BASE + 0x18c) + +#endif + diff --git a/elfloader/starlet.mk b/elfloader/starlet.mk new file mode 100644 index 0000000..47051da --- /dev/null +++ b/elfloader/starlet.mk @@ -0,0 +1,12 @@ +ifeq ($(strip $(DEVKITARM)),) +$(error "Set DEVKITARM in your environment.") +endif + +PREFIX = $(DEVKITARM)/bin/arm-eabi- + +CFLAGS = -mbig-endian -mcpu=arm926ej-s +CFLAGS += -fomit-frame-pointer -ffunction-sections +CFLAGS += -Wall -Wextra -Os -pipe +ASFLAGS = +LDFLAGS = -mbig-endian -n -nostartfiles -nodefaultlibs -Wl,-gc-sections + diff --git a/elfloader/start.S b/elfloader/start.S new file mode 100644 index 0000000..8b9a7d6 --- /dev/null +++ b/elfloader/start.S @@ -0,0 +1,113 @@ +/* + mini - a Free Software replacement for the Nintendo/BroadOn IOS. + + ELF loader: system startup + +Copyright (C) 2008, 2009 Hector Martin "marcan" + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 2. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ +.arm + +.extern _main +.extern __got_start +.extern __got_end +.extern __bss_start +.extern __bss_end +.extern __stack_addr +.extern delay +.globl _start +.globl debug_output + +.section .init + +_start: + @ Get real address of _start + sub r4, pc, #8 + @ Subtract offset to get the address that we were loaded at + ldr r0, =_start + sub r4, r4, r0 + @ Output 0x42 to the debug port + mov r0, #0x42 + bl debug_output + + @ Set up a stack + ldr sp, =__stack_addr + add sp, r4 + + @ Output 0x43 to the debug port + mov r0, #0x43 + bl debug_output + + @ relocate the GOT entries + ldr r1, =__got_start + add r1, r4 + ldr r2, =__got_end + add r2, r4 +got_loop: + @ check for the end + cmp r1, r2 + beq done_got + @ read the GOT entry + ldr r3, [r1] + @ add our base address + add r3, r4 + str r3, [r1] + @ move on + add r1, r1, #4 + b got_loop + +done_got: + @ clear BSS + ldr r1, =__bss_start + add r1, r4 + ldr r2, =__bss_end + add r2, r4 + mov r3, #0 +bss_loop: + @ check for the end + cmp r1, r2 + beq done_bss + @ clear the word and move on + str r3, [r1] + add r1, r1, #4 + b bss_loop + +done_bss: + mov r0, #0x44 + bl debug_output + @ take the plunge + mov r0, r4 + bl _main + @ _main returned! Go to whatever address it returned... + mov r1, r0 + mov r0, r4 + mov pc, r1 + +.pool + +debug_output: + @ load address of port + mov r3, #0xd800000 + @ load old value + ldr r2, [r3, #0xe0] + @ clear debug byte + bic r2, r2, #0xFF0000 + @ insert new value + and r0, r0, #0xFF + orr r2, r2, r0, LSL #16 + @ store back + str r2, [r3, #0xe0] + mov pc, lr diff --git a/elfloader/start.h b/elfloader/start.h new file mode 100644 index 0000000..a3458b1 --- /dev/null +++ b/elfloader/start.h @@ -0,0 +1,30 @@ +/* + mini - a Free Software replacement for the Nintendo/BroadOn IOS. + + ELF loader: system startup + +Copyright (C) 2008, 2009 Hector Martin "marcan" + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 2. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ +#ifndef __START_H__ +#define __START_H__ + +#include "types.h" + +void debug_output(u8 byte); + +#endif + diff --git a/elfloader/start.o b/elfloader/start.o new file mode 100644 index 0000000000000000000000000000000000000000..c19df0bff5bf12b199f60a69773138505fa250ef GIT binary patch literal 1304 zcma)5&ubG=5T1>jHZ8QKDuO7uV!(iP38e-+*=k#gMErH}w(Pn~8%&dseSr!^Y3sp@ z2hoEEA$#!P!N0%r{5$F$?1Zlmbmq5HUTlZEMLp^njd0J< z`wu8LO{7O}DirQl^k}z21780Y$A?j`Sd-dyXoo?Cq&}C?{p8v!sND}pPh*jQ`@xUQ zyvdxS$1u2FjoupJ@Jl%!5XJqyGDZ7F$a`j&S#{a=Y^R=__gsGY;oTbx)zv%K9??X; zpiOD>8kzpHEnzzxMJJ7$3JGspkm=gOCe!hKGCN+wtT*eN-*N{5(JNrs24MPJM^!;Zd1$usrzb>L(n%vwOhd>fHfjM$8KXKg;fduz_D>-v(g=FSEY`VFO3~&me5zBjaK4 z&aSEiUjo(_*b}|vH#6&iwK4v9j5}kzImXqj$)!`trj3@c8m(5F+*Z@Gm=XUKnGF7s zl1r8^?2aJUbGjQ=t1H@FK^Brvo?5o+c9@`2s!Flfgo6h8OORI7?nME!_7(L_}}L#4v1C1|9gid`3GrZ3tsqv?>}_XZ zYi}c&q?Q(~zhHj6rq~fdSk(8ux%bWOqzNavbMAM(@1A?^efQpZa(?WBa+JiTqz`>7 z;Cyc*c`{P;Nw;jRmeNwcDpD=EiB6H^^2f5&o~2cNQlvJLQhQcce^zdaQ$4o2pIYjc zKc*TQj06AM@Sl$kr>OaY^tH3Ds!uR)nR(m8rD0XSE)p&bE5!F|Ib@ zs($4A^lm=N6D~D!gbOa~_`@2)#k69)RxGQ*Qdz3k#M%C`9M#*&TC#o?nPN)ly?ka`D``Gj89MfB*JOFfwu3o%8SbnWFCw4jpz+dPClE8NpT#X8cTc zCi?7$+aNoAV(9#(qt|3ZTZh`Hx|2K9PPHr1qjsx3YJYM-iC27>4>DQ!V6Ne(O)u~t z1maC)f{b|CVo^K>s4Lv@3r(~J6mqidSnhw@UMP7NHs}$JThJVC?#ThIOZ-E32z&?HzjOmSpFJ;Q z#*(^o2HvjkCa{ZU%;+v6VC&|A$BYQx=y1B%=sp1VtfR}e=t5w=8^%n&y9ikGsxIJB zBZ4=&$1OVCdfB&*?nR4k7I?jUuUd3(f!C|=wbrHK*{$H`AbZ+aJKGyfWWE`o!@hkM zsG)5`vvsF{-;vN}bo7o1inP54bb&d3HyZaPg|-pR%GVwOUqLfw@)>M=98b#XR}-X1 zvY6A@sw3j9`6A3(@VvxE92>;^d$9TF@4^Vc^9}c)q}d Wd~V^5!wVZl;q@D + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 2. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ +#include "types.h" +#include "utils.h" +#include "start.h" +#include "hollywood.h" +#include "string.h" +#include "elf.h" + +typedef struct { + u32 hdrsize; + u32 loadersize; + u32 elfsize; + u32 argument; +} ioshdr; + +void *loadelf(const u8 *elf) { + if(memcmp("\x7F" "ELF\x01\x02\x01",elf,7)) { + panic(0xE3); + } + + Elf32_Ehdr *ehdr = (Elf32_Ehdr*)elf; + if(ehdr->e_phoff == 0) { + panic(0xE4); + } + int count = ehdr->e_phnum; + Elf32_Phdr *phdr = (Elf32_Phdr*)(elf + ehdr->e_phoff); + while(count--) + { + if(phdr->p_type == PT_LOAD) { + const void *src = elf + phdr->p_offset; + memcpy(phdr->p_paddr, src, phdr->p_filesz); + } + phdr++; + } + return ehdr->e_entry; +} + +static inline void disable_boot0() +{ + set32(HW_BOOT0, 0x1000); +} + +static inline void mem_setswap() +{ + set32(HW_MEMMIRR, 0x20); +} + +void *_main(void *base) +{ + ioshdr *hdr = (ioshdr*)base; + u8 *elf; + void *entry; + + elf = (u8*) base; + elf += hdr->hdrsize + hdr->loadersize; + + debug_output(0xF1); + mem_setswap(1); + disable_boot0(1); + + entry = loadelf(elf); + debug_output(0xC1); + return entry; + +} + diff --git a/elfloader/stub.ld b/elfloader/stub.ld new file mode 100644 index 0000000..11d8b4f --- /dev/null +++ b/elfloader/stub.ld @@ -0,0 +1,117 @@ +/* + elfloader - a Free Software replacement for the Nintendo/BroadOn IOS. + +Copyright (C) 2008, 2009 Hector Martin "marcan" + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 2. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ +OUTPUT_FORMAT("elf32-bigarm") +OUTPUT_ARCH(arm) +EXTERN(_start) +ENTRY(_start) + +__base_addr = 0; + +SECTIONS +{ + . = __base_addr; + .header : + { + __header = .; + /* Entry point (offset) */ + LONG(__code_start); + /* Loader size */ + LONG(__loader_size); + /* ELF size */ + LONG(0); + /* Boot argument? */ + LONG(0); + . = ALIGN(16); + } + + __code_start = .; + + .init : + { + *(.init) + . = ALIGN(4); + } + + .got : + { + __got_start = .; + *(.got.*) + *(.got) + . = ALIGN(4); + __got_end = . ; + } + + .text : + { + *(.text.*) + *(.gnu.warning) + *(.gnu.linkonce.t*) + *(.glue_7) + *(.glue_7t) + . = ALIGN(4); + } + + __text_end = . ; + + .rodata : + { + *(.rodata) + *all.rodata*(*) + *(.roda) + *(.rodata.*) + *(.gnu.linkonce.r*) + . = ALIGN(4); + } + + .data : + { + *(.data) + *(.data.*) + *(.gnu.linkonce.d*) + . = ALIGN(4); + } + + .bss : + { + __bss_start = . ; + *(.dynbss) + *(.gnu.linkonce.b*) + *(.bss*) + *(.sbss*) + *(COMMON) + . = ALIGN(32); + __bss_end = . ; + } + +} + +__stack_end = (__bss_end); +__stack_addr = (__bss_end + 0x100); + +__end = __stack_addr ; +__loader_size = __end - __code_start; + +PROVIDE (__stack_end = __stack_end); +PROVIDE (__stack_addr = __stack_addr); +PROVIDE (__got_start = __got_start); +PROVIDE (__got_end = __got_end); +PROVIDE (__bss_start = __bss_start); +PROVIDE (__bss_end = __bss_end); + diff --git a/elfloader/stub.o b/elfloader/stub.o new file mode 100644 index 0000000000000000000000000000000000000000..7b7bc9f564e790d4c1bce6a44383e7d22b5ee78c GIT binary patch literal 1832 zcma)6TTc^F5S{}Ih=Q(0B(WG+%SEDwha%uD7#m3R#RRtPstqk|*sV%J0!H+S zL=xrAg#Hjr^gsCEV@ut{%MJDvC$?QK#>ic# zg>q5XN^gn4Z}?TM{;kA`j$+TmZwwSND&w2jp`=tuv)O0A{k zSZ!%3reW?aua_c;pe`3lW6ZsS^VzpaLmhol?cc4Dk?Y||%6c}Fc7`YJh3Bk{W!hG_ zf3Pb&Ukd>P0LKAz3uI)1MOPh;Mm=sNvf|qA{xah?X)-}T54NGn`jpuTDKs> zp3gdF0@|7L^;2az)(eM>l3?IFC2h#!F*#_N{#g7b!CZC0AJW6;6=a2x3$-h+L-4Dc#M4OMRfjz;Cg zvcJOS|LQn|dtn~;{}d9O_Yd$WL=9Ch1xKJ>1IJZ8uA}NXu(@6z1VhB|;kX(cV|gWY z)DMW;&=-8$`zqc_es_-%5Ht7$&yIOKPD0dKz!dBFe1NE-c&uxb6K!vR`w932gqmsCo)3z2n!Yx}}_~QEVqBai9+`9+=O=YEM-e#>XTGA(?R-q*eMD z?+g^j6;&Z`HX}4-ZLxX+%MmgU_N8!uSgE#h_qSZ`P?1I=iFd^(B}I4`D$%m z5yYEd^vH^ + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 2. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ +#ifndef __TYPES_H__ +#define __TYPES_H__ + +typedef unsigned char u8; +typedef unsigned short u16; +typedef unsigned int u32; +typedef unsigned long long u64; + +typedef signed char s8; +typedef signed short s16; +typedef signed int s32; +typedef signed long long s64; + +typedef volatile unsigned char vu8; +typedef volatile unsigned short vu16; +typedef volatile unsigned int vu32; +typedef volatile unsigned long long vu64; + +typedef volatile signed char vs8; +typedef volatile signed short vs16; +typedef volatile signed int vs32; +typedef volatile signed long long vs64; + +typedef s32 size_t; + +#define NULL ((void *)0) + +#endif + diff --git a/elfloader/utils.c b/elfloader/utils.c new file mode 100644 index 0000000..df3426b --- /dev/null +++ b/elfloader/utils.c @@ -0,0 +1,45 @@ +/* + mini - a Free Software replacement for the Nintendo/BroadOn IOS. + + ELF loader: random utilities + +Copyright (C) 2008, 2009 Hector Martin "marcan" + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 2. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ +#include "types.h" +#include "utils.h" +#include "hollywood.h" +#include "start.h" + +void udelay(u32 d) +{ + // should be good to max .2% error + u32 ticks = d * 19 / 10; + + write32(HW_TIMER, 0); + while(read32(HW_TIMER) < ticks); +} + +void panic(u8 v) +{ + while(1) { + debug_output(v); + udelay(500000); + debug_output(0); + udelay(500000); + } +} + diff --git a/elfloader/utils.h b/elfloader/utils.h new file mode 100644 index 0000000..698c95b --- /dev/null +++ b/elfloader/utils.h @@ -0,0 +1,188 @@ +/* + mini - a Free Software replacement for the Nintendo/BroadOn IOS. + + ELF loader: random utilities + +Copyright (C) 2008, 2009 Hector Martin "marcan" + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 2. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ +#ifndef __UTILS_H__ +#define __UTILS_H__ + +static inline u32 read32(u32 addr) +{ + u32 data; + __asm__ volatile ("ldr\t%0, [%1]" : "=r" (data) : "r" (addr)); + return data; +} + +static inline void write32(u32 addr, u32 data) +{ + __asm__ volatile ("str\t%0, [%1]" : : "r" (data), "r" (addr)); +} + +static inline u32 set32(u32 addr, u32 set) +{ + u32 data; + __asm__ volatile ( + "ldr\t%0, [%1]\n" + "\torr\t%0, %2\n" + "\tstr\t%0, [%1]" + : "=&r" (data) + : "r" (addr), "r" (set) + ); + return data; +} + +static inline u32 clear32(u32 addr, u32 clear) +{ + u32 data; + __asm__ volatile ( + "ldr\t%0, [%1]\n" + "\tbic\t%0, %2\n" + "\tstr\t%0, [%1]" + : "=&r" (data) + : "r" (addr), "r" (clear) + ); + return data; +} + + +static inline u32 mask32(u32 addr, u32 clear, u32 set) +{ + u32 data; + __asm__ volatile ( + "ldr\t%0, [%1]\n" + "\tbic\t%0, %3\n" + "\torr\t%0, %2\n" + "\tstr\t%0, [%1]" + : "=&r" (data) + : "r" (addr), "r" (set), "r" (clear) + ); + return data; +} + +static inline u16 read16(u32 addr) +{ + u32 data; + __asm__ volatile ("ldrh\t%0, [%1]" : "=r" (data) : "r" (addr)); + return data; +} + +static inline void write16(u32 addr, u16 data) +{ + __asm__ volatile ("strh\t%0, [%1]" : : "r" (data), "r" (addr)); +} + +static inline u16 set16(u32 addr, u16 set) +{ + u16 data; + __asm__ volatile ( + "ldrh\t%0, [%1]\n" + "\torr\t%0, %2\n" + "\tstrh\t%0, [%1]" + : "=&r" (data) + : "r" (addr), "r" (set) + ); + return data; +} + +static inline u16 clear16(u32 addr, u16 clear) +{ + u16 data; + __asm__ volatile ( + "ldrh\t%0, [%1]\n" + "\tbic\t%0, %2\n" + "\tstrh\t%0, [%1]" + : "=&r" (data) + : "r" (addr), "r" (clear) + ); + return data; +} + + +static inline u16 mask16(u32 addr, u16 clear, u16 set) +{ + u16 data; + __asm__ volatile ( + "ldrh\t%0, [%1]\n" + "\tbic\t%0, %3\n" + "\torr\t%0, %2\n" + "\tstrh\t%0, [%1]" + : "=&r" (data) + : "r" (addr), "r" (set), "r" (clear) + ); + return data; +} + +static inline u8 read8(u32 addr) +{ + u32 data; + __asm__ volatile ("ldrb\t%0, [%1]" : "=r" (data) : "r" (addr)); + return data; +} + +static inline void write8(u32 addr, u8 data) +{ + __asm__ volatile ("strb\t%0, [%1]" : : "r" (data), "r" (addr)); +} + +static inline u8 set8(u32 addr, u8 set) +{ + u8 data; + __asm__ volatile ( + "ldrb\t%0, [%1]\n" + "\torr\t%0, %2\n" + "\tstrb\t%0, [%1]" + : "=&r" (data) + : "r" (addr), "r" (set) + ); + return data; +} + +static inline u8 clear8(u32 addr, u8 clear) +{ + u8 data; + __asm__ volatile ( + "ldrb\t%0, [%1]\n" + "\tbic\t%0, %2\n" + "\tstrb\t%0, [%1]" + : "=&r" (data) + : "r" (addr), "r" (clear) + ); + return data; +} + + +static inline u8 mask8(u32 addr, u8 clear, u8 set) +{ + u8 data; + __asm__ volatile ( + "ldrb\t%0, [%1]\n" + "\tbic\t%0, %3\n" + "\torr\t%0, %2\n" + "\tstrb\t%0, [%1]" + : "=&r" (data) + : "r" (addr), "r" (set), "r" (clear) + ); + return data; +} + +void udelay(u32 d); +void panic(u8 v); + +#endif + diff --git a/elfloader/utils.o b/elfloader/utils.o new file mode 100644 index 0000000000000000000000000000000000000000..f93734e86435dc6dc7d4369b8ec75f24d0efe424 GIT binary patch literal 1236 zcmb7D&ubG=5T4g=YFe8bYs6|*Rt%U*xuJi4_w|%$b!0fzleta`;miK1!$wM(FC=)>yKAVnbIRuxJ zj0zQK>f7R4e%P;F_(F6v>=&ng#PQ$Ju|3B=8ogybu1$}QY#MA6t;X@6ub&R{g+nTG zU2)J~qd}jnw1!Hs!#8 zcka+SPqpOwZZk+mUdVCU{k!$e$BR#CB9|AFV%92&i{jGwoVYBmi0f8WkP{wsq}yaG zd#Qb?Ptt!a$?;t2lG6-Ba=4`frxSU8+dVKGU3WKVk<;4ibo^Z|;?9mMWiMz((hqsA z|B-o4#?B{HQM&CD2K_&7sJ!u0@@{cF&w5&3P4St1R}?plrOs8hlj;oj2mXNnEPzsA z{15XUZN})KMe{vihspPmvCRrT%z`}dZLxw+bG+m8O;#<4L3g?*cSYGLwXyUsXxKnQ%V-Lne$-drmvB1eR;5p_SQmH)Vxu zjKOzX;bdtP$)FuNEh@WI_NdWF9&jTHykMWyJ4;`e=QpDljlD>ABWyO=c>!;Q=PkmP Oh-P4~D$IRn=KleD*^Yw% literal 0 HcmV?d00001 diff --git a/tools/bin2h/bin2h.exe b/tools/bin2h/bin2h.exe new file mode 100644 index 0000000000000000000000000000000000000000..bbd62bb992f98a183ef2e5fbf170ad8ecba072b4 GIT binary patch literal 7680 zcmeHM3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SQpZgy{C9qB#$19OCr_pY92K=D&xJ?*#h0N1Ka~?NGXwHXt=VN#Y~B!+lI| zBpj7$ixe?hCHVzD;*-`!LVhtO#e(u$+_P0aDN?%EUc^Lv(NK_=OABB>iUkPkLk1cCeIqzaoa@KHU#}F{=^zClt)W2RveEFOGN@FWnK&6}x+3 zN-wTW{9ZoHgek5q@<|Q)B`g*(N@%^GUV*hmL0?$niyp37cgOc9jqmuMqjAsdHS0bR zE532hCJpnNb+h$+*n?+jU0uWG$J*L5o&V05{%@xP>$b#JWGlDT+8(#bj=yo7aD2yc z(lP3|;z&9E)sfBK$F60|**|2P*>-j(dw}g{zsw$EzskPKzQ(@6US!{6-)DcqPOvxF zk6Dv5&$-6wbk;gII=|>_b%va>^C{;M=d;cioZoW3>in)V>3q}qediCHW6rD2kDRxh zGfoTldCtz2bG6(?u7P`;YvDS%0Jnz|xjyaycbGfM9p_%;{)+oHH_V;p{+=7-e#HF? zcbl8xjAfRx2g*vyqGfW~{<8kEqh((y`^&O7%FdPjQ`zk@L;1ty8_NUbq4LA!D=XGk zJW|nF@kGUw6(3YwtGH3IuyRM`uF9`fzFB#(@`K8sR(@3Z%gPm1tE +#include +#include +#include +#include +#include + +int main( int argc, char *argv[] ) +{ + if( argc != 2 ) + { + return 0; + } + + FILE *in = fopen( argv[1], "rb" ); + if( in == NULL ) + { + printf("couldn't open:\"%s\"\n", argv[1] ); + return -1; + } + + fseek( in, 0, SEEK_END ); + unsigned int size = ftell(in); + fseek( in, 0, 0 ); + + int point=0; + int slash=0; + + for( int i = strlen(argv[1]) - 1; i > 0; --i ) + { + if( argv[1][i] == '.' && point == 0 ) + point = strlen(argv[1]) - i; + + if( argv[1][i] == '\\' || argv[1][i] == '/' ) + { + slash = i + 1; + break; + } + } + + char * str = new char[ strlen(argv[1]) - slash - point + 3 ]; // '.' 'h' '\0' + + memcpy( str, argv[1]+slash, strlen(argv[1]) - slash - point ); + + str[ strlen(argv[1]) - slash - point + 0 ] = '.'; + str[ strlen(argv[1]) - slash - point + 1 ] = 'h'; + str[ strlen(argv[1]) - slash - point + 2 ] = '\0'; + + printf("Using:\"%s\" for name\n", str ); + + FILE *out = fopen( str, "wb" ); + + str[ strlen(argv[1]) - slash - point ] = '\0'; + + fprintf( out, "/*\n\tFilename : %s\n", argv[1] ); + + time_t t; + time(&t); + + fprintf( out, "\tDate created: %s*/\n\n", ctime (&t) ); + + fprintf( out, "#define %s_size 0x%x\n\n", str, size ); + + fprintf( out, "unsigned char %s[] = {\n\n\t", str ); + + for( int i=0; i < size; ++i ) + { + fprintf( out, "0x%02X", fgetc(in) ); + + if( i+1 != size ) + fprintf( out, ", " ); + + if( ((i+1) & 0xF) == 0 ) + fprintf( out, "\n" ); + + if( ((i+1) & 0x3) == 0 ) + fprintf( out, "\t" ); + } + + fprintf( out, "\n};\n" ); + + fclose( out ); + free( str ); + + return 0; +} \ No newline at end of file