:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / 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 <ddk/ntddk.h>
29 #include <internal/v86m.h>
30
31 #define NDEBUG
32 #include <internal/debug.h>
33
34 /* GLOBALS *******************************************************************/
35
36 #define TRAMPOLINE_BASE    (0x10000)
37
38 extern VOID Ki386RetToV86Mode(PKV86M_REGISTERS InRegs,
39                               PKV86M_REGISTERS OutRegs);
40
41 /* FUNCTIONS *****************************************************************/
42
43 NTSTATUS STDCALL
44 Ke386CallBios(UCHAR Int, PKV86M_REGISTERS Regs)
45 {
46   PUCHAR Ip;
47   KV86M_REGISTERS ORegs;
48   NTSTATUS Status;
49
50   /*
51    * Set up a trampoline for executing the BIOS interrupt
52    */
53   Ip = (PUCHAR)TRAMPOLINE_BASE;
54   Ip[0] = 0xCD;              /* int XX */
55   Ip[1] = Int;
56   Ip[2] = 0x63;              /* arpl ax, ax */
57   Ip[3] = 0xC0;         
58   Ip[4] = 0x90;              /* nop */
59   Ip[5] = 0x90;              /* nop */
60   
61   /*
62    * Munge the registers
63    */
64   Regs->Eip = 0;
65   Regs->Cs = TRAMPOLINE_BASE / 16;
66   Regs->Esp = 0xFFFF;
67   Regs->Ss = TRAMPOLINE_BASE / 16;
68   Regs->Eflags = (1 << 1) | (1 << 17) | (1 << 9);     /* VM, IF */
69   Regs->RecoveryAddress = TRAMPOLINE_BASE + 2;
70   Regs->RecoveryInstruction[0] = 0x63;       /* arpl ax, ax */
71   Regs->RecoveryInstruction[1] = 0xC0; 
72   Regs->RecoveryInstruction[2] = 0x90;       /* nop */
73   Regs->RecoveryInstruction[3] = 0x90;       /* nop */
74   Regs->Flags = KV86M_EMULATE_CLI_STI | KV86M_ALLOW_IO_PORT_ACCESS;
75   Regs->Vif = 1;
76   Regs->PStatus = &Status;
77
78   /*
79    * Execute the BIOS interrupt
80    */
81   Ki386RetToV86Mode(Regs, &ORegs);
82
83   /*
84    * Copy the return values back to the caller
85    */
86   memcpy(Regs, &ORegs, sizeof(KV86M_REGISTERS));
87    
88   return(Status);
89 }
90
91
92
93
94