Skip to content

Commit

Permalink
Changes to use unpatched binutils for linking IRX
Browse files Browse the repository at this point in the history
  • Loading branch information
uyjulian committed Mar 15, 2022
1 parent f786346 commit 20e47ee
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 10 deletions.
2 changes: 1 addition & 1 deletion iop/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Licenced under Academic Free License version 2.0
# Review ps2sdk README & LICENSE files for further details.

SUBDIRS = kernel dev9 fs hdd sound tcpip usb system debug memorycard network iLink cdvd sio dvrp
SUBDIRS = kernel dev9 fs hdd sound tcpip usb system debug memorycard network iLink cdvd sio dvrp startup

include $(PS2SDKSRC)/Defs.make
include $(PS2SDKSRC)/Rules.make
Expand Down
21 changes: 17 additions & 4 deletions iop/Rules.make
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ IOP_WARNFLAGS ?= -Wall -Werror
# for finer-grained control over what goes into each IRX.
IOP_CFLAGS := -D_IOP -fno-builtin -G0 $(IOP_OPTFLAGS) $(IOP_WARNFLAGS) $(IOP_INCS) $(IOP_CFLAGS)
# Linker flags
IOP_LDFLAGS := -nostdlib -s $(IOP_LDFLAGS)
IOP_LDFLAGS := -nostdlib -s -Wl,-q -Wl,-n -Wl,--no-check-sections $(IOP_LDFLAGS)

# Additional C compiler flags for GCC >=v5.3.0
# -msoft-float is to "remind" GCC/Binutils that the soft-float ABI is to be used. This is due to a bug, which
Expand Down Expand Up @@ -63,8 +63,15 @@ endif
# Assembler flags
IOP_ASFLAGS := $(ASFLAGS_TARGET) -EL -G0 $(IOP_ASFLAGS)

# Default link file
ifeq ($(IOP_LINKFILE),)
IOP_LINKFILE := $(PS2SDKSRC)/iop/startup/src/linkfile
endif

IOP_OBJS := $(IOP_OBJS:%=$(IOP_OBJS_DIR)%)

IOP_BIN_ELF := $(IOP_BIN:.irx=.elf)

# Externally defined variables: IOP_BIN, IOP_OBJS, IOP_LIB

# These macros can be used to simplify certain build rules.
Expand All @@ -81,6 +88,9 @@ $(IOP_OBJS_DIR)%.o: $(IOP_SRC_DIR)%.s

.INTERMEDIATE: $(IOP_OBJS_DIR)build-imports.c $(IOP_OBJS_DIR)build-exports.c

$(PS2SDKSRC)/tools/elftypechanger/bin/elftypechanger: $(PS2SDKSRC)/tools/elftypechanger
$(MAKEREC) $<

# Rules to build imports.lst.
$(IOP_OBJS_DIR)build-imports.c: $(IOP_SRC_DIR)imports.lst
$(ECHO) "#include \"irx_imports.h\"" > $@
Expand Down Expand Up @@ -108,8 +118,11 @@ $(IOP_LIB_DIR):

$(IOP_OBJS): | $(IOP_OBJS_DIR)

$(IOP_BIN): $(IOP_OBJS) | $(IOP_BIN_DIR)
$(IOP_C_COMPILE) $(IOP_OPTFLAGS) -o $(IOP_BIN) $(IOP_OBJS) $(IOP_LDFLAGS) $(IOP_LIBS)
$(IOP_BIN_ELF): $(IOP_OBJS) | $(IOP_BIN_DIR)
$(IOP_C_COMPILE) -T$(IOP_LINKFILE) $(IOP_OPTFLAGS) -o $@ $(IOP_OBJS) $(IOP_LDFLAGS) $(IOP_LIBS)

$(IOP_BIN): $(IOP_BIN_ELF) $(PS2SDKSRC)/tools/elftypechanger/bin/elftypechanger
$(PS2SDKSRC)/tools/elftypechanger/bin/elftypechanger $< $@ FF80

$(IOP_LIB): $(IOP_OBJS) | $(IOP_LIB_DIR)
$(IOP_AR) cru $(IOP_LIB) $(IOP_OBJS)
$(IOP_AR) cru $@ $(IOP_OBJS)
4 changes: 3 additions & 1 deletion iop/kernel/include/irx.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ struct irx_id {
#define IRX_ID(name, major, minor) \
struct irx_id _irx_id = { \
name, IRX_VER(major, minor) \
};
}; \
const u16 _irx_version __attribute__((section(".iopmod"))) = IRX_VER(major, minor); \
const char _irx_name[] __attribute__((aligned(1),section(".iopmod"))) = name;

/*
* Module imports
Expand Down
20 changes: 20 additions & 0 deletions iop/startup/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# _____ ___ ____ ___ ____
# ____| | ____| | | |____|
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
#-----------------------------------------------------------------------
# Copyright 2001-2004, ps2dev - http://www.ps2dev.org
# Licenced under Academic Free License version 2.0
# Review ps2sdk README & LICENSE files for further details.

all:

include $(PS2SDKSRC)/Defs.make
include $(PS2SDKSRC)/iop/Rules.make
include $(PS2SDKSRC)/iop/Rules.release

clean:

release:
$(ECHO) Installing $(IOP_SRC_DIR)linkfile into $(PS2SDK)/iop/startup
cp -f $(IOP_SRC_DIR)linkfile $(PS2SDK)/iop/startup

117 changes: 117 additions & 0 deletions iop/startup/src/linkfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
# _____ ___ ____ ___ ____
# ____| | ____| | | |____|
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
#-----------------------------------------------------------------------
# Copyright 2001-2022, ps2dev - http://www.ps2dev.org
# Licenced under Academic Free License version 2.0
# Review ps2sdk README & LICENSE files for further details.
#
# Linkfile script for iop-ld
*/

OUTPUT_FORMAT("elf32-littlemips")
SEARCH_DIR("");
ENTRY(_start)
PHDRS
{
irxhdr 0x70000080 FLAGS (PF_R);
defhdr PT_LOAD;
}
SECTIONS
{
/*
* This is the .iopmod section for the IRX, it contains information that
* the IOP uses when loading the IRX.
* This section is placed in its own segment.
*/
.iopmod (COPY) : ALIGN(4) {
/*
* The linker will replace this first LONG with a pointer to _irx_id
* if the symbol has been defined.
*/
LONG (DEFINED(_irx_id) ? _irx_id : 0xffffffff) ;
LONG (_start) ;
LONG (_gp) ;
LONG (_text_size) ;
LONG (_data_size) ;
LONG (_bss_size) ;
/*
* The linker will put a SHORT here with the version of the IRX
* (or zero if there is no version).
*/
/*
* The linker will put a null terminated string here containing the
* name of the IRX (or an empty string if the name is not known).
*/
INPUT_SECTION_FLAGS (!SHF_ALLOC & !SHF_WRITE & !SHF_EXECINSTR) * ( .iopmod )
} :irxhdr
. = 0x0 ;
_ftext = . ;
.text : {
CREATE_OBJECT_SYMBOLS
* ( .text )
* ( .text.* )
* ( .init )
* ( .fini )
} :defhdr = 0
_etext = . ;
. = . ;
_fdata = . ;
.rodata : {
* ( .rdata )
* ( .rodata )
* ( .rodata1 )
* ( .rodata.* )
} = 0
.data : {
* ( .data )
* ( .data1 )
* ( .data.* )
CONSTRUCTORS
}
. = ALIGN(16) ;
_gp = . + 0x8000 ;
.sdata : {
* ( .lit8 )
* ( .lit4 )
* ( .sdata )
* ( .sdata.* )
}
_edata = . ;
. = ALIGN(4) ;
_fbss = . ;
.sbss : {
* ( .sbss )
* ( .scommon )
}
_bss_start = . ;
.bss : {
* ( .bss )
* ( COMMON )
. = ALIGN(4) ;
}
_end = . ;
_text_size = _etext - _ftext ;
_data_size = _edata - _fdata ;
_bss_size = _end - _fbss ;
/*
* These are the stuff that we don't want to be put in an IRX.
*/
/DISCARD/ : {
* ( .MIPS.abiflags )
* ( .gnu.attributes )
* ( .comment )
* ( .reginfo )
* ( .mdebug.* )
/*
* This must go because it confuses the IOP kernel (treated as a reloc section).
*/
* ( .pdr )
/*
* Until I can figure out if there's a better way to rid ourselves of
* .rel.dyn this will have to do. - MRB
*/
* ( .rel.dyn )
}
}
19 changes: 15 additions & 4 deletions samples/Makefile.iopglobal_sample
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ IOP_WARNFLAGS ?= -Wall
# for finer-grained control over what goes into each IRX.
IOP_CFLAGS := -D_IOP -fno-builtin -G0 $(IOP_OPTFLAGS) $(IOP_WARNFLAGS) $(IOP_INCS) $(IOP_CFLAGS)
# linker flags
IOP_LDFLAGS := -nostdlib -s $(IOP_LDFLAGS)
IOP_LDFLAGS := -nostdlib -s -Wl,-q -Wl,-n -Wl,--no-check-sections $(IOP_LDFLAGS)

# Additional C compiler flags for GCC >=v5.3.0
# -msoft-float is to "remind" GCC/Binutils that the soft-float ABI is to be used. This is due to a bug, which
Expand Down Expand Up @@ -64,8 +64,15 @@ endif
# Assembler flags
IOP_ASFLAGS := $(ASFLAGS_TARGET) -EL -G0 $(IOP_ASFLAGS)

# Default link file
ifeq ($(IOP_LINKFILE),)
IOP_LINKFILE := $(PS2SDK)/iop/startup/linkfile
endif

IOP_OBJS := $(IOP_OBJS:%=$(IOP_OBJS_DIR)%)

IOP_BIN_ELF := $(IOP_BIN:.irx=.elf)

# Externally defined variables: IOP_BIN, IOP_OBJS, IOP_LIB

# These macros can be used to simplify certain build rules.
Expand Down Expand Up @@ -113,10 +120,14 @@ $(IOP_LIB_DIR):

$(IOP_OBJS): | $(IOP_OBJS_DIR)

$(IOP_BIN): $(IOP_OBJS) | $(IOP_BIN_DIR)
$(IOP_BIN_ELF): $(IOP_OBJS) | $(IOP_BIN_DIR)
$(DIR_GUARD)
$(IOP_C_COMPILE) -T$(IOP_LINKFILE) $(IOP_OPTFLAGS) -o $@ $(IOP_OBJS) $(IOP_LDFLAGS) $(IOP_LIBS)

$(IOP_BIN): $(IOP_BIN_ELF)
$(DIR_GUARD)
$(IOP_C_COMPILE) $(IOP_OPTFLAGS) -o $(IOP_BIN) $(IOP_OBJS) $(IOP_LDFLAGS) $(IOP_LIBS)
elftypechanger $< $@ FF80

$(IOP_LIB): $(IOP_OBJS) | $(IOP_LIB_DIR)
$(DIR_GUARD)
$(IOP_AR) cru $(IOP_LIB) $(IOP_OBJS)
$(IOP_AR) cru $@ $(IOP_OBJS)

0 comments on commit 20e47ee

Please sign in to comment.