home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 581b.lha / MoveSuperStuff / MSS.asm < prev    next >
Assembly Source File  |  1991-08-12  |  3KB  |  198 lines

  1.  
  2.     INCLUDE    "MAC:sysmacs.i"
  3.  
  4.     STDOPT    ;DEBUG
  5.     INCEQUS    ALL
  6.  
  7. CALL    MACRO
  8.     XREF    _LVO\1
  9.     JSR    _LVO\1(A6)
  10.     ENDM
  11.  
  12. MemHeader    EQUR    A2
  13. HighMem        EQUR    D2
  14. MemBase        EQUR    D3
  15. VBRstore    EQUR    D4
  16. LoMem        EQUR    D5
  17. HiMem        EQUR    D6
  18. Size        EQUR    D7
  19.  
  20. ; Check if we live in kick 1.2 or higher.
  21.  
  22.     move.l    $4.w,A6
  23.     cmp.w    #33,LIB_VERSION(A6)
  24.     bls    KickTooOld
  25.  
  26. ; Find the premier memlist entry, check if fast & set the highmem pointer.
  27.  
  28.     move.l    MemList(A6),MemHeader
  29.     btst.b    #MEMB_FAST,MH_ATTRIBUTES+1(MemHeader)
  30.     beq    NoFastMem
  31.     move.l    MH_UPPER(MemHeader),HighMem
  32.     add.l    #$8000,HighMem
  33.     clr.w    HighMem
  34.  
  35. ; Check if this is a 68010 or higher.
  36.  
  37.     btst.b    #AFB_68010,AttnFlags+1(A6)
  38.     beq.s    DoNotChangeVBR
  39.  
  40. ; Get the vector base register and check if it's already set.
  41.  
  42.     lea    GetVBR(PC),A5
  43.     CALL    Supervisor
  44.     tst.l    VBRstore
  45.     bne.s    DoNotChangeVBR
  46.  
  47. ; Allocate memory for the vector table
  48.  
  49.     move.l    #$400,D0
  50.     bsr    AllocHighMem
  51.     beq    NoFastMem
  52.     move.l    D0,MemBase
  53.  
  54. ; Copy the vector table.
  55.  
  56.     sub.l    A0,A0
  57.     move.l    MemBase,A1
  58.     move.l    #$400,D0
  59.     CALL    CopyMemQuick
  60.  
  61. ; Now change the vector base register.
  62.  
  63.     move.l    MemBase,VBRstore
  64.     lea    SetVBR(PC),A5
  65.     CALL    Supervisor
  66. DoNotChangeVBR:
  67.  
  68. ;
  69. ; ** The section below deals with moving the supervisor stack to fastmem **
  70. ;
  71.  
  72. ; Check if system stack already moved
  73.  
  74.     move.l    SysStkLower(A6),LoMem
  75.     cmp.l    MH_LOWER(MemHeader),LoMem
  76.     blo.s    SysStackNotMovedYet
  77.     cmp.l    HighMem,LoMem
  78.     blo.s    Exit
  79. SysStackNotMovedYet:
  80.  
  81. ; Compute the size of the supervisor stack.
  82.  
  83.     move.l    SysStkUpper(A6),HiMem
  84.     move.l    HiMem,Size
  85.     sub.l    LoMem,Size
  86.  
  87. ; Allocate memory for the new supervisor stack.
  88.  
  89.     move.l    Size,D0
  90.     bsr.s    AllocHighMem
  91.     beq.s    NoFastMem
  92.     move.l    D0,MemBase
  93.  
  94. ; Disable interrupts and copy the contents of the supervisor stack.
  95.  
  96.     CALL    Disable
  97.  
  98.     move.l    LoMem,A0
  99.     move.l    MemBase,A1
  100.     move.l    Size,D0
  101.     CALL    CopyMem
  102.  
  103. ; Fix up execbase
  104.  
  105.     move.l    MemBase,HiMem
  106.     add.l    Size,HiMem
  107.  
  108.     move.l    MemBase,SysStkLower(A6)
  109.     move.l    HiMem,SysStkUpper(A6)
  110.  
  111. ; Fix supervisor stack pointer and re-enable interrupts.
  112.  
  113.     CALL    SuperState
  114.     sub.l    LoMem,D0
  115.     add.l    MemBase,D0
  116.     CALL    UserState
  117.  
  118. ; Recalculate checksum
  119.  
  120.     LEA    $22(a6),a0
  121.     MOVEQ     #$16,d0
  122.     MOVEQ    #0,d1
  123. sumloop:ADD.W    (a0)+,d1
  124.     DBRA    d0,sumloop
  125.     NOT.W    d1
  126.     MOVE.W    d1,ChkSum(a6)
  127.  
  128. ; Adjust memlist and free the old system stack, gives us 6K additional chip.
  129.  
  130.     cmp.w    #36,LIB_VERSION(A6)
  131.     bhs.s    KickTooNew
  132.  
  133.     lea    MemList(A6),A0
  134. FetchMextMemHeader:
  135.     move.l    (A0),A0
  136.     tst.l    (A0)
  137.     beq.s    NoFreePossible
  138.     cmp.l    MH_UPPER(A0),LoMem
  139.     bne    FetchMextMemHeader
  140.     add.l    Size,MH_UPPER(A0)
  141.  
  142. KickTooNew:
  143.     move.l    LoMem,A1
  144.     move.l    Size,D0
  145.     CALL    FreeMem
  146. NoFreePossible:
  147.  
  148.     CALL    Enable
  149.  
  150. ; Done
  151.  
  152. Exit:
  153. NoFastMem:
  154. KickTooOld:
  155.     MOVEQ    #0,D0
  156.     RTS
  157.  
  158. ; Subroutine section
  159.  
  160. ; This func tries to allocate high memory at $A00000, $800000, $600000 or
  161. ; $400000. If it doesn't succeed, it will try to fetch any fast memory it
  162. ; can get its hands on.
  163. ; I : D0.L
  164. ;   : A6's gotta point to exec base.
  165. ; O : D0.L = Membase if succeeded. 0 if failed. Z=1 if failed.
  166.  
  167. AllocHighMem:
  168.     move.l    D0,-(SP)
  169.     sub.l    D0,HighMem
  170.  
  171. ; Try to allocate at the end of the premier mem chunk.
  172.  
  173.     move.l    HighMem,A1
  174.     CALL    AllocAbs
  175.     tst.l    D0
  176.     bne.s    AllocatedMem
  177.  
  178. ; Try to fetch any fastmem.
  179.  
  180.     move.l    (SP),D0
  181.     move.l    #MEMF_FAST,D1
  182.     CALL    AllocMem
  183.     tst.l    D0
  184. AllocatedMem:
  185.     addq.l    #4,SP
  186.     rts
  187.  
  188. ; These are the VBR get 'n set super-routines
  189.  
  190. GetVBR:
  191.     DC.W    $4E7A,$4801        ;  movec.l VBR,D4
  192.     rte
  193. SetVBR:
  194.     DC.W    $4E7B,$4801        ;  movec.l D4,VBR
  195.     rte
  196.  
  197.     END
  198.