3 #include "debugtools.h"
5 DEFAULT_DEBUG_CHANNEL(int)
7 struct Win87EmInfoStruct
9 unsigned short Version
;
10 unsigned short SizeSaveArea
;
11 unsigned short WinDataSeg
;
12 unsigned short WinCodeSeg
;
13 unsigned short Have80x87
;
14 unsigned short Unused
;
17 /* Implementing this is easy cause Linux and *BSD* ALWAYS have a numerical
18 * coprocessor. (either real or emulated on kernellevel)
20 /* win87em.dll also sets interrupt vectors: 2 (NMI), 0x34 - 0x3f (emulator
21 * calls of standard libraries, see Ralph Browns interrupt list), 0x75
22 * (int13 error reporting of coprocessor)
25 /* have a look at /usr/src/linux/arch/i386/math-emu/ *.[ch] for more info
26 * especially control_w.h and status_w.h
28 /* FIXME: Still rather skeletal implementation only */
30 static BOOL Installed
= 0;
31 static WORD RefCount
= 0;
32 static WORD CtrlWord_1
= 0;
33 static WORD CtrlWord_2
= 0;
34 static WORD CtrlWord_Internal
= 0;
35 static WORD StatusWord_1
= 0x000b;
36 static WORD StatusWord_2
= 0;
37 static WORD StatusWord_3
= 0;
38 static WORD StackTop
= 175;
39 static WORD StackBottom
= 0;
40 static WORD Inthandler02hVar
= 1;
42 static void WIN87_ClearCtrlWord( CONTEXT86
*context
)
51 StatusWord_3
= StatusWord_2
= 0;
54 static void WIN87_SetCtrlWord( CONTEXT86
*context
)
56 CtrlWord_1
= AX_reg(context
);
57 AX_reg(context
) &= 0xff3c;
59 CtrlWord_Internal
= AX_reg(context
);
61 __asm__("wait;fldcw %0" : : "m" (CtrlWord_Internal
));
64 CtrlWord_2
= AX_reg(context
);
67 void WIN87_Init( CONTEXT86
*context
)
75 StackBottom
= StackTop
;
76 AX_reg(context
) = 0x1332;
77 WIN87_SetCtrlWord(context
);
78 WIN87_ClearCtrlWord(context
);
81 /***********************************************************************
84 void WINAPI
WIN87_fpmath( CONTEXT86
*context
)
86 TRACE("(cs:eip=%x:%lx es=%x bx=%04x ax=%04x dx==%04x)\n",
87 (WORD
)context
->SegCs
, context
->Eip
,
88 (WORD
)context
->SegEs
, BX_reg(context
),
89 AX_reg(context
), DX_reg(context
) );
91 switch(BX_reg(context
))
93 case 0: /* install (increase instanceref) emulator, install NMI vector */
97 InstallIntVecs02hAnd75h();
103 case 1: /* Init Emulator */
107 case 2: /* deinstall emulator (decrease instanceref), deinstall NMI vector
108 * if zero. Every '0' call should have a matching '2' call.
113 if (!RefCount
&& Installed
)
120 /*INT_SetHandler(0x3E,MAKELONG(AX,DX));*/
123 case 4: /* set control word (& ~(CW_Denormal|CW_Invalid)) */
124 /* OUT: newset control word in AX */
125 WIN87_SetCtrlWord(context
);
128 case 5: /* return internal control word in AX */
129 AX_reg(context
) = CtrlWord_1
;
132 case 6: /* round top of stack to integer using method AX & 0x0C00 */
133 /* returns current controlword */
137 /* I don't know much about asm() programming. This could be
141 __asm__
__volatile__("fstcw %0;wait" : "=m" (save
) : : "memory");
142 __asm__
__volatile__("fstcw %0;wait" : "=m" (mask
) : : "memory");
143 __asm__
__volatile__("orw $0xC00,%0" : "=m" (mask
) : : "memory");
144 __asm__
__volatile__("fldcw %0;wait" : : "m" (mask
));
145 __asm__
__volatile__("frndint");
146 __asm__
__volatile__("fist %0;wait" : "=m" (dw
) : : "memory");
147 __asm__
__volatile__("fldcw %0" : : "m" (save
));
149 TRACE("On top of stack is %ld\n",dw
);
153 case 7: /* POP top of stack as integer into DX:AX */
154 /* IN: AX&0x0C00 rounding protocol */
155 /* OUT: DX:AX variable popped */
158 /* I don't know much about asm() programming. This could be
161 /* FIXME: could someone who really understands asm() fix this please? --AJ */
162 /* __asm__("fistp %0;wait" : "=m" (dw) : : "memory"); */
163 TRACE("On top of stack was %ld\n",dw
);
164 AX_reg(context
) = LOWORD(dw
);
165 DX_reg(context
) = HIWORD(dw
);
169 case 8: /* restore internal status words from emulator status word */
173 __asm__("fstsw %0;wait" : "=m" (StatusWord_1
));
175 AL_reg(context
) = (BYTE
)StatusWord_1
& 0x3f;
177 AX_reg(context
) |= StatusWord_2
;
178 AX_reg(context
) &= 0x1fff;
179 StatusWord_2
= AX_reg(context
);
182 case 9: /* clear emu control word and some other things */
183 WIN87_ClearCtrlWord(context
);
186 case 10: /* dunno. but looks like returning nr. of things on stack in AX */
190 case 11: /* just returns the installed flag in DX:AX */
192 AX_reg(context
) = Installed
;
195 case 12: /* save AX in some internal state var */
196 Inthandler02hVar
= AX_reg(context
);
199 default: /* error. Say that loud and clear */
200 FIXME("unhandled switch %d\n",BX_reg(context
));
201 AX_reg(context
) = DX_reg(context
) = 0xFFFF;
206 /***********************************************************************
209 void WINAPI
WIN87_WinEm87Info(struct Win87EmInfoStruct
*pWIS
,
210 int cbWin87EmInfoStruct
)
212 FIXME("(%p,%d), stub !\n",pWIS
,cbWin87EmInfoStruct
);
215 /***********************************************************************
216 * WIN87_WinEm87Restore
218 void WINAPI
WIN87_WinEm87Restore(void *pWin87EmSaveArea
,
219 int cbWin87EmSaveArea
)
221 FIXME("(%p,%d), stub !\n",
222 pWin87EmSaveArea
,cbWin87EmSaveArea
);
225 /***********************************************************************
228 void WINAPI
WIN87_WinEm87Save(void *pWin87EmSaveArea
, int cbWin87EmSaveArea
)
230 FIXME("(%p,%d), stub !\n",
231 pWin87EmSaveArea
,cbWin87EmSaveArea
);