summaryrefslogtreecommitdiffstats
path: root/private/mvdm/dpmi32/dpmi32.c
blob: b5f34ea5af384d364463957928da944bdf8563da (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/*++

Copyright (c) 1992  Microsoft Corporation

Module Name:

    dpmi32.c

Abstract:

    This function contains common code such as the dpmi dispatcher,
    and handling for the initialization of the dos extender.

Author:

    Dave Hastings (daveh) 24-Nov-1992

Revision History:

    Neil Sandlin (neilsa) 31-Jul-1995 - Updates for the 486 emulator

--*/
#include "precomp.h"
#pragma hdrstop
#include "softpc.h"
//
// Information about the current PSP
//
USHORT CurrentPSPSelector;

//
// Table of selector bases and limits
//
ULONG FlatAddress[LDT_SIZE];

//
// Index # for DPMI bop.  Used for error reporting on risc
//
ULONG Index;

//
// DPMI dispatch table
//
VOID (*DpmiDispatchTable[MAX_DPMI_BOP_FUNC])(VOID) = {
    DpmiSetDescriptorEntry,                     // 0
    switch_to_protected_mode,                   // 1
    DpmiSetProtectedmodeInterrupt,              // 2
    DpmiGetFastBopEntry,                        // 3
    DpmiInitDosx,                               // 4
    DpmiInitApp,                                // 5
    DpmiXlatInt21Call,                          // 6
    DpmiAllocateXmem,                           // 7
    DpmiFreeXmem,                               // 8
    DpmiReallocateXmem,                         // 9
    DpmiSetFaultHandler,                        // a
    DpmiGetMemoryInfo,                          // b
    DpmiDpmiInUse,                              // c
    DpmiDpmiNoLongerInUse,                      // d
    DpmiSetDebugRegisters,                      // e
    DpmiPassTableAddress,                       // f
    DpmiFreeAppXmem,                            // 10
    DpmiPassPmStackInfo,                        // 11
    DpmiVcdPmSvcCall32,                         // 12
    DpmiFreeAllXmem,                            // 13
    DpmiIntHandlerIret16,                       // 14
    DpmiIntHandlerIret32,                       // 15
    DpmiFaultHandlerIret16,                     // 16
    DpmiFaultHandlerIret32,                     // 17
    DpmiUnhandledExceptionHandler               // 18
};

VOID
DpmiDispatch(
    VOID
    )
/*++

Routine Description:

    This function dispatches to the appropriate subfunction

Arguments:

    None

Return Value:

    None.

--*/
{

    Index = *(Sim32GetVDMPointer(
        ((getCS() << 16) | getIP()),
        1,
        (UCHAR) (getMSW() & MSW_PE)));

    setIP((getIP() + 1));           // take care of subfn.

    DBGTRACE(DPMI_DISPATCH_ENTRY, Index, 0, 0);

    if (Index >= MAX_DPMI_BOP_FUNC) {
#if DBG
        DbgPrint("NtVdm: Invalid DPMI BOP %lx\n", Index);
#endif
        return;
    }

    (*DpmiDispatchTable[Index])();
}

VOID
DpmiIllegalFunction(
    VOID
    )
/*++

Routine Description:

    This routine ignores any Dpmi bops that are not implemented on a
    particular platform. It is called through the DpmiDispatchTable
    by #define'ing individual entries to this function.
    See dpmidata.h and dpmidatr.h.

Arguments:

    None.

Return Value:

    None.

--*/
{
   char szFormat[] = "NtVdm: Invalid DPMI BOP 0x%x from CS:IP %4.4x:%4.4x (%s mode), could be i386 dosx.exe.\n";
   char szMsg[sizeof(szFormat)+64];

   wsprintf(
       szMsg,
       szFormat,
       Index,
       (int)getCS(),
       (int)getIP(),
       (getMSW() & MSW_PE) ? "prot" : "real"
       );

   OutputDebugString(szMsg);
}

VOID
DpmiInitDosx(
    VOID
    )
/*++

Routine Description:

    This routine handle the initialization bop for the dos extender.
    It get the addresses of the structures that the dos extender and
    32 bit code share.

Arguments:

    None

Return Value:

    None.

--*/
{
    PUCHAR SharedData;

    ASSERT((getMSW() & MSW_PE));

    SharedData = Sim32GetVDMPointer(((getDS() << 16) | getSI()), 2, TRUE);

    DosxStackSegment = *((PWORD16)SharedData);

    SmallXlatBuffer = Sim32GetVDMPointer(*((PDWORD16)(SharedData+2)), 4, TRUE);

    LargeXlatBuffer = Sim32GetVDMPointer(*((PDWORD16)(SharedData+6)), 4, TRUE);

    DosxStackFramePointer = (PWORD16)((PULONG)Sim32GetVDMPointer(
                                     *((PDWORD16)(SharedData + 10)), 4, TRUE));

    DosxStackFrameSize = *((PWORD16)(SharedData + 14));

    RmBopFe = *((PDWORD16)(SharedData + 16));

    DosxRmCodeSegment = *((PWORD16)(SharedData + 20));

    DosxDtaBuffer = Sim32GetVDMPointer(*(PDWORD16)(SharedData+22), 4, TRUE);

    DosxPmDataSelector = *(PWORD16)(SharedData + 26);
    DosxRmCodeSelector = *(PWORD16)(SharedData + 28);
    DosxSegmentToSelector = *(PDWORD16)(SharedData + 30);

    DosxFaultHandlerIret = *(PDWORD16)(SharedData + 34);
    DosxFaultHandlerIretd= *(PDWORD16)(SharedData + 38);
    DosxIntHandlerIret   = *(PDWORD16)(SharedData + 42);
    DosxIntHandlerIretd  = *(PDWORD16)(SharedData + 46);
    DosxIret             = *(PDWORD16)(SharedData + 50);
    DosxIretd            = *(PDWORD16)(SharedData + 54);

}

VOID
DpmiInitApp(
    VOID
    )
/*++

Routine Description:

    This routine handles any necessary 32 bit initialization for extended
    applications.

Arguments:

    None.

Return Value:

    None.

Notes:

    This function contains a number of 386 specific things.
    Since we are likely to expand the 32 bit portions of DPMI in the
    future, this makes more sense than duplicating the common portions
    another file.

--*/
{
    PWORD16 Data;

    Data = (PWORD16)Sim32GetVDMPointer(
        ((ULONG)getSS() << 16) | getSP(),
        1,
        TRUE
        );


    // Only 1 bit defined in dpmi
    CurrentAppFlags = getAX() & DPMI_32BIT;
#if defined(i386)
    VdmTib.PmStackInfo.Flags = CurrentAppFlags;
    if (CurrentAppFlags & DPMI_32BIT) {
        *pNtVDMState |= VDM_32BIT_APP;
    }
#endif

    DpmiInitRegisterSize();

    CurrentDta = Sim32GetVDMPointer(
        *(PDWORD16)(Data),
        1,
        TRUE
        );

    CurrentDosDta = (PUCHAR) NULL;

    CurrentDtaOffset = *Data;
    CurrentDtaSelector = *(Data + 1);
    CurrentPSPSelector = *(Data + 2);
}
VOID DpmiPassTableAddress(
    VOID
    )
/*++

Routine Description:

    This routine stores the flat address for the LDT table in the 16bit
    land (pointed to by selGDT in 16bit land).

Arguments:

    None

Return Value:

    None.

--*/
{

    Ldt = (PVOID)Sim32GetVDMPointer(
        (getAX() << 16),
        0,
        (UCHAR) (getMSW() & MSW_PE)
        );

    IntelBase = (ULONG) Sim32GetVDMPointer((ULONG)0, 1, FALSE);

}