VOGONS


First post, by superfury

User metadata
Rank l33t++
Rank
l33t++

How should a x86 emulator respond to FPU opcodes (FWAIT and ESC) without a FPU present? I've just adjusted FINIT to do nothing, FSTSW, FNSTSW and FNSTCW to write FFFFh to the destination r/m16. And all other FPU opcodes do nothing (NOP).

And when CR0.TS or CR0.EM is set, it will trigger a #NM exception to allow the software to emulate it properly (or fault if it wants to).

What happens on real hardware with this x86 CPU without FPU? How is it actually detected to be properly not present?

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 2 of 4, by superfury

User metadata
Rank l33t++
Rank
l33t++

I've already made those opcodes write all-ones to memory or registers when used (for those mentioned FPU opcodes that save the state or status word). Dind't implement any non-1 data fields in the data yet.

But the BIOS still thinks that there is a FPU present, which there isn't. And the BIOS itself is too large (lots of nested functions) to easily figure out what's causing this issue.

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 3 of 4, by GloriousCow

User metadata
Rank Oldbie
Rank
Oldbie

I am not sure about other CPUs, but on the 8088 an ESC opcode reads the modr/m operand (always a read) and does nothing with it. So if you are writing anything I expect that may be your problem.

MartyPC: A cycle-accurate IBM PC/XT emulator | web version: https://martypc.net | https://github.com/dbalsom/martypc

Reply 4 of 4, by superfury

User metadata
Rank l33t++
Rank
l33t++
GloriousCow wrote on 2026-10-13, 17:22:

I am not sure about other CPUs, but on the 8088 an ESC opcode reads the modr/m operand (always a read) and does nothing with it. So if you are writing anything I expect that may be your problem.

I've just implemented a handful of control instructions to actually write (mostly) FFh's to memory. The only exception being the instruction and data pointers, which are kept track of by the CPU itself.

Details
void FPU80287_FPU_UD(byte isESC)
{ //Generic x86 FPU #UD opcode decoder!
byte normalx87instruction;
//MP needs to be set for TS to have effect during WAIT(throw emulation). It's always in effect with ESC instructions(ignoring MP). EM only has effect on ESC instructions(throw emulation if set).
if (((getActiveCPUregisters()->CR0&CR0_EM)&&(isESC)) || (((getActiveCPUregisters()->CR0&CR0_MP)||isESC) && (getActiveCPUregisters()->CR0&CR0_TS))) //To be emulated or task switched?
{
debugger_set = 0; //Override it to FPU emulation!
debugger_setcommand("<FPU EMULATION>");
THROWDESCNM(); //Only on 286+!
}
else //Normal execution?
{
normalx87instruction = isESC; //Default: normal x87 instruction to track!
//Perform the required disassembly and execution without an FPU, 80286+ style.
if ((getActiveCPU()->params.modrm==0xE3) && (getActiveCPU()->OP==0xDB))
{
FPU80287_OPDBE3();
/* Special naming! */
normalx87instruction = 0; //Don't track!
}
if ((getActiveCPU()->params.modrm==0xE0) && (getActiveCPU()->OP==0xDF))
{
FPU80287_OPDFE0(); /* Special handling! */
normalx87instruction = 0; //Don't track!
}
if ((getActiveCPU()->OP == 0xDD) && (getActiveCPU()->params.info[getActiveCPU()->MODRM_src0].isreg == 2))
{
if (getActiveCPU()->thereg == 7)
{
FPU80287_OPDDslash7(); /* Special handling! */
normalx87instruction = 0; //Don't track!
}
else if (getActiveCPU()->thereg == 6)
{
FPU80287_OPDDslash6(); /* Special handling! */
normalx87instruction = 0; //Don't track!
}
else if (getActiveCPU()->thereg == 4) //A control instruction?
{
normalx87instruction = 0; //Don't track!
}
}
if ((getActiveCPU()->OP == 0xD9) && (getActiveCPU()->params.info[getActiveCPU()->MODRM_src0].isreg == 2))
{
if (getActiveCPU()->thereg == 7)
{
if (getActiveCPU()->CPU_Operand_size)
{
FPU80287_OPD9slash7_32(); /* Special handling! */
}
else
{
FPU80287_OPD9slash7_16(); /* Special handling! */
}
normalx87instruction = 0; //Don't track!
}
else if (getActiveCPU()->thereg == 6)
{
if (getActiveCPU()->CPU_Operand_size)
{
…Show last 39 lines
					FPU80287_OPD9slash6_32(); /* Special handling! */
}
else
{
FPU80287_OPD9slash6_16(); /* Special handling! */
}
normalx87instruction = 0; //Don't track!
}
else if (getActiveCPU()->thereg >= 4) //A control instruction?
{
normalx87instruction = 0; //Don't track!
}
}
if (normalx87instruction && (getActiveCPU()->executed)) //Normal x86 instruction executed? Keep track of the internal state!
{
getActiveCPUregisters()->FPUinstructionpointer = getActiveCPU()->exec_EIP; //The instruction pointer of the last executed instruction!
getActiveCPUregisters()->FPUinstructionselector = getActiveCPU()->exec_CS; //The instruction selector of the last executed instruction!
getActiveCPUregisters()->FPUrealmodeinstructionpointer = getActiveCPU()->SEG_DESCRIPTOR[CPU_SEGMENT_CS].PRECALCS.base+getActiveCPU()->exec_EIP; //Real mode formatted instruction pointer!
if (MODRM_EA(getActiveCPU()->params)) //Memory is addressed? Resolve it and store it?
{
//Protected mode stores the segment and offset as-is.
getActiveCPUregisters()->FPUdatapointer = getActiveCPU()->params.info[getActiveCPU()->MODRM_src0].mem_offset; //The data pointer of the last executed instruction!
getActiveCPUregisters()->FPUdataselector = getActiveCPU()->params.info[getActiveCPU()->MODRM_src0].mem_segment; //The data segment of the last executed instruction!
//Real mode needs the actual segment base added into it.
getActiveCPUregisters()->FPUrealmodedatapointer = getActiveCPU()->params.info[getActiveCPU()->MODRM_src0].mem_offset+getActiveCPU()->SEG_DESCRIPTOR[getActiveCPU()->params.info[getActiveCPU()->MODRM_src0].segmentregister_index].PRECALCS.base; //The data pointer of the last executed instruction!
}
}

//Default case without any valid FPU instruction.
debugger_setcommand("<No COprocessor OPcodes implemented!>");
if (normalx87instruction && getActiveCPU()->executed)
{
if (CPU_apply286cycles()==0) //No 286+? Apply the 80286+ cycles!
{
getActiveCPU()->cycles_OP = MODRM_EA(getActiveCPU()->params) ? 8 : 2; //No hardware interrupt to use anymore!
}
}
}
}

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io