- NDK 0.98, now with versionned headers. Too many changes to list, see the TinyKRNL...
[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/i386/v86m.h"
26
27 /* PRIVATE FUNCTIONS **********************************************************/
28
29 VP_STATUS NTAPI
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 PKPROCESS CallingProcess;
39 KAPC_STATE ApcState;
40
41 DPRINT("IntInt10AllocateBuffer\n");
42
43 IntAttachToCSRSS(&CallingProcess, &ApcState);
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, &ApcState);
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, &ApcState);
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, &ApcState);
73
74 return NO_ERROR;
75 }
76
77 VP_STATUS NTAPI
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 PKPROCESS CallingProcess;
86 KAPC_STATE ApcState;
87
88 DPRINT("IntInt10FreeBuffer\n");
89 DPRINT("- Segment: %x\n", Seg);
90 DPRINT("- Offset: %x\n", Off);
91
92 IntAttachToCSRSS(&CallingProcess, &ApcState);
93 Status = ZwFreeVirtualMemory(NtCurrentProcess(), &MemoryAddress, 0,
94 MEM_RELEASE);
95 IntDetachFromCSRSS(&CallingProcess, &ApcState);
96
97 return Status;
98 }
99
100 VP_STATUS NTAPI
101 IntInt10ReadMemory(
102 IN PVOID Context,
103 IN USHORT Seg,
104 IN USHORT Off,
105 OUT PVOID Buffer,
106 IN ULONG Length)
107 {
108 PKPROCESS CallingProcess;
109 KAPC_STATE ApcState;
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, &ApcState);
118 RtlCopyMemory(Buffer, (PVOID)((Seg << 4) | Off), Length);
119 IntDetachFromCSRSS(&CallingProcess, &ApcState);
120
121 return NO_ERROR;
122 }
123
124 VP_STATUS NTAPI
125 IntInt10WriteMemory(
126 IN PVOID Context,
127 IN USHORT Seg,
128 IN USHORT Off,
129 IN PVOID Buffer,
130 IN ULONG Length)
131 {
132 PKPROCESS CallingProcess;
133 KAPC_STATE ApcState;
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, &ApcState);
142 RtlCopyMemory((PVOID)((Seg << 4) | Off), Buffer, Length);
143 IntDetachFromCSRSS(&CallingProcess, &ApcState);
144
145 return NO_ERROR;
146 }
147
148 VP_STATUS NTAPI
149 IntInt10CallBios(
150 IN PVOID Context,
151 IN OUT PINT10_BIOS_ARGUMENTS BiosArguments)
152 {
153 KV86M_REGISTERS Regs;
154 NTSTATUS Status;
155 PKPROCESS CallingProcess;
156 KAPC_STATE ApcState;
157
158 DPRINT("IntInt10CallBios\n");
159
160 IntAttachToCSRSS(&CallingProcess, &ApcState);
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, (PCONTEXT)&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, &ApcState);
193
194 return Status;
195 }
196
197 /* PUBLIC FUNCTIONS ***********************************************************/
198
199 /*
200 * @implemented
201 */
202
203 VP_STATUS NTAPI
204 VideoPortInt10(
205 IN PVOID HwDeviceExtension,
206 IN PVIDEO_X86_BIOS_ARGUMENTS BiosArguments)
207 {
208 KV86M_REGISTERS Regs;
209 NTSTATUS Status;
210 PKPROCESS CallingProcess;
211 KAPC_STATE ApcState;
212
213 DPRINT("VideoPortInt10\n");
214
215 if (!CsrssInitialized)
216 {
217 return ERROR_INVALID_PARAMETER;
218 }
219
220 IntAttachToCSRSS(&CallingProcess, &ApcState);
221
222 memset(&Regs, 0, sizeof(Regs));
223 DPRINT("- Input register Eax: %x\n", BiosArguments->Eax);
224 Regs.Eax = BiosArguments->Eax;
225 DPRINT("- Input register Ebx: %x\n", BiosArguments->Ebx);
226 Regs.Ebx = BiosArguments->Ebx;
227 DPRINT("- Input register Ecx: %x\n", BiosArguments->Ecx);
228 Regs.Ecx = BiosArguments->Ecx;
229 DPRINT("- Input register Edx: %x\n", BiosArguments->Edx);
230 Regs.Edx = BiosArguments->Edx;
231 DPRINT("- Input register Esi: %x\n", BiosArguments->Esi);
232 Regs.Esi = BiosArguments->Esi;
233 DPRINT("- Input register Edi: %x\n", BiosArguments->Edi);
234 Regs.Edi = BiosArguments->Edi;
235 DPRINT("- Input register Ebp: %x\n", BiosArguments->Ebp);
236 Regs.Ebp = BiosArguments->Ebp;
237 Status = Ke386CallBios(0x10, (PCONTEXT)&Regs);
238 BiosArguments->Eax = Regs.Eax;
239 BiosArguments->Ebx = Regs.Ebx;
240 BiosArguments->Ecx = Regs.Ecx;
241 BiosArguments->Edx = Regs.Edx;
242 BiosArguments->Esi = Regs.Esi;
243 BiosArguments->Edi = Regs.Edi;
244 BiosArguments->Ebp = Regs.Ebp;
245
246 IntDetachFromCSRSS(&CallingProcess, &ApcState);
247
248 return Status;
249 }