Skip to content

Commit 128672f

Browse files
committed
Elf Time!
Switching to .elf format
1 parent 0cebc3a commit 128672f

15 files changed

+1353
-0
lines changed

Makefile

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
#---------------------------------------------------------------------------------
2+
# Clear the implicit built in rules
3+
#---------------------------------------------------------------------------------
4+
.SUFFIXES:
5+
#---------------------------------------------------------------------------------
6+
ifeq ($(strip $(DEVKITPPC)),)
7+
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
8+
endif
9+
export PORTLIBS := ../../portlibs/ppc
10+
export PATH := $(DEVKITPPC)/bin:$(PORTLIBS)/bin:$(PATH)
11+
export LIBOGC_INC := $(DEVKITPRO)/libogc/include
12+
export LIBOGC_LIB := $(DEVKITPRO)/libogc/lib/wii
13+
14+
PREFIX := powerpc-eabi-
15+
16+
export AS := $(PREFIX)as
17+
export CC := $(PREFIX)gcc
18+
export CXX := $(PREFIX)g++
19+
export AR := $(PREFIX)ar
20+
export LD := $(PREFIX)ld
21+
export OBJCOPY := $(PREFIX)objcopy
22+
23+
#---------------------------------------------------------------------------------
24+
# TARGET is the name of the output
25+
# BUILD is the directory where object files & intermediate files will be placed
26+
# SOURCES is a list of directories containing source code
27+
# INCLUDES is a list of directories containing extra header files
28+
#---------------------------------------------------------------------------------
29+
TARGET := boot
30+
BUILD := build
31+
BUILD_DBG := $(BUILD)_dbg
32+
SOURCES := src
33+
DATA := data
34+
INCLUDES :=
35+
36+
#---------------------------------------------------------------------------------
37+
# options for code generation
38+
#---------------------------------------------------------------------------------
39+
CFLAGS := -std=gnu99 -nostdinc -fno-builtin $(INCLUDE)
40+
LDFLAGS := -nostartfiles -nostdlib
41+
42+
#---------------------------------------------------------------------------------
43+
# move loader to another location - THANKS CREDIAR - 0x81330000 for HBC
44+
#---------------------------------------------------------------------------------
45+
#LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map
46+
#LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map -Wl,--section-start,.init=0x80003f00
47+
Q := @
48+
MAKEFLAGS += --no-print-directory
49+
#---------------------------------------------------------------------------------
50+
# any extra libraries we wish to link with the project
51+
#---------------------------------------------------------------------------------
52+
#LIBS :=
53+
54+
#---------------------------------------------------------------------------------
55+
# list of directories containing libraries, this must be the top level containing
56+
# include and lib
57+
#---------------------------------------------------------------------------------
58+
#LIBDIRS := $(CURDIR)
59+
60+
#---------------------------------------------------------------------------------
61+
# no real need to edit anything past this point unless you need to add additional
62+
# rules for different file extensions
63+
#---------------------------------------------------------------------------------
64+
ifneq ($(BUILD),$(notdir $(CURDIR)))
65+
#---------------------------------------------------------------------------------
66+
67+
export OUTPUT := $(CURDIR)/$(TARGET)
68+
69+
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
70+
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
71+
72+
export DEPSDIR := $(CURDIR)/$(BUILD)
73+
74+
#---------------------------------------------------------------------------------
75+
# automatically build a list of object files for our project
76+
#---------------------------------------------------------------------------------
77+
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
78+
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
79+
sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
80+
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
81+
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
82+
PNGFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.png)))
83+
84+
#---------------------------------------------------------------------------------
85+
# use CXX for linking C++ projects, CC for standard C
86+
#---------------------------------------------------------------------------------
87+
export OFILES := $(addsuffix .o,$(BINFILES)) \
88+
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \
89+
$(sFILES:.s=.o) $(SFILES:.S=.o)
90+
91+
#---------------------------------------------------------------------------------
92+
# build a list of include paths
93+
#---------------------------------------------------------------------------------
94+
export INCLUDE := $(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \
95+
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
96+
-I$(CURDIR)/$(BUILD) \
97+
-I$(LIBOGC_INC)
98+
99+
#---------------------------------------------------------------------------------
100+
# build a list of library paths
101+
#---------------------------------------------------------------------------------
102+
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \
103+
-L$(LIBOGC_LIB)
104+
105+
export OUTPUT := $(CURDIR)/$(TARGET)
106+
.PHONY: $(BUILD) clean install
107+
108+
#---------------------------------------------------------------------------------
109+
$(BUILD):
110+
@[ -d $@ ] || mkdir -p $@
111+
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
112+
113+
#---------------------------------------------------------------------------------
114+
clean:
115+
@echo clean ...
116+
@rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).bin
117+
118+
#This should stop new builds from using old code (-SonyUSA)
119+
@rm -fr build
120+
#And just because I'm picky... (-SonyUSA)
121+
@mkdir bin
122+
@mv boot.elf /bin/
123+
@mv build_dbg.elf /bin/
124+
125+
#---------------------------------------------------------------------------------
126+
else
127+
128+
DEPENDS := $(OFILES:.o=.d)
129+
130+
#---------------------------------------------------------------------------------
131+
# main targets
132+
#---------------------------------------------------------------------------------
133+
$(OUTPUT).elf: $(OFILES)
134+
135+
#---------------------------------------------------------------------------------
136+
# This rule links in binary data with the .jpg extension
137+
#---------------------------------------------------------------------------------
138+
%.elf: link.ld $(OFILES)
139+
@echo "linking ... $(TARGET).elf"
140+
$(Q)$(CC) -n -T $^ $(LDFLAGS) -o ../$(BUILD_DBG).elf
141+
$(Q)$(OBJCOPY) -S -R .comment -R .gnu.attributes ../$(BUILD_DBG).elf $@
142+
143+
%.o: %.c
144+
@echo "$@"
145+
$(Q)$(CC) $(CFLAGS) -c $< -o $@
146+
147+
%.o: %.s
148+
@echo "$@"
149+
$(Q)$(CC) $(CFLAGS) -c $< -o $@
150+
151+
-include $(DEPENDS)
152+
153+
#---------------------------------------------------------------------------------
154+
endif
155+
#---------------------------------------------------------------------------------

old/Makefile old-DoNotUse/Makefile

File renamed without changes.

old/loader.c old-DoNotUse/loader.c

File renamed without changes.

old/loader.h old-DoNotUse/loader.h

File renamed without changes.

src/coreinit.h

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#ifndef COREINIT_H
2+
#define COREINIT_H
3+
4+
#include "types.h"
5+
6+
#if (VER==200)
7+
#define OSDynLoad_Acquire ((void (*)(char* rpl, unsigned int *handle))0x010220AC)
8+
#define OSDynLoad_FindExport ((void (*)(unsigned int handle, int isdata, char *symbol, void *address))0x01022D98)
9+
#define OSFatal ((void (*)(char* msg))0x01027688)
10+
#define __os_snprintf ((int(*)(char* s, int n, const char * format, ... ))0x01025FB4)
11+
#elif (VER==210)
12+
#define OSDynLoad_Acquire ((void (*)(char* rpl, unsigned int *handle))0x0102232C)
13+
#define OSDynLoad_FindExport ((void (*)(unsigned int handle, int isdata, char *symbol, void *address))0x01023018)
14+
#define OSFatal ((void (*)(char* msg))0x01027908)
15+
#define __os_snprintf ((int(*)(char* s, int n, const char * format, ... ))0x01026014)
16+
#elif (VER==300) | (VER==310)
17+
#define OSDynLoad_Acquire ((void (*)(char* rpl, unsigned int *handle))0x01022CBC)
18+
#define OSDynLoad_FindExport ((void (*)(unsigned int handle, int isdata, char *symbol, void *address))0x01023D88)
19+
#define OSFatal ((void (*)(char* msg))0x01028A68)
20+
#define __os_snprintf ((int(*)(char* s, int n, const char * format, ... ))0x01027390)
21+
#elif (VER==400) | (VER==410)
22+
#define OSDynLoad_Acquire ((void (*)(char* rpl, unsigned int *handle))0x01026e60)
23+
#define OSDynLoad_FindExport ((void (*)(unsigned int handle, int isdata, char *symbol, void *address))0x01028460)
24+
#define OSFatal ((void (*)(char* msg))0x0102D01C)
25+
#define __os_snprintf ((int(*)(char* s, int n, const char * format, ... ))0x0102b9ac)
26+
#elif VER==500
27+
#define OSDynLoad_Acquire ((void (*)(char* rpl, unsigned int *handle))0x01029CD8)
28+
#define OSDynLoad_FindExport ((void (*)(unsigned int handle, int isdata, char *symbol, void *address))0x0102B3E4)
29+
#define OSFatal ((void (*)(char* msg))0x01030ECC)
30+
#define __os_snprintf ((int(*)(char* s, int n, const char * format, ... ))0x0102ECE0)
31+
#elif VER==532
32+
#define OSDynLoad_Acquire ((void (*)(char* rpl, unsigned int *handle))0x102a31c)
33+
#define OSDynLoad_FindExport ((void (*)(unsigned int handle, int isdata, char *symbol, void *address))0x102b790)
34+
#define OSFatal ((void (*)(char* msg))0x1031368)
35+
#define __os_snprintf ((int(*)(char* s, int n, const char * format, ... ))0x102f09c)
36+
#elif VER==550
37+
#define OSDynLoad_Acquire ((void (*)(char* rpl, unsigned int *handle))0x0102A3B4)
38+
#define OSDynLoad_FindExport ((void (*)(unsigned int handle, int isdata, char *symbol, void *address))0x0102B828)
39+
#define OSFatal ((void (*)(char* msg))0x01031618)
40+
#define __os_snprintf ((int(*)(char* s, int n, const char * format, ... ))0x0102F160)
41+
#else
42+
//#error "Unsupported Wii U software version"
43+
// Do nothing, for elf compilation
44+
#endif
45+
46+
/* ioctlv() I/O vector */
47+
struct iovec
48+
{
49+
void *buffer;
50+
int len;
51+
char unknown8[0xc-0x8];
52+
};
53+
54+
typedef struct OSContext
55+
{
56+
/* OSContext identifier */
57+
uint32_t tag1;
58+
uint32_t tag2;
59+
60+
/* GPRs */
61+
uint32_t gpr[32];
62+
63+
/* Special registers */
64+
uint32_t cr;
65+
uint32_t lr;
66+
uint32_t ctr;
67+
uint32_t xer;
68+
69+
/* Initial PC and MSR */
70+
uint32_t srr0;
71+
uint32_t srr1;
72+
} OSContext;
73+
74+
#endif /* COREINIT_H */

src/crt0.S

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
.extern _memset
3+
.extern _doInit
4+
.extern _main
5+
.extern _doExit
6+
7+
.globl _start
8+
_start:
9+
# Setup stack.
10+
lis 1,_stack_top@ha ; addi 1,1,_stack_top@l ; li 0,0 ; stwu 0,-64(1)
11+
12+
# Clear BSS.
13+
lis 3,__bss_start@ha ; addi 3,3,__bss_start@l
14+
li 4,0
15+
lis 5,__bss_end@ha ; addi 5,5,__bss_end@l ; sub 5,5,3
16+
bl _memset
17+
18+
bl _doInit
19+
bl _main
20+
# Return to old stack for exit
21+
lis 1, 0x1ab5 ; ori 1, 1, 0xd138
22+
bl _doExit

0 commit comments

Comments
 (0)