Added envrion location accounting, identified the need to align the stack before starting Entry

This commit is contained in:
Pavel 2023-01-24 14:01:20 +03:00
parent 11551a1816
commit 6771f25d42
2 changed files with 12 additions and 8 deletions

View File

@ -2925,17 +2925,20 @@ end;
procedure _Entry(P:TEntryPoint;pFileName:Pchar);
var
StartupParams:TPS4StartupParams;
data:array[0..SizeOf(TPS4StartupParams)+38] of Byte;
psp:PPS4StartupParams;
begin
StartupParams:=Default(TPS4StartupParams);
StartupParams.argc:=1;
StartupParams.argv[0]:=pFileName;
psp:=Pointer(Align(@data,32)+8); //AVX align +8
psp^:=Default(TPS4StartupParams);
psp^.argc:=1;
psp^.argv[0]:=pFileName;
//OpenOrbis relies on the fact that besides %rdi and %rsp also link to StartupParams, a very strange thing
asm
xor %rsi,%rsi
lea StartupParams,%rdi
mov %rdi,%rsp
xor %rsi,%rsi //2
mov psp ,%rdi //1
mov %rdi,%rsp //stack
jmp P
end;

View File

@ -437,7 +437,8 @@ type
TPS4StartupParams=packed record
argc:Integer;
align:Integer;
argv:array[0..1] of Pointer;
argv:array[0..2] of Pointer;
//envrion = argv + argc + 1
end;
Const