home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d6xx / d619 / set040.lha / Set040 / Source / set040.s < prev   
Encoding:
Text File  |  1992-03-12  |  83.2 KB  |  1,729 lines

  1.                 INCPATH "includes:"
  2.                 MC68040
  3.                 super
  4.                 newsyntax
  5.                 exeobj
  6.                 strict
  7.                 objfile "Set040"
  8.                 maclib  "includes:commonmac/allmacs.mac"
  9.                 include "includes:commonmac/macs.i"
  10.                 
  11.                 SECTION main,CODE                       ;needed for macros
  12.      
  13. ;**************************************
  14. ;The beginning and end of the program.
  15. ;First we do the startup stuff, parse
  16. ;the cli command string, get the output
  17. ;file handle, branch to the main code
  18. ;on return free it all up and exit 
  19. ;**************************************                
  20.                 
  21.                 pushregs                                ;save non scratch
  22.                 ParseCL                                 ;parse the command line
  23.                 FindLibs                                ;get the libraries
  24.                 CALLDOS   Output                        ;get output handle
  25.                 move.l    d0,(_stdout)                  ;save it
  26.                 bsr.b     main                          ;go do the stuff
  27.                 FreeCL                                  ;free cli args
  28.                 popregs                                 ;pop the regs
  29.                 rts                                     ;bye bye!!
  30.                 
  31. ;************************************************
  32. ;We check for V2.04, we cannot allow V36 because 
  33. ;this program calls some V37 exec calls.  Then we 
  34. ;check if we are using a 68040 CPU. 
  35. ;************************************************               
  36.                 
  37. main            movea.l   (4).w,a6                      ;get exec
  38.                 cmpi.w    #37,(LIB_VERSION,a6)          ;check if vers is 2.0x
  39.                 blt.w     check4kick                    ;if not check kickrom
  40.                 move.w    (AttnFlags,a6),d0
  41.                 btst      #AFB_68040,d0                 ;check for 68040
  42.                 bne.b     found040                      ;skip to 040 stuff
  43.                 
  44.                 
  45. ;************************************************
  46. ;If a 68030 is found then the only switch allowed
  47. ;is the -s for switch to 68040, we check for this
  48. ;and error if any other switch or none is found.
  49. ;************************************************                
  50.  
  51.                 btst      #AFB_68030,d0                 ;at least 68030 ?
  52.                 beq       cpuerr                        ;error if not
  53.                 tst.l     (_argv)                       ;do we have args
  54.                 beq.w     cpuerr                        ;error if not
  55.                 movea.l   (_argv),a0                    ;get the arg array
  56.                 movea.l   (a0),a0                       ;get the first arg
  57.                 move.b    (a0)+,d0                      ;get first byte
  58.                 cmpi.b    #'-',d0                       ;is it a switch
  59.                 bne.w     cpuerr                        ;error if not
  60.                 move.b    (a0)+,d0                      ;get next byte
  61.                 bset      #5,d0
  62.                 cmpi.b    #'s',d0                       ;is it switch cpu's
  63.                 bne.w     cpuerr                        ;error if not
  64.                 bra.w     doswitch                      ;go switch 030-040
  65.                 
  66. ;********************************
  67. ;Check for CLI args, as we only 
  68. ;permit one multiple switch we do 
  69. ;not bother checking for any more
  70. ;********************************
  71.                 
  72. found040        tst.l     (_argv)                       ;check for CLI args
  73.                 beq.w      noargs                       ;skip if none
  74.                 movea.l   (_argv),a1                    ;else get ptr
  75.                 movea.l   (a1)+,a0                      ;get first arg
  76.                 move.b    (a0)+,d0                      ;get byte
  77.                 cmpi.b    #'?',d0                       ;is it usage
  78.                 beq.w     useprint                      ;go if so
  79.                 cmpi.b    #'-',d0                       ;else a switch ?
  80.                 bne.w     noargs                        ;not valid if not
  81.                 move.b    (a0)+,d0                      ;get next byte
  82.                 bset      #5,d0                         ;set lower case
  83.                 cmpi.b    #'k',d0                       ;is it kickrom
  84.                 bne.b     notkickrom                    ;skip if not
  85.                 move.l    (a1)+,(kickname)              ;else get the filename
  86.                 bra.w     instkick                      ;and do it
  87. notkickrom      cmpi.b    #'f',d0
  88.                 bne.w     notinst
  89. argloop         move.b    (a0)+,d0
  90.                 cmpi.b    #' ',d0
  91.                 ble.w     instfast
  92.                 cmpi.b    #'z',d0                       ;is it allow zcaching
  93.                 bne.b     .notz
  94.                 not.b     (zcache)
  95.                 bra.b     argloop
  96. .notz           cmpi.b    #'w',d0                       ;is mother board space
  97.                 bne.b     .notw
  98.                 not.b     (mbspace)
  99.                 bra.b     argloop
  100. .notw           cmpi.b    #'d',d0                       ;is it data cache
  101.                 bne.b     .notd
  102.                 clr.w     (dcaches)
  103.                 move.l    #datoff,(datstr)              
  104.                 bra.b     argloop
  105. .notd           cmpi.b    #'i',d0                       ;is it ins cache
  106.                 bne.b     .noti
  107.                 clr.w     (icaches)
  108.                 move.l    #insoff,(insstr)
  109.                 bra.b     argloop
  110. .noti           cmpi.b    #'t',d0
  111.                 bne.b     .nott
  112.                 not.b     (scrtit)
  113.                 bra.b     argloop                
  114. .nott           cmpi.b    #'c',d0
  115.                 bne.b     .notc
  116.                 clr.b     (z3var1+3)
  117.                 clr.b     (z3var0+3)
  118.                 bra.w     argloop                
  119. .notc           cmpi.b    #'n',d0
  120.                 bne.w     argloop
  121.                 not.b     (noclick)
  122.                 bra.w     argloop                
  123. notinst         cmpi.b    #'r',d0                       ;is it remove
  124.                 beq.w     removefr                      ;do it if so
  125.                 cmpi.b    #'s',d0
  126.                 beq.w     doswitch
  127.                 cmpi.b    #'c',d0
  128.                 bne.b     noargs
  129.                 movea.l   a0,a2
  130. maniploop       move.b    (a2)+,d0
  131.                 cmpi.b    #' ',d0
  132.                 ble.b     noargs
  133.                 cmpi.b    #'I',d0
  134.                 beq.w     icacheon
  135.                 cmpi.b    #'i',d0
  136.                 beq.w     icacheoff
  137.                 cmpi.b    #'D',d0
  138.                 beq.w     dcacheon
  139.                 cmpi.b    #'d',d0
  140.                 beq.w     dcacheoff
  141.                 cmpi.b    #'B',d0
  142.                 beq.w     bcacheon
  143.                 cmpi.b    #'b',d0
  144.                 beq.w     bcacheoff
  145.                 cmpi.b    #'C',d0
  146.                 beq.w     con
  147.                 cmpi.b    #'c',d0
  148.                 beq.w     coff
  149.                 
  150. ;**********************************
  151. ;There were no parameters so we 
  152. ;will just display some info unless
  153. ;we find a CHIPROM setup, in which
  154. ;case we will go and change it
  155. ;to FASTROM.
  156. ;**********************************
  157.  
  158. noargs          lea       (credstr,pc),a0               ;our main credits string
  159.                 Printf                                  ;print it
  160.                 lea       (getregs,pc),a5               ;point to supervisor code
  161.                 CALLEXEC  Supervisor
  162.                 move.w    d0,(tcreg)
  163.                 move.l    d7,(vbreg)
  164.                 move.l    d5,(it0)                      ;save itt0 in a var 
  165.                 move.l    d6,(it1)                      ;save itt1 in a var 
  166.                 move.l    d3,(dt0)                      ;save dtt0 in a var 
  167.                 move.l    d4,(dt1)                      ;save dtt1 in a var 
  168.                 move.l    d1,(table1)                   ;save urp in  var
  169.                 move.l    d1,(urpreg)                   ;user root pointer
  170.                 move.l    a0,(srpreg)                   ;supervisor root pointer
  171.                 tst.w     d0
  172.                 bpl.b     .notchiprom
  173.                 tst.l     (8,a0)
  174.                 beq.b     .notchiprom
  175.                 movea.l   (8,a0),a1
  176.                 move.l    #$80008000,(dcaches)
  177.                 move.l    (fr_kickmem,a1),d3
  178.                 cmpi.l    #'KICK',(fr_id,a1)
  179.                 beq.w     dochipkick                
  180.                 
  181. .notchiprom     moveq     #0,d3                         ;clear a reg
  182.                 move.l    d3,d4                         ;and another
  183.                 
  184.                 tst.w     d0                            ;test bit 15 of tc reg
  185.                 beq.b     tcoff                         ;clear = MMU is off
  186.                 tst.l     d1                            ;test urp
  187.                 beq.b     putzeros                      ;clear = all tables clear
  188.                 movea.l   d1,a0                         ;get into address
  189.                 move.l    (a0),d0                       ;get table 2
  190.                 clr.b     d0                            ;clear the descriptor byte
  191.                 move.l    d0,d3                         ;save it
  192.                 lea       (testcode,pc),a5              ;see if MMU set-up is ours
  193.                 CALLEXEC  Supervisor
  194.                 tst.l     d0                            ;test result
  195.                 beq.b     isours
  196.                 lea       (ok1str,pc),a0
  197.                 cmpi.l    #'FAST',(fr_id,a4)
  198.                 beq.b     ourkick
  199.                 bmi.b     notours                       ;nope not ours
  200.  
  201. tcoff           clr.l     (table1)
  202.                 bra.b     putzeros
  203. isours          lea       (okstr,pc),a0                 ;else get ours string
  204. ourkick         Printf                                  ;print it
  205. notours         tst.l     d3                            ;test table 2 
  206.                 beq.b     putzero                       ;skip if null
  207.                 movea.l   d3,a0                         ;else get in add reg
  208.                 move.l    (a0),d0                       ;get table 3
  209.                 clr.b     d0                            ;extract address
  210.                 move.l    d0,d4                         ;replace d4
  211.  
  212. putzeros        move.l    d3,(table2)                   ;fill table 2 var
  213. putzero         move.l    d4,(table3)                   ;and table 3 var
  214.                 tst.l     d2                            ;test data cache
  215.                 bpl.b     printoff                      ;branch if off
  216.                 lea       (daton,pc),a0                 ;else get on string
  217.                 Printf                                  ;print it
  218.                 bra.b     skipoff                       ;skip off code
  219. printoff        lea       (datoff,pc),a0                ;get off code
  220.                 Printf                                  ;print it
  221. skipoff         tst.w     d2                            ;test ins cache
  222.                 bpl.b     printoff1                     ;branch if off
  223.                 lea       (inson,pc),a0                 ;else get on string
  224.                 Printf                                  ;print it
  225.                 bra.b     skipoff1                      ;skip off code
  226. printoff1       lea       (insoff,pc),a0                ;get off string
  227.                 Printf                                  ;print it
  228. skipoff1        lea       (infostr,pc),a0               ;get rest of info
  229.                 lea       (table1,pc),a1                ;data for string
  230.                 Printf                                  ;print it
  231.                 lea       (usage1,pc),a0                ;info on usage
  232.                 Printf                                  ;print it
  233.                 rts                                     ;we're outa here!!
  234.         
  235. ;***********************************************
  236. ;The cache manipulation area, all cache modes
  237. ;are handled here also copyback and writethrough
  238. ;for the data cache.
  239. ;bits to change in D0 and the Mask in D1
  240. ;***********************************************        
  241.         
  242. icacheon        moveq     #0,d0
  243.                 or.l      #CACRF_EnableI,d0
  244.                 move.l    d0,d1
  245.                 bra.b     docache
  246.                 
  247. icacheoff       moveq     #0,d0
  248.                 move.l    d0,d1
  249.                 or.l      #CACRF_EnableI,d1
  250.                 bra.b     docache
  251.  
  252. dcacheon        moveq     #0,d0
  253.                 or.l      #CACRF_EnableD,d0
  254.                 move.l    d0,d1
  255.                 bra.b     docache
  256.  
  257. dcacheoff       moveq     #0,d0
  258.                 move.l    d0,d1
  259.                 or.l      #CACRF_EnableD,d1
  260.                 bra.b     docache
  261.  
  262. bcacheon        moveq     #0,d0
  263.                 or.l      #CACRF_EnableI|CACRF_EnableD,d0
  264.                 move.l    d0,d1
  265.                 bra.b     docache
  266.  
  267. bcacheoff       moveq     #0,d0
  268.                 move.l    d0,d1
  269.                 or.l      #CACRF_EnableI|CACRF_EnableD,d1
  270.  
  271. docache         CALLEXEC  CacheControl
  272. dout            bra.w     maniploop
  273.                      
  274. con             lea       (getmttx,pc),a5
  275.                 CALLEXEC  Supervisor
  276.                 bset      #5,d1
  277.                 cmp.l     (z3var1,pc),d1
  278.                 bne.w     testerr
  279.                 bset      #5,d0
  280.                 cmp.l     (z3var0,pc),d0
  281.                 bne.w     testerr
  282.                 bra.b     cout
  283.                 
  284. coff            lea       (getmttx,pc),a5
  285.                 CALLEXEC  Supervisor
  286.                 bclr      #5,d1
  287.                 cmpi.l    #$4fbc000,d1
  288.                 bne.w     testerr
  289.                 bclr      #5,d0
  290.                 cmpi.l    #$8f7c000,d0
  291.                 bne.w     testerr
  292. cout            lea       (setdttx,pc),a5
  293.                 CALLEXEC  Supervisor
  294.                 bra.b     dout
  295.                 
  296. ;************************************************************
  297. ;This function is the start of the kickrom code, it allocates
  298. ;all memory required in one big block in chip ram in the 
  299. ;highest aligned block possible.  The MMU set up remaps the 
  300. ;area to $F00000 so that the new kickstart will not see this 
  301. ;chip ram, making our set-up safe through the boot process.
  302. ;
  303. ;We allocate the required ram as high as possible by alloc-
  304. ;ating all of the largest block available, calculating the
  305. ;end address of this new block, subtracting the required 
  306. ;amount and then lowering this new address to the closest
  307. ;boundary required.  Once we have this new address we give
  308. ;back the allocated block and AllocAbs the new location.
  309. ;This is the reason for the Forbid, we cannot allow some
  310. ;other task to jump in ahead of us and take some ram in
  311. ;between our alloc, de-alloc and allocabs.
  312. ;************************************************************                           
  313.                            
  314. instkick        lea       (testcode,pc),a5              ;get registers
  315.                 CALLEXEC  Supervisor                    ;fetch it
  316.                 tst.l     d0
  317.                 bmi.w     mmuerr
  318. kickok          not.b     (kickflag)                    ;set the flag
  319.                 CALLEXEC  Forbid                        ;multitasking off
  320.                 move.l    #MEMF_CHIP+MEMF_LARGEST,d1     
  321.                 CALLEXEC  AvailMem                      ;get largest chip
  322.                 cmp.l     #559592+fr_SIZEOF,d0          ;enough?
  323.                 blt.w     mem1err                       ;err if not
  324.                 move.l    d0,d2                         ;save a copy
  325.                 move.l    #MEMF_CHIP,d1                 ;want chip
  326.                 CALLEXEC  AllocMem                      ;allocate it
  327.                 tst.l     d0                            ;did we?
  328.                 beq.w     mem1err                       ;err if not
  329.                 move.l    d0,-(sp)                      ;save it
  330.                 add.l     d2,d0                         ;add largest
  331.                 subi.l    #559592+fr_SIZEOF,d0          ;sub amount required
  332.                 andi.l    #$ffffe000,d0                 ;alignment required
  333.                 move.l    d2,d1                         ;allocated size
  334.                 move.l    d0,d2                         ;new location
  335.                 movea.l   (sp)+,a1                      ;get allocated area
  336.                 move.l    d1,d0                         ;shift size for call
  337.                 CALLEXEC  FreeMem                       ;free the block
  338.                 movea.l   d2,a1                         ;get new location
  339.                 move.l    #559592+fr_SIZEOF,d0          ;size needed
  340.                 CALLEXEC  AllocAbs                      ;allocate it
  341.                 move.l    d0,(kickmem)                  ;save ptr
  342.                 CALLEXEC  Permit                        ;multitasking on
  343.                 move.l    (kickmem,pc),d0               ;get ptr
  344.                 beq.w     mem1err                       ;exit if error
  345.                 
  346. ;********************
  347. ;Clear this new block
  348. ;********************
  349.                 
  350.                 movea.l   d0,a0
  351.                 addi.l    #559592+fr_SIZEOF,d0          ;get the end address
  352. ..loop          clr.w     (a0)+                         ;clear the whole block
  353.                 cmpa.l    d0,a0                         ;with words, may not be
  354.                 blt.b     ..loop                        ;multiples of longs
  355.                 
  356. ;************************************
  357. ;Set up pointers to each table within 
  358. ;this new block for the kickstart and
  359. ;ATC entries.
  360. ;************************************
  361.                 
  362.                 move.l    (kickmem,pc),d0               ;get block start
  363.                 addi.l    #524288,d0                    ;add kickstart size
  364.                 move.l    d0,(table1)                   ;table 1
  365.                 move.l    #512,d1
  366.                 add.l     d1,d0                       
  367.                 move.l    d0,(table2)                   ;table 2
  368.                 add.l     d1,d0                        
  369.                 move.l    d0,(table3)                   ;table 3
  370.                 addi.l    #16384,d0
  371.                 move.l    d0,(table22)                  ;2nd table 2
  372.                 add.l     d1,d0
  373.                 move.l    d0,(table23)                  ;2nd table 3
  374.                 addi.l    #16384,d0                     ;get end of table2/3
  375.                 movea.l   d0,a0                         ;our struct
  376.                 lea       (fr_SIZEOF,a0),a0
  377.                 move.l    a0,(kickchip)
  378.                 lea       (crunmmu,pc),a1               ;get the chip code
  379.                 lea       (crunend,pc),a2               ;and its end 
  380. ..kmloop        move.w    (a1)+,(a0)+                   ;move it to chip
  381.                 cmpa.l    a2,a1                         ;until finished
  382.                 bne.b     ..kmloop
  383.                 bra.w     gotkick                                 
  384.                                   
  385. ;**************************
  386. ;OK so we have to install
  387. ;FASTROM, but first we make
  388. ;sure that the MMU isn't 
  389. ;already in use
  390. ;**************************                
  391.  
  392. instfast        lea       (getregs,pc),a5               ;get registers
  393.                 CALLEXEC  Supervisor                    ;fetch it
  394.                 tst.w     d0                            ;is it enabled
  395.                 bpl.b     mmuok                         ;no its disabled
  396.                 tst.l     d1                            ;test urp reg
  397.                 beq.b     .mmuerr                       ;exit (saves a reloc)
  398.                 lsr.l     #1,d1                         ;make sure its even
  399.                 add.l     d1,d1                         ;quicker than lsl.l
  400.                 movea.l   d1,a0
  401.                 movea.l   (8,a0),a0                     ;get third ptr
  402.                 cmpi.l    #'NICS',(fr_id,a0)            ;is it our fastrom
  403.                 beq.w     ourfastrom
  404. .mmuerr         bra.w     mmuerr
  405.                 
  406.                 
  407. ;************************************
  408. ;Now we allocate 512k of memory 
  409. ;aligned on a 8k boundary this is
  410. ;handled by my AllocAligned macro and
  411. ;it will clear the block if the 
  412. ;MEMF_CLEAR attribute is set. It will
  413. ;return an aligned block according to
  414. ;the value in D2
  415. ;************************************
  416.                 
  417. mmuok           move.l    #524288,d0                    ;512k size
  418.                 move.l    #MEMF_FAST,d1                 ;clear not required
  419.                 move.l    #8192,d2                      ;8k boundary
  420.                 AllocAligned                            ;would be no point
  421.                 tst.l     d0                            ;did we get it
  422.                 beq.w     mem1err                       ;exit if not
  423.                 move.l    d0,(kickmem)                  ;save the ptr
  424.                 
  425. ;***********************
  426. ;Now we allocate memory 
  427. ;for the first table
  428. ;***********************
  429.                 
  430.                 move.l    #512,d3                       ;we'll use this more
  431.                 move.l    d3,d0                         ;size of table1
  432.                 move.l    #MEMF_FAST+MEMF_CLEAR,d1      ;we want fast & clear
  433.                 move.l    d3,d2                         ;512 byte boundary
  434.                 AllocAligned                            ;get it
  435.                 tst.l     d0                            ;did we?
  436.                 beq.w     mem2err                       ;exit if not
  437.                 move.l    d0,(table1)                   ;save it
  438.                 
  439. ;**********************
  440. ;Now we allocate memory 
  441. ;for the second table
  442. ;**********************
  443.                 
  444.                 move.l    d3,d0                         ;size of table2
  445.                 move.l    #MEMF_FAST+MEMF_CLEAR,d1      ;we want fast & clear
  446.                 move.l    d3,d2                         ;512 byte boundary
  447.                 AllocAligned                            ;get it
  448.                 tst.l     d0                            ;did we?
  449.                 beq.w     mem3err                       ;exit if not
  450.                 move.l    d0,(table2)                   ;save it
  451.  
  452. ;**********************
  453. ;Now we allocate memory
  454. ;for the third table
  455. ;**********************
  456.                 
  457.                 move.l    #16384,d0                     ;size of table3
  458.                 move.l    #MEMF_FAST+MEMF_CLEAR,d1      ;fast and clear
  459.                 move.l    d3,d2                         ;512 byte boundary
  460.                 AllocAligned                            ;get it
  461.                 tst.l     d0                            ;did we?
  462.                 beq.w     mem4err                       ;exit if not
  463.                 move.l    d0,(table3)                   ;save it
  464.                 
  465. ;**************************
  466. ;Now we allocate memory for
  467. ;the second-second table
  468. ;**************************
  469.                 
  470.                 move.l    d3,d0                         ;size of table2-2
  471.                 move.l    #MEMF_FAST+MEMF_CLEAR,d1      ;we want fast & clear
  472.                 move.l    d3,d2                         ;512 byte boundary
  473.                 AllocAligned                            ;get it
  474.                 tst.l     d0                            ;did we?
  475.                 beq.w     mem5err                       ;exit if not
  476.                 move.l    d0,(table22)                  ;save it
  477.  
  478. ;**************************
  479. ;Now we allocate memory for
  480. ;the second-third table
  481. ;**************************
  482.                 
  483.                 move.l    #16384,d0                     ;size of table3
  484.                 move.l    #MEMF_FAST+MEMF_CLEAR,d1      ;fast and clear
  485.                 move.l    d3,d2                         ;512 byte boundary
  486.                 AllocAligned                            ;get it
  487.                 tst.l     d0                            ;did we?
  488.                 beq.w     mem6err                       ;exit if not
  489.                 move.l    d0,(table23)                  ;save it
  490.                 
  491. ;****************************************
  492. ;Now we allocate a structure to hold 
  493. ;all the old values so we can remove all
  494. ;this if asked to this will be linked on
  495. ;to an invalid entry in table 1 so we 
  496. ;can retreive it later if needed
  497. ;***************************************                
  498.                 
  499.                 move.l    #fr_SIZEOF,d0                 ;size of struct
  500.                 move.l    #MEMF_FAST,d1                 ;fast
  501.                 move.l    #8192,d2                      ;8k byte boundary
  502.                 AllocAligned                            ;get it
  503.                 tst.l     d0                            ;did we?
  504.                 beq.w     mem7err                       ;exit if not
  505. gotkick         movea.l   d0,a4
  506.                 move.l    d0,(fr_struct,a4)             ;save it
  507.                 move.l    (table23,pc),(fr_table5,a4)
  508.                 move.l    (table22,pc),(fr_table4,a4)
  509.                 move.l    (table3,pc),(fr_table3,a4)
  510.                 move.l    (table2,pc),(fr_table2,a4)
  511.                 move.l    (table1,pc),(fr_table1,a4)
  512.                 move.l    (kickmem,pc),(fr_kickmem,a4)
  513.                 move.l    #'NICS',(fr_id,a4)            ;our id
  514.                 
  515. ;******************************************************************
  516. ;If we're kickromming we check the supplied filename, if a floppy
  517. ;drive only we read the disk to see if its a valid kickstart disk,
  518. ;if no disk is found we bring up a requester and ask for one,
  519. ;else we check to see if its an old kickstart or superkickstart.
  520. ;If superkickstart we bring up a requester asking if they want 
  521. ;kick 1.3 or v2.0.  If the filename is a pointer to a file we
  522. ;load that file check if its a 256k kick or 512k kick and set it up
  523. ;******************************************************************                
  524.                 
  525.                 tst.b     (kickflag,pc)                 ;check the flag
  526.                 bpl.w     notkick                       ;skip if not kickrom
  527.                 
  528.                 move.l    #'KICK',(fr_id,a4)            ;change the id
  529.                 movea.l   (kickname,pc),a0              ;get the filename
  530.                 move.b    (a0)+,d0                      ;get first byte
  531.                 bset      #5,d0                         ;set for lower case
  532.                 cmpi.b    #'d',d0                       ;is it a d
  533.                 bne.w     notrack                       ;not trackdisk if not
  534.                 move.b    (a0)+,d0                      ;get next byte
  535.                 bset      #5,d0                         ;lower case
  536.                 cmpi.b    #'f',d0                       ;is it an f
  537.                 bne.w     notrack                       ;not trackdisk if not
  538.                 move.b    (a0)+,d0                      ;get next byte
  539.                 cmpi.b    #$30,d0                       ;is it in range
  540.                 blt.w     notrack                       ;skip if not
  541.                 cmpi.b    #$33,d0                       ;check upper range
  542.                 bgt.w     notrack                       ;skip if not
  543.                 move.b    (a0),d0                       ;get next byte
  544.                 cmpi.b    #':',d0                       ;is it a colon
  545.                 bne.w     notrack                       ;skip if not
  546.                 movea.l   (kickname,pc),a0              ;get the name
  547.                 tst.b     (4,a0)                        ;is it null terminated
  548.                 bne.w     notrack                       ;skip out if not
  549.                 InitDrive                               ;initialise the drive
  550.                 tst.l     d0                            ;test result
  551.                 ble.w     kickerr                       ;end if error
  552.                 move.l    d1,(ioreq)                    ;save the iorequest
  553. .testdisk       movea.l   (ioreq,pc),a1
  554.                 DiskIn
  555.                 tst.l     d0
  556.                 beq.b     .diskisin
  557.                 lea       (easyreq,pc),a0               ;else get easy struct
  558.                 move.l    #diskgads,(es_GadgetFormat,a0) ;change the gadgets
  559.                 move.l    #disktext,(es_TextFormat,a0)  ;and the the text
  560.                 move.l    #DISKINSERTED,(esidcmp)
  561.                 move.l    #kickname,d0                  ;data
  562.                 bsr.w     requester                     ;do the requester
  563.                 tst.l     d0                            ;check their answer
  564.                 beq.w     kickabort                     ;they want kick 2.0
  565.                 bra.b     .testdisk
  566. .diskisin       movea.l   (kickmem,pc),a0               ;get the buffer
  567.                 movea.l   (ioreq,pc),a1                 ;and the ioreq
  568.                 moveq     #0,d0                         ;offset 'bootblock'
  569.                 move.l    #TD_SECTOR*2,d1               ;two sectors
  570.                 ReadBlocks                              ;read it
  571.                 tst.l     d0                            ;check result
  572.                 bne.w     kick1err                      ;end if error
  573.                 movea.l   (kickmem,pc),a0               ;get buffer
  574.                 cmpi.l    #'KICK',(a0)                  ;check if kickstart
  575.                 bne.w     kick1err                      ;end if not
  576.                 cmpi.l    #'SUP0',(4,a0)                ;check super
  577.                 bne.b     notsuper                      ;skip if not
  578.                 lea       (easyreq,pc),a0               ;else get easy struct
  579.                 move.l    #eskickgads,(es_GadgetFormat,a0) ;change the gadgets
  580.                 move.l    #eskick,(es_TextFormat,a0)    ;and the the text
  581.                 moveq     #0,d0                         ;no data
  582.                 move.l    d0,(esidcmp)                  ;clear idcmp
  583.                 bsr.w     requester                     ;do the requester
  584.                 tst.l     d0                            ;check their answer
  585.                 beq.b     kick2.0                       ;they want kick 2.0
  586.                 move.l    #$400,d0                      ;offset for 1.3 super
  587.                 bra.b     loadkick                      ;and go load it
  588. kick2.0         move.l    #$40400,d0                    ;offset for 2.0 super
  589.                 move.l    #$80000,d1                    ;512k length
  590.                 movea.l   (kickmem,pc),a0               ;get buffer
  591.                 bra.b     load2.0                       ;and go load it
  592. notsuper        move.l    #$200,d0                      ;offset for 1.3 normal
  593. loadkick        movea.l   (kickmem,pc),a0               ;get buffer
  594.                 lea       ($40000,a0),a0                ;add 256k for 1.3
  595.                 move.l    #$40000,d1                    ;and 256k as length
  596. load2.0         movea.l   (ioreq,pc),a1                 ;get it requester
  597.                 ReadBlocks                              ;read the data
  598.                 tst.l     d0                            ;test result
  599.                 bne.w     kick1err                      ;end if error
  600.                 movea.l   (ioreq,pc),a1                 ;get ioreq
  601.                 ExitDrive                               ;un-init the drive
  602.                 bra.b     endtrack                      ;and skip file part
  603.                 
  604. notrack         movea.l   (kickname,pc),a1              ;get the name
  605.                 movea.l   (kickmem,pc),a0               ;and the buffer
  606.                 moveq     #4,d0                         ;want 4 bytes
  607.                 ReadFile                                ;read it
  608.                 movea.l   (kickname,pc),a1              ;get the name
  609.                 movea.l   (kickmem,pc),a0               ;and the buffer
  610.                 cmpi.w    #$1111,(a0)                   ;what type of kick
  611.                 beq.s     dosmall                       ;is a 256k kick
  612.                 cmpi.w    #$1114,(a0)                   ;else is it 512k
  613.                 bne.w     kickfilerr                    ;end if not kickstart
  614.                 move.l    #524288,d0                    ;else set size
  615.                 bra.b     dobig                         ;and go get it
  616.                 
  617. dosmall         clr.l     (a0)                          ;clear the kick id
  618.                 lea       ($40000,a0),a0                ;add 256k to 1.3 buffer
  619.                 move.l    #262144,d0                    ;and its size
  620. dobig           ReadFile                                ;read the data
  621. endtrack        movea.l   (kickmem,pc),a0
  622.                 cmpi.w    #$1114,(a0)+                  ;is it 2.0
  623.                 bne.w     not2.0                        ;skip if not
  624.                 lea       (patch,pc),a0                 ;else tell we're patching
  625.                 Printf
  626.                 movea.l   (kickmem,pc),a1               ;get buffer
  627.                 lea       ($7ffff,a1),a1                ;get end address
  628.                 
  629. ;**************************************************
  630. ;This next part scans through a V2.0x kickstart and
  631. ;patches out any 68040 MMU instructions that would
  632. ;corrupt our set up.  Each one found is converted
  633. ;into a 'nop' instruction.
  634. ;**************************************************
  635.                 
  636.                 
  637.                 movea.l   (kickmem,pc),a0               ;get buffer
  638. .loop           cmpa.l    a1,a0                         ;are we finsihed
  639.                 bgt.w     not2.0                        ;exit if so
  640.                 cmpi.w    #$4e7b,(a0)+                  ;look for movec 
  641.                 bne.b     .loop                         ;loop to find
  642.                 
  643.                 move.b    (1,a0),d0                     ;if next byte less than
  644.                 cmpi.b    #3,d0                         ;3 we're not interested
  645.                 blt.b     .loop                         ;so loop back
  646.                 cmpi.b    #7,d0                         ;if it is greater than
  647.                 bgt.b     .loop                         ;7 we're not interested
  648.                 move.b    (a0),d0                       ;so loop
  649.                 andi.b    #$0f,d0                       ;test bits 0-3 if >0 
  650.                 bne.b     .loop                         ;we're not interested
  651.                 move.w    #$4e71,(-2,a0)                ;OK so we've got an MMU
  652.                 move.w    #$4e71,(a0)+                  ;instruction so nop'em
  653.                 bra.b     .loop                         ;and loop
  654.                 
  655. ;*******************************************
  656. ;Once all the above mods are made we correct
  657. ;the checksum of the kickstart
  658. ;*******************************************
  659.  
  660. not2.0          movea.l   (kickmem,pc),a0
  661.                 movea.l   a0,a1
  662.                 lea       ($7ffe8,a0),a0
  663.                 moveq     #0,d5
  664.                 move.l    d5,(a0)                       ;clear checksum 
  665.                 moveq     #-1,d1
  666.                 moveq     #1,d2
  667. .oneloop        add.l     (a1)+,d5
  668.                 bcc.b     .csloop               
  669.                 addq.l    #1,d5
  670. .csloop         dbf       d1,.oneloop           
  671.                 dbf       d2,.oneloop
  672.                 moveq     #-1,d0
  673.                 sub.l     d5,d1
  674.                 move.l    d1,(a0)
  675.                 CALLEXEC  CacheClearU                   ;flush the changes 
  676.                 bra.w     skipclick
  677.                 
  678. ;**************************************************
  679. ;Now we copy the ROM image,  that's the beauty of
  680. ;assembler, we can take advantage of the efficiency
  681. ;of the MOVE16 instruction. C programmers have no 
  682. ;idea, they call CopyMemQuick and hope for the
  683. ;best!!  Plus it saves us from having to flush
  684. ;the cache as MOVE16 instruction prevents the
  685. ;data from being cached and invalidates any entry
  686. ;in the cache.
  687. ;**************************************************                
  688.                 
  689. notkick         move.l    #$7fff,d0                     ;(512k/16)-1 loop count
  690.                 lea       ($f80000),a0                  ;ROM kickstart address
  691.                 movea.l   (kickmem,pc),a1               ;destination
  692. ..turbocopy     move16    (a0)+,(a1)+                   ;16 bytes at a time
  693.                 dbf       d0,..turbocopy                ;loop till done
  694.                                 
  695. ;***************************************
  696. ;This will change the Workbench screen
  697. ;title to Amiga FastBench if the command
  698. ;line option allows it.
  699. ;***************************************                
  700.                 
  701. lookbyte        tst.b     (scrtit,pc)
  702.                 bmi.b     skiptit
  703.                 subq.l    #1,a1
  704.                 cmpi.b    #'W',-(a1)
  705.                 bne.b     lookbyte
  706.                 cmpi.b    #'o',(1,a1)
  707.                 bne.b     lookbyte
  708.                 cmpi.b    #'r',(2,a1)
  709.                 bne.b     lookbyte
  710.                 cmpi.b    #'k',(3,a1)
  711.                 bne.b     lookbyte
  712.                 cmpi.b    #' ',(-1,a1)
  713.                 bne.b     lookbyte
  714.                 cmpi.b    #'a',(-2,a1)
  715.                 bne.b     lookbyte
  716.                 move.b    #'F',(a1)+
  717.                 move.b    #'a',(a1)+
  718.                 move.b    #'s',(a1)+
  719.                 move.b    #'t',(a1)+
  720.                 
  721. ;***********************************************
  722. ;This will patch the kickstart to stop drives
  723. ;from clicking if the command line option allows
  724. ;it
  725. ;***********************************************                
  726.                 
  727. skiptit         tst.b     (noclick,pc)
  728.                 beq.b     skipclick
  729.                 movea.l   (4).w,a0
  730.                 lea       (DeviceList,a0),a0
  731.                 lea       (tdname,pc),a1
  732.                 CALLEXEC  FindName
  733.                 tst.l     d0
  734.                 beq.b     skipclick
  735.                 movea.l   d0,a0
  736.                 movea.l   (LN_NAME,a0),a0
  737. .look6b         cmpi.b    #$6b,(a0)+                    ;find bchg instruction
  738.                 bne.b     .look6b
  739.                 tst.b     (a0)+                         ;2nd byte of instruction
  740.                 bne.b     .look6b
  741.                 cmpi.b    #1,(a0)+                      ;is it the one we want
  742.                 bne.b     .look6b                       ;nope! keep looking
  743.                 suba.l    #$f80003,a0                   ;calculate offset value
  744.                 adda.l    (kickmem,pc),a0               ;add new start address
  745.                 move.b    #$eb,(a0)                     ;change it to bset
  746.                 
  747.  
  748. ;**************************************************
  749. ;place the pointer to the second table in the first
  750. ;and 'OR' in the descriptor type the rest are set
  751. ;as invalid but we link our structure of old values
  752. ;onto an invalid descriptor.
  753. ;**************************************************                
  754.                 
  755. skipclick       movea.l   (table1,pc),a0                ;get first table
  756.                 move.l    (table2,pc),d0                ;get second table
  757.                 or.b      #3,d0                         ;UDT descriptor
  758.                 move.l    d0,(a0)+                      ;shove it in
  759.                 move.l    (table22,pc),d0               ;get 2nd table 2
  760.                 or.b      #3,d0                         ;UDT descriptor
  761.                 move.l    d0,(a0)+                      ;shove it in
  762.                 move.l    a4,(a0)                       ;link our struct on
  763.                                                         ;invalid entry UDT=0
  764. ;****************************************************                
  765. ;Now we set-up table 2, 128 pointers to table3 entries
  766. ;and descriptor type 'ORed' in.
  767. ;****************************************************
  768.                 
  769.                 movea.l   (table2,pc),a0                ;get table 2
  770.                 move.l    (table3,pc),d2                ;get table 3
  771.                 moveq     #127,d0                       ;128 entries
  772.                 or.l      #3,d2                         ;UDT descriptor 
  773. dotable2        move.l    d2,(a0)+                      ;move one in
  774.                 addi.l    #128,d2                       ;add next address
  775.                 dbf       d0,dotable2                   ;loop till done
  776.                 
  777. ;******************************************                
  778. ;Addresses from $0 up to $f7ffff marked as 
  779. ;global, non-cachable serialized
  780. ;******************************************                
  781.                               
  782.                 movea.l   (table3,pc),a0
  783.                 move.l    #$441,d1
  784.                 move.l    #1983,d0
  785. dotable32       move.l    d1,(a0)+
  786.                 addi.l    #$2000,d1
  787.                 dbf       d0,dotable32
  788.                 
  789. ;**********************************************
  790. ;If kickrom, this will map the Chip memory area 
  791. ;we allocated as $F00000 - $FFFFFF to fool the 
  792. ;kickstart as to the size of chip memory
  793. ;**********************************************
  794.                 
  795.                 tst.b     (kickflag,pc)
  796.                 beq.b     skipk               
  797.                 movea.l   (table3,pc),a1
  798.                 move.l    (kickmem,pc),d0
  799.                 moveq     #11,d1
  800.                 lsr.l     d1,d0
  801.                 lea       (a1,d0.l),a1
  802.                 move.l    #$f00000,d1
  803.                 sub.l     (kickmem,pc),d1
  804.                 moveq     #63,d0
  805. dokickm         add.l     d1,(a1)+
  806.                 dbf       d0,dokickm            
  807.                 
  808. ;**********************************************
  809. ;If allowed by the CLI switch this will map the
  810. ;ZorroII memory area $200000 - $A00000 as
  811. ;cachable copyback
  812. ;**********************************************
  813.                 
  814. skipk           tst.b     (zcache,pc)
  815.                 beq.b     skipz                
  816.                 movea.l   (table3,pc),a1
  817.                 lea       ($400,a1),a1
  818.                 move.l    #1023,d0
  819.                 move.b    #$21,d1
  820. dozorro         move.b    d1,(3,a1)
  821.                 dbf       d0,dozorro            
  822.                 
  823. ;*************************************************
  824. ;the rest of table 3 for the kickstart remap
  825. ;64 entries mapping 8k each, and write protected
  826. ;************************************************* 
  827.                
  828. skipz           moveq     #63,d0
  829.                 move.l    (kickmem,pc),d1
  830.                 or.l      #$405,d1
  831. dotable33       move.l    d1,(a0)+
  832.                 addi.l    #$2000,d1
  833.                 dbf       d0,dotable33
  834.                 
  835. ;*********************************************
  836. ;The second 16MB/256k segments are mapped here
  837. ;each entry maps 8k of the 256k making a total
  838. ;of 32 per 256k & 64 of these map the 16MB
  839. ;These are set for Data Cachable Copyback as 
  840. ;memory on some boards will reside here but an
  841. ;optional cli flag allows this to be changed
  842. ;to writethrough
  843. ;*********************************************
  844.                 
  845.                 move.l    #2047,d0
  846.                 move.l    #$1000421,d1
  847.                 tst.b     (mbspace,pc)
  848.                 beq.b     dotable34
  849.                 bclr      #5,d1
  850. dotable34       move.l    d1,(a0)+
  851.                 addi.l    #$2000,d1
  852.                 dbf       d0,dotable34          
  853.                 
  854. ;******************************************************                
  855. ;Now we set-up table 2 for the second 32 Meg address
  856. ;space, 128 pointers to table3 entries and descriptor 
  857. ;type 'ORed' in.  Each table3 entry controls 8k of
  858. ;the 256k of each table 2 entry, each is a long word
  859. ;so the address increment value is 32*4 = 128 as shown. 
  860. ;******************************************************
  861.                 
  862.                 movea.l   (table22,pc),a0
  863.                 move.l    (table23,pc),d2
  864.                 moveq     #127,d0
  865.                 or.l      #3,d2
  866. dotable22       move.l    d2,(a0)+
  867.                 addi.l    #128,d2
  868.                 dbf       d0,dotable22
  869.                 
  870. ;**************************************************************                
  871. ;and now table 3 number 2.  This maps each of the 256k segments
  872. ;in table 2 above with 32 8k page descriptors.
  873. ;**************************************************************
  874.                 
  875.                 movea.l   (table23,pc),a0
  876.                 move.l    #$2000421,d1
  877.                 move.l    #4095,d0
  878.                 tst.b     (mbspace,pc)
  879.                 beq.b     dotable23
  880.                 bclr      #5,d1
  881. dotable23       move.l    d1,(a0)+
  882.                 addi.l    #$2000,d1
  883.                 dbf       d0,dotable23
  884.                 
  885. ;***********************************
  886. ;We save the old transparent values
  887. ;straight into our structure that is
  888. ;tagged on to an invalid entry.
  889. ;A4 points to the table.
  890. ;***********************************                
  891.  
  892.                 lea       (getmttx,pc),a5
  893.                 CALLEXEC  Supervisor
  894.                 move.l    d0,(fr_dtt0,a4)
  895.                 move.l    d1,(fr_dtt1,a4)
  896.                 move.l    d2,(fr_itt0,a4)
  897.                 move.l    d3,(fr_itt1,a4)
  898.                 
  899. ;***********************************************************
  900. ;ZorroIII Memory expansion space is set for Data Cachable
  901. ;Copyback and the ZorroIII Expansion space is invalid at
  902. ;the moment. 
  903. ;This is all done in the Transparent Translation
  904. ;instruction and data registers.
  905. ;When setting all this up we do as much as we can without
  906. ;being disabled.  We can only disable for a very short
  907. ;period of time, so there is no need to be disabled for 
  908. ;the entire installation.  The Transparent settings will
  909. ;take effect immediately but thats ok too!  We only need
  910. ;be disabled for turning the MMU on. 
  911. ;
  912. ;
  913. ;OK, now the magic stuff.  Stick in the keys, clean out the
  914. ;carby, give a couple of pumps, and a bit of choke and lets 
  915. ;see if she'll start.
  916. ;***********************************************************                
  917.                 
  918.                 move.l    (table1,pc),d3        ;get table start
  919.                 move.l    (z3var0,pc),d6        ;copyback up to  $0FFFFFFF
  920.                 move.l    (z3var1,pc),d4        ;copyback up to  $07FFFFFF
  921.                 move.w    #$c000,(tcreg)
  922.                 move.l    (table1,pc),(urpreg)
  923.                 move.l    (table1,pc),(srpreg)
  924.                 move.l    d4,(dt1)              ;save for printing
  925.                 move.l    d6,(dt0)              ;save for printing
  926.                 move.l    #$c040,d5
  927.                 tst.b     (kickflag,pc)
  928.                 bmi.b     .leaveon
  929.                 moveq     #0,d0                 ;d0 = cache bits
  930.                 move.l    d0,d1                 ;clear d1
  931.                 or.l      #CACRF_EnableI|CACRF_EnableD,d1 ;ins & data caches mask
  932.                 CALLEXEC  CacheControl          ;turn 'em both off
  933.                 bsr.w     flushcaches           ;flush the caches
  934. .leaveon        moveq     #0,d2                 ;need a clear reg
  935.                 lea       (setmmu,pc),a5        ;set-up some of the regs
  936.                 CALLEXEC  Supervisor
  937.                 move.l    d0,(vbreg)
  938.                 CALLEXEC  Disable               ;really selfish!!
  939.                 lea       (magic,pc),a5         ;turn this all on
  940.                 CALLEXEC  Supervisor            
  941.                 CALLEXEC  Enable                
  942.                 move.l    d4,(it1)              ;save for printing
  943.                 move.l    d5,(it0)              ;save for printing
  944.                 lea       (okstr,pc),a0         ;finsihed string
  945.                 bra.w     prin                  ;we're outa here
  946.                                                 
  947.                 
  948. setmmu          movec     d2,tc                 ;make sure the MMU is off
  949.                 nop
  950.                 pflusha                         ;invalidate all ATC entries
  951.                 nop
  952.                 movec     d3,urp                ;set the user root pointer
  953.                 movec     d3,srp                ;and the supervisor one
  954.                 movec     d4,dtt1               ;set the data trans' reg
  955.                 movec     d5,dtt0               ;control the lowest 16MB
  956.                 move.l    #$8f7c000,d5             
  957.                 move.l    #$4fbc000,d4          
  958.                 movec     d4,itt1               ;and set the itt1 reg
  959.                 movec     d5,itt0               ;and the itt0 reg
  960.                 movec     vbr,d0
  961.                 rte
  962.  
  963. magic           tst.b     (kickflag,pc)
  964.                 bmi.b     notfast
  965.                 move.w    #$c000,d2             ;set for MMU on with 8k pages
  966.                 movec     d2,tc                 ;IGNITION...
  967.                 movec     d6,dtt0               ;set dtt0 for ZorroIII control
  968.                 move.l    (dcaches,pc),d0       ;requested cache settings
  969.                 movec     d0,cacr               ;and do it
  970.                 rte                             ;I can smell the rubber..
  971. notfast         move.l    #$80008000,d0
  972.                 movec     d0,cacr
  973.                 lea       (crunjmp),a0
  974.                 moveq     #0,d3
  975.                 lea       (crun),a6
  976. crunloop        jmp       (a6)
  977. crunit          reset
  978.                 reset
  979. crun            move.w    ($dff010),d0            ;read something 
  980.                 subq.l    #1,d3
  981.                 bpl.b     crun
  982.                 move.b    #3,($bfe201)
  983.                 move.b    #2,($bfe001)
  984.                 cmpa.l    a0,a6
  985.                 beq.b     crunloop
  986.                 movea.l   a0,a6
  987.                 move.l    #400,d3
  988.                 bra.b     crunit 
  989.                                
  990. crunjmp         movea.l   (kickchip,pc),a0
  991.                 lea       ($f80002),a2
  992.                 movea.l   (kickmem,pc),a1
  993.                 cmpi.w    #$1114,(a1)
  994.                 beq.b     crungo
  995.                 lea       ($fc0002),a2
  996. crungo          jmp       (a0)                
  997.  
  998. crunmmu         movea.l   (4).w,a0
  999.                 movea.l   a0,a1
  1000.                 lea       ($2000,a1),a1
  1001. ..loop          clr.l     (a0)+
  1002.                 cmpa.l    a0,a1
  1003.                 bge.b     ..loop
  1004.                 moveq     #0,d0
  1005.                 move.l    d0,(4)
  1006.                 move.l    d0,(0)
  1007.                 movec     d0,cacr
  1008.                 movec     d0,tc
  1009.                 nop
  1010.                 cpusha    bc
  1011.                 cinva     bc       
  1012.                 pflusha                            
  1013.                 nop
  1014.                 moveq     #19,d0
  1015. .loopled        move.l    #$3fff,d1
  1016.                 bchg      #1,($bfe001)
  1017. .led            dbf       d1,.led
  1018.                 dbf       d0,.loopled
  1019.                 move.l    #$c000,d0
  1020.                 movec     d0,tc
  1021.                 movec     d6,dtt0
  1022.                 jmp       (a2)
  1023.                 nop
  1024.                 nop
  1025. crunend         nop
  1026.                 
  1027. ;************************
  1028. ;Return various registers
  1029. ;************************                
  1030.  
  1031. getregs         movec     tc,d0                 ;traslation control
  1032.                 movec     urp,d1                ;user root pointer
  1033.                 movec     cacr,d2               ;cache control register
  1034.                 movec     dtt0,d3               ;data transparaent translation 0
  1035.                 movec     dtt1,d4               ;data transparaent translation 1
  1036.                 movec     itt0,d5               ;ins transparaent translation 0
  1037.                 movec     itt1,d6               ;ins transparaent translation 1
  1038.                 movec     vbr,d7
  1039.                 movec     srp,a0
  1040.                 rte             
  1041.                 
  1042. flushcaches     suba.l    a0,a0                 ;clear a0
  1043.                 moveq     #-1,d0                ;length = all
  1044.                 moveq     #0,d1                 ;clear d1
  1045.                 or.l      #CACRF_ClearI|CACRF_ClearD,d1  ;both ins & data
  1046.                 JMPEXEC   CacheClearE           ;flush 'em
  1047.                                 
  1048.                 
  1049. getmttx         movec     dtt0,d0
  1050.                 movec     dtt1,d1
  1051.                 movec     itt0,d2
  1052.                 movec     itt1,d3
  1053.                 rte             
  1054.                 
  1055. ;*********************************************************
  1056. ;This routine will test if the MMU set-up is ours, if so
  1057. ;it will extract our structure from the invalid descriptor
  1058. ;and remove the MMU set-up, restore it the way it was and
  1059. ;free up all the resources.
  1060. ;*********************************************************
  1061.  
  1062. removefr        lea       (testcode,pc),a5      ;go and see if MMU is ours
  1063.                 CALLEXEC  Supervisor
  1064.                 tst.l     d0                    ;is it? (struct returned in a4)
  1065.                 beq.b     .oursison
  1066.                 bpl.w     prnorom
  1067.                 cmpi.l    #'FAST',(fr_id,a4)
  1068.                 beq.w     remerr
  1069.                 bra.w     testerr
  1070. .oursison       move.l    (fr_dtt0,a4),d2       ;get old dtt0 value 
  1071.                 move.l    (fr_dtt1,a4),d3       ;get old dtt1 value
  1072.                 move.l    (fr_itt0,a4),d4       ;get old itt0 value
  1073.                 move.l    (fr_itt1,a4),d5       ;get old itt1 value
  1074.                 moveq     #0,d0                 ;se the bits as off
  1075.                 move.l    d0,d1                 ;clear the mask
  1076.                 or.l      #CACRF_EnableI|CACRF_EnableD,d1     ;set the mask bits
  1077.                 CALLEXEC  CacheControl          ;turn them off
  1078.                 bsr.w     flushcaches           ;and flush 'em
  1079.                 lea       (restoremmu,pc),a5    ;replace old values
  1080.                 CALLEXEC  Supervisor
  1081.                 CALLEXEC  Disable               ;shut down till fastrom is gone!
  1082.                 lea       (removemmu,pc),a5     ;go remove MMU set-up
  1083.                 CALLEXEC  Supervisor
  1084.                 CALLEXEC  Enable                ;all OK if we're still here
  1085.                 move.l    (fr_table1,a4),(table1)  
  1086.                 move.l    (fr_table2,a4),(table2)  
  1087.                 move.l    (fr_table3,a4),(table3)  
  1088.                 move.l    (fr_table4,a4),(table22) 
  1089.                 move.l    (fr_table5,a4),(table23) 
  1090.                 move.l    (fr_kickmem,a4),(kickmem)
  1091.                 bsr.w     freetab6              ;go free all memory
  1092.                 moveq     #0,d0                 ;se the bits as off
  1093.                 or.l      #CACRF_EnableI|CACRF_EnableD,d0  ;set the mask bits
  1094.                 move.l    d0,d1                 ;clear the mask
  1095.                 CALLEXEC  CacheControl          ;turn them on
  1096.                 move.l    #remstr,-(sp)         ;tell 'em we removed it OK
  1097. printstr        lea       (credstr,pc),a0       ;print the credits
  1098.                 Printf
  1099.                 bra.w     nobuff                ;bye bye 
  1100.                 
  1101. ;*********************
  1102. ;Print kickrom aborted
  1103. ;*********************
  1104.  
  1105. kickabort       move.l    #opabo,-(sp)
  1106.                 bra.b     freedr
  1107.  
  1108. ;*************************
  1109. ;Print error opening drive
  1110. ;*************************
  1111.  
  1112. kickfilerr      move.l    #notkickf,-(sp)
  1113.                 bra.b     freeabs
  1114.  
  1115. ;*************************
  1116. ;Print error opening drive
  1117. ;*************************
  1118.  
  1119. kickerr         move.l    #baddrive,-(sp)
  1120.                 bra.b     freeabs
  1121.                 
  1122. ;*************************
  1123. ;Print error opening drive
  1124. ;*************************
  1125.  
  1126. kick1err        move.l    #readerr,-(sp)
  1127. freedr          movea.l   (ioreq,pc),a1
  1128.                 ExitDrive
  1129. freeabs         move.l    #559592+fr_SIZEOF,d0          ;total size alloced
  1130.                 movea.l   (kickmem,pc),a1  
  1131.                 CALLEXEC  FreeMem
  1132.                 bra.b     printstr
  1133.                 
  1134. ;********************
  1135. ;Print cannot kickrom
  1136. ;********************
  1137.  
  1138. remerr          move.l    #badkick,-(sp)
  1139.                 bra.b     printstr
  1140.                 
  1141. ;**********************************
  1142. ;Print credits and unkown mmu setup
  1143. ;**********************************
  1144.  
  1145. testerr         move.l    #unkmmu,-(sp)
  1146.                 bra.b     printstr
  1147.                 
  1148. ;***************************************
  1149. ;Print credits and cannot remove fastrom
  1150. ;***************************************
  1151.  
  1152. prnorom         move.l    #norom,-(sp)
  1153.                 bra.b     printstr
  1154.                 
  1155. ;***********************
  1156. ;Print credits and usage
  1157. ;***********************
  1158.  
  1159. useprint        move.l    #usage,-(sp)
  1160.                 bra.b     printstr
  1161.                 
  1162. ;************************************************
  1163. ;Print credits and error if no PP&S card is found
  1164. ;************************************************
  1165.                 
  1166. perr            move.l    #ppserr,-(sp)
  1167.                 bra.b     printstr
  1168.  
  1169. ;************************************
  1170. ;This will turn the FASTROM settings
  1171. ;off and restore all as it was before 
  1172. ;we changed it
  1173. ;It is done in two sections because
  1174. ;some of it does not need to be done
  1175. ;on a disable and the other should.
  1176. ;************************************
  1177.  
  1178. removemmu       moveq     #0,d0
  1179.                 pflusha
  1180.                 movec     d0,tc
  1181.                 rte
  1182.                 
  1183. restoremmu      movec     d2,dtt0
  1184.                 movec     d3,dtt1
  1185.                 movec     d4,itt0
  1186.                 movec     d5,itt1
  1187.                 movec     d0,urp
  1188.                 movec     d0,srp
  1189.                 rte
  1190.                 
  1191. ;***********************************************
  1192. ;Check if the urp register is pointing to
  1193. ;our FASTROM table or something else and
  1194. ;return the result 
  1195. ;INPUT = none  RESULT = 0  our fastrom installed
  1196. ;                       1  if MMU not on
  1197. ;                       -1 MMU on but not ours
  1198. ;***********************************************
  1199.                 
  1200. testcode        movec      tc,d0
  1201.                 tst.w      d0
  1202.                 beq.b      tc_err1
  1203.                 movec      urp,d0
  1204.                 beq.b      tc_err
  1205.                 movea.l    d0,a4
  1206.                 move.l     (8,a4),d0
  1207.                 beq.b      tc_err
  1208.                 movea.l    d0,a4
  1209.                 cmpi.l     #'NICS',(fr_id,a4)
  1210.                 bne.b      tc_err
  1211.                 moveq      #0,d0
  1212.                 rte
  1213. tc_err          moveq      #-1,d0
  1214.                 rte               
  1215. tc_err1         moveq      #1,d0                
  1216.                 rte
  1217.                 
  1218. ;*********************
  1219. ;Set the dtt1 register
  1220. ;*********************
  1221.                 
  1222. setdttx         movec     d0,dtt0
  1223.                 movec     d1,dtt1
  1224.                 rte
  1225.                 
  1226. ;**********************************************
  1227. ;Free memory routines for removal of FASTROM or
  1228. ;partial freeing if memory error on installing
  1229. ;**********************************************                
  1230.                 
  1231. freetab6        movea.l   (fr_struct,a4),a1
  1232.                 move.l    #fr_SIZEOF,d0
  1233.                 bsr.b     freeit
  1234. freetab5        movea.l   (table23,pc),a1
  1235.                 move.l    #16384,d0
  1236.                 bsr.b     freeit
  1237. freetab4        movea.l   (table22,pc),a1
  1238.                 move.l    #512,d0
  1239.                 bsr.b     freeit
  1240. freetab3        movea.l   (table3,pc),a1
  1241.                 move.l    #16384,d0
  1242.                 bsr.b     freeit
  1243. freetab2        movea.l   (table2,pc),a1
  1244.                 move.l    #512,d0
  1245.                 bsr.b     freeit
  1246. freetab1        movea.l   (table1,pc),a1
  1247.                 move.l    #512,d0
  1248.                 bsr.b     freeit
  1249. freekick        movea.l   (kickmem,pc),a1
  1250.                 move.l    #524288,d0
  1251. freeit          CALLEXEC  FreeMem
  1252.                 rts
  1253.                 
  1254. ;**********************************
  1255. ;Error string handling and printing
  1256. ;**********************************
  1257.  
  1258. mem7err         lea       (str3,pc),a0
  1259.                 bsr.b     dofree
  1260.                 bra.b     freetab5
  1261.  
  1262. mem6err         lea       (str2,pc),a0
  1263.                 bsr.b     dofree
  1264.                 bra.b     freetab4
  1265.  
  1266. mem5err         lea       (str2,pc),a0
  1267.                 bsr.b     dofree
  1268.                 bra.b     freetab3
  1269.  
  1270. mem4err         lea       (str2,pc),a0
  1271.                 bsr.b     dofree
  1272.                 bra.b     freetab2
  1273.  
  1274. mem3err         lea       (str2,pc),a0
  1275.                 bsr.b     dofree
  1276.                 bra.b     freetab1
  1277.  
  1278. mem2err         lea       (str2,pc),a0
  1279.                 bsr.b     dofree
  1280.                 bra.b     freekick
  1281.  
  1282. mem1err         lea       (str1,pc),a0
  1283.                 bsr.b     dofree
  1284.                 rts
  1285.                 
  1286. dofree          move.l    a0,-(sp)
  1287.                 lea       (memstr,pc),a0                
  1288.                 bsr.b     steprintf
  1289.                 movea.l   (sp)+,a0
  1290.                 bsr.b     prin
  1291.                 rts
  1292.  
  1293. steprintf       Printf
  1294.                 rts
  1295.  
  1296. ourfastrom      lea       (ourrom,pc),a0
  1297.                 bra.b     prin          
  1298.  
  1299. mmuerr          lea       (mmustr,pc),a0
  1300.                 bra.b     prin          
  1301. cpuerr          lea       (cpustr,pc),a0
  1302.                 bra.b     prin
  1303.  
  1304. vererr          lea       (verstr,pc),a0
  1305. prin            move.l    a0,-(sp)
  1306.                 lea       (credstr,pc),a0
  1307.                 bsr.b     steprintf
  1308.                 tst.l     (table1,pc)
  1309.                 beq.b     nobuff
  1310.                 lea       (kickstr,pc),a0
  1311.                 lea       (kickmem,pc),a1
  1312.                 bsr.b     steprintf
  1313.                 lea       (infostr,pc),a0
  1314.                 lea       (table1,pc),a1
  1315.                 bsr.b     steprintf
  1316.                 movea.l   (datstr,pc),a0
  1317.                 bsr.b     steprintf
  1318.                 movea.l   (insstr,pc),a0
  1319.                 bsr.b     steprintf
  1320. nobuff          movea.l   (sp)+,a0
  1321.                 bsr.b     steprintf
  1322.                 rts
  1323.                 
  1324. ;***********************************************************
  1325. ;We have to be careful here, so far we have found that we
  1326. ;are not running under 2.0x.  We maybe illegal but we might
  1327. ;also be a kick'ed rom 1.3 or 1.2 and they are asking us
  1328. ;to do a fastrom.  Firstly exec probably is not aware of the
  1329. ;68040.  We make sure we have a 68040 then we will check the
  1330. ;mmu set up for our magic kickrom id.  As we need the mmu
  1331. ;urp register, and that instruction is 68040 specific, we
  1332. ;may aswell use that to test for 68040 presence.
  1333. ;The movec instruction will always except to the trap code
  1334. ;but if we are on a 68040 the exception will be a privilege
  1335. ;violation else it will be an illegal instruction.
  1336. ;If all is OK, we copy the entire kickstart and atc entries
  1337. ;over into an allocated fast ram area, then modify the
  1338. ;necessary atc entries for this new ram area, kill the
  1339. ;current set up, turn on the new one and add the 1MB chip
  1340. ;ram back to the system.
  1341. ;***********************************************************
  1342.  
  1343. check4kick      move.l    #$8000,(dcaches)
  1344.                 movea.l   (_TaskBlock),a0               ;get our task
  1345.                 move.l    (TC_TRAPCODE,a0),-(sp)        ;save trap code
  1346.                 move.l    #test040,(TC_TRAPCODE,a0)     ;patch ours in
  1347.                 movec     urp,d0                        ;do 68040 instruction
  1348.                 move.l    (sp)+,(TC_TRAPCODE,a0)        ;replace trap code
  1349.                 tst.l     d0                            ;test result
  1350.                 beq.w     vererr                        ;error, we're illegal 
  1351.                 tst.w     d1                            ;check if MMU is on
  1352.                 bpl.w     vererr                        ;if not we're illegal
  1353.                 movea.l   (4).w,a6                      ;get execbase
  1354.                 move.w    (AttnFlags,a6),d1             ;get the attn flags
  1355.                 bset      #AFB_68040,d1                 ;set for 68040
  1356.                 bset      #AFB_FPU40,d1                 ;set for 040 FPU
  1357.                 bset      #AFB_68030,d1                 ;and for 68030
  1358.                 move.w    d1,(AttnFlags,a6)             ;and put back
  1359.                 movea.l   d0,a0                         ;make a copy of urp
  1360.                 tst.l     (8,a0)                        ;test for a third ptr
  1361.                 beq.w     vererr                        ;skip if null
  1362.                 movea.l   (8,a0),a0                     ;else get third ptr
  1363.                 cmpi.l    #'KICK',(fr_id,a0)            ;look for our id
  1364.                 bne.w     vererr                        ;skip out if not kickrom
  1365.                 move.l    (fr_kickmem,a0),d3
  1366. dochipkick      move.l    #559592+fr_SIZEOF,d0          ;total size needed
  1367.                 move.l    #MEMF_FAST,d1                 ;need fast memory
  1368.                 move.l    #8192,d2                      ;8k boundary
  1369.                 AllocAligned                            ;get aligned memory
  1370.                 tst.l     d0                            ;test result
  1371.                 beq.w     mem1err                       ;out on error
  1372.                 move.l    d0,(kickmem)                  ;we just put it there
  1373.                 movea.l   d0,a1                         ;copy dest ram
  1374.                 move.l    #$7fff,d0                     ;(512k/16)-1 loop count
  1375.                 lea       ($f80000),a0                  ;ROM kickstart address
  1376. ..turbocopy     move16    (a0)+,(a1)+                   ;16 bytes at a time
  1377.                 dbf       d0,..turbocopy                ;loop till done
  1378.                 move.l    #35304+fr_SIZEOF,d0           ;remainder (-512k)
  1379.                 movea.l   d3,a0
  1380.                 lea       ($80000,a0),a0
  1381.                 movea.l   a0,a2                         ;make a copy 
  1382.                 lea       (a2,d0.l),a2                  ;calc end address
  1383.                 movea.l   (kickmem,pc),a1               ;get new block
  1384.                 lea       ($80000,a1),a1                ;calc end address
  1385. ..loop          move.l    (a0)+,(a1)+                   ;move it over 
  1386.                 cmpa.l    a0,a2                         ;finished?
  1387.                 bpl.b     ..loop                        ;nope! more yet
  1388.                 move.l    (kickmem,pc),d0               ;set up all the
  1389.                 addi.l    #524288,d0                    ;pointers to each
  1390.                 move.l    d0,(table1)                   ;table1
  1391.                 move.l    #512,d1
  1392.                 add.l     d1,d0                       
  1393.                 move.l    d0,(table2)                   ;table2
  1394.                 add.l     d1,d0                       
  1395.                 move.l    d0,(table3)                   ;table3
  1396.                 addi.l    #16384,d0
  1397.                 move.l    d0,(table22)                  ;table2/2
  1398.                 add.l     d1,d0
  1399.                 move.l    d0,(table23)                  ;table2/3
  1400.                 addi.l    #16384,d0                     ;last on is our struct
  1401.                 movea.l   d0,a4                         ;save, need it later
  1402.                 move.l    d0,(fr_struct,a4)             ;save it
  1403.                 move.l    (table23,pc),(fr_table5,a4)   ;fill
  1404.                 move.l    (table22,pc),(fr_table4,a4)   ;er
  1405.                 move.l    (table3,pc),(fr_table3,a4)    ;up
  1406.                 move.l    (table2,pc),(fr_table2,a4)    ;please
  1407.                 move.l    (table1,pc),(fr_table1,a4)
  1408.                 move.l    (kickmem,pc),(fr_kickmem,a4)
  1409.                 move.l    #'FAST',(fr_id,a4)            ;our id
  1410.                 movea.l   (table3,pc),a1                ;third level
  1411.                 move.l    d3,d0
  1412.                 moveq     #11,d1
  1413.                 lsr.l     d1,d0
  1414.                 lea       (a1,d0.l),a1
  1415.                 move.l    #$f00000,d1
  1416.                 sub.l     d3,d1
  1417.                 moveq     #63,d0                        ;512k to remap = 64
  1418. ..dokickm       sub.l     d1,(a1)+                      ;convert to same address
  1419.                 dbf       d0,..dokickm                  ;till done
  1420.                 movea.l   (table3,pc),a0                ;third level
  1421.                 lea       ($1f00,a0),a0                 ;$f80000 mapping
  1422.                 moveq     #63,d0                        ;64 to do
  1423.                 move.l    (kickmem,pc),d1               ;get new block
  1424.                 or.l      #$405,d1                      ;or in types
  1425. ..dotable33     move.l    d1,(a0)+                      ;and map it new area
  1426.                 addi.l    #$2000,d1                     ;each is 8k
  1427.                 dbf       d0,..dotable33                ;till done
  1428.                 movea.l   (table1,pc),a0                ;get first table
  1429.                 move.l    (table2,pc),d0                ;get second table
  1430.                 or.b      #3,d0                         ;UDT descriptor
  1431.                 move.l    d0,(a0)+                      ;shove it in
  1432.                 move.l    (table22,pc),d0               ;get 2nd table 2
  1433.                 or.b      #3,d0                         ;UDT descriptor
  1434.                 move.l    d0,(a0)+                      ;shove it in
  1435.                 move.l    a4,(a0)                       ;link our struct on
  1436.                 movea.l   (table2,pc),a0                ;get table 2
  1437.                 move.l    (table3,pc),d2                ;get table 3
  1438.                 moveq     #127,d0                       ;128 entries
  1439.                 or.l      #3,d2                         ;UDT descriptor 
  1440. ..dotable2      move.l    d2,(a0)+                      ;move one in
  1441.                 addi.l    #128,d2                       ;add next address
  1442.                 dbf       d0,..dotable2                 ;loop till done
  1443.                 CALLEXEC  Disable                       ;imples Forbid
  1444.                 movea.l   (table1,pc),a2                ;get table start
  1445.                 move.l    a2,(urpreg)                   ;set print var
  1446.                 move.l    a2,(srpreg)                   ;set printvar
  1447.                 move.l    #inson,(insstr)               ;set print var
  1448.                 move.l    #daton,(datstr)               ;set print var
  1449.                 cmpi.l    #$80008000,(dcaches)          ;all caches on?
  1450.                 beq.b     .callon                       ;skip if so
  1451.                 move.l    #datoff,(datstr)              ;else change print var
  1452. .callon         lea       (chipfast),a0                 ;tell we changing it
  1453.                 Printf
  1454.                 lea       (changemmu),a5                ;get main code
  1455.                 CALLEXEC  Supervisor                    ;go do it
  1456.                 CALLEXEC  Enable                        ;turn it all back on
  1457.                 movea.l   d3,a0
  1458.                 move.l    d3,d1
  1459.                 andi.l    #$fffff,d1
  1460.                 move.l    #$100000,d0
  1461.                 sub.l     d1,d0
  1462.                 move.l    #MEMF_CHIP,d1                 ;its chip
  1463.                 moveq     #-10,d2                       ;chip priority -10
  1464.                 lea       (memname,pc),a1               ;name for it
  1465.                 CALLEXEC  AddMemList                    ;add the memory
  1466.                 lea       (okstr,pc),a0                 ;get all done string
  1467.                 bra.w     prin                          ;and exit
  1468.                 
  1469. ;*************************************
  1470. ;At this point the chiprom OS is alive
  1471. ;and we are going to change it over to
  1472. ;the fastrom setup.  We flush all atc
  1473. ;entries and all caches, so that any
  1474. ;references to the chip OS are gone.
  1475. ;************************************
  1476.                 
  1477. changemmu       moveq     #0,d0                         ;set for caches off
  1478.                 movec     d0,cacr                       ;turn the caches off
  1479.                 movec     d0,tc                         ;turn MMU off
  1480.                 nop
  1481.                 pflusha                                 ;invalidate all ATC
  1482.                 cpusha    bc                            ;flush all caches
  1483.                 cinva     bc                            ;inavalidate all
  1484.                 nop
  1485.                 movec     dtt0,d0                       ;get dtt0
  1486.                 move.l    d0,(dt0)                      ;set print var
  1487.                 movec     dtt1,d0                       ;get dtt1
  1488.                 move.l    d0,(dt1)                      ;set print var
  1489.                 movec     itt0,d0                       ;get itt0 
  1490.                 move.l    d0,(it0)                      ;set print var
  1491.                 movec     itt1,d0                       ;get itt1
  1492.                 move.l    d0,(it1)                      ;set print var
  1493.                 movec     vbr,d0                        ;get vbr
  1494.                 move.l    d0,(vbreg)                    ;set print var
  1495.                 movec     a2,urp                        ;set new urp
  1496.                 movec     a2,srp                        ;and srp
  1497.                 move.l    #$c000,d0                     ;mmu on 8k pages
  1498.                 move.w    d0,(tcreg)                    ;set print var
  1499.                 movec     d0,tc                         ;MMU on
  1500.                 move.l    (dcaches,pc),d0               ;cache settings
  1501.                 movec     d0,cacr                       ;set caches
  1502.                 rte                                     ;finished
  1503.                 
  1504. ;**********************************************
  1505. ;This is the trapcode handler to check if we 
  1506. ;have a 68040 in the system.  The instruction
  1507. ;used before always gave an exception and will
  1508. ;come here.  We get the supplied exception from
  1509. ;the stack and we check if it is a privilege
  1510. ;violation, if so we have a 68040 and we return 
  1511. ;the URP in D0, and TC in D1, else we return 
  1512. ;NULL in D0.
  1513. ;**********************************************               
  1514.                 
  1515. test040         move.l    (sp)+,d0                      ;get Amiga exception
  1516.                 cmpi.w    #8,d0                         ;privilege violation?
  1517.                 bne.b     .not040                       ;skip if not
  1518.                 movec     urp,d0                        ;get the urp reg
  1519.                 movec     tc,d1
  1520. .trapxit        addq.l    #4,(2,sp)                     ;skip movec instruction
  1521.                 rte                                     ;return from exeption
  1522. .not040         moveq     #0,d0                         ;clear return reg
  1523.                 bra.b     .trapxit                      ;and exit
  1524.  
  1525. ;**********************************************
  1526. ;This routine will manipulate a register on the 
  1527. ;PP&S 68040 card so that the next boot will
  1528. ;switch to the required processor.  The choice
  1529. ;to switch or abort is done via the V2.04 
  1530. ;function, EasyRequestArgs.
  1531. ;**********************************************
  1532.  
  1533. doswitch        lea       ($800c000),a2                 ;address of PP&S register
  1534.                 move.l    #68040,(from)                 ;set data for RDF string
  1535.                 move.l    #68030,(to)                   ;set data for RDF string
  1536.                 move.b    (a2),d0                       ;get a byte
  1537.                 not.b     d0                            ;invert it
  1538.                 beq.b     .mode030                      ;if zero we're in 68040
  1539.                 move.l    #68030,(from)                 ;set data for RDF string
  1540.                 move.l    #68040,(to)                   ;set data for RDF string
  1541. .mode030        move.l    d0,d2                         ;save current mode
  1542.                 move.l    #from,d0                      ;get data for RDF string
  1543.                 clr.l     (esidcmp)
  1544.                 bsr.b     requester                     ;do the EasyRequestArgs
  1545.                 tst.l     d0                            ;which gadget?
  1546.                 beq.b     .dsexit                       ;abort
  1547.                 tst.b     d2
  1548.                 beq.b     .do030
  1549.                 move.l    #-1,(a2)                      ;set for 68040
  1550.                 move.l    #-1,(a2)                      ;push it twice
  1551.                 cmpi.b    #-1,(a2)                      ;read it byte! did it set?
  1552.                 beq.b     .pok                          ;PP&S is here!
  1553. .pperr          bra.w     perr                          ;else they dunna got one
  1554. .do030          move.l    (a2),d2                       ;save current mode
  1555.                 move.l    #$fefefefe,(a2)               ;set for 68030
  1556.                 move.l    #$fefefefe,(a2)               ;set long
  1557.                 cmpi.b    #$fe,(a2)                     ;check read byte
  1558.                 bne.b     .pperr                        ;if not no PP&S here!
  1559. .pok            lea       (easyreq,pc),a0               ;else get easy struct
  1560.                 move.l    #esabort,(es_GadgetFormat,a0) ;change the gadgets
  1561.                 move.l    #esboot,(es_TextFormat,a0)    ;and the the text
  1562.                 moveq     #0,d0                         ;no data
  1563.                 move.l    d0,(esidcmp)
  1564.                 bsr.b     requester                     ;will not come back
  1565.                                                         ;unless they aborted
  1566.                 move.l    d2,($800c000)                 ;set old value back
  1567.                 bsr.w     flushcaches                   ;flush em
  1568. .dsexit         lea       (credstr,pc),a0
  1569.                 bsr.b     .prntf
  1570.                 lea       (opabo,pc),a0                 ;get aborted string
  1571. .prntf          Printf                                  ;print it
  1572.                 rts                                     ;and we're gone..
  1573.                 
  1574.                 
  1575. ;******************
  1576. ;Call the requester
  1577. ;******************                    
  1578.                 
  1579. requester       movem.l  a2-a3,-(sp)                    ;save non scratch
  1580.                 suba.l   a0,a0                          ;WB window
  1581.                 lea      (easyreq,pc),a1                ;easy struct
  1582.                 lea      (esidcmp,pc),a2                ;null ext idcmp 
  1583.                 movea.l  d0,a3                          ;data for string
  1584.                 CALLINT  EasyRequestArgs                ;do requester
  1585.                 movem.l  (sp)+,a2-a3                    ;pop 'em
  1586.                 rts                                     ;and return
  1587.                 
  1588. ;************
  1589. ;Data section
  1590. ;************                
  1591.                 include "/set040/set040.i"              ;structure definitions
  1592.                
  1593. ioreq           dc.l      0
  1594. kickchip        dc.l      0
  1595. kickname        dc.l      0
  1596. from            dc.l      0
  1597. to              dc.l      0
  1598. _stdout         dc.l      0                
  1599. kickmem         dc.l      0
  1600. table1          dc.l      0
  1601. table2          dc.l      0
  1602. table3          dc.l      0
  1603. it0             dc.l      0
  1604. it1             dc.l      0
  1605. dt0             dc.l      0
  1606. dt1             dc.l      0
  1607. urpreg          dc.l      0
  1608. srpreg          dc.l      0
  1609. vbreg           dc.l      0
  1610. tcreg           dc.w      0
  1611. table22         dc.l      0
  1612. table23         dc.l      0
  1613. zcache          dc.b      0
  1614. mbspace         dc.b      0
  1615. scrtit          dc.b      0
  1616. noclick         dc.b      0
  1617. kickflag        dc.b      0
  1618. kludge          dc.b      0
  1619. datstr          dc.l      daton
  1620. insstr          dc.l      inson
  1621. dcaches         dc.w      $8000
  1622. icaches         dc.w      $8000
  1623. z3var1          dc.l      $4fbc020
  1624. z3var0          dc.l      $8f7c020
  1625. tdname          dc.b      'trackdisk.device',0
  1626. credstr         dc.b      $0a,$1b,'[1;33m',$1b,'[4mSet040 V1.12 ',$1b,'[31m',$1b,'[4mWritten in Assembler by Nic Wilson',$1b,'[0m',$0a,$0a,0
  1627. infostr         dc.b      'Level A ->',$1b,'[0;32m$%lx ',$1b,'[0mLevel B ->',$1b,'[0;32m$%lx',$1b,'[0m Level C ->',$1b,'[0;32m$%lx',$0a,$0a
  1628.                 dc.b      $1b,'[0mITT0 ->',$1b,'[32m$%-8.lx',$1b,'[0m ITT1 ->',$1b,'[32m$%-8.lx ',$1b,'[0m',$0a
  1629.                 dc.b      'DTT0 ->',$1b,'[32m$%-8.lx',$1b,'[0m DTT1 ->',$1b,'[32m$%-8.lx',$1b,'[0m',$0a
  1630.                 dc.b      'URP  ->',$1b,'[32m$%-8.lx',$1b,'[0m SRP  ->',$1b,'[32m$%-8.lx',$1b,'[0m',$0a
  1631.                 dc.b      'VBR  ->',$1b,'[32m$%-8.lx',$1b,'[0m TC   ->',$1b,'[32m$%-4.x',$1b,'[0m',$0a,0
  1632. usage           dc.b      $0a,'USAGE-> ',$1b,'[0;33mSet040 <switch> (only one ',"'-'",' switch is permitted).',$0a
  1633.                 dc.b      $1b,'[0;33m',TAB,'If no switch is supplied, the current setup will be displayed,',$0a
  1634.                 dc.b      TAB,'and if a CHIPROM setup is found, it will be changed to FASTROM ',$1b,'[0m',$0a
  1635.                 dc.b      $1b,'[0;32m-f<args>  = install FASTROM with optional parameters (EG. -fzi).',$1b,'[0m',$0a
  1636.                 dc.b      $1b,'[0;33m',TAB,'If no arguments are supplied, a default FASTROM will be installed.',$1b,'[0m',$0a
  1637.                 dc.b      TAB,'z = allow caching of ZorroII memory space ($200000 - $A00000).',$0a
  1638.                 dc.b      TAB,'w = set ($1000000 - $3FFFFFF) as Writethrough.',$0a
  1639.                 dc.b      TAB,'c = set ($4000000 - $FFFFFFF) as Writethrough.',$0a
  1640.                 dc.b      TAB,'d = do not enable data cache.',$0a
  1641.                 dc.b      TAB,'i = do not enable instruction cache.',$0a
  1642.                 dc.b      TAB,'t = do not change Workbench screen title.',$0a
  1643.                 dc.b      TAB,'n = patch to stop floppy drives clicking.',$0a
  1644.                 dc.b      $1b,'[0;32m-k <file> = Load, install and boot a different kickstart',$1b,'[0m',$0a
  1645.                 dc.b      '   <file> = Path and filename to kickstart file (1.2 - 2.0).',$0a
  1646.                 dc.b      TAB,'    For loading from Kickstart or SuperKickstart disk,',$0a
  1647.                 dc.b      TAB,'    use floppy drive name for <file> (EG. Set040 -k DF0:).',$0a
  1648.                 dc.b      $1b,'[0;32m-c<args>  = manipulate caches as per options (EG. -cIdC).',$1b,'[0m',$0a
  1649.                 dc.b      TAB,'I = Enable  Instruction Cache.',$0a
  1650.                 dc.b      TAB,'i = Disable Instruction Cache.',$0a
  1651.                 dc.b      TAB,'D = Enable  Data Cache.',$0a
  1652.                 dc.b      TAB,'d = Disable Data Cache.',$0a
  1653.                 dc.b      TAB,'B = Enable  Both Caches.',$0a
  1654.                 dc.b      TAB,'b = Disable Both Caches.',$0a
  1655.                 dc.b      TAB,'C = Enable  Copyback ($4000000 - $FFFFFFF).',$0a
  1656.                 dc.b      TAB,'c = Disable Copyback ($4000000 - $FFFFFFF).',$0a
  1657.                 dc.b      $1b,'[0;32m-r',TAB,'  = remove FASTROM & reclaim resources.',$1b,'[0m',$0a
  1658.                 dc.b      $1b,'[0;32m-s',TAB,'  = Switch CPU 68040-><-68030 (PP&S A3000 Card Only)',$1b,'[0m',$0a,0
  1659. usage1          dc.b      'For usage, type -> ',$1b,'[32mSet040 ?',$1b,'[0m',$0a,0
  1660. kickstr         dc.b      $1b,'[0mKickstart physical address ->',$1b,'[32m$%lx',$1b,'[0m',$0a,0
  1661. daton           dc.b      'DATA CACHE ENABLED  ',0
  1662. datoff          dc.b      'DATA CACHE DISABLED ',0
  1663. inson           dc.b      'INST CACHE ENABLED  ',$0a,$0a,0
  1664. insoff          dc.b      'INST CACHE DISABLED ',$0a,$0a,0
  1665. okstr           dc.b      'FASTROM is installed. ',$0a,0                         
  1666. ok1str          dc.b      'KICKROM is installed. ',$0a,0                         
  1667. unkmmu          dc.b      $0A,'ERROR, UNKNOWN MMU SETUP!!',$0a,0                         
  1668. badkick         dc.b      $0A,'ERROR, CANNOT REMOVE A KICKROM SETUP!',$0a,0
  1669. remstr          dc.b      $0A,'FASTROM removed OK!',$0a,0                         
  1670. ourrom          dc.b      $0A,'ERROR, FASTROM already installed!',$0a,0                         
  1671. norom           dc.b      $0A,'ERROR, FASTROM not installed!',$0a,0                         
  1672. verstr          dc.b      $0A,'ERROR, AmigaDOS V2.04 (V37) or greater required.',$0a,0                         
  1673. cpustr          dc.b      $0A,'ERROR, A 68040 CPU is not installed in this system.',$0a,0                             
  1674. mmustr          dc.b      $0A,'ERROR, MMU already in use, I cannot install FASTROM/KICKROM.',$0a,0                            
  1675. ppserr          dc.b      $0A,'ERROR, A PP&S A3000 card must be installed.',0
  1676. baddrive        dc.b      $0A,'ERROR, Opening drive.',0
  1677. readerr         dc.b      $0A,'ERROR, Error reading disk.',0
  1678. notkickf        dc.b      $0A,'ERROR, File is not a kickstart file.',0
  1679. memstr          dc.b      $0A,'ERROR, Could not get memory for '
  1680. str1            dc.b      'KickStart.',$0a,0                       
  1681. str2            dc.b      'translation tables.',$0a,0                       
  1682. str3            dc.b      'structure.',$0a,0                       
  1683. chipfast        dc.b      $0A,'Converting CHIPROM to FASTROM',$0a,0                       
  1684. patch           dc.b      'Patching Kickstart to stop MMU being disabled',0
  1685. opabo           dc.b      'Operation aborted.',$0a,0
  1686. memname         dc.b      'chip memory',0
  1687.                 
  1688.                 END
  1689.                           
  1690. ;This code is Copyright © Nic Wilson 1991, 1992
  1691. ;It is supplied here only as an example of programming
  1692. ;the 68040 MMU on a fully blown 68040 compatible assembler.
  1693. ;such as the one I use, Macro68.
  1694. ;
  1695. ;I am a dealer for Macro68, if anyone is interested in
  1696. ;purchasing this, then please contact me.
  1697. ;
  1698. ;No part of this source code may be used without permission 
  1699. ;from Nic Wilson, but i'm easy to talk to so phone or
  1700. ;email me {cbmvax|cbmehq}!cbmaus!wilson!nic@uunet.uu.net
  1701. ;
  1702. ;The source, docs and executable  must remain completely unmodified
  1703. ;
  1704. ;I would be grateful if you notify me of any bugs or suggestions
  1705. ;
  1706. ;If you find this source useful as an example when
  1707. ;writing your own then give credit to the author
  1708. ;               
  1709. ;NOTE:  The macro's used in this source code, are not supplied but
  1710. ;they work in a unique way.  All macros are always included but do
  1711. ;not produce object code unless called.  When called for the first
  1712. ;time the assembler is forced to change hunk and insert the macro.
  1713. ;The macro call in the main hunk is replaced with a "JSR macro" call, 
  1714. ;subsequent calls to the same macro are just replaced with the
  1715. ;"JSR macro".  This has benefits, in that code is smaller because
  1716. ;macros are never expanded more than once, and under a debugger
  1717. ;the code looks the same as the source without falling into macro
  1718. ;code that may have been written ages ago.  It can then be debugged
  1719. ;without having to see old code.  If a large library of routines is
  1720. ;built up this way, it also allows for bug free programming as the 
  1721. ;macros will become bug free after a period of time.
  1722.  
  1723.  
  1724.  
  1725.  
  1726.  
  1727.  
  1728.                 
  1729.