Release 950817
[wine/multimedia.git] / miscemu / dpmi.c
blob1c787e97b643c8e5987ecd3783278a11c9f0996a
1 /*
2 * DPMI 0.9 emulation
4 * Copyright 1995 Alexandre Julliard
5 */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include "windows.h"
11 #include "ldt.h"
12 #include "registers.h"
13 #include "wine.h"
14 #include "miscemu.h"
15 #include "stddebug.h"
16 /* #define DEBUG_INT */
17 #include "debug.h"
20 /**********************************************************************
21 * INT_Int31Handler
23 * Handler for int 31h (DPMI).
25 void INT_Int31Handler( struct sigcontext_struct context )
27 DWORD dw;
28 BYTE *ptr;
30 RESET_CFLAG(&context);
31 switch(AX_reg(&context))
33 case 0x0000: /* Allocate LDT descriptors */
34 if (!(AX_reg(&context) = AllocSelectorArray( CX_reg(&context) )))
36 AX_reg(&context) = 0x8011; /* descriptor unavailable */
37 SET_CFLAG(&context);
39 break;
41 case 0x0001: /* Free LDT descriptor */
42 if (FreeSelector( BX_reg(&context) ))
44 AX_reg(&context) = 0x8022; /* invalid selector */
45 SET_CFLAG(&context);
47 break;
49 case 0x0003: /* Get next selector increment */
50 AX_reg(&context) = __AHINCR;
51 break;
53 case 0x0004: /* Lock selector (not supported) */
54 AX_reg(&context) = 0; /* FIXME: is this a correct return value? */
55 break;
57 case 0x0005: /* Unlock selector (not supported) */
58 AX_reg(&context) = 0; /* FIXME: is this a correct return value? */
59 break;
61 case 0x0006: /* Get selector base address */
62 if (!(dw = GetSelectorBase( BX_reg(&context) )))
64 AX_reg(&context) = 0x8022; /* invalid selector */
65 SET_CFLAG(&context);
67 else
69 CX_reg(&context) = HIWORD(dw);
70 DX_reg(&context) = LOWORD(dw);
72 break;
74 case 0x0007: /* Set selector base address */
75 SetSelectorBase( BX_reg(&context),
76 MAKELONG( DX_reg(&context), CX_reg(&context) ) );
77 break;
79 case 0x0008: /* Set selector limit */
80 SetSelectorLimit( BX_reg(&context),
81 MAKELONG( DX_reg(&context), CX_reg(&context) ) );
82 break;
84 case 0x0009: /* Set selector access rights */
85 SelectorAccessRights( BX_reg(&context), 1, CX_reg(&context) );
87 case 0x000a: /* Allocate selector alias */
88 if (!(AX_reg(&context) = AllocCStoDSAlias( BX_reg(&context) )))
90 AX_reg(&context) = 0x8011; /* descriptor unavailable */
91 SET_CFLAG(&context);
93 break;
95 case 0x000b: /* Get descriptor */
97 ldt_entry entry;
98 LDT_GetEntry( SELECTOR_TO_ENTRY( BX_reg(&context) ), &entry );
99 /* FIXME: should use ES:EDI for 32-bit clients */
100 LDT_EntryToBytes( PTR_SEG_OFF_TO_LIN( ES_reg(&context),
101 DI_reg(&context) ), &entry );
103 break;
105 case 0x000c: /* Set descriptor */
107 ldt_entry entry;
108 LDT_BytesToEntry( PTR_SEG_OFF_TO_LIN( ES_reg(&context),
109 DI_reg(&context) ), &entry );
110 LDT_GetEntry( SELECTOR_TO_ENTRY( BX_reg(&context) ), &entry );
112 break;
114 case 0x000d: /* Allocate specific LDT descriptor */
115 AX_reg(&context) = 0x8011; /* descriptor unavailable */
116 SET_CFLAG(&context);
117 break;
119 case 0x0204: /* Get protected mode interrupt vector */
120 dw = (DWORD)INT_GetHandler( BL_reg(&context) );
121 CX_reg(&context) = HIWORD(dw);
122 DX_reg(&context) = LOWORD(dw);
123 break;
125 case 0x0205: /* Set protected mode interrupt vector */
126 INT_SetHandler( BL_reg(&context),
127 (SEGPTR)MAKELONG( DX_reg(&context), CX_reg(&context) ));
128 break;
130 case 0x0400: /* Get DPMI version */
131 AX_reg(&context) = 0x005a; /* DPMI version 0.90 */
132 BX_reg(&context) = 0x0005; /* Flags: 32-bit, virtual memory */
133 CL_reg(&context) = 3; /* CPU type: 386 */
134 DX_reg(&context) = 0x0102; /* Master/slave interrupt controller base*/
135 break;
137 case 0x0500: /* Get free memory information */
138 ptr = (BYTE *)PTR_SEG_OFF_TO_LIN( ES_reg(&context), DI_reg(&context) );
139 *(DWORD *)ptr = 0x00ff0000; /* Largest block available */
140 memset( ptr + 4, 0xff, 0x2c ); /* No other information supported */
141 break;
143 case 0x0501: /* Allocate memory block */
144 if (!(ptr = (BYTE *)malloc( MAKELONG( CX_reg(&context),
145 BX_reg(&context) ) )))
147 AX_reg(&context) = 0x8012; /* linear memory not available */
148 SET_CFLAG(&context);
150 else
152 BX_reg(&context) = SI_reg(&context) = HIWORD(ptr);
153 CX_reg(&context) = DI_reg(&context) = LOWORD(ptr);
155 break;
157 case 0x0502: /* Free memory block */
158 free( (void *)MAKELONG( DI_reg(&context), SI_reg(&context) ) );
159 break;
161 case 0x0503: /* Resize memory block */
162 if (!(ptr = (BYTE *)realloc( (void *)MAKELONG(DI_reg(&context),SI_reg(&context)),
163 MAKELONG(CX_reg(&context),BX_reg(&context)))))
165 AX_reg(&context) = 0x8012; /* linear memory not available */
166 SET_CFLAG(&context);
168 else
170 BX_reg(&context) = SI_reg(&context) = HIWORD(ptr);
171 CX_reg(&context) = DI_reg(&context) = LOWORD(ptr);
173 break;
175 case 0x0600: /* Lock linear region */
176 break; /* Just ignore it */
178 case 0x0601: /* Unlock linear region */
179 break; /* Just ignore it */
181 default:
182 INT_BARF( &context, 0x31 );
183 AX_reg(&context) = 0x8001; /* unsupported function */
184 SET_CFLAG(&context);
185 break;