*: clean up code

The EE side of the code has been moved to a library at rom/ee.

The rom/ tree now simply builds the rom entrypoint, and will link to
both libraries, allowing them to be seperate and manages.

The buildsystem has now been greatly refactored, and IOP support kind of
exists now? Only kind of, I haven't really tested if it works yet
This commit is contained in:
Lily Tsuru 2023-11-06 01:56:09 -05:00
parent d7e07280d0
commit feb0648b9a
16 changed files with 193 additions and 110 deletions

View File

@ -1,4 +1,4 @@
.PHONY: all clean .PHONY: all copy clean
TOP=$(shell pwd) TOP=$(shell pwd)
@ -8,7 +8,16 @@ CONFIG=release
endif endif
all: all:
make -C rom/ee TOP=$(TOP) CONFIG=$(CONFIG)
make -C rom TOP=$(TOP) CONFIG=$(CONFIG) make -C rom TOP=$(TOP) CONFIG=$(CONFIG)
clean: clean:
make -C rom/ee TOP=$(TOP) CONFIG=$(CONFIG) clean
make -C rom TOP=$(TOP) CONFIG=$(CONFIG) clean make -C rom TOP=$(TOP) CONFIG=$(CONFIG) clean
# copy to PCSX2 BIOS root
# NOTE: You will have to manually edit the PCSX2 ini file,
# since our ROM file does not have anything resembling a
# ROMDIR (and the BIOS selection menu only shows ROMs with a ROMDIR)
copy:
cp bin/ps2rom_$(CONFIG).rom ~/.config/PCSX2/bios

6
README.md Normal file
View File

@ -0,0 +1,6 @@
# ps2rom
A bare-metal "template"? for the PS2. This essentially builds a replacement BIOS for both the EE and IOP.
No EE kernel, or IOP RTOS is loaded in this state. It's up to you to write the code to initalize either side of the system.

View File

@ -23,14 +23,14 @@ BINDIR = $(TOP)/bin
OBJDIR = obj/$(CONFIG) OBJDIR = obj/$(CONFIG)
# include target-specific recipies specifying how to
# build for the target.
include $(TOP)/build/$(TARGET)-common.mk
#include $(TOP)/build/$(TARGET)-$(KIND).mk
FINALNAME=$(NAME)_$(CONFIG) FINALNAME=$(NAME)_$(CONFIG)
OBJECTS := $(patsubst %.c,obj/$(CONFIG)/%.o,$(filter %.c,$(SRCS))) OBJECTS := $(patsubst %.c,obj/$(CONFIG)/%.o,$(filter %.c,$(SRCS)))
OBJECTS += $(patsubst %.cpp,obj/$(CONFIG)/%.o,$(filter %.cpp,$(SRCS))) OBJECTS += $(patsubst %.cpp,obj/$(CONFIG)/%.o,$(filter %.cpp,$(SRCS)))
OBJECTS += $(patsubst %.s,obj/$(CONFIG)/%.o,$(filter %.s,$(SRCS))) OBJECTS += $(patsubst %.s,obj/$(CONFIG)/%.o,$(filter %.s,$(SRCS)))
# include target-specific recipies specifying how to
# build for the target.
include $(TOP)/build/targets/$(TARGET).mk

View File

@ -1,12 +0,0 @@
FINALNAME=$(NAME)_$(CONFIG)
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)))
$(BINDIR)/$(FINALNAME).elf: $(OBJDIR)/ $(BINDIR)/ $(OBJECTS)
$(LD) $(LDFLAGS) $(LIBS) $(OBJECTS) -o $@
clean-products:
-rm $(BINDIR)/$(FINALNAME).elf
-rm -rf obj

View File

@ -1,36 +0,0 @@
# common EE toolchain stuff
# EE toolchain root.
EE_TRIPLET=mips64r5900el-ps2-elf
CC=$(EE_TRIPLET)-gcc
AS=$(CC) -mabi=32 -march=r3000 #HACK
CXX=$(EE_TRIPLET)-g++
#LD=$(CC)
LD=mipsel-ps2-irx-gcc # HACK
AR=$(EE_TRIPLET)-ar
OBJCOPY=$(EE_TRIPLET)-objcopy
ifeq ($(CONFIG),release)
CFLAGS := $(CFLAGS) -G0 -O3 -Wall -Wextra -Werror -fno-common -fno-strict-aliasing
ASFLAGS := -xassembler-with-cpp
endif
ifeq ($(CONFIG),debug)
CFLAGS := $(CFLAGS) -G0 -O0 -g3 -Wall -Wextra -fno-common -fno-strict-aliasing
ASFLAGS := -xassembler-with-cpp -g3
endif
CXXFLAGS := $(CXXFLAGS) $(CFLAGS)
# compile rules
$(OBJDIR)/%.o: %.c
$(CC) -c $(CFLAGS) $< -o $@
$(OBJDIR)/%.o: %.cpp
$(CXX) -c $(CXXFLAGS) $< -o $@
$(OBJDIR)/%.o: %.s
$(AS) -c $(ASFLAGS) $< -o $@

View File

@ -1,12 +0,0 @@
FINALNAME=$(NAME)_$(CONFIG)
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)))
clean-products:
-rm $(BINDIR)/lib$(FINALNAME).a
-rm -rf obj
$(BINDIR)/lib$(FINALNAME).a: $(OBJDIR)/ $(BINDIR)/ $(OBJECTS)
$(AR) rv $@ $(OBJECTS)

7
build/products/bin.mk Normal file
View File

@ -0,0 +1,7 @@
$(BINDIR)/$(FINALNAME).elf: $(OBJDIR)/ $(BINDIR)/ $(OBJECTS)
$(LD) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $@
clean-products:
-rm $(BINDIR)/$(FINALNAME).elf
-rm $(BINDIR)/$(FINALNAME).map
-rm -rf obj

8
build/products/lib.mk Normal file
View File

@ -0,0 +1,8 @@
$(BINDIR)/lib$(FINALNAME).a: $(OBJDIR)/ $(BINDIR)/ $(OBJECTS)
$(AR) rv $@ $(OBJECTS)
clean-products:
-rm $(BINDIR)/lib$(FINALNAME).a
-rm -rf obj

41
build/targets/ee.mk Normal file
View File

@ -0,0 +1,41 @@
# common EE toolchain stuff
# EE toolchain root.
EE_TRIPLET=mips64r5900el-ps2-elf
CC=$(EE_TRIPLET)-gcc
AS=$(CC)
CXX=$(EE_TRIPLET)-g++
# we need to use this to link, because
# we target the 32bit ABI, which the
# EE linker really doesn't like.
# It seems like a hack, probably because it is.
LD=mipsel-ps2-irx-gcc
AR=$(EE_TRIPLET)-ar
OBJCOPY=$(EE_TRIPLET)-objcopy
ifeq ($(CONFIG),release)
CFLAGS := $(CFLAGS) -mabi=32 -G0 -O3 -Wall -Wextra -Werror -fno-common -fno-strict-aliasing
ASFLAGS := -mabi=32 -xassembler-with-cpp $(ASFLAGS)
LDFLAGS := -s $(LDFLAGS)
endif
ifeq ($(CONFIG),debug)
CFLAGS := $(CFLAGS) -mabi=32 -G0 -O0 -g3 -Wall -Wextra -fno-common -fno-strict-aliasing
ASFLAGS := -mabi=32 -xassembler-with-cpp -g3 $(ASFLAGS)
endif
CXXFLAGS := $(CXXFLAGS) $(CFLAGS)
# compile rules
$(OBJDIR)/%.o: %.c
$(CC) -c $(CFLAGS) $< -o $@
$(OBJDIR)/%.o: %.cpp
$(CXX) -c $(CXXFLAGS) $< -o $@
$(OBJDIR)/%.o: %.s
$(AS) -c $(ASFLAGS) $< -o $@

35
build/targets/iop.mk Normal file
View File

@ -0,0 +1,35 @@
# common IOP toolchain stuff
# EE toolchain root.
IOP_TRIPLET=mipsel-ps2-irx
CC=$(IOP_TRIPLET)-gcc
AS=$(CC)
CXX=$(IOP_TRIPLET)-g++
LD=$(CC)
AR=$(IOP_TRIPLET)-ar
OBJCOPY=$(IOP_TRIPLET)-objcopy
ifeq ($(CONFIG),release)
CFLAGS := $(CFLAGS) -msoft-float -G0 -O3 -Wall -Wextra -Werror -fno-common -fno-strict-aliasing
ASFLAGS := -EL -xassembler-with-cpp
endif
ifeq ($(CONFIG),debug)
CFLAGS := $(CFLAGS) -msoft-float -G0 -O0 -g3 -Wall -Wextra -fno-common -fno-strict-aliasing
ASFLAGS := -EL -xassembler-with-cpp -g3
endif
CXXFLAGS := $(CXXFLAGS) $(CFLAGS)
# compile rules
$(OBJDIR)/%.o: %.c
$(CC) -c $(CFLAGS) $< -o $@
$(OBJDIR)/%.o: %.cpp
$(CXX) -c $(CXXFLAGS) $< -o $@
$(OBJDIR)/%.o: %.s
$(AS) -c $(ASFLAGS) $< -o $@

View File

@ -3,42 +3,41 @@ TARGET=ee
KIND=bin KIND=bin
SELF=$(shell pwd) SELF=$(shell pwd)
INCS = -I$(TOP)/src INCS = -I$(TOP)/rom
CFLAGS = -ffreestanding -fno-stack-protector -mabi=32 CFLAGS = -ffreestanding -fno-stack-protector
CXXFLAGS = -fno-exceptions -fno-rtti CXXFLAGS = -fno-exceptions -fno-rtti
LDFLAGS = -nostartfiles -nodefaultlibs -Wl,-Map,$(BINDIR)/$(FINALNAME).map -T$(SELF)/link.ld LDFLAGS = -nostartfiles -nodefaultlibs -Wl,-Map,$(BINDIR)/$(FINALNAME).map -T$(SELF)/link.ld -L$(BINDIR)
# Link to each portion of the ROM codebase. For now,
# this will only link to the EE ROM codebase.
LIBS=-lps2rom_ee_$(CONFIG)
# sources # sources
SRCS = start.s \ SRCS = rom_start.s
ee_start.c
.PHONY: all clean clean-products
include $(TOP)/build/core.mk include $(TOP)/build/core.mk
all: $(BINDIR)/$(FINALNAME).rom .PHONY: all clean clean-products
all: $(BINDIR)/$(FINALNAME).rom
$(BINDIR)/: $(BINDIR)/:
mkdir -p $@ mkdir -p $@
$(OBJDIR)/: $(OBJDIR)/:
mkdir -p $@ mkdir -p $@
# make sure to assemble the primary ROM start routine
clean-products: # as MIPS-I, so that we don't get into any issues.
-rm $(BINDIR)/$(FINALNAME).elf $(OBJDIR)/rom_start.o: AS += -march=r3000
-rm -rf obj
clean: clean-products
-rm $(BINDIR)/$(FINALNAME).rom
$(BINDIR)/$(FINALNAME).rom: $(BINDIR)/$(FINALNAME).elf $(BINDIR)/$(FINALNAME).rom: $(BINDIR)/$(FINALNAME).elf
$(OBJCOPY) -O binary $< $@ $(OBJCOPY) -O binary $< $@
$(BINDIR)/$(FINALNAME).elf: $(OBJDIR)/ $(BINDIR)/ $(OBJECTS) clean: clean-products
$(LD) $(LDFLAGS) $(LIBS) $(OBJECTS) -o $@ -rm $(BINDIR)/$(FINALNAME).rom
include $(TOP)/build/products/$(KIND).mk

28
rom/ee/Makefile Normal file
View File

@ -0,0 +1,28 @@
NAME=ps2rom_ee
TARGET=ee
KIND=lib
INCS = -I$(TOP)/rom
CFLAGS = -ffreestanding -fno-stack-protector
CXXFLAGS = -fno-exceptions -fno-rtti
# sources
SRCS = _ee_start.s \
ee_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

9
rom/ee/_ee_start.s Normal file
View File

@ -0,0 +1,9 @@
.set noat
.globl _ee_start
.extern ee_start
// __noreturn __naked void _ee_start()
// This is the primary entrypoint for the EE code
_ee_start:
li $sp, 0x80010000 // temporary stack
j ee_start

View File

@ -6,19 +6,11 @@ static void putc(char c) {
} }
static void puts(const char* s) { static void puts(const char* s) {
while (*s != 0) { while (*s)
putc(*s++); putc(*s++);
} }
}
__noreturn void _ee_start() { __noreturn void _ee_start() {
puts("Hello World from Riri~ (EE)\n"); puts("EE: Hello World from Lily~\n");
while(1); while(1);
} }
__asm__ (
".global ee_start\n"
"ee_start:\n"
"li $sp, 0x80010000\n"
"j _ee_start\n");

25
rom/rom_start.s Normal file
View File

@ -0,0 +1,25 @@
// This is the entry point of the ROM.
// It is limited to 32-bit MIPS-I code,
// because it runs on both the EE and the IOP.
//
// The task of this relatively short bit of code
// is to start the approiate part of the ROM
// on the correct processor.
//
// It's a bit creative, but also a bit annoying.
.org 0
.set noat
// externs
.extern _ee_start
.globl _start
_start:
mfc0 $at, $15 // load the PRID
sltiu $at, 0x59 // Check for EE PRID
bne $15, 0, __iop // Branch if not EE
nop
j _ee_start // Call EE start routine
nop
__iop: // for now the iop stalls.
j __iop

View File

@ -1,16 +0,0 @@
.org 0
.set noat
// externs
.extern ee_start
.globl _start
_start:
mfc0 $at, $15 // load PRID
sltiu $at, 0x59
bne $15, 0, __iop
nop
j ee_start
nop
__iop: // for now iop stalls.
j __iop