58cb5bbf4d426bba306163eb3680e3052e782444
[reactos.git] / reactos / ntoskrnl / ke / i386 / bios.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/ke/i386/bios.c
6 * PURPOSE: Support for calling the BIOS in v86 mode
7 *
8 * PROGRAMMERS: David Welch (welch@cwcom.net)
9 */
10
11 /* INCLUDES *****************************************************************/
12
13 #include <ntoskrnl.h>
14 #define NDEBUG
15 #include <internal/debug.h>
16
17 /* GLOBALS *******************************************************************/
18
19 #define TRAMPOLINE_BASE (0x10000)
20
21 extern VOID Ki386RetToV86Mode(PKV86M_REGISTERS InRegs,
22 PKV86M_REGISTERS OutRegs);
23
24 /* FUNCTIONS *****************************************************************/
25
26 NTSTATUS STDCALL
27 Ke386CallBios(ULONG Int, PCONTEXT regs)
28 {
29 PUCHAR Ip;
30 KV86M_REGISTERS ORegs;
31 NTSTATUS Status;
32 PKV86M_REGISTERS Regs = (PKV86M_REGISTERS)regs;
33
34 /*
35 * Set up a trampoline for executing the BIOS interrupt
36 */
37 Ip = (PUCHAR)TRAMPOLINE_BASE;
38 Ip[0] = 0xCD; /* int XX */
39 Ip[1] = Int;
40 Ip[2] = 0x63; /* arpl ax, ax */
41 Ip[3] = 0xC0;
42 Ip[4] = 0x90; /* nop */
43 Ip[5] = 0x90; /* nop */
44
45 /*
46 * Munge the registers
47 */
48 Regs->Eip = 0;
49 Regs->Cs = TRAMPOLINE_BASE / 16;
50 Regs->Esp = 0xFFFF;
51 Regs->Ss = TRAMPOLINE_BASE / 16;
52 Regs->Eflags = (1 << 1) | (1 << 17) | (1 << 9); /* VM, IF */
53 Regs->RecoveryAddress = TRAMPOLINE_BASE + 2;
54 Regs->RecoveryInstruction[0] = 0x63; /* arpl ax, ax */
55 Regs->RecoveryInstruction[1] = 0xC0;
56 Regs->RecoveryInstruction[2] = 0x90; /* nop */
57 Regs->RecoveryInstruction[3] = 0x90; /* nop */
58 Regs->Flags = KV86M_EMULATE_CLI_STI | KV86M_ALLOW_IO_PORT_ACCESS;
59 Regs->Vif = 1;
60 Regs->PStatus = &Status;
61
62 /*
63 * Execute the BIOS interrupt
64 */
65 Ki386RetToV86Mode(Regs, &ORegs);
66
67 /*
68 * Copy the return values back to the caller
69 */
70 memcpy(Regs, &ORegs, sizeof(KV86M_REGISTERS));
71
72 return(Status);
73 }
74
75
76
77
78