From 5f5461879c73720359e87fa41cbfe8c452f5155e Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Tue, 17 Aug 2021 11:36:50 +0000 Subject: Added missing header declarations, FlushCache, misc library bugfixes --- libpsn00b/libc/_mem_init.s | 20 ----- libpsn00b/libc/malloc.s | 11 ++- libpsn00b/libc/start.c | 181 +++++++++++++++++++++++---------------------- 3 files changed, 103 insertions(+), 109 deletions(-) delete mode 100644 libpsn00b/libc/_mem_init.s (limited to 'libpsn00b/libc') diff --git a/libpsn00b/libc/_mem_init.s b/libpsn00b/libc/_mem_init.s deleted file mode 100644 index 672ac2f..0000000 --- a/libpsn00b/libc/_mem_init.s +++ /dev/null @@ -1,20 +0,0 @@ -.set noreorder - -.global _mem_init -.type _mem_init, @function -_mem_init: - -.section .text - -_mem_init: - la $a0, __bss_start - la $a1, _end -.Lclear_bss: - sb $0 , 0($a0) - blt $a0, $a1, .Lclear_bss - addiu $a0, 1 - la $a0, _end+4 # Initialize heap for malloc (does not use BIOS maalloc) - li $a1, 1572864 # Allocate 1.5MB at end of bss - j InitHeap - nop - \ No newline at end of file diff --git a/libpsn00b/libc/malloc.s b/libpsn00b/libc/malloc.s index 90f9bd4..e441bbe 100644 --- a/libpsn00b/libc/malloc.s +++ b/libpsn00b/libc/malloc.s @@ -1,5 +1,10 @@ # Custom first-fit malloc routines by Lameguy64 # Part of the PSn00bSDK Project +# +# NOTE: there reportedly is a GCC bug which messes up .weak functions written +# in assembly if LTO is enabled. I haven't tested but, according to the +# internet, this bug has never been fixed. +# https://gcc.gnu.org/legacy-ml/gcc-help/2019-10/msg00092.html .set noreorder @@ -10,7 +15,6 @@ .section .text - # Stupid small function just to get bss end # due to GCC insisting externs to be gp relative .global GetBSSend @@ -27,6 +31,7 @@ GetBSSend: # .global InitHeap .type InitHeap, @function +.weak InitHeap InitHeap: la $v0, _malloc_addr sw $a0, 0($v0) @@ -43,6 +48,7 @@ InitHeap: # a0 - Size of memory heap in bytes .global SetHeapSize .type SetHeapSize, @function +.weak SetHeapSize SetHeapSize: la $v1, _malloc_size lw $v0, 0($v1) @@ -55,6 +61,7 @@ SetHeapSize: # .global malloc .type malloc, @function +.weak malloc malloc: addiu $a0, 3 # Round size to a multiple of 4 srl $a0, 2 @@ -170,6 +177,7 @@ malloc: # .global calloc .type calloc, @function +.weak calloc calloc: mult $a0, $a1 addiu $sp, -4 @@ -199,6 +207,7 @@ calloc: # .global free .type free, @function +.weak free free: addiu $a0, -ND_HSIZ diff --git a/libpsn00b/libc/start.c b/libpsn00b/libc/start.c index 354ebb9..c5872df 100644 --- a/libpsn00b/libc/start.c +++ b/libpsn00b/libc/start.c @@ -1,110 +1,115 @@ -#include +/* + * PSn00bSDK startup code + * (C) 2021 Lameguy64, spicyjpeg - MPL licensed + */ + +#include #include #include -#define load_gp() __asm__ volatile ( \ - "la $gp, _gp;" ) - -extern int _end; -extern int main(int argc, const char* argv[]); +#define KERNEL_ARG_STRING ((const char *) 0x80000180) +#define KERNEL_RETURN_VALUE ((volatile int *) 0x8000dffc) -void _mem_init(void); +/* Argument parsing */ -int __argc; +int32_t __argc; const char **__argv; -static const char *_arg_ptrs_int[8]; -static char _arg_buff[132]; +#define ARGC_MAX 16 -static void _call_global_ctors(void) -{ - extern void (*__CTOR_LIST__[])(void); +static const char *_argv_buffer[ARGC_MAX]; +static char _arg_string_buffer[132]; - // Constructors are called in reverse order of the list - int i; - for (i = (int)__CTOR_LIST__[0]; i >= 1; i--) { - // Each function handles one or more destructor (within - // file scope) - __CTOR_LIST__[i](); +static void _parse_kernel_args() { + // Copy the argument string from kernel memory into a private buffer (which + // won't be cleared or deallocated) and trim it at the first newline. + memset(_arg_string_buffer, 0, 132); + strncpy(_arg_string_buffer, KERNEL_ARG_STRING, 128); + + for (char *ptr = _arg_string_buffer; *ptr; ptr++) { + if ((*ptr == '\r') || (*ptr == '\n')) { + *ptr = 0; + break; + } } -} -static void _call_global_dtors(void) -{ - extern void (*__DTOR_LIST__[])(void); + __argv = _argv_buffer; + for (__argc = 0; __argc < ARGC_MAX; __argc++) { + const char *ptr; + if (!__argc) + ptr = strtok(_arg_string_buffer, " "); + else + ptr = strtok(0, " "); - /* Destructors in forward order */ - int i; - for (i = 0; i < (int)__DTOR_LIST__[0]; i++) { - /* Each function handles one or more destructor (within - * file scope) */ - __DTOR_LIST__[i + 1](); + _argv_buffer[__argc] = ptr; + if (!ptr) + break; } } -void _parse_args( int argc, const char *args[] ) -{ - int i; - char *c,*s; - - memset( _arg_buff, 0, 132 ); - - if( !args ) - { - // Use arguments from kernel if args is NULL - strncpy( _arg_buff, (char*)0x180, 128 ); - - // Clean-up args froom stray line-ends - while( ( c = strrchr( _arg_buff, '\r' ) ) || - ( c = strrchr( _arg_buff, '\n' ) ) ) - *c = 0; - } - else - { - __argc = argc; - __argv = args; - return; - } - - __argc = 0; - for( i=0; i<8; i++ ) - _arg_ptrs_int[i] = 0; - - s = _arg_buff; - while( c = strtok( s, " " ) ) - { - _arg_ptrs_int[__argc] = c; - __argc++; - s = NULL; - if( __argc >= 8 ) - break; - } - - __argv = _arg_ptrs_int; - -} /* parse_args */ +/* Main */ + +// How much space at the end of RAM to leave for the stack (instead of using it +// as heap). By default 128 KB are reserved for the stack, but this constant +// can be overridden in main.c (or anywhere else) simply by redeclaring it +// without the weak attribute. +const int32_t __attribute__((weak)) STACK_MAX_SIZE = 0x20000; -void _start( int argc, const char *args[] ) -{ - // Load GP address - load_gp(); +// These are defined by the linker script. Note that these are *NOT* pointers, +// they are virtual symbols whose location matches their value. The simplest +// way to turn them into pointers is to declare them as arrays, so here we go. +extern uint8_t __text_start[]; +extern uint8_t __bss_start[]; +extern uint8_t _end[]; +//extern uint8_t _gp[]; + +extern void (*__CTOR_LIST__[])(void); +extern void (*__DTOR_LIST__[])(void); + +extern int32_t main(int32_t argc, const char* argv[]); + +// Even though _start() usually takes no arguments, this implementation allows +// parent executables to pass args directly to child executables without having +// to overwrite the arg strings in kernel RAM. +void _start(int32_t override_argc, const char **override_argv) { + __asm__ volatile("la $gp, _gp;"); // Mem init assembly function (clears BSS and InitHeap to _end which is // not possible to do purely in C because the linker complains about // relocation truncated to fit: R_MIPS_GPREL16 against `_end' // Workaround is to do it in assembly because la pseudo-op doesn't use // stupid gp relative addressing - _mem_init(); - - // process command line arguments - _parse_args( argc, args ); - - _call_global_ctors(); - - *((int*)0x8000DFFC) = main( __argc, __argv ); - - _call_global_dtors(); - - // Set return value to kernel return value area - -} /* _start */ \ No newline at end of file + //_mem_init(); + + // Clear BSS 4 bytes at a time. BSS is always aligned to 4 bytes by the + // linker script. + for (uint32_t *i = (uint32_t *) __bss_start; i < (uint32_t *) _end; i++) + *i = 0; + + // Calculate how much RAM is available after the loaded executable and + // initialize heap accordingly. + void *exe_end = _end + 4; + unsigned int exe_size = (unsigned int) exe_end - (unsigned int) __text_start; + InitHeap(exe_end, 0x200000 - (exe_size + STACK_MAX_SIZE)); + + if (override_argv) { + __argc = override_argc; + __argv = override_argv; + } else { + _parse_kernel_args(); + } + + // Call the global constructors (if any) to initialize global objects + // before calling main(). Constructors are put by the linker script in a + // length-prefixed array in reverse order. + for (uint32_t i = (uint32_t) __CTOR_LIST__[0]; i >= 1; i--) + __CTOR_LIST__[i](); + + // Store main()'s return value into the kernel return value area (for child + // executables). + *KERNEL_RETURN_VALUE = main(__argc, __argv); + + // Call global destructors (in forward order). + for (uint32_t i = 0; i < (uint32_t) __DTOR_LIST__[0]; i++) + __DTOR_LIST__[i + 1](); +} -- cgit v1.2.3 From 89751f29467b359339a8c8b57c218cc3328bae43 Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Tue, 17 Aug 2021 11:36:56 +0000 Subject: Rewritten all Makefiles, set up proper GCC options, added iso.xml to template --- doc/dev notes.txt | 44 ++++- examples/beginner/cppdemo/makefile | 81 ++++---- examples/beginner/hello/makefile | 81 ++++---- examples/cdrom/cdbrowse/iso.xml | 33 ++-- examples/cdrom/cdbrowse/makefile | 80 +++++--- examples/cdrom/cdxa/iso.xml | 29 +-- examples/cdrom/cdxa/makefile | 80 +++++--- examples/demos/n00bdemo/data.s | 2 +- examples/demos/n00bdemo/data.xml | 6 +- examples/demos/n00bdemo/makefile | 82 +++++--- examples/examples-setup.mk | 64 ------- examples/graphics/balls/makefile | 81 ++++---- examples/graphics/billboard/makefile | 76 +++++--- examples/graphics/fpscam/makefile | 76 +++++--- examples/graphics/gte/makefile | 76 +++++--- examples/graphics/hdtv/makefile | 77 +++++--- examples/graphics/render2tex/makefile | 76 +++++--- examples/graphics/rgb24/makefile | 76 +++++--- examples/makefile | 4 +- examples/system/childexec/child.c | 326 -------------------------------- examples/system/childexec/child/child.c | 326 ++++++++++++++++++++++++++++++++ examples/system/childexec/child_exe.s | 2 +- examples/system/childexec/makefile | 105 +++++++--- examples/system/console/makefile | 81 ++++---- examples/system/timer/makefile | 76 +++++--- examples/system/tty/makefile | 81 ++++---- libpsn00b/ldscripts/dll.ld | 122 ++++++++++++ libpsn00b/ldscripts/exe.ld | 114 +++++++++++ libpsn00b/libc/makefile | 59 +++--- libpsn00b/lzp/makefile | 61 ++++-- libpsn00b/psxapi/makefile | 62 ++++-- libpsn00b/psxcd/makefile | 57 +++--- libpsn00b/psxetc/makefile | 59 +++--- libpsn00b/psxgpu/makefile | 57 +++--- libpsn00b/psxgte/makefile | 57 +++--- libpsn00b/psxsio/makefile | 57 +++--- libpsn00b/psxspu/makefile | 61 +++--- psn00bsdk-setup.mk | 121 ++++++++++++ template/iso.xml | 27 +++ template/makefile | 83 ++++---- template/psn00bsdk-setup.mk | 68 ------- template/system.cnf | 4 + toolchain.txt | 38 ++-- 43 files changed, 2027 insertions(+), 1201 deletions(-) delete mode 100644 examples/examples-setup.mk delete mode 100644 examples/system/childexec/child.c create mode 100644 examples/system/childexec/child/child.c create mode 100644 libpsn00b/ldscripts/dll.ld create mode 100644 libpsn00b/ldscripts/exe.ld create mode 100644 psn00bsdk-setup.mk create mode 100644 template/iso.xml delete mode 100644 template/psn00bsdk-setup.mk create mode 100644 template/system.cnf (limited to 'libpsn00b/libc') diff --git a/doc/dev notes.txt b/doc/dev notes.txt index 2b280c7..47aa2df 100644 --- a/doc/dev notes.txt +++ b/doc/dev notes.txt @@ -49,4 +49,46 @@ DRAWENV.isbg is not effective in the official SDK. * In the official SDK, DMA IRQs appear to be enabled only when a callback function is set (ie. DrawSyncCallback() enables IRQ for DMA channel 2). DMA -IRQs are only triggered on transfer completion. \ No newline at end of file +IRQs are only triggered on transfer completion. + +Additional notes by spicyjpeg: + +* The SDK provides no support yet for replacing the BIOS exception handler with +a custom one, however it can be done (if you are ok with losing all BIOS +controller, memory card and file functionality). In order not to break anything +your exception handler must do the following: + + * prevent GTE opcodes from being executed twice due to a hardware glitch (the + nocash docs explain how to do this); + * define _irq_func_table[12] as an *extern* array of function pointers, call + the appropriate entry when an IRQ occurs and clear the respective flag in + register 1F801070h; + * handle syscalls 01h-02h, i.e. EnterCriticalSection and ExitCriticalSection + properly. You should also handle syscall FF00h (invalid API usage), as well + as breaks 1800h and 1C00h (division errors injected by GCC), by locking up + and maybe showing a BSOD or similar; + * overwrite the default BIOS API vectors with a passthrough that checks no + controller- or interrupt-related function is being called. This is necessary + (although ugly) as libpsn00b often calls such functions internally. + +* For some reason mipsel-unknown-elf-nm (symbol map generator) insists on +outputting 64-bit addresses (with the top 32 bits set, e.g. FFFFFFFF80010000) +even when feeding it a regular 32-bit MIPS executable, while the standard x86 +nm tool that ships with most GCC packages prints the proper 32-bit address. +Unclear whether this is a bug, intended behavior or the result of some ancient +ELF ABI flag crap. DL_ParseSymbolMap() will ignore the top 32 bits, so this +should only bother you if you're implementing your own symbol map parser. + +* I haven't worked on psxspu but, for those willing to write some code, this is +the formula to calculate SPU pitch values for playing musical notes ("^" is the +power operator, not xor): + + frequency = (ref / 32) * (2 ^ ((note - 9) / 12)) + spu_pitch = frequency / 44100 * 4096 + + ref = frequency the sample should be played at to play a middle A (MIDI note 69) + note = MIDI note number (usually 0-127, 60 is middle C) + +* If you are overriding any of the memory allocation functions, DO NOT ENABLE +LINK-TIME OPTIMIZATION. GCC has a long-standing bug with LTO and weak functions +written in assembly, also LTO hasn't been tested at all yet. diff --git a/examples/beginner/cppdemo/makefile b/examples/beginner/cppdemo/makefile index 3e122ab..630a280 100644 --- a/examples/beginner/cppdemo/makefile +++ b/examples/beginner/cppdemo/makefile @@ -1,54 +1,65 @@ -include ../../examples-setup.mk +# PSn00bSDK makefile template +# Part of the PSn00bSDK Project +# 2019 - 2021 Lameguy64 / Meido-Tek Productions + +## Settings + +PSN00BSDK_LIBS ?= ../../../libpsn00b + +# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's +# root folder (it only depends on environment variables). +include ../../../psn00bsdk-setup.mk # Project target name -TARGET = cppdemo.elf +TARGET = cppdemo + +## Files # Searches for C, C++ and S (assembler) files in local directory -CFILES = $(notdir $(wildcard *.c)) -CPPFILES = $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) +CFILES = $(notdir $(wildcard *.c)) +CPPFILES= $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) -# Determine object files -OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ - $(addprefix build/,$(CPPFILES:.cpp=.o)) \ - $(addprefix build/,$(AFILES:.s=.o)) +# Create names for object files +OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ + $(addprefix build/,$(CPPFILES:.cpp=.o)) \ + $(addprefix build/,$(AFILES:.s=.o)) -# Project specific include and library directories -# (use -I for include dirs, -L for library dirs) -INCLUDE += -LIBDIRS += +# Project specific includes and libraries +# (use -I for include dirs, -L for library dirs, -l for static libraries) +INCLUDE += +LIBDIRS += +LIBS += -# Libraries to link -LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc +## Build rules -# C compiler flags -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections +#all: iso +all: build/$(TARGET) -# C++ compiler flags -CPPFLAGS = $(CFLAGS) -fno-builtin -fno-rtti -fno-exceptions +iso: build/$(TARGET) resources + $(MKPSXISO) -y -q iso.xml -# Assembler flags -AFLAGS = -g -msoft-float +resources: + # Add commands to build/convert your assets here + #$(LZPACK) data.xml -# Linker flags -LDFLAGS = -g -Ttext=0x80010000 -gc-sections \ - -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x +build/$(TARGET): $(OFILES) + @mkdir -p $(dir $@) + $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ + $(NM) -f posix -l -n $@ >$@.map + $(ELF2X) -q $@ $@.exe -all: $(OFILES) - $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) - elf2x -q $(TARGET) - build/%.o: %.c @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ - + $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ + build/%.o: %.cpp @mkdir -p $(dir $@) - $(CXX) $(CPPFLAGS) $(INCLUDE) -c $< -o $@ - + $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ + build/%.o: %.s @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - + $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ + clean: - rm -rf build $(TARGET) $(TARGET:.elf=.exe) + rm -rf build diff --git a/examples/beginner/hello/makefile b/examples/beginner/hello/makefile index 3fce1ae..e4bed20 100644 --- a/examples/beginner/hello/makefile +++ b/examples/beginner/hello/makefile @@ -1,54 +1,65 @@ -include ../../examples-setup.mk +# PSn00bSDK makefile template +# Part of the PSn00bSDK Project +# 2019 - 2021 Lameguy64 / Meido-Tek Productions + +## Settings + +PSN00BSDK_LIBS ?= ../../../libpsn00b + +# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's +# root folder (it only depends on environment variables). +include ../../../psn00bsdk-setup.mk # Project target name -TARGET = hello.elf +TARGET = hello + +## Files # Searches for C, C++ and S (assembler) files in local directory -CFILES = $(notdir $(wildcard *.c)) -CPPFILES = $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) +CFILES = $(notdir $(wildcard *.c)) +CPPFILES= $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) -# Determine object files -OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ - $(addprefix build/,$(CPPFILES:.cpp=.o)) \ - $(addprefix build/,$(AFILES:.s=.o)) +# Create names for object files +OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ + $(addprefix build/,$(CPPFILES:.cpp=.o)) \ + $(addprefix build/,$(AFILES:.s=.o)) -# Project specific include and library directories -# (use -I for include dirs, -L for library dirs) -INCLUDE += -LIBDIRS += +# Project specific includes and libraries +# (use -I for include dirs, -L for library dirs, -l for static libraries) +INCLUDE += +LIBDIRS += +LIBS += -# Libraries to link -LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc +## Build rules -# C compiler flags -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections +#all: iso +all: build/$(TARGET) -# C++ compiler flags -CPPFLAGS = $(CFLAGS) -fno-exceptions +iso: build/$(TARGET) resources + $(MKPSXISO) -y -q iso.xml -# Assembler flags -AFLAGS = -g -msoft-float +resources: + # Add commands to build/convert your assets here + #$(LZPACK) data.xml -# Linker flags -LDFLAGS = -g -Ttext=0x80010000 -gc-sections \ - -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x +build/$(TARGET): $(OFILES) + @mkdir -p $(dir $@) + $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ + $(NM) -f posix -l -n $@ >$@.map + $(ELF2X) -q $@ $@.exe -all: $(OFILES) - $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) - elf2x -q $(TARGET) - build/%.o: %.c @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ - + $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ + build/%.o: %.cpp @mkdir -p $(dir $@) - $(CXX) $(AFLAGS) $(INCLUDE) -c $< -o $@ - + $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ + build/%.o: %.s @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - + $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ + clean: - rm -rf build $(TARGET) $(TARGET:.elf=.exe) + rm -rf build diff --git a/examples/cdrom/cdbrowse/iso.xml b/examples/cdrom/cdbrowse/iso.xml index a828df1..5d8963d 100644 --- a/examples/cdrom/cdbrowse/iso.xml +++ b/examples/cdrom/cdbrowse/iso.xml @@ -1,33 +1,34 @@ - - - - + + - + + + - - - - - + + - + - - + diff --git a/examples/cdrom/cdbrowse/makefile b/examples/cdrom/cdbrowse/makefile index ee925d2..954408b 100644 --- a/examples/cdrom/cdbrowse/makefile +++ b/examples/cdrom/cdbrowse/makefile @@ -1,45 +1,65 @@ -include ../../examples-setup.mk +# PSn00bSDK makefile template +# Part of the PSn00bSDK Project +# 2019 - 2021 Lameguy64 / Meido-Tek Productions -TARGET = cdbrowse.elf +## Settings -CFILES = $(notdir $(wildcard *.c)) -CPPFILES = $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) +PSN00BSDK_LIBS ?= ../../../libpsn00b -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o)) +# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's +# root folder (it only depends on environment variables). +include ../../../psn00bsdk-setup.mk -LIBS = -lpsxcd -lpsxgpu -lpsxgte -lpsxspu -lpsxsio -lpsxetc -lpsxapi -lc +# Project target name +TARGET = cdbrowse -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections -CPPFLAGS = $(CFLAGS) \ - -fno-exceptions \ - -fno-rtti \ - -fno-unwind-tables \ - -fno-threadsafe-statics \ - -fno-use-cxa-atexit +## Files -AFLAGS = -g -msoft-float -LDFLAGS = -g -Ttext=0x80010000 -gc-sections \ - -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x +# Searches for C, C++ and S (assembler) files in local directory +CFILES = $(notdir $(wildcard *.c)) +CPPFILES= $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) + +# Create names for object files +OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ + $(addprefix build/,$(CPPFILES:.cpp=.o)) \ + $(addprefix build/,$(AFILES:.s=.o)) + +# Project specific includes and libraries +# (use -I for include dirs, -L for library dirs, -l for static libraries) +INCLUDE += +LIBDIRS += +LIBS += + +## Build rules + +all: iso +#all: build/$(TARGET) + +iso: build/$(TARGET) resources + $(MKPSXISO) -y -q iso.xml + +resources: + # Add commands to build/convert your assets here + #$(LZPACK) data.xml + +build/$(TARGET): $(OFILES) + @mkdir -p $(dir $@) + $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ + $(NM) -f posix -l -n $@ >$@.map + $(ELF2X) -q $@ $@.exe -all: $(OFILES) - $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) - elf2x -q $(TARGET) - -iso: - mkpsxiso -y -q iso.xml - build/%.o: %.c @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ build/%.o: %.cpp @mkdir -p $(dir $@) - $(CXX) $(CPPFLAGS) $(INCLUDE) -c $< -o $@ - + $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ + build/%.o: %.s @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - + $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ + clean: - rm -rf build $(TARGET) $(TARGET:.elf=.exe) + rm -rf build diff --git a/examples/cdrom/cdxa/iso.xml b/examples/cdrom/cdxa/iso.xml index 840b414..9a6a206 100644 --- a/examples/cdrom/cdxa/iso.xml +++ b/examples/cdrom/cdxa/iso.xml @@ -1,29 +1,30 @@ - - - - + + - + + + - - - - + - - + diff --git a/examples/cdrom/cdxa/makefile b/examples/cdrom/cdxa/makefile index b95efa7..b1627f7 100644 --- a/examples/cdrom/cdxa/makefile +++ b/examples/cdrom/cdxa/makefile @@ -1,45 +1,65 @@ -include ../../examples-setup.mk +# PSn00bSDK makefile template +# Part of the PSn00bSDK Project +# 2019 - 2021 Lameguy64 / Meido-Tek Productions -TARGET = cdxa.elf +## Settings -CFILES = $(notdir $(wildcard *.c)) -CPPFILES = $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) +PSN00BSDK_LIBS ?= ../../../libpsn00b -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o)) +# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's +# root folder (it only depends on environment variables). +include ../../../psn00bsdk-setup.mk -LIBS = -lpsxcd -lpsxgpu -lpsxgte -lpsxspu -lpsxsio -lpsxetc -lpsxapi -lc +# Project target name +TARGET = cdxa -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections -CPPFLAGS = $(CFLAGS) \ - -fno-exceptions \ - -fno-rtti \ - -fno-unwind-tables \ - -fno-threadsafe-statics \ - -fno-use-cxa-atexit +## Files -AFLAGS = -g -msoft-float -LDFLAGS = -g -Ttext=0x80010000 -gc-sections \ - -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x +# Searches for C, C++ and S (assembler) files in local directory +CFILES = $(notdir $(wildcard *.c)) +CPPFILES= $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) + +# Create names for object files +OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ + $(addprefix build/,$(CPPFILES:.cpp=.o)) \ + $(addprefix build/,$(AFILES:.s=.o)) + +# Project specific includes and libraries +# (use -I for include dirs, -L for library dirs, -l for static libraries) +INCLUDE += +LIBDIRS += +LIBS += + +## Build rules + +#all: iso +all: build/$(TARGET) + +iso: build/$(TARGET) resources + $(MKPSXISO) -y -q iso.xml + +resources: + # Add commands to build/convert your assets here + #$(LZPACK) data.xml + +build/$(TARGET): $(OFILES) + @mkdir -p $(dir $@) + $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ + $(NM) -f posix -l -n $@ >$@.map + $(ELF2X) -q $@ $@.exe -all: $(OFILES) - $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) - elf2x -q $(TARGET) - -iso: - mkpsxiso -y -q iso.xml - build/%.o: %.c @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ build/%.o: %.cpp @mkdir -p $(dir $@) - $(CXX) $(CPPFLAGS) $(INCLUDE) -c $< -o $@ - + $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ + build/%.o: %.s @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - + $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ + clean: - rm -rf build $(TARGET) $(TARGET:.elf=.exe) + rm -rf build diff --git a/examples/demos/n00bdemo/data.s b/examples/demos/n00bdemo/data.s index 3ca33cb..f3b2a83 100644 --- a/examples/demos/n00bdemo/data.s +++ b/examples/demos/n00bdemo/data.s @@ -3,7 +3,7 @@ .global lz_resources .type lz_resources, @object lz_resources: - .incbin "data.lzp" + .incbin "build/data.lzp" #.global smd_mtekdisk #.type smd_mtekdisk, @object diff --git a/examples/demos/n00bdemo/data.xml b/examples/demos/n00bdemo/data.xml index 292a325..6761f16 100644 --- a/examples/demos/n00bdemo/data.xml +++ b/examples/demos/n00bdemo/data.xml @@ -1,6 +1,6 @@ - + data/petscum16c.tim data/bungirl.tim @@ -19,7 +19,7 @@ - + data/mtekdisk.smd @@ -42,7 +42,7 @@ data/hatkid.smd - textures.qlp + build/textures.qlp diff --git a/examples/demos/n00bdemo/makefile b/examples/demos/n00bdemo/makefile index 7e3bd8e..9206e09 100644 --- a/examples/demos/n00bdemo/makefile +++ b/examples/demos/n00bdemo/makefile @@ -1,39 +1,65 @@ -include ../../examples-setup.mk +# PSn00bSDK makefile template +# Part of the PSn00bSDK Project +# 2019 - 2021 Lameguy64 / Meido-Tek Productions -TARGET = demo.elf +## Settings -CFILES = $(notdir $(wildcard *.c)) -AFILES = $(notdir $(wildcard *.s)) +PSN00BSDK_LIBS ?= ../../../libpsn00b -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(AFILES:.s=.o)) +# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's +# root folder (it only depends on environment variables). +include ../../../psn00bsdk-setup.mk -INCLUDE += -I../../../libpsn00b/lzp +# Project target name +TARGET = demo -LIBS = -llzp -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc +## Files -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections -CPPFLAGS = $(CFLAGS) -fno-exceptions -AFLAGS = -g -msoft-float -LDFLAGS = -g -Ttext=0x80010000 -gc-sections -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x +# Searches for C, C++ and S (assembler) files in local directory +CFILES = $(notdir $(wildcard *.c)) +CPPFILES= $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) + +# Create names for object files +OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ + $(addprefix build/,$(CPPFILES:.cpp=.o)) \ + $(addprefix build/,$(AFILES:.s=.o)) + +# Project specific includes and libraries +# (use -I for include dirs, -L for library dirs, -l for static libraries) +INCLUDE += +LIBDIRS += +LIBS += -llzp + +## Build rules + +#all: iso +all: build/$(TARGET) + +iso: build/$(TARGET) + $(MKPSXISO) -y -q iso.xml + +resources: + $(LZPACK) data.xml + touch data.s + +build/$(TARGET): $(OFILES) + @mkdir -p $(dir $@) + $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ + $(NM) -f posix -l -n $@ >$@.map + $(ELF2X) -q $@ $@.exe -all: resources $(OFILES) - $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) - elf2x -q $(TARGET) - build/%.o: %.c @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s + $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ + +build/%.o: %.cpp @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - -resources: - lzpack data.xml - touch data.s - -iso: - mkpsxiso -y -q -o demo.iso iso.xml - + $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ + +build/%.o: %.s resources + @mkdir -p $(dir $@) + $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ + clean: - rm -rf build *.lzp *.qlp $(TARGET) $(TARGET:.elf=.exe) $(TARGET:.elf=.iso) + rm -rf build diff --git a/examples/examples-setup.mk b/examples/examples-setup.mk deleted file mode 100644 index 1fadd84..0000000 --- a/examples/examples-setup.mk +++ /dev/null @@ -1,64 +0,0 @@ -# PSn00bSDK examples setup file -# Part of the PSn00bSDK Project -# 2019 - 2020 Lameguy64 / Meido-Tek Productions -# -# This is only for the PSn00bSDK example programs, not recommended -# for use with user projects - -PREFIX = mipsel-unknown-elf - -ifndef GCC_VERSION - -GCC_VERSION = 7.4.0 - -endif # GCC_VERSION - -# PSn00bSDK library/include path setup -ifndef PSN00BSDK_LIBS - -# Default assumes libpsn00b is just in the parent dir of the examples dir - -LIBDIRS = -L../../../libpsn00b -INCLUDE = -I../../../libpsn00b/include - -else - -LIBDIRS = -L$(PSN00BSDK_LIBS) -INCLUDE = -I$(PSN00BSDK_LIBS)/include - -endif # PSN00BSDK_LIBS - -# PSn00bSDK toolchain path setup -ifndef GCC_BASE - -ifndef PSN00BSDK_TC - -# Default assumes GCC toolchain is in root of C drive or /usr/local - -ifeq "$(OS)" "Windows_NT" - -GCC_BASE = /c/mipsel-unknown-elf -GCC_BIN = - -else - -GCC_BASE = /usr/local/mipsel-unknown-elf -GCC_BIN = - -endif - -else - -GCC_BASE = $(PSN00BSDK_TC) -GCC_BIN = $(PSN00BSDK_TC)/bin/ - -endif # PSN00BSDK_TC - -endif # GCC_BASE - -CC = $(GCC_BIN)$(PREFIX)-gcc -CXX = $(GCC_BIN)$(PREFIX)-g++ -AS = $(GCC_BIN)$(PREFIX)-as -AR = $(GCC_BIN)$(PREFIX)-ar -LD = $(GCC_BIN)$(PREFIX)-ld -RANLIB = $(GCC_BIN)$(PREFIX)-ranlib \ No newline at end of file diff --git a/examples/graphics/balls/makefile b/examples/graphics/balls/makefile index 70f41bf..44d3d71 100644 --- a/examples/graphics/balls/makefile +++ b/examples/graphics/balls/makefile @@ -1,54 +1,65 @@ -include ../../examples-setup.mk +# PSn00bSDK makefile template +# Part of the PSn00bSDK Project +# 2019 - 2021 Lameguy64 / Meido-Tek Productions + +## Settings + +PSN00BSDK_LIBS ?= ../../../libpsn00b + +# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's +# root folder (it only depends on environment variables). +include ../../../psn00bsdk-setup.mk # Project target name -TARGET = balls.elf +TARGET = balls + +## Files # Searches for C, C++ and S (assembler) files in local directory -CFILES = $(notdir $(wildcard *.c)) -CPPFILES = $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) +CFILES = $(notdir $(wildcard *.c)) +CPPFILES= $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) -# Determine object files -OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ - $(addprefix build/,$(CPPFILES:.cpp=.o)) \ - $(addprefix build/,$(AFILES:.s=.o)) +# Create names for object files +OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ + $(addprefix build/,$(CPPFILES:.cpp=.o)) \ + $(addprefix build/,$(AFILES:.s=.o)) -# Project specific include and library directories -# (use -I for include dirs, -L for library dirs) -INCLUDE += -LIBDIRS += +# Project specific includes and libraries +# (use -I for include dirs, -L for library dirs, -l for static libraries) +INCLUDE += +LIBDIRS += +LIBS += -# Libraries to link -LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc +## Build rules -# C compiler flags -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections +#all: iso +all: build/$(TARGET) -# C++ compiler flags -CPPFLAGS = $(CFLAGS) -fno-exceptions +iso: build/$(TARGET) resources + $(MKPSXISO) -y -q iso.xml -# Assembler flags -AFLAGS = -g -msoft-float +resources: + # Add commands to build/convert your assets here + #$(LZPACK) data.xml -# Linker flags -LDFLAGS = -g -Ttext=0x80010000 -gc-sections \ - -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x +build/$(TARGET): $(OFILES) + @mkdir -p $(dir $@) + $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ + $(NM) -f posix -l -n $@ >$@.map + $(ELF2X) -q $@ $@.exe -all: $(OFILES) - $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) - elf2x -q $(TARGET) - build/%.o: %.c @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ - + $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ + build/%.o: %.cpp @mkdir -p $(dir $@) - $(CXX) $(AFLAGS) $(INCLUDE) -c $< -o $@ - + $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ + build/%.o: %.s @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - + $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ + clean: - rm -rf build $(TARGET) $(TARGET:.elf=.exe) + rm -rf build diff --git a/examples/graphics/billboard/makefile b/examples/graphics/billboard/makefile index 4f0fcf4..462e73c 100644 --- a/examples/graphics/billboard/makefile +++ b/examples/graphics/billboard/makefile @@ -1,35 +1,65 @@ -include ../../examples-setup.mk +# PSn00bSDK makefile template +# Part of the PSn00bSDK Project +# 2019 - 2021 Lameguy64 / Meido-Tek Productions -TARGET = billboard.elf +## Settings -CFILES = $(notdir $(wildcard *.c)) -CPPFILES = $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) +PSN00BSDK_LIBS ?= ../../../libpsn00b -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o)) +# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's +# root folder (it only depends on environment variables). +include ../../../psn00bsdk-setup.mk -INCLUDE += -LIBDIRS += +# Project target name +TARGET = billboard -LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc +## Files -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections -CPPFLAGS = $(CFLAGS) -fno-exceptions -AFLAGS = -g -msoft-float -LDFLAGS = -g -Ttext=0x80010000 -gc-sections \ - -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x +# Searches for C, C++ and S (assembler) files in local directory +CFILES = $(notdir $(wildcard *.c)) +CPPFILES= $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) + +# Create names for object files +OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ + $(addprefix build/,$(CPPFILES:.cpp=.o)) \ + $(addprefix build/,$(AFILES:.s=.o)) + +# Project specific includes and libraries +# (use -I for include dirs, -L for library dirs, -l for static libraries) +INCLUDE += +LIBDIRS += +LIBS += + +## Build rules + +#all: iso +all: build/$(TARGET) + +iso: build/$(TARGET) resources + $(MKPSXISO) -y -q iso.xml + +resources: + # Add commands to build/convert your assets here + #$(LZPACK) data.xml + +build/$(TARGET): $(OFILES) + @mkdir -p $(dir $@) + $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ + $(NM) -f posix -l -n $@ >$@.map + $(ELF2X) -q $@ $@.exe -all: $(OFILES) - $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) - elf2x -q $(TARGET) - build/%.o: %.c @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ - + $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ + +build/%.o: %.cpp + @mkdir -p $(dir $@) + $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ + build/%.o: %.s @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - + $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ + clean: - rm -rf build $(TARGET) $(TARGET:.elf=.exe) + rm -rf build diff --git a/examples/graphics/fpscam/makefile b/examples/graphics/fpscam/makefile index dac1d43..2ddb7fd 100644 --- a/examples/graphics/fpscam/makefile +++ b/examples/graphics/fpscam/makefile @@ -1,35 +1,65 @@ -include ../../examples-setup.mk +# PSn00bSDK makefile template +# Part of the PSn00bSDK Project +# 2019 - 2021 Lameguy64 / Meido-Tek Productions -TARGET = fpscam.elf +## Settings -CFILES = $(notdir $(wildcard *.c)) -CPPFILES = $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) +PSN00BSDK_LIBS ?= ../../../libpsn00b -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o)) +# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's +# root folder (it only depends on environment variables). +include ../../../psn00bsdk-setup.mk -INCLUDE += -LIBDIRS += +# Project target name +TARGET = fpscam -LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc +## Files -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections -CPPFLAGS = $(CFLAGS) -fno-exceptions -AFLAGS = -g -msoft-float -LDFLAGS = -g -Ttext=0x80010000 -gc-sections \ - -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x +# Searches for C, C++ and S (assembler) files in local directory +CFILES = $(notdir $(wildcard *.c)) +CPPFILES= $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) + +# Create names for object files +OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ + $(addprefix build/,$(CPPFILES:.cpp=.o)) \ + $(addprefix build/,$(AFILES:.s=.o)) + +# Project specific includes and libraries +# (use -I for include dirs, -L for library dirs, -l for static libraries) +INCLUDE += +LIBDIRS += +LIBS += + +## Build rules + +#all: iso +all: build/$(TARGET) + +iso: build/$(TARGET) resources + $(MKPSXISO) -y -q iso.xml + +resources: + # Add commands to build/convert your assets here + #$(LZPACK) data.xml + +build/$(TARGET): $(OFILES) + @mkdir -p $(dir $@) + $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ + $(NM) -f posix -l -n $@ >$@.map + $(ELF2X) -q $@ $@.exe -all: $(OFILES) - $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) - elf2x -q $(TARGET) - build/%.o: %.c @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ - + $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ + +build/%.o: %.cpp + @mkdir -p $(dir $@) + $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ + build/%.o: %.s @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - + $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ + clean: - rm -rf build $(TARGET) $(TARGET:.elf=.exe) + rm -rf build diff --git a/examples/graphics/gte/makefile b/examples/graphics/gte/makefile index 43b7c5b..f44e72b 100644 --- a/examples/graphics/gte/makefile +++ b/examples/graphics/gte/makefile @@ -1,35 +1,65 @@ -include ../../examples-setup.mk +# PSn00bSDK makefile template +# Part of the PSn00bSDK Project +# 2019 - 2021 Lameguy64 / Meido-Tek Productions -TARGET = gte.elf +## Settings -CFILES = $(notdir $(wildcard *.c)) -CPPFILES = $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) +PSN00BSDK_LIBS ?= ../../../libpsn00b -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o)) +# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's +# root folder (it only depends on environment variables). +include ../../../psn00bsdk-setup.mk -INCLUDE += -LIBDIRS += +# Project target name +TARGET = gte -LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc +## Files -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections -CPPFLAGS = $(CFLAGS) -fno-exceptions -AFLAGS = -g -msoft-float -LDFLAGS = -g -Ttext=0x80010000 -gc-sections \ - -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x +# Searches for C, C++ and S (assembler) files in local directory +CFILES = $(notdir $(wildcard *.c)) +CPPFILES= $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) + +# Create names for object files +OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ + $(addprefix build/,$(CPPFILES:.cpp=.o)) \ + $(addprefix build/,$(AFILES:.s=.o)) + +# Project specific includes and libraries +# (use -I for include dirs, -L for library dirs, -l for static libraries) +INCLUDE += +LIBDIRS += +LIBS += + +## Build rules + +#all: iso +all: build/$(TARGET) + +iso: build/$(TARGET) resources + $(MKPSXISO) -y -q iso.xml + +resources: + # Add commands to build/convert your assets here + #$(LZPACK) data.xml + +build/$(TARGET): $(OFILES) + @mkdir -p $(dir $@) + $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ + $(NM) -f posix -l -n $@ >$@.map + $(ELF2X) -q $@ $@.exe -all: $(OFILES) - $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) - elf2x -q $(TARGET) - build/%.o: %.c @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ - + $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ + +build/%.o: %.cpp + @mkdir -p $(dir $@) + $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ + build/%.o: %.s @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - + $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ + clean: - rm -rf build $(TARGET) $(TARGET:.elf=.exe) + rm -rf build diff --git a/examples/graphics/hdtv/makefile b/examples/graphics/hdtv/makefile index 2c7cb71..6659c98 100644 --- a/examples/graphics/hdtv/makefile +++ b/examples/graphics/hdtv/makefile @@ -1,36 +1,65 @@ -include ../../examples-setup.mk +# PSn00bSDK makefile template +# Part of the PSn00bSDK Project +# 2019 - 2021 Lameguy64 / Meido-Tek Productions -TARGET = hdtv.elf +## Settings -CFILES = $(notdir $(wildcard *.c)) -CPPFILES = $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) +PSN00BSDK_LIBS ?= ../../../libpsn00b -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o)) +# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's +# root folder (it only depends on environment variables). +include ../../../psn00bsdk-setup.mk -INCLUDE += -LIBDIRS += +# Project target name +TARGET = hdtv -LIBS = -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc -LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc +## Files -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections -CPPFLAGS = $(CFLAGS) -fno-exceptions -AFLAGS = -g -msoft-float -LDFLAGS = -g -Ttext=0x80010000 -gc-sections \ - -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x +# Searches for C, C++ and S (assembler) files in local directory +CFILES = $(notdir $(wildcard *.c)) +CPPFILES= $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) + +# Create names for object files +OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ + $(addprefix build/,$(CPPFILES:.cpp=.o)) \ + $(addprefix build/,$(AFILES:.s=.o)) + +# Project specific includes and libraries +# (use -I for include dirs, -L for library dirs, -l for static libraries) +INCLUDE += +LIBDIRS += +LIBS += + +## Build rules + +#all: iso +all: build/$(TARGET) + +iso: build/$(TARGET) resources + $(MKPSXISO) -y -q iso.xml + +resources: + # Add commands to build/convert your assets here + #$(LZPACK) data.xml + +build/$(TARGET): $(OFILES) + @mkdir -p $(dir $@) + $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ + $(NM) -f posix -l -n $@ >$@.map + $(ELF2X) -q $@ $@.exe -all: $(OFILES) - $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) - elf2x -q $(TARGET) - build/%.o: %.c @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ - + $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ + +build/%.o: %.cpp + @mkdir -p $(dir $@) + $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ + build/%.o: %.s @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - + $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ + clean: - rm -rf build $(TARGET) $(TARGET:.elf=.exe) + rm -rf build diff --git a/examples/graphics/render2tex/makefile b/examples/graphics/render2tex/makefile index 52d650b..bb0ef3c 100644 --- a/examples/graphics/render2tex/makefile +++ b/examples/graphics/render2tex/makefile @@ -1,35 +1,65 @@ -include ../../examples-setup.mk +# PSn00bSDK makefile template +# Part of the PSn00bSDK Project +# 2019 - 2021 Lameguy64 / Meido-Tek Productions -TARGET = render2tex.elf +## Settings -CFILES = $(notdir $(wildcard *.c)) -CPPFILES = $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) +PSN00BSDK_LIBS ?= ../../../libpsn00b -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o)) +# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's +# root folder (it only depends on environment variables). +include ../../../psn00bsdk-setup.mk -INCLUDE += -LIBDIRS += +# Project target name +TARGET = render2tex -LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc +## Files -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections -CPPFLAGS = $(CFLAGS) -fno-exceptions -AFLAGS = -g -msoft-float -LDFLAGS = -g -Ttext=0x80010000 -gc-sections \ - -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x +# Searches for C, C++ and S (assembler) files in local directory +CFILES = $(notdir $(wildcard *.c)) +CPPFILES= $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) + +# Create names for object files +OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ + $(addprefix build/,$(CPPFILES:.cpp=.o)) \ + $(addprefix build/,$(AFILES:.s=.o)) + +# Project specific includes and libraries +# (use -I for include dirs, -L for library dirs, -l for static libraries) +INCLUDE += +LIBDIRS += +LIBS += + +## Build rules + +#all: iso +all: build/$(TARGET) + +iso: build/$(TARGET) resources + $(MKPSXISO) -y -q iso.xml + +resources: + # Add commands to build/convert your assets here + #$(LZPACK) data.xml + +build/$(TARGET): $(OFILES) + @mkdir -p $(dir $@) + $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ + $(NM) -f posix -l -n $@ >$@.map + $(ELF2X) -q $@ $@.exe -all: $(OFILES) - $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) - elf2x -q $(TARGET) - build/%.o: %.c @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ - + $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ + +build/%.o: %.cpp + @mkdir -p $(dir $@) + $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ + build/%.o: %.s @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - + $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ + clean: - rm -rf build $(TARGET) $(TARGET:.elf=.exe) + rm -rf build diff --git a/examples/graphics/rgb24/makefile b/examples/graphics/rgb24/makefile index 3ec9cfe..9fa35ec 100644 --- a/examples/graphics/rgb24/makefile +++ b/examples/graphics/rgb24/makefile @@ -1,37 +1,65 @@ -include ../../examples-setup.mk +# PSn00bSDK makefile template +# Part of the PSn00bSDK Project +# 2019 - 2021 Lameguy64 / Meido-Tek Productions -TARGET = rgb24.elf +## Settings -CFILES = $(notdir $(wildcard *.c)) -CPPFILES = $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) +PSN00BSDK_LIBS ?= ../../../libpsn00b -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o)) +# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's +# root folder (it only depends on environment variables). +include ../../../psn00bsdk-setup.mk -INCLUDE += -LIBDIRS += +# Project target name +TARGET = rgb24 -LIBS = -lpsxgpu -lpsxetc -lpsxapi -lc +## Files -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections -CPPFLAGS = $(CFLAGS) -fno-exceptions -AFLAGS = -g -msoft-float -LDFLAGS = -g -Ttext=0x80010000 -gc-sections \ - -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x +# Searches for C, C++ and S (assembler) files in local directory +CFILES = $(notdir $(wildcard *.c)) +CPPFILES= $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) + +# Create names for object files +OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ + $(addprefix build/,$(CPPFILES:.cpp=.o)) \ + $(addprefix build/,$(AFILES:.s=.o)) + +# Project specific includes and libraries +# (use -I for include dirs, -L for library dirs, -l for static libraries) +INCLUDE += +LIBDIRS += +LIBS += + +## Build rules + +#all: iso +all: build/$(TARGET) + +iso: build/$(TARGET) resources + $(MKPSXISO) -y -q iso.xml + +resources: + # Add commands to build/convert your assets here + #$(LZPACK) data.xml + +build/$(TARGET): $(OFILES) + @mkdir -p $(dir $@) + $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ + $(NM) -f posix -l -n $@ >$@.map + $(ELF2X) -q $@ $@.exe -all: $(OFILES) - $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) - elf2x -q $(TARGET) - build/%.o: %.c @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ - + $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ + +build/%.o: %.cpp + @mkdir -p $(dir $@) + $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ + build/%.o: %.s @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - -build/%.o: %.tim + $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ clean: - rm -rf build $(TARGET) $(TARGET:.elf=.exe) + rm -rf build diff --git a/examples/makefile b/examples/makefile index e02f7ba..bdc62ce 100644 --- a/examples/makefile +++ b/examples/makefile @@ -13,8 +13,8 @@ DIRS += graphics/balls graphics/billboard graphics/fpscam \ graphics/rgb24 # System related examples -DIRS += system/childexec system/console system/timer \ - system/tty +DIRS += system/childexec system/console system/dynlink \ + system/timer system/tty # Low-level examples DIRS += diff --git a/examples/system/childexec/child.c b/examples/system/childexec/child.c deleted file mode 100644 index 2ddfa73..0000000 --- a/examples/system/childexec/child.c +++ /dev/null @@ -1,326 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -/* OT and Packet Buffer sizes */ -#define OT_LEN 256 -#define PACKET_LEN 1024 - -/* Screen resolution */ -#define SCREEN_XRES 320 -#define SCREEN_YRES 240 - -/* Screen center position */ -#define CENTERX SCREEN_XRES>>1 -#define CENTERY SCREEN_YRES>>1 - - -/* Double buffer structure */ -typedef struct { - DISPENV disp; /* Display environment */ - DRAWENV draw; /* Drawing environment */ - u_long ot[OT_LEN]; /* Ordering table */ - char p[PACKET_LEN]; /* Packet buffer */ -} DB; - -/* Double buffer variables */ -DB db[2]; -int db_active = 0; -char *db_nextpri; - - -/* For easier handling of vertex indices */ -typedef struct { - short v0,v1,v2,v3; -} INDEX; - -/* Cube vertices */ -SVECTOR cube_verts[] = { - { -100, -100, -100, 0 }, - { 100, -100, -100, 0 }, - { -100, 100, -100, 0 }, - { 100, 100, -100, 0 }, - { 100, -100, 100, 0 }, - { -100, -100, 100, 0 }, - { 100, 100, 100, 0 }, - { -100, 100, 100, 0 } -}; - -/* Cube face normals */ -SVECTOR cube_norms[] = { - { 0, 0, -ONE, 0 }, - { 0, 0, ONE, 0 }, - { 0, -ONE, 0, 0 }, - { 0, ONE, 0, 0 }, - { -ONE, 0, 0, 0 }, - { ONE, 0, 0, 0 } -}; - -/* Cube vertex indices */ -INDEX cube_indices[] = { - { 0, 1, 2, 3 }, - { 4, 5, 6, 7 }, - { 5, 4, 0, 1 }, - { 6, 7, 3, 2 }, - { 0, 2, 5, 7 }, - { 3, 1, 6, 4 } -}; - -/* Number of faces of cube */ -#define CUBE_FACES 6 - - -/* Light color matrix */ -/* Each column represents the color matrix of each light source and is */ -/* used as material color when using gte_ncs() or multiplied by a */ -/* source color when using gte_nccs(). 4096 is 1.0 in this matrix */ -/* A column of zeroes disables the light source. */ -MATRIX color_mtx = { - ONE, 0, 0, /* Red */ - ONE, 0, 0, /* Green */ - ONE, 0, 0 /* Blue */ -}; - -/* Light matrix */ -/* Each row represents a vector direction of each light source. */ -/* An entire row of zeroes disables the light source. */ -MATRIX light_mtx = { - /* X, Y, Z */ - -2048 , -2048 , -2048, - 0 , 0 , 0, - 0 , 0 , 0 -}; - -char pad_buff[2][34]; - -/* Function declarations */ -void init(); -void display(); - - -/* Main function */ -int main(int argc, const char *argv[]) { - - int i,p,xy_temp; - - SVECTOR rot = { 0 }; /* Rotation vector for Rotmatrix */ - VECTOR pos = { 0, 0, 400 }; /* Translation vector for TransMatrix */ - MATRIX mtx,lmtx; /* Rotation matrices for geometry and lighting */ - - POLY_F4 *pol4; /* Flat shaded quad primitive pointer */ - - - printf( "Arguments passed: %d\n", argc ); - for( i=0; istat == 0 ) { - - // For digital pad, dual-analog and dual-shock - if( ( pad->type == 0x4 ) || ( pad->type == 0x5 ) || ( pad->type == 0x7 ) ) { - - if( !(pad->btn&PAD_SELECT) ) { - break; - } - - } - - } - - /* Set rotation and translation to the matrix */ - RotMatrix( &rot, &mtx ); - TransMatrix( &mtx, &pos ); - - /* Multiply light matrix by rotation matrix so light source */ - /* won't appear relative to the model's rotation */ - MulMatrix0( &light_mtx, &mtx, &lmtx ); - - /* Set rotation and translation matrix */ - gte_SetRotMatrix( &mtx ); - gte_SetTransMatrix( &mtx ); - - /* Set light matrix */ - gte_SetLightMatrix( &lmtx ); - - /* Make the cube SPEEN */ - rot.vx += 16; - rot.vz += 16; - - - /* Draw the cube */ - pol4 = (POLY_F4*)db_nextpri; - - for( i=0; i>2) > OT_LEN ) - continue; - - /* Initialize a quad primitive */ - setPolyF4( pol4 ); - - /* Set the projected vertices to the primitive */ - gte_stsxy0( &pol4->x0 ); - gte_stsxy1( &pol4->x1 ); - gte_stsxy2( &pol4->x2 ); - - /* Compute the last vertex and set the result */ - gte_ldv0( &cube_verts[cube_indices[i].v3] ); - gte_rtps(); - gte_stsxy( &pol4->x3 ); - - /* Load primitive color even though gte_ncs() doesn't use it. */ - /* This is so the GTE will output a color result with the */ - /* correct primitive code. */ - gte_ldrgb( &pol4->r0 ); - - /* Load the face normal */ - gte_ldv0( &cube_norms[i] ); - - /* Normal Color Single */ - gte_ncs(); - - /* Store result to the primitive */ - gte_strgb( &pol4->r0 ); - - /* Sort primitive to the ordering table */ - addPrim( db[db_active].ot+(p>>2), pol4 ); - - /* Advance to make another primitive */ - pol4++; - - } - - /* Update nextpri variable */ - /* (IMPORTANT if you plan to sort more primitives after this) */ - db_nextpri = (char*)pol4; - - /* Swap buffers and draw the primitives */ - display(); - - } - - StopPAD(); - - return 0; - -} - -void init() { - - /* Reset the GPU, also installs a VSync event handler */ - ResetGraph( 0 ); - - /* Set display and draw environment areas */ - /* (display and draw areas must be separate, otherwise hello flicker) */ - SetDefDispEnv( &db[0].disp, 0, 0, SCREEN_XRES, SCREEN_YRES ); - SetDefDrawEnv( &db[0].draw, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); - - /* Enable draw area clear and dither processing */ - setRGB0( &db[0].draw, 63, 0, 127 ); - db[0].draw.isbg = 1; - db[0].draw.dtd = 1; - - - /* Define the second set of display/draw environments */ - SetDefDispEnv( &db[1].disp, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); - SetDefDrawEnv( &db[1].draw, 0, 0, SCREEN_XRES, SCREEN_YRES ); - - setRGB0( &db[1].draw, 63, 0, 127 ); - db[1].draw.isbg = 1; - db[1].draw.dtd = 1; - - - /* Apply the drawing environment of the first double buffer */ - PutDrawEnv( &db[0].draw ); - - - /* Clear both ordering tables to make sure they are clean at the start */ - ClearOTagR( db[0].ot, OT_LEN ); - ClearOTagR( db[1].ot, OT_LEN ); - - /* Set primitive pointer address */ - db_nextpri = db[0].p; - - /* Initialize the GTE */ - InitGeom(); - - /* Set GTE offset (recommended method of centering) */ - gte_SetGeomOffset( CENTERX, CENTERY ); - - /* Set screen depth (basically FOV control, W/2 works best) */ - gte_SetGeomScreen( CENTERX ); - - /* Set light ambient color and light color matrix */ - gte_SetBackColor( 63, 63, 63 ); - gte_SetColorMatrix( &color_mtx ); - - InitPAD(pad_buff[0], 34, pad_buff[1], 34); - StartPAD(); - ChangeClearPAD(0); - -} - -void display() { - - /* Wait for GPU to finish drawing and vertical retrace */ - DrawSync( 0 ); - VSync( 0 ); - - /* Swap buffers */ - db_active ^= 1; - db_nextpri = db[db_active].p; - - /* Clear the OT of the next frame */ - ClearOTagR( db[db_active].ot, OT_LEN ); - - /* Apply display/drawing environments */ - PutDrawEnv( &db[db_active].draw ); - PutDispEnv( &db[db_active].disp ); - - /* Enable display */ - SetDispMask( 1 ); - - /* Start drawing the OT of the last buffer */ - DrawOTag( db[1-db_active].ot+(OT_LEN-1) ); - -} \ No newline at end of file diff --git a/examples/system/childexec/child/child.c b/examples/system/childexec/child/child.c new file mode 100644 index 0000000..2ddfa73 --- /dev/null +++ b/examples/system/childexec/child/child.c @@ -0,0 +1,326 @@ +#include +#include +#include +#include +#include +#include +#include + +/* OT and Packet Buffer sizes */ +#define OT_LEN 256 +#define PACKET_LEN 1024 + +/* Screen resolution */ +#define SCREEN_XRES 320 +#define SCREEN_YRES 240 + +/* Screen center position */ +#define CENTERX SCREEN_XRES>>1 +#define CENTERY SCREEN_YRES>>1 + + +/* Double buffer structure */ +typedef struct { + DISPENV disp; /* Display environment */ + DRAWENV draw; /* Drawing environment */ + u_long ot[OT_LEN]; /* Ordering table */ + char p[PACKET_LEN]; /* Packet buffer */ +} DB; + +/* Double buffer variables */ +DB db[2]; +int db_active = 0; +char *db_nextpri; + + +/* For easier handling of vertex indices */ +typedef struct { + short v0,v1,v2,v3; +} INDEX; + +/* Cube vertices */ +SVECTOR cube_verts[] = { + { -100, -100, -100, 0 }, + { 100, -100, -100, 0 }, + { -100, 100, -100, 0 }, + { 100, 100, -100, 0 }, + { 100, -100, 100, 0 }, + { -100, -100, 100, 0 }, + { 100, 100, 100, 0 }, + { -100, 100, 100, 0 } +}; + +/* Cube face normals */ +SVECTOR cube_norms[] = { + { 0, 0, -ONE, 0 }, + { 0, 0, ONE, 0 }, + { 0, -ONE, 0, 0 }, + { 0, ONE, 0, 0 }, + { -ONE, 0, 0, 0 }, + { ONE, 0, 0, 0 } +}; + +/* Cube vertex indices */ +INDEX cube_indices[] = { + { 0, 1, 2, 3 }, + { 4, 5, 6, 7 }, + { 5, 4, 0, 1 }, + { 6, 7, 3, 2 }, + { 0, 2, 5, 7 }, + { 3, 1, 6, 4 } +}; + +/* Number of faces of cube */ +#define CUBE_FACES 6 + + +/* Light color matrix */ +/* Each column represents the color matrix of each light source and is */ +/* used as material color when using gte_ncs() or multiplied by a */ +/* source color when using gte_nccs(). 4096 is 1.0 in this matrix */ +/* A column of zeroes disables the light source. */ +MATRIX color_mtx = { + ONE, 0, 0, /* Red */ + ONE, 0, 0, /* Green */ + ONE, 0, 0 /* Blue */ +}; + +/* Light matrix */ +/* Each row represents a vector direction of each light source. */ +/* An entire row of zeroes disables the light source. */ +MATRIX light_mtx = { + /* X, Y, Z */ + -2048 , -2048 , -2048, + 0 , 0 , 0, + 0 , 0 , 0 +}; + +char pad_buff[2][34]; + +/* Function declarations */ +void init(); +void display(); + + +/* Main function */ +int main(int argc, const char *argv[]) { + + int i,p,xy_temp; + + SVECTOR rot = { 0 }; /* Rotation vector for Rotmatrix */ + VECTOR pos = { 0, 0, 400 }; /* Translation vector for TransMatrix */ + MATRIX mtx,lmtx; /* Rotation matrices for geometry and lighting */ + + POLY_F4 *pol4; /* Flat shaded quad primitive pointer */ + + + printf( "Arguments passed: %d\n", argc ); + for( i=0; istat == 0 ) { + + // For digital pad, dual-analog and dual-shock + if( ( pad->type == 0x4 ) || ( pad->type == 0x5 ) || ( pad->type == 0x7 ) ) { + + if( !(pad->btn&PAD_SELECT) ) { + break; + } + + } + + } + + /* Set rotation and translation to the matrix */ + RotMatrix( &rot, &mtx ); + TransMatrix( &mtx, &pos ); + + /* Multiply light matrix by rotation matrix so light source */ + /* won't appear relative to the model's rotation */ + MulMatrix0( &light_mtx, &mtx, &lmtx ); + + /* Set rotation and translation matrix */ + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + + /* Set light matrix */ + gte_SetLightMatrix( &lmtx ); + + /* Make the cube SPEEN */ + rot.vx += 16; + rot.vz += 16; + + + /* Draw the cube */ + pol4 = (POLY_F4*)db_nextpri; + + for( i=0; i>2) > OT_LEN ) + continue; + + /* Initialize a quad primitive */ + setPolyF4( pol4 ); + + /* Set the projected vertices to the primitive */ + gte_stsxy0( &pol4->x0 ); + gte_stsxy1( &pol4->x1 ); + gte_stsxy2( &pol4->x2 ); + + /* Compute the last vertex and set the result */ + gte_ldv0( &cube_verts[cube_indices[i].v3] ); + gte_rtps(); + gte_stsxy( &pol4->x3 ); + + /* Load primitive color even though gte_ncs() doesn't use it. */ + /* This is so the GTE will output a color result with the */ + /* correct primitive code. */ + gte_ldrgb( &pol4->r0 ); + + /* Load the face normal */ + gte_ldv0( &cube_norms[i] ); + + /* Normal Color Single */ + gte_ncs(); + + /* Store result to the primitive */ + gte_strgb( &pol4->r0 ); + + /* Sort primitive to the ordering table */ + addPrim( db[db_active].ot+(p>>2), pol4 ); + + /* Advance to make another primitive */ + pol4++; + + } + + /* Update nextpri variable */ + /* (IMPORTANT if you plan to sort more primitives after this) */ + db_nextpri = (char*)pol4; + + /* Swap buffers and draw the primitives */ + display(); + + } + + StopPAD(); + + return 0; + +} + +void init() { + + /* Reset the GPU, also installs a VSync event handler */ + ResetGraph( 0 ); + + /* Set display and draw environment areas */ + /* (display and draw areas must be separate, otherwise hello flicker) */ + SetDefDispEnv( &db[0].disp, 0, 0, SCREEN_XRES, SCREEN_YRES ); + SetDefDrawEnv( &db[0].draw, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); + + /* Enable draw area clear and dither processing */ + setRGB0( &db[0].draw, 63, 0, 127 ); + db[0].draw.isbg = 1; + db[0].draw.dtd = 1; + + + /* Define the second set of display/draw environments */ + SetDefDispEnv( &db[1].disp, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); + SetDefDrawEnv( &db[1].draw, 0, 0, SCREEN_XRES, SCREEN_YRES ); + + setRGB0( &db[1].draw, 63, 0, 127 ); + db[1].draw.isbg = 1; + db[1].draw.dtd = 1; + + + /* Apply the drawing environment of the first double buffer */ + PutDrawEnv( &db[0].draw ); + + + /* Clear both ordering tables to make sure they are clean at the start */ + ClearOTagR( db[0].ot, OT_LEN ); + ClearOTagR( db[1].ot, OT_LEN ); + + /* Set primitive pointer address */ + db_nextpri = db[0].p; + + /* Initialize the GTE */ + InitGeom(); + + /* Set GTE offset (recommended method of centering) */ + gte_SetGeomOffset( CENTERX, CENTERY ); + + /* Set screen depth (basically FOV control, W/2 works best) */ + gte_SetGeomScreen( CENTERX ); + + /* Set light ambient color and light color matrix */ + gte_SetBackColor( 63, 63, 63 ); + gte_SetColorMatrix( &color_mtx ); + + InitPAD(pad_buff[0], 34, pad_buff[1], 34); + StartPAD(); + ChangeClearPAD(0); + +} + +void display() { + + /* Wait for GPU to finish drawing and vertical retrace */ + DrawSync( 0 ); + VSync( 0 ); + + /* Swap buffers */ + db_active ^= 1; + db_nextpri = db[db_active].p; + + /* Clear the OT of the next frame */ + ClearOTagR( db[db_active].ot, OT_LEN ); + + /* Apply display/drawing environments */ + PutDrawEnv( &db[db_active].draw ); + PutDispEnv( &db[db_active].disp ); + + /* Enable display */ + SetDispMask( 1 ); + + /* Start drawing the OT of the last buffer */ + DrawOTag( db[1-db_active].ot+(OT_LEN-1) ); + +} \ No newline at end of file diff --git a/examples/system/childexec/child_exe.s b/examples/system/childexec/child_exe.s index 842ac88..66bd0e2 100644 --- a/examples/system/childexec/child_exe.s +++ b/examples/system/childexec/child_exe.s @@ -3,4 +3,4 @@ .global child_exe # Insert spoopypasta .type child_exe, @object child_exe: - .incbin "child.exe" \ No newline at end of file + .incbin "build/child/child.exe" \ No newline at end of file diff --git a/examples/system/childexec/makefile b/examples/system/childexec/makefile index 30229ae..e801739 100644 --- a/examples/system/childexec/makefile +++ b/examples/system/childexec/makefile @@ -1,36 +1,93 @@ -include ../../examples-setup.mk +# PSn00bSDK makefile template +# Part of the PSn00bSDK Project +# 2019 - 2021 Lameguy64 / Meido-Tek Productions -INCLUDE += -LIBDIRS += +## Settings -LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc +PSN00BSDK_LIBS ?= ../../../libpsn00b -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections -CPPFLAGS = $(CFLAGS) -fno-exceptions -AFLAGS = -g -msoft-float -LDFLAGS = -g -gc-sections \ - -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x +# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's +# root folder (it only depends on environment variables). +include ../../../psn00bsdk-setup.mk -LDFLAGS_P = $(LDFLAGS) -Ttext=0x80010000 -LDFLAGS_C = $(LDFLAGS) -Ttext=0x80030000 +# Project target name +#TARGET = childexec -all: child parent +## Files -child: build/child.o - $(LD) $(LDFLAGS_C) $(LIBDIRS) build/child.o $(LIBS) -o child.elf - elf2x -q child.elf +# Searches for C, C++ and S (assembler) files in local directory +CFILES_PARENT = $(notdir $(wildcard *.c)) +CPPFILES_PARENT = $(notdir $(wildcard *.cpp)) +AFILES_PARENT = $(notdir $(wildcard *.s)) + +CFILES_CHILD = $(notdir $(wildcard child/*.c)) +CPPFILES_CHILD = $(notdir $(wildcard child/*.cpp)) +AFILES_CHILD = $(notdir $(wildcard child/*.s)) + +# Create names for object files +OFILES_PARENT = $(addprefix build/,$(CFILES_PARENT:.c=.o)) \ + $(addprefix build/,$(CPPFILES_PARENT:.cpp=.o)) \ + $(addprefix build/,$(AFILES_PARENT:.s=.o)) +OFILES_CHILD = $(addprefix build/child/,$(CFILES_CHILD:.c=.o)) \ + $(addprefix build/child/,$(CPPFILES_CHILD:.cpp=.o)) \ + $(addprefix build/child/,$(AFILES_CHILD:.s=.o)) + +# Project specific includes and libraries +# (use -I for include dirs, -L for library dirs, -l for static libraries) +INCLUDE += +LIBDIRS += +LIBS += + +# Relocate the child executable to 0x30000 +LDFLAGS_CHILD = -Ttext=0x80030000 + +## Build rules + +#all: iso +all: build/child/child build/parent + +iso: build/child/child build/parent resources + $(MKPSXISO) -y -q iso.xml + +resources: + # Add commands to build/convert your assets here + #$(LZPACK) data.xml + +build/child/child: $(OFILES_CHILD) + @mkdir -p $(dir $@) + $(LD) $(LDFLAGS_EXE) $(LDFLAGS_CHILD) $(LIBDIRS) $^ $(LIBS) -o $@ + $(NM) -f posix -l -n $@ >$@.map + $(ELF2X) -q $@ $@.exe + +build/parent: $(OFILES_PARENT) + @mkdir -p $(dir $@) + $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ + $(NM) -f posix -l -n $@ >$@.map + $(ELF2X) -q $@ $@.exe + +build/child/%.o: child/%.c + @mkdir -p $(dir $@) + $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ + +build/child/%.o: child/%.cpp + @mkdir -p $(dir $@) + $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ + +build/child/%.o: child/%.s + @mkdir -p $(dir $@) + $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ -parent: build/parent.o build/child_exe.o - $(LD) $(LDFLAGS_P) $(LIBDIRS) build/parent.o build/child_exe.o $(LIBS) -o parent.elf - elf2x -q parent.elf - build/%.o: %.c @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ - + $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ + +build/%.o: %.cpp + @mkdir -p $(dir $@) + $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ + build/%.o: %.s @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - + $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ + clean: - rm -rf build parent.elf parent.exe child.elf child.exe + rm -rf build diff --git a/examples/system/console/makefile b/examples/system/console/makefile index 1ee638f..addf02a 100644 --- a/examples/system/console/makefile +++ b/examples/system/console/makefile @@ -1,54 +1,65 @@ -include ../../examples-setup.mk +# PSn00bSDK makefile template +# Part of the PSn00bSDK Project +# 2019 - 2021 Lameguy64 / Meido-Tek Productions + +## Settings + +PSN00BSDK_LIBS ?= ../../../libpsn00b + +# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's +# root folder (it only depends on environment variables). +include ../../../psn00bsdk-setup.mk # Project target name -TARGET = console.elf +TARGET = console + +## Files # Searches for C, C++ and S (assembler) files in local directory -CFILES = $(notdir $(wildcard *.c)) -CPPFILES = $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) +CFILES = $(notdir $(wildcard *.c)) +CPPFILES= $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) -# Determine object files -OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ - $(addprefix build/,$(CPPFILES:.cpp=.o)) \ - $(addprefix build/,$(AFILES:.s=.o)) +# Create names for object files +OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ + $(addprefix build/,$(CPPFILES:.cpp=.o)) \ + $(addprefix build/,$(AFILES:.s=.o)) -# Project specific include and library directories -# (use -I for include dirs, -L for library dirs) -INCLUDE += -LIBDIRS += +# Project specific includes and libraries +# (use -I for include dirs, -L for library dirs, -l for static libraries) +INCLUDE += +LIBDIRS += +LIBS += -# Libraries to link -LIBS = -lpsxsio -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc +## Build rules -# C compiler flags -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections +#all: iso +all: build/$(TARGET) -# C++ compiler flags -CPPFLAGS = $(CFLAGS) -fno-exceptions +iso: build/$(TARGET) resources + $(MKPSXISO) -y -q iso.xml -# Assembler flags -AFLAGS = -g -msoft-float +resources: + # Add commands to build/convert your assets here + #$(LZPACK) data.xml -# Linker flags -LDFLAGS = -g -Ttext=0x80010000 -gc-sections \ - -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x +build/$(TARGET): $(OFILES) + @mkdir -p $(dir $@) + $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ + $(NM) -f posix -l -n $@ >$@.map + $(ELF2X) -q $@ $@.exe -all: $(OFILES) - $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) - elf2x -q $(TARGET) - build/%.o: %.c @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ - + $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ + build/%.o: %.cpp @mkdir -p $(dir $@) - $(CXX) $(AFLAGS) $(INCLUDE) -c $< -o $@ - + $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ + build/%.o: %.s @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - + $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ + clean: - rm -rf build $(TARGET) $(TARGET:.elf=.exe) + rm -rf build diff --git a/examples/system/timer/makefile b/examples/system/timer/makefile index a8defe7..c418af4 100644 --- a/examples/system/timer/makefile +++ b/examples/system/timer/makefile @@ -1,35 +1,65 @@ -include ../../examples-setup.mk +# PSn00bSDK makefile template +# Part of the PSn00bSDK Project +# 2019 - 2021 Lameguy64 / Meido-Tek Productions -TARGET = timer.elf +## Settings -CFILES = $(notdir $(wildcard *.c)) -CPPFILES = $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) +PSN00BSDK_LIBS ?= ../../../libpsn00b -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o)) +# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's +# root folder (it only depends on environment variables). +include ../../../psn00bsdk-setup.mk -INCLUDE += -LIBDIRS += +# Project target name +TARGET = timer -LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc +## Files -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections -CPPFLAGS = $(CFLAGS) -fno-exceptions -AFLAGS = -g -msoft-float -LDFLAGS = -g -Ttext=0x80010000 -gc-sections \ - -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x +# Searches for C, C++ and S (assembler) files in local directory +CFILES = $(notdir $(wildcard *.c)) +CPPFILES= $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) + +# Create names for object files +OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ + $(addprefix build/,$(CPPFILES:.cpp=.o)) \ + $(addprefix build/,$(AFILES:.s=.o)) + +# Project specific includes and libraries +# (use -I for include dirs, -L for library dirs, -l for static libraries) +INCLUDE += +LIBDIRS += +LIBS += + +## Build rules + +#all: iso +all: build/$(TARGET) + +iso: build/$(TARGET) resources + $(MKPSXISO) -y -q iso.xml + +resources: + # Add commands to build/convert your assets here + #$(LZPACK) data.xml + +build/$(TARGET): $(OFILES) + @mkdir -p $(dir $@) + $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ + $(NM) -f posix -l -n $@ >$@.map + $(ELF2X) -q $@ $@.exe -all: $(OFILES) - $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) - elf2x -q $(TARGET) - build/%.o: %.c @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ - + $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ + +build/%.o: %.cpp + @mkdir -p $(dir $@) + $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ + build/%.o: %.s @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - + $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ + clean: - rm -rf build $(TARGET) $(TARGET:.elf=.exe) + rm -rf build diff --git a/examples/system/tty/makefile b/examples/system/tty/makefile index 43893d5..381aa41 100644 --- a/examples/system/tty/makefile +++ b/examples/system/tty/makefile @@ -1,54 +1,65 @@ -include ../../examples-setup.mk +# PSn00bSDK makefile template +# Part of the PSn00bSDK Project +# 2019 - 2021 Lameguy64 / Meido-Tek Productions + +## Settings + +PSN00BSDK_LIBS ?= ../../../libpsn00b + +# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's +# root folder (it only depends on environment variables). +include ../../../psn00bsdk-setup.mk # Project target name -TARGET = tty.elf +TARGET = tty + +## Files # Searches for C, C++ and S (assembler) files in local directory -CFILES = $(notdir $(wildcard *.c)) -CPPFILES = $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) +CFILES = $(notdir $(wildcard *.c)) +CPPFILES= $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) -# Determine object files -OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ - $(addprefix build/,$(CPPFILES:.cpp=.o)) \ - $(addprefix build/,$(AFILES:.s=.o)) +# Create names for object files +OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ + $(addprefix build/,$(CPPFILES:.cpp=.o)) \ + $(addprefix build/,$(AFILES:.s=.o)) -# Project specific include and library directories -# (use -I for include dirs, -L for library dirs) -INCLUDE += -LIBDIRS += +# Project specific includes and libraries +# (use -I for include dirs, -L for library dirs, -l for static libraries) +INCLUDE += +LIBDIRS += +LIBS += -# Libraries to link -LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc +## Build rules -# C compiler flags -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections +#all: iso +all: build/$(TARGET) -# C++ compiler flags -CPPFLAGS = $(CFLAGS) -fno-exceptions +iso: build/$(TARGET) resources + $(MKPSXISO) -y -q iso.xml -# Assembler flags -AFLAGS = -g -msoft-float +resources: + # Add commands to build/convert your assets here + #$(LZPACK) data.xml -# Linker flags -LDFLAGS = -g -Ttext=0x80010000 -gc-sections \ - -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x +build/$(TARGET): $(OFILES) + @mkdir -p $(dir $@) + $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ + $(NM) -f posix -l -n $@ >$@.map + $(ELF2X) -q $@ $@.exe -all: $(OFILES) - $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) - elf2x -q $(TARGET) - build/%.o: %.c @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ - + $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ + build/%.o: %.cpp @mkdir -p $(dir $@) - $(CXX) $(AFLAGS) $(INCLUDE) -c $< -o $@ - + $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ + build/%.o: %.s @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - + $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ + clean: - rm -rf build $(TARGET) $(TARGET:.elf=.exe) + rm -rf build diff --git a/libpsn00b/ldscripts/dll.ld b/libpsn00b/ldscripts/dll.ld new file mode 100644 index 0000000..59cbb53 --- /dev/null +++ b/libpsn00b/ldscripts/dll.ld @@ -0,0 +1,122 @@ +/* + * PSn00bSDK linker script for dynamically-loaded libraries + * (C) 2021 spicyjpeg - MPL licensed + * + * This script is similar to the one for executables. The main differences are + * the header at the beginning of the file, the .sdata/.sbss sections being + * replaced by the global offset table (GOT) and .bss being merged with .data. + */ + +OUTPUT_FORMAT(elf32-littlemips) +/*ENTRY(_start) +STARTUP(start.o)*/ + +MEMORY { + /* Code is position-independent, so we just set zero as address */ + RELOC_RAM (rwx) : ORIGIN = 0x00000000, LENGTH = 1M +} + +SECTIONS { + /* + * DLL "header", containing the following sections: + * + * .dynamic: key-value pairs describing various section offsets, flags and + * other stuff + * .dynsym: dynamic symbol table, listing all functions to relocate as well + * as exported symbols + * .hash: pre-generated hash table to quickly look up symbol table + * entries by their names + * .dynstr: string blob referenced by symbol table entries + */ + + .dynamic : { *(.dynamic) } > RELOC_RAM + .dynsym : { *(.dynsym) } > RELOC_RAM + .hash : { *(.hash) } > RELOC_RAM + .dynstr : { *(.dynstr) } > RELOC_RAM + + /* Text section, i.e. code and constants */ + + .text : ALIGN(16) { + __text_start = .; + + *(.text .text.* .gnu.linkonce.t.*) + *(.plt .MIPS.stubs) + } > RELOC_RAM + .rodata : { + *(.rodata .rodata.* .gnu.linkonce.r.*) + } > RELOC_RAM + + /* Global constructor and destructor arrays (length-prefixed) */ + + /* + * https://sourceware.org/binutils/docs/ld/Output-Section-Keywords.html + * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46770 + */ + .ctors : ALIGN(16) { + __CTOR_LIST__ = .; + + LONG(((__CTOR_END__ - __CTOR_LIST__) / 4) - 2) + KEEP(*(SORT(.ctors.*))) + KEEP(*(.ctors)) + LONG(0) + + __CTOR_END__ = .; + } > RELOC_RAM + .dtors : ALIGN(16) { + __DTOR_LIST__ = .; + + LONG(((__DTOR_END__ - __DTOR_LIST__) / 4) - 2) + KEEP(*(SORT(.dtors.*))) + KEEP(*(.dtors)) + LONG(0) + + __DTOR_END__ = .; + } > RELOC_RAM + + /* Data and BSS sections, i.e. variables */ + + .data : { + *(.data .data.* .gnu.linkonce.d.*) + + /* + * Merge the .bss section into the .data section, so uninitialized + * variables are treated as if they were initialized and preallocated. + * This makes DLLs unnecessarily larger (BSS values shouldn't be stored + * as they are always zero) but greatly simplifies the dynamic linker, + * as we don't have to worry about managing .bss separately from the + * main DLL blob. + */ + __bss_start = .; + + *(.bss .bss.* .gnu.linkonce.b.*) + *(COMMON) + + . = ALIGN((. != 0) ? 4 : 1); + } > RELOC_RAM + + /* + * Set _gp to point to the beginning of the GOT plus 0x7ff0, so anything + * within the GOT can be accessed using the $gp register as base plus a + * signed 16-bit immediate. Note that $gp is set to _gp in all exported + * functions (GCC adds the relevant code automatically). + */ + HIDDEN(_gp = ALIGN(16) + 0x7ff0); + + .got : { + *(.got) + } > RELOC_RAM + + _end = .; + + /* Dummy section */ + + .dummy (NOLOAD) : { + KEEP(*(.dummy)) + } > RELOC_RAM + + /* Remove anything flagged as link-time optimized */ + + /DISCARD/ : { + *(.gnu.lto_*) + } +} diff --git a/libpsn00b/ldscripts/exe.ld b/libpsn00b/ldscripts/exe.ld new file mode 100644 index 0000000..3033636 --- /dev/null +++ b/libpsn00b/ldscripts/exe.ld @@ -0,0 +1,114 @@ +/* + * PSn00bSDK linker script for executables + * (C) 2021 spicyjpeg - MPL licensed + * + * GP-relative addressing (i.e. placing small variables in a 64 KB block and + * using $gp to reference them) is fully supported; the block is made up of + * sections .sdata and .sbss. Note that GP-relative addressing is not + * compatible with dynamic linking, as DLLs require GP to be unused. + */ + +OUTPUT_FORMAT(elf32-littlemips) +ENTRY(_start) +/*STARTUP(start.o)*/ + +MEMORY { + /* Mapped into KSEG0 */ + KERNEL_RAM (rwx) : ORIGIN = 0x80000000, LENGTH = 0x010000 + APP_RAM (rwx) : ORIGIN = 0x80010000, LENGTH = 0x1f0000 +} + +SECTIONS { + /* Text section, i.e. code and constants */ + + .text : { + __text_start = .; + + *(.text .text.* .gnu.linkonce.t.*) + *(.plt .MIPS.stubs) + } > APP_RAM + .rodata : { + *(.rodata .rodata.* .gnu.linkonce.r.*) + } > APP_RAM + + /* Global constructor and destructor arrays (length-prefixed) */ + + /* + * TODO: replace this crap with .init_array and .fini_array, which are the + * "modern" way of doing it without reversed arrays and weird length + * prefixes. That would require even more patching though. + * + * https://sourceware.org/binutils/docs/ld/Output-Section-Keywords.html + * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46770 + */ + .ctors : ALIGN(16) { + __CTOR_LIST__ = .; + + LONG(((__CTOR_END__ - __CTOR_LIST__) / 4) - 2) + KEEP(*(SORT(.ctors.*))) + KEEP(*(.ctors)) + LONG(0) + + __CTOR_END__ = .; + } > APP_RAM + .dtors : ALIGN(16) { + __DTOR_LIST__ = .; + + LONG(((__DTOR_END__ - __DTOR_LIST__) / 4) - 2) + KEEP(*(SORT(.dtors.*))) + KEEP(*(.dtors)) + LONG(0) + + __DTOR_END__ = .; + } > APP_RAM + + /* Data sections, i.e. variables with default values */ + + .data : { + *(.data .data.* .gnu.linkonce.d.*) + } > APP_RAM + + /* + * Set _gp to point to the beginning of .sdata plus 0x7ff0, so anything + * within .sdata (and .sbss) can be accessed using the $gp register as + * base plus a signed 16-bit immediate. Note that $gp is set to _gp on + * boot by _start() in the SDK. + */ + HIDDEN(_gp = ALIGN(16) + 0x7ff0); + + .sdata : { + *(.sdata .sdata.* .gnu.linkonce.s.*) + } > APP_RAM + + /* BSS sections, i.e. uninitialized variables */ + + __bss_start = .; + + .sbss (NOLOAD) : { + *(.sbss .sbss.* .gnu.linkonce.sb.*) + *(.scommon) + } > APP_RAM + .bss (NOLOAD) : { + *(.bss .bss.* .gnu.linkonce.b.*) + *(COMMON) + + /* + * This crap was in the stock GCC linker script. + */ + . = ALIGN((. != 0) ? 4 : 1); + } > APP_RAM + + _end = .; + + /* Dummy section */ + + .dummy (NOLOAD) : { + KEEP(*(.dummy)) + } > APP_RAM + + /* Remove anything flagged as link-time optimized */ + + /DISCARD/ : { + *(.gnu.lto_*) + } +} diff --git a/libpsn00b/libc/makefile b/libpsn00b/libc/makefile index a515ad5..bb3a687 100644 --- a/libpsn00b/libc/makefile +++ b/libpsn00b/libc/makefile @@ -1,54 +1,61 @@ -# Run using make (Linux) or gmake (BSD) +# PSn00bSDK library makefile # Part of the PSn00bSDK Project -# 2019 - 2020 Lameguy64 / Meido-Tek Productions +# 2019 - 2021 Lameguy64 / Meido-Tek Productions -include ../../template/psn00bsdk-setup.mk +## Settings -TARGET = libc.a +PSN00BSDK_LIBS ?= .. -INCLUDE = -I../include +include ../../psn00bsdk-setup.mk -CFLAGS = -g -O2 -msoft-float -fno-builtin -fdata-sections \ - -ffunction-sections -Wa,--strip-local-absolute -AFLAGS = -g -msoft-float -Wa,-strip-local-absolute +# Project target name +TARGET = libc.a -CFILES = $(notdir $(wildcard ./*.c)) -CXXFILES = $(notdir $(wildcard ./*.cxx)) -AFILES = $(notdir $(wildcard ./*.s)) +## Files -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CXXFILES:.cxx=.o) \ - $(AFILES:.s=.o)) +# Searches for C, C++ and S (assembler) files in local directory +CFILES = $(notdir $(wildcard *.c)) +CXXFILES= $(notdir $(wildcard *.cxx)) +AFILES = $(notdir $(wildcard *.s)) -ifndef PSN00BSDK_LIBS +# Create names for object files +OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ + $(addprefix build/,$(CXXFILES:.cxx=.o)) \ + $(addprefix build/,$(AFILES:.s=.o)) -PSN00BSDK_LIBS = .. +# Project specific includes and libraries +# (use -I for include dirs, -L for library dirs, -l for static libraries) +INCLUDE += +LIBDIRS += +LIBS += -endif +## Build rules -all: $(TARGET) +all: build/$(TARGET) -$(TARGET): $(OFILES) - cp $(GCC_BASE)/lib/gcc/$(PREFIX)/$(GCC_VERSION)/libgcc.a ./$(TARGET) - $(AR) r $(TARGET) $(OFILES) - $(RANLIB) $(TARGET) +build/$(TARGET): $(OFILES) + @mkdir -p $(dir $@) + # "Import" libgcc's contents + cp $(GCC_BASE)/lib/gcc/$(PREFIX)/$(GCC_VERSION)/libgcc.a ./$@ + $(AR) rs $@ $(OFILES) build/%.o: %.c @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + $(CC) $(CFLAGS_LIB) $(INCLUDE) -c $< -o $@ build/%.o: %.cxx @mkdir -p $(dir $@) - $(CXX) $(CFLAGS) $(INCLUDE) -c $< -o $@ + $(CXX) $(CPPFLAGS_LIB) $(INCLUDE) -c $< -o $@ build/%.o: %.s @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ + $(CC) $(AFLAGS_LIB) $(INCLUDE) -c $< -o $@ install: ifneq ($(PSN00BSDK_LIBS), "..") @mkdir -p $(PSN00BSDK_LIBS) endif - cp $(TARGET) $(PSN00BSDK_LIBS)/$(TARGET) + cp build/$(TARGET) $(PSN00BSDK_LIBS)/$(TARGET) clean: - rm -Rf build $(TARGET) + rm -rf build diff --git a/libpsn00b/lzp/makefile b/libpsn00b/lzp/makefile index 729a500..02654ed 100644 --- a/libpsn00b/lzp/makefile +++ b/libpsn00b/lzp/makefile @@ -1,40 +1,59 @@ -# Run using make (Linux) or gmake (BSD) +# PSn00bSDK library makefile # Part of the PSn00bSDK Project -# 2019 - 2020 Lameguy64 / Meido-Tek Productions +# 2019 - 2021 Lameguy64 / Meido-Tek Productions -include ../../template/psn00bsdk-setup.mk +## Settings -TARGET = liblzp.a +PSN00BSDK_LIBS ?= .. -INCLUDE = -I../include +include ../../psn00bsdk-setup.mk -CFILES = $(notdir $(wildcard ./*.c)) -OFILES = $(addprefix build/,$(CFILES:.c=.o)) +# Project target name +TARGET = liblzp.a -CFLAGS = -g -O2 -msoft-float -fno-builtin -nostdlib -fdata-sections \ - -ffunction-sections -Wa,--strip-local-absolute +## Files -ifndef PSN00BSDK_LIBS +# Searches for C, C++ and S (assembler) files in local directory +CFILES = $(notdir $(wildcard *.c)) +CXXFILES= $(notdir $(wildcard *.cxx)) +AFILES = $(notdir $(wildcard *.s)) -PSN00BSDK_LIBS = .. +# Create names for object files +OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ + $(addprefix build/,$(CXXFILES:.cxx=.o)) \ + $(addprefix build/,$(AFILES:.s=.o)) -endif +# Project specific includes and libraries +# (use -I for include dirs, -L for library dirs, -l for static libraries) +INCLUDE += +LIBDIRS += +LIBS += -all: $(TARGET) +## Build rules + +all: build/$(TARGET) + +build/$(TARGET): $(OFILES) + @mkdir -p $(dir $@) + $(AR) crs $@ $(OFILES) -$(TARGET): $(OFILES) - $(AR) cr $(TARGET) $(OFILES) - $(RANLIB) $(TARGET) - build/%.o: %.c - @mkdir -p build - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + @mkdir -p $(dir $@) + $(CC) $(CFLAGS_LIB) $(INCLUDE) -c $< -o $@ + +build/%.o: %.cxx + @mkdir -p $(dir $@) + $(CXX) $(CPPFLAGS_LIB) $(INCLUDE) -c $< -o $@ + +build/%.o: %.s + @mkdir -p $(dir $@) + $(CC) $(AFLAGS_LIB) $(INCLUDE) -c $< -o $@ install: ifneq ($(PSN00BSDK_LIBS), "..") @mkdir -p $(PSN00BSDK_LIBS) endif - cp $(TARGET) $(PSN00BSDK_LIBS)/$(TARGET) + cp build/$(TARGET) $(PSN00BSDK_LIBS)/$(TARGET) clean: - rm -Rf build $(OFILES) $(TARGET) + rm -rf build diff --git a/libpsn00b/psxapi/makefile b/libpsn00b/psxapi/makefile index 0b0d603..f300e5f 100644 --- a/libpsn00b/psxapi/makefile +++ b/libpsn00b/psxapi/makefile @@ -1,41 +1,61 @@ -# Run using make (Linux) or gmake (BSD) +# PSn00bSDK library makefile # Part of the PSn00bSDK Project -# 2019 - 2020 Lameguy64 / Meido-Tek Productions +# 2019 - 2021 Lameguy64 / Meido-Tek Productions -include ../../template/psn00bsdk-setup.mk +## Settings -TARGET = libpsxapi.a +PSN00BSDK_LIBS ?= .. -INCLUDE = -I../include +include ../../psn00bsdk-setup.mk -SOURCES = stdio fs sys +# Project target name +TARGET = libpsxapi.a -AFILES = $(foreach dir,$(SOURCES),$(wildcard $(dir)/*.s)) -OFILES = $(addprefix build/,$(AFILES:.s=.o)) +## Files -AFLAGS = -g -msoft-float -Wa,--strip-local-absolute +SOURCES = stdio fs sys -ifndef PSN00BSDK_LIBS +# Searches for C, C++ and S (assembler) files in local directory +CFILES = $(foreach dir,$(SOURCES),$(wildcard $(dir)/*.c)) +CXXFILES= $(foreach dir,$(SOURCES),$(wildcard $(dir)/*.cxx)) +AFILES = $(foreach dir,$(SOURCES),$(wildcard $(dir)/*.s)) -PSN00BSDK_LIBS = .. +# Create names for object files +OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ + $(addprefix build/,$(CXXFILES:.cxx=.o)) \ + $(addprefix build/,$(AFILES:.s=.o)) -endif +# Project specific includes and libraries +# (use -I for include dirs, -L for library dirs, -l for static libraries) +INCLUDE += +LIBDIRS += +LIBS += -all: $(TARGET) - -$(TARGET): $(OFILES) - $(AR) cr $(TARGET) $(OFILES) - $(RANLIB) $(TARGET) +## Build rules + +all: build/$(TARGET) + +build/$(TARGET): $(OFILES) + @mkdir -p $(dir $@) + $(AR) crs $@ $(OFILES) + +build/%.o: %.c + @mkdir -p $(dir $@) + $(CC) $(CFLAGS_LIB) $(INCLUDE) -c $< -o $@ + +build/%.o: %.cxx + @mkdir -p $(dir $@) + $(CXX) $(CPPFLAGS_LIB) $(INCLUDE) -c $< -o $@ build/%.o: %.s @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ + $(CC) $(AFLAGS_LIB) $(INCLUDE) -c $< -o $@ install: ifneq ($(PSN00BSDK_LIBS), "..") @mkdir -p $(PSN00BSDK_LIBS) endif - cp $(TARGET) $(PSN00BSDK_LIBS)/$(TARGET) - + cp build/$(TARGET) $(PSN00BSDK_LIBS)/$(TARGET) + clean: - rm -Rf build $(TARGET) + rm -rf build diff --git a/libpsn00b/psxcd/makefile b/libpsn00b/psxcd/makefile index cf1eda5..ee9b958 100644 --- a/libpsn00b/psxcd/makefile +++ b/libpsn00b/psxcd/makefile @@ -1,46 +1,59 @@ -# Run using make (Linux) or gmake (BSD) +# PSn00bSDK library makefile # Part of the PSn00bSDK Project -# 2019 - 2020 Lameguy64 / Meido-Tek Productions +# 2019 - 2021 Lameguy64 / Meido-Tek Productions -include ../../template/psn00bsdk-setup.mk +## Settings -TARGET = libpsxcd.a +PSN00BSDK_LIBS ?= .. -INCLUDE = -I../include +include ../../psn00bsdk-setup.mk -CFILES = $(notdir $(wildcard ./*.c)) -AFILES = $(notdir $(wildcard ./*.s)) -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(AFILES:.s=.o)) +# Project target name +TARGET = libpsxcd.a -CFLAGS = -g -msoft-float -fno-builtin -fdata-sections \ - -ffunction-sections -Wa,--strip-local-absolute -AFLAGS = -g -msoft-float -Wa,--strip-local-absolute +## Files -ifndef PSN00BSDK_LIBS +# Searches for C, C++ and S (assembler) files in local directory +CFILES = $(notdir $(wildcard *.c)) +CXXFILES= $(notdir $(wildcard *.cxx)) +AFILES = $(notdir $(wildcard *.s)) -PSN00BSDK_LIBS = .. +# Create names for object files +OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ + $(addprefix build/,$(CXXFILES:.cxx=.o)) \ + $(addprefix build/,$(AFILES:.s=.o)) -endif +# Project specific includes and libraries +# (use -I for include dirs, -L for library dirs, -l for static libraries) +INCLUDE += +LIBDIRS += +LIBS += + +## Build rules -all: $(TARGET) +all: build/$(TARGET) -$(TARGET): $(OFILES) - $(AR) cr $(TARGET) $(OFILES) - $(RANLIB) $(TARGET) +build/$(TARGET): $(OFILES) + @mkdir -p $(dir $@) + $(AR) crs $@ $(OFILES) build/%.o: %.c @mkdir -p $(dir $@) - $(CC) -O2 $(CFLAGS) $(INCLUDE) -c $< -o $@ + $(CC) $(CFLAGS_LIB) $(INCLUDE) -c $< -o $@ + +build/%.o: %.cxx + @mkdir -p $(dir $@) + $(CXX) $(CPPFLAGS_LIB) $(INCLUDE) -c $< -o $@ build/%.o: %.s @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ + $(CC) $(AFLAGS_LIB) $(INCLUDE) -c $< -o $@ install: ifneq ($(PSN00BSDK_LIBS), "..") @mkdir -p $(PSN00BSDK_LIBS) endif - cp $(TARGET) $(PSN00BSDK_LIBS)/$(TARGET) + cp build/$(TARGET) $(PSN00BSDK_LIBS)/$(TARGET) clean: - rm -Rf build $(TARGET) + rm -rf build diff --git a/libpsn00b/psxetc/makefile b/libpsn00b/psxetc/makefile index cc12944..84bb64b 100644 --- a/libpsn00b/psxetc/makefile +++ b/libpsn00b/psxetc/makefile @@ -1,46 +1,59 @@ -# Run using make (Linux) or gmake (BSD) +# PSn00bSDK library makefile # Part of the PSn00bSDK Project -# 2019 - 2020 Lameguy64 / Meido-Tek Productions +# 2019 - 2021 Lameguy64 / Meido-Tek Productions -include ../../template/psn00bsdk-setup.mk +## Settings -TARGET = libpsxetc.a +PSN00BSDK_LIBS ?= .. -CFILES = $(notdir $(wildcard ./*.c)) -AFILES = $(notdir $(wildcard ./*.s)) -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(AFILES:.s=.o)) +include ../../psn00bsdk-setup.mk -CFLAGS = -g -O2 -msoft-float -fno-builtin -nostdlib -fdata-sections \ - -ffunction-sections -Wa,--strip-local-absolute -AFLAGS = -g -msoft-float -strip-local-absolute +# Project target name +TARGET = libpsxetc.a -INCLUDE = -I../include +## Files -ifndef PSN00BSDK_LIBS +# Searches for C, C++ and S (assembler) files in local directory +CFILES = $(notdir $(wildcard *.c)) +CXXFILES= $(notdir $(wildcard *.cxx)) +AFILES = $(notdir $(wildcard *.s)) -PSN00BSDK_LIBS = .. +# Create names for object files +OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ + $(addprefix build/,$(CXXFILES:.cxx=.o)) \ + $(addprefix build/,$(AFILES:.s=.o)) -endif +# Project specific includes and libraries +# (use -I for include dirs, -L for library dirs, -l for static libraries) +INCLUDE += +LIBDIRS += +LIBS += -all: $(TARGET) +## Build rules -$(TARGET): $(OFILES) - $(AR) cr $(TARGET) $(OFILES) - $(RANLIB) $(TARGET) +all: build/$(TARGET) + +build/$(TARGET): $(OFILES) + @mkdir -p $(dir $@) + $(AR) crs $@ $(OFILES) build/%.o: %.c @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + $(CC) $(CFLAGS_LIB) $(INCLUDE) -c $< -o $@ + +build/%.o: %.cxx + @mkdir -p $(dir $@) + $(CXX) $(CPPFLAGS_LIB) $(INCLUDE) -c $< -o $@ build/%.o: %.s @mkdir -p $(dir $@) - $(AS) $(AFLAGS) $(INCLUDE) $< -o $@ + $(CC) $(AFLAGS_LIB) $(INCLUDE) -c $< -o $@ install: ifneq ($(PSN00BSDK_LIBS), "..") @mkdir -p $(PSN00BSDK_LIBS) endif - cp $(TARGET) $(PSN00BSDK_LIBS)/$(TARGET) - + cp build/$(TARGET) $(PSN00BSDK_LIBS)/$(TARGET) + clean: - rm -Rf build $(TARGET) + rm -rf build diff --git a/libpsn00b/psxgpu/makefile b/libpsn00b/psxgpu/makefile index 5442958..adcb7fa 100644 --- a/libpsn00b/psxgpu/makefile +++ b/libpsn00b/psxgpu/makefile @@ -1,46 +1,59 @@ -# Run using make (Linux) or gmake (BSD) +# PSn00bSDK library makefile # Part of the PSn00bSDK Project -# 2019 - 2020 Lameguy64 / Meido-Tek Productions +# 2019 - 2021 Lameguy64 / Meido-Tek Productions -include ../../template/psn00bsdk-setup.mk +## Settings -TARGET = libpsxgpu.a +PSN00BSDK_LIBS ?= .. -INCLUDE = -I../include +include ../../psn00bsdk-setup.mk -CFILES = $(notdir $(wildcard ./*.c)) -AFILES = $(notdir $(wildcard ./*.s)) -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(AFILES:.s=.o)) +# Project target name +TARGET = libpsxgpu.a -CFLAGS = -g -O2 -msoft-float -fno-builtin -fdata-sections \ - -ffunction-sections -Wa,--strip-local-absolute -AFLAGS = -g -msoft-float -Wa,--strip-local-absolute +## Files -ifndef PSN00BSDK_LIBS +# Searches for C, C++ and S (assembler) files in local directory +CFILES = $(notdir $(wildcard *.c)) +CXXFILES= $(notdir $(wildcard *.cxx)) +AFILES = $(notdir $(wildcard *.s)) -PSN00BSDK_LIBS = .. +# Create names for object files +OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ + $(addprefix build/,$(CXXFILES:.cxx=.o)) \ + $(addprefix build/,$(AFILES:.s=.o)) -endif +# Project specific includes and libraries +# (use -I for include dirs, -L for library dirs, -l for static libraries) +INCLUDE += +LIBDIRS += +LIBS += -all: $(TARGET) +## Build rules -$(TARGET): $(OFILES) - $(AR) cr $(TARGET) $(OFILES) - $(RANLIB) $(TARGET) +all: build/$(TARGET) + +build/$(TARGET): $(OFILES) + @mkdir -p $(dir $@) + $(AR) crs $@ $(OFILES) build/%.o: %.c @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + $(CC) $(CFLAGS_LIB) $(INCLUDE) -c $< -o $@ + +build/%.o: %.cxx + @mkdir -p $(dir $@) + $(CXX) $(CPPFLAGS_LIB) $(INCLUDE) -c $< -o $@ build/%.o: %.s @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ + $(CC) $(AFLAGS_LIB) $(INCLUDE) -c $< -o $@ install: ifneq ($(PSN00BSDK_LIBS), "..") @mkdir -p $(PSN00BSDK_LIBS) endif - cp $(TARGET) $(PSN00BSDK_LIBS)/$(TARGET) + cp build/$(TARGET) $(PSN00BSDK_LIBS)/$(TARGET) clean: - rm -Rf build $(TARGET) + rm -rf build diff --git a/libpsn00b/psxgte/makefile b/libpsn00b/psxgte/makefile index 7c1683f..e60ff1e 100644 --- a/libpsn00b/psxgte/makefile +++ b/libpsn00b/psxgte/makefile @@ -1,46 +1,59 @@ -# Run using make (Linux) or gmake (BSD) +# PSn00bSDK library makefile # Part of the PSn00bSDK Project -# 2019 - 2020 Lameguy64 / Meido-Tek Productions +# 2019 - 2021 Lameguy64 / Meido-Tek Productions -include ../../template/psn00bsdk-setup.mk +## Settings -TARGET = libpsxgte.a +PSN00BSDK_LIBS ?= .. -INCLUDE = -I../include +include ../../psn00bsdk-setup.mk -CFILES = $(notdir $(wildcard ./*.c)) -AFILES = $(notdir $(wildcard ./*.s)) -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(AFILES:.s=.o)) +# Project target name +TARGET = libpsxgte.a -CFLAGS = -g -O2 -msoft-float -fno-builtin -fdata-sections \ - -ffunction-sections -Wa,--strip-local-absolute -AFLAGS = -g -msoft-float -strip-local-absolute +## Files -ifndef PSN00BSDK_LIBS +# Searches for C, C++ and S (assembler) files in local directory +CFILES = $(notdir $(wildcard *.c)) +CXXFILES= $(notdir $(wildcard *.cxx)) +AFILES = $(notdir $(wildcard *.s)) -PSN00BSDK_LIBS = .. +# Create names for object files +OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ + $(addprefix build/,$(CXXFILES:.cxx=.o)) \ + $(addprefix build/,$(AFILES:.s=.o)) -endif +# Project specific includes and libraries +# (use -I for include dirs, -L for library dirs, -l for static libraries) +INCLUDE += +LIBDIRS += +LIBS += + +## Build rules -all: $(TARGET) +all: build/$(TARGET) -$(TARGET): $(OFILES) - $(AR) cr $(TARGET) $(OFILES) - $(RANLIB) $(TARGET) +build/$(TARGET): $(OFILES) + @mkdir -p $(dir $@) + $(AR) crs $@ $(OFILES) build/%.o: %.c @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + $(CC) $(CFLAGS_LIB) $(INCLUDE) -c $< -o $@ + +build/%.o: %.cxx + @mkdir -p $(dir $@) + $(CXX) $(CPPFLAGS_LIB) $(INCLUDE) -c $< -o $@ build/%.o: %.s @mkdir -p $(dir $@) - $(AS) $(AFLAGS) $(INCLUDE) $< -o $@ + $(CC) $(AFLAGS_LIB) $(INCLUDE) -c $< -o $@ install: ifneq ($(PSN00BSDK_LIBS), "..") @mkdir -p $(PSN00BSDK_LIBS) endif - cp $(TARGET) $(PSN00BSDK_LIBS)/$(TARGET) + cp build/$(TARGET) $(PSN00BSDK_LIBS)/$(TARGET) clean: - rm -Rf build $(TARGET) + rm -rf build diff --git a/libpsn00b/psxsio/makefile b/libpsn00b/psxsio/makefile index 06971ba..c9dcade 100644 --- a/libpsn00b/psxsio/makefile +++ b/libpsn00b/psxsio/makefile @@ -1,46 +1,59 @@ -# Run using make (Linux) or gmake (BSD) +# PSn00bSDK library makefile # Part of the PSn00bSDK Project -# 2019 - 2020 Lameguy64 / Meido-Tek Productions +# 2019 - 2021 Lameguy64 / Meido-Tek Productions -include ../../template/psn00bsdk-setup.mk +## Settings -TARGET = libpsxsio.a +PSN00BSDK_LIBS ?= .. -INCLUDE = -I../include +include ../../psn00bsdk-setup.mk -CFILES = $(notdir $(wildcard ./*.c)) -AFILES = $(notdir $(wildcard ./*.s)) -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(AFILES:.s=.o)) +# Project target name +TARGET = libpsxsio.a -CFLAGS = -g -O2 -msoft-float -fno-builtin -fdata-sections \ - -ffunction-sections -Wa,--strip-local-absolute -AFLAGS = -g -msoft-float -Wa,--strip-local-absolute +## Files -ifndef PSN00BSDK_LIBS +# Searches for C, C++ and S (assembler) files in local directory +CFILES = $(notdir $(wildcard *.c)) +CXXFILES= $(notdir $(wildcard *.cxx)) +AFILES = $(notdir $(wildcard *.s)) -PSN00BSDK_LIBS = .. +# Create names for object files +OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ + $(addprefix build/,$(CXXFILES:.cxx=.o)) \ + $(addprefix build/,$(AFILES:.s=.o)) -endif +# Project specific includes and libraries +# (use -I for include dirs, -L for library dirs, -l for static libraries) +INCLUDE += +LIBDIRS += +LIBS += + +## Build rules -all: $(TARGET) +all: build/$(TARGET) -$(TARGET): $(OFILES) - $(AR) cr $(TARGET) $(OFILES) - $(RANLIB) $(TARGET) +build/$(TARGET): $(OFILES) + @mkdir -p $(dir $@) + $(AR) crs $@ $(OFILES) build/%.o: %.c @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + $(CC) $(CFLAGS_LIB) $(INCLUDE) -c $< -o $@ + +build/%.o: %.cxx + @mkdir -p $(dir $@) + $(CXX) $(CPPFLAGS_LIB) $(INCLUDE) -c $< -o $@ build/%.o: %.s @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ + $(CC) $(AFLAGS_LIB) $(INCLUDE) -c $< -o $@ install: ifneq ($(PSN00BSDK_LIBS), "..") @mkdir -p $(PSN00BSDK_LIBS) endif - cp $(TARGET) $(PSN00BSDK_LIBS)/$(TARGET) + cp build/$(TARGET) $(PSN00BSDK_LIBS)/$(TARGET) clean: - rm -Rf build $(TARGET) + rm -rf build diff --git a/libpsn00b/psxspu/makefile b/libpsn00b/psxspu/makefile index 7948f34..5710f39 100644 --- a/libpsn00b/psxspu/makefile +++ b/libpsn00b/psxspu/makefile @@ -1,46 +1,59 @@ -# Run using make (Linux) or gmake (BSD) +# PSn00bSDK library makefile # Part of the PSn00bSDK Project -# 2019 - 2020 Lameguy64 / Meido-Tek Productions +# 2019 - 2021 Lameguy64 / Meido-Tek Productions -include ../../template/psn00bsdk-setup.mk +## Settings -TARGET = libpsxspu.a +PSN00BSDK_LIBS ?= .. -INCLUDE = -I../include +include ../../psn00bsdk-setup.mk -CFILES = $(notdir $(wildcard ./*.c)) -AFILES = $(notdir $(wildcard ./*.s)) -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(AFILES:.s=.o)) +# Project target name +TARGET = libpsxspu.a -CFLAGS = -g -O2 -msoft-float -fdata-sections -ffunction-sections \ - -Wa,--strip-local-absolute -AFLAGS = -g -msoft-float -strip-local-absolute +## Files -ifndef PSN00BSDK_LIBS +# Searches for C, C++ and S (assembler) files in local directory +CFILES = $(notdir $(wildcard *.c)) +CXXFILES= $(notdir $(wildcard *.cxx)) +AFILES = $(notdir $(wildcard *.s)) -PSN00BSDK_LIBS = .. +# Create names for object files +OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ + $(addprefix build/,$(CXXFILES:.cxx=.o)) \ + $(addprefix build/,$(AFILES:.s=.o)) -endif +# Project specific includes and libraries +# (use -I for include dirs, -L for library dirs, -l for static libraries) +INCLUDE += +LIBDIRS += +LIBS += + +## Build rules -all: $(TARGET) +all: build/$(TARGET) -$(TARGET): $(OFILES) - $(AR) cr $(TARGET) $(OFILES) - $(RANLIB) $(TARGET) +build/$(TARGET): $(OFILES) + @mkdir -p $(dir $@) + $(AR) crs $@ $(OFILES) build/%.o: %.c @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + $(CC) $(CFLAGS_LIB) $(INCLUDE) -c $< -o $@ + +build/%.o: %.cxx + @mkdir -p $(dir $@) + $(CXX) $(CPPFLAGS_LIB) $(INCLUDE) -c $< -o $@ build/%.o: %.s @mkdir -p $(dir $@) - $(AS) $(AFLAGS) $(INCLUDE) $< -o $@ - + $(CC) $(AFLAGS_LIB) $(INCLUDE) -c $< -o $@ + install: ifneq ($(PSN00BSDK_LIBS), "..") @mkdir -p $(PSN00BSDK_LIBS) endif - cp $(TARGET) $(PSN00BSDK_LIBS)/$(TARGET) - + cp build/$(TARGET) $(PSN00BSDK_LIBS)/$(TARGET) + clean: - rm -Rf build $(TARGET) + rm -rf build diff --git a/psn00bsdk-setup.mk b/psn00bsdk-setup.mk new file mode 100644 index 0000000..8417358 --- /dev/null +++ b/psn00bsdk-setup.mk @@ -0,0 +1,121 @@ +# PSn00bSDK project setup file +# Part of the PSn00bSDK Project +# 2019 - 2021 Lameguy64 / Meido-Tek Productions +# +# This file does not depend on any other files (besides paths specified via +# environment variables) and may be copied for use with your projects. See the +# template directory for a makefile template. + +#PREFIX ?= mipsel-none-elf +PREFIX ?= mipsel-unknown-elf + +## Path setup + +# PSn00bSDK library/include path setup +ifndef PSN00BSDK_LIBS + # Default assumes PSn00bSDK is in the same parent dir as this project + LIBDIRS = -L../libpsn00b + INCLUDE = -I../libpsn00b/include -I../libpsn00b/lzp + LDBASE = ../libpsn00b/ldscripts +else + LIBDIRS = -L$(PSN00BSDK_LIBS) + INCLUDE = -I$(PSN00BSDK_LIBS)/include -I$(PSN00BSDK_LIBS)/lzp + LDBASE = ${PSN00BSDK_LIBS}/ldscripts +endif + +# PSn00bSDK toolchain path setup +ifndef PSN00BSDK_TC + # Default assumes GCC toolchain is in root of C drive or /usr/local + ifeq "$(OS)" "Windows_NT" + GCC_BASE ?= /c/$(PREFIX) + GCC_BIN ?= + else + GCC_BASE ?= /usr/local/$(PREFIX) + GCC_BIN ?= + endif +else + GCC_BASE ?= $(PSN00BSDK_TC) + GCC_BIN ?= $(PSN00BSDK_TC)/bin/ +endif + +# Autodetect GCC version by folder name (ugly but it works, lol) +#GCC_VERSION ?= 7.4.0 +GCC_VERSION ?= $(word 1, $(notdir $(wildcard $(GCC_BASE)/lib/gcc/$(PREFIX)/*))) + +# PSn00bSDK tools path setup (TODO) +PSN00BSDK_BIN ?= + +## Commands + +# GCC toolchain +CC = $(GCC_BIN)$(PREFIX)-gcc +CXX = $(GCC_BIN)$(PREFIX)-g++ +AS = $(GCC_BIN)$(PREFIX)-as +AR = $(GCC_BIN)$(PREFIX)-ar +LD = $(GCC_BIN)$(PREFIX)-ld +RANLIB = $(GCC_BIN)$(PREFIX)-ranlib +OBJCOPY = $(GCC_BIN)$(PREFIX)-objcopy +NM = $(GCC_BIN)$(PREFIX)-nm + +# PSn00bSDK tools + mkpsxiso +ELF2X = $(PSN00BSDK_BIN)elf2x +LZPACK = $(PSN00BSDK_BIN)lzpack +SMXLINK = $(PSN00BSDK_BIN)smxlink +MKPSXISO = $(PSN00BSDK_BIN)mkpsxiso + +## Flags + +# SDK libraries (IMPORTANT: don't change the order) +LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxcd -lpsxsio -lpsxetc -lpsxapi -lc + +# Common options: +# - Debugging symbols enabled +# - Wrap each symbol in a separate section +# - Optimize for R3000, no FPU, 32-bit ABI +# - Division by zero causes break opcodes to be executed +# - C standard library (including libgcc) disabled +# - C++ features that rely on runtime support disabled +AFLAGS = -g -msoft-float -march=r3000 -mtune=r3000 -mabi=32 +CFLAGS = $(AFLAGS) -mdivide-breaks -O2 -ffreestanding -fno-builtin -nostdlib \ + -fdata-sections -ffunction-sections -fsigned-char -fno-strict-overflow +CPPFLAGS= $(CFLAGS) -fno-exceptions -fno-rtti -fno-unwind-tables \ + -fno-threadsafe-statics -fno-use-cxa-atexit +LDFLAGS = -nostdlib + +# Options for static libraries (and SDK libraries): +# - GP-relative addressing disabled +# - ABI-compatible calls disabled +# - Local stripping enabled +AFLAGS_LIB = $(AFLAGS) -G0 -Wa,--strip-local-absolute +CFLAGS_LIB = $(CFLAGS) -G0 -mno-abicalls -mno-gpopt +CPPFLAGS_LIB = $(CPPFLAGS) -G0 -mno-abicalls -mno-gpopt + +# Options for executables without support for dynamic linking: +# - Position-independent code disabled +# - GP-relative addressing enabled only for local symbols +# - ABI-compatible calls disabled (incompatible with GP-relative addressing) +# - Unused section stripping enabled +AFLAGS_EXE = $(AFLAGS) -G8 +CFLAGS_EXE = $(CFLAGS) -G8 -mno-abicalls -mgpopt -mno-extern-sdata +CPPFLAGS_EXE = $(CPPFLAGS) -G8 -mno-abicalls -mgpopt -mno-extern-sdata +LDFLAGS_EXE = $(LDFLAGS) -G8 -static -T$(LDBASE)/exe.ld -gc-sections + +# Options for executables with support for dynamic linking: +# - Position-independent code disabled +# - GP-relative addressing disabled +# - ABI-compatible calls disabled (must be done manually) +# - Unused section stripping enabled +AFLAGS_EXEDYN = $(AFLAGS) -G0 +CFLAGS_EXEDYN = $(CFLAGS) -G0 -mno-abicalls -mno-gpopt +CPPFLAGS_EXEDYN = $(CPPFLAGS) -G0 -mno-abicalls -mno-gpopt +LDFLAGS_EXEDYN = $(LDFLAGS) -G0 -static -T$(LDBASE)/exe.ld -gc-sections + +# Options for dynamically-loaded libraries: +# - Position-independent code enabled +# - GP-relative addressing disabled (incompatible with ABI calls) +# - ABI-compatible calls enabled +# - Unused section stripping not available +AFLAGS_DLL = $(AFLAGS) -G0 +CFLAGS_DLL = $(CFLAGS) -G0 -mabicalls -mshared -mno-gpopt -fPIC +CPPFLAGS_DLL = $(CPPFLAGS) -G0 -mabicalls -mshared -mno-gpopt -fPIC +LDFLAGS_DLL = $(LDFLAGS) -G0 -shared -T$(LDBASE)/dll.ld diff --git a/template/iso.xml b/template/iso.xml new file mode 100644 index 0000000..ba2b29d --- /dev/null +++ b/template/iso.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + diff --git a/template/makefile b/template/makefile index 42ff370..707a8d7 100644 --- a/template/makefile +++ b/template/makefile @@ -1,54 +1,69 @@ -include psn00bsdk-setup.mk +# PSn00bSDK makefile template +# Part of the PSn00bSDK Project +# 2019 - 2021 Lameguy64 / Meido-Tek Productions + +## Settings + +# You can edit these here or pass them as environment variables. +#PREFIX = +#GCC_VERSION = +#PSN00BSDK_TC = +#PSN00BSDK_LIBS = + +# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's +# root folder (it only depends on environment variables). +include ../psn00bsdk-setup.mk # Project target name -TARGET = template.elf +TARGET = template + +## Files # Searches for C, C++ and S (assembler) files in local directory -CFILES = $(notdir $(wildcard *.c)) -CPPFILES = $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) +CFILES = $(notdir $(wildcard *.c)) +CPPFILES= $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) # Create names for object files -OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ - $(addprefix build/,$(CPPFILES:.cpp=.o)) \ - $(addprefix build/,$(AFILES:.s=.o)) +OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ + $(addprefix build/,$(CPPFILES:.cpp=.o)) \ + $(addprefix build/,$(AFILES:.s=.o)) -# Project specific include and library directories -# (use -I for include dirs, -L for library dirs) -INCLUDE += -LIBDIRS += +# Project specific includes and libraries +# (use -I for include dirs, -L for library dirs, -l for static libraries) +INCLUDE += +LIBDIRS += +LIBS += -# Libraries to link -LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc +## Build rules -# C compiler flags -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections +all: iso +#all: build/$(TARGET) -# C++ compiler flags -CPPFLAGS = $(CFLAGS) -fno-exceptions +iso: build/$(TARGET) resources + $(MKPSXISO) -y -q iso.xml -# Assembler flags -AFLAGS = -g +resources: + # Add commands to build/convert your assets here + #$(LZPACK) data.xml -# Linker flags (-Ttext specifies the program text address) -LDFLAGS = -g -Ttext=0x80010000 -gc-sections \ - -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x +build/$(TARGET): $(OFILES) + @mkdir -p $(dir $@) + $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ + $(NM) -f posix -l -n $@ >$@.map + $(ELF2X) -q $@ $@.exe -all: $(OFILES) - $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) - elf2x -q $(TARGET) - build/%.o: %.c @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ - + $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ + build/%.o: %.cpp @mkdir -p $(dir $@) - $(CXX) $(AFLAGS) $(INCLUDE) -c $< -o $@ - + $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ + build/%.o: %.s @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - + $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ + clean: - rm -rf build $(TARGET) $(TARGET:.elf=.exe) + rm -rf build diff --git a/template/psn00bsdk-setup.mk b/template/psn00bsdk-setup.mk deleted file mode 100644 index 6ba23ae..0000000 --- a/template/psn00bsdk-setup.mk +++ /dev/null @@ -1,68 +0,0 @@ -# PSn00bSDK project setup file -# Part of the PSn00bSDK Project -# 2019 - 2020 Lameguy64 / Meido-Tek Productions -# -# This file may be copied for use with your projects, see the template -# directory for a makefile template - -ifndef PREFIX - -PREFIX = mipsel-unknown-elf - -endif # PREFIX - -ifndef GCC_VERSION - -GCC_VERSION = 7.4.0 - -endif # GCC_VERSION - -# PSn00bSDK library/include path setup -ifndef PSN00BSDK_LIBS - -# Default assumes PSn00bSDK is in the same parent dir as this project - -LIBDIRS = -L../psn00bsdk/libpsn00b -INCLUDE = -I../psn00bsdk/libpsn00b/include - -else - -LIBDIRS = -L$(PSN00BSDK_LIBS) -INCLUDE = -I$(PSN00BSDK_LIBS)/include - -endif # PSN00BSDK_LIBS - -# PSn00bSDK toolchain path setup -ifndef GCC_BASE - -ifndef PSN00BSDK_TC - -# Default assumes GCC toolchain is in root of C drive or /usr/local - -ifeq "$(OS)" "Windows_NT" - -GCC_BASE = /c/mipsel-unknown-elf -GCC_BIN = - -else - -GCC_BASE = /usr/local/mipsel-unknown-elf -GCC_BIN = - -endif - -else - -GCC_BASE = $(PSN00BSDK_TC) -GCC_BIN = $(PSN00BSDK_TC)/bin/ - -endif # PSN00BSDK_TC - -endif # GCC_BASE - -CC = $(GCC_BIN)$(PREFIX)-gcc -CXX = $(GCC_BIN)$(PREFIX)-g++ -AS = $(GCC_BIN)$(PREFIX)-as -AR = $(GCC_BIN)$(PREFIX)-ar -LD = $(GCC_BIN)$(PREFIX)-ld -RANLIB = $(GCC_BIN)$(PREFIX)-ranlib \ No newline at end of file diff --git a/template/system.cnf b/template/system.cnf new file mode 100644 index 0000000..e221726 --- /dev/null +++ b/template/system.cnf @@ -0,0 +1,4 @@ +BOOT=cdrom:\template.exe;1 +TCB=4 +EVENT=10 +STACK=801FFFF0 diff --git a/toolchain.txt b/toolchain.txt index 439f486..e67cfe1 100644 --- a/toolchain.txt +++ b/toolchain.txt @@ -107,12 +107,27 @@ Under Windows, you'll have to add the path to the PATH environment variable through System Properties. -Updating the ldscript: +Note regarding C++ support: + +C++ support in PSn00bSDK only goes as far as basic classes, namespaces and +the ability to dynamically create and delete class objects at any point of +the program. The required dependencies are supplied by libc of libpsn00b. + +Standard C++ libraries are not implemented and likely never going to be +implemented due to bloat concerns that it may introduce. Besides, the official +SDK lacks full C++ support as well. + +If you're trying to compile with C++ code and you get a linker error about +undefined vtables, try specifying --fno-rtti to the g++ command line. + +----------------------------------------------------------------------------- +Updating the ldscript (NO LONGER REQUIRED as PSn00bSDK now ships with its own +linker scripts, the section below is only kept for reference): -The following changes are required in order for basic C++ functionality to work -in PSn00bSDK. The changes define the constructor and deconstructor sections -which are required for the relevant support functions in PSn00bSDK's libc -library to be linked properly for C++. +The following changes used to be required in order for basic C++ functionality +to work in older PSn00bSDK versions. The changes define the constructor and +deconstructor sections which are required for the relevant support functions +in PSn00bSDK's libc library to be linked properly for C++. * Go to mipsel-unknown-elf/lib/ldscripts in the toolchain directory. @@ -150,16 +165,3 @@ Alternatively, you can make a copy of the ldscript file and modify it within your project directory. This is especially useful if your project uses code overlays. - -Note regarding C++ support: - -C++ support in PSn00bSDK only goes as far as basic classes, namespaces and -the ability to dynamically create and delete class objects at any point of -the program. The required dependencies are supplied by libc of libpsn00b. - -Standard C++ libraries are not implemented and likely never going to be -implemented due to bloat concerns that it may introduce. Besides, the official -SDK lacks full C++ support as well. - -If you're trying to compile with C++ code and you get a linker error about -undefined vtables, try specifying --fno-rtti to the g++ command line. \ No newline at end of file -- cgit v1.2.3