Release 960114
[wine/gsoc-2012-control.git] / miscemu / emulate.c
blobd31ccb73d5800d7018967cef2e75e79d0dc131a2
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include "wine.h"
4 #include "miscemu.h"
5 #include "registers.h"
6 #include "stddebug.h"
7 /* #define DEBUG_INT */
8 #include "debug.h"
10 struct Win87EmInfoStruct
12 unsigned short Version;
13 unsigned short SizeSaveArea;
14 unsigned short WinDataSeg;
15 unsigned short WinCodeSeg;
16 unsigned short Have80x87;
17 unsigned short Unused;
20 /* Implementing this is easy cause Linux and *BSD* ALWAYS have a numerical
21 * coprocessor. (either real or emulated on kernellevel)
23 /* win87em.dll also sets interrupt vectors: 2 (NMI), 0x34 - 0x3f (emulator
24 * calls of standard libraries, see Ralph Browns interrupt list), 0x75
25 * (int13 error reporting of coprocessor)
28 /* have a look at /usr/src/linux/arch/i386/math-emu/ *.[ch] for more info
29 * especially control_w.h and status_w.h
31 /* FIXME: Only skeletal implementation for now */
33 void WIN87_fpmath( struct sigcontext_struct context )
35 dprintf_int(stddeb, "_fpmath: (cs:eip=%x:%lx es=%x bx=%04x ax=%04x dx==%04x)\n",
36 CS_reg(&context), EIP_reg(&context),
37 ES_reg(&context), BX_reg(&context),
38 AX_reg(&context), DX_reg(&context) );
40 switch(BX_reg(&context))
42 case 0: /* install (increase instanceref) emulator, install NMI vector */
43 AX_reg(&context) = 0;
44 break;
46 case 1: /* Init Emulator */
47 AX_reg(&context) = 0;
48 break;
50 case 2: /* deinstall emulator (decrease instanceref), deinstall NMI vector
51 * if zero. Every '0' call should have a matching '2' call.
53 AX_reg(&context) = 0;
54 break;
56 case 3:
57 /*INT_SetHandler(0x3E,MAKELONG(AX,DX));*/
58 break;
60 case 4: /* set control word (& ~(CW_Denormal|CW_Invalid)) */
61 /* OUT: newset control word in AX */
62 break;
64 case 5: /* return internal control word in AX */
65 break;
67 case 6: /* round top of stack to integer using method AX & 0x0C00 */
68 /* returns current controlword */
69 break;
71 case 7: /* POP top of stack as integer into DX:AX */
72 /* IN: AX&0x0C00 rounding protocol */
73 /* OUT: DX:AX variable popped */
75 DWORD dw=0;
76 /* I don't know much about asm() programming. This could be
77 * wrong.
79 /* FIXME: could someone who really understands asm() fix this please? --AJ */
80 /* __asm__("fistp %0;wait" : "=m" (dw) : : "memory"); */
81 dprintf_int(stddeb,"emulate.c:On top of stack was %ld\n",dw);
82 AX_reg(&context) = LOWORD(dw);
83 DX_reg(&context) = HIWORD(dw);
85 break;
87 case 8: /* restore internal control words from emulator control word */
88 break;
90 case 9: /* clear emu control word and some other things */
91 break;
93 case 10: /* dunno. but looks like returning nr. of things on stack in AX */
94 AX_reg(&context) = 0;
95 break;
97 case 11: /* just returns the installed flag in DX:AX */
98 DX_reg(&context) = 0;
99 AX_reg(&context) = 1;
100 break;
102 case 12: /* save AX in some internal state var */
103 break;
105 default: /* error. Say that loud and clear */
106 AX_reg(&context) = DX_reg(&context) = 0xFFFF;
107 break;
112 void
113 WIN87_WinEm87Info(struct Win87EmInfoStruct *pWIS, int cbWin87EmInfoStruct)
115 dprintf_int(stddeb, "__WinEm87Info(%p,%d)\n",pWIS,cbWin87EmInfoStruct);
118 void
119 WIN87_WinEm87Restore(void *pWin87EmSaveArea, int cbWin87EmSaveArea)
121 dprintf_int(stddeb, "__WinEm87Restore(%p,%d)\n",
122 pWin87EmSaveArea,cbWin87EmSaveArea);
125 void
126 WIN87_WinEm87Save(void *pWin87EmSaveArea, int cbWin87EmSaveArea)
128 dprintf_int(stddeb, "__WinEm87Save(%p,%d)\n",
129 pWin87EmSaveArea,cbWin87EmSaveArea);