mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-10 15:45:57 +02:00
AROS: massively enhanced i386 startup code, including
- fixed to always update the stacksize in __stklen, so the RTL knows the correct stacksize (StackLength in system unit is correct) - this probably also fixes stack checking or opens the way to have a working stack checking on AROS, but that was not tested + call PASCALMAIN via exec/NewStackSwap() and provide a larger stack when the pre-set value is higher than what the system provides + use operatingsystem_result to simplify return code handling These changes bring the AROS startup's stack handling to the Amiga/m68k and MorphOS level git-svn-id: trunk@28611 -
This commit is contained in:
parent
2722421d96
commit
5a10472729
@ -12,11 +12,10 @@
|
|||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
#
|
#
|
||||||
|
|
||||||
#AROS Startup Code
|
# AROS Startup Code
|
||||||
#
|
|
||||||
.text
|
.text
|
||||||
.align 4
|
.align 4
|
||||||
.section .aros.startup, "ax"
|
.section .aros.startup, "ax"
|
||||||
.globl _start
|
.globl _start
|
||||||
.globl start
|
.globl start
|
||||||
.globl _haltproc
|
.globl _haltproc
|
||||||
@ -24,65 +23,138 @@
|
|||||||
_start:
|
_start:
|
||||||
start:
|
start:
|
||||||
|
|
||||||
/* Save the exec library base */
|
/* Save the exec library base */
|
||||||
movl 12(%esp), %ecx
|
movl 12(%esp),%eax
|
||||||
movl %ecx, _ExecBase
|
movl %eax,_ExecBase
|
||||||
|
|
||||||
/* Save the command line pointer length to CommandLineLen */
|
/* Save the command line pointer length to CommandLineLen */
|
||||||
movl 8(%esp),%ecx
|
movl 8(%esp),%eax
|
||||||
movl %ecx,CommandLineLen
|
movl %eax,CommandLineLen
|
||||||
|
|
||||||
/* Save the command line pointer to CommandLine */
|
/* Save the command line pointer to CommandLine */
|
||||||
movl 4(%esp),%eax
|
movl 4(%esp),%eax
|
||||||
movl %eax,CommandLine
|
movl %eax,CommandLine
|
||||||
|
|
||||||
/* save all register */
|
/* save all registers */
|
||||||
pushal
|
pushal
|
||||||
|
|
||||||
/* Save stack pointer for exit() routine */
|
/* get the pointer to current stack */
|
||||||
movl %esp,STKPTR
|
movl _ExecBase,%eax
|
||||||
|
pushl %eax
|
||||||
|
pushl $0
|
||||||
|
movl -196(%eax),%eax /* FindTask(nil) */
|
||||||
|
call *%eax
|
||||||
|
addl $8,%esp
|
||||||
|
|
||||||
call PASCALMAIN
|
movl 64(%eax),%ecx /* SPUpper */
|
||||||
/* if returns from here set an empty returncode */
|
subl 60(%eax),%ecx /* SPLower */
|
||||||
xorl %eax, %eax
|
|
||||||
pushl %eax
|
|
||||||
pushl %eax
|
|
||||||
|
|
||||||
|
/* Uncomment the symbol line below to force system stack use,
|
||||||
|
and do not attempt to reallocate stack if the system-provided
|
||||||
|
stack is smaller than the user specified */
|
||||||
|
# FORCE_USE_SYSTEM_STACK:
|
||||||
|
|
||||||
/* entry for stop the program*/
|
.ifndef FORCE_USE_SYSTEM_STACK
|
||||||
_haltproc:
|
/* Check if we need a new stack
|
||||||
haltproc:
|
Only allocate a new stack if the system-provided
|
||||||
|
stack is smaller than the one set compile time */
|
||||||
|
cmpl __stklen,%ecx
|
||||||
|
jl _allocStack
|
||||||
|
.endif
|
||||||
|
|
||||||
/* get retun code from stack */
|
movl %ecx,__stklen /* Store the new stack size */
|
||||||
movl 4(%esp),%eax
|
xorl %eax,%eax
|
||||||
|
movl %eax,StackAreaPtr /* Clear the stackAreaPtr for exit test */
|
||||||
|
jmp _noAllocStack
|
||||||
|
|
||||||
/* save for later use */
|
_allocStack:
|
||||||
movl %eax,_returncode
|
/* Allocating new stack */
|
||||||
|
movl _ExecBase,%eax
|
||||||
|
pushl %eax
|
||||||
|
pushl $0 /* MEMF_ANY */
|
||||||
|
pushl __stklen
|
||||||
|
movl -456(%eax),%eax /* AllocVec() */
|
||||||
|
call *%eax
|
||||||
|
addl $12,%esp
|
||||||
|
|
||||||
/* get back my stack */
|
testl %eax,%eax
|
||||||
movl STKPTR,%esp
|
je __exit
|
||||||
|
movl %eax,StackAreaPtr
|
||||||
|
|
||||||
|
/* Setting up StackSwap structure, and do the StackSwap */
|
||||||
|
lea StackSwapStruct,%ecx
|
||||||
|
movl %eax,(%ecx) /* Bottom of the stack */
|
||||||
|
addl __stklen,%eax
|
||||||
|
movl %eax,4(%ecx) /* Top of the stack */
|
||||||
|
movl %eax,8(%ecx) /* Initial stackpointer */
|
||||||
|
movl _ExecBase,%eax
|
||||||
|
pushl %eax
|
||||||
|
pushl $0
|
||||||
|
lea _initProc,%ebx
|
||||||
|
pushl %ebx
|
||||||
|
pushl %ecx
|
||||||
|
movl -536(%eax),%eax /* NewStackSwap() */
|
||||||
|
call *%eax
|
||||||
|
addl $16,%esp
|
||||||
|
jmp _afterMain
|
||||||
|
|
||||||
|
_noAllocStack:
|
||||||
|
call _initProc
|
||||||
|
|
||||||
|
_afterMain:
|
||||||
|
/* check if we have a StackArea to free */
|
||||||
|
movl StackAreaPtr,%eax
|
||||||
|
testl %eax,%eax
|
||||||
|
je __exit
|
||||||
|
|
||||||
|
_freeStack:
|
||||||
|
/* Freeing up stack area */
|
||||||
|
movl _ExecBase,%eax
|
||||||
|
pushl %eax
|
||||||
|
pushl StackAreaPtr
|
||||||
|
movl -460(%eax),%eax /* FreeVec() */
|
||||||
|
call *%eax
|
||||||
|
addl $8,%esp
|
||||||
|
|
||||||
|
__exit:
|
||||||
/* get back all registers */
|
/* get back all registers */
|
||||||
popal
|
popal
|
||||||
|
/* get returncode */
|
||||||
/* reset returncode */
|
movl operatingsystem_result,%eax
|
||||||
movl _returncode, %eax
|
|
||||||
|
|
||||||
/* bye bye */
|
/* bye bye */
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
/* This function is getting called from NewStackSwap() or
|
||||||
|
as standalone if we don't do stackswap */
|
||||||
|
_initProc:
|
||||||
|
pushal
|
||||||
|
/* Save stack pointer */
|
||||||
|
movl %esp,STKPTR
|
||||||
|
|
||||||
|
/* call the main function */
|
||||||
|
call PASCALMAIN
|
||||||
|
|
||||||
|
/* entry to stop the program */
|
||||||
|
_haltproc:
|
||||||
|
haltproc:
|
||||||
|
/* restore the old stackPtr and return */
|
||||||
|
movl STKPTR,%esp
|
||||||
|
popal
|
||||||
|
ret
|
||||||
|
|
||||||
/*----------------------------------------------------*/
|
/*----------------------------------------------------*/
|
||||||
|
|
||||||
.data
|
.bss
|
||||||
.global CommandLineLen # byte length of command line
|
.global CommandLineLen # byte length of command line
|
||||||
.global CommandLine # comandline as PChar
|
.global CommandLine # comandline as PChar
|
||||||
.global STKPTR # Used to terminate the program, initial SP
|
.global STKPTR # Used to terminate the program, initial SP
|
||||||
.global _ExecBase # exec library base
|
.global _ExecBase # exec library base
|
||||||
.align 4
|
.align 4
|
||||||
|
|
||||||
_returncode: .long 0
|
CommandLine: .skip 4
|
||||||
CommandLine: .long 0
|
CommandLineLen: .skip 4
|
||||||
CommandLineLen: .long 0
|
STKPTR: .skip 4
|
||||||
STKPTR: .long 0
|
_ExecBase: .skip 4
|
||||||
_ExecBase: .long 0
|
|
||||||
|
|
||||||
|
StackAreaPtr: .skip 4
|
||||||
|
StackSwapStruct: .skip 12
|
||||||
|
Loading…
Reference in New Issue
Block a user