2004-01-19 15:56:53 +00:00
|
|
|
/*
|
|
|
|
* VideoPort driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002, 2003, 2004 ReactOS Team
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2009-10-27 10:34:16 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
2004-01-19 15:56:53 +00:00
|
|
|
* License as published by the Free Software Foundation; either
|
2009-10-27 10:34:16 +00:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2004-01-19 15:56:53 +00:00
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2009-10-27 10:34:16 +00:00
|
|
|
* Lesser General Public License for more details.
|
2004-01-19 15:56:53 +00:00
|
|
|
*
|
2009-10-27 10:34:16 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2004-01-19 15:56:53 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "videoprt.h"
|
|
|
|
|
2004-03-19 20:58:32 +00:00
|
|
|
/* PRIVATE FUNCTIONS **********************************************************/
|
2004-01-19 15:56:53 +00:00
|
|
|
|
2010-03-25 05:03:29 +00:00
|
|
|
#if defined(_M_IX86)
|
2005-08-24 21:29:24 +00:00
|
|
|
VP_STATUS NTAPI
|
2004-01-19 15:56:53 +00:00
|
|
|
IntInt10AllocateBuffer(
|
|
|
|
IN PVOID Context,
|
|
|
|
OUT PUSHORT Seg,
|
|
|
|
OUT PUSHORT Off,
|
|
|
|
IN OUT PULONG Length)
|
|
|
|
{
|
|
|
|
PVOID MemoryAddress;
|
|
|
|
NTSTATUS Status;
|
2008-12-26 15:24:54 +00:00
|
|
|
PKPROCESS CallingProcess = (PKPROCESS)PsGetCurrentProcess();
|
2005-06-14 20:24:02 +00:00
|
|
|
KAPC_STATE ApcState;
|
2004-01-19 15:56:53 +00:00
|
|
|
|
2007-12-28 14:47:03 +00:00
|
|
|
TRACE_(VIDEOPRT, "IntInt10AllocateBuffer\n");
|
2004-01-19 15:56:53 +00:00
|
|
|
|
2005-06-14 20:24:02 +00:00
|
|
|
IntAttachToCSRSS(&CallingProcess, &ApcState);
|
2004-03-08 21:45:39 +00:00
|
|
|
|
2004-01-19 15:56:53 +00:00
|
|
|
MemoryAddress = (PVOID)0x20000;
|
|
|
|
Status = ZwAllocateVirtualMemory(NtCurrentProcess(), &MemoryAddress, 0,
|
|
|
|
Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
|
2004-03-19 20:58:32 +00:00
|
|
|
|
2004-01-19 15:56:53 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2007-12-28 14:47:03 +00:00
|
|
|
WARN_(VIDEOPRT, "- ZwAllocateVirtualMemory failed\n");
|
2005-06-14 20:24:02 +00:00
|
|
|
IntDetachFromCSRSS(&CallingProcess, &ApcState);
|
2004-03-19 20:58:32 +00:00
|
|
|
return ERROR_NOT_ENOUGH_MEMORY;
|
2004-01-19 15:56:53 +00:00
|
|
|
}
|
2004-03-19 20:58:32 +00:00
|
|
|
|
2004-01-19 15:56:53 +00:00
|
|
|
if (MemoryAddress > (PVOID)(0x100000 - *Length))
|
|
|
|
{
|
|
|
|
ZwFreeVirtualMemory(NtCurrentProcess(), &MemoryAddress, Length,
|
|
|
|
MEM_RELEASE);
|
2007-12-28 14:47:03 +00:00
|
|
|
WARN_(VIDEOPRT, "- Unacceptable memory allocated\n");
|
2005-06-14 20:24:02 +00:00
|
|
|
IntDetachFromCSRSS(&CallingProcess, &ApcState);
|
2004-03-19 20:58:32 +00:00
|
|
|
return ERROR_NOT_ENOUGH_MEMORY;
|
2004-01-19 15:56:53 +00:00
|
|
|
}
|
|
|
|
|
2011-06-25 14:10:19 +00:00
|
|
|
*Seg = (USHORT)((ULONG)MemoryAddress >> 4);
|
|
|
|
*Off = (USHORT)((ULONG)MemoryAddress & 0xF);
|
2004-01-19 15:56:53 +00:00
|
|
|
|
2007-12-28 14:47:03 +00:00
|
|
|
INFO_(VIDEOPRT, "- Segment: %x\n", (ULONG)MemoryAddress >> 4);
|
|
|
|
INFO_(VIDEOPRT, "- Offset: %x\n", (ULONG)MemoryAddress & 0xF);
|
|
|
|
INFO_(VIDEOPRT, "- Length: %x\n", *Length);
|
2004-02-22 22:19:42 +00:00
|
|
|
|
2005-06-14 20:24:02 +00:00
|
|
|
IntDetachFromCSRSS(&CallingProcess, &ApcState);
|
2004-03-08 21:45:39 +00:00
|
|
|
|
2004-03-19 20:58:32 +00:00
|
|
|
return NO_ERROR;
|
2004-01-19 15:56:53 +00:00
|
|
|
}
|
|
|
|
|
2005-08-24 21:29:24 +00:00
|
|
|
VP_STATUS NTAPI
|
2004-01-19 15:56:53 +00:00
|
|
|
IntInt10FreeBuffer(
|
|
|
|
IN PVOID Context,
|
|
|
|
IN USHORT Seg,
|
|
|
|
IN USHORT Off)
|
|
|
|
{
|
2004-07-19 17:55:33 +00:00
|
|
|
PVOID MemoryAddress = (PVOID)((Seg << 4) | Off);
|
2004-03-08 21:45:39 +00:00
|
|
|
NTSTATUS Status;
|
2008-12-26 15:24:54 +00:00
|
|
|
PKPROCESS CallingProcess = (PKPROCESS)PsGetCurrentProcess();
|
2005-06-14 20:24:02 +00:00
|
|
|
KAPC_STATE ApcState;
|
2011-12-17 09:18:24 +00:00
|
|
|
SIZE_T Size = 0;
|
2004-03-08 21:45:39 +00:00
|
|
|
|
2007-12-28 14:47:03 +00:00
|
|
|
TRACE_(VIDEOPRT, "IntInt10FreeBuffer\n");
|
|
|
|
INFO_(VIDEOPRT, "- Segment: %x\n", Seg);
|
|
|
|
INFO_(VIDEOPRT, "- Offset: %x\n", Off);
|
2004-03-08 21:45:39 +00:00
|
|
|
|
2005-06-14 20:24:02 +00:00
|
|
|
IntAttachToCSRSS(&CallingProcess, &ApcState);
|
2011-12-17 09:18:24 +00:00
|
|
|
Status = ZwFreeVirtualMemory(NtCurrentProcess(), &MemoryAddress, &Size,
|
2004-01-19 15:56:53 +00:00
|
|
|
MEM_RELEASE);
|
2005-06-14 20:24:02 +00:00
|
|
|
IntDetachFromCSRSS(&CallingProcess, &ApcState);
|
2004-03-08 21:45:39 +00:00
|
|
|
|
|
|
|
return Status;
|
2004-01-19 15:56:53 +00:00
|
|
|
}
|
|
|
|
|
2005-08-24 21:29:24 +00:00
|
|
|
VP_STATUS NTAPI
|
2004-01-19 15:56:53 +00:00
|
|
|
IntInt10ReadMemory(
|
|
|
|
IN PVOID Context,
|
|
|
|
IN USHORT Seg,
|
|
|
|
IN USHORT Off,
|
|
|
|
OUT PVOID Buffer,
|
|
|
|
IN ULONG Length)
|
|
|
|
{
|
2008-12-26 15:24:54 +00:00
|
|
|
PKPROCESS CallingProcess = (PKPROCESS)PsGetCurrentProcess();
|
2005-06-14 20:24:02 +00:00
|
|
|
KAPC_STATE ApcState;
|
2004-03-08 21:45:39 +00:00
|
|
|
|
2007-12-28 14:47:03 +00:00
|
|
|
TRACE_(VIDEOPRT, "IntInt10ReadMemory\n");
|
|
|
|
INFO_(VIDEOPRT, "- Segment: %x\n", Seg);
|
|
|
|
INFO_(VIDEOPRT, "- Offset: %x\n", Off);
|
|
|
|
INFO_(VIDEOPRT, "- Buffer: %x\n", Buffer);
|
|
|
|
INFO_(VIDEOPRT, "- Length: %x\n", Length);
|
2004-03-08 21:45:39 +00:00
|
|
|
|
2005-06-14 20:24:02 +00:00
|
|
|
IntAttachToCSRSS(&CallingProcess, &ApcState);
|
2004-07-19 17:55:33 +00:00
|
|
|
RtlCopyMemory(Buffer, (PVOID)((Seg << 4) | Off), Length);
|
2005-06-14 20:24:02 +00:00
|
|
|
IntDetachFromCSRSS(&CallingProcess, &ApcState);
|
2004-03-08 21:45:39 +00:00
|
|
|
|
2004-03-19 20:58:32 +00:00
|
|
|
return NO_ERROR;
|
2004-01-19 15:56:53 +00:00
|
|
|
}
|
|
|
|
|
2005-08-24 21:29:24 +00:00
|
|
|
VP_STATUS NTAPI
|
2004-01-19 15:56:53 +00:00
|
|
|
IntInt10WriteMemory(
|
|
|
|
IN PVOID Context,
|
|
|
|
IN USHORT Seg,
|
|
|
|
IN USHORT Off,
|
|
|
|
IN PVOID Buffer,
|
|
|
|
IN ULONG Length)
|
|
|
|
{
|
2008-12-26 15:24:54 +00:00
|
|
|
PKPROCESS CallingProcess = (PKPROCESS)PsGetCurrentProcess();
|
2005-06-14 20:24:02 +00:00
|
|
|
KAPC_STATE ApcState;
|
2004-03-08 21:45:39 +00:00
|
|
|
|
2007-12-28 14:47:03 +00:00
|
|
|
TRACE_(VIDEOPRT, "IntInt10WriteMemory\n");
|
|
|
|
INFO_(VIDEOPRT, "- Segment: %x\n", Seg);
|
|
|
|
INFO_(VIDEOPRT, "- Offset: %x\n", Off);
|
|
|
|
INFO_(VIDEOPRT, "- Buffer: %x\n", Buffer);
|
|
|
|
INFO_(VIDEOPRT, "- Length: %x\n", Length);
|
2004-03-08 21:45:39 +00:00
|
|
|
|
2005-06-14 20:24:02 +00:00
|
|
|
IntAttachToCSRSS(&CallingProcess, &ApcState);
|
2004-07-19 17:55:33 +00:00
|
|
|
RtlCopyMemory((PVOID)((Seg << 4) | Off), Buffer, Length);
|
2005-06-14 20:24:02 +00:00
|
|
|
IntDetachFromCSRSS(&CallingProcess, &ApcState);
|
2004-03-08 21:45:39 +00:00
|
|
|
|
2004-03-19 20:58:32 +00:00
|
|
|
return NO_ERROR;
|
2004-01-19 15:56:53 +00:00
|
|
|
}
|
|
|
|
|
2006-08-28 23:56:35 +00:00
|
|
|
VP_STATUS
|
|
|
|
NTAPI
|
2004-01-19 15:56:53 +00:00
|
|
|
IntInt10CallBios(
|
2006-08-28 23:56:35 +00:00
|
|
|
IN PVOID Context,
|
|
|
|
IN OUT PINT10_BIOS_ARGUMENTS BiosArguments)
|
2004-01-19 15:56:53 +00:00
|
|
|
{
|
2006-08-28 23:56:35 +00:00
|
|
|
CONTEXT BiosContext;
|
|
|
|
NTSTATUS Status;
|
2008-12-26 15:24:54 +00:00
|
|
|
PKPROCESS CallingProcess = (PKPROCESS)PsGetCurrentProcess();
|
2006-08-28 23:56:35 +00:00
|
|
|
KAPC_STATE ApcState;
|
|
|
|
|
|
|
|
/* Attach to CSRSS */
|
|
|
|
IntAttachToCSRSS(&CallingProcess, &ApcState);
|
|
|
|
|
|
|
|
/* Clear the context */
|
|
|
|
RtlZeroMemory(&BiosContext, sizeof(CONTEXT));
|
|
|
|
|
2008-02-25 14:25:15 +00:00
|
|
|
/* Fill out the bios arguments */
|
2006-08-28 23:56:35 +00:00
|
|
|
BiosContext.Eax = BiosArguments->Eax;
|
|
|
|
BiosContext.Ebx = BiosArguments->Ebx;
|
|
|
|
BiosContext.Ecx = BiosArguments->Ecx;
|
|
|
|
BiosContext.Edx = BiosArguments->Edx;
|
|
|
|
BiosContext.Esi = BiosArguments->Esi;
|
|
|
|
BiosContext.Edi = BiosArguments->Edi;
|
|
|
|
BiosContext.Ebp = BiosArguments->Ebp;
|
|
|
|
BiosContext.SegDs = BiosArguments->SegDs;
|
|
|
|
BiosContext.SegEs = BiosArguments->SegEs;
|
|
|
|
|
|
|
|
/* Do the ROM BIOS call */
|
|
|
|
Status = Ke386CallBios(0x10, &BiosContext);
|
|
|
|
|
|
|
|
/* Return the arguments */
|
|
|
|
BiosArguments->Eax = BiosContext.Eax;
|
|
|
|
BiosArguments->Ebx = BiosContext.Ebx;
|
|
|
|
BiosArguments->Ecx = BiosContext.Ecx;
|
|
|
|
BiosArguments->Edx = BiosContext.Edx;
|
|
|
|
BiosArguments->Esi = BiosContext.Esi;
|
|
|
|
BiosArguments->Edi = BiosContext.Edi;
|
|
|
|
BiosArguments->Ebp = BiosContext.Ebp;
|
2011-06-25 14:10:19 +00:00
|
|
|
BiosArguments->SegDs = (USHORT)BiosContext.SegDs;
|
|
|
|
BiosArguments->SegEs = (USHORT)BiosContext.SegEs;
|
2006-08-28 23:56:35 +00:00
|
|
|
|
|
|
|
/* Detach and return status */
|
|
|
|
IntDetachFromCSRSS(&CallingProcess, &ApcState);
|
2010-03-03 05:22:45 +00:00
|
|
|
if (NT_SUCCESS(Status)) return NO_ERROR;
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2004-01-19 15:56:53 +00:00
|
|
|
}
|
2010-03-25 05:03:29 +00:00
|
|
|
#endif
|
2004-03-19 20:58:32 +00:00
|
|
|
|
|
|
|
/* PUBLIC FUNCTIONS ***********************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
|
2005-08-24 21:29:24 +00:00
|
|
|
VP_STATUS NTAPI
|
2004-03-19 20:58:32 +00:00
|
|
|
VideoPortInt10(
|
2008-12-27 04:01:26 +00:00
|
|
|
IN PVOID HwDeviceExtension,
|
|
|
|
IN PVIDEO_X86_BIOS_ARGUMENTS BiosArguments)
|
2004-03-19 20:58:32 +00:00
|
|
|
{
|
2010-03-25 05:03:29 +00:00
|
|
|
#if defined(_M_IX86)
|
2008-12-27 04:01:26 +00:00
|
|
|
CONTEXT BiosContext;
|
|
|
|
NTSTATUS Status;
|
|
|
|
PKPROCESS CallingProcess = (PKPROCESS)PsGetCurrentProcess();
|
|
|
|
KAPC_STATE ApcState;
|
2004-03-19 20:58:32 +00:00
|
|
|
|
2008-12-27 04:01:26 +00:00
|
|
|
if (!CsrssInitialized)
|
|
|
|
{
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
2004-03-19 20:58:32 +00:00
|
|
|
|
2008-12-27 04:01:26 +00:00
|
|
|
/* Attach to CSRSS */
|
|
|
|
IntAttachToCSRSS(&CallingProcess, &ApcState);
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2008-12-27 04:01:26 +00:00
|
|
|
/* Clear the context */
|
|
|
|
RtlZeroMemory(&BiosContext, sizeof(CONTEXT));
|
|
|
|
|
|
|
|
/* Fill out the bios arguments */
|
|
|
|
BiosContext.Eax = BiosArguments->Eax;
|
|
|
|
BiosContext.Ebx = BiosArguments->Ebx;
|
|
|
|
BiosContext.Ecx = BiosArguments->Ecx;
|
|
|
|
BiosContext.Edx = BiosArguments->Edx;
|
|
|
|
BiosContext.Esi = BiosArguments->Esi;
|
|
|
|
BiosContext.Edi = BiosArguments->Edi;
|
|
|
|
BiosContext.Ebp = BiosArguments->Ebp;
|
2004-03-19 20:58:32 +00:00
|
|
|
|
2008-12-27 04:01:26 +00:00
|
|
|
/* Do the ROM BIOS call */
|
|
|
|
Status = Ke386CallBios(0x10, &BiosContext);
|
2004-03-19 20:58:32 +00:00
|
|
|
|
2008-12-27 04:01:26 +00:00
|
|
|
/* Return the arguments */
|
|
|
|
BiosArguments->Eax = BiosContext.Eax;
|
|
|
|
BiosArguments->Ebx = BiosContext.Ebx;
|
|
|
|
BiosArguments->Ecx = BiosContext.Ecx;
|
|
|
|
BiosArguments->Edx = BiosContext.Edx;
|
|
|
|
BiosArguments->Esi = BiosContext.Esi;
|
|
|
|
BiosArguments->Edi = BiosContext.Edi;
|
|
|
|
BiosArguments->Ebp = BiosContext.Ebp;
|
2004-03-19 20:58:32 +00:00
|
|
|
|
2008-12-27 04:01:26 +00:00
|
|
|
/* Detach from CSRSS */
|
|
|
|
IntDetachFromCSRSS(&CallingProcess, &ApcState);
|
2010-03-03 05:22:45 +00:00
|
|
|
if (NT_SUCCESS(Status)) return NO_ERROR;
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2010-03-25 05:03:29 +00:00
|
|
|
#else
|
|
|
|
/* Not implemented for anything else than X86*/
|
|
|
|
DPRINT1("Int10 not available on non-x86!\n");
|
|
|
|
return ERROR_INVALID_FUNCTION;
|
|
|
|
#endif
|
2004-03-19 20:58:32 +00:00
|
|
|
}
|