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"
|
|
|
|
|
2014-02-04 17:15:06 +00:00
|
|
|
#include <ndk/kefuncs.h>
|
2018-02-11 18:22:30 +00:00
|
|
|
#include <ndk/halfuncs.h>
|
2021-02-10 14:21:55 +00:00
|
|
|
#include <ndk/mmfuncs.h>
|
2014-02-04 17:15:06 +00:00
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2004-03-19 20:58:32 +00:00
|
|
|
/* PRIVATE FUNCTIONS **********************************************************/
|
2004-01-19 15:56:53 +00:00
|
|
|
|
2021-02-10 14:21:55 +00:00
|
|
|
#define IsLowV86Mem(_Seg, _Off) ((((_Seg) << 4) + (_Off)) < (0xa0000))
|
|
|
|
|
|
|
|
/* Those two functions below are there so that CSRSS can't access low mem.
|
|
|
|
* Expecially, MAKE IT CRASH ON NULL ACCESS */
|
|
|
|
static
|
|
|
|
VOID
|
|
|
|
ProtectLowV86Mem(VOID)
|
|
|
|
{
|
|
|
|
/* We pass a non-NULL address so that ZwAllocateVirtualMemory really does it
|
|
|
|
* And we truncate one page to get the right range spanned. */
|
|
|
|
PVOID BaseAddress = (PVOID)1;
|
|
|
|
NTSTATUS Status;
|
|
|
|
SIZE_T ViewSize = 0xa0000 - PAGE_SIZE;
|
|
|
|
|
|
|
|
/* We should only do that for CSRSS. */
|
|
|
|
ASSERT(PsGetCurrentProcess() == (PEPROCESS)CsrProcess);
|
|
|
|
|
|
|
|
/* Commit (again) the pages, but with PAGE_NOACCESS protection */
|
|
|
|
Status = ZwAllocateVirtualMemory(NtCurrentProcess(),
|
|
|
|
&BaseAddress,
|
|
|
|
0,
|
|
|
|
&ViewSize,
|
|
|
|
MEM_COMMIT,
|
|
|
|
PAGE_NOACCESS);
|
|
|
|
ASSERT(NT_SUCCESS(Status));
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
VOID
|
|
|
|
UnprotectLowV86Mem(VOID)
|
|
|
|
{
|
|
|
|
/* We pass a non-NULL address so that ZwAllocateVirtualMemory really does it
|
|
|
|
* And we truncate one page to get the right range spanned. */
|
|
|
|
PVOID BaseAddress = (PVOID)1;
|
|
|
|
NTSTATUS Status;
|
|
|
|
SIZE_T ViewSize = 0xa0000 - PAGE_SIZE;
|
|
|
|
|
|
|
|
/* We should only do that for CSRSS, for the v86 address space */
|
|
|
|
ASSERT(PsGetCurrentProcess() == (PEPROCESS)CsrProcess);
|
|
|
|
|
|
|
|
/* Commit (again) the pages, but with PAGE_READWRITE protection */
|
|
|
|
Status = ZwAllocateVirtualMemory(NtCurrentProcess(),
|
|
|
|
&BaseAddress,
|
|
|
|
0,
|
|
|
|
&ViewSize,
|
|
|
|
MEM_COMMIT,
|
|
|
|
PAGE_READWRITE);
|
|
|
|
ASSERT(NT_SUCCESS(Status));
|
|
|
|
}
|
|
|
|
|
2013-11-16 18:40:24 +00:00
|
|
|
#if defined(_M_IX86) || defined(_M_AMD64)
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
IntInitializeVideoAddressSpace(VOID)
|
|
|
|
{
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
UNICODE_STRING PhysMemName = RTL_CONSTANT_STRING(L"\\Device\\PhysicalMemory");
|
|
|
|
NTSTATUS Status;
|
|
|
|
HANDLE PhysMemHandle;
|
|
|
|
PVOID BaseAddress;
|
|
|
|
LARGE_INTEGER Offset;
|
|
|
|
SIZE_T ViewSize;
|
2019-01-05 09:50:11 +00:00
|
|
|
#ifdef _M_IX86
|
2018-02-11 12:43:05 +00:00
|
|
|
CHAR IVTAndBda[1024 + 256];
|
2019-01-05 09:50:11 +00:00
|
|
|
#endif // _M_IX86
|
2013-11-16 18:40:24 +00:00
|
|
|
|
|
|
|
/* Free the 1MB pre-reserved region. In reality, ReactOS should simply support us mapping the view into the reserved area, but it doesn't. */
|
|
|
|
BaseAddress = 0;
|
|
|
|
ViewSize = 1024 * 1024;
|
|
|
|
Status = ZwFreeVirtualMemory(NtCurrentProcess(),
|
|
|
|
&BaseAddress,
|
|
|
|
&ViewSize,
|
|
|
|
MEM_RELEASE);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("Couldn't unmap reserved memory (%x)\n", Status);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Open the physical memory section */
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&PhysMemName,
|
2015-09-19 21:10:11 +00:00
|
|
|
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
|
2013-11-16 18:40:24 +00:00
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
Status = ZwOpenSection(&PhysMemHandle,
|
|
|
|
SECTION_ALL_ACCESS,
|
|
|
|
&ObjectAttributes);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("Couldn't open \\Device\\PhysicalMemory\n");
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Map the BIOS and device registers into the address space */
|
|
|
|
Offset.QuadPart = 0xa0000;
|
|
|
|
ViewSize = 0x100000 - 0xa0000;
|
|
|
|
BaseAddress = (PVOID)0xa0000;
|
|
|
|
Status = ZwMapViewOfSection(PhysMemHandle,
|
|
|
|
NtCurrentProcess(),
|
|
|
|
&BaseAddress,
|
|
|
|
0,
|
|
|
|
ViewSize,
|
|
|
|
&Offset,
|
|
|
|
&ViewSize,
|
|
|
|
ViewUnmap,
|
|
|
|
0,
|
|
|
|
PAGE_EXECUTE_READWRITE);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("Couldn't map physical memory (%x)\n", Status);
|
|
|
|
ZwClose(PhysMemHandle);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Close physical memory section handle */
|
|
|
|
ZwClose(PhysMemHandle);
|
|
|
|
|
|
|
|
if (BaseAddress != (PVOID)0xa0000)
|
|
|
|
{
|
|
|
|
DPRINT1("Couldn't map physical memory at the right address (was %x)\n",
|
|
|
|
BaseAddress);
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate some low memory to use for the non-BIOS
|
|
|
|
* parts of the v86 mode address space
|
|
|
|
*/
|
|
|
|
BaseAddress = (PVOID)0x1;
|
|
|
|
ViewSize = 0xa0000 - 0x1000;
|
|
|
|
Status = ZwAllocateVirtualMemory(NtCurrentProcess(),
|
|
|
|
&BaseAddress,
|
|
|
|
0,
|
|
|
|
&ViewSize,
|
|
|
|
MEM_RESERVE | MEM_COMMIT,
|
|
|
|
PAGE_EXECUTE_READWRITE);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("Failed to allocate virtual memory (Status %x)\n", Status);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
if (BaseAddress != (PVOID)0x0)
|
|
|
|
{
|
|
|
|
DPRINT1("Failed to allocate virtual memory at right address (was %x)\n",
|
|
|
|
BaseAddress);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-01-05 09:50:11 +00:00
|
|
|
#ifdef _M_IX86
|
2013-11-16 18:40:24 +00:00
|
|
|
/* Get the real mode IVT and BDA from the kernel */
|
|
|
|
Status = NtVdmControl(VdmInitialize, IVTAndBda);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("NtVdmControl failed (status %x)\n", Status);
|
|
|
|
return Status;
|
|
|
|
}
|
2019-01-05 09:50:11 +00:00
|
|
|
#endif // _M_IX86
|
2013-11-16 18:40:24 +00:00
|
|
|
|
2021-02-10 14:21:55 +00:00
|
|
|
/* Protect the V86 address space after this */
|
|
|
|
ProtectLowV86Mem();
|
|
|
|
|
2013-11-16 18:40:24 +00:00
|
|
|
/* Return success */
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2015-05-14 22:33:03 +00:00
|
|
|
#else
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
IntInitializeVideoAddressSpace(VOID)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
NT_ASSERT(FALSE);
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
2013-11-16 18:40:24 +00:00
|
|
|
#endif
|
|
|
|
|
2018-02-11 12:43:05 +00:00
|
|
|
VP_STATUS
|
|
|
|
NTAPI
|
2004-01-19 15:56:53 +00:00
|
|
|
IntInt10AllocateBuffer(
|
2018-02-11 12:43:05 +00:00
|
|
|
IN PVOID Context,
|
|
|
|
OUT PUSHORT Seg,
|
|
|
|
OUT PUSHORT Off,
|
|
|
|
IN OUT PULONG Length)
|
2004-01-19 15:56:53 +00:00
|
|
|
{
|
2018-02-11 12:43:05 +00:00
|
|
|
NTSTATUS Status;
|
2018-02-11 18:22:30 +00:00
|
|
|
#ifdef _M_IX86
|
|
|
|
PVOID MemoryAddress;
|
2018-02-11 12:43:05 +00:00
|
|
|
PKPROCESS CallingProcess = (PKPROCESS)PsGetCurrentProcess();
|
|
|
|
KAPC_STATE ApcState;
|
2018-02-11 13:01:43 +00:00
|
|
|
SIZE_T Size;
|
2004-01-19 15:56:53 +00:00
|
|
|
|
2018-02-11 12:43:05 +00:00
|
|
|
TRACE_(VIDEOPRT, "IntInt10AllocateBuffer\n");
|
2004-03-08 21:45:39 +00:00
|
|
|
|
2018-02-11 12:43:05 +00:00
|
|
|
IntAttachToCSRSS(&CallingProcess, &ApcState);
|
2004-03-19 20:58:32 +00:00
|
|
|
|
2018-02-11 13:01:43 +00:00
|
|
|
Size = *Length;
|
2018-02-11 12:43:05 +00:00
|
|
|
MemoryAddress = (PVOID)0x20000;
|
2021-02-10 14:21:55 +00:00
|
|
|
|
2018-02-11 12:43:05 +00:00
|
|
|
Status = ZwAllocateVirtualMemory(NtCurrentProcess(),
|
|
|
|
&MemoryAddress,
|
|
|
|
0,
|
2018-02-11 13:01:43 +00:00
|
|
|
&Size,
|
2018-02-11 12:43:05 +00:00
|
|
|
MEM_COMMIT,
|
|
|
|
PAGE_EXECUTE_READWRITE);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
WARN_(VIDEOPRT, "- ZwAllocateVirtualMemory failed\n");
|
|
|
|
IntDetachFromCSRSS(&CallingProcess, &ApcState);
|
|
|
|
return ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
}
|
2004-03-19 20:58:32 +00:00
|
|
|
|
2018-02-11 13:01:43 +00:00
|
|
|
if (MemoryAddress > (PVOID)(0x100000 - Size))
|
2018-02-11 12:43:05 +00:00
|
|
|
{
|
2018-02-11 13:01:43 +00:00
|
|
|
ZwFreeVirtualMemory(NtCurrentProcess(),
|
|
|
|
&MemoryAddress,
|
|
|
|
&Size,
|
|
|
|
MEM_RELEASE);
|
2018-02-11 12:43:05 +00:00
|
|
|
WARN_(VIDEOPRT, "- Unacceptable memory allocated\n");
|
|
|
|
IntDetachFromCSRSS(&CallingProcess, &ApcState);
|
|
|
|
return ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
}
|
2004-01-19 15:56:53 +00:00
|
|
|
|
2018-02-11 13:01:43 +00:00
|
|
|
*Length = (ULONG)Size;
|
|
|
|
*Seg = (USHORT)((ULONG_PTR)MemoryAddress >> 4);
|
|
|
|
*Off = (USHORT)((ULONG_PTR)MemoryAddress & 0xF);
|
2004-01-19 15:56:53 +00:00
|
|
|
|
2018-02-11 13:01:43 +00:00
|
|
|
INFO_(VIDEOPRT, "- Segment: %x\n", (ULONG_PTR)MemoryAddress >> 4);
|
|
|
|
INFO_(VIDEOPRT, "- Offset: %x\n", (ULONG_PTR)MemoryAddress & 0xF);
|
2018-02-11 12:43:05 +00:00
|
|
|
INFO_(VIDEOPRT, "- Length: %x\n", *Length);
|
2004-02-22 22:19:42 +00:00
|
|
|
|
2018-02-11 12:43:05 +00:00
|
|
|
IntDetachFromCSRSS(&CallingProcess, &ApcState);
|
2004-03-08 21:45:39 +00:00
|
|
|
|
2018-02-11 12:43:05 +00:00
|
|
|
return NO_ERROR;
|
2018-02-11 18:22:30 +00:00
|
|
|
#else
|
|
|
|
Status = x86BiosAllocateBuffer(Length, Seg, Off);
|
|
|
|
return NT_SUCCESS(Status) ? NO_ERROR : ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
#endif
|
2004-01-19 15:56:53 +00:00
|
|
|
}
|
|
|
|
|
2018-02-11 12:43:05 +00:00
|
|
|
VP_STATUS
|
|
|
|
NTAPI
|
2004-01-19 15:56:53 +00:00
|
|
|
IntInt10FreeBuffer(
|
2018-02-11 12:43:05 +00:00
|
|
|
IN PVOID Context,
|
|
|
|
IN USHORT Seg,
|
|
|
|
IN USHORT Off)
|
2004-01-19 15:56:53 +00:00
|
|
|
{
|
2018-02-11 12:43:05 +00:00
|
|
|
NTSTATUS Status;
|
2018-02-11 18:22:30 +00:00
|
|
|
#ifdef _M_IX86
|
|
|
|
PVOID MemoryAddress = (PVOID)((ULONG_PTR)(Seg << 4) | Off);
|
2018-02-11 12:43:05 +00:00
|
|
|
PKPROCESS CallingProcess = (PKPROCESS)PsGetCurrentProcess();
|
|
|
|
KAPC_STATE ApcState;
|
|
|
|
SIZE_T Size = 0;
|
|
|
|
|
|
|
|
TRACE_(VIDEOPRT, "IntInt10FreeBuffer\n");
|
|
|
|
INFO_(VIDEOPRT, "- Segment: %x\n", Seg);
|
|
|
|
INFO_(VIDEOPRT, "- Offset: %x\n", Off);
|
|
|
|
|
|
|
|
IntAttachToCSRSS(&CallingProcess, &ApcState);
|
|
|
|
Status = ZwFreeVirtualMemory(NtCurrentProcess(),
|
|
|
|
&MemoryAddress,
|
|
|
|
&Size,
|
|
|
|
MEM_RELEASE);
|
|
|
|
|
|
|
|
IntDetachFromCSRSS(&CallingProcess, &ApcState);
|
|
|
|
|
|
|
|
return Status;
|
2018-02-11 18:22:30 +00:00
|
|
|
#else
|
|
|
|
Status = x86BiosFreeBuffer(Seg, Off);
|
|
|
|
return NT_SUCCESS(Status) ? NO_ERROR : ERROR_INVALID_PARAMETER;
|
|
|
|
#endif
|
2004-01-19 15:56:53 +00:00
|
|
|
}
|
|
|
|
|
2018-02-11 12:43:05 +00:00
|
|
|
VP_STATUS
|
|
|
|
NTAPI
|
2004-01-19 15:56:53 +00:00
|
|
|
IntInt10ReadMemory(
|
2018-02-11 12:43:05 +00:00
|
|
|
IN PVOID Context,
|
|
|
|
IN USHORT Seg,
|
|
|
|
IN USHORT Off,
|
|
|
|
OUT PVOID Buffer,
|
|
|
|
IN ULONG Length)
|
2004-01-19 15:56:53 +00:00
|
|
|
{
|
2018-02-11 18:22:30 +00:00
|
|
|
#ifdef _M_IX86
|
2018-02-11 12:43:05 +00:00
|
|
|
PKPROCESS CallingProcess = (PKPROCESS)PsGetCurrentProcess();
|
|
|
|
KAPC_STATE ApcState;
|
2004-03-08 21:45:39 +00:00
|
|
|
|
2018-02-11 12:43:05 +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
|
|
|
|
2018-02-11 12:43:05 +00:00
|
|
|
IntAttachToCSRSS(&CallingProcess, &ApcState);
|
2021-02-10 14:21:55 +00:00
|
|
|
|
|
|
|
if (IsLowV86Mem(Seg, Off))
|
|
|
|
UnprotectLowV86Mem();
|
2018-02-11 13:01:43 +00:00
|
|
|
RtlCopyMemory(Buffer, (PVOID)((ULONG_PTR)(Seg << 4) | Off), Length);
|
2021-02-10 14:21:55 +00:00
|
|
|
if (IsLowV86Mem(Seg, Off))
|
|
|
|
ProtectLowV86Mem();
|
|
|
|
|
2018-02-11 12:43:05 +00:00
|
|
|
IntDetachFromCSRSS(&CallingProcess, &ApcState);
|
2004-03-08 21:45:39 +00:00
|
|
|
|
2018-02-11 12:43:05 +00:00
|
|
|
return NO_ERROR;
|
2018-02-11 18:22:30 +00:00
|
|
|
#else
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
Status = x86BiosReadMemory(Seg, Off, Buffer, Length);
|
|
|
|
return NT_SUCCESS(Status) ? NO_ERROR : ERROR_INVALID_PARAMETER;
|
|
|
|
#endif
|
2004-01-19 15:56:53 +00:00
|
|
|
}
|
|
|
|
|
2018-02-11 12:43:05 +00:00
|
|
|
VP_STATUS
|
|
|
|
NTAPI
|
2004-01-19 15:56:53 +00:00
|
|
|
IntInt10WriteMemory(
|
2018-02-11 12:43:05 +00:00
|
|
|
IN PVOID Context,
|
|
|
|
IN USHORT Seg,
|
|
|
|
IN USHORT Off,
|
|
|
|
IN PVOID Buffer,
|
|
|
|
IN ULONG Length)
|
2004-01-19 15:56:53 +00:00
|
|
|
{
|
2018-02-11 18:22:30 +00:00
|
|
|
#ifdef _M_IX86
|
2018-02-11 12:43:05 +00:00
|
|
|
PKPROCESS CallingProcess = (PKPROCESS)PsGetCurrentProcess();
|
|
|
|
KAPC_STATE ApcState;
|
2004-03-08 21:45:39 +00:00
|
|
|
|
2018-02-11 12:43:05 +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
|
|
|
|
2018-02-11 12:43:05 +00:00
|
|
|
IntAttachToCSRSS(&CallingProcess, &ApcState);
|
2021-02-10 14:21:55 +00:00
|
|
|
if (IsLowV86Mem(Seg, Off))
|
|
|
|
UnprotectLowV86Mem();
|
2018-02-11 13:01:43 +00:00
|
|
|
RtlCopyMemory((PVOID)((ULONG_PTR)(Seg << 4) | Off), Buffer, Length);
|
2021-02-10 14:21:55 +00:00
|
|
|
if (IsLowV86Mem(Seg, Off))
|
|
|
|
ProtectLowV86Mem();
|
2018-02-11 12:43:05 +00:00
|
|
|
IntDetachFromCSRSS(&CallingProcess, &ApcState);
|
2004-03-08 21:45:39 +00:00
|
|
|
|
2018-02-11 12:43:05 +00:00
|
|
|
return NO_ERROR;
|
2018-02-11 18:22:30 +00:00
|
|
|
#else
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
Status = x86BiosWriteMemory(Seg, Off, Buffer, Length);
|
|
|
|
return NT_SUCCESS(Status) ? NO_ERROR : ERROR_INVALID_PARAMETER;
|
|
|
|
#endif
|
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
|
|
|
{
|
2018-02-11 18:22:30 +00:00
|
|
|
#ifdef _M_AMD64
|
|
|
|
X86_BIOS_REGISTERS BiosContext;
|
|
|
|
#else
|
2006-08-28 23:56:35 +00:00
|
|
|
CONTEXT BiosContext;
|
2018-02-11 18:22:30 +00:00
|
|
|
#endif
|
2006-08-28 23:56:35 +00:00
|
|
|
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 */
|
2018-02-11 12:43:05 +00:00
|
|
|
RtlZeroMemory(&BiosContext, sizeof(BiosContext));
|
2006-08-28 23:56:35 +00:00
|
|
|
|
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 */
|
2018-02-11 12:43:05 +00:00
|
|
|
(void)KeWaitForMutexObject(&VideoPortInt10Mutex,
|
|
|
|
Executive,
|
|
|
|
KernelMode,
|
|
|
|
FALSE,
|
|
|
|
NULL);
|
|
|
|
|
2021-02-10 14:21:55 +00:00
|
|
|
/* The kernel needs access here */
|
|
|
|
UnprotectLowV86Mem();
|
2018-02-11 18:22:30 +00:00
|
|
|
#ifdef _M_AMD64
|
|
|
|
Status = x86BiosCall(0x10, &BiosContext) ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL;
|
|
|
|
#else
|
2006-08-28 23:56:35 +00:00
|
|
|
Status = Ke386CallBios(0x10, &BiosContext);
|
2018-02-11 18:22:30 +00:00
|
|
|
#endif
|
2021-02-10 14:21:55 +00:00
|
|
|
ProtectLowV86Mem();
|
2018-02-11 12:43:05 +00:00
|
|
|
|
2017-05-18 21:29:24 +00:00
|
|
|
KeReleaseMutex(&VideoPortInt10Mutex, FALSE);
|
2006-08-28 23:56:35 +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;
|
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);
|
2018-02-11 12:43:05 +00:00
|
|
|
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2010-03-03 05:22:45 +00:00
|
|
|
return ERROR_INVALID_PARAMETER;
|
2004-01-19 15:56:53 +00:00
|
|
|
}
|
2004-03-19 20:58:32 +00:00
|
|
|
|
|
|
|
/* PUBLIC FUNCTIONS ***********************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2018-02-11 12:43:05 +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
|
|
|
{
|
2018-02-11 12:49:14 +00:00
|
|
|
INT10_BIOS_ARGUMENTS Int10BiosArguments;
|
|
|
|
VP_STATUS Status;
|
2004-03-19 20:58:32 +00:00
|
|
|
|
[WIN32K][VIDEOPRT] Improve initialization and interfacing with INBV.
CORE-12149
VIDEOPRT:
=========
Improve interfacing with INBV, so as to detect when an external module
acquired INBV display ownership, and whether ownership is being released
later on. (This does NOT rely on hooking!)
For this purpose we improve the IntVideoPortResetDisplayParameters(Ex)
callback that gets registered with an InbvNotifyDisplayOwnershipLost()
call during initialization, and we add a monitoring thread.
The callback is called whenever an external module calls
InbvAcquireDisplayOwnership(), for example the bugcheck code or the KDBG
debugger in SCREEN mode. When this happens, a flag that tells the
monitoring thread to start monitoring INBV is set (ReactOS-specific),
and the display adapters get reset with HwResetHw() (as done on Windows).
Due to the fact that this INBV callback can be called at *ANY* IRQL, we
cannot use dispatcher synchronization mechanisms such as events to tell
the INBV monitoring thread to start its operations, so we need to rely
instead on a flag to be set. And, since INBV doesn't provide with any
proper callback/notification system either, we need to actively monitor
its state by pooling. To reduce the load on the system the monitoring
thread performs 1-second waits between each check for the flag set by
the INBV callback, and during checking the INBV ownership status.
When the INBV ownership is detected to be released by an external module,
the INBV callback is re-registered (this is *MANDATORY* since the
external module has called InbvNotifyDisplayOwnershipLost() with a
different callback parameter!), and then we callout to Win32k for
re-enabling the display.
This has the virtue of correctly resetting the display once the KDBG
debugger in SCREEN mode is being exited, and fixes CORE-12149 .
The following additional fixes were needed:
VIDEOPRT & WIN32K:
==================
Remove the registration with INBV that was previously done in a ReactOS-
specific hacked IRP_MJ_WRITE call; it is now done correctly during the
video device opening done by EngpRegisterGraphicsDevice() in the VIDEOPRT's
IRP_MJ_CREATE handler, as done on Windows.
WIN32K:
=======
- Stub the VideoPortCallout() support, for VIDEOPRT -> WIN32 callbacks.
This function gets registered with VIDEOPRT through an
IOCTL_VIDEO_INIT_WIN32K_CALLBACKS call in EngpRegisterGraphicsDevice().
- Only partially implement the 'VideoFindAdapterCallout' case, that just
re-enables the primary display by refreshing it (using the new function
UserRefreshDisplay()).
VIDEOPRT:
=========
- PVIDEO_WIN32K_CALLOUT is an NTAPI (stdcall) callback.
- In the IntVideoPortResetDisplayParameters(Ex) callback, reset all the
"resettable" adapters registered in the HwResetAdaptersList list.
We thus get rid of the global ResetDisplayParametersDeviceExtension.
- Make the IntVideoPortResetDisplayParameters(Ex) callback slightly more
robust (using SEH) against potential HwResetListEntry list corruption
or invalid DriverExtension->InitializationData.HwResetHw() that would
otherwise trigger a BSOD, and this would be disastrous since that
callback is precisely called when INBV is acquired, typically when the
BSOD code initializes the display for displaying its information...
Extras:
- Validate the IrpStack->MajorFunction in IntVideoPortDispatchDeviceControl()
and implement IRP_MJ_SHUTDOWN handling. Stub out the other IOCTLs that
are handled by VIDEOPRT only (and not by the miniports).
- VIDEOPRT doesn't require IRP_MJ_INTERNAL_DEVICE_CONTROL (unused).
- Implement IOCTL_VIDEO_PREPARE_FOR_EARECOVERY that just resets the
display to standard VGA 80x25 text mode.
2019-11-26 01:49:35 +00:00
|
|
|
if (!CsrProcess)
|
2008-12-27 04:01:26 +00:00
|
|
|
{
|
2018-02-11 12:43:05 +00:00
|
|
|
return ERROR_INVALID_PARAMETER;
|
2008-12-27 04:01:26 +00:00
|
|
|
}
|
2004-03-19 20:58:32 +00:00
|
|
|
|
2018-02-11 12:49:14 +00:00
|
|
|
/* Copy arguments to other format */
|
2019-08-17 19:15:04 +00:00
|
|
|
RtlCopyMemory(&Int10BiosArguments, BiosArguments, sizeof(*BiosArguments));
|
2018-02-11 12:49:14 +00:00
|
|
|
Int10BiosArguments.SegDs = 0;
|
|
|
|
Int10BiosArguments.SegEs = 0;
|
2004-03-19 20:58:32 +00:00
|
|
|
|
2018-02-11 12:49:14 +00:00
|
|
|
/* Do the BIOS call */
|
|
|
|
Status = IntInt10CallBios(NULL, &Int10BiosArguments);
|
2018-02-11 12:43:05 +00:00
|
|
|
|
2018-02-11 12:49:14 +00:00
|
|
|
/* Copy results back */
|
2019-08-17 19:15:04 +00:00
|
|
|
RtlCopyMemory(BiosArguments, &Int10BiosArguments, sizeof(*BiosArguments));
|
2018-02-11 12:43:05 +00:00
|
|
|
|
2018-02-11 12:49:14 +00:00
|
|
|
return Status;
|
2004-03-19 20:58:32 +00:00
|
|
|
}
|