OSDN Git Service

added dro2imf to .gitignore
[proj16/16.git] / src / util / cputype.asm
1 ; To assemble the code using MASM 5.10:
2 ;  MASM cputype;
3 ;  LINK cputype;
4 ;  EXE2COM cputype;
5 ;  Version:  1.00b
6
7 ;  Author:  Ben Lunt (Forever Young Software)
8
9 ;  Date:  20 Nov 1997
10
11 ; If you need an EXE to COM converter, you can get one here
12 ;
13 ; The following code won't assemble with NBASM yet, since
14 ;  I have not added all the FPU instructions.  I hope to get to them soon.
15 ;  Until then, you will have to use a different assembler.  Sorry.
16 ;
17
18 CodeSeg    segment
19            assume cs:CodeSeg, ds:CodeSeg, es:CodeSeg
20 .186
21            org  100h
22 start:     mov  ax,cs                   ; free unused part of Mem Block
23            mov  es,ax                   ;   for .COM file format
24            mov  bx,4096                 ;
25            mov  ah,4Ah                  ;
26            int  21h                     ;
27
28            mov  cx,0121h                ; If CH can be shifted by 21h,
29            shl  ch,cl                   ; then it's an 8086, because
30            jz   short p1_8086           ; a 186+ limits shift counts.
31            push sp                      ; If SP is pushed as its
32            pop  ax                      ; original value, then
33            cmp  ax,sp                   ; it's a 286+.
34            jne  short p1_186
35            mov  ax,7000h                ; if bits 12,13,14 are still set
36            push ax                      ; after pushing/poping to/from
37            popf                         ; the flags register then we have
38            pushf                        ; a 386+
39            pop  ax
40            and  ax,7000h
41            cmp  ax,7000h
42            jne  short p1_286            ; it's a 386+
43 .386
44            push bp                      ; Align stack to dword
45            mov  bp,sp
46            and  sp,0FFFCh
47            pushfd                       ; Save eflags
48            cli                          ; No interrupts
49            pushfd                       ; EAX = eflags
50            pop  eax
51            mov  ebx,eax                 ; EBX = eflags
52            xor  eax,40000h              ; Toggle AC bit
53            push eax                     ; Eflags = EAX
54            popfd
55            pushfd                       ; EAX = eflags
56            pop  eax
57            popfd                        ; Restore eflags
58            mov  sp,bp                   ; Restore stack
59            pop  bp
60            cmp  eax,ebx                 ; If the bit was not
61            je   short p1_386            ; reset, it's a 486+
62            pushfd                       ; Save eflags
63            cli                          ; No interrupts
64            pushfd                       ; EAX = eflags
65            pop  eax
66            xor  eax,200000h             ; Toggle ID bit
67            push eax                     ; Eflags = EAX
68            popfd
69            pushfd                       ; EBX = eflags
70            pop  ebx
71            popfd                        ; Restore eflags
72            cmp  eax,ebx                 ; If the bit was not
73            jne  short p1_486            ; reset, it's a 586+
74            mov  dx,offset CPUType5      ; 586+
75            jmp  short cpudone
76 p1_486:    mov  dx,offset CPUType4      ; 486
77            jmp  short cpudone
78 p1_386:    mov  dx,offset CPUType3      ; 386
79            jmp  short cpudone
80 p1_286:    mov  dx,offset CPUType2      ; 286
81            jmp  short cpudone
82 p1_186:    mov  dx,offset CPUType1      ; 186
83            jmp  short cpudone
84 p1_8086:   mov  dx,offset CPUType0      ; 8086
85 cpudone:   mov  ah,09
86            int  21h
87 .186                                    ; make sure we set proc back to 186
88 .8087      fninit                       ; Initialize FPU
89            mov  _Junk,55AAh             ; Set junk value
90            fnstsw _Junk                 ; Store status word
91            cmp  _Junk,0                 ; If it's not 0, no FPU
92            jne  short p2_nofpu
93            fnstcw _Junk                 ; Store control word
94            mov  ax,_Junk                ; If the bits are not the way
95            and  ax,103Fh                ; they should be, no FPU
96            cmp  ax,3Fh
97            jne  short p2_nofpu
98
99            and  _Junk,0FF7Fh            ; Clear interrupt bit
100            fldcw _Junk                  ; Load control word
101            fdisi                        ; Disable interrupts
102            fstcw _Junk                  ; Store control word
103            test _Junk,80h               ; If it changed, it's an 8087
104            jnz  short p2_8087
105 .286                                    ; allowes .287 also
106            finit                        ; Re-initialize
107            fld1                         ; Divide 1 by 0 to get
108            fldz                         ; a positive infinity
109            fdiv
110            fld  st                      ; Get a negative infinity
111            fchs
112            fcompp                       ; Compare them
113            fstsw ax                     ; Store status word
114            sahf                         ; If the FPU thought that they
115            je   short p2_287            ; were equal, it's a 287
116            mov  dx,offset FPUType3      ; 387
117            finit                        ; Init processor
118            jmp  short fputypeD
119 p2_287:    mov  dx,offset FPUType2      ; 287
120            finit                        ; Init processor
121            jmp  short fputypeD
122 p2_8087:   mov  dx,offset FPUType0      ; 8087
123            finit                        ; Init processor
124            jmp  short fputypeD
125 p2_nofpu:  mov  dx,offset FPUType
126 fputypeD:  mov  ah,09
127            int  21h
128 .186
129 .8087
130            ret
131
132
133 _Junk      dw  00h
134 CPUType0   db  13,10,'You have an 8086/88 processor.$'
135 CPUType1   db  13,10,'You have an 186/88 processor.$'
136 CPUType2   db  13,10,'You have an 286 processor.$'
137 CPUType3   db  13,10,'You have an 386 processor.$'
138 CPUType4   db  13,10,'You have an 486 processor.$'
139 CPUType5   db  13,10,'You have an 586 or better processor.$'
140
141 FPUType    db  13,10,"You don't have a math coprocessor.$"
142 FPUType0   db  13,10,'You have an 8087 math coprocessor.$'
143 FPUType2   db  13,10,'You have an 287 math coprocessor.$'
144 FPUType3   db  13,10,'You have an 387 or better math coprocessor.$'
145
146 CodeSeg    ends
147            end  start