- Implement RtlPrefectMemoryNonTemporal. Patch by Patrick Baggett <baggett.patrick...
[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(UCHAR Int, PKV86M_REGISTERS Regs)
28 {
29 PUCHAR Ip;
30 KV86M_REGISTERS ORegs;
31 NTSTATUS Status;
32
33 /*
34 * Set up a trampoline for executing the BIOS interrupt
35 */
36 Ip = (PUCHAR)TRAMPOLINE_BASE;
37 Ip[0] = 0xCD; /* int XX */
38 Ip[1] = Int;
39 Ip[2] = 0x63; /* arpl ax, ax */
40 Ip[3] = 0xC0;
41 Ip[4] = 0x90; /* nop */
42 Ip[5] = 0x90; /* nop */
43
44 /*
45 * Munge the registers
46 */
47 Regs->Eip = 0;
48 Regs->Cs = TRAMPOLINE_BASE / 16;
49 Regs->Esp = 0xFFFF;
50 Regs->Ss = TRAMPOLINE_BASE / 16;
51 Regs->Eflags = (1 << 1) | (1 << 17) | (1 << 9); /* VM, IF */
52 Regs->RecoveryAddress = TRAMPOLINE_BASE + 2;
53 Regs->RecoveryInstruction[0] = 0x63; /* arpl ax, ax */
54 Regs->RecoveryInstruction[1] = 0xC0;
55 Regs->RecoveryInstruction[2] = 0x90; /* nop */
56 Regs->RecoveryInstruction[3] = 0x90; /* nop */
57 Regs->Flags = KV86M_EMULATE_CLI_STI | KV86M_ALLOW_IO_PORT_ACCESS;
58 Regs->Vif = 1;
59 Regs->PStatus = &Status;
60
61 /*
62 * Execute the BIOS interrupt
63 */
64 Ki386RetToV86Mode(Regs, &ORegs);
65
66 /*
67 * Copy the return values back to the caller
68 */
69 memcpy(Regs, &ORegs, sizeof(KV86M_REGISTERS));
70
71 return(Status);
72 }
73
74
75
76
77