home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / disks / disk400.lzh / SetCPU / reboot.a < prev    next >
Text File  |  1990-11-03  |  5KB  |  200 lines

  1. ;======================================================================
  2. ;
  3. ;    SetCPU V1.60
  4. ;    by Dave Haynie, April 13, 1990
  5. ;    Released to the Public Domain
  6. ;
  7. ;    REBOOT.A MODULE
  8. ;
  9. ;    This module contains functions that do the clever reset magic
  10. ;    needed for KickStart imaging.
  11. ;
  12. ;======================================================================
  13.  
  14.     include "setcpu.i"
  15.  
  16.     cseg
  17.  
  18.     xdef    _RAMBoot    ; Effects the reboot into a RAM image
  19.     xdef    _BootCode    ; Actual main reboot code
  20.     xdef    _BootCodeSize    ; Size of this magic code
  21.     xdef    _CleanBoot    ; Boot back to system ROM, reset Exec
  22.     xdef    _ResetCode    ; Smart reset routine
  23.     xdef    _ResetCodeSize    ; Size of this magic code
  24.  
  25. ;======================================================================
  26. ;
  27. ;    This is the RAMBoot routine as called from C.  The C code has
  28. ;    set up the tag structure with valid MMU data and a pointer to
  29. ;    the main reset routine in safe memory.  The routine will fetch
  30. ;    the systag from the stack, then call the safe routine in the
  31. ;    supervisor mode.  That call is the last kernal call used; the
  32. ;    reset routine itself doesn't use any ROM routines, so it can
  33. ;    safely turn off the MMU before it goes to work, methinks.
  34. ;
  35. ;    void RAMBoot(struct systag *tag, LONG ClearExec,LONG Delay)
  36. ;
  37. ;======================================================================
  38.  
  39. _RAMBoot:
  40.     move.l    4(sp),a2        ; Get the systag where we can use it
  41.     move.l    8(sp),d4        ; KeepExec?
  42.     move.l    12(sp),d5        ; Delay value
  43.     move.l    4,a6
  44.     lea.l    TrickyBits,a5        ; Get the supervisor code
  45.     CALLSYS    Supervisor        ; Go to supervisor mode
  46.     rts                ; We never get here!
  47.  
  48. ;======================================================================
  49. ;
  50. ;    This is the start of the supervisor portion of the reboot code.
  51. ;    This code gets things in the registers the ChipRAM code 
  52. ;    requires, loads up a reset routine into cache, freezes the
  53. ;    cache, resets, waits for the CIA chips, and then calls the
  54. ;    ChipRAM code portion which will turn the MMU on and jump to
  55. ;    ROM's start address.
  56. ;
  57. ;    a2    SetCPU system tag
  58. ;    a6    ExecBase
  59. ;    d4    KeepExec Flag
  60. ;    d5    Boot Delay
  61. ;
  62. ;======================================================================
  63.  
  64. TrickyBits:
  65.     move.l    TAG_ROMSTART(a2),a4    ; Get the ROM jump address
  66.     move.l    TAG_RESETCODE(a2),a3    ; Get the ChipRAM based code
  67.     lea.l    TAG_CRP_0(a2),a1    ; Get CRP register
  68.     lea.l    TAG_TC(a2),a0        ; Get TC register
  69.  
  70.     and.l    #$7fffffff,(a0)        ; Turn off MMU
  71.     PMOVE_    (a0),tc            ; -> $f010,$4000            
  72.     or.l    #$80000000,(a0)        ; Prep for startup
  73.     PMOVE_    (a1),crp        ; -> $f011,$4c00
  74.  
  75.     cmp.l    #0,d4            ; If asked for, zap ExecBase good
  76.     bne    1$
  77.     moveq.l    #0,d0
  78.     move.l    d0,$4
  79. 1$
  80.     move.l    #1,d1            ; Make sure inst cache is on!
  81.     MOVEC_    d1,cacr
  82.  
  83.     move.l    #1,d3            ; First pass, no delay
  84.     lea.l    CacheRun,a6        ; Get the initial branch address
  85.  
  86. RSTLoop:    
  87.     jmp (a6)
  88.  
  89. RSTIt:
  90.     reset                ; Clobber the system
  91.     reset
  92.  
  93. CacheRun:
  94.     move.w    ANYCREG,d1        ; Set a spell, take yer shoes off
  95.     subq.l    #1,d3
  96.     bne    CacheRun
  97.     move.b    #3,$bfe201        ; Turn off Amiga ROM Overlay
  98.     move.b    #2,$bfe001
  99.  
  100.     cmp.l    a3,a6            ; Last time through?
  101.     beq    RSTLoop            ; If so, go back
  102.     
  103.     move.l    a3,a6            ; No?  Get the address,
  104.     move.l    d5,d3            ;          the delay
  105.     move.l    #3,d1            ;          freeze the cache
  106.     MOVEC_    d1,cacr            
  107.     bra    RSTIt            ; And Up to the reset stuff
  108.  
  109. ;======================================================================
  110. ;
  111. ;    This is the RAM reboot code, which is called to reset the 
  112. ;    system into the new ROM, which is of course now in some magic
  113. ;    and safe place.  The ROM's jump address in in A4 when this
  114. ;    code is called, and the TC register is in A0.
  115. ;
  116. ;======================================================================
  117.  
  118. RAMBootCode:
  119.     move.l    #0,d1            ; Turn all caches off
  120.     MOVEC_    d1,cacr
  121.     move.l    #10,d1            ; Let 'em know we're here
  122. 1$
  123.     bchg    #1,$bfe001
  124.     move.l    #80000,d0
  125. 2$    subq.l    #1,d0
  126.     bne    2$
  127.     dbra    d1,1$
  128.  
  129.     PMOVE_    (a0),tc            ; Turn on the MMU
  130.     jmp    (a4)            ; Start up the ROM
  131.     nop
  132.     nop
  133.     nop
  134.     nop
  135. RAMBootEnd:
  136.  
  137. _BootCode:
  138.     dc.l    RAMBootCode
  139. _BootCodeSize:
  140.     dc.l    RAMBootEnd-RAMBootCode+1
  141.  
  142. ;======================================================================
  143. ;
  144. ;    This routine forces a boot back to ROM, clearing out the 
  145. ;    ExecBase and turning off the MMU and caches.  
  146. ;
  147. ;    void CleanBoot(void)
  148. ;
  149. ;======================================================================
  150.  
  151. _CleanBoot:
  152.     move.l    4,a6
  153.  
  154.     lea    1$,a5
  155.     CALLSYS    Supervisor
  156.     rts
  157. 1$
  158.     move.l    #0,(sp)            ; Turn off MMU
  159.     move.l    sp,a0
  160.     PMOVE_    (a0),tc            ; -> $f010,$4000
  161.  
  162.     move.l    #0,d1            ; Turn all caches off
  163.     MOVEC_    d1,cacr
  164.  
  165.     move.l    4,a6            ; Clear out ExecBase
  166.     move.l    #0,$4
  167.  
  168.     move.l    $00f80000,d0        ; Which kind of real ROM?
  169.     cmp.l    #$11144ef9,d0
  170.     beq    2$
  171.     move.l    $00fc0004,a0
  172.     bra 3$
  173. 2$
  174.     move.l    $00f80004,a0        ; We have a 512K ROM
  175. 3$
  176.     reset
  177.     reset
  178.     jmp (a0)
  179.     nop
  180.     nop
  181.     nop
  182.     nop
  183. CleanBootEnd:
  184.  
  185. ;======================================================================
  186. ;
  187. ;    Pointers to the smart reset routine, and the length of this
  188. ;    routine.  Currently I'm using the CleanBoot routine, which will
  189. ;    get the machine back to the ROM OS.  A better smart reset routine
  190. ;    could boot back to the virtual ROM rather than the physcial ROM.
  191. ;
  192. ;======================================================================
  193.  
  194. _ResetCode:
  195.     dc.l    _CleanBoot
  196. _ResetCodeSize:
  197.     dc.l    CleanBootEnd-_CleanBoot+1
  198.  
  199.     end
  200.