Răsfoiți Sursa

* add initialstkptr to get the stackpointer at startup before
PASCALMAIN is called so the main body framepointer is seen as
a valid pointer with backtracing

git-svn-id: trunk@2266 -

peter 19 ani în urmă
părinte
comite
94f2b1d941

+ 5 - 4
rtl/inc/system.inc

@@ -44,15 +44,16 @@ const
 var
 var
   emptychar : char;public name 'FPC_EMPTYCHAR';
   emptychar : char;public name 'FPC_EMPTYCHAR';
   initialstklen : SizeUint;external name '__stklen';
   initialstklen : SizeUint;external name '__stklen';
+  initialstkptr : Pointer;external name '__stkptr';
 
 
 { checks whether the given suggested size for the stack of the current
 { checks whether the given suggested size for the stack of the current
- thread is acceptable. If this is the case, returns it unaltered. 
+ thread is acceptable. If this is the case, returns it unaltered.
  Otherwise it should return an acceptable value.
  Otherwise it should return an acceptable value.
- 
- Operating systems that automatically expand their stack on demand, should 
+
+ Operating systems that automatically expand their stack on demand, should
  simply return a very large value.
  simply return a very large value.
  Operating systems which do not have a possibility to retrieve stack size
  Operating systems which do not have a possibility to retrieve stack size
- information, should simply return the given stklen value (This is the default 
+ information, should simply return the given stklen value (This is the default
  implementation).
  implementation).
 }
 }
 function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt; forward;
 function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt; forward;

+ 6 - 0
rtl/linux/arm/cprt0.as

@@ -62,6 +62,10 @@ _start:
 	str sp,[a3]
 	str sp,[a3]
     	str a4,[ip]
     	str a4,[ip]
 
 
+    /* Save initial stackpointer */
+	ldr ip,=__stkptr
+	str sp,[ip]
+
         /* Fetch address of fini */
         /* Fetch address of fini */
         ldr ip, =_fini
         ldr ip, =_fini
 
 
@@ -108,6 +112,8 @@ __data_start:
 	data_start = __data_start
 	data_start = __data_start
 
 
 .bss
 .bss
+        .comm __stkptr,4
+
         .comm operatingsystem_parameter_envp,4
         .comm operatingsystem_parameter_envp,4
         .comm operatingsystem_parameter_argc,4
         .comm operatingsystem_parameter_argc,4
         .comm operatingsystem_parameter_argv,4
         .comm operatingsystem_parameter_argv,4

+ 6 - 0
rtl/linux/arm/prt0.as

@@ -62,6 +62,10 @@ _start:
 	str sp,[a3]
 	str sp,[a3]
    	str a2,[ip]
    	str a2,[ip]
 
 
+    /* Save initial stackpointer */
+	ldr ip,=__stkptr
+	str sp,[ip]
+
 	/* Let the libc call main and exit with its return code.  */
 	/* Let the libc call main and exit with its return code.  */
 	bl PASCALMAIN
 	bl PASCALMAIN
 
 
@@ -82,6 +86,8 @@ __data_start:
 	data_start = __data_start
 	data_start = __data_start
 
 
 .bss
 .bss
+        .comm __stkptr,4
+
         .comm operatingsystem_parameter_envp,4
         .comm operatingsystem_parameter_envp,4
         .comm operatingsystem_parameter_argc,4
         .comm operatingsystem_parameter_argc,4
         .comm operatingsystem_parameter_argv,4
         .comm operatingsystem_parameter_argv,4

+ 21 - 8
rtl/linux/i386/cprt0.as

@@ -66,6 +66,9 @@ _start:
         popl    %eax
         popl    %eax
         popl    %eax
         popl    %eax
 
 
+        /* Save initial stackpointer */
+        movl    %esp,__stkptr
+
         xorl    %ebp,%ebp
         xorl    %ebp,%ebp
         call    PASCALMAIN              /* start the program */
         call    PASCALMAIN              /* start the program */
 
 
@@ -74,20 +77,30 @@ _start:
 _haltproc:
 _haltproc:
 _haltproc2:             # GAS <= 2.15 bug: generates larger jump if a label is exported
 _haltproc2:             # GAS <= 2.15 bug: generates larger jump if a label is exported
         movzwl  operatingsystem_result,%ebx
         movzwl  operatingsystem_result,%ebx
-	pushl   %ebx
-	call    exit
+        pushl   %ebx
+        call    exit
         xorl    %eax,%eax
         xorl    %eax,%eax
         incl    %eax                    /* eax=1, exit call */
         incl    %eax                    /* eax=1, exit call */
-	popl    %ebx
+        popl    %ebx
         int     $0x80
         int     $0x80
         jmp     _haltproc2
         jmp     _haltproc2
 
 
 .data
 .data
 
 
 .bss
 .bss
-        .type   ___fpc_brk_addr,@object
-        .comm   ___fpc_brk_addr,4        /* heap management */
+        .type   __stkptr,@object
+        .size   __stkptr,4
+__stkptr:
+        .skip   4
+
+        .type operatingsystem_parameters,@object
+        .size operatingsystem_parameters,12
+operatingsystem_parameters:
+        .skip 3*4
 
 
-        .comm operatingsystem_parameter_envp,4
-        .comm operatingsystem_parameter_argc,4
-        .comm operatingsystem_parameter_argv,4
+        .global operatingsystem_parameter_envp
+        .global operatingsystem_parameter_argc
+        .global operatingsystem_parameter_argv
+        .set operatingsystem_parameter_envp,operatingsystem_parameters+0
+        .set operatingsystem_parameter_argc,operatingsystem_parameters+4
+        .set operatingsystem_parameter_argv,operatingsystem_parameters+8

+ 18 - 5
rtl/linux/i386/cprt21.as

@@ -73,6 +73,9 @@ main:
         movl    %ebp,___fpc_ret_ebp
         movl    %ebp,___fpc_ret_ebp
         pushl   %eax
         pushl   %eax
 
 
+        /* Save initial stackpointer */
+        movl    %esp,__stkptr
+
         /* start the program */
         /* start the program */
         xorl    %ebp,%ebp
         xorl    %ebp,%ebp
         call    PASCALMAIN
         call    PASCALMAIN
@@ -102,9 +105,19 @@ ___fpc_ret_ebp:
         .long   0
         .long   0
 
 
 .bss
 .bss
-        .type   ___fpc_brk_addr,@object
-        .comm   ___fpc_brk_addr,4        /* heap management */
+        .type   __stkptr,@object
+        .size   __stkptr,4
+__stkptr:
+        .skip   4
+
+        .type operatingsystem_parameters,@object
+        .size operatingsystem_parameters,12
+operatingsystem_parameters:
+        .skip 3*4
 
 
-        .comm operatingsystem_parameter_envp,4
-        .comm operatingsystem_parameter_argc,4
-        .comm operatingsystem_parameter_argv,4
+        .global operatingsystem_parameter_envp
+        .global operatingsystem_parameter_argc
+        .global operatingsystem_parameter_argv
+        .set operatingsystem_parameter_envp,operatingsystem_parameters+0
+        .set operatingsystem_parameter_argc,operatingsystem_parameters+4
+        .set operatingsystem_parameter_argv,operatingsystem_parameters+8

+ 20 - 3
rtl/linux/i386/dllprt0.as

@@ -35,6 +35,9 @@ FPC_LIB_START:
 
 
         movb    $1,U_SYSTEM_ISLIBRARY
         movb    $1,U_SYSTEM_ISLIBRARY
 
 
+        /* Save initial stackpointer */
+        movl    %esp,__stkptr
+
         call    PASCALMAIN
         call    PASCALMAIN
 
 
         leave
         leave
@@ -51,6 +54,20 @@ _haltproc2:             # GAS <= 2.15 bug: generates larger jump if a label is e
         jmp     _haltproc2
         jmp     _haltproc2
 
 
 .bss
 .bss
-        .comm operatingsystem_parameter_envp,4
-        .comm operatingsystem_parameter_argc,4
-        .comm operatingsystem_parameter_argv,4
+        .type   __stkptr,@object
+        .size   __stkptr,4
+__stkptr:
+        .skip   4
+
+        .type operatingsystem_parameters,@object
+        .size operatingsystem_parameters,12
+operatingsystem_parameters:
+        .skip 3*4
+
+        .global operatingsystem_parameter_envp
+        .global operatingsystem_parameter_argc
+        .global operatingsystem_parameter_argv
+        .set operatingsystem_parameter_envp,operatingsystem_parameters+0
+        .set operatingsystem_parameter_argc,operatingsystem_parameters+4
+        .set operatingsystem_parameter_argv,operatingsystem_parameters+8
+

+ 18 - 5
rtl/linux/i386/gprt0.as

@@ -46,6 +46,9 @@ _start:
         call    atexit
         call    atexit
         addl    $4,%esp
         addl    $4,%esp
 
 
+        /* Save initial stackpointer */
+        movl    %esp,__stkptr
+
         xorl    %ebp,%ebp
         xorl    %ebp,%ebp
         call    PASCALMAIN
         call    PASCALMAIN
 
 
@@ -67,9 +70,19 @@ ___fpucw:
         .long   0x1332
         .long   0x1332
 
 
 .bss
 .bss
-        .type   ___fpc_brk_addr,@object
-        .comm   ___fpc_brk_addr,4        /* heap management */
+        .type   __stkptr,@object
+        .size   __stkptr,4
+__stkptr:
+        .skip   4
+
+        .type operatingsystem_parameters,@object
+        .size operatingsystem_parameters,12
+operatingsystem_parameters:
+        .skip 3*4
 
 
-        .comm operatingsystem_parameter_envp,4
-        .comm operatingsystem_parameter_argc,4
-        .comm operatingsystem_parameter_argv,4
+        .global operatingsystem_parameter_envp
+        .global operatingsystem_parameter_argc
+        .global operatingsystem_parameter_argv
+        .set operatingsystem_parameter_envp,operatingsystem_parameters+0
+        .set operatingsystem_parameter_argc,operatingsystem_parameters+4
+        .set operatingsystem_parameter_argv,operatingsystem_parameters+8

+ 20 - 6
rtl/linux/i386/gprt21.as

@@ -58,7 +58,10 @@ cmain:
         movl    %edi,___fpc_ret_edi
         movl    %edi,___fpc_ret_edi
         pushl   %eax
         pushl   %eax
 
 
-	call    __gmon_start__
+        call    __gmon_start__
+
+        /* Save initial stackpointer */
+        movl    %esp,__stkptr
 
 
         /* start the program */
         /* start the program */
         call    PASCALMAIN
         call    PASCALMAIN
@@ -115,9 +118,20 @@ ___fpc_ret_edi:
 .bss
 .bss
         .lcomm __monstarted,4
         .lcomm __monstarted,4
 
 
-        .type   ___fpc_brk_addr,@object
-        .comm   ___fpc_brk_addr,4        /* heap management */
+        .type   __stkptr,@object
+        .size   __stkptr,4
+__stkptr:
+        .skip   4
+
+        .type operatingsystem_parameters,@object
+        .size operatingsystem_parameters,12
+operatingsystem_parameters:
+        .skip 3*4
+
+        .global operatingsystem_parameter_envp
+        .global operatingsystem_parameter_argc
+        .global operatingsystem_parameter_argv
+        .set operatingsystem_parameter_envp,operatingsystem_parameters+0
+        .set operatingsystem_parameter_argc,operatingsystem_parameters+4
+        .set operatingsystem_parameter_argv,operatingsystem_parameters+8
 
 
-        .comm operatingsystem_parameter_envp,4
-        .comm operatingsystem_parameter_argc,4
-        .comm operatingsystem_parameter_argv,4

+ 9 - 4
rtl/linux/i386/prt0.as

@@ -63,6 +63,9 @@ _start:
 #        movw    %ds,%ax
 #        movw    %ds,%ax
 #        movw    %ax,%gs
 #        movw    %ax,%gs
 
 
+        /* Save initial stackpointer */
+        movl    %esp,__stkptr
+
         xorl    %ebp,%ebp
         xorl    %ebp,%ebp
         call    PASCALMAIN
         call    PASCALMAIN
 
 
@@ -70,7 +73,7 @@ _start:
         .type   _haltproc,@function
         .type   _haltproc,@function
 _haltproc:
 _haltproc:
 _haltproc2:             # GAS <= 2.15 bug: generates larger jump if a label is exported
 _haltproc2:             # GAS <= 2.15 bug: generates larger jump if a label is exported
-	movl    $252,%eax                /* exit_group */
+        movl    $252,%eax                /* exit_group */
         movzwl  operatingsystem_result,%ebx
         movzwl  operatingsystem_result,%ebx
         int     $0x80
         int     $0x80
         movl    $1,%eax                /* exit */
         movl    $1,%eax                /* exit */
@@ -84,9 +87,11 @@ ___fpucw:
 
 
 
 
 .bss
 .bss
-        .type   ___fpc_brk_addr,@object
-        .comm   ___fpc_brk_addr,4        /* heap management */
-
+        .type   __stkptr,@object
+        .size   __stkptr,4
+        .global __stkptr
+__stkptr:
+        .skip   4
 
 
         .type operatingsystem_parameters,@object
         .type operatingsystem_parameters,@object
         .size operatingsystem_parameters,12
         .size operatingsystem_parameters,12

+ 6 - 3
rtl/linux/powerpc/cprt0.as

@@ -3,7 +3,7 @@
  * version.
  * version.
  *
  *
  * Adapted from the glibc-sources (2.3.5) in the file
  * Adapted from the glibc-sources (2.3.5) in the file
- * 
+ *
  *     sysdeps/powerpc/powerpc32/elf/start.S
  *     sysdeps/powerpc/powerpc32/elf/start.S
  *
  *
  * Original header follows.
  * Original header follows.
@@ -26,7 +26,7 @@
    You should have received a copy of the GNU Lesser General Public
    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, write to the Free
    License along with the GNU C Library; if not, write to the Free
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  
+   02111-1307 USA.
 */
 */
 
 
 /* These are the various addresses we require.  */
 /* These are the various addresses we require.  */
@@ -60,7 +60,7 @@ _start:
     .globl  main_stub
     .globl  main_stub
     .type   main_stub, @function
     .type   main_stub, @function
 main_stub:
 main_stub:
- /* save link register and setup stack frame */ 
+ /* save link register and setup stack frame */
     mflr    0
     mflr    0
     stw     0, 0(1)
     stw     0, 0(1)
     stwu    1, -16(1)
     stwu    1, -16(1)
@@ -74,6 +74,9 @@ main_stub:
     lis     11, operatingsystem_parameter_envp@ha
     lis     11, operatingsystem_parameter_envp@ha
     stw      5, operatingsystem_parameter_envp@l(11);
     stw      5, operatingsystem_parameter_envp@l(11);
 
 
+    lis 	11,__stkptr@ha
+	stw 	1,__stkptr@l(11);
+
     lis     11, ___fpc_ret@ha
     lis     11, ___fpc_ret@ha
     stw     1, ___fpc_ret@l(11)
     stw     1, ___fpc_ret@l(11)
 
 

+ 0 - 15
rtl/linux/powerpc/dllprt0.as

@@ -1,15 +0,0 @@
-/*
-  $Id: dllprt0.as,v 1.3 2002/09/07 16:01:20 peter Exp $
-*/
-
-/* 
-
-  Revision 1.3  2002/09/07 16:01:20  peter
-    * old logs removed and tabs fixed
-
-  Revision 1.2  2002/07/26 17:09:44  florian
-    * log fixed
-
-  Revision 1.1  2002/07/26 17:07:11  florian
-    + dummy implementation to test the makefile
-*/

+ 0 - 15
rtl/linux/powerpc/gprt0.as

@@ -1,15 +0,0 @@
-/*
-  $Id: gprt0.as,v 1.3 2002/09/07 16:01:20 peter Exp $
-*/
-
-/*
-
-  Revision 1.3  2002/09/07 16:01:20  peter
-    * old logs removed and tabs fixed
-
-  Revision 1.2  2002/07/26 17:09:44  florian
-    * log fixed
-
-  Revision 1.1  2002/07/26 17:07:11  florian
-    + dummy implementation to test the makefile
-*/

+ 6 - 54
rtl/linux/powerpc/prt0.as

@@ -1,6 +1,3 @@
-/*
-  $Id: prt0.as,v 1.14 2004/08/18 14:26:50 karoly Exp $
-*/
 /* Startup code for programs linked with GNU libc.
 /* Startup code for programs linked with GNU libc.
    Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
    Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    This file is part of the GNU C Library.
@@ -44,8 +41,11 @@ _start:
 	lis 	11,operatingsystem_parameter_envp@ha
 	lis 	11,operatingsystem_parameter_envp@ha
 	stw 	5,operatingsystem_parameter_envp@l(11);
 	stw 	5,operatingsystem_parameter_envp@l(11);
 
 
+    lis 	11,__stkptr@ha
+	stw 	1,__stkptr@l(11);
+
 	bl	PASCALMAIN
 	bl	PASCALMAIN
-	
+
 	b	_haltproc
 	b	_haltproc
 
 
         .globl  _haltproc
         .globl  _haltproc
@@ -60,58 +60,10 @@ _haltproc:
 	.globl	__data_start
 	.globl	__data_start
 __data_start:
 __data_start:
 data_start:
 data_start:
-        .globl  ___fpc_brk_addr         /* heap management */
-        .type   ___fpc_brk_addr,@object
-        .size   ___fpc_brk_addr,4
-___fpc_brk_addr:
-        .long   0
 
 
 .text
 .text
+        .comm __stkptr,4
+
         .comm operatingsystem_parameter_envp,4
         .comm operatingsystem_parameter_envp,4
         .comm operatingsystem_parameter_argc,4
         .comm operatingsystem_parameter_argc,4
         .comm operatingsystem_parameter_argv,4
         .comm operatingsystem_parameter_argv,4
-/*
-
-  Revision 1.14  2004/08/18 14:26:50  karoly
-    * quick fix to make it compile
-
-  Revision 1.13  2004/07/03 21:50:31  daniel
-    * Modified bootstrap code so separate prt0.as/prt0_10.as files are no
-      longer necessary
-
-  Revision 1.12  2004/05/26 20:48:17  florian
-    * _haltproc fixed
-
-  Revision 1.11  2004/01/04 17:23:57  florian
-    + header added
-
-  Revision 1.10  2003/05/12 22:36:45  florian
-    + added setup of argv, argc and envp
-
-  Revision 1.9  2002/09/07 16:01:20  peter
-    * old logs removed and tabs fixed
-
-  Revision 1.8  2002/08/31 21:29:57  florian
-    * several PC related fixes
-
-  Revision 1.7  2002/08/31 16:13:12  florian
-    * made _start global
-
-  Revision 1.6  2002/08/31 14:02:23  florian
-    * r3 renamed to 3
-
-  Revision 1.5  2002/08/31 14:01:28  florian
-    * _haltproc to prt0.as added (Linux/PPC)
-
-  Revision 1.4  2002/08/31 13:11:11  florian
-    * several fixes for Linux/PPC compilation
-
-  Revision 1.3  2002/08/19 21:19:15  florian
-    * small fixes
-
-  Revision 1.2  2002/07/26 17:09:44  florian
-    * log fixed
-
-  Revision 1.1  2002/07/26 16:57:40  florian
-    + initial version, plain copy from glibc/sysdeps/powerpc/elf/start.S
-*/

+ 28 - 23
rtl/linux/powerpc64/cprt0.as

@@ -3,7 +3,7 @@
  * version.
  * version.
  *
  *
  * Adapted from the glibc-sources (2.3.5) in the file
  * Adapted from the glibc-sources (2.3.5) in the file
- * 
+ *
  *     sysdeps/powerpc/powerpc64/elf/start.S
  *     sysdeps/powerpc/powerpc64/elf/start.S
  *
  *
  * Original header follows.
  * Original header follows.
@@ -31,12 +31,12 @@
 /* some macros which simplify the startup code */
 /* some macros which simplify the startup code */
 
 
 /* load the 64 bit value "value" into register ra */
 /* load the 64 bit value "value" into register ra */
-.macro LOAD_64BIT_VAL ra, value 
+.macro LOAD_64BIT_VAL ra, value
     lis       \ra,\value@highest
     lis       \ra,\value@highest
     ori       \ra,\ra,\value@higher
     ori       \ra,\ra,\value@higher
     sldi      \ra,\ra,32
     sldi      \ra,\ra,32
     oris      \ra,\ra,\value@h
     oris      \ra,\ra,\value@h
-    ori       \ra,\ra,\value@l    
+    ori       \ra,\ra,\value@l
 .endm
 .endm
 
 
 /* create function prolog for symbol "fn" */
 /* create function prolog for symbol "fn" */
@@ -50,20 +50,20 @@
     .quad     .\fn, .TOC.@tocbase, 0
     .quad     .\fn, .TOC.@tocbase, 0
     .previous
     .previous
     .size     \fn, 24
     .size     \fn, 24
-    .type     \fn, @function	
+    .type     \fn, @function
     .globl    .\fn
     .globl    .\fn
 .\fn:
 .\fn:
 .endm
 .endm
 
 
-/* 
- * "ptrgl" glue code for calls via pointer. This function 
- * sequence loads the data from the function descriptor 
+/*
+ * "ptrgl" glue code for calls via pointer. This function
+ * sequence loads the data from the function descriptor
  * referenced by R11 into the CTR register (function address),
  * referenced by R11 into the CTR register (function address),
  * R2 (GOT/TOC pointer), and R11 (the outer frame pointer).
  * R2 (GOT/TOC pointer), and R11 (the outer frame pointer).
- * 
+ *
  * On entry, R11 must be set to point to the function descriptor.
  * On entry, R11 must be set to point to the function descriptor.
  *
  *
- * See also the 64-bit PowerPC ABI specification for more 
+ * See also the 64-bit PowerPC ABI specification for more
  * information, chapter 3.5.11 (in v1.7).
  * information, chapter 3.5.11 (in v1.7).
  */
  */
 .section ".text"
 .section ".text"
@@ -81,18 +81,18 @@
 .type .ptrgl, @function
 .type .ptrgl, @function
 .size .ptrgl, . - .ptrgl
 .size .ptrgl, . - .ptrgl
 
 
-/* 
- * Function prolog/epilog helpers, which are part of the 64-bit 
+/*
+ * Function prolog/epilog helpers, which are part of the 64-bit
  * PowerPC ABI.
  * PowerPC ABI.
  *
  *
- * See also the 64-bit PowerPC ABI specification for more 
+ * See also the 64-bit PowerPC ABI specification for more
  * information, chapter 3.5.5, "Register saving and restoring
  * information, chapter 3.5.5, "Register saving and restoring
  * function" (in v1.7).
  * function" (in v1.7).
  */
  */
 
 
 /* Each _savegpr0_N routine saves the general registers from rN to r31,
 /* Each _savegpr0_N routine saves the general registers from rN to r31,
- * inclusive. When the routine is called, r1 must point to the start 
- * of the general register save area. R0 must contain the old LR on 
+ * inclusive. When the routine is called, r1 must point to the start
+ * of the general register save area. R0 must contain the old LR on
  * entry.
  * entry.
  */
  */
 _savegpr0_14: std 14,-144(1)
 _savegpr0_14: std 14,-144(1)
@@ -112,7 +112,7 @@ _savegpr0_27: std 27,-40(1)
 _savegpr0_28: std 28,-32(1)
 _savegpr0_28: std 28,-32(1)
 _savegpr0_29: std 29,-24(1)
 _savegpr0_29: std 29,-24(1)
 _savegpr0_30: std 30,-16(1)
 _savegpr0_30: std 30,-16(1)
-_savegpr0_31: 
+_savegpr0_31:
     std 31,-8(1)
     std 31,-8(1)
     std 0, 16(1)
     std 0, 16(1)
     blr
     blr
@@ -120,7 +120,7 @@ _savegpr0_31:
 .byte 0, 12, 64, 0, 0, 0, 0, 0
 .byte 0, 12, 64, 0, 0, 0, 0, 0
 
 
 /* Each _restgpr0_N routine restores the general registers from rN to r31,
 /* Each _restgpr0_N routine restores the general registers from rN to r31,
- * inclusive. When the routine is called, r1 must point to the start 
+ * inclusive. When the routine is called, r1 must point to the start
  * of the general register save area.
  * of the general register save area.
  */
  */
 _restgpr0_14: ld 14,-144(1)
 _restgpr0_14: ld 14,-144(1)
@@ -138,7 +138,7 @@ _restgpr0_25: ld 25,-56(1)
 _restgpr0_26: ld 26,-48(1)
 _restgpr0_26: ld 26,-48(1)
 _restgpr0_27: ld 27,-40(1)
 _restgpr0_27: ld 27,-40(1)
 _restgpr0_28: ld 28,-32(1)
 _restgpr0_28: ld 28,-32(1)
-_restgpr0_29: 
+_restgpr0_29:
     ld 0, 16(1)
     ld 0, 16(1)
     ld 29,-24(1)
     ld 29,-24(1)
     mtlr 0
     mtlr 0
@@ -254,7 +254,7 @@ _restfpr_25: lfd 25,-56(1)
 _restfpr_26: lfd 26,-48(1)
 _restfpr_26: lfd 26,-48(1)
 _restfpr_27: lfd 27,-40(1)
 _restfpr_27: lfd 27,-40(1)
 _restfpr_28: lfd 28,-32(1)
 _restfpr_28: lfd 28,-32(1)
-_restfpr_29: 
+_restfpr_29:
     ld 0, 16(1)
     ld 0, 16(1)
     lfd 29,-24(1)
     lfd 29,-24(1)
     mtlr 0
     mtlr 0
@@ -265,7 +265,7 @@ _restfpr_29:
 .byte 0, 12, 64, 0, 0, 0, 0, 0
 .byte 0, 12, 64, 0, 0, 0, 0, 0
 
 
 _restfpr_30: lfd 30,-16(1)
 _restfpr_30: lfd 30,-16(1)
-_restfpr_31: 
+_restfpr_31:
     ld 0, 16(1)
     ld 0, 16(1)
     lfd 31,-8(1)
     lfd 31,-8(1)
     mtlr 0
     mtlr 0
@@ -338,8 +338,8 @@ _restvr_31: addi r12,r0,-16
     blr
     blr
 */
 */
 
 
-/* 
- * start_addresses is a structure containing the real 
+/*
+ * start_addresses is a structure containing the real
  * entry point (next to other things not interesting to
  * entry point (next to other things not interesting to
  * us here).
  * us here).
  *
  *
@@ -372,9 +372,9 @@ FUNCTION_PROLOG _start
     /* put the address of start_addresses in r8...  */
     /* put the address of start_addresses in r8...  */
     /* PPC64 ABI uses R13 for thread local, so we leave it alone */
     /* PPC64 ABI uses R13 for thread local, so we leave it alone */
     LOAD_64BIT_VAL 8, start_addresses
     LOAD_64BIT_VAL 8, start_addresses
-    
+
     b   .__libc_start_main
     b   .__libc_start_main
-    nop                      /* a NOP for the linker */ 
+    nop                      /* a NOP for the linker */
 
 
 /*
 /*
  * This is our FreePascal main procedure which is called by
  * This is our FreePascal main procedure which is called by
@@ -395,6 +395,9 @@ FUNCTION_PROLOG main_stub
     LOAD_64BIT_VAL 8, operatingsystem_parameter_envp
     LOAD_64BIT_VAL 8, operatingsystem_parameter_envp
     std     5,0(8)
     std     5,0(8)
 
 
+    LOAD_64BIT_VAL 8, __stkptr
+    std     1,0(8)
+
     LOAD_64BIT_VAL 8, ___fpc_ret
     LOAD_64BIT_VAL 8, ___fpc_ret
     std     1,0(8)
     std     1,0(8)
 
 
@@ -425,6 +428,8 @@ ___fpc_ret:                            /* return address to libc */
     .quad   0
     .quad   0
 
 
 .text
 .text
+    .comm __stkptr, 8
+
     .comm operatingsystem_parameter_argc, 4
     .comm operatingsystem_parameter_argc, 4
     .comm operatingsystem_parameter_argv, 8
     .comm operatingsystem_parameter_argv, 8
     .comm operatingsystem_parameter_envp, 8
     .comm operatingsystem_parameter_envp, 8

+ 28 - 23
rtl/linux/powerpc64/prt0.as

@@ -12,13 +12,13 @@
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  */
  */
-   
-.macro LOAD_64BIT_VAL ra, value 
+
+.macro LOAD_64BIT_VAL ra, value
     lis       \ra,\value@highest
     lis       \ra,\value@highest
     ori       \ra,\ra,\value@higher
     ori       \ra,\ra,\value@higher
     sldi      \ra,\ra,32
     sldi      \ra,\ra,32
     oris      \ra,\ra,\value@h
     oris      \ra,\ra,\value@h
-    ori       \ra,\ra,\value@l    
+    ori       \ra,\ra,\value@l
 .endm
 .endm
 
 
 /* create function prolog for symbol "fn" */
 /* create function prolog for symbol "fn" */
@@ -32,20 +32,20 @@
     .quad     .\fn, .TOC.@tocbase, 0
     .quad     .\fn, .TOC.@tocbase, 0
     .previous
     .previous
     .size     \fn, 24
     .size     \fn, 24
-    .type     \fn, @function	
+    .type     \fn, @function
     .globl    .\fn
     .globl    .\fn
 .\fn:
 .\fn:
 .endm
 .endm
 
 
-/* 
- * "ptrgl" glue code for calls via pointer. This function 
- * sequence loads the data from the function descriptor 
+/*
+ * "ptrgl" glue code for calls via pointer. This function
+ * sequence loads the data from the function descriptor
  * referenced by R11 into the CTR register (function address),
  * referenced by R11 into the CTR register (function address),
  * R2 (GOT/TOC pointer), and R11 (the outer frame pointer).
  * R2 (GOT/TOC pointer), and R11 (the outer frame pointer).
- * 
+ *
  * On entry, R11 must be set to point to the function descriptor.
  * On entry, R11 must be set to point to the function descriptor.
  *
  *
- * See also the 64-bit PowerPC ABI specification for more 
+ * See also the 64-bit PowerPC ABI specification for more
  * information, chapter 3.5.11 (in v1.7).
  * information, chapter 3.5.11 (in v1.7).
  */
  */
 .section ".text"
 .section ".text"
@@ -63,18 +63,18 @@
 .type .ptrgl, @function
 .type .ptrgl, @function
 .size .ptrgl, . - .ptrgl
 .size .ptrgl, . - .ptrgl
 
 
-/* 
- * Function prolog/epilog helpers, which are part of the 64-bit 
+/*
+ * Function prolog/epilog helpers, which are part of the 64-bit
  * PowerPC ABI.
  * PowerPC ABI.
  *
  *
- * See also the 64-bit PowerPC ABI specification for more 
+ * See also the 64-bit PowerPC ABI specification for more
  * information, chapter 3.5.5, "Register saving and restoring
  * information, chapter 3.5.5, "Register saving and restoring
  * function" (in v1.7).
  * function" (in v1.7).
  */
  */
 
 
 /* Each _savegpr0_N routine saves the general registers from rN to r31,
 /* Each _savegpr0_N routine saves the general registers from rN to r31,
- * inclusive. When the routine is called, r1 must point to the start 
- * of the general register save area. R0 must contain the old LR on 
+ * inclusive. When the routine is called, r1 must point to the start
+ * of the general register save area. R0 must contain the old LR on
  * entry.
  * entry.
  */
  */
 _savegpr0_14: std 14,-144(1)
 _savegpr0_14: std 14,-144(1)
@@ -94,7 +94,7 @@ _savegpr0_27: std 27,-40(1)
 _savegpr0_28: std 28,-32(1)
 _savegpr0_28: std 28,-32(1)
 _savegpr0_29: std 29,-24(1)
 _savegpr0_29: std 29,-24(1)
 _savegpr0_30: std 30,-16(1)
 _savegpr0_30: std 30,-16(1)
-_savegpr0_31: 
+_savegpr0_31:
     std 31,-8(1)
     std 31,-8(1)
     std 0, 16(1)
     std 0, 16(1)
     blr
     blr
@@ -102,7 +102,7 @@ _savegpr0_31:
 .byte 0, 12, 64, 0, 0, 0, 0, 0
 .byte 0, 12, 64, 0, 0, 0, 0, 0
 
 
 /* Each _restgpr0_N routine restores the general registers from rN to r31,
 /* Each _restgpr0_N routine restores the general registers from rN to r31,
- * inclusive. When the routine is called, r1 must point to the start 
+ * inclusive. When the routine is called, r1 must point to the start
  * of the general register save area.
  * of the general register save area.
  */
  */
 _restgpr0_14: ld 14,-144(1)
 _restgpr0_14: ld 14,-144(1)
@@ -120,7 +120,7 @@ _restgpr0_25: ld 25,-56(1)
 _restgpr0_26: ld 26,-48(1)
 _restgpr0_26: ld 26,-48(1)
 _restgpr0_27: ld 27,-40(1)
 _restgpr0_27: ld 27,-40(1)
 _restgpr0_28: ld 28,-32(1)
 _restgpr0_28: ld 28,-32(1)
-_restgpr0_29: 
+_restgpr0_29:
     ld 0, 16(1)
     ld 0, 16(1)
     ld 29,-24(1)
     ld 29,-24(1)
     mtlr 0
     mtlr 0
@@ -236,7 +236,7 @@ _restfpr_25: lfd 25,-56(1)
 _restfpr_26: lfd 26,-48(1)
 _restfpr_26: lfd 26,-48(1)
 _restfpr_27: lfd 27,-40(1)
 _restfpr_27: lfd 27,-40(1)
 _restfpr_28: lfd 28,-32(1)
 _restfpr_28: lfd 28,-32(1)
-_restfpr_29: 
+_restfpr_29:
     ld 0, 16(1)
     ld 0, 16(1)
     lfd 29,-24(1)
     lfd 29,-24(1)
     mtlr 0
     mtlr 0
@@ -247,7 +247,7 @@ _restfpr_29:
 .byte 0, 12, 64, 0, 0, 0, 0, 0
 .byte 0, 12, 64, 0, 0, 0, 0, 0
 
 
 _restfpr_30: lfd 30,-16(1)
 _restfpr_30: lfd 30,-16(1)
-_restfpr_31: 
+_restfpr_31:
     ld 0, 16(1)
     ld 0, 16(1)
     lfd 31,-8(1)
     lfd 31,-8(1)
     mtlr 0
     mtlr 0
@@ -328,9 +328,9 @@ FUNCTION_PROLOG _start
     mr   26, 1            /* save stack pointer */
     mr   26, 1            /* save stack pointer */
     /* Set up an initial stack frame, and clear the LR */
     /* Set up an initial stack frame, and clear the LR */
     clrrdi  1, 1, 5       /* align r1 */
     clrrdi  1, 1, 5       /* align r1 */
-    li      0, 0          
-    stdu    1,-128(1)      
-    mtlr    0             
+    li      0, 0
+    stdu    1,-128(1)
+    mtlr    0
     std     0, 0(1)       /* r1 = pointer to NULL value */
     std     0, 0(1)       /* r1 = pointer to NULL value */
 
 
     /* store argument count (= 0(r1) )*/
     /* store argument count (= 0(r1) )*/
@@ -348,12 +348,15 @@ FUNCTION_PROLOG _start
     LOAD_64BIT_VAL 10, operatingsystem_parameter_envp
     LOAD_64BIT_VAL 10, operatingsystem_parameter_envp
     std     5, 0(10)
     std     5, 0(10)
 
 
+    LOAD_64BIT_VAL 8, __stkptr
+    std     1,0(8)
+
     bl      .PASCALMAIN
     bl      .PASCALMAIN
     nop
     nop
 
 
     /* directly jump to exit procedure, not via the function pointer */
     /* directly jump to exit procedure, not via the function pointer */
     b       ._haltproc
     b       ._haltproc
-	
+
 FUNCTION_PROLOG _haltproc
 FUNCTION_PROLOG _haltproc
     /* exit call */
     /* exit call */
     li      0, 1
     li      0, 1
@@ -367,6 +370,8 @@ __data_start:
 data_start:
 data_start:
 
 
 .text
 .text
+    .comm __stkptr, 8
+
     .comm operatingsystem_parameter_argc, 4
     .comm operatingsystem_parameter_argc, 4
     .comm operatingsystem_parameter_argv, 8
     .comm operatingsystem_parameter_argv, 8
     .comm operatingsystem_parameter_envp, 8
     .comm operatingsystem_parameter_envp, 8

+ 6 - 1
rtl/linux/sparc/cprt0.as

@@ -29,6 +29,11 @@ _start:
        	or	%o1,%lo(operatingsystem_parameter_envp),%o1
        	or	%o1,%lo(operatingsystem_parameter_envp),%o1
        	st	%o2, [%o1]
        	st	%o2, [%o1]
 
 
+    /* Save initial stackpointer */
+	sethi	%hi(__stkptr),%o1
+	or	%o1,%lo(__stkptr),%o1
+	st	%sp, [%o1]
+
   /* reload the addresses for C startup code  */
   /* reload the addresses for C startup code  */
         ld      [%sp+22*4], %o1
         ld      [%sp+22*4], %o1
         add     %sp, 23*4, %o2
         add     %sp, 23*4, %o2
@@ -71,7 +76,7 @@ _start:
 
 
 .data
 .data
 
 
-        .comm   ___fpc_brk_addr,4        /* heap management */
+        .comm __stkptr,4
 
 
         .comm operatingsystem_parameter_envp,4
         .comm operatingsystem_parameter_envp,4
         .comm operatingsystem_parameter_argc,4
         .comm operatingsystem_parameter_argc,4

+ 6 - 1
rtl/linux/sparc/gprt0.as

@@ -29,6 +29,11 @@ _start:
        	or	%o1,%lo(operatingsystem_parameter_envp),%o1
        	or	%o1,%lo(operatingsystem_parameter_envp),%o1
        	st	%o2, [%o1]
        	st	%o2, [%o1]
 
 
+    /* Save initial stackpointer */
+	sethi	%hi(__stkptr),%o1
+	or	%o1,%lo(__stkptr),%o1
+	st	%sp, [%o1]
+
   /* reload the addresses for C startup code  */
   /* reload the addresses for C startup code  */
         ld      [%sp+22*4], %o1
         ld      [%sp+22*4], %o1
         add     %sp, 23*4, %o2
         add     %sp, 23*4, %o2
@@ -92,7 +97,7 @@ _start:
 
 
 .data
 .data
 
 
-        .comm   ___fpc_brk_addr,4        /* heap management */
+        .comm __stkptr,4
 
 
         .comm operatingsystem_parameter_envp,4
         .comm operatingsystem_parameter_envp,4
         .comm operatingsystem_parameter_argc,4
         .comm operatingsystem_parameter_argc,4

+ 7 - 0
rtl/linux/sparc/prt0.as

@@ -49,6 +49,11 @@ _start:
 	or	%o1,%lo(operatingsystem_parameter_envp),%o1
 	or	%o1,%lo(operatingsystem_parameter_envp),%o1
 	st	%o2, [%o1]
 	st	%o2, [%o1]
 
 
+    /* Save initial stackpointer */
+	sethi	%hi(__stkptr),%o1
+	or	%o1,%lo(__stkptr),%o1
+	st	%sp, [%o1]
+
   	/* Call the user program entry point.  */
   	/* Call the user program entry point.  */
   	call	PASCALMAIN
   	call	PASCALMAIN
   	nop
   	nop
@@ -67,6 +72,8 @@ _haltproc:
 
 
 	.size _start, .-_start
 	.size _start, .-_start
 
 
+        .comm __stkptr,4
+
         .comm operatingsystem_parameter_envp,4
         .comm operatingsystem_parameter_envp,4
         .comm operatingsystem_parameter_argc,4
         .comm operatingsystem_parameter_argc,4
         .comm operatingsystem_parameter_argv,4
         .comm operatingsystem_parameter_argv,4

+ 2 - 2
rtl/linux/system.pp

@@ -1,5 +1,5 @@
 {
 {
-    This file is part of the Free Pascal run time librar~y.
+    This file is part of the Free Pascal run time library.
     Copyright (c) 2000 by Marco van de Voort
     Copyright (c) 2000 by Marco van de Voort
     member of the Free Pascal development team.
     member of the Free Pascal development team.
 
 
@@ -254,7 +254,7 @@ Begin
   IsConsole := TRUE;
   IsConsole := TRUE;
   IsLibrary := FALSE;
   IsLibrary := FALSE;
   StackLength := CheckInitialStkLen(initialStkLen);
   StackLength := CheckInitialStkLen(initialStkLen);
-  StackBottom := Sptr - StackLength;
+  StackBottom := initialstkptr - StackLength;
   { Set up signals handlers }
   { Set up signals handlers }
   InstallSignals;
   InstallSignals;
   { Setup heap }
   { Setup heap }

+ 5 - 0
rtl/linux/x86_64/cprt0.as

@@ -83,6 +83,9 @@ main_stub:
         movq    %rbp,___fpc_ret_rbp
         movq    %rbp,___fpc_ret_rbp
         pushq   %rax
         pushq   %rax
 
 
+        /* Save initial stackpointer */
+        movl    %rsp,__stkptr
+
         /* start the program */
         /* start the program */
         xorq    %rbp,%rbp
         xorq    %rbp,%rbp
         call    PASCALMAIN
         call    PASCALMAIN
@@ -120,6 +123,8 @@ ___fpc_ret_rbp:
         .quad   0
         .quad   0
 
 
 .bss
 .bss
+        .comm __stkptr,8
+
         .comm operatingsystem_parameter_envp,8
         .comm operatingsystem_parameter_envp,8
         .comm operatingsystem_parameter_argc,8
         .comm operatingsystem_parameter_argc,8
         .comm operatingsystem_parameter_argv,8
         .comm operatingsystem_parameter_argv,8

+ 5 - 0
rtl/linux/x86_64/gprt0.as

@@ -91,6 +91,9 @@ main_stub:
         movq    $_mcleanup,%rdi
         movq    $_mcleanup,%rdi
         call    atexit
         call    atexit
 
 
+        /* Save initial stackpointer */
+        movl    %rsp,__stkptr
+
         /* start the program */
         /* start the program */
         xorq    %rbp,%rbp
         xorq    %rbp,%rbp
         call    PASCALMAIN
         call    PASCALMAIN
@@ -128,6 +131,8 @@ ___fpc_ret_rbp:
         .quad   0
         .quad   0
 
 
 .bss
 .bss
+        .comm __stkptr,8
+
         .comm operatingsystem_parameter_envp,8
         .comm operatingsystem_parameter_envp,8
         .comm operatingsystem_parameter_argc,8
         .comm operatingsystem_parameter_argc,8
         .comm operatingsystem_parameter_argv,8
         .comm operatingsystem_parameter_argv,8

+ 5 - 0
rtl/linux/x86_64/prt0.as

@@ -48,6 +48,9 @@ _start:
         movq     %rax,operatingsystem_parameter_envp
         movq     %rax,operatingsystem_parameter_envp
         andq     $~15,%rsp            /* Align the stack to a 16 byte boundary to follow the ABI.  */
         andq     $~15,%rsp            /* Align the stack to a 16 byte boundary to follow the ABI.  */
 
 
+        /* Save initial stackpointer */
+        movl    %rsp,__stkptr
+
         xorq    %rbp, %rbp
         xorq    %rbp, %rbp
         call    PASCALMAIN
         call    PASCALMAIN
 	jmp	_haltproc
 	jmp	_haltproc
@@ -69,6 +72,8 @@ __data_start:
         data_start = __data_start
         data_start = __data_start
 
 
 .bss
 .bss
+        .comm __stkptr,8
+
         .comm operatingsystem_parameter_envp,8
         .comm operatingsystem_parameter_envp,8
         .comm operatingsystem_parameter_argc,8
         .comm operatingsystem_parameter_argc,8
         .comm operatingsystem_parameter_argv,8
         .comm operatingsystem_parameter_argv,8