home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / c / chipsc / chipstc / chipstc.lst < prev    next >
Encoding:
File List  |  1990-02-09  |  20.9 KB  |  314 lines

  1. Turbo Assembler  Version 1.0        02-09-90 21:24:44         Page 1
  2. CHIPSTC.ASM
  3. chips() - CPU and Math Coprocessor (NDP) Type Check
  4.  
  5.       1
  6.       2                              ;   calling convention:
  7.       3                              ;
  8.       4                              ;       int chips( void );
  9.       5                              ;
  10.       6                              ;   returns:
  11.       7                              ;
  12.       8                              ;       tucked away neatly in your AX....
  13.       9                              ;
  14.      10                              ;       you get back   8x if an 8088/8086
  15.      11                              ;                     18x if an 80186/80188
  16.      12                              ;                     28x if an 80286
  17.      13                              ;                     38x if an 80386
  18.      14                              ;                     20x for a NEC V20/V30
  19.      15                              ;                AND
  20.      16                              ;                     xx0 if NO NDP is found
  21.      17                              ;                     xx1 if an 8087
  22.      18                              ;                     xx2 if an 80287
  23.      19                              ;                     xx3 for an 80387
  24.      20                              ;
  25.      21                              ;   OR.....
  26.      22                              ;
  27.      23                              ;   >>> A return of 280 means you got an 80286 machine with no NDP, <<<
  28.      24                              ;   >>> 383 means you have an 80386/80387 rig to work with, and a   <<<
  29.      25                              ;   >>> return of 81 sez that you have 8088/8086 CPU with an 8087.  <<<
  30.      26                              ;   >>> A 200 tells you that you got an NEC V20/V30 without an NDP. <<<
  31.      27                              ;   >>> ETC., Etc., etc.                                            <<<
  32.      28                              ;
  33.      29                              ;   NOTE:
  34.      30                              ;
  35.      31                              ;       There are lotsa ways of handling the way this function returns
  36.      32                              ;       it's data.  For my purposes, I have elected this one because
  37.      33                              ;       it requires only int arithmetic on the caller's end to extract
  38.      34                              ;       all the info I need from the return value.  I think that I'm
  39.      35                              ;       well enough 'commented' in the following code so that you will
  40.      36                              ;       be able to tinker and Putz until you find the best return tech-
  41.      37                              ;       nique for Ur purposes without having to reinvent the wheel.
  42.      38                              ;
  43.      39                              ;     >>>>        Please see TEST.C, enclosed in this .ZIP.      <<<<
  44.      40                              ;
  45.      41                              ;   REFERENCES:
  46.      42                              ;
  47.      43                              ;     _chips is made up of two PROC's, cpu_type and ndp_type.
  48.      44                              ;
  49.      45                              ;       cpu_type is based on uncopyrighted, published logic by
  50.      46                              ;         Clif (that's the way he spells it) Purkiser of Intel -
  51.      47                              ;         Santa Clara.
  52.      48                              ;
  53.      49                              ;       ndp_type is adopted from Ted Forgeron's article in PC
  54.      50                              ;         Tech Journal, Aug '87 p43.
  55.      51                              ;
  56.      52                              ;     In the event of subsequent republication of this function,
  57.      53                              ;       please carry forward reference to these two gentlemen as
  58.      54                              ;       original authors.
  59.      55                              ;
  60.      56                              ;       Copr. 1987      Pat Shea - Psi! (that Copr. is on there cuz my
  61. Turbo Assembler  Version 1.0        02-09-90 21:24:44         Page 2
  62. CHIPSTC.ASM
  63. chips() - CPU and Math Coprocessor (NDP) Type Check
  64.  
  65.      57                              ;                                        lawyer sez I should, but feel
  66.      58                              ;                                        free to hack away!!!    pats.)
  67.      59                              ;
  68.      60                              ;------------------------------------------------------------------------
  69.      61                              ;
  70.      62                              ;     02/09/90  -  Program modified to work with TurboC 2.0:
  71.      63                              ;
  72.      64                              ;     Here is a quick example of how the code is used from TurboC 2.0:
  73.      65                              ;
  74.      66                              ;
  75.      67                              ;         int  chips (void);         ; declare external CHIPS routine
  76.      68                              ;
  77.      69                              ;         main ()
  78.      70                              ;           {
  79.      71                              ;             return (chips ());     ; return result as DOS errorlevel
  80.      72                              ;           }
  81.      73                              ;
  82.      74                              ;
  83.      75                              ;     Notes:
  84.      76                              ;
  85.      77                              ;        1) You need to link the CHIPS.OBJ file into the
  86.      78                              ;           TurboC program with either a project file or
  87.      79                              ;           by adding it to you .LIB libaries.
  88.      80                              ;
  89.      81                              ;        2) The included CHIPS.OBJ file is compiled for
  90.      82                              ;           the Tiny, Small and Compact memory models.
  91.      83                              ;
  92.      84                              ;        3) To use thw Medium, Large and Huge memory
  93.      85                              ;           models refer to pp 366-367 of the Turbo C
  94.      86                              ;           User's Guide manual.
  95.      87                              ;
  96.      88                              ;        4) If you re-assemble this file make sure you use
  97.      89                              ;           case sensitivity on symbols (/ml switch for TASM)
  98.      90                              ;
  99.      91                              ;
  100.      92                              ;                                           - Henrik Schmiediche
  101.      93                              ;
  102.      94
  103.      95
  104.      96 0000                         _TEXT   SEGMENT BYTE PUBLIC 'CODE'
  105.      97                                      ASSUME  CS:_TEXT,DS:DGROUP
  106.      98
  107.      99                                      PUBLIC  _chips
  108.     100
  109.     101 0000                         _chips         PROC NEAR
  110.     102
  111.     103 0000  0000                   control dw     0              ; control word needed for the NDP test
  112.     104
  113.     105 0002  55                             push   BP             ; save where Ur at
  114.     106 0003  8B EC                          mov    BP,SP          ;   going in.....
  115.     107 0005  57                             push   DI
  116.     108 0006  56                             push   SI
  117.     109 0007  51                             push   CX             ; not really needed for MSC but kinda
  118.     110                                                            ;   nice to do cuz someone else might
  119.     111                                                            ;   want to use the function and we do
  120.     112                                                            ;   use CX later on
  121. Turbo Assembler  Version 1.0        02-09-90 21:24:44         Page 3
  122. CHIPSTC.ASM
  123. chips() - CPU and Math Coprocessor (NDP) Type Check
  124.  
  125.     113
  126.     114 0008  E8 000A                        call   cpu_type       ; find out what kinda CPU you got and
  127.     115                                                            ;   and save it in DX for future reference
  128.     116 000B  E8 004E                        call   ndp_type       ; check for math coprocessor (NDP) type
  129.     117                                                            ;   and hold that result in AX
  130.     118
  131.     119 000E  03 C2                          add    AX,DX          ; add the two results together and hold
  132.     120                                                            ;   'em in AX for Ur return to the caller
  133.     121
  134.     122 0010  59                             pop    CX             ; put things back the way that you
  135.     123 0011  5E                             pop    SI             ;   found 'em when you started this
  136.     124 0012  5F                             pop    DI             ;   little drill off.....
  137.     125 0013  5D                             pop    BP
  138.     126                                                            ; AND
  139.     127 0014  C3                             ret                   ; go back to where you came from....
  140.     128                                                            ;   ( ===>  the calling program )
  141.     129                                                            ;   with Ur results sittin' in AX !!
  142.     130 0015                         _chips         endp
  143.     131
  144.     132
  145.     133 0015                         cpu_type       PROC NEAR
  146.     134
  147.     135 0015  9C                             pushf                 ; pump Ur flags register onto the stack
  148.     136 0016  33 D2                          xor    DX,DX          ; blow out Ur DX and AX to start off
  149.     137 0018  33 C0                          xor    AX,AX          ;   with a clean slate
  150.     138 001A  50                             push   AX             ; put AX on the stack
  151.     139 001B  9D                             popf                  ; bring it back in Ur flags
  152.     140 001C  9C                             pushf                 ; try to set bits 12 thru 15 to a zero
  153.     141 001D  58                             pop    AX             ; get back Ur flags word in AX
  154.     142 001E  25 F000                        and    AX, 0f000h     ; if bits 12 thru 15 are set then you got
  155.     143 0021  3D F000                        cmp    AX, 0f000h     ;   an Intel 8018x or a 808x or maybe even
  156.     144 0024  74 16                          jz     dig            ;   a NEC V20/V30 ??? - gotta look more...
  157.     145
  158.     146                              ; OTHERWISE....
  159.     147                              ;   Here's the BIG one.... 'tells the difference between an 80286 and
  160.     148                              ;   an 80386 !!
  161.     149
  162.     150 0026  B8 7000                        mov    AX, 07000h     ; try to set FLAG bits 12 thru 14
  163.     151                                                            ;   - NT, IOPL
  164.     152 0029  50                             push   AX             ; put it onto the stack
  165.     153 002A  9D                             popf                  ;   and try to pump 07000H into Ur flags
  166.     154 002B  9C                             pushf                 ; push Ur flags, again
  167.     155 002C  58                             pop    AX             ;   and bring back AX for a compare
  168.     156 002D  25 7000                        and    AX,07000h      ; if Ur bits 12 thru 14 are set
  169.     157 0030  75 05                          jnz    got386         ;   then Ur workin' with an 80386
  170.     158 0032  BA 0118                        mov    DX, 0280       ; save 280 in DX cuz it's an 80286
  171.     159 0035  EB 23                          jmp    SHORT CPUbye   ;   and bail out
  172.     160
  173.     161 0037  BA 017C                got386: mov    DX, 0380       ; save 380 in DX cuz it's an Intel 80386
  174.     162 003A  EB 1E                          jmp    SHORT CPUbye   ;   and bail out
  175.     163
  176.     164                              ; here's we try to figger out whether it's an 80188/80186, an 8088/8086
  177.     165                              ;   or an NEC V20/V30 - 'couple of slick tricks from Clif Purkiser.....
  178.     166
  179.     167 003C  B8 FFFF                dig:    mov    AX, 0ffffh     ; load up AX
  180.     168 003F  B1 21                          mov    CL, 33         ; HERE's the FIRST TRICK.... this will
  181. Turbo Assembler  Version 1.0        02-09-90 21:24:44         Page 4
  182. CHIPSTC.ASM
  183. chips() - CPU and Math Coprocessor (NDP) Type Check
  184.  
  185.     169                                                            ;   shift everything 33 times if it's
  186.     170                                                            ;   8088/8086, or once for a 80188/80186!
  187.     171 0041  D3 E0                          shl    AX, CL         ; on a shift of 33, all bits get zeroed
  188.     172 0043  74 05                          jz     digmor         ;   out so if anything is left ON it's
  189.     173                                                            ;   gotta be an 80188/80186
  190.     174 0045  BA 00B4                        mov    DX,0180        ; save 180 in DX cuz it's an 80188/80186
  191.     175 0048  EB 10                          jmp    SHORT CPUbye   ;   and bail out
  192.     176
  193.     177 004A  32 C0                  digmor: xor    AL,AL          ; clean out AL to set ZF
  194.     178 004C  B0 40                          mov    AL,40h         ; ANOTHER TRICK.... mul on an NEC duz NOT
  195.     179 004E  F6 E0                          mul    AL             ;   effect the zero flag BUT on an Intel
  196.     180 0050  74 05                          jz     gotNEC         ;   8088/8086, the zero flag gets thrown
  197.     181 0052  BA 0050                        mov    DX,0080        ; 80 into DX cuz it's an Intel 8088/8086
  198.     182 0055  EB 03                          jmp    SHORT CPUbye   ;   and bail out
  199.     183
  200.     184 0057  BA 00C8                gotNEC: mov    DX,0200        ; it's an NEC V20/V30 so save 200 in DX
  201.     185
  202.     186 005A  9D                     CPUbye: popf                  ; putchur flags back to where they were
  203.     187 005B  C3                             ret                   ;   and go back to where you came from
  204.     188                                                            ;   (i.e., ===>  _chips) with the CPU type
  205.     189                                                            ;   tucked away in DX for future reference
  206.     190 005C                         cpu_type       endp
  207.     191
  208.     192                              ; Check for an NDP.
  209.     193                              ;
  210.     194                              ; >>>>NOTE:  If you are using an MASM version < 5.0, don't forget to
  211.     195                              ; use the /R option or you will bomb cuz of the coprocessor instruc-
  212.     196                              ; tions.  /R is not needed for version 5.0.<<<<<<<<<<<<<<<<<<<<<<<<<
  213.     197
  214.     198 005C                         ndp_type       PROC NEAR
  215.     199
  216.     200 005C  DB E3                  do_we:  fninit                          ; try to initialize the NDP
  217.     201 005E  2E: C6 06 0001r 00             mov    byte ptr control+1,0     ; clear memory byte
  218.     202 0064  2E: D9 3E 0000r                fnstcw control                  ; put control word in memory
  219.     203 0069  2E: 8A 26 0001r                mov    AH,byte ptr control+1    ; iff AH is 03h, you got
  220.     204 006E  80 FC 03                       cmp    AH,03h                   ;   an NDP on board !!
  221.     205 0071  74 04                          je     chk_87                   ; found somethin', keep goin'
  222.     206 0073  33 C0                          xor    AX,AX                    ; clean out AX to show a zero
  223.     207 0075  EB 4F                          jmp    SHORT NDPbye             ;   return (i.e., no NDP)
  224.     208
  225.     209                              ; 'got an 8087 ??
  226.     210
  227.     211 0077  2E: 81 26 0000r FF7F   chk_87: and    control,NOT 0080h        ; turn ON interrupts (IEM = 0)
  228.     212 007E  9B 2E: D9 2E 0000r             fldcw  control                  ; load control word
  229.     213 0084  9B DB E1                       fdisi                           ; turn OFF interrupts (IEM = 1)
  230.     214 0087  9B 2E: D9 3E 0000r             fstcw  control                  ; store control word
  231.     215 008D  2E: F7 06 0000r 0080           test   control,0080h            ; iff IEM=1, 8087
  232.     216 0094  74 05                          jz     chk287                   ; 'guess not!  March on....
  233.     217 0096  B8 0001                        mov    AX,0001                  ; set up for a 1 return to
  234.     218 0099  EB 2B                          jmp    SHORT NDPbye             ;   show an 8087 is on board
  235.     219
  236.     220                              ; if not.... would you believe an 80287 maybe ??
  237.     221
  238.     222 009B  9B DB E3               chk287: finit                 ; set default infinity mode
  239.     223 009E  9B D9 E8                       fld1                  ; make infinity
  240.     224 00A1  9B D9 EE                       fldz                  ;   by dividing
  241. Turbo Assembler  Version 1.0        02-09-90 21:24:44         Page 5
  242. CHIPSTC.ASM
  243. chips() - CPU and Math Coprocessor (NDP) Type Check
  244.  
  245.     225 00A4  9B DE F9                       fdiv                  ;   1 by zero !!
  246.     226 00A7  9B D9 C0                       fld    st             ; now make a
  247.     227 00AA  9B D9 E0                       fchs                  ;   negative infinity
  248.     228 00AD  9B DE D9                       fcompp                ; compare Ur two infinities
  249.     229 00B0  9B 2E: DD 3E 0000r             fstsw  control        ; iff, for 8087 or 80287
  250.     230 00B6  9B                             fwait                 ; sit tight 'til status word is put away
  251.     231 00B7  2E: A1 0000r                   mov    AX,control     ; getchur control word
  252.     232 00BB  9E                             sahf                  ; putchur AH into flags
  253.     233 00BC  75 05                          jnz    got387         ; NO GOOD.... march on !!
  254.     234 00BE  B8 0002                        mov    AX,0002        ; gotta be a 80287 cuz we already tested
  255.     235 00C1  EB 03                          jmp    SHORT NDPbye   ;   for an 8087
  256.     236
  257.     237                              ; We KNOW that there is an NDP on board otherwise we would have bailed
  258.     238                              ; out after 'do_we'.  It isn't an 8087 or an 80287 or we wouldn't have
  259.     239                              ; gotten this far.  It's gotta be an 80387 !!
  260.     240
  261.     241 00C3  B8 0003                got387: mov    AX,0003        ; call it an 80387 and return 3
  262.     242
  263.     243 00C6  C3                     NDPbye: ret                   ; and go back where you came from
  264.     244                                                            ;   (i.e., ===>  _chips) carrying the NDP
  265.     245                                                            ;   type in Ur AX register
  266.     246 00C7                         ndp_type       endp
  267.     247
  268.     248 00C7                         _TEXT   ENDS
  269.     249
  270.     250                              ;
  271.     251                              ; The following lines are required for TurboC 2.0:
  272.     252                              ;
  273.     253
  274.     254                              DGROUP  GROUP _DATA
  275.     255
  276.     256 0000                         _DATA   SEGMENT WORD PUBLIC 'DATA'
  277.     257 0000                         _DATA   ENDS
  278.     258
  279.     259                                      END
  280. Turbo Assembler  Version 1.0        02-09-90 21:24:44         Page 6
  281. Symbol Table
  282.  
  283.  
  284. Symbol Name                       Type   Value
  285.  
  286. ??date                            Text   "02-09-90"
  287. ??filename                        Text   "CHIPSTC "
  288. ??time                            Text   "21:24:43"
  289. ??version                         Number 0100
  290. @Cpu                              Text   0101H
  291. @FileName                         Text   CHIPSTC
  292. @WordSize                         Text   2
  293. @curseg                           Text   _DATA
  294. CPUbye                            Near   _TEXT:005A
  295. NDPbye                            Near   _TEXT:00C6
  296. _chips                            Near   _TEXT:0000
  297. chk287                            Near   _TEXT:009B
  298. chk_87                            Near   _TEXT:0077
  299. control                           Word   _TEXT:0000
  300. cpu_type                          Near   _TEXT:0015
  301. dig                               Near   _TEXT:003C
  302. digmor                            Near   _TEXT:004A
  303. do_we                             Near   _TEXT:005C
  304. got386                            Near   _TEXT:0037
  305. got387                            Near   _TEXT:00C3
  306. gotNEC                            Near   _TEXT:0057
  307. ndp_type                          Near   _TEXT:005C
  308.  
  309. Groups & Segments                 Bit Size Align  Combine Class
  310.  
  311. DGROUP                            Group
  312.   _DATA                           16  0000 Word   Public  DATA
  313. _TEXT                             16  00C7 Byte   Public  CODE
  314.