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