home *** CD-ROM | disk | FTP | other *** search
/ World of A1200 / World_Of_A1200.iso / programs / monitors / rsys / rsyssrc.lha / RSysIdents.asm < prev    next >
Assembly Source File  |  1993-06-21  |  8KB  |  347 lines

  1. ;======================================================================
  2. ;
  3. ;    SetCPU V1.60
  4. ;    by Dave Haynie, April 13, 1990
  5. ;    Released to the Public Domain
  6. ;
  7. ;    IDENTS.A MODULE
  8. ;
  9. ;    This module contains the functions that ID the CPU, MMU, and FPU
  10. ;    type indtalled in the system.
  11. ;
  12. ;======================================================================
  13.  
  14. ;    include "setcpu.i"
  15.  
  16.     include "exec/types.i"
  17.     include "exec/execbase.i"
  18.     include "exec/tasks.i"
  19.  
  20. CALLSYS        macro   *
  21.         jsr     LVO\1(A6)
  22.         endm
  23.  
  24. MOVEC_        macro    *
  25.         ifc '\1','cacr'
  26.             ifc '\2','d0'
  27.             dc.w    $4e7a    ; MOVEC    cacr,d0
  28.             dc.w    $0002
  29.             mexit
  30.             endc
  31.             ifc '\2','d1'
  32.             dc.w    $4e7a    ; MOVEC    cacr,d1
  33.             dc.w    $1002
  34.             mexit
  35.             endc
  36.         endc
  37.         ifc '\2','cacr'
  38.             ifc '\1','d0'
  39.             dc.w    $4e7b    ; MOVEC d0,cacr
  40.             dc.w    $0002
  41.             mexit
  42.             endc
  43.             ifc '\1','d1'
  44.             dc.w    $4e7b    ; MOVEC d1,cacr
  45.             dc.w    $1002
  46.             mexit
  47.             endc
  48.         endc
  49.         ifc '\1','vbr'
  50.             ifc '\2','d0'
  51.             dc.w    $4e7a    ; MOVEC    vbr,d0
  52.             dc.w    $0801
  53.             mexit
  54.             endc
  55.         endm
  56.  
  57. PMOVE_        macro    *
  58.         ifc '\1','tc'
  59.             ifc '\2','(sp)'
  60.             dc.w    $f017    ; PMOVE tc,(sp)
  61.             dc.w    $4200
  62.             mexit
  63.             endc
  64.             ifc '\2','(a0)'
  65.             dc.w    $f010    ; PMOVE tc,(a0)
  66.             dc.w    $4200
  67.             mexit
  68.             endc
  69.         endc
  70.         ifc '\1','crp'
  71.             ifc '\2','(a0)'
  72.             dc.w    $f010    ; PMOVE    crp,(a0)
  73.             dc.w    $4e00
  74.             mexit
  75.             endc
  76.         endc
  77.         ifc '\1','(a0)'
  78.             ifc '\2','crp'
  79.             dc.w    $f010    ; PMOVE    (a0),crp
  80.             dc.w    $4c00
  81.             mexit
  82.             endc
  83.             ifc '\2','tc'
  84.             dc.w    $f010    ; PMOVE (a0),tc
  85.             dc.w    $4000
  86.             mexit
  87.             endc
  88.         endc
  89.         ifc '\1','(a1)'
  90.             ifc '\2','crp'
  91.             dc.w    $f011    ; PMOVE (a1),crp
  92.             dc.w    $4c00
  93.             mexit
  94.             endc
  95.         endc
  96.         endm
  97.  
  98. CIB_ENABLE    EQU    0
  99. CIB_FREEZE    EQU    1
  100. CIB_ENTRY    EQU    2
  101. CIB_CLEAR    EQU    3
  102. CIB_BURST    EQU    4
  103.  
  104. CDB_ENABLE    EQU    8
  105. CDB_FREEZE    EQU    9
  106. CDB_ENTRY    EQU    10
  107. CDB_CLEAR    EQU    11
  108. CDB_BURST    EQU    12
  109. CDB_WALLOC    EQU    13
  110.  
  111. CIB_ENABLE40    EQU    15
  112. CDB_ENABLE40    EQU    31
  113.  
  114. ;AFB_68030    EQU    2
  115. ;AFB_68040    EQU    3
  116. ;AFB_68882    EQU    5
  117.  
  118. ATNFLGS        EQU    $129
  119.  
  120. LVOSupervisor    EQU    -30
  121. LVOSuperState    EQU    -150
  122. LVOFindTask    EQU    -294
  123. LVOAllocTrap    EQU    -342
  124. LVOFreeTrap    EQU    -348
  125. LVOCacheClearU    EQU    -636
  126. LVOCacheControl    EQU    -648
  127.  
  128. ANYCREG        EQU    $00dff010
  129.  
  130.     machine mc68020
  131.         mc68881
  132.  
  133.  
  134.     cseg
  135.  
  136.     xdef    _GetCPUType    ; ID the CPU
  137.     xdef    _GetMMUType    ; ID the MMU
  138.     xdef    _GetFPUType    ; ID the FPU
  139.  
  140. ;======================================================================
  141. ;
  142. ;    This routine checks CPU flags early in ExecBase for extended
  143. ;    CPUs that test as a 68020 under 1.3.  If these flags are set,
  144. ;    the actual CPU/MMU type test can be skipped.
  145. ;
  146. ;======================================================================
  147.  
  148. TestFlags:
  149.     moveq.l    #0,d0
  150.     btst.b    #AFB_68040,ATNFLGS(a6)    ; Does the OS think an '040 is here?
  151.     beq NoEarly40
  152.     move.l    #68040,d0
  153.     rts
  154. NoEarly40:
  155.     btst.b    #AFB_68030,ATNFLGS(a6)    ; Does the OS think an '030 is here?
  156.     beq    NoEarly30
  157.     move.l    #68030,d0        ; Sure does...
  158. NoEarly30:
  159.     rts
  160.  
  161.  
  162. ;======================================================================
  163. ;
  164. ;    This function returns the type of the CPU in the system as a
  165. ;    longword: 68000, 68010, 68020, or 68030.  The testing must be done
  166. ;    in reverse order, in that any higher CPU also has the bits set for
  167. ;    a lower CPU.  Also, since 1.3 doesn't recognize the 68030, if I
  168. ;    find the 68020 bit set, I always check for the presence of a
  169. ;    68030.
  170. ;
  171. ;    This routine should be the first test routine called under 1.2
  172. ;    and 1.3.
  173. ;
  174. ;    ULONG GetCPUType();
  175. ;
  176. ;======================================================================
  177.  
  178. _GetCPUType:
  179.     move.l    4,a6            ; Get ExecBase
  180.     jsr    TestFlags        ; Check extended CPU types
  181.     cmp.l    #0,d0
  182.     beq    CPURealTest
  183.     rts
  184. CPURealTest:
  185.     movem.l    a4/a5,-(sp)        ; Save this register
  186.     btst.b    #AFB_68020,ATNFLGS(a6)    ; Maybe a 68020
  187.     bne    FindReal32
  188.     btst.b    #AFB_68010,ATNFLGS(a6)    ; Maybe a 68010?
  189.     bne    Found10
  190.     move.l    #68000,d0        ; Just a measley '000
  191.     movem.l    (sp)+,a4/a5
  192.     rts
  193. Found10:
  194.     move.l    #68010,d0        ; Yup, we're an '010
  195.     movem.l    (sp)+,a4/a5
  196.     rts
  197. FindReal32:
  198.     move.w    LIB_VERSION(a6),d0    ; Are we in 2.0?
  199.     cmp.w    #36,d0            ; If so, we don't need to test
  200.     bge    No40
  201.  
  202.     lea.l    SuperGCT,a5        ; Get the start of the supervisor code
  203.     CALLSYS    Supervisor
  204.  
  205.     btst.l    #CIB_BURST,d0        ; Do we have a set burst bit?
  206.     beq    No30
  207.     move.l    #68030,d0        ; It's a 68030
  208.     bset.b    #AFB_68030,ATNFLGS(a6)
  209.     movem.l    (sp)+,a4/a5
  210.     rts
  211. No30:    
  212.     btst.l    #CIB_ENABLE40,d1    ; Do we have 040 cache enable?
  213.     beq    No40
  214.     move.l    #68040,d0        ; It's a 68040
  215.     bset.b    #AFB_68040,ATNFLGS(a6)
  216.     movem.l    (sp)+,a4/a5
  217.     rts
  218. No40:
  219.     move.l    #68020,d0        ; Guess we're a plain old '020
  220.     movem.l    (sp)+,a4/a5
  221.     rts
  222.  
  223.     ; This routine tries to set a few interesting CACR bits, and
  224.     ; returns the actual register value that took in d0.
  225. SuperGCT:
  226.     MOVEC_    cacr,d1            ; Get the cache register
  227.     move.l    d1,d0            ; Make a copy
  228.     bset.l    #CIB_BURST,d0        ; Set the inst burst bit 030
  229.     bclr.l    #CIB_ENABLE,d0        ; Clear the inst cache bit 030
  230.     bset.l    #CIB_ENABLE40,d0    ; Set the inst cache bit 040
  231.     MOVEC_    d0,cacr            ; Try to set the CACR
  232.     MOVEC_    cacr,d0            ; Save the real value
  233.     MOVEC_    d1,cacr            ; Restore it
  234.     rte
  235.  
  236. ;======================================================================
  237. ;
  238. ;    This function returns 0L if the system contains no MMU, 
  239. ;    68851L if the system does contain an 68851, or the CPU number
  240. ;    for CPUs with integral CPUs.
  241. ;
  242. ;    This routine seems to lock up on at least some CSA 68020 
  243. ;    boards, though it runs just fine on those from Ronin and 
  244. ;    Commodore, as well as all 68030 boards it's been tested on.
  245. ;
  246. ;    ULONG GetMMUType()
  247. ;
  248. ;======================================================================
  249.  
  250. _GetMMUType:
  251.     move.l    4,a6            ; Get ExecBase
  252.     jsr    TestFlags        ; Check extended CPU types
  253.     cmp.l    #0,d0
  254.     beq    MMURealTest
  255.     rts
  256.  
  257.     ; For any other machine, a real test must be done.  The test will
  258.     ; try an MMU instruction.  The instruction will fail unless we're
  259.     ; on a "bogus MMU" system, where the FPU responds as an MMU.
  260. MMURealTest:
  261.     movem.l    a3/a4/a5,-(sp)        ; Save this stuff
  262.     move.l    #0,a1    
  263.     CALLSYS    FindTask        ; Call FindTask(0L)
  264.     move.l    d0,a3
  265.  
  266.     move.l    TC_TRAPCODE(a3),a4    ; Change the exception vector
  267.     move.l    #MMUTraps,TC_TRAPCODE(a3)
  268.     
  269.     move.l    #-1,d0            ; Try to detect undecode FPU
  270.     subq.l    #4,sp            ; Get a local variable
  271.     PMOVE_    tc,(sp)            ; Let's try an MMU instruction
  272.     addq.l    #4,sp            ; Return that local
  273.     move.l    a4,TC_TRAPCODE(a3)    ; Reset exception stuff
  274.     movem.l    (sp)+,a3/a4/a5        ; and return the registers
  275.     rts
  276.  
  277.     ; This is the exception code.  No matter what machine we're on,
  278.     ; we get an exception.  If the MMU's in place, we should get a
  279.     ; privilige violation; if not, an F-Line emulation exception.
  280. MMUTraps:
  281.     move.l    (sp)+,d0        ; Get Amiga supplied exception #
  282.     cmpi    #11,d0            ; Is it an F-Line?
  283.     beq    MMUNope            ; If so, go to the fail routine
  284.     move.l    #68851,d0        ; We have MMU
  285.     addq.l    #4,2(sp)        ; Skip the MMU instruction
  286.     rte
  287. MMUNope:
  288.     moveq.l    #0,d0            ; It dinna woik,
  289.     addq.l    #4,2(sp)        ; Skip the MMU instruction
  290.     rte
  291.  
  292. ;======================================================================
  293. ;
  294. ;    This function returns the type of the FPU in the system as a
  295. ;    longword: 0 (no FPU), 68881, or 68882.
  296. ;
  297. ;    ULONG GetFPUType();
  298. ;
  299. ;======================================================================
  300.  
  301. _GetFPUType:
  302.     move.l    4,a6            ; Get ExecBase
  303.     btst.b    #AFB_68040,ATNFLGS(a6)    ; Is there a 68040 here?
  304.     beq    Look4FPU
  305.     move.l    #68040,d0
  306.     rts
  307. Look4FPU:    
  308.     move.l    a5,-(sp)        ; Save this register
  309.     btst.b    #AFB_68881,ATNFLGS(a6)    ; Does the OS think an FPU is here?
  310.     bne    FPUHere
  311.     moveq.l    #0,d0            ; No FPU here, dude
  312.     move.l    (sp)+,a5        ; Give back the register
  313.     rts
  314. FPUHere:
  315.     btst.b    #AFB_68882,ATNFLGS(a6)    ; How's about an '882?
  316.     beq    FPUTest
  317.     move.l    #68882,d0        ; Sure does...
  318.     move.l    (sp)+,a5
  319.     rts
  320. FPUTest:
  321.     move.w    LIB_VERSION(a6),d0    ; Are we in 2.0?
  322.     cmp.w    #36,d0            ; If so, we don't need to test
  323.     blt    FPUTrap
  324.     move.l    #68881,d0
  325.     move.l    (sp)+,a5
  326.     rts
  327. FPUTrap:
  328.     lea.l    FPUSuper,a5        ; Get the start of the supervisor code
  329.     CALLSYS    Supervisor
  330.     move.l    (sp)+,a5        ; Give back registers
  331.     rts
  332. FPUSuper:
  333.     move.l    #68881,d0        ; Assume we're a 68881
  334.     fsave    -(sp)            ; Test and check
  335.     moveq.l    #0,d1
  336.     move.b    1(sp),d1        ; Size of this frame
  337.     cmpi    #$18,d1
  338.     beq FPU81
  339.     move.l    #68882,d0        ; It's a 68882
  340.     bset.b    #AFB_68882,ATNFLGS(a6)
  341. FPU81:
  342.     frestore (sp)+            ; Restore the stack
  343.     rte
  344.  
  345.     end
  346.  
  347.