How do I know the processor is in 32 bit mode? (edited by Ernie... does it work now?) This message was edited by Ernie, on 2/6/2001 10:44:43 PM
Posted on 2001-02-06 11:22:00 by Hel
Thats not good!
Posted on 2001-02-06 11:30:00 by Mirno
Knowing if the processor is in 32bit more, well...........im guessing that your not writing a prog for windows (or if its a VxD, i dont know much about that, but isn't certain segments of a VxD, designed to be run in 16 bit mode, and others 32bit). The anyway i can think of to fine out wheater you are in 32bit or 16bit mode is to lookup either the LDT or the GDT, and then test the D bit (sorry, but im basicly coping out of the Intel protected mode manual and that bit is the 22 bit of the second dword (at least I think it is the second)) To lookup the table, this is what is says in the manual...


segment descriptor: (ie: value laoded into ds)
bits: 15       -       3 :     2     :  1&0
      entry in the table : Set = LDT : requested
                         : else GDT  : privilegde level
.data
 GDTBase DWORD ?
 GDT Limit WORD ?
.code

xor eax,eax
mov ax,cs ;get the segment
sgdt Offset GDTBase
.IF (ax & 1 SHL 3) ;If bit 3 is set, we need the ldt
    ;Get the address of the ldt in ebx, im not sure, but i think this is the first entry in the gdt 
.ELSE             ;Else the gdt
    mov ebx,GDTBase
.ENDIF
and ax,NOT 0111b ;same as the entry number * 8

add ebx,eax
.IF ( & 1 SHL 22) ;If this bit is set it is a 32bit segment
    ;you are in a 32bit segment
.ELSE     
    ;you are in a 16bit segment
.ENDIF

The only problem with the above, is that is it designed to run in a 32bit segment, and probably wont work in an 16bit segment. Also, i wrote it and i guarenteee it wont work. Cause i havn't even tested it and i am only going on theory. Here are some things that are related to 32/16 bit mode, protected/real mode: The processor is in protected mode, if CR0.PE (cr0, bit zero) is set else, it is in real mode. (This technicly means you are real mode, and im not sure if it invalidates the gdt, cause i dont think they are needed in real mode.) If the EFLAGS.VM (bit 11) is set, the processor is running is virtual 8086 mode, ie. in proteced mode, but emulating a 8086 program. The processor in 16bit mode, only executes 16bit instructions, and the same for 32bit mode, unless.... the operand size opcode is used, (066h, or 067h for the address size overide) ie: mov eax,eax ;Depending on what mode the processor is in mov ax,ax ;Depends on which of these instructions is executed so say, mov eax,0ffffffffh, will corrupt the instruction stream in 16bit mode, but will run fine in 32bit mode BYTE 066h ;will work fine in 16bit mode, provided the mov eax,0ffffffffh ;processor supports 32bit registers, but not in 32bit mode But anyway, the morale of all this, is 16bit code, should only be run in 16bit mode, cause that will be linked into you app and very well defined, (and the same for 32bit code).
Posted on 2001-02-08 03:18:00 by George