Lecture 21. _getproc proc near pushf ;Secure flag register contents push di ;== Determine whether...

15
Lecture 21

Transcript of Lecture 21. _getproc proc near pushf ;Secure flag register contents push di ;== Determine whether...

Page 1: Lecture 21. _getproc proc near pushf ;Secure flag register contents push di ;== Determine whether model came before or after 80286 === xor ax,ax ;Set.

Lecture 21

Page 2: Lecture 21. _getproc proc near pushf ;Secure flag register contents push di ;== Determine whether model came before or after 80286 === xor ax,ax ;Set.

_getproc proc near

pushf ;Secure flag register contents push di

;== Determine whether model came before or after 80286 ===

xor ax,ax ;Set AX to 0 push ax ;and push onto stack popf ;Pop flag register off of stack pushf ;Push back onto stack pop ax ;and pop off of AX and ax,0f000h ;Do not clear the upper four bits cmp ax,0f000h ;Are bits 12 - 15 all equal to 1? je not_286_386 ;YES --> Not 80386 or 80286

Page 3: Lecture 21. _getproc proc near pushf ;Secure flag register contents push di ;== Determine whether model came before or after 80286 === xor ax,ax ;Set.

;-- Test for determining whether 80486, 80386 or 80286 ------

mov dl,p_80286 ;In any case, it's one of the mov ax,07000h ;three processors push ax ;Push 07000h onto stack popf ;Pop flag register off pushf ;and push back onto the stack pop ax ;Pop into AX register and ax,07000h ;Mask everything except bits 12-14 je pende ;Are bits 12 - 14 all equal to 0?

;YES --> It's an 80286 inc dl ;No --> it's either an 80386 or an

;80486. First set to 386

Page 4: Lecture 21. _getproc proc near pushf ;Secure flag register contents push di ;== Determine whether model came before or after 80286 === xor ax,ax ;Set.

cli ;No interrupts now mov ebx,offset array mov [ebx],eax pushfd pop eax mov first,eax;

mov [ebx+1],eax pushfd pop eax shr first,18 shr eax,18 and first,1 and eax,1 cmp first,eax inc dl

sti jne pende

Page 5: Lecture 21. _getproc proc near pushf ;Secure flag register contents push di ;== Determine whether model came before or after 80286 === xor ax,ax ;Set.

pushfdpop eaxmov temp, eax mov eax,1shl eax,21push eaxpopfdpushfdpop eaxshr eax,21shr temp,21cmp temp, eaxinc dlje pende

jmp pende ;Test is ended

Page 6: Lecture 21. _getproc proc near pushf ;Secure flag register contents push di ;== Determine whether model came before or after 80286 === xor ax,ax ;Set.

#include "stdafx.h"#include <stdio.h>#include <dos.h>unsigned long int id[3];unsigned char ch='\0';unsigned int steppingid ;unsigned int model,family,type1;unsigned int cpcw;int main(int argc, char* argv[]){

_asm xor eax,eax_asm cpuid_asm mov id[0], ebx;_asm mov id[4], edx;_asm mov id[8], ecx;printf("%s\n ", (char *) (id));_asm mov eax,1_asm cpuid_asm mov ecx,eax_asm AND eax,0xf;_asm mov steppingid,eax;_asm mov eax, ecx

Page 7: Lecture 21. _getproc proc near pushf ;Secure flag register contents push di ;== Determine whether model came before or after 80286 === xor ax,ax ;Set.

_asm shr eax,4_asm and eax, 0xf;_asm mov model,eax_asm mov eax,ecx_asm shr eax,8_asm and eax, 0xf_asm mov family,eax;_asm mov eax,ecx_asm shr eax,12_asm and eax, 0x3;_asm mov type1, eax;printf("\nstepping is %d\n model is %d\n

Family is %d\nType is%d\n",steppingid,model,family,type1);

}

Page 8: Lecture 21. _getproc proc near pushf ;Secure flag register contents push di ;== Determine whether model came before or after 80286 === xor ax,ax ;Set.

void main{

_asm finit_asm mov byte ptr cpcw+1, 0;_asm fstcw cpcwif ( *(((char *) (&cpcw))+1)==3)

puts("Coprocessor found");else

puts ("Coprocessor not found");}

Page 9: Lecture 21. _getproc proc near pushf ;Secure flag register contents push di ;== Determine whether model came before or after 80286 === xor ax,ax ;Set.

_getco proc near mov dx,co_none mov byte ptr cs:wait1,NOP_CODE mov byte ptr cs:wait2,NOP_CODE

wait1: finit mov byte ptr cpz+1,0

wait2: fstcw cpz cmp byte ptr cpz+1,3 jne gcende

;-- Coprocessor exists. Test for 8087 --- inc dx and cpz,0FF7Fh fldcw cpz fdisi fstcw cpz test cpz,80h jne gcende

Page 10: Lecture 21. _getproc proc near pushf ;Secure flag register contents push di ;== Determine whether model came before or after 80286 === xor ax,ax ;Set.

;-- Test for 80287/80387 ---- inc dx finit fld1 fldz fdiv fld st fchs fcompp fstsw cpz mov ah,byte ptr cpz+1 sahf je gcende

inc dx gcende: mov ax,dx

ret _getco endp

Page 11: Lecture 21. _getproc proc near pushf ;Secure flag register contents push di ;== Determine whether model came before or after 80286 === xor ax,ax ;Set.

KeyBoard Interface

64H

60H

Processor

INTR

PICIRQ1

Synchronous Data Keyboard

Page 12: Lecture 21. _getproc proc near pushf ;Secure flag register contents push di ;== Determine whether model came before or after 80286 === xor ax,ax ;Set.

7 6 5 4 3 2 1 0

Port 64H Status Register

1 = Output Buffer full

1 = Input Buffer full

1 = Keyboard Active

1 = Parity Error

1 = Time Out Error during input

1 = Time Out Error during output

Page 13: Lecture 21. _getproc proc near pushf ;Secure flag register contents push di ;== Determine whether model came before or after 80286 === xor ax,ax ;Set.

Typematic Rate

Typematic Rate11111 = 2 char/s11110 = 2.1 char/s11101 = 2.3 char/s11010 = 3 char/s::::::::::::::::::::::::::::::::00100 = 20 char/s00011 = 21.8 char/s00010 = 24 char/s00001 = 26.7 char/s00000 = 30 char/s

Delay00 ¼ Second01 ½ Second10 ¼ Second11 1 Second

7 6 5 4 3 2 1 0

Page 14: Lecture 21. _getproc proc near pushf ;Secure flag register contents push di ;== Determine whether model came before or after 80286 === xor ax,ax ;Set.

Sending bytes to the Keyboard

60H

64H

Input from Keyboard

Input buffer full

Page 15: Lecture 21. _getproc proc near pushf ;Secure flag register contents push di ;== Determine whether model came before or after 80286 === xor ax,ax ;Set.

Sending bytes to the Keyboard

60H

64H

From Processor

Output buffer full

Later on

Receives 0xFA to indicate successful transmission