diff --git a/.clang-format b/.clang-format new file mode 100755 index 0000000..8a3795a --- /dev/null +++ b/.clang-format @@ -0,0 +1,46 @@ +# .clang-format for native code portion + +BasedOnStyle: Google + +# force T* or T& +DerivePointerAlignment: false +PointerAlignment: Left + +TabWidth: 4 +IndentWidth: 4 +UseTab: Always +IndentPPDirectives: BeforeHash + +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortFunctionsOnASingleLine: InlineOnly +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: true + +BinPackArguments: true +BinPackParameters: true +BreakConstructorInitializers: BeforeColon +BreakStringLiterals: false + +ColumnLimit: 150 +CompactNamespaces: false + +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ContinuationIndentWidth: 0 + +# turning this on causes major issues with initializer lists +Cpp11BracedListStyle: false +SpaceBeforeCpp11BracedList: true + +FixNamespaceComments: true + +NamespaceIndentation: All +ReflowComments: true + +SortIncludes: CaseInsensitive +SortUsingDeclarations: true + +SpacesInSquareBrackets: false +SpaceBeforeParens: Never +SpacesBeforeTrailingComments: 1 diff --git a/.gitignore b/.gitignore index c2c5afb..6df5a29 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ bin/ **/obj +/.cache +/compile_commands.json \ No newline at end of file diff --git a/Makefile b/Makefile index 8695c14..6a543a8 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: all copy clean +.PHONY: all copy clean bear TOP=$(shell pwd) @@ -9,10 +9,12 @@ endif all: make -C rom/ee TOP=$(TOP) CONFIG=$(CONFIG) + make -C rom/iop TOP=$(TOP) CONFIG=$(CONFIG) make -C rom TOP=$(TOP) CONFIG=$(CONFIG) clean: make -C rom/ee TOP=$(TOP) CONFIG=$(CONFIG) clean + make -C rom/iop TOP=$(TOP) CONFIG=$(CONFIG) clean make -C rom TOP=$(TOP) CONFIG=$(CONFIG) clean # copy to PCSX2 BIOS root @@ -21,3 +23,6 @@ clean: # ROMDIR (and the BIOS selection menu only shows ROMs with a ROMDIR) copy: cp bin/ps2rom_$(CONFIG).rom ~/.config/PCSX2/bios + +bear: + bear -- $(MAKE) CONFIG=$(CONFIG) \ No newline at end of file diff --git a/build/core.mk b/build/core.mk index 50f5b6d..09572c9 100644 --- a/build/core.mk +++ b/build/core.mk @@ -29,6 +29,8 @@ OBJECTS := $(patsubst %.c,obj/$(CONFIG)/%.o,$(filter %.c,$(SRCS))) OBJECTS += $(patsubst %.cpp,obj/$(CONFIG)/%.o,$(filter %.cpp,$(SRCS))) OBJECTS += $(patsubst %.s,obj/$(CONFIG)/%.o,$(filter %.s,$(SRCS))) +CFLAGS := $(CFLAGS) $(INCS) + # include target-specific recipies specifying how to # build for the target. include $(TOP)/build/targets/$(TARGET).mk diff --git a/rom/Makefile b/rom/Makefile index 770b86a..3cc5169 100644 --- a/rom/Makefile +++ b/rom/Makefile @@ -1,5 +1,5 @@ NAME=ps2rom -TARGET=iop +TARGET=ee KIND=bin SELF=$(shell pwd) @@ -11,7 +11,9 @@ LDFLAGS = -nostartfiles -nodefaultlibs -Wl,-Map,$(BINDIR)/$(FINALNAME).map -T$(S # Link to each portion of the ROM codebase. For now, # this will only link to the EE ROM codebase. -LIBS=-lps2rom_ee_$(CONFIG) +LIBS=-lps2rom_ee_$(CONFIG) + +#-lps2rom_iop_$(CONFIG) # sources SRCS = rom_start.s @@ -30,6 +32,10 @@ $(BINDIR)/: $(OBJDIR)/: mkdir -p $@ +# make sure to assemble the primary ROM start routine +# as MIPS-I, so that we don't get into any issues. +$(OBJDIR)/rom_start.o: AS += -march=r3000 + $(BINDIR)/$(FINALNAME).rom: $(BINDIR)/$(FINALNAME).elf $(OBJCOPY) -O binary $< $@ diff --git a/rom/ee/Makefile b/rom/ee/Makefile index 008fd19..f672b5c 100644 --- a/rom/ee/Makefile +++ b/rom/ee/Makefile @@ -9,6 +9,7 @@ CXXFLAGS = -fno-exceptions -fno-rtti # sources SRCS = _ee_start.s \ + ee_sio.c \ ee_start.c .PHONY: all clean clean-products diff --git a/rom/ee/ee_sio.c b/rom/ee/ee_sio.c new file mode 100644 index 0000000..36a6572 --- /dev/null +++ b/rom/ee/ee_sio.c @@ -0,0 +1,11 @@ +//! EE SIO implementation +#include + +void SIO_putc(char c) { + *((char*)0x1000f180) = c; +} + +void SIO_puts(const char* s) { + while(*s) + SIO_putc(*s++); +} \ No newline at end of file diff --git a/rom/ee/ee_start.c b/rom/ee/ee_start.c index 85ccf64..66d57f6 100644 --- a/rom/ee/ee_start.c +++ b/rom/ee/ee_start.c @@ -1,16 +1,8 @@ - -#define __noreturn __attribute__((noreturn)) - -static void putc(char c) { - *((char*)0x1000f180) = c; -} - -static void puts(const char* s) { - while (*s) - putc(*s++); -} +#include "shared/sio.h" +#include "shared/attributes.h" __noreturn void _ee_start() { - puts("EE: Hello World from Lily~\n"); - while(1); + SIO_puts("EE: Hello World from Lily~\n"); + while(1) + ; } diff --git a/rom/iop/Makefile b/rom/iop/Makefile new file mode 100644 index 0000000..0569aca --- /dev/null +++ b/rom/iop/Makefile @@ -0,0 +1,29 @@ +NAME=ps2rom_iop +TARGET=iop +KIND=lib + +INCS = -I$(TOP)/rom + +CFLAGS = -ffreestanding -fno-stack-protector +CXXFLAGS = -fno-exceptions -fno-rtti + +# sources +SRCS = _iop_start.s \ + iop_sio.c \ + iop_start.c + +.PHONY: all clean clean-products + +include $(TOP)/build/core.mk + +all: $(BINDIR)/lib$(FINALNAME).a + +$(BINDIR)/: + mkdir -p $@ + +$(OBJDIR)/: + mkdir -p $@ + +clean: clean-products + +include $(TOP)/build/products/$(KIND).mk diff --git a/rom/iop/_iop_start.s b/rom/iop/_iop_start.s new file mode 100644 index 0000000..224c0d1 --- /dev/null +++ b/rom/iop/_iop_start.s @@ -0,0 +1,10 @@ +.set noat +.globl _iop_start +.extern iop_start + +// __noreturn __naked void _iop_start() +// This is the primary entrypoint for the IOP code +_iop_start: + li $sp, 0x001fffc0 // temporary stack (2<<20-0x40) + move $fp, $sp + j iop_start diff --git a/rom/iop/iop_sio.c b/rom/iop/iop_sio.c new file mode 100644 index 0000000..5e59866 --- /dev/null +++ b/rom/iop/iop_sio.c @@ -0,0 +1,11 @@ +//! IOP SIO implementation +#include + +void SIO_putc(char c) { + *((char*)0x1f80380c) = c; +} + +void SIO_puts(const char* s) { + while(*s) + SIO_putc(*s++); +} \ No newline at end of file diff --git a/rom/iop/iop_start.c b/rom/iop/iop_start.c new file mode 100644 index 0000000..685d32f --- /dev/null +++ b/rom/iop/iop_start.c @@ -0,0 +1,24 @@ +#include "shared/attributes.h" +#include "shared/sio.h" + +__noreturn void _iop_start() { + // setup iop + *(char*)0xbf802070 = 9; + + // Poke around with the cache control registers + // + *(int*)0xfffe0130 = 0xcc4; + *(int*)0xfffe0130 = 0xcc0; + + // it seems like if bit 8 is set here, + // then the cache control is set nearly + // exactly like the PS1 kernel did + if((*(int*)0xbf801450) & 8) + *(int*)0xfffe0130 = 0x1e988; + else + *(int*)0xfffe0130 = 0x1edd8; + + SIO_puts("IOP: Hello World from Lily~\n"); + while(1) + ; +} diff --git a/rom/link.ld b/rom/link.ld index 4962398..4a8e29e 100644 --- a/rom/link.ld +++ b/rom/link.ld @@ -1,14 +1,21 @@ _stack_size = 0x80000; _heap_size = 1024*1024*10; +_text_origin = 0xbfc00000; + ENTRY(_start); SECTIONS { - .text 0xbfc00000 : { - _text_origin = .; - *start.o /* Always link reset first */ + . = 0xbfc00000; + + .text : { + *rom_start.o /* Always link reset as the first object */ + + *(libps2rom_ee_*.a) + *(libps2rom_iop_*.a) *(.text) *(.rodata) + *(.rodata.*) } _text_size = . - _text_origin; diff --git a/rom/rom_start.s b/rom/rom_start.s index ff394c2..d53c2c4 100644 --- a/rom/rom_start.s +++ b/rom/rom_start.s @@ -10,8 +10,9 @@ .org 0 .set noat -// externs +// externs from each piece of the code .extern _ee_start +.extern _iop_start .globl _start _start: @@ -21,5 +22,7 @@ _start: nop j _ee_start // Call EE start routine nop -__iop: // for now the iop stalls. +__iop: j __iop + //j _iop_start // Call IOP start routine + //nop \ No newline at end of file diff --git a/rom/shared/attributes.h b/rom/shared/attributes.h new file mode 100644 index 0000000..fe8cb36 --- /dev/null +++ b/rom/shared/attributes.h @@ -0,0 +1 @@ +#define __noreturn __attribute__((noreturn)) \ No newline at end of file diff --git a/rom/shared/sio.h b/rom/shared/sio.h new file mode 100644 index 0000000..5e58eee --- /dev/null +++ b/rom/shared/sio.h @@ -0,0 +1,16 @@ +#ifndef SIO_H +#define SIO_H + +#ifdef __cplusplus +extern "C" { +#endif + +void SIO_putc(char c); + +void SIO_puts(const char* s); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file