home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 570.lha / LoadKickC0_v1.0 / src / StartKick.asm < prev   
Encoding:
Assembly Source File  |  1991-09-13  |  4.0 KB  |  209 lines

  1. ;*************************************************************************
  2. ;*                                                                       *
  3. ;* LoadKickC0 V1.0 -- Copyright 1991 by Matthias Scheler                 *
  4. ;*                                                                       *
  5. ;*      This program may be freely copied, as long as all copyright      *
  6. ;*      notices are left intact and unchanged.                           *
  7. ;*                                                                       *
  8. ;*************************************************************************
  9.  
  10.         CSECT text,0
  11.  
  12.         INCLUDE "exec/types.i"
  13.         INCLUDE "exec/execbase.i"
  14.         INCLUDE "exec/resident.i"
  15.  
  16. _AbsExecBase    EQU 4
  17.  
  18. PatchOffset    EQU $7FF00
  19.  
  20.         XREF _SysBase
  21.         XREF _LVODisable
  22.         XREF _LVOSuperState
  23.        
  24.         XREF rtable
  25.  
  26.         XDEF _StartKick
  27. _StartKick:    movem.l 4(sp),a2/a3
  28.  
  29. ; relocate kickstart image
  30.  
  31.         move.l a3,d0        ; calculate offset for relocation
  32.         sub.l #$200000,d0
  33.         lea rtable(pc),a0
  34. RelocKickImage:    move.l (a0)+,d1
  35.         beq.s PatchKickImage
  36.         add.l d0,0(a2,d1.l)
  37.         bra.s RelocKickImage
  38.  
  39. ; patch kickstart memory configuration
  40.  
  41. PatchKickImage:    move.l a3,d0
  42.         swap d0
  43.         addq.l #$08,d0        ; ($C80000 - $C00000) / $10000 = $08
  44.         move.w d0,$2B4(a2)
  45.         move.w d0,$2C8(a2)
  46.  
  47. ; relocate tag for patch
  48.  
  49.         move.l a3,a1
  50.         add.l #PatchOffset,a1
  51.         
  52.         lea ResetTag(pc),a0
  53.         move.l a1,RT_MATCHTAG(a0)
  54.         lea RT_SIZE(a1),a5
  55.         move.l a5,RT_ENDSKIP(a0)
  56.         move.l a5,RT_INIT(a0)
  57.         lea ResetName-ResetTag(a1),a5
  58.         move.l a5,RT_NAME(a0)
  59.  
  60. ; copy patch into kickstart image
  61.  
  62.         move.l a2,a1
  63.         add.l #PatchOffset,a1
  64.         move.w #(ResetEnd-ResetTag)/2-1,d0
  65. PatchResetCode:    move.w (a0)+,(a1)+
  66.         dbf d0,PatchResetCode
  67.  
  68. ; prepare reboot
  69.  
  70.         move.l a2,KickSource
  71.         move.l a3,KickTarget
  72.  
  73.         move.l _SysBase(a4),a6
  74.         lea StartKick(pc),a0
  75.         bsr SetCold
  76.  
  77.         jsr _LVODisable(a6)     ; interrupts off
  78.         jsr _LVOSuperState(a6)    ; call copy code in supervisor mode
  79.  
  80.         bra Reboot
  81.  
  82. ; init and save some exec pointers
  83.  
  84. StartKick:    move.l KickSource(pc),a0
  85.         move.l KickTarget(pc),a1
  86.         lea 2(a1),a2
  87.  
  88.         move.w LIB_NEGSIZE(a6),d2
  89.         movem.l KickMemPtr(a6),d3-d5
  90.  
  91. ; copy kickstart image and recalculate checksum
  92.  
  93.         moveq #8,d0        ; clear old checksum
  94.         swap d0
  95.         clr.l -24(a0,d0.l)
  96.  
  97.         moveq #2,d0        ; 131072 * 4 = 524288
  98.         swap d0
  99.         moveq #0,d1
  100. CopyKickImage:    add.l (a0),d1
  101.         bcc.s NoOverFlow1
  102.         addq.l #1,d1
  103. NoOverFlow1:    move.l (a0)+,(a1)+
  104.         subq.l #1,d0
  105.         bne.s CopyKickImage
  106.  
  107.         not.l d1
  108.         move.l d1,-24(a1)
  109.  
  110. ; create a faked execbase, so that a hard disk driver gets a chance to survive
  111.  
  112.         lea 0(a1,d2.w),a6
  113.         move.l a6,_AbsExecBase.w
  114.  
  115.         move.l #$00220002,SoftVer(a6)
  116.         move.l a6,d0
  117.         not.l d0
  118.         move.l d0,ChkBase(a6)
  119.         clr.l ColdCapture(a6)
  120.         clr.l CoolCapture(a6)
  121.         clr.l WarmCapture(a6)            
  122.  
  123.         lea SoftVer(a6),a0
  124.         moveq #23,d0
  125.         moveq #0,d1
  126. SumLoop1:    add.w (a0)+,d1
  127.         dbf d0,SumLoop1
  128.         not.w d1
  129.         move.w d1,(a0)
  130.  
  131.         movem.l d3-d5,KickMemPtr(a6)
  132.  
  133. ; start OS 2.0 first time
  134.  
  135.         jmp (a2)
  136.  
  137. KickSource:    dc.l 0
  138. KickTarget:    dc.l 0
  139.  
  140. ; reset tag
  141.  
  142. ResetTag:    dc.w RTC_MATCHWORD
  143.         dc.l 0
  144.         dc.l 0
  145.         dc.b RTF_COLDSTART
  146.         dc.b 37
  147.         dc.b 0
  148.         dc.b 109
  149.         dc.l 0
  150.         dc.l 0
  151.         dc.l 0
  152.  
  153. ; set cold capture when OS 2.0 is running
  154.  
  155.         lea RestartKick(pc),a0
  156. SetCold:    move.l a0,ColdCapture(a6)
  157. SumExec:    lea SoftVer(a6),a0
  158.         moveq #23,d0
  159.         moveq #0,d1
  160. SumLoop2:    add.w (a0)+,d1
  161.         dbf d0,SumLoop2
  162.         not.w d1
  163.         move.w d1,(a0)
  164.         rts
  165.  
  166. ; restart kickstart 2.0
  167.  
  168. RestartKick:    lea SoftVer(a6),a0
  169.         moveq #23,d0
  170.         moveq #0,d1
  171. SumLoop3:    add.w (a0)+,d1
  172.         dbf d0,SumLoop3
  173.         not.w d1
  174.         move.w d1,(a0)
  175.  
  176. ; check kickstart
  177.  
  178.         lea ResetTag(pc),a0
  179.         sub.l #PatchOffset,a0
  180.         lea 2(a0),a1
  181.  
  182.         moveq #2,d0        ; 131072 * 4 = 524288
  183.         swap d0
  184.         moveq #0,d1
  185. CheckKickImage:    add.l (a0)+,d1
  186.         bcc.s NoOverFlow3
  187.         addq.l #1,d1
  188. NoOverFlow3:    subq.l #1,d0
  189.         bne.s CheckKickImage
  190.  
  191.         addq.l #1,d1
  192.         bne.s ColdReboot    ; kickstart is corrupt
  193.  
  194.         jmp (a1)        ; jump into OS 2.0
  195.  
  196. ; reboot
  197.  
  198. ColdReboot:    clr.l ChkBase(a6)    ; force complete reset
  199. Reboot:        lea $01000000,a0    ; entry point for rom kickstart
  200.         sub.l -20(a0),a0
  201.         move.l 4(a0),a0
  202.         jmp -2(a0)        ; jump on reset instruction
  203.  
  204. ResetName:    dc.b "LoadKickC0",0
  205.         ds.w 0
  206.  
  207. ResetEnd:
  208.         END
  209.