|
@@ -44,14 +44,13 @@ _start:
|
|
|
popq %rsi /* Pop the argument count. */
|
|
|
movq %rsp, %rdx /* argv starts just at the current stack top. */
|
|
|
|
|
|
- movq operatingsystem_parameter_argc@GOTPCREL(%rip),%rax
|
|
|
- movq %rsi,(%rax)
|
|
|
- movq operatingsystem_parameter_argv@GOTPCREL(%rip),%rax
|
|
|
- movq %rsp,(%rax) /* argv starts just at the current stack top. */
|
|
|
+ movq entryinfo@GOTPCREL(%rip),%r10 /* load address of entryinfo variable */
|
|
|
+
|
|
|
+ movq %rsi,56(%r10)
|
|
|
+ movq %rsp,64(%r10) /* argv starts just at the current stack top */
|
|
|
leaq 8(,%rsi,8),%rax
|
|
|
addq %rsp,%rax
|
|
|
- movq operatingsystem_parameter_envp@GOTPCREL(%rip),%rcx
|
|
|
- movq %rax,(%rcx)
|
|
|
+ movq %rax,72(%r10)
|
|
|
|
|
|
/* Align the stack to a 16 byte boundary to follow the ABI. */
|
|
|
andq $~15, %rsp
|
|
@@ -98,13 +97,38 @@ main_stub:
|
|
|
movq _mcleanup@GOTPCREL(%rip),%rdi
|
|
|
call atexit@PLT
|
|
|
|
|
|
+ /* fill the remaining fields of the entry information */
|
|
|
+ movq entryinfo@GOTPCREL(%rip),%rdi /* load address of entryinfo variable into argument for SysEntry*/
|
|
|
+
|
|
|
/* Save initial stackpointer */
|
|
|
- movq __stkptr@GOTPCREL(%rip),%rax
|
|
|
- movq %rsp,(%rax)
|
|
|
+ movq %rsp,80(%rdi)
|
|
|
+
|
|
|
+ /* store stack length */
|
|
|
+ movq __stklen@GOTPCREL(%rip),%rax
|
|
|
+ movq %rax,88(%rdi)
|
|
|
+
|
|
|
+ /* store pointer to _haltproc */
|
|
|
+ movq _haltproc@GOTPCREL(%rip),%rax
|
|
|
+ movq %rax,96(%rdi)
|
|
|
+
|
|
|
+ /* populate the table pointers */
|
|
|
+ movq INITFINAL@GOTPCREL(%rip),%rax
|
|
|
+ movq %rax,(%rdi)
|
|
|
+ movq FPC_THREADVARTABLES@GOTPCREL(%rip),%rax
|
|
|
+ movq %rax,8(%rdi)
|
|
|
+ movq FPC_RESOURCESTRINGTABLES@GOTPCREL(%rip),%rax
|
|
|
+ movq %rax,16(%rdi)
|
|
|
+ movq FPC_RESSTRINITTABLES@GOTPCREL(%rip),%rax
|
|
|
+ movq %rax,24(%rdi)
|
|
|
+ movq FPC_RESLOCATION@GOTPCREL(%rip),%rax
|
|
|
+ movq %rax,32(%rdi)
|
|
|
+ movq PASCALMAIN@GOTPCREL(%rip),%rax
|
|
|
+ movq %rax,40(%rdi)
|
|
|
+ /* valgrind_used can stay 0 */
|
|
|
|
|
|
/* start the program */
|
|
|
xorq %rbp,%rbp
|
|
|
- call PASCALMAIN@PLT
|
|
|
+ call FPC_SysEntry@PLT
|
|
|
hlt
|
|
|
.size main_stub,.-main_stub
|
|
|
|
|
@@ -155,11 +179,38 @@ ___fpc_ret_rbp:
|
|
|
.quad 0
|
|
|
|
|
|
.bss
|
|
|
- .comm __stkptr,8
|
|
|
+/* the entry information looks like this:
|
|
|
+
|
|
|
+ TEntryInformation = record
|
|
|
+ InitFinalTable : Pointer; // offset 0
|
|
|
+ ThreadvarTablesTable : Pointer; // offset 8
|
|
|
+ ResourceStringTables : Pointer; // offset 16
|
|
|
+ ResStrInitTables : Pointer; // offset 24
|
|
|
+ ResLocation : Pointer; // offset 32
|
|
|
+ PascalMain : Procedure; // offset 40
|
|
|
+ valgrind_used : boolean; // offset 48
|
|
|
+ OS : TEntryInformationOS; // offset 56
|
|
|
+ end;
|
|
|
+
|
|
|
+ with TEntryInformationOS being
|
|
|
|
|
|
- .comm operatingsystem_parameter_envp,8
|
|
|
- .comm operatingsystem_parameter_argc,8
|
|
|
- .comm operatingsystem_parameter_argv,8
|
|
|
+ TEntryInformationOS = record
|
|
|
+ argc: longint; // offset 56
|
|
|
+ argv: ppchar; // offset 64
|
|
|
+ envp: ppchar; // offset 72
|
|
|
+ stkptr: pointer; // offset 80
|
|
|
+ stklen: sizeuint; // offset 88
|
|
|
+ haltproc: procedure(e:longint);cdecl; // offset 96
|
|
|
+ end;
|
|
|
+
|
|
|
+ The size of TEntryInformationOS including padding is 5 * sizeof(Pointer) = 40
|
|
|
+
|
|
|
+ The size of TEntryInformation including padding without OS is 8 * sizeof(Pointer) = 64
|
|
|
+
|
|
|
+ Thus the total size of TEntryInformation including padding is 104
|
|
|
+
|
|
|
+*/
|
|
|
+ .comm entryinfo,104
|
|
|
|
|
|
/* We need this stuff to make gdb behave itself, otherwise
|
|
|
gdb will chokes with SIGILL when trying to debug apps.
|