home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 100-199 / ff187.lzh / SetCPU / 030Stuff.a < prev    next >
Text File  |  1989-02-26  |  10KB  |  391 lines

  1. ;======================================================================
  2. ;
  3. ;    SetCPU V1.4
  4. ;    by Dave Haynie (released to the public domain)
  5. ;
  6. ;    68030 Assembly Function Module
  7. ;
  8. ;    This module contains functions that access functions in the 68020,
  9. ;    68030, and 68851 chips, and ID all of these, plus the 68881/68882
  10. ;    FPU chips.
  11. ;
  12. ;======================================================================
  13.  
  14. ;======================================================================
  15. ;
  16. ;    Macros & constants used herein...
  17. ;
  18. ;======================================================================
  19.  
  20. CALLSYS macro   *
  21.     jsr     LVO\1(A6)
  22.     endm
  23.  
  24. CIB_ENABLE    EQU    0
  25. CIB_FREEZE    EQU    1
  26. CIB_ENTRY    EQU    2
  27. CIB_CLEAR    EQU    3
  28. CIB_BURST    EQU    4
  29.  
  30. CDB_ENABLE    EQU    8
  31. CDB_FREEZE    EQU    9
  32. CDB_ENTRY    EQU    10
  33. CDB_CLEAR    EQU    11
  34. CDB_BURST    EQU    12
  35. CDB_WALLOC    EQU    13
  36.  
  37. AFB_68030    EQU    2
  38.  
  39. ATNFLGS        EQU    $129
  40.  
  41. LVOSupervisor    EQU    -30
  42. LVOFindTask    EQU    -294
  43. LVOAllocTrap    EQU    -342
  44. LVOFreeTrap    EQU    -348
  45.  
  46. ;======================================================================
  47. ;
  48. ;    Need just a little more stuff
  49. ;
  50. ;======================================================================
  51.  
  52.     NOLIST
  53.     include "exec/execbase.i"
  54.     include "exec/tasks.i"
  55.     LIST
  56.  
  57.     machine mc68020
  58.         mc68881
  59.     cseg
  60.  
  61. ;**********************************************************************
  62. ;
  63. ;    This section contains functions that identify and operate on CPU 
  64. ;    things.
  65. ;
  66. ;**********************************************************************
  67.  
  68.     public    _GetCPUType    ; ID the CPU
  69.     public    _GetCACR    ; Get 020/030 CACR register
  70.     public    _SetCACR    ; Set 020/030 CACR register
  71.  
  72. ;======================================================================
  73. ;
  74. ;    This function returns the type of the CPU in the system as a
  75. ;    longword: 68000, 68010, 68020, or 68030.  The testing must be done
  76. ;    in reverse order, in that any higher CPU also has the bits set for
  77. ;    a lower CPU.  Also, since 1.3 doesn't recognize the 68030, if I
  78. ;    find the 68020 bit set, I always check for the presence of a 
  79. ;    68030.
  80. ;
  81. ;    This routine should be the first test routine called under 1.2
  82. ;    and 1.3.
  83. ;
  84. ;    ULONG GetCPUType();
  85. ;
  86. ;======================================================================
  87.  
  88. _GetCPUType:
  89.     movem.l    a4/a5,-(sp)        ; Save this register
  90.     move.l    4,a6            ; Get ExecBase
  91.     btst.b    #AFB_68030,ATNFLGS(a6)    ; Does the OS think an '030 is here?
  92.     beq    0$
  93.     move.l    #68030,d0        ; Sure does...
  94.     movem.l    (sp)+,a4/a5
  95.     rts
  96. 0$
  97.     btst.b    #AFB_68020,ATNFLGS(a6)    ; Maybe a 68020
  98.     bne    2$
  99.     btst.b    #AFB_68010,ATNFLGS(a6)    ; Maybe a 68010?
  100.     bne    1$
  101.     move.l    #68000,d0        ; Just a measley '000
  102.     movem.l    (sp)+,a4/a5
  103.     rts
  104. 1$
  105.     move.l    #68010,d0        ; Yup, we're an '010
  106.     movem.l    (sp)+,a4/a5
  107.     rts
  108. 2$
  109.     move.l    #68020,d0        ; Assume we're an '020
  110.     lea    3$,a5            ; Get the start of the supervisor code
  111.     CALLSYS    Supervisor
  112.     movem.l    (sp)+,a4/a5
  113.     rts
  114. 3$
  115.     movec    cacr,d1            ; Get the cache register
  116.     move.l    d1,a4            ; Save it for a minute
  117.     bset.l    #CIB_BURST,d1        ; Set the inst burst bit
  118.     bclr.l    #CIB_ENABLE,d1        ; Clear the inst cache bit
  119.     movec    d1,cacr            ; Try to set the CACR
  120.     movec    cacr,d1
  121.     btst.l    #CIB_BURST,d1        ; Do we have a set burst bit?
  122.     beq    4$
  123.     move.l    #68030,d0        ; It's a 68030
  124.     bset.b    #AFB_68030,ATNFLGS(a6)
  125. 4$
  126.     move.l    a4,d1            ; Restore the original CACR
  127.     movec    d1,cacr
  128.     rte
  129.  
  130. ;======================================================================
  131. ;
  132. ;    This function returns the 68020/68030 CACR register.  It assumes
  133. ;    a 68020 or 68030 based system.
  134. ;
  135. ;    ULONG GetCACR()
  136. ;
  137. ;======================================================================
  138.  
  139. _GetCACR:
  140.     move.l    4,a6            ; Get ExecBase
  141.     btst.b    #AFB_68020,ATNFLGS(a6)    ; Does the OS think an '020 is here?
  142.     bne    1$
  143.     moveq.l    #0,d0            ; No CACR here, pal
  144.     rts
  145. 1$
  146.     move.l    a5,-(sp)        ; Save this register
  147.     lea    2$,a5            ; Get the start of the supervisor code
  148.     CALLSYS    Supervisor
  149.     move.l    (sp)+,a5        ; Give back registers
  150.     rts
  151. 2$
  152.     movec    cacr,d0            ; Make CACR the return value
  153.     rte
  154.  
  155. ;======================================================================
  156. ;
  157. ;    This function sets the value of the 68020/68030 CACR register.  
  158. ;    It assumes a 68020 or 68030 based system.
  159. ;
  160. ;    void SetCACR(cacr)
  161. ;    ULONG cacr;
  162. ;
  163. ;======================================================================
  164.  
  165. _SetCACR:
  166.     move.l    4(sp),d0        ; New CACR is on stack
  167.     move.l    4,a6            ; Get ExecBase
  168.     btst.b    #AFB_68020,ATNFLGS(a6)    ; Does the OS think an '020 is here?
  169.     bne    1$
  170.     rts                ; No CACR here, pal
  171. 1$
  172.     move.l    a5,-(sp)        ; Save this register
  173.     lea    2$,a5            ; Get the start of the supervisor code
  174.     CALLSYS    Supervisor
  175.     move.l    (sp)+,a5        ; Give back register
  176.     rts
  177. 2$
  178.     movec    d0,cacr            ; Set the CACR
  179.     rte
  180.  
  181. ;**********************************************************************
  182. ;
  183. ;    This section contains functions that identify and operate on
  184. ;    MMU things.  Unfortunately, there aren't any MMU op-codes in
  185. ;    the Manx assembler yet, so I have to fudge them here.
  186. ;
  187. ;**********************************************************************
  188.  
  189.     public    _GetMMUType    ; Returns the type of MMU
  190.     public    _GetCRP        ; Gets MMU CRP register
  191.     public    _SetCRP        ; Sets MMU CRP register
  192.     public    _GetTC        ; Gets MMU TC register
  193.     public    _SetTC        ; Gets MMU TC register
  194.  
  195. ;======================================================================
  196. ;
  197. ;    This function returns 0L if the system contains no MMU, 
  198. ;    68851L if the system does contain an 68851, or 68030L if the
  199. ;    system contains a 68030.
  200. ;
  201. ;    This routine seems to lock up on at least some CSA 68020 
  202. ;    boards, though it runs just fine on those from Ronin and 
  203. ;    Commodore, as well as all 68030 boards it's been tested on.
  204. ;
  205. ;    ULONG GetMMUType()
  206. ;
  207. ;======================================================================
  208.  
  209. _GetMMUType:
  210.     move.l    4,a6            ; Get ExecBase
  211.     movem.l    a3/a4/a5,-(sp)        ; Save this stuff
  212.     move.l    #0,a1    
  213.     CALLSYS    FindTask        ; Call FindTask(0L)
  214.     move.l    d0,a3
  215.  
  216.     move.l    TC_TRAPCODE(a3),a4    ; Change the exception vector
  217.     move.l    #2$,TC_TRAPCODE(a3)
  218.     
  219.     subq.l    #4,sp            ; Let's try an MMU instruction
  220.     dc.w    $f017            ; Slimey PMOVE tc,(sp)
  221.     dc.w    $4200
  222.     cmpi    #0,d0            ; Any MMU here?
  223.     beq    1$
  224.     btst.b    #AFB_68030,ATNFLGS(a6)    ; Does the OS think an '030 is here?
  225.     beq    1$
  226.     move.l    #68030,d0
  227.  
  228. 1$
  229.     addq.l    #4,sp            ; Return that local
  230.     move.l    a4,TC_TRAPCODE(a3)    ; Reset exception stuff
  231.     movem.l    (sp)+,a3/a4/a5        ; and return the registers
  232.     rts
  233.  
  234.     ; This is the exception code.  No matter what machine we're on,
  235.     ; we get an exception.  If the MMU's in place, we should get a
  236.     ; privilige violation; if not, an F-Line emulation exception.
  237. 2$
  238.     move.l    (sp)+,d0        ; Get Amiga supplied exception #
  239.     cmpi    #11,d0            ; Is it an F-Line?
  240.     beq    3$            ; If so, go to the fail routine
  241.     move.l    #68851,d0        ; We have MMU
  242.     addq.l    #4,2(sp)        ; Skip the MMU instruction
  243.     rte
  244. 3$
  245.     moveq.l    #0,d0            ; It dinna woik,
  246.     addq.l    #4,2(sp)        ; Skip the MMU instruction
  247.     rte
  248.  
  249. ;======================================================================
  250. ;
  251. ;    This function returns the MMU CRP register.  It assumes a 68020 
  252. ;    system with MMU, or a 68030 based system (eg, test for MMU before
  253. ;    you call this, or you wind up in The Guru Zone).  Note that the
  254. ;    CRP register is two longwords long.
  255. ;
  256. ;    void GetCRP(ULONG *)
  257. ;
  258. ;======================================================================
  259.  
  260. _GetCRP:
  261.     move.l    4(sp),a0        ; Pointer to the CRP storage area
  262.     move.l    4,a6            ; Get ExecBase
  263.     move.l    a5,-(sp)
  264.     lea    2$,a5            ; Get the start of the supervisor code
  265.     CALLSYS    Supervisor
  266.     move.l    (sp)+,a5
  267.     rts
  268. 2$
  269.     dc.w    $f010            ; PMOVE CRP,(a0)
  270.     dc.w    $4e00
  271.     rte
  272.  
  273. ;======================================================================
  274. ;
  275. ;    This function sets the MMU CRP register.  It assumes a 68020 
  276. ;    system with MMU, or a 68030 based system (eg, test for MMU before
  277. ;    you call this, or you wind up in The Guru Zone).  Note that the
  278. ;    CRP register is two longwords long.
  279. ;
  280. ;    void SetCRP(ULONG *)
  281. ;
  282. ;======================================================================
  283.  
  284. _SetCRP:
  285.     move.l    4(sp),a0        ; Pointer to the CRP storage area
  286.     move.l    4,a6            ; Get ExecBase
  287.     move.l    a5,-(sp)
  288.     lea    2$,a5            ; Get the start of the supervisor code
  289.     CALLSYS    Supervisor
  290.     move.l    (sp)+,a5        ; Give back registers
  291.     rts
  292. 2$
  293.     dc.w    $f010            ; PMOVE (a0),CRP
  294.     dc.w    $4c00
  295.     rte
  296.  
  297. ;======================================================================
  298. ;
  299. ;    This function returns the MMU TC register.  It assumes a 68020 
  300. ;    system with MMU, or a 68030 based system (eg, test for MMU before
  301. ;    you call this, or you wind up in The Guru Zone).  
  302. ;
  303. ;    ULONG GetTC()
  304. ;
  305. ;======================================================================
  306.  
  307. _GetTC:
  308.     move.l    4,a6            ; Get ExecBase
  309.     move.l    a5,-(sp)
  310.     subq.l    #4,sp            ; Make a place to dump TC
  311.     move.l    sp,a0
  312.     lea    2$,a5            ; Get the start of the supervisor code
  313.     CALLSYS    Supervisor
  314.     move.l    (sp),d0            ; Here's the result
  315.     addq.l    #4,sp
  316.     move.l    (sp)+,a5
  317.     rts
  318. 2$
  319.     dc.w    $f010            ; PMOVE TC,(a0)
  320.     dc.w    $4200
  321.     rte
  322.  
  323. ;======================================================================
  324. ;
  325. ;    This function sets the MMU TC register.  It assumes a 68020 
  326. ;    system with MMU, or a 68030 based system (eg, test for MMU before
  327. ;    you call this, or you wind up in The Guru Zone).  
  328. ;
  329. ;    void SetTC(ULONG)
  330. ;
  331. ;======================================================================
  332.  
  333. _SetTC:
  334.     lea    4(sp),a0        ; Get address of our new TC value
  335.     move.l    4,a6            ; Get ExecBase
  336.     move.l    a5,-(sp)
  337.     lea    2$,a5            ; Get the start of the supervisor code
  338.      CALLSYS    Supervisor
  339.     move.l    (sp)+,a5
  340.     rts
  341. 2$
  342.     dc.w    $f010            ; PMOVE (a0),TC
  343.     dc.w    $4000
  344.     rte
  345.  
  346.  
  347. ;**********************************************************************
  348. ;
  349. ;    This section contains functions that identify and operate on
  350. ;    FPU things.  
  351. ;
  352. ;**********************************************************************
  353.  
  354.     public    _GetFPUType    ; Gets the FPU type
  355.  
  356. ;======================================================================
  357. ;
  358. ;    This function returns the type of the FPU in the system as a
  359. ;    longword: 0 (no FPU), 68881, or 68882.
  360. ;
  361. ;    ULONG GetFPUType();
  362. ;
  363. ;======================================================================
  364.  
  365. _GetFPUType:
  366.     move.l    a5,-(sp)        ; Save this register
  367.     move.l    4,a6            ; Get ExecBase
  368.     btst.b    #AFB_68881,ATNFLGS(a6)    ; Does the OS think an FPU is here?
  369.     bne    1$    
  370.     moveq.l    #0,d0            ; No FPU here, dude
  371.     move.l    (sp)+,a5        ; Give back the register
  372.     rts
  373. 1$
  374.     lea    2$,a5            ; Get the start of the supervisor code
  375.     CALLSYS    Supervisor
  376.     move.l    (sp)+,a5        ; Give back registers
  377.     rts
  378. 2$
  379.     move.l    #68881,d0        ; Assume we're a 68881
  380.     fsave    -(sp)            ; Test and check
  381.     moveq.l    #0,d1
  382.     move.b    1(sp),d1        ; Size of this frame
  383.     cmpi    #$18,d1
  384.     beq 3$
  385.     move.l    #68882,d0        ; It's a 68882
  386. 3$
  387.     frestore (sp)+            ; Restore the stack
  388.     rte
  389.  
  390.     end
  391.