clearing the bss section on startup

this allows smart linking
This commit is contained in:
Kirill Kranz 2024-11-09 03:32:52 +01:00 committed by FPK
parent c3ad885277
commit dad75d4472
5 changed files with 65 additions and 41 deletions

View File

@ -398,7 +398,8 @@ interface
system_riscv32_linux,system_riscv64_linux,
system_aarch64_win64,
system_z80_zxspectrum,system_z80_msxdos,
system_wasm32_wasi,system_loongarch64_linux
system_wasm32_wasi,system_loongarch64_linux,
system_mipsel_ps1
]+systems_darwin+systems_amigalike;
{ all systems that use the PE+ header in the PE/COFF file

View File

@ -37,7 +37,7 @@ type
public
constructor Create; override;
procedure InitSysInitUnitName; override;
procedure SetDefaultInfo; override;
function MakeExecutable: boolean; override;
@ -57,6 +57,10 @@ begin
Inherited Create;
end;
Procedure TLinkerPS1.InitSysInitUnitName;
begin
sysinitunit:='si_prc';
end;
procedure TLinkerPS1.SetDefaultInfo;
begin
@ -72,14 +76,6 @@ Var
megastr : ansistring;
newname : ansistring;
HPath : TCmdStrListItem;
ObjectFilesTable : TStringList;
procedure delLib(name: string);
begin
if ObjectFilesTable.indexof(name) <> -1 then ObjectFilesTable.delete(ObjectFilesTable.indexof(name));
end;
begin
@ -91,7 +87,7 @@ begin
LinkRes.Add('{');
LinkRes.Add('ram (rwx) : ORIGIN = 0x80010000, LENGTH = 2M - 64K');
LinkRes.Add('}');
LinkRes.Add('ENTRY(main)');
LinkRes.Add('ENTRY(_start)');
HPath:= TCmdStrListItem(LibrarySearchPath.First);
@ -104,34 +100,9 @@ begin
end;
ObjectFilesTable := TStringList.Create;
while not ObjectFiles.Empty do begin
ObjectFilesTable.add(ExtractFileName(ObjectFiles.GetFirst));
LinkRes.Add('INPUT(' + ExtractFileName(ObjectFiles.GetFirst) + ')');
end;
{
delLib('libcard.o');
delLib('libpress.o');
delLib('libgpu.o');
delLib('libgs.o');
delLib('libgte.o');
delLib('libcd.o');
delLib('libetc.o');
delLib('libsn.o');
delLib('libsnd.o ');
delLib('libspu.o');
delLib('libmath.o');
delLib('libcomb.o');
delLib('libtap.o');
delLib('libsio.o');
delLib('libpad.o');
delLib('libc2.o');
delLib('libapi.o');
}
for i:= 0 to ObjectFilesTable.count - 1 do begin
LinkRes.Add('INPUT(' + ObjectFilesTable[i] + ')');
end;
ObjectFilesTable.Free;
LinkRes.Add('INPUT(libcard.a libpress.a libgpu.a libgs.a libgte.a)');
@ -145,7 +116,7 @@ begin
LinkRes.Add(' __exe_start__ = .;');
LinkRes.Add('');
LinkRes.Add(' __text_start__ = .;');
LinkRes.Add(' KEEP(*(.text.n_main));');
LinkRes.Add(' KEEP(*(.text.n_start));');
LinkRes.Add(' *(.text .text.*)');
LinkRes.Add(' __text_end__ = .;');
LinkRes.Add('');

View File

@ -925,7 +925,7 @@ ifdef NO_EXCEPTIONS_IN_SYSTEM
override FPCOPT+=-dNO_EXCEPTIONS_IN_SYSTEM
endif
ifeq ($(CPU_OS_TARGET),mipsel-ps1)
override TARGET_UNITS+=$(SYSTEMUNIT) $(OBJPASUNIT) $(FPINTRESUNIT) $(ISO7185UNIT) $(CTYPESUNIT) $(SYSCONSTUNIT) $(UUCHARUNIT) $(STRINGSUNIT) libstd libetc libgte libgpu libapi libcd libcomb libgs libsnd libspu libds libgun libmcrd libtap libpad libmcx libpress libsn libmcgui libhmd
override TARGET_UNITS+=$(SYSTEMUNIT) $(OBJPASUNIT) $(FPINTRESUNIT) $(ISO7185UNIT) $(CTYPESUNIT) $(SYSCONSTUNIT) $(UUCHARUNIT) $(STRINGSUNIT) libstd libetc libgte libgpu libapi libcd libcomb libgs libsnd libspu libds libgun libmcrd libtap libpad libmcx libpress libsn libmcgui libhmd si_prc
endif
override INSTALL_FPCPACKAGE=y y
ifeq ($(CPU_OS_TARGET),mipsel-ps1)
@ -2970,3 +2970,5 @@ libmcgui$(PPUEXT) : psy-q-sdk/libmcgui.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$
$(COMPILER) $<
libhmd$(PPUEXT) : psy-q-sdk/libhmd.pas libgte$(PPUEXT) libgs$(PPUEXT) $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
$(COMPILER) $<
si_prc$(PPUEXT) : $(SYSTEMUNIT)$(PPUEXT)
$(COMPILER) si_prc.pp

View File

@ -7,7 +7,8 @@ main=rtl
loaders=
units=$(SYSTEMUNIT) $(OBJPASUNIT) $(FPINTRESUNIT) $(ISO7185UNIT) $(CTYPESUNIT) \
$(SYSCONSTUNIT) $(UUCHARUNIT) $(STRINGSUNIT) \
libstd libetc libgte libgpu libapi libcd libcomb libgs libsnd libspu libds libgun libmcrd libtap libpad libmcx libpress libsn libmcgui libhmd
libstd libetc libgte libgpu libapi libcd libcomb libgs libsnd libspu libds libgun libmcrd libtap libpad libmcx libpress libsn libmcgui libhmd \
si_prc
[require]
nortl=y
@ -110,6 +111,10 @@ libmcgui$(PPUEXT) : psy-q-sdk/libmcgui.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$
libhmd$(PPUEXT) : psy-q-sdk/libhmd.pas libgte$(PPUEXT) libgs$(PPUEXT) $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
$(COMPILER) $<
#
# Loaders
#
#
si_prc$(PPUEXT) : $(SYSTEMUNIT)$(PPUEXT)
$(COMPILER) si_prc.pp

45
rtl/ps1/si_prc.pp Normal file
View File

@ -0,0 +1,45 @@
{$SMARTLINK OFF}
{$GOTO ON}
unit si_prc;
interface
implementation
procedure PascalMain; external name 'PASCALMAIN';
var
_bss_start: record end; external name '__bss_start__';
_bss_end: record end; external name '__bss_end__';
function _FPC_proc_start: longint; cdecl; public name '_start';
label _loop, _exit;
begin
// fill the bss section with zeros
asm
la $t0, _bss_end
la $t1, _bss_start
sub $t0, $t0, $t1
_loop:
beq $t0, 0, _exit
nop
la $t1, _bss_start
add $t1,$t1,$t0
sw $0, 0($t1)
addi $t0,$t0,-4
j _loop
nop
_exit:
end;
PascalMain;
end;
begin
end.