home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / LK_V1.06.LHA / LK V1.06 / SOURCES / stackpri.s < prev    next >
Encoding:
Text File  |  1994-11-01  |  2.3 KB  |  106 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    PRIORITY
  19.     XREF    __STACKSIZE
  20.     XREF    __autostartup
  21.  
  22.     SECTION    ENTRYHUNK,CODE
  23. ;--------------------------------------------------
  24. __Startup
  25.     MoveM.L    D0-D1/A0-A1/A6,-(A7)        ;Keep all registers
  26.     MoveA.L    4.W,A6
  27.     MoveA.L    ThisTask(A6),A1
  28.     Move.B    #PRIORITY,D0
  29.     SYS    SetTaskPri            ;Set my priority
  30.     Move.L    #__STACKSIZE,D0
  31.     MoveA.L    ThisTask(A6),A1
  32.     Move.L    TC_SPUPPER(A1),D1        ;Enough stack already
  33.     Sub.L    TC_SPLOWER(A1),D1
  34.     Cmp.L    D1,D0
  35.     Bls.B    .stackok
  36.     MoveQ    #$00,D1
  37.     SYS    AllocMem
  38.     Tst.L    D0
  39.     Bne.B    .setstack
  40.     Lea    DName(PC),A1
  41.     SYS    OldOpenLibrary
  42.     Tst.L    D0
  43.     Beq.B    .error
  44.     SYS    Output,D0
  45.     Move.L    D0,D1
  46.     Beq.B    .close
  47.     Lea    Message(PC),A0
  48.     Move.L    A0,D2
  49.     Move.L    #MessageEnd-Message,D3
  50.     SYS    Write
  51. .close
  52.     MoveA.L    A6,A1
  53.     MoveA.L    4.W,A6
  54.     SYS    CloseLibrary
  55. .error
  56.     MoveM.L    (A7)+,D0-D1/A0-A1/A6
  57.     Rts
  58. .setstack
  59.     Lea    __lowerstack(PC),A0
  60.     Move.L    D0,__newstack-__lowerstack(A0)
  61.     Move.L    A7,__oldstack-__lowerstack(A0)
  62.     MoveA.L    ThisTask(A6),A1
  63.     Move.L    TC_SPLOWER(A1),__lowerstack-__lowerstack(A0)
  64.     Move.L    TC_SPUPPER(A1),__upperstack-__lowerstack(A0)
  65.     SYS    Disable
  66.     Move.L    D0,TC_SPLOWER(A1)
  67.     Add.L    #__STACKSIZE,D0
  68.     Move.L    D0,TC_SPUPPER(A1)
  69.     MoveA.L    A7,A0                ;Save old stack in A0
  70.     MoveA.L    D0,A7                ;Get new stack pointer
  71.     SYS    Enable
  72.     MoveM.L    (A0),D0-D1/A0-A1/A6        ;The stack has been saved in A0
  73.     Bra.B    .start
  74. .stackok
  75.     MoveM.L    (A7)+,D0-D1/A0-A1/A6
  76. .start
  77.     Jsr    __autostartup            ;Go to your startup
  78.     Move.L    __newstack(PC),D7
  79.     Beq.B    .nostack
  80.     Move.L    D0,D6
  81.     MoveA.L    4.W,A6
  82.     MoveA.L    ThisTask(A6),A5
  83.     SYS    Disable
  84.     Move.L    __lowerstack(PC),TC_SPLOWER(A5)
  85.     Move.L    __upperstack(PC),TC_SPUPPER(A5)
  86.     MoveA.L    __oldstack(PC),A7        ;Restore previous stack
  87.     SYS    Enable
  88.     AddA.W    #4*5,A7
  89.     MoveA.L    D7,A1
  90.     Move.L    #__STACKSIZE,D0
  91.     SYS    FreeMem
  92.     Move.L    D6,D0
  93. .nostack
  94.     Rts
  95.  
  96. __newstack    DS.L    1
  97. __oldstack    DS.L    1
  98. __lowerstack    DS.L    1
  99. __upperstack    DS.L    1
  100.  
  101. DName        Dc.B    "dos.library",0
  102. Message        Dc.B    "Cannot allocate correct stack."
  103. MessageEnd
  104.     EVEN
  105.  
  106.