Fixed typo in wine_get_unix_file_name().
[wine/multimedia.git] / dlls / kernel / win87em.c
blob814e069862125996b99c2045f687221c682d7d58
1 #include <stdlib.h>
2 #include "miscemu.h"
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 )
44 AX_reg(context) = 0;
45 if (Installed)
46 #ifdef __i386__
47 __asm__("fclex");
48 #else
50 #endif
51 StatusWord_3 = StatusWord_2 = 0;
54 static void WIN87_SetCtrlWord( CONTEXT86 *context )
56 CtrlWord_1 = AX_reg(context);
57 AX_reg(context) &= 0xff3c;
58 if (Installed) {
59 CtrlWord_Internal = AX_reg(context);
60 #ifdef __i386__
61 __asm__("wait;fldcw %0" : : "m" (CtrlWord_Internal));
62 #endif
64 CtrlWord_2 = AX_reg(context);
67 void WIN87_Init( CONTEXT86 *context )
69 if (Installed) {
70 #ifdef __i386__
71 __asm__("fninit");
72 __asm__("fninit");
73 #endif
75 StackBottom = StackTop;
76 AX_reg(context) = 0x1332;
77 WIN87_SetCtrlWord(context);
78 WIN87_ClearCtrlWord(context);
81 /***********************************************************************
82 * WIN87_fpmath
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 */
94 RefCount++;
95 #if 0
96 if (Installed)
97 InstallIntVecs02hAnd75h();
98 #endif
99 WIN87_Init(context);
100 AX_reg(context) = 0;
101 break;
103 case 1: /* Init Emulator */
104 WIN87_Init(context);
105 break;
107 case 2: /* deinstall emulator (decrease instanceref), deinstall NMI vector
108 * if zero. Every '0' call should have a matching '2' call.
110 WIN87_Init(context);
111 RefCount--;
112 #if 0
113 if (!RefCount && Installed)
114 RestoreInt02h();
115 #endif
117 break;
119 case 3:
120 /*INT_SetHandler(0x3E,MAKELONG(AX,DX));*/
121 break;
123 case 4: /* set control word (& ~(CW_Denormal|CW_Invalid)) */
124 /* OUT: newset control word in AX */
125 WIN87_SetCtrlWord(context);
126 break;
128 case 5: /* return internal control word in AX */
129 AX_reg(context) = CtrlWord_1;
130 break;
132 case 6: /* round top of stack to integer using method AX & 0x0C00 */
133 /* returns current controlword */
135 DWORD dw=0;
136 WORD save,mask;
137 /* I don't know much about asm() programming. This could be
138 * wrong.
140 #ifdef __i386__
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));
148 #endif
149 TRACE("On top of stack is %ld\n",dw);
151 break;
153 case 7: /* POP top of stack as integer into DX:AX */
154 /* IN: AX&0x0C00 rounding protocol */
155 /* OUT: DX:AX variable popped */
157 DWORD dw=0;
158 /* I don't know much about asm() programming. This could be
159 * wrong.
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);
167 break;
169 case 8: /* restore internal status words from emulator status word */
170 AX_reg(context) = 0;
171 if (Installed) {
172 #ifdef __i386__
173 __asm__("fstsw %0;wait" : "=m" (StatusWord_1));
174 #endif
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);
180 break;
182 case 9: /* clear emu control word and some other things */
183 WIN87_ClearCtrlWord(context);
184 break;
186 case 10: /* dunno. but looks like returning nr. of things on stack in AX */
187 AX_reg(context) = 0;
188 break;
190 case 11: /* just returns the installed flag in DX:AX */
191 DX_reg(context) = 0;
192 AX_reg(context) = Installed;
193 break;
195 case 12: /* save AX in some internal state var */
196 Inthandler02hVar = AX_reg(context);
197 break;
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;
202 break;
206 /***********************************************************************
207 * WIN87_WinEm87Info
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 /***********************************************************************
226 * WIN87_WinEm87Save
228 void WINAPI WIN87_WinEm87Save(void *pWin87EmSaveArea, int cbWin87EmSaveArea)
230 FIXME("(%p,%d), stub !\n",
231 pWin87EmSaveArea,cbWin87EmSaveArea);