home *** CD-ROM | disk | FTP | other *** search
/ CD Shareware Magazine 1996 December / CD_shareware_12-96.iso / DOS / Programa / CCDL122.ZIP / LIBS / CMDLINE / SOURCE / CPU.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-10-25  |  3.0 KB  |  162 lines

  1. ;
  2. ; CPU.ASM
  3. ;
  4. ; Return CPU type
  5. ;
  6. ; 0 = 8086
  7. ; 1 = 80186
  8. ; 2 = 80286
  9. ; 3 = 80386
  10. ; 4 = 80486
  11. ;
  12. INCLUDE    rules.asi
  13.  
  14.  
  15. GETINTR    = 035h
  16. SETINTR = 025h
  17. UNDEFINTR = 6
  18. BOUNDINTR = 5
  19.  
  20. ;MAcro fools the assembler by not creating an END statement until needed
  21. ENDEXP    MACRO    Sym,E
  22.     E&NDIF            ; First close the IF
  23.     E&ND    Sym        ; Now END
  24.     ENDM
  25.  
  26.     .386p
  27. Code_Seg@
  28.     assume    ds:nothing, es:nothing, ss:nothing
  29.     ifdef    STANDALONE
  30.     org    100h        ; for TINY version
  31.     endif
  32. PubProc@    CpuType,c
  33.     link@    si
  34.     sub    si,si        ; CPU type = 8086
  35.     mov    al,BOUNDINTR    ; See if BOUND instr failes
  36.     mov    cx, offset Isbound
  37.     call    Taken
  38.     jc    found        ; not taken, 8086
  39.     inc    si        ; assume 80186
  40.     mov    ax, 0ffffh    ; init AX and flags
  41.     clc            ; This will guarantee AX to change
  42.                 ; if the SMSW succeeds
  43.     cli
  44.     mov    cx,sp        ; Clear stack pointer
  45.     sub    sp,sp
  46.     smsw    ax        ; If this 286 instruction fails
  47.                 ; It will look like an ADD AX,SP
  48.                 ; to the 8086
  49.     mov    sp,cx        ; Restore stack pointer
  50.     sti
  51.     inc    ax
  52.     jz    found
  53.     inc    si        ; assume 80286
  54.     mov    al, UNDEFINTR
  55.     mov    cx, offset Undef
  56.     call    Taken
  57.     jc    found        ; not taken,80286
  58.     inc    si        ; assume 80386
  59.         mov       edx,esp
  60.         and       ah,-4
  61.         pushfd
  62.         cli
  63.         pop       eax
  64.         mov       ecx,eax
  65.         xor       eax,40000h
  66.         push      eax
  67.         popfd
  68.         pushfd
  69.         pop       eax
  70.         xor       eax,ecx
  71.         shr       eax,12h
  72.         and       al,+1
  73.         push      ecx
  74.         popfd
  75.         mov       esp,edx
  76.     or    al,al
  77.     jz    found
  78.     inc    si        ; 80486
  79. found:
  80.     mov    ax,si
  81.     unLink@    si
  82.     ifdef    STANDALONE
  83.     push    ax
  84.     mov    dx,offset msg1
  85.     mov    ah,9
  86.     MSDOS@
  87.     pop    ax
  88.     or    al,al
  89.     jz    domsg2
  90.     mov    dl,al        ; Tiny version, display results
  91.     add    dl,'0'
  92.     mov    ah,2
  93.     MSDOS@
  94. domsg2:
  95.     mov    dx,offset msg2
  96.     mov    ah,9
  97.     MSDOS@
  98.     mov    al,0        ; and exit
  99.     mov    ah,4ch
  100.     MSDOS@
  101.     endif
  102.     ret
  103.  
  104. EndProc@    CpuType,c
  105. msg1    db    "CPU type: 80$"
  106. msg2    db    "86$"
  107. Taken    PROC    NEAR
  108.     push    ds        ; Save segs
  109.     push    es
  110.     mov    ah, GETINTR    ; Get old value of interrupt
  111.     MSDOS@
  112.     push    cs        ; Make our own
  113.     pop    ds
  114.     mov    dx, offset istaken
  115.     mov    ah, SETINTR
  116.     MSDOS@
  117.     call    cx        ; Call the routine
  118.     stc            ; Failed, set carry
  119.     jmp    clearint
  120. istaken:
  121.                 ; IF we got here the interrupt was taken
  122.     pop    cx        ; Clear stack of INTR params
  123.     pop    cx
  124.     pop    cx
  125.     pop    cx        ; And the subroutine return
  126.     clc            ; Success, clear carry
  127. clearint:
  128.     pushf
  129.     push    es        ; Restore the interrupt
  130.     pop    ds
  131.     mov    dx,bx
  132.     mov    ah, SETINTR
  133.     MSDOS@
  134.     popf
  135.     pop    es        ; Restore segment regs
  136.     pop    ds
  137.     ret
  138. Taken    ENDP
  139. bounds    dw    5,10
  140. Isbound    PROC    NEAR
  141.     sub    cx,cx        ; Set us out of bounds
  142.     bound    cx,dword ptr [bounds]    ; Check bounds
  143.     db    0c9h        ; MODRM cx,cx, in case this fails
  144.                 ; we want to have no adverse affects
  145.                 ; on an 8086; failure will look like
  146.                 ; PUSH CS; ADD CX,CX
  147.     pop    cx        ; So clear the stack
  148.     ret
  149. Isbound    ENDP
  150. Undef    PROC    NEAR
  151.     db    00fh        ; Undefined 2 byte 386 opcode
  152.     clc            ; So we don't affect anything if 286
  153.     ret
  154. Undef    ENDP
  155.  
  156.  
  157. Code_EndS@
  158.     ifdef    STANDALONE
  159.     ENDEXP CpuType@,E
  160.     else
  161.     ENDEXP ,E
  162.     endif