summaryrefslogtreecommitdiffstats
path: root/private/ntos/nthals/haldti/mips/x86bios.c
blob: c31a8baf586c3b4beb74232e16ff3bca24c58d2f (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
/*++

Copyright (c) 1994  Microsoft Corporation

Module Name:

    x86bios.c

Abstract:


    This module implements the platform specific interface between a device
    driver and the execution of x86 ROM bios code for the device.

Author:

    David N. Cutler (davec) 17-Jun-1994

Environment:

    Kernel mode only.

Revision History:

--*/

#include "halp.h"

typedef struct FIRMWARE_INT_ARGUMENTS {
    ULONG pEAX;
    ULONG pEBX;
    ULONG pECX;
    ULONG pEDX;
    ULONG pESI;
    ULONG pEDI;
    ULONG pEBP;
    USHORT pES;
    USHORT pDS;
    USHORT pFlags;
} FIRMWARE_INT_ARGUMENTS, *PFIRMWARE_INT_ARGUMENTS;

ULONG HalpX86BiosInitialized     = FALSE;
ULONG HalpEnableInt10Calls       = FALSE;
ULONG HalpUseFirmwareX86Emulator = FALSE;

typedef
VOID
(*PVENDOR_EXECUTE_INT) (
    IN USHORT Type,
    IN PFIRMWARE_INT_ARGUMENTS Context
    );

PVENDOR_EXECUTE_INT VendorX86ExecuteInt;

VOID HalpInitializeX86DisplayAdapter()

{
    PSYSTEM_PARAMETER_BLOCK SystemParameterBlock = (PSYSTEM_PARAMETER_BLOCK)(0x80001000);

    //
    // If EISA I/O Ports or EISA Memory could not be mapped, then leave the
    // X86 BIOS Emulator disabled.
    //

    if (HalpEisaControlBase == NULL || HalpEisaMemoryBase == NULL) {

//        DbgPrint("X86 BIOS Emulator Disabled\n");

        return;
    }

    //
    // If Firmware level X86 Bios Emulator exists, then use that instead of the
    // one built into the HAL.
    //

    if ((SystemParameterBlock->VendorVectorLength/4) >= 34) {

        VendorX86ExecuteInt =
            *(PVENDOR_EXECUTE_INT *)((ULONG)(SystemParameterBlock->VendorVector) + 34*4);

        if (VendorX86ExecuteInt != NULL) {
            HalpX86BiosInitialized     = TRUE;
            HalpUseFirmwareX86Emulator = TRUE;
            HalpEnableInt10Calls       = TRUE;

//            DbgPrint("Firmware X86 BIOS Emulator Enabled\n");
//            DbgPrint("INT 10 Calls Enabled\n");

            return;
        }
    }

//    DbgPrint("HAL X86 BIOS Emulator Enabled\n");

    x86BiosInitializeBios(HalpEisaControlBase, HalpEisaMemoryBase);

    HalpX86BiosInitialized = TRUE;

    //
    // Attempt to initialize the Display Adapter by executing the Display Adapters
    // initialization code in its BIOS.  The standard for PC video adapters is for
    // the BIOS to reside at 0xC000:0000 on the ISA bus.
    //

//    DbgPrint("X86BiosInitializeAdapter(0xc0000)\n");

    if (x86BiosInitializeAdapter(0xc0000, NULL, NULL, NULL) != XM_SUCCESS) {
        HalpEnableInt10Calls = FALSE;

//        DbgPrint("INT 10 Calls Disabled\n");

        return;
    }

    HalpEnableInt10Calls = TRUE;

//    DbgPrint("INT 10 Calls Enabled\n");
}

VOID HalpResetX86DisplayAdapter()

{
    XM86_CONTEXT Context;

    //
    // Make INT 10 call to initialize 80x25 color text mode.
    //

    Context.Eax = 0x0003;  // Function 0, Mode 3
    Context.Ebx = 0;
    Context.Ecx = 0;
    Context.Edx = 0;
    Context.Esi = 0;
    Context.Edi = 0;
    Context.Ebp = 0;

    HalCallBios(0x10,
                &Context.Eax,
                &Context.Ebx,
                &Context.Ecx,
                &Context.Edx,
                &Context.Esi,
                &Context.Edi,
                &Context.Ebp);
}


BOOLEAN
HalCallBios (
    IN ULONG BiosCommand,
    IN OUT PULONG Eax,
    IN OUT PULONG Ebx,
    IN OUT PULONG Ecx,
    IN OUT PULONG Edx,
    IN OUT PULONG Esi,
    IN OUT PULONG Edi,
    IN OUT PULONG Ebp
    )

/*++

Routine Description:

    This function provides the platform specific interface between a device
    driver and the execution of the x86 ROM bios code for the specified ROM
    bios command.

Arguments:

    BiosCommand - Supplies the ROM bios command to be emulated.

    Eax to Ebp - Supplies the x86 emulation context.

Return Value:

    A value of TRUE is returned if the specified function is executed.
    Otherwise, a value of FALSE is returned.

--*/

{
    FIRMWARE_INT_ARGUMENTS Arguments;
    XM86_CONTEXT        Context;


    //
    // If the X86 BIOS Emulator has not been initialized then fail all INT calls.
    //

    if (HalpX86BiosInitialized == FALSE) {
        return(FALSE);
    }

    //
    // If the Video Adapter initialization failed, then we can not make INT 10 calls.
    //

    if (BiosCommand == 0x10 && HalpEnableInt10Calls == FALSE) {
        return(FALSE);
    }

//    DbgPrint("HalCallBios(%02X,%04X,%04X,%04X,%04X,%04X,%04X,%04X)\n",BiosCommand,*Eax,*Ebx,*Ecx,*Edx,*Esi,*Edi,*Ebp);

    if (HalpUseFirmwareX86Emulator == TRUE) {

        //
        // Make private vector call to the emulator in the firmware.
        //

        Arguments.pEAX   = *Eax;
        Arguments.pEBX   = *Ebx;
        Arguments.pECX   = *Ecx;
        Arguments.pEDX   = *Edx;
        Arguments.pESI   = *Esi;
        Arguments.pEDI   = *Edi;
        Arguments.pEBP   = *Ebp;
        Arguments.pES    = 0;
        Arguments.pDS    = 0;
        Arguments.pFlags = 0;

        VendorX86ExecuteInt((USHORT)BiosCommand,&Arguments);

        *Eax = Arguments.pEAX;
        *Ebx = Arguments.pEBX;
        *Ecx = Arguments.pECX;
        *Edx = Arguments.pEDX;
        *Esi = Arguments.pESI;
        *Edi = Arguments.pEDI;
        *Ebp = Arguments.pEBP;

    }
    else {

        //
        // Make call to emulator build into HAL
        //

        Context.Eax = *Eax;
        Context.Ebx = *Ebx;
        Context.Ecx = *Ecx;
        Context.Edx = *Edx;
        Context.Esi = *Esi;
        Context.Edi = *Edi;
        Context.Ebp = *Ebp;

        if (x86BiosExecuteInterrupt((UCHAR)BiosCommand, &Context, NULL, NULL) != XM_SUCCESS) {
            return FALSE;
        }

        *Eax = Context.Eax;
        *Ebx = Context.Ebx;
        *Ecx = Context.Ecx;
        *Edx = Context.Edx;
        *Esi = Context.Esi;
        *Edi = Context.Edi;
        *Ebp = Context.Ebp;

    }

    return TRUE;
}