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
This commit is contained in:
parent
ef7ac95153
commit
d103461fa9
@ -1,4 +1,4 @@
|
|||||||
@echo off
|
@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 %devkitpro:~1,1%:\%devkitpro:~3%\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 (*.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 "C:\Users\crediar\Documents\Visual Studio 2010\Projects\bin2h\Release\bin2h.exe" %%~ni.bin
|
for /R %%i in (*.bin) DO "..\tools\bin2h\bin2h.exe" %%~ni.bin
|
||||||
|
7
elfloader/.deps/string.d
Normal file
7
elfloader/.deps/string.d
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
string.o: string.c ../string.c ../string.h ../global.h
|
||||||
|
|
||||||
|
../string.c:
|
||||||
|
|
||||||
|
../string.h:
|
||||||
|
|
||||||
|
../global.h:
|
18
elfloader/.deps/stub.d
Normal file
18
elfloader/.deps/stub.d
Normal file
@ -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:
|
9
elfloader/.deps/utils.d
Normal file
9
elfloader/.deps/utils.d
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
utils.o: utils.c types.h utils.h hollywood.h start.h
|
||||||
|
|
||||||
|
types.h:
|
||||||
|
|
||||||
|
utils.h:
|
||||||
|
|
||||||
|
hollywood.h:
|
||||||
|
|
||||||
|
start.h:
|
23
elfloader/Makefile
Normal file
23
elfloader/Makefile
Normal file
@ -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)
|
||||||
|
|
60
elfloader/common.mk
Normal file
60
elfloader/common.mk
Normal file
@ -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 $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(<F) | tr . _)`.h
|
||||||
|
@echo "extern const u8" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(<F) | tr . _)`.h
|
||||||
|
@echo "extern const u32" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(<F) | tr . _)`.h
|
||||||
|
endef
|
||||||
|
|
||||||
|
-include $(DEPDIR)/*
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
|
66
elfloader/elf.h
Normal file
66
elfloader/elf.h
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
mini - a Free Software replacement for the Nintendo/BroadOn IOS.
|
||||||
|
|
||||||
|
ELF loader: ELF structures
|
||||||
|
|
||||||
|
Copyright (C) 2008, 2009 Hector Martin "marcan" <marcan@marcansoft.com>
|
||||||
|
|
||||||
|
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
|
||||||
|
|
168
elfloader/elfloader.elf.map
Normal file
168
elfloader/elfloader.elf.map
Normal file
@ -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
|
31
elfloader/hollywood.h
Normal file
31
elfloader/hollywood.h
Normal file
@ -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" <marcan@marcansoft.com>
|
||||||
|
|
||||||
|
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
|
||||||
|
|
12
elfloader/starlet.mk
Normal file
12
elfloader/starlet.mk
Normal file
@ -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
|
||||||
|
|
113
elfloader/start.S
Normal file
113
elfloader/start.S
Normal file
@ -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" <marcan@marcansoft.com>
|
||||||
|
|
||||||
|
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
|
30
elfloader/start.h
Normal file
30
elfloader/start.h
Normal file
@ -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" <marcan@marcansoft.com>
|
||||||
|
|
||||||
|
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
|
||||||
|
|
BIN
elfloader/start.o
Normal file
BIN
elfloader/start.o
Normal file
Binary file not shown.
1
elfloader/string.c
Normal file
1
elfloader/string.c
Normal file
@ -0,0 +1 @@
|
|||||||
|
#include "../string.c"
|
1
elfloader/string.h
Normal file
1
elfloader/string.h
Normal file
@ -0,0 +1 @@
|
|||||||
|
#include "../string.h"
|
BIN
elfloader/string.o
Normal file
BIN
elfloader/string.o
Normal file
Binary file not shown.
86
elfloader/stub.c
Normal file
86
elfloader/stub.c
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
mini - a Free Software replacement for the Nintendo/BroadOn IOS.
|
||||||
|
|
||||||
|
ELF loader
|
||||||
|
|
||||||
|
Copyright (C) 2008, 2009 Hector Martin "marcan" <marcan@marcansoft.com>
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
117
elfloader/stub.ld
Normal file
117
elfloader/stub.ld
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
/*
|
||||||
|
elfloader - a Free Software replacement for the Nintendo/BroadOn IOS.
|
||||||
|
|
||||||
|
Copyright (C) 2008, 2009 Hector Martin "marcan" <marcan@marcansoft.com>
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
BIN
elfloader/stub.o
Normal file
BIN
elfloader/stub.o
Normal file
Binary file not shown.
50
elfloader/types.h
Normal file
50
elfloader/types.h
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
mini - a Free Software replacement for the Nintendo/BroadOn IOS.
|
||||||
|
|
||||||
|
ELF loader: types
|
||||||
|
|
||||||
|
Copyright (C) 2008, 2009 Hector Martin "marcan" <marcan@marcansoft.com>
|
||||||
|
|
||||||
|
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
|
||||||
|
|
45
elfloader/utils.c
Normal file
45
elfloader/utils.c
Normal file
@ -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" <marcan@marcansoft.com>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
188
elfloader/utils.h
Normal file
188
elfloader/utils.h
Normal file
@ -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" <marcan@marcansoft.com>
|
||||||
|
|
||||||
|
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
|
||||||
|
|
BIN
elfloader/utils.o
Normal file
BIN
elfloader/utils.o
Normal file
Binary file not shown.
BIN
tools/bin2h/bin2h.exe
Normal file
BIN
tools/bin2h/bin2h.exe
Normal file
Binary file not shown.
86
tools/bin2h/main.cpp
Normal file
86
tools/bin2h/main.cpp
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <memory.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user