home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 15 / AACD15.ISO / AACD / Programming / MultiDesktop / system / system.asm < prev    next >
Encoding:
Assembly Source File  |  1997-03-27  |  14.9 KB  |  518 lines

  1.  PMMU
  2.  FPU
  3.  
  4. CALLSYS  macro \1
  5.       jsr      _LVO\1(A6)
  6.       endm
  7.  
  8.  xdef _GetCPUType
  9.  xdef _GetMMUType
  10.  xdef _GetFPUType
  11.  xdef _GetCACR
  12.  xdef _SetCACR
  13.  xdef _GetCRP
  14.  xdef _SetCRP
  15.  xdef _GetSRP
  16.  xdef _SetSRP
  17.  xdef _GetTC
  18.  xdef _SetTC
  19.  xdef _GetTT0
  20.  xdef _SetTT0
  21.  xdef _GetTT1
  22.  xdef _SetTT1
  23.  
  24. _LVOSupervisor   equ -30
  25. _LVOFindTask     equ -294
  26. _AbsExecBase     equ   $4
  27.  
  28. CIB_ENABLE     equ   0
  29. CIB_FREEZE     equ   1
  30. CIB_CLEAR      equ   3
  31. CIB_BURST      equ   4
  32.  
  33. CDB_ENABLE     equ   8
  34. CDB_FREEZE     equ   9
  35. CDB_CLEAR      equ   11
  36. CDB_BURST      equ   12
  37.  
  38. AFB_68881      equ   4
  39. AFB_68030      equ   2
  40. AFB_68020      equ   1
  41. AFB_68010      equ   0
  42.  
  43. TC_TRAPCODE    equ   $0032
  44. ATNFLGS        equ   $0129
  45.  
  46.  
  47.  jmp _GetMMUType
  48.  
  49.  ;======================================================================
  50.  ;
  51.  ;  This function returns the type of the CPU in the system as a
  52.  ;  longword: 68000, 68010, 68020, or 68030.  The testing must be done
  53.  ;  in reverse order, in that any higher CPU also has the bits set for
  54.  ;  a lower CPU.  Also, since 1.3 doesn't recognize the 68030, if I
  55.  ;  find the 68020 bit set, I always check for the presence of a
  56.  ;  68030.
  57.  ;
  58.  ;  This routine should be the first test routine called under 1.2
  59.  ;  and 1.3.
  60.  ;
  61.  ;  ULONG GetCPUType();
  62.  ;
  63.  ;======================================================================
  64.  
  65. _GetCPUType:
  66.    movem.l  a4/a5,-(sp)             ; Save this register
  67.    move.l   _AbsExecBase,a6         ; Get ExecBase
  68.    btst.b   #AFB_68030,ATNFLGS(a6)  ; Does the OS think an '030 is here?
  69.    beq.s _GetCPUType_0
  70.    move.l   #68030,d0               ; Sure does...
  71.    movem.l  (sp)+,a4/a5
  72.    rts
  73.  
  74. _GetCPUType_0:
  75.    btst.b   #AFB_68020,ATNFLGS(a6)  ; Maybe a 68020
  76.    bne.s _GetCPUType_2
  77.    btst.b   #AFB_68010,ATNFLGS(a6)  ; Maybe a 68010?
  78.    bne.s _GetCPUType_1
  79.    move.l   #68000,d0               ; Just a measley '000
  80.    movem.l  (sp)+,a4/a5
  81.    rts
  82.  
  83. _GetCPUType_1:
  84.    move.l   #68010,d0               ; Yup, we're an '010
  85.    movem.l  (sp)+,a4/a5
  86.    rts
  87.  
  88. _GetCPUType_2:
  89.    move.l   #68020,d0               ; Assume we're an '020
  90.    lea   _GetCPUType_3,a5           ; Get the start of the supervisor code
  91.    CALLSYS Supervisor
  92.    movem.l  (sp)+,a4/a5
  93.    rts
  94.  
  95.    machine mc68020
  96. _GetCPUType_3:
  97.    movec cacr,d1                    ; Get the cache register
  98.    move.l   d1,a4                   ; Save it for a minute
  99.    bset.l   #CIB_BURST,d1           ; Set the inst burst bit
  100.    bclr.l   #CIB_ENABLE,d1          ; Clear the inst cache bit
  101.    movec d1,cacr                    ; Try to set the CACR
  102.    movec cacr,d1
  103.    btst.l   #CIB_BURST,d1           ; Do we have a set burst bit?
  104.    beq.s _GetCPUType_4
  105.    move.l   #68030,d0               ; It's a 68030
  106.    bset.b   #AFB_68030,ATNFLGS(a6)
  107.  
  108. _GetCPUType_4:
  109.    move.l   a4,d1                   ; Restore the original CACR
  110.    movec d1,cacr
  111.    rte
  112.    machine mc68000
  113.  
  114. ;======================================================================
  115. ;
  116. ;  This function returns the type of the FPU in the system as a
  117. ;  longword: 0 (no FPU), 68881, or 68882.
  118. ;
  119. ;  ULONG GetFPUType();
  120. ;
  121. ;======================================================================
  122.  
  123. _GetFPUType:
  124.    move.l   a5,-(sp)                ; Save this register
  125.    move.l   _AbsExecBase,a6         ; Get ExecBase
  126.    btst.b   #AFB_68881,ATNFLGS(a6)  ; Does the OS think an FPU is here?
  127.    bne.s _GetFPUType_1
  128.    moveq.l  #0,d0                   ; No FPU here, dude
  129.    move.l   (sp)+,a5                ; Give back the register
  130.    rts
  131.  
  132. _GetFPUType_1:
  133.    lea   _GetFPUType_2,a5           ; Get the start of the supervisor code
  134.    CALLSYS Supervisor
  135.    move.l   (sp)+,a5                ; Give back registers
  136.    rts
  137.  
  138. _GetFPUType_2:
  139.    move.l   #68881,d0               ; Assume we're a 68881
  140.    fsave -(sp)                      ; Test and check
  141.    moveq.l  #0,d1
  142.    move.b   1(sp),d1                ; Size of this frame
  143.    cmpi  #$18,d1
  144.    beq   _GetFPUType_3
  145.    move.l   #68882,d0               ; It's a 68882
  146.  
  147. _GetFPUType_3:
  148.    frestore (sp)+                   ; Restore the stack
  149.    rte               
  150.  
  151. ;======================================================================
  152. ;
  153. ;  This function returns 0L if the system contains no MMU, 
  154. ;  68851L if the system does contain an 68851, or 68030L if the
  155. ;  system contains a 68030.
  156. ;
  157. ;  This routine seems to lock up on at least some CSA 68020 
  158. ;  boards, though it runs just fine on those from Ronin and 
  159. ;  Commodore, as well as all 68030 boards it's been tested on.
  160. ;
  161. ;  ULONG GetMMUType()
  162. ;
  163. ;======================================================================
  164.  
  165. _GetMMUType:
  166.    move.l   _AbsExecBase,a6         ; Get ExecBase
  167.    movem.l  a3/a4/a5,-(sp)          ; Save this stuff
  168.    moveq #0,d0
  169.    move.l   d0,a1
  170.    CALLSYS  FindTask                ; Call FindTask(0L)
  171.    move.l   d0,a3                 
  172.                                  
  173.    move.l   TC_TRAPCODE(a3),a4      ; Change the exception vector
  174.    lea      _GetMMUType_2,a0
  175.    move.l   a0,TC_TRAPCODE(a3)
  176.    
  177.    subq.l   #4,sp                   ; Let's try an MMU instruction
  178.    pmove tc,(sp)
  179.    cmpi  #0,d0                      ; Any MMU here?
  180.    beq.s _GetMMUType_1
  181.    btst.b   #AFB_68030,ATNFLGS(a6)  ; Does the OS think an '030 is here?
  182.    beq.s _GetMMUType_1
  183.    move.l   #68030,d0
  184.  
  185. _GetMMUType_1:
  186.    addq.l   #4,sp                   ; Return that local
  187.    move.l   a4,TC_TRAPCODE(a3)      ; Reset exception stuff
  188.    movem.l  (sp)+,a3/a4/a5          ; and return the registers
  189.    rts
  190.  
  191.  ; This is the exception code.  No matter what machine we're on,
  192.  ; we get an exception.  If the MMU's in place, we should get a
  193.  ; privilige violation; if not, an F-Line emulation exception.
  194.  
  195. _GetMMUType_2:
  196.    move.l   (sp)+,d0                ; Get Amiga supplied exception #
  197.    cmpi  #11,d0                     ; Is it an F-Line?
  198.    beq.s _GetMMUType_3              ; If so, go to the fail routine
  199.    move.l   #68851,d0               ; We have MMU
  200.    addq.l   #4,2(sp)                ; Skip the MMU instruction
  201.    rte
  202.  
  203. _GetMMUType_3:
  204.    moveq.l  #0,d0                   ; It dinna woik,
  205.    addq.l   #4,2(sp)                ; Skip the MMU instruction
  206.    rte
  207.  
  208. ;======================================================================
  209. ;
  210. ;  This function returns the MMU CRP register.  It assumes a 68020
  211. ;  system with MMU, or a 68030 based system (eg, test for MMU before
  212. ;  you call this, or you wind up in The Guru Zone).  Note that the
  213. ;  CRP register is two longwords long.
  214. ;
  215. ;  void GetCRP(a4)
  216. ;
  217. ;======================================================================
  218.  
  219. _GetCRP:
  220.    move.l   _AbsExecBase,a6         ; Get ExecBase
  221.    move.l   a5,-(sp)
  222.    lea   _GetCRP_2,a5               ; Get the start of the supervisor code
  223.    CALLSYS  Supervisor
  224.    move.l   (sp)+,a5
  225.    rts
  226.  
  227. _GetCRP_2:
  228.    pmove crp,(a0)
  229.    rte
  230.  
  231. ;======================================================================
  232. ;
  233. ;  This function sets the MMU CRP register.  It assumes a 68020 
  234. ;  system with MMU, or a 68030 based system (eg, test for MMU before
  235. ;  you call this, or you wind up in The Guru Zone).  Note that the
  236. ;  CRP register is two longwords long.
  237. ;
  238. ;  void SetCRP(a4)
  239. ;
  240. ;======================================================================
  241.  
  242. _SetCRP:
  243.    move.l   _AbsExecBase,a6      ; Get ExecBase
  244.    move.l   a5,-(sp)
  245.    lea   _SetCRP_2,a5            ; Get the start of the supervisor code
  246.    CALLSYS  Supervisor
  247.    move.l   (sp)+,a5             ; Give back registers
  248.    rts
  249.  
  250. _SetCRP_2:
  251.    pflusha                       ; explicitly flush the ATC for now
  252.    pmove (a0),crp
  253.    rte
  254.  
  255. ;======================================================================
  256. ;
  257. ;  This function returns the MMU SRP register.  It assumes a 68020
  258. ;  system with MMU, or a 68030 based system (eg, test for MMU before
  259. ;  you call this, or you wind up in The Guru Zone).  Note that the
  260. ;  SRP register is two longwords long.
  261. ;
  262. ;  void GetSRP(a4)
  263. ;
  264. ;======================================================================
  265.  
  266. _GetSRP:
  267.    move.l   _AbsExecBase,a6         ; Get ExecBase
  268.    move.l   a5,-(sp)
  269.    lea   _GetSRP_2,a5               ; Get the start of the supervisor code
  270.    CALLSYS  Supervisor
  271.    move.l   (sp)+,a5
  272.    rts
  273.  
  274. _GetSRP_2:
  275.    pmove srp,(a0)
  276.    rte
  277.  
  278. ;======================================================================
  279. ;
  280. ;  This function sets the MMU SRP register.  It assumes a 68020
  281. ;  system with MMU, or a 68030 based system (eg, test for MMU before
  282. ;  you call this, or you wind up in The Guru Zone).  Note that the
  283. ;  SRP register is two longwords long.
  284. ;
  285. ;  void SetSRP(a4)
  286. ;
  287. ;======================================================================
  288.  
  289. _SetSRP:
  290.    move.l   _AbsExecBase,a6      ; Get ExecBase
  291.    move.l   a5,-(sp)
  292.    lea   _SetSRP_2,a5            ; Get the start of the supervisor code
  293.    CALLSYS  Supervisor
  294.    move.l   (sp)+,a5             ; Give back registers
  295.    rts
  296.  
  297. _SetSRP_2:
  298.    pflusha                       ; explicitly flush the ATC for now
  299.    pmove (a0),srp
  300.    rte
  301.  
  302. ;======================================================================
  303. ;
  304. ;  This function returns the MMU TC register.  It assumes a 68020 
  305. ;  system with MMU, or a 68030 based system (eg, test for MMU before
  306. ;  you call this, or you wind up in The Guru Zone).  
  307. ;
  308. ;  ULONG GetTC()
  309. ;
  310. ;======================================================================
  311.  
  312. _GetTC:
  313.    move.l   _AbsExecBase,a6      ; Get ExecBase
  314.    move.l   a5,-(sp)
  315.    subq.l   #4,sp                ; Make a place to dump TC
  316.    move.l   sp,a0
  317.    lea   _GetTC_2,a5             ; Get the start of the supervisor code
  318.    CALLSYS  Supervisor
  319.    move.l   (sp),d0              ; Here's the result
  320.    addq.l   #4,sp          
  321.    move.l   (sp)+,a5
  322.    rts
  323.  
  324. _GetTC_2:
  325.    pmove tc,(a0)
  326.    rte
  327.  
  328. ;======================================================================
  329. ;
  330. ;  This function sets the MMU TC register.  It assumes a 68020 
  331. ;  system with MMU, or a 68030 based system (eg, test for MMU before
  332. ;  you call this, or you wind up in The Guru Zone).
  333. ;
  334. ;  void SetTC(ULONG)
  335. ;
  336. ;======================================================================
  337.  
  338. _SetTC:
  339.    lea   4(sp),a0                ; Get address of our new TC value
  340.    move.l   _AbsExecBase,a6      ; Get ExecBase
  341.    move.l   a5,-(sp)
  342.    lea   _SetTC_2,a5             ; Get the start of the supervisor code
  343.    CALLSYS  Supervisor
  344.    move.l   (sp)+,a5
  345.    rts
  346.  
  347. _SetTC_2:
  348.    pflusha                       ; explicitly flush the ATC for now
  349.    pmove (a0),tc
  350.    rte
  351.  
  352. ;======================================================================
  353. ;
  354. ;  This function returns the MMU TT0 register.  It assumes a 68020
  355. ;  system with MMU, or a 68030 based system (eg, test for MMU before
  356. ;  you call this, or you wind up in The Guru Zone).  
  357. ;
  358. ;  ULONG GetTT0()
  359. ;
  360. ;======================================================================
  361.  
  362.    machine mc68030
  363. _GetTT0:
  364.    move.l   _AbsExecBase,a6      ; Get ExecBase
  365.    move.l   a5,-(sp)
  366.    subq.l   #4,sp                ; Make a place to dump TT0
  367.    move.l   sp,a0
  368.    lea   _GetTT0_2,a5             ; Get the start of the supervisor code
  369.    CALLSYS  Supervisor
  370.    move.l   (sp),d0              ; Here's the result
  371.    addq.l   #4,sp          
  372.    move.l   (sp)+,a5
  373.    rts
  374.  
  375. _GetTT0_2:
  376.    pmove tt0,(a0)
  377.    rte
  378.    machine mc68000
  379.  
  380. ;======================================================================
  381. ;
  382. ;  This function sets the MMU TT0 register.  It assumes a 68020
  383. ;  system with MMU, or a 68030 based system (eg, test for MMU before
  384. ;  you call this, or you wind up in The Guru Zone).
  385. ;
  386. ;  void SetTT0(ULONG)
  387. ;
  388. ;======================================================================
  389.  
  390.    machine mc68030
  391. _SetTT0:
  392.    lea   4(sp),a0                ; Get address of our new TT0 value
  393.    move.l   _AbsExecBase,a6      ; Get ExecBase
  394.    move.l   a5,-(sp)
  395.    lea   _SetTT0_2,a5             ; Get the start of the supervisor code
  396.    CALLSYS  Supervisor
  397.    move.l   (sp)+,a5
  398.    rts
  399.  
  400. _SetTT0_2:
  401.    pflusha                       ; explicitly flush the ATC for now
  402.    pmove (a0),tt0
  403.    rte
  404.    machine mc68000
  405.  
  406. ;======================================================================
  407. ;
  408. ;  This function returns the MMU TT1 register.  It assumes a 68020
  409. ;  system with MMU, or a 68030 based system (eg, test for MMU before
  410. ;  you call this, or you wind up in The Guru Zone).  
  411. ;
  412. ;  ULONG GetTT1()
  413. ;
  414. ;======================================================================
  415.  
  416.    machine mc68030
  417. _GetTT1:
  418.    move.l   _AbsExecBase,a6      ; Get ExecBase
  419.    move.l   a5,-(sp)
  420.    subq.l   #4,sp                ; Make a place to dump TT1
  421.    move.l   sp,a0
  422.    lea   _GetTT1_2,a5             ; Get the start of the supervisor code
  423.    CALLSYS  Supervisor
  424.    move.l   (sp),d0              ; Here's the result
  425.    addq.l   #4,sp          
  426.    move.l   (sp)+,a5
  427.    rts
  428.  
  429. _GetTT1_2:
  430.    pmove tt1,(a0)
  431.    rte
  432.    machine mc68000
  433.  
  434. ;======================================================================
  435. ;
  436. ;  This function sets the MMU TT1 register.  It assumes a 68020
  437. ;  system with MMU, or a 68030 based system (eg, test for MMU before
  438. ;  you call this, or you wind up in The Guru Zone).
  439. ;
  440. ;  void SetTT1(ULONG)
  441. ;
  442. ;======================================================================
  443.  
  444.    machine mc68030
  445. _SetTT1:
  446.    lea   4(sp),a0                ; Get address of our new TT1 value
  447.    move.l   _AbsExecBase,a6      ; Get ExecBase
  448.    move.l   a5,-(sp)
  449.    lea   _SetTT1_2,a5             ; Get the start of the supervisor code
  450.    CALLSYS  Supervisor
  451.    move.l   (sp)+,a5
  452.    rts
  453.  
  454. _SetTT1_2:
  455.    pflusha                       ; explicitly flush the ATC for now
  456.    pmove (a0),tt1
  457.    rte
  458.    machine mc68000
  459.  
  460. ;======================================================================
  461. ;
  462. ;  This function returns the 68020/68030 CACR register.  It assumes
  463. ;  a 68020 or 68030 based system.
  464. ;
  465. ;  ULONG GetCACR()
  466. ;
  467. ;======================================================================
  468.  
  469. _GetCACR:
  470.    move.l   _AbsExecBase,a6         ; Get ExecBase
  471.    btst.b   #AFB_68020,ATNFLGS(a6)  ; Does the OS think an '020 is here?
  472.    bne.s _GetCACR_1
  473.    moveq #0,d0                      ; No CACR here, pal
  474.    rts
  475.  
  476.    machine mc68020
  477. _GetCACR_1:
  478.    move.l   a5,-(sp)                ; Save this register
  479.    lea   _GetCACR_2,a5              ; Get the start of the supervisor code
  480.    CALLSYS  Supervisor
  481.    move.l   (sp)+,a5                ; Give back registers
  482.    rts
  483.  
  484. _GetCACR_2:
  485.    movec cacr,d0                    ; Make CACR the return value
  486.    rte
  487.    machine mc68000
  488.  
  489. ;======================================================================
  490. ;
  491. ;  This function sets the value of the 68020/68030 CACR register.  
  492. ;  It assumes a 68020 or 68030 based system.
  493. ;
  494. ;  void SetCACR(cacr)
  495. ;  ULONG cacr;
  496. ;
  497. ;======================================================================
  498.  
  499. _SetCACR:
  500.    move.l   4(sp),d0                ; New CACR is on stack
  501.    move.l   _AbsExecBase,a6         ; Get ExecBase
  502.    btst.b   #AFB_68020,ATNFLGS(a6)  ; Does the OS think an '020 is here?
  503.    bne.s _SetCACR_1
  504.    rts                              ; No CACR here, pal
  505.  
  506.    machine mc68020
  507. _SetCACR_1:
  508.    move.l   a5,-(sp)                ; Save this register
  509.    lea   _SetCACR_2,a5              ; Get the start of the supervisor code
  510.    CALLSYS  Supervisor
  511.    move.l   (sp)+,a5                ; Give back register
  512.    rts
  513.  
  514. _SetCACR_2:
  515.    movec d0,cacr                    ; Set the CACR
  516.    rte
  517.    machine mc68000
  518.