home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / proasm / routines / typeofprocessor.r < prev   
Text File  |  1995-01-02  |  10KB  |  455 lines

  1.  
  2. ;---;  TypeOfProcessor  ;------------------------------------------------------
  3. *
  4. *    ****    TYPEOFPROCESSOR ROUTINE    ****
  5. *
  6. *    Author        Daniel Weber
  7. *    Version        1.62
  8. *    Start        1992
  9. *    Last Revision    22.12.94
  10. *    Identifier    top_defined
  11. *       Prefix        top_    (TypeOfProcessor)
  12. *                 ¯   ¯ ¯
  13. *    Functions    TypeOfProcessor
  14. *
  15. *    Note        - The result is not compatible with the exec AttnFlags!
  16. *            - About 220 bytes of stack needed.
  17. *            - Don't use TypeOfProcessor() in the supervisor state!
  18. *            - LC060/EC060 dedection same as the LC/EC040.
  19. *
  20. *    Flags        MC.68EC030    - enable special MC68EC030 recognision
  21. *
  22. *    Processors    MC68000
  23. *            MC68010
  24. *            MC68020
  25. *            MC68030
  26. *            MC68040
  27. *            MC68060
  28. *
  29. *            (MC68EC030)    EC
  30. *            MC68EC040
  31. *            MC68EC060
  32. *
  33. *            MC68LC040    LC
  34. *            MC68LC060
  35. *
  36. *            FPU40        Software emulation
  37. *            FPU60        (not supported yet)
  38. *            SP60
  39. *
  40. ;------------------------------------------------------------------------------
  41.  
  42. ;------------------
  43.     ifnd    top_defined
  44. top_defined    equ 1
  45.  
  46. ;------------------
  47. top_oldbase    equ __BASE
  48.     base    top_base
  49. top_base:
  50.  
  51. ;------------------
  52.  
  53.     opt    sto,o+,q+,ow-,qw-
  54.     super
  55.     relax
  56.     mcrelax
  57.     mc68882
  58.     mc68851
  59.  
  60. ;------------------
  61.  
  62.     IFGT    __PRO,137
  63.     FAILAT    1
  64.     FAIL    *** ProAsm version 0.89 or higher required! ***
  65.     ENDC
  66.  
  67.     WARN    *** TypeOfProcessor(): FPU60 recognition not implemented.
  68.  
  69.  
  70. ;------------------------------------------------------------------------------
  71. *
  72. * the most of the below defined symbols are compatible to the C= include files
  73. *
  74. ;------------------------------------------------------------------------------
  75.  
  76. top_def        MACRO            ;smart macro to define a symbol
  77.         IFND    TOPB_\1
  78. TOPB_\1        EQU    \2
  79.         ENDC
  80.         IFND    TOPF_\1
  81. TOPF_\1        EQU    1<<TOPB_\1
  82.         ENDC
  83.         ENDM
  84.  
  85.  
  86.  
  87.     IFND    TOPF_68000
  88. TOPF_68000    EQU    0
  89.     ENDC
  90.  
  91.     top_def    68010,0            ;also set for 68020
  92.     top_def    68020,1            ;also set for 68030
  93.     top_def    68030,2            ;also set for 68040
  94.     top_def    68040,3            ;also set for 68060
  95.     top_def    68881,4            ;also set for 68881
  96.     top_def    68882,5
  97.     top_def    FPU40,6            ;set for 68040FPSP (software emulation)
  98.     top_def    68851_MMU,7        ;not supported by exec
  99.     top_def    68851,7            ;not supported by exec
  100.     top_def    68060,8            ;not supported by exec
  101.     top_def    FPU60,9            ;not supported by exec
  102.     top_def    SP60,10            ;not supported by exec
  103.     top_def    68LC060,11        ;not supported by exec
  104.     top_def    68LC040,12        ;not supported by exec
  105.     top_def    68EC030,13        ;not supported by exec
  106.     top_def    68EC040,14        ;not supported by exec
  107.     top_def    68EC060,15        ;not supported by exec
  108.  
  109.  
  110.  
  111.     IFND    TOPF_MASK
  112. top_TOPF_MASK    equ    TOPF_68010|TOPF_68020|TOPF_68030
  113. top_TOPF_MASK    set    top_TOPF_MASK|TOPF_68040|TOPF_68EC030|TOPF_68EC040
  114. top_TOPF_MASK    set    top_TOPF_MASK|TOPF_68060
  115. top_TOPF_MASK    set    top_TOPF_MASK|TOPF_68LC040
  116. ;top_TOPF_MASK    set    top_TOPF_MASK|TOPF_FPU60|TOPF_SP60|TOPF_68EC060|TOPF_68LC060
  117.  
  118. TOPF_MASK    equ    top_TOPF_MASK
  119.     ENDC
  120.  
  121.  
  122.  
  123. *
  124. * The TOPB_FPU40 bit is set when a working 68040 FPU
  125. * is in the system.  If this bit is set and both the
  126. * TOPB_68881 and TOPB_68882 bits are not set, then the 68040
  127. * math emulation code has not been loaded and only 68040
  128. * FPU instructions are available.  This bit is valid *ONLY*
  129. * if the TOPB_68040 bit is set.
  130. *
  131.  
  132.  
  133.  
  134.  
  135.  
  136. ;------------------------------------------------------------------------------
  137. *
  138. * TypeOfProcessor  - Get the current CPU/FPU/MMU
  139. *
  140. * INPUT:    none
  141. *
  142. * RESULT:    D0:  attn flags (more or less V37 compatible,
  143. *                 except the MMU and 'ECs flags)
  144. *
  145. ;------------------------------------------------------------------------------
  146.  
  147. TypeOfProcessor:
  148.     movem.l    d1-a6,-(a7)
  149.     move.l    (4).w,a6
  150.     moveq    #1,d2            ;delete upper word of d2 for later use
  151.     
  152.     move.b (.top_flager-1.b,pc,d2*2),d0
  153.     bne.s  .turbo
  154.  
  155. ;------------------
  156.     move.l    (276,a6),a1        ;*thistask
  157.     move.l    (50,a1),a2        ;save old tc_trapcode
  158.     mea    (\ProcExHd10,pc),(50,a1) ;new tc_trapcode
  159.     moveq    #0,d2
  160.  
  161.     move    ccr,d0            ;68010 only instruction
  162.     moveq    #TOPF_68010,d2        ;set to 68010
  163.  
  164.     move.l    a2,(50,a1)        ;set handler back
  165.     bra.s    \gotit
  166.  
  167. ;------------------
  168. .top_flager:    dc.b 0,-1        ;flags for the 32/16 bit processor test
  169.  
  170.  
  171. ;----------------------------
  172. .turbo:    lea    (\cacher,pc),a5        ;68020/30/40/60
  173.     jsr    (-30,a6)        ;supervisor()
  174.  
  175.     move.w    #TOPF_68060|TOPF_68040|TOPF_68030|TOPF_68020|TOPF_68010,d2
  176.     btst    #14,d0                ;test NAI
  177.     bne.s    \gotit
  178.     moveq    #TOPF_68040|TOPF_68030|TOPF_68020|TOPF_68010,d2
  179.     tst.w    d0
  180.     bmi.s    \gotit
  181.     moveq    #TOPF_68030|TOPF_68020|TOPF_68010,d2
  182.     btst    #8,d0            ;ED, 68030 only
  183.     bne.s    \gotit
  184.     moveq    #TOPF_68020|TOPF_68010,d2    ;68020! must be...
  185.  
  186.  
  187. ;------------------------------------------------
  188. *
  189. * recognise a possible 68851 & 68060
  190. *
  191. \gotit:    move.l    (276,a6),a1
  192.     move.l    (50,a1),a2        ;save old tc_trapcode
  193.     mea    (\MMUExHd,pc),(50,a1)    ;new tc_trapcode
  194.  
  195.     btst    #TOPB_68040,d2        ;68040? (following PMOVE'll be sensless)
  196.     bne.s    .68060
  197.  
  198.     subq.l    #4,a7
  199.     pmove    tc,(sp)            ;try MMU exception (f-line/priviledge)
  200.     nop
  201.     nop
  202.     addq.l    #4,sp
  203.     btst    #TOPB_68030,d2        ;68030?
  204.     bne.s    \cpummu
  205.     tst.w    d0
  206.     beq.s    .68851
  207. ;    move.w    #TOPF_68851,d0        ;68EC030/040 (not supported by the exec)
  208. \pmmu:    or.w    d0,d2            ;set 68851 bit (or 68EC0x0 bit)
  209.  
  210.  
  211.     IFD    MC.68030
  212.     bra.s    \endEC030    
  213. \cpummu:                ;68030 only
  214.     bsr    top_EC030
  215.     tst.l    d0
  216.     beq.s    \endEC030
  217.     eor.w    #TOPF_68030|TOPF_68EC030,d2 ;(before: 030 set / EC cleared)
  218. \endEC030:
  219.     ELSE
  220. \cpummu:
  221.     ENDC
  222.  
  223.  
  224. ;------------------
  225. .68060:    btst    #TOPB_68060,d2        ;only if 68060 dedected yet...
  226.     beq.s    .68851
  227. .60SP:    moveq    #1,d0
  228.     moveq    #1,d1
  229.     mulu.l    d1,d0:d1        ;unimplemented integer instruction
  230.     nop                ;\MMUExHd still installed
  231.     nop                ;means: d0: 0 -> no SP60 installed
  232.     tst.w    d0            ;       d0: - -> SP60 installed
  233.     beq.s    .68851
  234.     or.w    #TOPF_SP60,d2        ;68060 software-supported instructions
  235.  
  236. ;------------------
  237. .68851:    btst    #TOPB_68851_MMU,d2    ;may i dedect a 68EC0x0 togehter
  238.     bne.s    .68851            ;with a 68851?
  239. \tst68851:
  240.     psbc    d1            ;68851 only instr. psr not affected
  241.     nop
  242.     nop                ;one would be enough!!!
  243.     tst.w    d0            ;PScc is a priviledged instruction
  244.     beq.s    0$
  245.     or.w    #TOPF_68851,d2        ;it's a 68851 installed!!!
  246. 0$:
  247.  
  248.  
  249. ;------------------------------------------------
  250. *
  251. * recognise a FPU...
  252. *
  253. * a1: taskstructure
  254. * a2: old trapcode
  255. *
  256.     moveq    #-1,d0
  257.     fnop                ;detect a FPU (same handler like MMU)
  258.     nop
  259.     nop
  260.     tst.l    d0
  261.     bne.s    \fpu1
  262.     bclr    #TOPB_68040,d2
  263.     beq.s    \nofpu
  264.  
  265. \LC_EC:    lea    (\getLCEC,pc),a5
  266.     move.l    (4).w,a6
  267.     jsr    (-30,a6)        ;_LVOSupervisor
  268.  
  269.     bclr    #TOPB_68060,d2
  270.     bne.s    2$
  271.     tst.w    d0            ;M68040
  272.     bne.s    1$
  273.     bset    #TOPB_68EC040,d2    ;68EC040 (no MMU available)
  274.     bra.s    \nofpu
  275. 1$:    bset    #TOPB_68LC040,d2    ;68LC040 (MMU available)
  276.     bra.s    \nofpu
  277.  
  278. 2$:    tst.w    d0            ;M68060
  279.     bne.s    21$
  280.     bset    #TOPB_68EC060,d2    ;68EC060 (no MMU available)
  281.     bra.s    \nofpu
  282. 21$:    bset    #TOPB_68LC060,d2    ;68LC060 (MMU available)
  283.     bra.s    \nofpu
  284.  
  285.  
  286. ;------------------
  287. \fpu1:    moveq    #0,d1            ;get FPU type (68881/2/68040)
  288.     lea    (\getFPU,pc),a5
  289.     move.l    (4).w,a6
  290.     jsr    (-30,a6)        ;supervisor()
  291.     or.w    d0,d2            ;set the reckon FPU
  292.  
  293. ;------------------
  294.     btst    #TOPB_68040,d2        ;check for a software emulation
  295.     beq.s    \nofpu
  296.     and.w    #~(TOPF_68881|TOPF_68882),d2
  297.     moveq    #-1,d0
  298.     fmove.s    #1.23123123,fp0
  299.     fsin    fp0            ;or use 'fmovecr #$00,fp0 ;(PI)'
  300.     fnop                ;force exception
  301.     nop
  302.     nop    
  303.     tst.l    d0            ;d0=0 no 68040FPSP
  304.     beq.s    \nofpu
  305.     or.w    #TOPF_68881|TOPF_68882,d2
  306.  
  307. ;------------------------------------------------
  308. \nofpu:    move.l    a2,(50,a1)        ;restore tc_trapcode
  309.     move.l    a4,a5            ;restore database
  310.     move.l    d2,d0
  311.     movem.l    (a7)+,d1-a6
  312.     rts
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319. ;------------------------------------------------------------------------------
  320. *
  321. * subroutines, exception handlers,...
  322. *
  323. ;------------------------------------------------------------------------------
  324.  
  325. ;----------------------------------------------------------
  326. *
  327. * use cache to reckon the 68020/30/40/60 processors
  328. *
  329. * => d0: $0000    --> 68020 installed    no data cache etc.
  330. *     $0100    --> 68030 installed    68030 data cache
  331. *     $8000    --> 68040 installed    68040 instruction cache
  332. *     $4000    --> 68060 installed    68060 no alloc. mode (instruction cache)
  333. *
  334. \cacher:
  335.     movec    cacr,d1            ;save cacr
  336.     move.l    d1,d0
  337.     bclr    #0,d0            ;disable instruction cache
  338.     or.w    #$c100,d0        ;enable data cache (8), 68040 cache (15), 68060 NAI (14)
  339.     movec    d0,cacr            ;for processor testing only...
  340.     movec    cacr,d0
  341.     movec    d1,cacr            ;restore cacr
  342.     rte
  343.  
  344. ;------------------------------------------------
  345. *
  346. * hadle the excpetion for the processor test (68010: move ccr,d0)
  347. *
  348. \ProcExHd10:
  349.     addq.l    #4,a7            ;must be an illegal....
  350.     moveq    #TOPF_68000,d0        ;68000
  351.     addq.l    #4,(2,a7)        ;back after the 'moveq #1,d2'
  352.     rte 
  353.  
  354.  
  355. ;------------------------------------------------
  356. *
  357. * handle the line-f exception for the pmove/fnop/... instructions,
  358. * returns the TOPF_68851 bit for the MMU-instruction and
  359. * D0=0 for a none existing FPU.
  360. *
  361. * => d0: 0: failed (line-f)   TOPF_68851: successful
  362. *
  363. \MMUExHd:
  364.     move.l    (a7)+,d0        ;exception
  365.     cmp.w    #11,d0            ;line-f or higher (for FPU stuff)
  366.     bge.s    \nommu
  367.     moveq.l    #TOPF_68851,d0
  368.     addq.l    #4,(2,sp)        ;skip an MMU instruction
  369.     rte
  370.  
  371. \nommu:    moveq    #0,d0
  372.     addq.l    #4,(2,sp)        ;skip MMU instruction or FNOP
  373.     rte
  374.  
  375.  
  376. ;------------------------------------------------
  377. *
  378. * get the FPU type...
  379. *
  380. * => d0: TOPF_(FPUtype)
  381. *
  382. \getFPU:
  383.     fsave    -(a7)            ;save internal state
  384.     fmove.x    fp0,-(a7)
  385.     fmove.s    #1.99319921991E2,fp0    ;just a nice number
  386.     fsqrt    fp0            ;just another nice number
  387.     fsave    -(a7)
  388.  
  389. .f81:    moveq    #TOPF_68881,d0
  390.     move.b    1(a7),d1
  391.     cmp.b    #$18,d1            ;state frame size: idle state '81
  392.     beq.s    .xfpu
  393.     cmp.b    #$b4,d1            ;busy state '81
  394.     beq.s    .xfpu
  395. .f82:    moveq    #TOPF_68882|TOPF_68881,d0
  396.     cmp.b    #$38,d1            ;idle state '82
  397.     beq.s    .xfpu
  398.     cmp.b    #$d4,d1            ;busy state '82
  399.     beq.s    .xfpu
  400. .f40:    moveq    #TOPF_FPU40,d0        ;internal 68040 FPU
  401.     cmp.b    #$40,(a7)        ;version...
  402.     beq.s    .xfpu
  403.     cmp.b    #$41,(a7)        ;version...
  404.     beq.s    .xfpu
  405.  
  406.     moveq    #TOPF_68881,d0        ;not sure... -> MC68881
  407.  
  408. .xfpu:    frestore (a7)+
  409.     fmove.x  (a7)+,fp0
  410.     frestore (a7)+            ;restore internal state
  411.     rte
  412.  
  413.  
  414. ;------------------------------------------------
  415. *
  416. * 68LC040 or 68EC040
  417. * 68LC060 or 68EC060
  418. *
  419. * ???
  420. *
  421. * The code assumes that if the MMU is not on that the ITTx/DTTx registers
  422. * are set up like from the OS to map all of memory such that they override
  423. * any MMU settings (thus making the turn-on of the MMU a "NO-OP")
  424. *
  425. * => d0:  0: EC040, -: LC040
  426. *
  427. \getLCEC:
  428.     or.w    #$0700,sr        ;don't get interrupted...
  429.     movec    tc,d1
  430.     move.l    d1,d0            ;keep the page size...
  431.     bne.s    \LC_
  432.     or.w    #$8000,d0        ;turn on MMU
  433.     movec    d0,tc
  434.     movec    tc,d0
  435.     movec    d1,tc            ;restore MMU (turn off MMU)
  436. \LC_:    rte
  437.  
  438.  
  439. ;--------------------------------------------------------------------
  440.  
  441.     IFD    MC.68EC030
  442.     include    EC030.r
  443.     ENDC
  444.  
  445. ;--------------------------------------------------------------------
  446.  
  447.     base    top_oldbase
  448.     opt    rcl
  449.  
  450. ;------------------
  451.     endif
  452.  
  453.  end
  454.  
  455.