home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 553.lha / ZKick_v3.01 / romtag.asm < prev    next >
Assembly Source File  |  1991-09-09  |  11KB  |  572 lines

  1. *
  2. *    ZKick V3.01 -- Copyright (C) 1991 by Daniel Zenchelsky
  3. *
  4. *        This program may be freely copied, as long as all copyright
  5. *        notices are left intact and unchanged.
  6. *
  7.  
  8.  
  9.    SECTION   code
  10.  
  11.    NOLIST
  12.    INCLUDE "exec/types.i"
  13.    INCLUDE "exec/initializers.i"
  14.    INCLUDE "exec/libraries.i"
  15.    INCLUDE "exec/lists.i"
  16.    INCLUDE "exec/alerts.i"
  17.    INCLUDE "exec/resident.i"
  18.    INCLUDE "exec/memory.i"
  19.    INCLUDE "exec/tasks.i"
  20.    INCLUDE "exec/execbase.i"
  21.    INCLUDE "libraries/expansion.i"
  22.  
  23.    INCLUDE "zkick.i"
  24.    INCLUDE "mmu.i"
  25.  
  26.    LIST
  27.  
  28.    XDEF   Reboot
  29.    XDEF   _MakeRomTag
  30.    XDEF   _config
  31.    XDEF   _connum
  32.    XDEF   _memory
  33.    XDEF   _memnum
  34.    XDEF   _Survive
  35.    XDEF   _MMU
  36.  
  37.    XDEF    _NOMMU
  38.    XDEF   _NOCHECKSUM
  39.    XDEF   _NORESET
  40.    XDEF   _DEBUG
  41.    XDEF   _PRINT
  42.    XDEF    _LOADC0
  43.    XDEF    _V175
  44.  
  45.    XDEF   _StartKick
  46.  
  47.    ;------ These don't have to be external, but it helps some
  48.    ;------ debuggers to have them globally visible
  49.    XDEF   modName
  50.    XDEF   MemName
  51.    XDEF   _InitRoutine
  52.    XDEF   initDDescrip
  53.    XDEF   ABSEXECBASE
  54.    XDEF   SaveMem
  55.    XDEF   KickMem
  56.    XDEF   KickTag
  57.    XDEF   expansionname
  58.    XDEF   ExpansionBase
  59.    XDEF   ConfigCopy
  60.    XDEF   AddMem
  61.    XDEF   EndTag
  62.    XDEF    CheckSum
  63.  
  64.    XREF   _LVOSumKickData
  65.  
  66.    XREF   _LVOOpenLibrary
  67.    XREF   _LVOCloseLibrary
  68.    XREF   _LVOAddConfigDev
  69.    XREF   _LVOAllocConfigDev
  70.    XREF   _LVOCopyMem
  71.    XREF   _LVOAddMemList
  72.    XREF   _LVOSetFunction
  73.    XREF   _LVOSuperState
  74.    XREF   _LVOSupervisor
  75.    XREF   _LVODisable
  76.  
  77. ;
  78. ; Offsets from ExecBase
  79. ;
  80.  
  81. *KickMemPtr    EQU    $222
  82. *KickTagPtr    EQU    $226
  83. *KickCheckSum    EQU    $22a
  84. *WarmCapture    EQU    50
  85. *CoolCapture    EQU    46
  86. *ColdCapture    EQU    42
  87. ExecVersion    EQU    $14
  88.  
  89. ROMVersion    EQU    $FC0010
  90.  
  91. VERSION:    EQU    3
  92. REVISION:    EQU    01
  93.  
  94.  
  95. _MakeRomTag:
  96.     move.l ABSEXECBASE,a6
  97. ;
  98. ; Set up KickMemPtr
  99. ;
  100.     lea.l KickMem+14,a0
  101.     move.w #1,(a0)+            ; Number of Entries = 1
  102.     lea.l SaveMem,a1
  103.     move.l a1,(a0)+            ; Allocation Start
  104.     lea.l EndTag-SaveMem,a1        ; Allocation Length
  105.     move.l a1,(a0)+
  106.     lea.l KickMem,a0
  107.  
  108.     move.l KickMemPtr(a6),(a0)    ; old pointer in ln_Succ
  109.  
  110.     move.l a0,KickMemPtr(a6)
  111.     
  112. ;
  113. ; Set up KickTagPtr
  114. ;
  115.     lea KickTag,a0
  116.  
  117.     move.l KickTagPtr(a6),4(a0)    ; Old pointer at the end of the table
  118.     beq.s .nomore
  119.  
  120.     bset.b #7,4(a0)            ; Bit 31 = Extend table
  121.  
  122. .nomore:
  123.     move.l a0,KickTagPtr(a6)
  124.  
  125. ;
  126. ; Calculate checksum
  127. ;
  128.  
  129.     jsr _LVOSumKickData(a6)
  130.     move.l d0,KickCheckSum(a6)
  131. ;
  132. ; Setup reboot code
  133. ;
  134.     jsr SetVectors
  135.     rts
  136.  
  137. ;-----------------------------------------------------------------------
  138. ; From here on is protected from erasure during reboot
  139. ;-----------------------------------------------------------------------
  140.  
  141. SaveMem:
  142.  
  143. KickMem:
  144.     DC.L 0,0,0,0,0,0
  145.  
  146. KickTag:
  147.     DC.L    initDDescrip
  148.     DC.L    $0
  149.  
  150. _StartKick:    DC.L $00000000
  151. OldAddMemList:    DC.L    $00000000
  152. _Survive:        DC.L    $00000000
  153. _MMU:        DC.L    $00000000
  154. _NOMMU:        DC.L $00000000
  155. _NOCHECKSUM:    DC.L $00000000
  156. _NORESET:        DC.L    $00000000
  157. _DEBUG:        DC.L $00000000
  158. _PRINT:        DC.L $00000000
  159. _LOADC0:        DC.L    $00000000
  160. _V175:        DC.L $00000000
  161.  
  162. ;
  163. ; --- ColdReboot()
  164. ;
  165.  
  166.         XREF    _LVOSupervisor
  167.  
  168. MAGIC_ROMEND        EQU $01000000   ;End of Kickstart ROM
  169. MAGIC_SIZEOFFSET    EQU -$14        ;Offset from end of ROM to Kickstart size
  170. V36_EXEC        EQU 36        ;Exec with the ColdReboot() function
  171. TEMP_ColdReboot     EQU -726        ;Offset of the V36 ColdReboot function
  172.  
  173.  
  174. _ColdReboot:    move.l    ABSEXECBASE,a6
  175.         cmp.w    #V36_EXEC,LIB_VERSION(a6)
  176.         blt.s    old_exec
  177.         jmp    TEMP_ColdReboot(a6)     ;Let Exec do it...
  178.         ;NOTE: Control flow never returns to here
  179.  
  180.  
  181. ;---- manually reset the Amiga ---------------------------------------------
  182. old_exec:    lea.l    GoAway(pc),a5           ;address of code to execute
  183.         jsr    _LVOSupervisor(a6)      ;trap to code at (a5)...
  184.         ;NOTE: Control flow never returns to here
  185.  
  186.  
  187. ;-------------- MagicResetCode ---------DO NOT CHANGE-----------------------
  188.         CNOP    0,4            ;IMPORTANT! Longword align!
  189. GoAway:     lea.l    MAGIC_ROMEND,a0     ;(end of ROM)
  190.         sub.l    MAGIC_SIZEOFFSET(a0),a0 ;(end of ROM)-(ROM size)=PC
  191.         move.l    4(a0),a0                ;Get Initial Program Counter
  192.         subq.l    #2,a0            ;now points to second RESET
  193.         reset                ;first RESET instruction
  194.         jmp    (a0)                    ;CPU Prefetch executes this
  195.         ;NOTE: the RESET and JMP instructions must share a longword!
  196. ;---------------------------------------DO NOT CHANGE-----------------------
  197.  
  198. ;
  199. ; Set up the reboot routines
  200. ;
  201.  
  202. SetVectors:
  203.  
  204.  
  205.     PUTMSG <'SetVectors'>
  206.  
  207.     tst.l _LOADC0
  208.     beq.s 1$
  209.     move.l #0,MaxExtMem(a6)
  210.     
  211. 1$:    lea.l ColdRoutine,a0
  212.     move.l a0,ColdCapture(a6)
  213.  
  214.     lea.l CoolRoutine,a0
  215.     move.l a0,CoolCapture(a6)
  216.  
  217. ; Recalculate checksum
  218.  
  219.     lea $22(a6),a0
  220.     moveq #$16,d0
  221.     moveq #0,d1
  222. sumloop:
  223.     add.w (a0)+,d1
  224.     dbra d0,sumloop
  225.     not.w d1
  226.     move.w d1,$52(a6)
  227.  
  228.     rts
  229.  
  230. tmp:    dc.l 0
  231.  
  232. ColdRoutine:
  233.     
  234.     NS_PUTMSG <'ColdRoutine'>
  235.  
  236.     move.l a5,tmp                ; We can't test ExecBase because 1.3
  237.                             ; will use the 2.0 ExecBase.
  238.     and.w #$FFF0,tmp            ; So we look at the return address
  239.     cmp.w #$00F0,tmp            ; to see if we are running from ROM.
  240.                             ; <-- Should check for $F80000-$FFFFFF
  241.     bne DoneCold
  242.  
  243.     NS_PUTMSG <'Version 1.2/1.3 ColdCapture'>
  244.  
  245.     cmp.l #-$1,d6            ; Test to see if there is a delayed GURU
  246.     beq NoGuru            ; If not, skip this.
  247.     move.l #$48454C50,0        ; move "HELP" to location 0
  248.                         ; KickStart 2.0 will take care of the rest
  249.  
  250. NoGuru:
  251.  
  252.     cmp.l #$B7FC0004,$1e(a5)    ; Verify that this is really 1.2/1.3
  253.     bne.s skipfix
  254.     move.l $3E(A6),A3        ; Skip version and >512k chip mem
  255.     jmp $1e(a5)            ; checks
  256.  
  257. skipfix:
  258.  
  259.     NS_PUTMSG <'skipfix'>
  260.  
  261. DoneCold:
  262.     jmp (a5)
  263.  
  264. CoolRoutine:
  265.  
  266.     PUTMSG <'CoolRoutine'>
  267.  
  268.     movem.l a0-a6/d0-d7,-(SP)
  269.  
  270.     move.l ABSEXECBASE,a6            
  271.  
  272.     move.w ROMVersion,a0        ; If we're running under 2.0
  273.     cmp.w ExecVersion(a6),a0        ; skip this.
  274.     bne.s DoneCool
  275.  
  276.     PUTMSG <'Version 1.2/1.3 CoolCapture'>
  277.     
  278.     movea.l a6,a1            ; Keep exec 1.2/1.3 from stomping
  279.     lea.l NewAddMemList,a0    ; on the first few bytes
  280.     move.l a0,d0            ; of kickstart memory.
  281.     lea.l _LVOAddMemList,a0
  282.     jsr _LVOSetFunction(a6)
  283.     move.l d0,OldAddMemList
  284.  
  285. DoneCool:
  286.     movem.l (SP)+,a0-a6/d0-d7
  287.     rts
  288.  
  289. NewAddMemList:
  290.  
  291.     PUTMSG <'NewAddMemList'>
  292.  
  293.     rts
  294.  
  295. ;-----------------------------------------------------------------------
  296. ; A romtag structure.  Both "exec" and "ramlib" look for
  297. ; this structure to discover magic constants about you
  298. ; (such as where to start running you from...).
  299. ;-----------------------------------------------------------------------
  300.  
  301.    ; Most people will not need a priority and should leave it at zero.
  302.    ; the RT_PRI field is used for _configuring the roms.  Use "mods" from
  303.    ; wack to look at the other romtags in the system
  304.  
  305. MYPRI   EQU   107     
  306.  
  307. initDDescrip:
  308.                ;STRUCTURE RT,0
  309.      DC.W    RTC_MATCHWORD      ; UWORD RT_MATCHWORD
  310.      DC.L    initDDescrip       ; APTR  RT_MATCHTAG
  311.      DC.L    EndTag             ; APTR  RT_ENDSKIP
  312.      DC.B    RTF_COLDSTART      ; UBYTE RT_FLAGS
  313.      DC.B    VERSION            ; UBYTE RT_VERSION
  314.      DC.B    NT_UNKNOWN         ; UBYTE RT_TYPE
  315.      DC.B    MYPRI              ; BYTE  RT_PRI
  316.      DC.L    modName            ; APTR  RT_NAME
  317.      DC.L    idString           ; APTR  RT_IDSTRING
  318.      DC.L    _InitRoutine       ; APTR  RT_INIT
  319.  
  320.  
  321.    ; this is the name that the module will have
  322. modName:    DC.B   'zkick.romtag',0
  323.  
  324. idString:   dc.b   'zkick.romtag 3.01 (7/10/91)',13,10,0
  325.  
  326. MemName:    dc.b  'zkick memory',0
  327.  
  328. expansionname:    dc.b  'expansion.library',0
  329.  
  330.     CNOP 0,4
  331.  
  332. ABSEXECBASE    EQU     $00000004
  333. ExpansionBase:    DC.L     $00000000
  334. ConfigCopy:    DC.L     $00000000
  335.  
  336.  
  337. _InitRoutine:
  338.  
  339.     movem.l d0-d7/a0-a6,-(a7)
  340.  
  341.     PUTMSG <'InitRoutine'>
  342.  
  343.     move.l ABSEXECBASE,a6        ; If we're running under 1.2/1.3
  344.     move.l ROMVersion,a0        ; we wan't to start KickStart
  345.     cmp.l ExecVersion(a6),a0        ; from _StartKick
  346.     bne okversion
  347.  
  348.     tst.l    _NOCHECKSUM
  349.     bne.s    skipsum
  350.  
  351.     move.l    _StartKick,a0        ; Checksum KickStart image
  352.     move.l    #$80000,d1        ; at _StartKick
  353.     jsr     CheckSum
  354.     tst.l    d0
  355.     bne        panic
  356.  
  357.     PUTMSG <'KickStart Checksum valid'>
  358.  
  359. skipsum:
  360.                             ; Let's be doubly cautious:
  361.     jsr     _LVOSuperState(a6)
  362.     move.l    _StartKick,a0        ; Verify that there's a
  363.                             ; KickStart image at
  364.     cmp.w    #$4ef9,2(a0)        ; _StartKick
  365.     bne        panic
  366.  
  367.     PUTMSG <'KickStart checks out OK'>
  368.  
  369.     tst.l _NOMMU
  370.     bne.s 1$
  371.  
  372.     move.l    ABSEXECBASE,a6        ; If there is an MMU
  373.     jsr        _LVODisable(a6)    ; disable it before
  374.     tst.l     _MMU                ; starting KickStart
  375.     beq        1$
  376.     move.l    #0,a0
  377.     jsr        SetTC
  378.  
  379. 1$:    
  380.     PUTMSG <'Jumping to KickStart'>
  381.  
  382.     move.l _StartKick,A0
  383.     move.l 4(A0),A0
  384.     jmp    (A0)                    ; Start KickStart
  385.  
  386. panic:                        ; Uh oh, doesn't look like
  387.                             ; KickStart at _StartKick
  388.     PUTMSG <'panic!'>
  389.  
  390.     clr.l    ColdCapture(a6)    
  391.     clr.l    CoolCapture(a6)
  392.     clr.l    WarmCapture(a6)    ; Clear vectors and reboot
  393.     clr.l    KickTagPtr(a6)
  394.     clr.l    KickMemPtr(a6)
  395.  
  396.     jmp Reboot
  397.     
  398. okversion:
  399.  
  400.     PUTMSG <'okversion'>
  401.  
  402.     tst.l _Survive            ; Do we want to survive?
  403.     beq.s 2$
  404.     jsr SetVectors            ; Set up Capture vectors
  405.                         ; for reboot survival
  406.  
  407. 2$:    lea.l expansionname,A1
  408.     clr.l D0    
  409.     jsr _LVOOpenLibrary(a6)        ; Open expansion.library
  410.     move.l D0,ExpansionBase
  411.     tst.l D0
  412.     bne.s 1$
  413.     jmp exit
  414.  
  415. 1$:
  416.     lea.l _config,a2
  417.     move.l _connum,a3
  418.  
  419.     PUTMSG <'Adding expansion devices'>
  420.  
  421. loop:    
  422.     cmp.l #0,a3
  423.     beq close
  424.  
  425.     move.l ExpansionBase,a6        ; For each configdev structure we
  426.     jsr _LVOAllocConfigDev(a6)    ; saved, allocate a fresh configdev
  427.     move.l D0,ConfigCopy        ; structure.
  428.     tst.l D0
  429.     bne.s 2$
  430.     jmp close
  431.  
  432. 2$:    
  433.     move.l a2,A0
  434.     move.l ConfigCopy,A1        ; Copy the old configdev onto
  435.     move.l #end_config-_config,D0    ; the new one
  436.     move.l ABSEXECBASE,a6
  437.     jsr _LVOCopyMem(a6)
  438.  
  439.     move.l ConfigCopy,A0
  440.     move.l ExpansionBase,a6
  441.     jsr _LVOAddConfigDev(a6)        ; Add it to the configdev list
  442.  
  443.     PUTMSG <'Linked 1 ConfigDev'>
  444.  
  445.     subq.l #1,a3
  446.     add.l #end_config-_config,a2    ; Go get another configdev structure
  447.     jmp loop
  448.  
  449. close:
  450.     move.l ExpansionBase,A1
  451.     move.l ABSEXECBASE,a6        ; Close expansion.library
  452.     jsr _LVOCloseLibrary(a6)
  453.  
  454. AddMem:
  455.  
  456.  
  457.     PUTMSG <'Adding Memory'>
  458.  
  459.     lea _memory,a2            ; Do the same thing
  460.     move.l _memnum,a3        ; for the memory lists
  461.  
  462. AddMemLoop:
  463.     cmp.l #0,a3
  464.     beq.s exit
  465.  
  466.     move.l (a2),a0
  467.     addq.l #4,a2
  468.     move.l (a2),d0
  469.     addq.l #4,a2
  470.     move.l #MEMF_FAST+MEMF_PUBLIC,d1
  471.     clr.l d2
  472.     lea.l MemName,a1
  473.     move.l ABSEXECBASE,a6
  474.     jsr _LVOAddMemList(a6)
  475.     
  476.     PUTMSG <'Linked 1 mem board'>
  477.     
  478.     subq.l #1,a3
  479.     jmp AddMemLoop
  480.  
  481. exit:
  482.     movem.l (a7)+,d0-d7/a0-a6
  483.     rts
  484.  
  485. CheckSum:
  486.  
  487.     PUTMSG <'CheckSum'>
  488.  
  489.     lsr.l    #2,d1
  490.     subq.l    #1,d1
  491.     moveq    #0,d0
  492.  
  493. 1$:    add.l    (a0)+,d0
  494.     bcc.s    2$
  495.     addq.l    #1,d0
  496.  
  497. 2$:    dbra    d1,1$
  498.     sub.l    #$10000,d1
  499.     bpl.s    1$
  500.     addq.l    #1,d0
  501.     rts
  502.  
  503. ;======================================================================
  504. ;
  505. ;    This function sets the MMU TC register.  It assumes a 68020 
  506. ;    system with MMU, or a 68030 based system (eg, test for MMU before
  507. ;    you call this, or you wind up in The Guru Zone).  
  508. ;
  509. ;    SetTC(ULONG)
  510. ;        a0
  511. ;======================================================================
  512.  
  513. SetTC:
  514.  
  515.     PUTMSG <'SetTC'>
  516.  
  517.     move.l    4,a6                ; Get ExecBase
  518.     move.l    a5,-(sp)
  519.     lea.l    1$,a5            ; Get the start of the supervisor code
  520.      CALLSYS    Supervisor
  521.     move.l    (sp)+,a5
  522.     rts
  523. 1$
  524.     _PMOVE    a0,tc            ; Just set the TC register
  525.  
  526.             ; Was _PMOVE (a0),tc  <-- Looked wrong!
  527.     rte
  528.  
  529. Reboot:
  530.  
  531.     PUTMSG <'Reboot'>
  532.  
  533.     tst.l    _NOMMU
  534.     bne.s    nommu
  535.  
  536.     PUTMSG <'Disabling MMU'>
  537.  
  538.     move.l    ABSEXECBASE,a6        ; If there is an MMU,
  539.     jsr        _LVODisable(a6)    ; disable it before
  540.     tst.l    _MMU                ; rebooting.
  541.     beq        nommu
  542.     move.l    #0,a0
  543.     jsr        SetTC
  544. nommu:
  545.     jmp        _ColdReboot
  546.  
  547. EndCode:
  548.  
  549. *********
  550.  
  551.     CNOP 0,4    ; LongWord Align (For CopyMem)
  552.  
  553. _connum:    
  554.     DS.L 1
  555.  
  556. _config:
  557.     DS.L 17
  558. end_config:
  559.     DS.L 17*7
  560.  
  561. _memnum:    
  562.     DS.L 1
  563.  
  564. _memory:
  565.     DS.L 2
  566. end_memory:
  567.     DS.L 2*7
  568.  
  569. EndTag:
  570.  
  571.    END
  572.