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 void WINAPI WIN87_fpmath( CONTEXT86 *context )
83 TRACE("(cs:eip=%x:%lx es=%x bx=%04x ax=%04x dx==%04x)\n",
84 (WORD)CS_reg(context), EIP_reg(context),
85 (WORD)ES_reg(context), BX_reg(context),
86 AX_reg(context), DX_reg(context) );
88 switch(BX_reg(context))
90 case 0: /* install (increase instanceref) emulator, install NMI vector */
93 /* InstallIntVecs02hAnd75h(); */ ;
98 case 1: /* Init Emulator */
102 case 2: /* deinstall emulator (decrease instanceref), deinstall NMI vector
103 * if zero. Every '0' call should have a matching '2' call.
106 if (!(--RefCount) && (Installed))
107 /* RestoreInt02h() */ ;
112 /*INT_SetHandler(0x3E,MAKELONG(AX,DX));*/
115 case 4: /* set control word (& ~(CW_Denormal|CW_Invalid)) */
116 /* OUT: newset control word in AX */
117 WIN87_SetCtrlWord(context);
120 case 5: /* return internal control word in AX */
121 AX_reg(context) = CtrlWord_1;
124 case 6: /* round top of stack to integer using method AX & 0x0C00 */
125 /* returns current controlword */
129 /* I don't know much about asm() programming. This could be
133 __asm__ __volatile__("fstcw %0;wait" : "=m" (save) : : "memory");
134 __asm__ __volatile__("fstcw %0;wait" : "=m" (mask) : : "memory");
135 __asm__ __volatile__("orw $0xC00,%0" : "=m" (mask) : : "memory");
136 __asm__ __volatile__("fldcw %0;wait" : : "m" (mask));
137 __asm__ __volatile__("frndint");
138 __asm__ __volatile__("fist %0;wait" : "=m" (dw) : : "memory");
139 __asm__ __volatile__("fldcw %0" : : "m" (save));
141 TRACE("On top of stack is %ld\n",dw);
145 case 7: /* POP top of stack as integer into DX:AX */
146 /* IN: AX&0x0C00 rounding protocol */
147 /* OUT: DX:AX variable popped */
150 /* I don't know much about asm() programming. This could be
153 /* FIXME: could someone who really understands asm() fix this please? --AJ */
154 /* __asm__("fistp %0;wait" : "=m" (dw) : : "memory"); */
155 TRACE("On top of stack was %ld\n",dw);
156 AX_reg(context) = LOWORD(dw);
157 DX_reg(context) = HIWORD(dw);
161 case 8: /* restore internal status words from emulator status word */
165 __asm__("fstsw %0;wait" : "=m" (StatusWord_1));
167 AL_reg(context) = (BYTE)StatusWord_1 & 0x3f;
169 AX_reg(context) |= StatusWord_2;
170 AX_reg(context) &= 0x1fff;
171 StatusWord_2 = AX_reg(context);
174 case 9: /* clear emu control word and some other things */
175 WIN87_ClearCtrlWord(context);
178 case 10: /* dunno. but looks like returning nr. of things on stack in AX */
182 case 11: /* just returns the installed flag in DX:AX */
184 AX_reg(context) = Installed;
187 case 12: /* save AX in some internal state var */
188 Inthandler02hVar = AX_reg(context);
191 default: /* error. Say that loud and clear */
192 FIXME("unhandled switch %d\n",BX_reg(context));
193 AX_reg(context) = DX_reg(context) = 0xFFFF;
198 /***********************************************************************
201 void WINAPI WIN87_WinEm87Info(struct Win87EmInfoStruct *pWIS,
202 int cbWin87EmInfoStruct)
204 FIXME("(%p,%d), stub !\n",pWIS,cbWin87EmInfoStruct);
207 /***********************************************************************
208 * WIN87_WinEm87Restore
210 void WINAPI WIN87_WinEm87Restore(void *pWin87EmSaveArea,
211 int cbWin87EmSaveArea)
213 FIXME("(%p,%d), stub !\n",
214 pWin87EmSaveArea,cbWin87EmSaveArea);
217 /***********************************************************************
220 void WINAPI WIN87_WinEm87Save(void *pWin87EmSaveArea, int cbWin87EmSaveArea)
222 FIXME("(%p,%d), stub !\n",
223 pWin87EmSaveArea,cbWin87EmSaveArea);