home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / HARDWARE / SHOW285.ZIP / CHIPS.ASM next >
Encoding:
Assembly Source File  |  1987-09-21  |  9.3 KB  |  217 lines

  1. page    60,132
  2. title   chips() - CPU and Math Coprocessor (NDP) Type Check
  3.  
  4. ;   calling convention:
  5. ;
  6. ;       int chips( void );
  7. ;
  8. ;   returns:
  9. ;
  10. ;       tucked away neatly in your AX....
  11. ;
  12. ;       you get back   8x if an 8088/8086
  13. ;                     18x if an 80186/80188
  14. ;                     28x if an 80286
  15. ;                     38x if an 80386
  16. ;                     20x for a NEC V20/V30
  17. ;                AND
  18. ;                     xx0 if NO NDP is found
  19. ;                     xx1 if an 8087
  20. ;                     xx2 if an 80287
  21. ;                     xx3 for an 80387
  22. ;
  23. ;   OR.....
  24. ;
  25. ;   >>> A return of 280 means you got an 80286 machine with no NDP, <<<
  26. ;   >>> 383 means you have an 80386/80387 rig to work with, and a   <<<
  27. ;   >>> return of 81 sez that you have 8088/8086 CPU with an 8087.  <<<
  28. ;   >>> A 200 tells you that you got an NEC V20/V30 without an NDP. <<<
  29. ;   >>> ETC., Etc., etc.                                            <<<
  30. ;
  31. ;   NOTE:
  32. ;
  33. ;       There are lotsa ways of handling the way this function returns
  34. ;       it's data.  For my purposes, I have elected this one because
  35. ;       it requires only int arithmetic on the caller's end to extract
  36. ;       all the info I need from the return value.  I think that I'm
  37. ;       well enough 'commented' in the following code so that you will
  38. ;       be able to tinker and Putz until you find the best return tech-
  39. ;       nique for Ur purposes without having to reinvent the wheel.
  40. ;
  41. ;     >>>>        Please see TEST.C, enclosed in this .ARC.      <<<<
  42. ;
  43. ;   REFERENCES:
  44. ;
  45. ;     _chips is made up of two PROC's, cpu_type and ndp_type.
  46. ;
  47. ;       cpu_type is based on uncopyrighted, published logic by
  48. ;         Clif (that's the way he spells it) Purkiser of Intel -
  49. ;         Santa Clara.
  50. ;
  51. ;       ndp_type is adopted from Ted Forgeron's article in PC
  52. ;         Tech Journal, Aug '87 p43.
  53. ;
  54. ;     In the event of subsequent republication of this function,
  55. ;       please carry forward reference to these two gentlemen as
  56. ;       original authors.
  57. ;
  58. ;       Copr. 1987      Pat Shea - Psi! (that Copr. is on there cuz my
  59. ;                                        lawyer sez I should, but feel
  60. ;                                        free to hack away!!!    pats.)
  61. ;
  62.  
  63. _text   SEGMENT BYTE PUBLIC 'CODE'
  64.         ASSUME  CS:_text
  65.  
  66.         PUBLIC  _chips
  67.  
  68. _chips         PROC NEAR
  69.  
  70. control dw     0              ; control word needed for the NDP test
  71.  
  72.         push   BP             ; save where Ur at
  73.         mov    BP,SP          ;   going in.....
  74.         push   DI
  75.         push   SI
  76.         push   CX             ; not really needed for MSC but kinda
  77.                               ;   nice to do cuz someone else might
  78.                               ;   want to use the function and we do
  79.                               ;   use CX later on
  80.  
  81.         call   cpu_type       ; find out what kinda CPU you got and
  82.                               ;   and save it in DX for future reference
  83.         call   ndp_type       ; check for math coprocessor (NDP) type
  84.                               ;   and hold that result in AX
  85.  
  86.         add    AX,DX          ; add the two results together and hold
  87.                               ;   'em in AX for Ur return to the caller
  88.  
  89.         pop    CX             ; put things back the way that you
  90.         pop    SI             ;   found 'em when you started this
  91.         pop    DI             ;   little drill off.....
  92.         pop    BP
  93.                               ; AND
  94.         ret                   ; go back to where you came from....
  95.                               ;   ( ===>  the calling program )
  96.                               ;   with Ur results sittin' in AX !!
  97. _chips         endp
  98.  
  99.  
  100. cpu_type       PROC NEAR
  101.  
  102.         pushf                 ; pump Ur flags register onto the stack
  103.         xor    DX,DX          ; blow out Ur DX and AX to start off
  104.         xor    AX,AX          ;   with a clean slate
  105.         push   AX             ; put AX on the stack
  106.         popf                  ; bring it back in Ur flags
  107.         pushf                 ; try to set bits 12 thru 15 to a zero
  108.         pop    AX             ; get back Ur flags word in AX
  109.         and    AX, 0f000h     ; if bits 12 thru 15 are set then you got
  110.         cmp    AX, 0f000h     ;   an Intel 8018x or a 808x or maybe even
  111.         jz     dig            ;   a NEC V20/V30 ??? - gotta look more...
  112.  
  113. ; OTHERWISE....
  114. ;   Here's the BIG one.... 'tells the difference between an 80286 and
  115. ;   an 80386 !!
  116.  
  117.         mov    AX, 07000h     ; try to set FLAG bits 12 thru 14
  118.                               ;   - NT, IOPL
  119.         push   AX             ; put it onto the stack
  120.         popf                  ;   and try to pump 07000H into Ur flags
  121.         pushf                 ; push Ur flags, again
  122.         pop    AX             ;   and bring back AX for a compare
  123.         and    AX,07000h      ; if Ur bits 12 thru 14 are set
  124.         jnz    got386         ;   then Ur workin' with an 80386
  125.         mov    DX, 0280       ; save 280 in DX cuz it's an 80286
  126.         jmp    SHORT CPUbye   ;   and bail out
  127.  
  128. got386: mov    DX, 0380       ; save 380 in DX cuz it's an Intel 80386
  129.         jmp    SHORT CPUbye   ;   and bail out
  130.  
  131. ; here's we try to figger out whether it's an 80188/80186, an 8088/8086
  132. ;   or an NEC V20/V30 - 'couple of slick tricks from Clif Purkiser.....
  133.  
  134. dig:    mov    AX, 0ffffh     ; load up AX
  135.         mov    CL, 33         ; HERE's the FIRST TRICK.... this will
  136.                               ;   shift everything 33 times if it's
  137.                               ;   8088/8086, or once for a 80188/80186!
  138.         shl    AX, CL         ; on a shift of 33, all bits get zeroed
  139.         jz     digmor         ;   out so if anything is left ON it's
  140.                               ;   gotta be an 80188/80186
  141.         mov    DX,0180        ; save 180 in DX cuz it's an 80188/80186
  142.         jmp    SHORT CPUbye   ;   and bail out
  143.  
  144. digmor: xor    AL,AL          ; clean out AL to set ZF
  145.         mov    AL,40h         ; ANOTHER TRICK.... mul on an NEC duz NOT
  146.         mul    AL             ;   effect the zero flag BUT on an Intel
  147.         jz     gotNEC         ;   8088/8086, the zero flag gets thrown
  148.         mov    DX,0080        ; 80 into DX cuz it's an Intel 8088/8086
  149.         jmp    SHORT CPUbye   ;   and bail out
  150.  
  151. gotNEC: mov    DX,0200        ; it's an NEC V20/V30 so save 200 in DX
  152.  
  153. CPUbye: popf                  ; putchur flags back to where they were
  154.         ret                   ;   and go back to where you came from
  155.                               ;   (i.e., ===>  _chips) with the CPU type
  156.                               ;   tucked away in DX for future reference
  157. cpu_type       endp
  158.  
  159. ; Check for an NDP.
  160. ;
  161. ; >>>>NOTE:  If you are using an MASM version < 5.0, don't forget to
  162. ; use the /R option or you will bomb cuz of the coprocessor instruc-
  163. ; tions.  /R is not needed for version 5.0.<<<<<<<<<<<<<<<<<<<<<<<<<
  164.  
  165. ndp_type       PROC NEAR
  166.  
  167. do_we:  fninit                          ; try to initialize the NDP
  168.         mov    byte ptr control+1,0     ; clear memory byte
  169.         fnstcw control                  ; put control word in memory
  170.         mov    AH,byte ptr control+1    ; iff AH is 03h, you got
  171.         cmp    AH,03h                   ;   an NDP on board !!
  172.         je     chk_87                   ; found somethin', keep goin'
  173.         xor    AX,AX                    ; clean out AX to show a zero
  174.         jmp    SHORT NDPbye             ;   return (i.e., no NDP)
  175.  
  176. ; 'got an 8087 ??
  177.  
  178. chk_87: and    control,NOT 0080h        ; turn ON interrupts (IEM = 0)
  179.         fldcw  control                  ; load control word
  180.         fdisi                           ; turn OFF interrupts (IEM = 1)
  181.         fstcw  control                  ; store control word
  182.         test   control,0080h            ; iff IEM=1, 8087
  183.         jz     chk287                   ; 'guess not!  March on....
  184.         mov    AX,0001                  ; set up for a 1 return to
  185.         jmp    SHORT NDPbye             ;   show an 8087 is on board
  186.  
  187. ; if not.... would you believe an 80287 maybe ??
  188.  
  189. chk287: finit                 ; set default infinity mode
  190.         fld1                  ; make infinity
  191.         fldz                  ;   by dividing
  192.         fdiv                  ;   1 by zero !!
  193.         fld    st             ; now make a
  194.         fchs                  ;   negative infinity
  195.         fcompp                ; compare Ur two infinities
  196.         fstsw  control        ; iff, for 8087 or 80287
  197.         fwait                 ; sit tight 'til status word is put away
  198.         mov    AX,control     ; getchur control word
  199.         sahf                  ; putchur AH into flags
  200.         jnz    got387         ; NO GOOD.... march on !!
  201.         mov    AX,0002        ; gotta be a 80287 cuz we already tested
  202.         jmp    SHORT NDPbye   ;   for an 8087
  203.  
  204. ; We KNOW that there is an NDP on board otherwise we would have bailed
  205. ; out after 'do_we'.  It isn't an 8087 or an 80287 or we wouldn't have
  206. ; gotten this far.  It's gotta be an 80387 !!
  207.  
  208. got387: mov    AX,0003        ; call it an 80387 and return 3
  209.  
  210. NDPbye: ret                   ; and go back where you came from
  211.                               ;   (i.e., ===>  _chips) carrying the NDP
  212.                               ;   type in Ur AX register
  213. ndp_type       endp
  214.  
  215. _text   ends
  216.         end
  217.