Copy msimg32
[reactos.git] / reactos / ntoskrnl / ke / i386 / bios.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2000 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /*
20 * PROJECT: ReactOS kernel
21 * FILE: ntoskrnl/ke/i386/bios.c
22 * PURPOSE: Support for calling the BIOS in v86 mode
23 * PROGRAMMER: David Welch (welch@cwcom.net)
24 */
25
26 /* INCLUDES *****************************************************************/
27
28 #include <ntoskrnl.h>
29 #define NDEBUG
30 #include <internal/debug.h>
31
32 /* GLOBALS *******************************************************************/
33
34 #define TRAMPOLINE_BASE (0x10000)
35
36 extern VOID Ki386RetToV86Mode(PKV86M_REGISTERS InRegs,
37 PKV86M_REGISTERS OutRegs);
38
39 /* FUNCTIONS *****************************************************************/
40
41 NTSTATUS STDCALL
42 Ke386CallBios(UCHAR Int, PKV86M_REGISTERS Regs)
43 {
44 PUCHAR Ip;
45 KV86M_REGISTERS ORegs;
46 NTSTATUS Status;
47
48 /*
49 * Set up a trampoline for executing the BIOS interrupt
50 */
51 Ip = (PUCHAR)TRAMPOLINE_BASE;
52 Ip[0] = 0xCD; /* int XX */
53 Ip[1] = Int;
54 Ip[2] = 0x63; /* arpl ax, ax */
55 Ip[3] = 0xC0;
56 Ip[4] = 0x90; /* nop */
57 Ip[5] = 0x90; /* nop */
58
59 /*
60 * Munge the registers
61 */
62 Regs->Eip = 0;
63 Regs->Cs = TRAMPOLINE_BASE / 16;
64 Regs->Esp = 0xFFFF;
65 Regs->Ss = TRAMPOLINE_BASE / 16;
66 Regs->Eflags = (1 << 1) | (1 << 17) | (1 << 9); /* VM, IF */
67 Regs->RecoveryAddress = TRAMPOLINE_BASE + 2;
68 Regs->RecoveryInstruction[0] = 0x63; /* arpl ax, ax */
69 Regs->RecoveryInstruction[1] = 0xC0;
70 Regs->RecoveryInstruction[2] = 0x90; /* nop */
71 Regs->RecoveryInstruction[3] = 0x90; /* nop */
72 Regs->Flags = KV86M_EMULATE_CLI_STI | KV86M_ALLOW_IO_PORT_ACCESS;
73 Regs->Vif = 1;
74 Regs->PStatus = &Status;
75
76 /*
77 * Execute the BIOS interrupt
78 */
79 Ki386RetToV86Mode(Regs, &ORegs);
80
81 /*
82 * Copy the return values back to the caller
83 */
84 memcpy(Regs, &ORegs, sizeof(KV86M_REGISTERS));
85
86 return(Status);
87 }
88
89
90
91
92