Browse Source

Amiga: improved the startup code, only allocate a new stack area if the area requested compile time is smaller than the one the system provides to us

git-svn-id: trunk@28525 -
Károly Balogh 11 years ago
parent
commit
feb255ec48
1 changed files with 47 additions and 16 deletions
  1. 47 16
      rtl/amiga/m68k/prt0.as

+ 47 - 16
rtl/amiga/m68k/prt0.as

@@ -1,6 +1,6 @@
 |
 |
 |  This file is part of the Free Pascal run time library.
 |  This file is part of the Free Pascal run time library.
-|  Copyright (c) 2005 by Karoly Balogh
+|  Copyright (c) 2005-2014 by Karoly Balogh
 |
 |
 |  Startup code for Amiga/m68k RTL
 |  Startup code for Amiga/m68k RTL
 |
 |
@@ -24,35 +24,63 @@ __EXESTART:
 _start:
 _start:
 start:
 start:
    movem.l  d0-d7/a0-a6,-(sp)
    movem.l  d0-d7/a0-a6,-(sp)
-   
+
    | Get ExecBase
    | Get ExecBase
    move.l   0x4,a6
    move.l   0x4,a6
    move.l   a6,_ExecBase
    move.l   a6,_ExecBase
-   
+
+   | Get current stacksize
+   move     #0,a1            | nil
+   jsr      -294(a6)         | FindTask()
+   move.l   d0,a0
+   move.l   62(a0),d1        | SPUpper
+   sub.l    58(a0),d1        | SPLower
+
+   | Check if we need a new stack
+   | Only allocate a new stack if the system-provided
+   | stack is smaller than the one set compile time
+   move.l   __stklen,d0      | Also an argument for AllocVec() below
+   cmp.l    d0,d1
+   blt      _allocStack
+
+   move.l   d1,__stklen      | Store the new stack size
+   moveq.l  #0,d0
+   move.l   d0,stackArea     | Clear the stackArea pointer for exit test
+   move.l   sp,stackPtr      | Store the stackPointer for restoration
+   bra      _noAllocStack
+
+_allocStack:
    | Allocating new stack
    | Allocating new stack
-   move.l   __stklen,d0
    moveq.l  #0,d1            | MEMF_ANY
    moveq.l  #0,d1            | MEMF_ANY
    jsr      -684(a6)         | AllocVec()
    jsr      -684(a6)         | AllocVec()
    tst.l    d0
    tst.l    d0
-   beq      __exit  
+   beq      __exit
    move.l   d0,stackArea
    move.l   d0,stackArea
 
 
    | Setting up StackSwap structure, and do the StackSwap
    | Setting up StackSwap structure, and do the StackSwap
-   lea.l    stackSwap,a0
+   lea      stackSwap,a0
    move.l   d0,(a0)          | Bottom of the stack
    move.l   d0,(a0)          | Bottom of the stack
    add.l    __stklen,d0
    add.l    __stklen,d0
    move.l   d0,4(a0)         | Top of the stack
    move.l   d0,4(a0)         | Top of the stack
    move.l   d0,8(a0)         | Initial stackpointer
    move.l   d0,8(a0)         | Initial stackpointer
    jsr      -732(a6)         | StackSwap()
    jsr      -732(a6)         | StackSwap()
 
 
+_noAllocStack:
    jsr PASCALMAIN
    jsr PASCALMAIN
 
 
    .globl _haltproc 
    .globl _haltproc 
 _haltproc:
 _haltproc:
+   | Check if we need to release a stack
+   tst.l    stackArea
+   bne      _freeStack
 
 
+   move.l   stackPtr,sp
+   bra      __exit
+
+_freeStack:
    | Swapping the stack back
    | Swapping the stack back
    move.l   _ExecBase,a6
    move.l   _ExecBase,a6
-   lea.l    stackSwap,a0
+   lea      stackSwap,a0
    jsr      -732(a6)         | StackSwap()
    jsr      -732(a6)         | StackSwap()
 
 
    | Freeing up stack area
    | Freeing up stack area
@@ -64,23 +92,26 @@ __exit:
    move.l   operatingsystem_result,d0
    move.l   operatingsystem_result,d0
    rts
    rts
 
 
-   .data
+   .bss
 
 
    .globl _ExecBase
    .globl _ExecBase
    .globl SysBase
    .globl SysBase
-   .align 4
+   .balign 4
 SysBase:
 SysBase:
 _ExecBase:
 _ExecBase:
-   .long 0
+   .skip 4
 
 
    .globl stackArea
    .globl stackArea
-   .align 4
+   .balign 4
 stackArea:
 stackArea:
-   .long 0
+   .skip 4
+
+   .globl stackPtr
+   .balign 4
+stackPtr:
+   .skip 4
 
 
    .globl stackSwap
    .globl stackSwap
-   .align 4
+   .balign 4
 stackSwap:
 stackSwap:
-   .long 0
-   .long 0
-   .long 0
+   .skip 12