migrate substitution keywords to SVN
[reactos.git] / reactos / drivers / video / videoprt / int10.c
1 /*
2 * VideoPort driver
3 *
4 * Copyright (C) 2002, 2003, 2004 ReactOS Team
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; see the file COPYING.LIB.
18 * If not, write to the Free Software Foundation,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 *
21 * $Id$
22 */
23
24 #include "videoprt.h"
25 #include "internal/v86m.h"
26
27 /* PRIVATE FUNCTIONS **********************************************************/
28
29 VP_STATUS STDCALL
30 IntInt10AllocateBuffer(
31 IN PVOID Context,
32 OUT PUSHORT Seg,
33 OUT PUSHORT Off,
34 IN OUT PULONG Length)
35 {
36 PVOID MemoryAddress;
37 NTSTATUS Status;
38 PEPROCESS CallingProcess;
39 PEPROCESS PrevAttachedProcess;
40
41 DPRINT("IntInt10AllocateBuffer\n");
42
43 IntAttachToCSRSS(&CallingProcess, &PrevAttachedProcess);
44
45 MemoryAddress = (PVOID)0x20000;
46 Status = ZwAllocateVirtualMemory(NtCurrentProcess(), &MemoryAddress, 0,
47 Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
48
49 if (!NT_SUCCESS(Status))
50 {
51 DPRINT("- ZwAllocateVirtualMemory failed\n");
52 IntDetachFromCSRSS(&CallingProcess, &PrevAttachedProcess);
53 return ERROR_NOT_ENOUGH_MEMORY;
54 }
55
56 if (MemoryAddress > (PVOID)(0x100000 - *Length))
57 {
58 ZwFreeVirtualMemory(NtCurrentProcess(), &MemoryAddress, Length,
59 MEM_RELEASE);
60 DPRINT("- Unacceptable memory allocated\n");
61 IntDetachFromCSRSS(&CallingProcess, &PrevAttachedProcess);
62 return ERROR_NOT_ENOUGH_MEMORY;
63 }
64
65 *Seg = (ULONG)MemoryAddress >> 4;
66 *Off = (ULONG)MemoryAddress & 0xF;
67
68 DPRINT("- Segment: %x\n", (ULONG)MemoryAddress >> 4);
69 DPRINT("- Offset: %x\n", (ULONG)MemoryAddress & 0xF);
70 DPRINT("- Length: %x\n", *Length);
71
72 IntDetachFromCSRSS(&CallingProcess, &PrevAttachedProcess);
73
74 return NO_ERROR;
75 }
76
77 VP_STATUS STDCALL
78 IntInt10FreeBuffer(
79 IN PVOID Context,
80 IN USHORT Seg,
81 IN USHORT Off)
82 {
83 PVOID MemoryAddress = (PVOID)((Seg << 4) | Off);
84 NTSTATUS Status;
85 PEPROCESS CallingProcess;
86 PEPROCESS PrevAttachedProcess;
87
88 DPRINT("IntInt10FreeBuffer\n");
89 DPRINT("- Segment: %x\n", Seg);
90 DPRINT("- Offset: %x\n", Off);
91
92 IntAttachToCSRSS(&CallingProcess, &PrevAttachedProcess);
93 Status = ZwFreeVirtualMemory(NtCurrentProcess(), &MemoryAddress, 0,
94 MEM_RELEASE);
95 IntDetachFromCSRSS(&CallingProcess, &PrevAttachedProcess);
96
97 return Status;
98 }
99
100 VP_STATUS STDCALL
101 IntInt10ReadMemory(
102 IN PVOID Context,
103 IN USHORT Seg,
104 IN USHORT Off,
105 OUT PVOID Buffer,
106 IN ULONG Length)
107 {
108 PEPROCESS CallingProcess;
109 PEPROCESS PrevAttachedProcess;
110
111 DPRINT("IntInt10ReadMemory\n");
112 DPRINT("- Segment: %x\n", Seg);
113 DPRINT("- Offset: %x\n", Off);
114 DPRINT("- Buffer: %x\n", Buffer);
115 DPRINT("- Length: %x\n", Length);
116
117 IntAttachToCSRSS(&CallingProcess, &PrevAttachedProcess);
118 RtlCopyMemory(Buffer, (PVOID)((Seg << 4) | Off), Length);
119 IntDetachFromCSRSS(&CallingProcess, &PrevAttachedProcess);
120
121 return NO_ERROR;
122 }
123
124 VP_STATUS STDCALL
125 IntInt10WriteMemory(
126 IN PVOID Context,
127 IN USHORT Seg,
128 IN USHORT Off,
129 IN PVOID Buffer,
130 IN ULONG Length)
131 {
132 PEPROCESS CallingProcess;
133 PEPROCESS PrevAttachedProcess;
134
135 DPRINT("IntInt10WriteMemory\n");
136 DPRINT("- Segment: %x\n", Seg);
137 DPRINT("- Offset: %x\n", Off);
138 DPRINT("- Buffer: %x\n", Buffer);
139 DPRINT("- Length: %x\n", Length);
140
141 IntAttachToCSRSS(&CallingProcess, &PrevAttachedProcess);
142 RtlCopyMemory((PVOID)((Seg << 4) | Off), Buffer, Length);
143 IntDetachFromCSRSS(&CallingProcess, &PrevAttachedProcess);
144
145 return NO_ERROR;
146 }
147
148 VP_STATUS STDCALL
149 IntInt10CallBios(
150 IN PVOID Context,
151 IN OUT PINT10_BIOS_ARGUMENTS BiosArguments)
152 {
153 KV86M_REGISTERS Regs;
154 NTSTATUS Status;
155 PEPROCESS CallingProcess;
156 PEPROCESS PrevAttachedProcess;
157
158 DPRINT("IntInt10CallBios\n");
159
160 IntAttachToCSRSS(&CallingProcess, &PrevAttachedProcess);
161
162 memset(&Regs, 0, sizeof(Regs));
163 DPRINT("- Input register Eax: %x\n", BiosArguments->Eax);
164 Regs.Eax = BiosArguments->Eax;
165 DPRINT("- Input register Ebx: %x\n", BiosArguments->Ebx);
166 Regs.Ebx = BiosArguments->Ebx;
167 DPRINT("- Input register Ecx: %x\n", BiosArguments->Ecx);
168 Regs.Ecx = BiosArguments->Ecx;
169 DPRINT("- Input register Edx: %x\n", BiosArguments->Edx);
170 Regs.Edx = BiosArguments->Edx;
171 DPRINT("- Input register Esi: %x\n", BiosArguments->Esi);
172 Regs.Esi = BiosArguments->Esi;
173 DPRINT("- Input register Edi: %x\n", BiosArguments->Edi);
174 Regs.Edi = BiosArguments->Edi;
175 DPRINT("- Input register Ebp: %x\n", BiosArguments->Ebp);
176 Regs.Ebp = BiosArguments->Ebp;
177 DPRINT("- Input register SegDs: %x\n", BiosArguments->SegDs);
178 Regs.Ds = BiosArguments->SegDs;
179 DPRINT("- Input register SegEs: %x\n", BiosArguments->SegEs);
180 Regs.Es = BiosArguments->SegEs;
181 Status = Ke386CallBios(0x10, &Regs);
182 BiosArguments->Eax = Regs.Eax;
183 BiosArguments->Ebx = Regs.Ebx;
184 BiosArguments->Ecx = Regs.Ecx;
185 BiosArguments->Edx = Regs.Edx;
186 BiosArguments->Esi = Regs.Esi;
187 BiosArguments->Edi = Regs.Edi;
188 BiosArguments->Ebp = Regs.Ebp;
189 BiosArguments->SegDs = Regs.Ds;
190 BiosArguments->SegEs = Regs.Es;
191
192 IntDetachFromCSRSS(&CallingProcess, &PrevAttachedProcess);
193
194 return Status;
195 }
196
197 /* PUBLIC FUNCTIONS ***********************************************************/
198
199 /*
200 * @implemented
201 */
202
203 VP_STATUS STDCALL
204 VideoPortInt10(
205 IN PVOID HwDeviceExtension,
206 IN PVIDEO_X86_BIOS_ARGUMENTS BiosArguments)
207 {
208 KV86M_REGISTERS Regs;
209 NTSTATUS Status;
210 PEPROCESS CallingProcess;
211 PEPROCESS PrevAttachedProcess;
212
213 DPRINT("VideoPortInt10\n");
214
215 IntAttachToCSRSS(&CallingProcess, &PrevAttachedProcess);
216
217 memset(&Regs, 0, sizeof(Regs));
218 DPRINT("- Input register Eax: %x\n", BiosArguments->Eax);
219 Regs.Eax = BiosArguments->Eax;
220 DPRINT("- Input register Ebx: %x\n", BiosArguments->Ebx);
221 Regs.Ebx = BiosArguments->Ebx;
222 DPRINT("- Input register Ecx: %x\n", BiosArguments->Ecx);
223 Regs.Ecx = BiosArguments->Ecx;
224 DPRINT("- Input register Edx: %x\n", BiosArguments->Edx);
225 Regs.Edx = BiosArguments->Edx;
226 DPRINT("- Input register Esi: %x\n", BiosArguments->Esi);
227 Regs.Esi = BiosArguments->Esi;
228 DPRINT("- Input register Edi: %x\n", BiosArguments->Edi);
229 Regs.Edi = BiosArguments->Edi;
230 DPRINT("- Input register Ebp: %x\n", BiosArguments->Ebp);
231 Regs.Ebp = BiosArguments->Ebp;
232 Status = Ke386CallBios(0x10, &Regs);
233 BiosArguments->Eax = Regs.Eax;
234 BiosArguments->Ebx = Regs.Ebx;
235 BiosArguments->Ecx = Regs.Ecx;
236 BiosArguments->Edx = Regs.Edx;
237 BiosArguments->Esi = Regs.Esi;
238 BiosArguments->Edi = Regs.Edi;
239 BiosArguments->Ebp = Regs.Ebp;
240
241 IntDetachFromCSRSS(&CallingProcess, &PrevAttachedProcess);
242
243 return Status;
244 }