From: jim AT curved-logic DOT com (James Shaw) Newsgroups: comp.os.msdos.programmer,comp.lang.asm.x86,comp.os.msdos.djgpp,comp.unix.pc-clone.32bit Subject: Re: FPU and protected mode Date: Thu, 27 Mar 1997 12:05:42 GMT Organization: None Lines: 95 Message-ID: <333d6018.5876843@snews2.zippo.com> References: <3339DFBB DOT 3A4B AT turbotek DOT co DOT kr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Heo Sung-Gwan wrote: >Hi, > >I am coding FPU context switch with Pentium processor using fnsave and >frstor FPU instructions. And I found these FPU instructions behaves >differently between real mode and protected mode. > >See the following code: > > int i; > char fpusave[124]; > > fpusave[0] = 0x7f; fpusave[1] = 0x03; > fpusave[2] = 0x00; fpusave[3] = 0x00; > fpusave[4] = 0xff; fpusave[5] = 0xff; > > asm { > frstor fpusave > fwait > fnsave fpusave > fwait > } > for( i = 0; i < 124; i++ ) > printf("%x ", fpusave[i]); > >When compiled with bcc -B, it output 7f 03 00 00 ff .... >but when compiled with bcc32 and PMC protectd library, it output 7f 03 >ff ff 7f 7f ..... >Also when compiled with djgpp in DOS and gcc in linux after inline >assembly code is modified, it output the same as bcc32 and PMC lib: 7f >03 ff ff 7f 7f .... > >What happened to FPU in protected mode? The data structures saved out by frstor are different in protected mode and real mode. In real mode the structure is 94 bytes, in pmode it's 108 bytes. The two values you notice that have changed are marked as reserved (and so could contain anything). Real Mode structure controlword:WORD statusword:WORD tagword:WORD ipoffset:WORD csselector:WORD operandoffset:WORD operandselector:WORD V86 structure controlword:WORD statusword:WORD tagword:WORD ip bits 0-15:WORD ip bits 0-19,0,opcode bits 0-10:WORD (opcode is lower bits, ip is higher bits) operand ptr bits 0-15:WORD operand ptr bits 16-19,12 0's:DWORD (ditto) 32bit Real Mode controlword:WORD reserved:WORD statusword:WORD reserved:WORD tagword:WORD reserved:WORD ip bits 0-15:WORD reserved:WORD 0,0,0,0,ip bits 16-31,0,opcode bits 0-10:DWORD operand ptr bits 0-15:WORD reserved:WORD 0,0,0,0,operand ptr bits 16-31,12 0's:DWORD (hi->low bit order) 32bit Protected Mode controlword:WORD reserved:WORD statusword:WORD reserved:WORD tagword:WORD reserved:WORD ip offset:DWORD cs selector:WORD 0,0,0,0,opcode bits 0-10:WORD data operand offset:DWORD operand selector:WORD reserved:WORD All this comes from Pentium Processor Family Developer's Manual Volume 3: Architecture and Programming Manual Ch6 pp17-18 Jim