4 * Copyright (C) 2002, 2003, 2004 ReactOS Team
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
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 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "internal/i386/v86m.h"
25 /* PRIVATE FUNCTIONS **********************************************************/
29 IntInt10AllocateBuffer(
37 PKPROCESS CallingProcess
= (PKPROCESS
)PsGetCurrentProcess();
40 TRACE_(VIDEOPRT
, "IntInt10AllocateBuffer\n");
42 IntAttachToCSRSS(&CallingProcess
, &ApcState
);
44 MemoryAddress
= (PVOID
)0x20000;
45 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(), &MemoryAddress
, 0,
46 Length
, MEM_COMMIT
, PAGE_EXECUTE_READWRITE
);
48 if (!NT_SUCCESS(Status
))
50 WARN_(VIDEOPRT
, "- ZwAllocateVirtualMemory failed\n");
51 IntDetachFromCSRSS(&CallingProcess
, &ApcState
);
52 return ERROR_NOT_ENOUGH_MEMORY
;
55 if (MemoryAddress
> (PVOID
)(0x100000 - *Length
))
57 ZwFreeVirtualMemory(NtCurrentProcess(), &MemoryAddress
, Length
,
59 WARN_(VIDEOPRT
, "- Unacceptable memory allocated\n");
60 IntDetachFromCSRSS(&CallingProcess
, &ApcState
);
61 return ERROR_NOT_ENOUGH_MEMORY
;
64 *Seg
= (ULONG
)MemoryAddress
>> 4;
65 *Off
= (ULONG
)MemoryAddress
& 0xF;
67 INFO_(VIDEOPRT
, "- Segment: %x\n", (ULONG
)MemoryAddress
>> 4);
68 INFO_(VIDEOPRT
, "- Offset: %x\n", (ULONG
)MemoryAddress
& 0xF);
69 INFO_(VIDEOPRT
, "- Length: %x\n", *Length
);
71 IntDetachFromCSRSS(&CallingProcess
, &ApcState
);
82 PVOID MemoryAddress
= (PVOID
)((Seg
<< 4) | Off
);
84 PKPROCESS CallingProcess
= (PKPROCESS
)PsGetCurrentProcess();
87 TRACE_(VIDEOPRT
, "IntInt10FreeBuffer\n");
88 INFO_(VIDEOPRT
, "- Segment: %x\n", Seg
);
89 INFO_(VIDEOPRT
, "- Offset: %x\n", Off
);
91 IntAttachToCSRSS(&CallingProcess
, &ApcState
);
92 Status
= ZwFreeVirtualMemory(NtCurrentProcess(), &MemoryAddress
, 0,
94 IntDetachFromCSRSS(&CallingProcess
, &ApcState
);
107 PKPROCESS CallingProcess
= (PKPROCESS
)PsGetCurrentProcess();
110 TRACE_(VIDEOPRT
, "IntInt10ReadMemory\n");
111 INFO_(VIDEOPRT
, "- Segment: %x\n", Seg
);
112 INFO_(VIDEOPRT
, "- Offset: %x\n", Off
);
113 INFO_(VIDEOPRT
, "- Buffer: %x\n", Buffer
);
114 INFO_(VIDEOPRT
, "- Length: %x\n", Length
);
116 IntAttachToCSRSS(&CallingProcess
, &ApcState
);
117 RtlCopyMemory(Buffer
, (PVOID
)((Seg
<< 4) | Off
), Length
);
118 IntDetachFromCSRSS(&CallingProcess
, &ApcState
);
131 PKPROCESS CallingProcess
= (PKPROCESS
)PsGetCurrentProcess();
134 TRACE_(VIDEOPRT
, "IntInt10WriteMemory\n");
135 INFO_(VIDEOPRT
, "- Segment: %x\n", Seg
);
136 INFO_(VIDEOPRT
, "- Offset: %x\n", Off
);
137 INFO_(VIDEOPRT
, "- Buffer: %x\n", Buffer
);
138 INFO_(VIDEOPRT
, "- Length: %x\n", Length
);
140 IntAttachToCSRSS(&CallingProcess
, &ApcState
);
141 RtlCopyMemory((PVOID
)((Seg
<< 4) | Off
), Buffer
, Length
);
142 IntDetachFromCSRSS(&CallingProcess
, &ApcState
);
151 IN OUT PINT10_BIOS_ARGUMENTS BiosArguments
)
155 PKPROCESS CallingProcess
= (PKPROCESS
)PsGetCurrentProcess();
158 /* Attach to CSRSS */
159 IntAttachToCSRSS(&CallingProcess
, &ApcState
);
161 /* Clear the context */
162 RtlZeroMemory(&BiosContext
, sizeof(CONTEXT
));
164 /* Fill out the bios arguments */
165 BiosContext
.Eax
= BiosArguments
->Eax
;
166 BiosContext
.Ebx
= BiosArguments
->Ebx
;
167 BiosContext
.Ecx
= BiosArguments
->Ecx
;
168 BiosContext
.Edx
= BiosArguments
->Edx
;
169 BiosContext
.Esi
= BiosArguments
->Esi
;
170 BiosContext
.Edi
= BiosArguments
->Edi
;
171 BiosContext
.Ebp
= BiosArguments
->Ebp
;
172 BiosContext
.SegDs
= BiosArguments
->SegDs
;
173 BiosContext
.SegEs
= BiosArguments
->SegEs
;
175 /* Do the ROM BIOS call */
176 Status
= Ke386CallBios(0x10, &BiosContext
);
178 /* Return the arguments */
179 BiosArguments
->Eax
= BiosContext
.Eax
;
180 BiosArguments
->Ebx
= BiosContext
.Ebx
;
181 BiosArguments
->Ecx
= BiosContext
.Ecx
;
182 BiosArguments
->Edx
= BiosContext
.Edx
;
183 BiosArguments
->Esi
= BiosContext
.Esi
;
184 BiosArguments
->Edi
= BiosContext
.Edi
;
185 BiosArguments
->Ebp
= BiosContext
.Ebp
;
186 BiosArguments
->SegDs
= BiosContext
.SegDs
;
187 BiosArguments
->SegEs
= BiosContext
.SegEs
;
189 /* Detach and return status */
190 IntDetachFromCSRSS(&CallingProcess
, &ApcState
);
191 if (NT_SUCCESS(Status
)) return NO_ERROR
;
192 return ERROR_INVALID_PARAMETER
;
196 /* PUBLIC FUNCTIONS ***********************************************************/
204 IN PVOID HwDeviceExtension
,
205 IN PVIDEO_X86_BIOS_ARGUMENTS BiosArguments
)
210 PKPROCESS CallingProcess
= (PKPROCESS
)PsGetCurrentProcess();
213 if (!CsrssInitialized
)
215 return ERROR_INVALID_PARAMETER
;
218 /* Attach to CSRSS */
219 IntAttachToCSRSS(&CallingProcess
, &ApcState
);
221 /* Clear the context */
222 RtlZeroMemory(&BiosContext
, sizeof(CONTEXT
));
224 /* Fill out the bios arguments */
225 BiosContext
.Eax
= BiosArguments
->Eax
;
226 BiosContext
.Ebx
= BiosArguments
->Ebx
;
227 BiosContext
.Ecx
= BiosArguments
->Ecx
;
228 BiosContext
.Edx
= BiosArguments
->Edx
;
229 BiosContext
.Esi
= BiosArguments
->Esi
;
230 BiosContext
.Edi
= BiosArguments
->Edi
;
231 BiosContext
.Ebp
= BiosArguments
->Ebp
;
233 /* Do the ROM BIOS call */
234 Status
= Ke386CallBios(0x10, &BiosContext
);
236 /* Return the arguments */
237 BiosArguments
->Eax
= BiosContext
.Eax
;
238 BiosArguments
->Ebx
= BiosContext
.Ebx
;
239 BiosArguments
->Ecx
= BiosContext
.Ecx
;
240 BiosArguments
->Edx
= BiosContext
.Edx
;
241 BiosArguments
->Esi
= BiosContext
.Esi
;
242 BiosArguments
->Edi
= BiosContext
.Edi
;
243 BiosArguments
->Ebp
= BiosContext
.Ebp
;
245 /* Detach from CSRSS */
246 IntDetachFromCSRSS(&CallingProcess
, &ApcState
);
247 if (NT_SUCCESS(Status
)) return NO_ERROR
;
248 return ERROR_INVALID_PARAMETER
;
250 /* Not implemented for anything else than X86*/
251 DPRINT1("Int10 not available on non-x86!\n");
252 return ERROR_INVALID_FUNCTION
;