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 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.
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.
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.
24 #include "internal/i386/v86m.h"
26 /* PRIVATE FUNCTIONS **********************************************************/
29 IntInt10AllocateBuffer(
37 PKPROCESS CallingProcess
;
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
;
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
;
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
;
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
;
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
);
194 /* PUBLIC FUNCTIONS ***********************************************************/
202 IN PVOID HwDeviceExtension
,
203 IN PVIDEO_X86_BIOS_ARGUMENTS BiosArguments
)
205 KV86M_REGISTERS Regs
;
207 PKPROCESS CallingProcess
;
210 TRACE_(VIDEOPRT
, "VideoPortInt10\n");
212 if (!CsrssInitialized
)
214 return ERROR_INVALID_PARAMETER
;
217 IntAttachToCSRSS(&CallingProcess
, &ApcState
);
219 memset(&Regs
, 0, sizeof(Regs
));
220 INFO_(VIDEOPRT
, "- Input register Eax: %x\n", BiosArguments
->Eax
);
221 Regs
.Eax
= BiosArguments
->Eax
;
222 INFO_(VIDEOPRT
, "- Input register Ebx: %x\n", BiosArguments
->Ebx
);
223 Regs
.Ebx
= BiosArguments
->Ebx
;
224 INFO_(VIDEOPRT
, "- Input register Ecx: %x\n", BiosArguments
->Ecx
);
225 Regs
.Ecx
= BiosArguments
->Ecx
;
226 INFO_(VIDEOPRT
, "- Input register Edx: %x\n", BiosArguments
->Edx
);
227 Regs
.Edx
= BiosArguments
->Edx
;
228 INFO_(VIDEOPRT
, "- Input register Esi: %x\n", BiosArguments
->Esi
);
229 Regs
.Esi
= BiosArguments
->Esi
;
230 INFO_(VIDEOPRT
, "- Input register Edi: %x\n", BiosArguments
->Edi
);
231 Regs
.Edi
= BiosArguments
->Edi
;
232 INFO_(VIDEOPRT
, "- Input register Ebp: %x\n", BiosArguments
->Ebp
);
233 Regs
.Ebp
= BiosArguments
->Ebp
;
234 Status
= Ke386CallBios(0x10, (PCONTEXT
)&Regs
);
235 BiosArguments
->Eax
= Regs
.Eax
;
236 BiosArguments
->Ebx
= Regs
.Ebx
;
237 BiosArguments
->Ecx
= Regs
.Ecx
;
238 BiosArguments
->Edx
= Regs
.Edx
;
239 BiosArguments
->Esi
= Regs
.Esi
;
240 BiosArguments
->Edi
= Regs
.Edi
;
241 BiosArguments
->Ebp
= Regs
.Ebp
;
243 IntDetachFromCSRSS(&CallingProcess
, &ApcState
);