home *** CD-ROM | disk | FTP | other *** search
/ The Best of Mecomp Multimedia 2 / MECOMP-CD-II.iso / amiga / emulation / qlsource / romsrc / sys / processor_asm < prev    next >
Encoding:
Text File  |  1998-03-02  |  7.5 KB  |  308 lines

  1. */beginfile PROCESSOR_asm
  2. ; --------------------------------------------------------------
  3. ; PROCESSOR_asm - QDOS processor specific routines
  4. ;           - last modified 22/02/98
  5. ; QDOS-Amiga sources by Rainer Kowallik
  6. ;    ...latest changes by Mark J Swift
  7. ;    ...68040/68060 changes by SNG, 16/8/94
  8. ; --------------------------------------------------------------
  9. ;*/beginoverlay
  10. ; -------------------------------------------------------------
  11. ;    check attn flags for 68000/008 processor. Returns Z if so
  12.  
  13. CHK6800X:
  14.     movem.l    d1/a6,-(a7)
  15.  
  16.     bsr    GET_ATTN
  17.     btst    #0,d1
  18.  
  19.     movem.l    (a7)+,d1/a6
  20.     rts
  21.  
  22. ; -------------------------------------------------------------
  23. ;    set attn flags for processor.
  24.  
  25. SET_ATTN:
  26.     movem.l    d0/a6,-(a7)
  27.  
  28.     move.l    a7,d1        ; Calculate start of
  29.     andi.w    #-$8000,d1    ; system variables
  30.     move.l    d1,a6
  31.  
  32.     bsr    ATTN_FLGS
  33.     move.w    d0,d1
  34.     move.w    d1,SV_IDENT+2(a6) ; set attn flags
  35.  
  36.     movem.l    (a7)+,d0/a6
  37.     rts
  38.  
  39. ; -------------------------------------------------------------
  40. ;    get attn flags for processor.
  41.  
  42. GET_ATTN:
  43.     movem.l    d0/a6,-(a7)
  44.  
  45.     move.l    a7,d1        ; Calculate start of
  46.     andi.w    #-$8000,d1    ; system variables
  47.     move.l    d1,a6
  48.     move.w    SV_IDENT+2(a6),d1 ; get attn flags
  49.  
  50.     movem.l    (a7)+,d0/a6
  51.     rts
  52.  
  53. ; -------------------------------------------------------------
  54. ;    create attention flags (check processor type)
  55.  
  56. ;    bit 0 - at least 68010
  57. ;    bit 1 - at least 68020
  58. ;    bit 2 - at least 68030
  59. ;    bit 3 - at least 68040
  60. ;    bit 4 - at least 68881 (possibly 68882)
  61. ;    bit 5 - 68882 present (or emulation)
  62. ;    bit 6 - 68040 or 68060 on-chip FPU enabled
  63. ;    bit 7 - at least 68060
  64. ;
  65. ; Note: If the MC68060 FPU has been turned off in software since
  66. ; the last reset (which enables it) bit 6 is zero, as if the FPU
  67. ; was not present and we were using an EC or LC processor.
  68. ;
  69. ATTN_FLGS:
  70.     movem.l    d1/a0-a3,-(a7)
  71.  
  72.     dc.w    $2078,$0010    ; move.l  $10.w,a0
  73.     dc.w    $2478,$002C    ; move.l  $2C.w,a2
  74.  
  75.     lea    LF80C18(pc),a1
  76.     dc.w    $21C9,$0010    ; move.l  a1,$10.w
  77.                 ; (ILLEGAL INSTRUCTION vector)
  78.     dc.w    $21C9,$002C    ; move.l  a1,$2C.w
  79.                 ; (F-LINE EMULATION vector)
  80.  
  81.     move.l    a7,a1
  82.  
  83.     moveq    #$0,d0        ; initialise attn flags
  84.     move.b    #0,161(a6)    ; ditto for QDOS
  85.  
  86.     dc.w    $4E7B,$0801    ; movec    d0,vbr
  87.     bset    #$0,d0        ; vbr present - 68010 at least
  88.  
  89. ;              Clear Data cache
  90. ;              | Freeze Data cache
  91. ;              | |Enable Data cache (off)
  92. ;              | ||    Clear Instruction cache
  93. ;              | ||    |  Enable Instruction cache
  94. ;              | ||    |  |
  95.     move.l    #%0000101000001001,d1
  96.  
  97.     dc.w    $4E7B,$1002    ; movec    d1,cacr
  98.     dc.w    $4E7A,$1002    ; movec    cacr,d1
  99.     bset    #$1,d0        ; cacr present - 68020 at least
  100.     move.b    #$20,161(a6)    ; store for QDOS
  101.  
  102.     btst    #$9,d1
  103.     beq.s    LF80BB4        ; no data cache - not a 68030
  104.  
  105.     bset    #$2,d0        ; definitely a 68030
  106.     move.b    #$30,161(a6)    ; store for QDOS
  107.  
  108. LF80BB4:
  109.     btst    #$0,d1
  110.     bne.s    LF80BDC        ; cacr present and (EI) bit
  111.                 ; operative - not a 68040
  112.  
  113.     or.w    #$C,d0        ; 68040 at least!
  114.     move.b    #$40,161(a6)    ; store for QDOS
  115.  
  116.     dc.w    $F4D8        ; CINVA ic/dc - inavalidate caches
  117.  
  118.     moveq    #0,d1        ; MMU off
  119.     dc.w    $4E7B,$1003    ; movec d1,TCR
  120.  
  121. ; This code set up the TTR/ACU registers to stop data cacheing of memory
  122. ; in the first 16 Mb. This is not needed under Amiga Qdos as the cache is
  123. ; explicitly cleared when necessary after DMA - SNG
  124.  
  125. ;     move.l     #$0000C000,d1     ; Write Through to Chip memory
  126.  
  127. ; However, enabling caching on first 16 megs causes problems with IDE
  128. ; hardware which is in this address range, so lets disable caching. If
  129. ; we want a better solution, think about using the MMU - MJS
  130.  
  131.     move.l    #$0000C040,d1    ; Serialize 0-16 Mb
  132.     dc.w    $4E7B,$1006    ; movec d1,(006) DTT0
  133.  
  134.     move.l    #$00FFC000,d1    ; ACU/TTU off
  135. ;     dc.w     $4E7B,$1007     ; movec d1,(007)
  136.     dc.w    $4E7B,$1004    ; movec d1,(004)
  137.     dc.w    $4E7B,$1005    ; movec d1,(005)
  138.  
  139.     move.l    #$00FFC020,d1    ; Copyback on all memory
  140.     dc.w    $4E7B,$1007    ; movec d1,(007) DTT1
  141.  
  142.     move.l    #$80008000,d1    ; Both caches on, for 040+
  143.     bra.s    SetCACR
  144.  
  145. LF80BDC:
  146. ;          Enable Instruction cache >=040 (1=ON)
  147. ;          | Write Allocation (1=ON)
  148. ;          | |Data Burst enable (0=OFF)
  149. ;          | | Clear Data cache
  150. ;          | | |    Enable Data cache (1=ON)
  151. ;          | | |    |   Instruction Burst enable (1=ON)
  152. ;          | | |    |    Clear Instruction cache
  153. ;          | | |    |    |  Enable Instruction cache
  154. ;          | | |    |    |  |
  155.     move.l    #%1010100100011001,d1
  156.  
  157. SetCACR    dc.w    $4E7B,$1002    ; movec       d1,cacr
  158.  
  159.     btst    #$3,d0
  160.     beq.s    LF80BF6        ; skip if not a 68040 or later
  161. ;
  162. ; 68060 initialisation added here
  163. ;
  164. ; Note this tests the new PCR register to find out if we're on
  165. ; an 060. If this fails, the routine returns after checking for
  166. ; a 68040 FPU. Otherwise it turns on the 060 accelerators and
  167. ; reports the presence of an enabled FPU, if it finds one.
  168. ;
  169.     lea    NoPCR(pc),a3    ; Continuation if PCR absent
  170.     dc.w    $21CB,$0010    ; move.l  a3,$10.w
  171.                 ; (ILLEGAL INSTRUCTION vector)
  172.  
  173.     dc.w    $4E7A,$1808    ; 68060 PCR to D1 or illegal
  174.     swap    d1
  175.     cmp.w    #$0431,d1
  176.     beq.s    No60FPU        ; No FPU!
  177. ;    cmp.w    #$0430,d1    ; The only other possibility
  178. ;    bne.s    Unknown        ; at the time of writing...
  179.     btst    #17,d1        ; Test swapped DFP flag bit
  180.     bne.s    No60FPU        ; If FPU is disabled, leave off
  181.  
  182.     bset    #6,d0        ; Note 68060 FPU is available
  183.  
  184.     dc.w    $F37A,NULL-*    ; FRESTORE NULL
  185.  
  186. No60FPU    bset    #7,d0        ; Set 060 bit in ATTN flags
  187.     move.b    #$60,161(a6)    ; Tell Qdos we're on an 060
  188.     swap    d1
  189.     bset    #0,d1        ; Ensure SOEP is on
  190.     dc.w    $4E7B,$1808    ; Store updated PCR
  191. ;
  192. ; Enable store buffer, code, data and (cleared) branch cache
  193. ;
  194.     move.l    #$A0C08000,d1    ; EDC+ESB+EBC+CABC+EIC
  195.     dc.w    $4E7B,$1002    ; movec       d1,cacr
  196.     bra.s    LF80C18
  197. ;
  198. ; The old code to check for the 040 FPU always failed because the
  199. ; 68040 does not support cpSAVE and cpRESTORE! Substitute FNOP
  200. ;
  201. ;    dc.w    $F327        ; cpSAVE
  202. ;    dc.w    $F35F        ; cpRESTORE
  203.  
  204. TryFPU:
  205.  
  206.     dc.w    $F37A,NULL-*    ; FRESTORE NULL
  207.  
  208.     dc.w    $F280,0        ; FNOP sifts out ECs and LCs
  209.  
  210.  
  211.     bset    #$6,d0        ; 68040 FPU present
  212.     bra.s    LF80C18
  213.  
  214. NoPCR    movea.l    a1,a7        ; Tidy stacked exception frame
  215.     bra.s    TryFPU
  216. ;
  217. ; Test for an off-CPU co-processor
  218. ;
  219. LF80BF6:
  220.     dc.w    $F37A,NULL-*    ; FRESTORE NULL
  221.  
  222.     moveq    #$0,d1
  223.  
  224.     dc.w    $F201,$9000    ; FMOVE D1 to FPU
  225.     dc.w    $F201,$B000    ; FMOVE FPU to D1
  226.  
  227.     tst.l    d1        ; A most unlikely case
  228.     bne.s    LF80C18        ; Something strange has happened
  229.  
  230.     bset    #$4,d0        ; 68881 at least
  231.  
  232.     dc.w    $F327        ; cpSAVE -(A7)
  233.  
  234.     cmpi.b    #$18,$1(a7)    ; Check for 68882 frame
  235.     beq.s    LF80C16
  236.  
  237.     bset    #$5,d0        ; 68882 at least
  238.  
  239. LF80C16:
  240.     dc.w    $F35F        ; cpRESTORE (A7)+
  241.  
  242. LF80C18:
  243.     move.l    a1,a7        ; clean-up stack
  244.  
  245.     dc.w    $21C8,$0010    ; move.l  a0,$10.w
  246.     dc.w    $21CA,$002C    ; move.l  a2,$2C.w
  247.  
  248.     movem.l    (a7)+,d1/a0-a3
  249.     rts
  250.  
  251. NULL:
  252.     DC.L    0,0,0,0
  253.  
  254. ; --------------------------------------------------------------
  255. * routine to clear/flush caches on all processors
  256. * callable from user or supervisor modes
  257. ; --------------------------------------------------------------
  258.  
  259. CLRALL:
  260.     movem.l    d0/a0/a6,-(a7)
  261.     movea.l    a7,a0
  262.     trap    #0
  263.     move.w    sr,-(a7)
  264.     ori.w    #$0700,sr    interrupts off
  265.  
  266.     subq.l    #2,a0
  267.     cmpa.l    a0,a7
  268.     beq.s    DOCACHSV     entered routine as supervisor
  269.  
  270.     bclr    #5,0(a7)     otherwise sr on exit = user mode
  271.  
  272. DOCACHSV:
  273.     move.l    a7,d0        Calculate start of
  274.     andi.w    #-$8000,d0    system variables
  275.     move.l    d0,a6
  276.  
  277.     cmpi.b    #$10,$A1(a6)
  278.     bls.s    DOCACHX        exit if 010 or less
  279.  
  280.     dc.w    $4E7A,$0002    movec    cacr,d0
  281.     ori.w    #$0808,d0    always clear 020/030 caches if available
  282.  
  283.     tst.w    d0        check 040 bits
  284.     bpl.s    DOCACHDCHK    branch if instruction cache off
  285.     dc.w    $F4B8        cpusha    ic
  286.                 ; otherwise update memory from cache
  287.     dc.w    $F498        cinva    ic
  288.                 ; invalidate cache
  289.  
  290. DOCACHDCHK:
  291.     tst.l    d0        check 040 bits
  292.     bpl.s    DOCACHSET    branch if data cache off
  293.     dc.w    $F478        cpusha    dc
  294.                 ; otherwise update memory from cache
  295.  
  296. DOCACHSET:
  297.     dc.w    $4E7B,$0002    movec    d0,cacr
  298.                 ; set the cache
  299.  
  300. DOCACHX:
  301.     move.w    (a7)+,sr
  302.     movem.l    (a7)+,d0/a0/a6
  303.     rts
  304.  
  305. ;*/endoverlay
  306. ; --------------------------------------------------------------
  307. ;*/endfile
  308.