diff --git a/Makefile b/Makefile index 7ca76aa..b06b74d 100644 --- a/Makefile +++ b/Makefile @@ -4,20 +4,11 @@ EE_OBJS = main.o cnf_lite.o EE_INCS := -I$(PS2SDK)/ee/include -I$(PS2SDK)/common/include -I. EE_GPVAL = -G0 EE_CFLAGS = -D_EE -Os -mno-gpopt $(EE_GPVAL) -Wall $(EE_INCS) -EE_LDFLAGS = -Tlinkfile -L$(PS2SDK)/ee/lib -s -EE_LIBS += -lcdvd -ldebug -lc -lkernel-nopatch +EE_LIBS += -ldebug +EE_NEWLIB_NANO ?= 1 +EE_COMPACT_EXECUTABLE ?= 1 -%.o : %.c - $(EE_CC) $(EE_CFLAGS) $(EE_INCS) -c $< -o $@ - -%.o : %.S - $(EE_CC) $(EE_CFLAGS) $(EE_INCS) -c $< -o $@ - -%.o : %.s - $(EE_AS) $(EE_ASFLAGS) $< -o $@ - -$(EE_BIN) : $(EE_OBJS) - $(EE_CC) $(EE_CFLAGS) $(EE_LDFLAGS) -o $(EE_BIN) $(EE_OBJS) $(EE_LIBS) +EE_LINKFILE ?= linkfile all: $(EE_BIN) @@ -25,3 +16,4 @@ clean: rm -f $(EE_OBJS) $(EE_BIN) include $(PS2SDK)/Defs.make +include $(PS2SDK)/samples/Makefile.eeglobal \ No newline at end of file diff --git a/cnf_lite.c b/cnf_lite.c index 6e75f3e..c2ec88b 100644 --- a/cnf_lite.c +++ b/cnf_lite.c @@ -2,6 +2,9 @@ #include #include +#define NEWLIB_PORT_AWARE +#include + #include "cnf_lite.h" // Function prototypes. diff --git a/linkfile b/linkfile index fc2a08c..5663d22 100644 --- a/linkfile +++ b/linkfile @@ -1,97 +1,70 @@ -ENTRY(_start); +ENTRY(__start); + +MEMORY { + bios : ORIGIN = 0x00000000, LENGTH = 528K /* 0x00000000 - 0x00084000: BIOS memory */ + bram : ORIGIN = 0x00084000, LENGTH = 496K /* 0x00084000 - 0x00100000: BIOS unused memory */ + gram : ORIGIN = 0x00100000, LENGTH = 31M /* 0x00100000 - 0x02000000: GAME memory */ +} + +REGION_ALIAS("MAIN_REGION", bram); + +PHDRS { + text PT_LOAD; +} SECTIONS { - .text 0x00084000: { - _ftext = . ; + .text : { *(.text) - *(.text.*) - *(.gnu.linkonce.t*) - KEEP(*(.init)) - KEEP(*(.fini)) - QUAD(0) - } - - PROVIDE(_etext = .); - PROVIDE(etext = .); + } >MAIN_REGION :text - .reginfo : { *(.reginfo) } + .reginfo : { *(.reginfo) } >MAIN_REGION - /* Global/static constructors and deconstructors. */ .ctors ALIGN(16): { KEEP(*crtbegin*.o(.ctors)) KEEP(*(EXCLUDE_FILE(*crtend*.o) .ctors)) KEEP(*(SORT(.ctors.*))) KEEP(*(.ctors)) - } + } >MAIN_REGION + .dtors ALIGN(16): { KEEP(*crtbegin*.o(.dtors)) KEEP(*(EXCLUDE_FILE(*crtend*.o) .dtors)) KEEP(*(SORT(.dtors.*))) KEEP(*(.dtors)) - } + } >MAIN_REGION - /* Static data. */ .rodata ALIGN(128): { *(.rodata) - *(.rodata.*) - *(.gnu.linkonce.r*) - } + } >MAIN_REGION .data ALIGN(128): { _fdata = . ; *(.data) - *(.data.*) - *(.gnu.linkonce.d*) SORT(CONSTRUCTORS) - } - - .rdata ALIGN(128): { *(.rdata) } - .gcc_except_table ALIGN(128): { *(.gcc_except_table) } + } >MAIN_REGION _gp = ALIGN(128) + 0x7ff0; - .lit4 ALIGN(128): { *(.lit4) } - .lit8 ALIGN(128): { *(.lit8) } + .lit4 ALIGN(128): { *(.lit4) } >MAIN_REGION + .lit8 ALIGN(128): { *(.lit8) } >MAIN_REGION .sdata ALIGN(128): { *(.sdata) - *(.sdata.*) - *(.gnu.linkonce.s*) - } - - _edata = .; - PROVIDE(edata = .); + } >MAIN_REGION - /* Uninitialized data. */ .sbss ALIGN(128) : { _fbss = . ; *(.sbss) - *(.sbss.*) - *(.gnu.linkonce.sb*) - *(.scommon) - } + } >MAIN_REGION .bss ALIGN(128) : { *(.bss) - *(.bss.*) - *(.gnu.linkonce.b*) - *(COMMON) - } - _end_bss = .; + } >MAIN_REGION /* Symbols needed by crt0.s. */ - PROVIDE(_heap_size = 0x2000); - PROVIDE(_stack_size = 0x2000); + PROVIDE(_end = .); + PROVIDE(_heap_size = -1); - _stack = ALIGN(128); PROVIDE(_stack = .); - . = _stack + _stack_size; - - _end = .; - PROVIDE(end = .); - - /* Unwanted stuff */ - /DISCARD/ : { - * ( .MIPS.abiflags ) - } + PROVIDE(_stack_size = ORIGIN(MAIN_REGION) + LENGTH(MAIN_REGION) - _stack); } diff --git a/main.c b/main.c index fe30f35..f662ae0 100644 --- a/main.c +++ b/main.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -8,13 +9,19 @@ #include #include + +#define NEWLIB_PORT_AWARE #include + #include #include #include "cnf_lite.h" +// Disable all the patched functions +DISABLE_PATCHED_FUNCTIONS(); + /* Some macros used for patching. */ #define JAL(addr) (0x0c000000 | (0x3ffffff & ((addr) >> 2))) #define JMP(addr) (0x08000000 | (0x3ffffff & ((addr) >> 2))) @@ -78,18 +85,18 @@ static int InitVideoModeParams(void) temp = (temp & 0xFFFFFC00) | 3; temp = (temp & 0xFFF003FF) | 0x1800; temp = (temp & 0xC00FFFFF) | 0x01200000; - temp = (temp & 0xFFFFFC00FFFFFFFF) | (0xC000L << 19); - temp = (temp & 0xFFE003FFFFFFFFFF) | (0xF300L << 35); - temp = (temp & 0x801FFFFFFFFFFFFF) | (0xC000L << 40); + temp = (temp & 0xFFFFFC00FFFFFFFF) | (0xC000LL << 19); + temp = (temp & 0xFFE003FFFFFFFFFF) | (0xF300LL << 35); + temp = (temp & 0x801FFFFFFFFFFFFF) | (0xC000LL << 40); *emu_SYNCHV_I = temp; // Nearly a repeat of the block above. temp = (temp & 0xFFFFFC00) | 4; temp = (temp & 0xFFF003FF) | 0x1800; temp = (temp & 0xC00FFFFF) | 0x01200000; - temp = (temp & 0xFFFFFC00FFFFFFFF) | (0xC000L << 19); - temp = (temp & 0xFFE003FFFFFFFFFF) | (0xF300L << 35); - temp = (temp & 0x801FFFFFFFFFFFFF) | (0xC000L << 40); + temp = (temp & 0xFFFFFC00FFFFFFFF) | (0xC000LL << 19); + temp = (temp & 0xFFE003FFFFFFFFFF) | (0xF300LL << 35); + temp = (temp & 0x801FFFFFFFFFFFFF) | (0xC000LL << 40); *emu_SYNCHV_NI = temp; }