home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / LK_V1.06.LHA / LK V1.06 / SOURCES / stacksize.s < prev    next >
Encoding:
Text File  |  1994-11-01  |  2.2 KB  |  102 lines

  1. ;    OPT    O+,OW-,L+
  2. ;--------------------------------------------------
  3. ;    lk V1.01 stack header.
  4. ;    $VER: stack.s 1.00 (18.07.94)
  5. ;    Written by Alexis WILKE (c) 1994.
  6. ;
  7. ;    This code will be used to ensure a specific
  8. ;    stack size at the startup of a command.
  9. ;--------------------------------------------------
  10.  
  11.     INCDIR    "INCLUDE:INCLUDE.STRIP/"
  12.     INCLUDE    "EXEC/execbase.i"
  13.     INCLUDE    "EXEC/tasks.i"
  14.     INCLUDE    "INCLUDE:sw.i"
  15.  
  16.     XDEF    __Startup
  17.  
  18.     XREF    __STACKSIZE
  19.     XREF    __autostartup
  20.  
  21.     SECTION    ENTRYHUNK,CODE
  22. ;--------------------------------------------------
  23. __Startup
  24.     MoveM.L    D0-D1/A0-A1/A6,-(A7)        ;Keep all registers
  25.     MoveA.L    4.W,A6
  26.     Move.L    #__STACKSIZE,D0
  27.     MoveA.L    ThisTask(A6),A1
  28.     Move.L    TC_SPUPPER(A1),D1        ;Enough stack already
  29.     Sub.L    TC_SPLOWER(A1),D1
  30.     Cmp.L    D1,D0
  31.     Bls.B    .stackok
  32.     MoveQ    #$00,D1
  33.     SYS    AllocMem
  34.     Tst.L    D0
  35.     Bne.B    .setstack
  36.     Lea    DName(PC),A1
  37.     SYS    OldOpenLibrary
  38.     Tst.L    D0
  39.     Beq.B    .error
  40.     SYS    Output,D0
  41.     Move.L    D0,D1
  42.     Beq.B    .close
  43.     Lea    Message(PC),A0
  44.     Move.L    A0,D2
  45.     Move.L    #MessageEnd-Message,D3
  46.     SYS    Write
  47. .close
  48.     MoveA.L    A6,A1
  49.     MoveA.L    4.W,A6
  50.     SYS    CloseLibrary
  51. .error
  52.     MoveM.L    (A7)+,D0-D1/A0-A1/A6
  53.     Rts
  54. .setstack
  55.     Lea    __lowerstack(PC),A0
  56.     Move.L    D0,__newstack-__lowerstack(A0)
  57.     Move.L    A7,__oldstack-__lowerstack(A0)
  58.     MoveA.L    ThisTask(A6),A1
  59.     Move.L    TC_SPLOWER(A1),__lowerstack-__lowerstack(A0)
  60.     Move.L    TC_SPUPPER(A1),__upperstack-__lowerstack(A0)
  61.     SYS    Disable
  62.     Move.L    D0,TC_SPLOWER(A1)
  63.     Add.L    #__STACKSIZE,D0
  64.     Move.L    D0,TC_SPUPPER(A1)
  65.     MoveA.L    A7,A0                ;Save old stack in A0
  66.     MoveA.L    D0,A7                ;Get new stack pointer
  67.     SYS    Enable
  68.     MoveM.L    (A0),D0-D1/A0-A1/A6        ;The stack has been saved in A0
  69.     Bra.B    .start
  70. .stackok
  71.     MoveM.L    (A7)+,D0-D1/A0-A1/A6
  72. .start
  73.     Jsr    __autostartup            ;Go to your startup
  74.     Move.L    __newstack(PC),D7
  75.     Beq.B    .nostack
  76.     Move.L    D0,D6
  77.     MoveA.L    4.W,A6
  78.     MoveA.L    ThisTask(A6),A5
  79.     SYS    Disable
  80.     Move.L    __lowerstack(PC),TC_SPLOWER(A5)
  81.     Move.L    __upperstack(PC),TC_SPUPPER(A5)
  82.     MoveA.L    __oldstack(PC),A7        ;Restore previous stack
  83.     SYS    Enable
  84.     AddA.W    #4*5,A7
  85.     MoveA.L    D7,A1
  86.     Move.L    #__STACKSIZE,D0
  87.     SYS    FreeMem
  88.     Move.L    D6,D0
  89. .nostack
  90.     Rts
  91.  
  92. __newstack    DS.L    1
  93. __oldstack    DS.L    1
  94. __lowerstack    DS.L    1
  95. __upperstack    DS.L    1
  96.  
  97. DName        Dc.B    "dos.library",0
  98. Message        Dc.B    "Cannot allocate correct stack."
  99. MessageEnd
  100.     EVEN
  101.  
  102.