mirror of
https://github.com/reactos/reactos.git
synced 2024-12-27 01:24:38 +00:00
Porting pice. Added keyboard hook and some file functions.
svn path=/trunk/; revision=2420
This commit is contained in:
parent
8c3f4003e7
commit
ef93b48310
12 changed files with 902 additions and 741 deletions
|
@ -444,7 +444,7 @@ BOOLEAN ConsoleInitHercules(void)
|
|||
|
||||
attr.u.Asuchar = 0x07;
|
||||
|
||||
pScreenBufferHercules=ioremap(0xb0000,FRAMEBUFFER_SIZE);
|
||||
pScreenBufferHercules=MmMapIoSpace(0xb0000,FRAMEBUFFER_SIZE,MmWriteCombined);
|
||||
|
||||
DPRINT((0,"VGA memory phys. 0xb0000 mapped to virt. 0x%x\n",pScreenBufferHercules));
|
||||
|
||||
|
@ -483,7 +483,7 @@ void ConsoleShutdownHercules(void)
|
|||
outb_p(0,0x3bf);
|
||||
|
||||
if(pScreenBufferHercules)
|
||||
iounmap(pScreenBufferHercules);
|
||||
MmUnmapIoSpace(pScreenBufferHercules,FRAMEBUFFER_SIZE);
|
||||
|
||||
LEAVE_FUNC();
|
||||
}
|
||||
|
|
|
@ -36,7 +36,6 @@ Copyright notice:
|
|||
#include "precomp.h"
|
||||
|
||||
#include <linux/fs.h>
|
||||
#include <linux/vmalloc.h>
|
||||
#include <asm/uaccess.h>
|
||||
#include <asm/io.h>
|
||||
#include <asm/delay.h>
|
||||
|
@ -187,13 +186,12 @@ BOOLEAN InitPICE(void)
|
|||
}
|
||||
|
||||
DPRINT((0,"InitPICE(): trace step 12\n"));
|
||||
// need these two to hook the keyboard
|
||||
ScanExports("handle_scancode",&ulHandleScancode);
|
||||
ScanExports("handle_kbd_event",&ulHandleKbdEvent);
|
||||
|
||||
|
||||
DPRINT((0,"InitPICE(): trace step 13\n"));
|
||||
// patch the keyboard driver
|
||||
if(!(ulHandleScancode && ulHandleKbdEvent && PatchKeyboardDriver(ulHandleKbdEvent,ulHandleScancode)) )
|
||||
|
||||
if(PatchKeyboardDriver())
|
||||
{
|
||||
Print(OUTPUT_WINDOW,"pICE: ABORT (couldn't patch keyboard driver)\n");
|
||||
Print(OUTPUT_WINDOW,"pICE: press any key to continue...\n");
|
||||
|
|
|
@ -164,4 +164,4 @@ COMMAND_PROTOTYPE(ShowPCI);
|
|||
COMMAND_PROTOTYPE(SetKeyboardLayout);
|
||||
COMMAND_PROTOTYPE(ShowSysCallTable);
|
||||
COMMAND_PROTOTYPE(SetAltKey);
|
||||
COMMAND_PROTOTYPE(ShowContext);
|
||||
COMMAND_PROTOTYPE(ShowContext);
|
||||
|
|
|
@ -17,11 +17,13 @@ Environment:
|
|||
Author:
|
||||
|
||||
Klaus P. Gerlicher
|
||||
Reactos Port: Eugene Ingerman
|
||||
|
||||
Revision History:
|
||||
|
||||
10-Jul-1999: created
|
||||
15-Nov-2000: general cleanup of source files
|
||||
12/1/2001 reactos port
|
||||
|
||||
Copyright notice:
|
||||
|
||||
|
@ -37,6 +39,9 @@ Copyright notice:
|
|||
|
||||
#include <asm/system.h>
|
||||
|
||||
#include <ddk/ntddkbd.h>
|
||||
#include <ddk/ntdd8042.h>
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
// GLOBALS
|
||||
////
|
||||
|
@ -44,7 +49,7 @@ Copyright notice:
|
|||
static PUCHAR pPatchAddress;
|
||||
static ULONG ulOldOffset = 0;
|
||||
static ULONG ulKeyPatchFlags;
|
||||
BOOLEAN bPatched = FALSE;
|
||||
|
||||
void (*old_handle_scancode)(UCHAR,int);
|
||||
char tempPatch[256];
|
||||
UCHAR ucBreakKey = 'D'; // key that will break into debugger in combination with CTRL
|
||||
|
@ -53,29 +58,44 @@ UCHAR ucBreakKey = 'D'; // key that will break into debugger in combination with
|
|||
// FUNCTIONS
|
||||
////
|
||||
|
||||
// the keyboard hook
|
||||
void pice_handle_scancode(UCHAR scancode,int bKeyPressed)
|
||||
//***********************************************************************************
|
||||
// PiceKbdIsr - keyboard isr hook routine.
|
||||
// IsrContext - context that we passed to keyboard driver in internal iocontrol
|
||||
// pCurrentInput, pCurrentOutput - not implemented yet
|
||||
// StatusByte - keyboard status register
|
||||
// pByte - pointer to the byte read from keyboard data port. can be changed.
|
||||
// pContinueProcessing - should keyboard driver continue processing this byte.
|
||||
//***********************************************************************************
|
||||
BOOLEAN PiceKbdIsr (
|
||||
PVOID IsrContext,
|
||||
PKEYBOARD_INPUT_DATA pCurrentInput,
|
||||
POUTPUT_PACKET pCurrentOutput,
|
||||
UCHAR StatusByte,
|
||||
PUCHAR pByte,
|
||||
PBOOLEAN pContinueProcessing,
|
||||
PKEYBOARD_SCAN_STATE pScanState
|
||||
)
|
||||
{
|
||||
UCHAR ucKey = scancode & 0x7f;
|
||||
static BOOLEAN bControl = FALSE;
|
||||
BOOLEAN bForward=TRUE;
|
||||
BOOLEAN bForward=TRUE; // should we let keyboard driver process this keystroke
|
||||
BOOLEAN isDown=!(*pByte & 0x80);
|
||||
UCHAR ucKey = *pByte & 0x7f;
|
||||
|
||||
ENTER_FUNC();
|
||||
|
||||
DPRINT((0,"pice_handle_scancode(%x,%u)\n",scancode,bKeyPressed));
|
||||
DPRINT((0,"pice_handle_scancode(1): bControl = %u bForward = %u bEnterNow = %u\n",bControl,bForward,bEnterNow));
|
||||
if(bKeyPressed)
|
||||
// BUG!! should protect with spinlock since bControl is static.
|
||||
DPRINT((0,"PiceKbdIsr(%x,%u)\n",pByte,isDown));
|
||||
DPRINT((0,"PiceKbdIsr(1): bControl = %u bForward = %u bEnterNow = %u\n",bControl,bForward,bEnterNow));
|
||||
|
||||
if(isDown)
|
||||
{
|
||||
// CTRL pressed
|
||||
if(ucKey==0x1d)
|
||||
{
|
||||
bControl=TRUE;
|
||||
}
|
||||
else if(bControl==TRUE && ucKey==AsciiToScan(ucBreakKey)) // CTRL-F
|
||||
else if(bControl==TRUE && ucKey==AsciiToScan(ucBreakKey)) // CTRL-D
|
||||
{
|
||||
// fake a CTRL-F release call
|
||||
old_handle_scancode(0x1d|0x80,FALSE);
|
||||
old_handle_scancode(AsciiToScan(ucBreakKey)|0x80,FALSE);
|
||||
// fake a CTRL-D release call
|
||||
bForward=FALSE;
|
||||
bEnterNow=TRUE;
|
||||
bControl=FALSE;
|
||||
|
@ -98,80 +118,102 @@ void pice_handle_scancode(UCHAR scancode,int bKeyPressed)
|
|||
bForward=FALSE;
|
||||
}
|
||||
}
|
||||
*ContinueProcessing = bForward;
|
||||
LEAVE_FUNC();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if(bForward)
|
||||
{
|
||||
DPRINT((0,"pice_handle_scancode(): forwarding key stroke\n"));
|
||||
old_handle_scancode(scancode,bKeyPressed);
|
||||
//***********************************************************************************
|
||||
// PiceSendIoctl - send internal_io_control to the driver
|
||||
// Target - Device Object that receives control request
|
||||
// Ioctl - request
|
||||
// InputBuffer - Type3Buffer will be pointing here
|
||||
// InputBufferLength - length of inputbuffer
|
||||
//***********************************************************************************
|
||||
NTSTATUS PiceSendIoctl(PDEVICE_OBJECT Target, ULONG Ioctl,
|
||||
PVOID InputBuffer, ULONG InputBufferLength)
|
||||
{
|
||||
KEVENT event;
|
||||
NTSTATUS status = STATUS_SUCCESS;
|
||||
IO_STATUS_BLOCK iosb;
|
||||
PIRP irp;
|
||||
|
||||
KeInitializeEvent(&event,
|
||||
NotificationEvent,
|
||||
FALSE
|
||||
);
|
||||
|
||||
if (NULL == (irp = IoBuildDeviceIoControlRequest(Ioctl,
|
||||
Target,
|
||||
InputBuffer,
|
||||
InputBufferLength,
|
||||
0,
|
||||
0,
|
||||
TRUE,
|
||||
&event,
|
||||
&iosb))) {
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
LEAVE_FUNC();
|
||||
status = IoCallDriver(Target, irp);
|
||||
|
||||
if (STATUS_PENDING == status) {
|
||||
|
||||
status = KeWaitForSingleObject(&event,
|
||||
Executive,
|
||||
KernelMode,
|
||||
FALSE,
|
||||
NULL);
|
||||
|
||||
assert(STATUS_SUCCESS == status);
|
||||
status = iosb.Status;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
BOOLEAN PatchKeyboardDriver(ULONG AddrOfKbdEvent,ULONG AddrOfScancode)
|
||||
//**************************************************
|
||||
// PatchKeyboardDriver - set keyboard driver hook.
|
||||
// We use interface supported by standard keyboard drivers.
|
||||
//**************************************************
|
||||
BOOLEAN PatchKeyboardDriver(void)
|
||||
{
|
||||
UCHAR ucPattern[5] = {0xE8,0x0,0x0,0x0,0x0};
|
||||
PULONG pOffset = (PULONG)&ucPattern[1];
|
||||
ULONG ulOffset,countBytes = 0;
|
||||
PINTERNAL_I8042_HOOK_KEYBOARD phkData;
|
||||
UNICODE_STRING DevName;
|
||||
PDEVICE_OBJECT kbdDevice = NULL;
|
||||
PFILE_OBJECT FO = NULL;
|
||||
NTSTATUS status;
|
||||
|
||||
ENTER_FUNC();
|
||||
ENTER_FUNC();
|
||||
//When we have i8042 driver this should be changed!!!!!!!
|
||||
RtlInitUnicodeString(&DevName, L"\\Device\\Keyboard");
|
||||
|
||||
(void*)old_handle_scancode = AddrOfScancode;
|
||||
DPRINT((0,"handle_scancode = %X\n",AddrOfScancode));
|
||||
|
||||
pPatchAddress = (PUCHAR)AddrOfKbdEvent; // handle_kbd_event
|
||||
DPRINT((0,"initial patch address = %X\n",AddrOfKbdEvent));
|
||||
ulOffset = (ULONG)old_handle_scancode - ((ULONG)pPatchAddress+sizeof(ULONG)+1);
|
||||
DPRINT((0,"initial offset = %X\n",ulOffset));
|
||||
*pOffset = ulOffset;
|
||||
|
||||
while((RtlCompareMemory(pPatchAddress,ucPattern,sizeof(ucPattern))!=0) &&
|
||||
(countBytes<0x1000))
|
||||
{
|
||||
/* DPRINT((0,"offset = %X\n",ulOffset));
|
||||
DPRINT((0,"patch address = %X\n",pPatchAddress));
|
||||
DPRINT((0,"pattern1 = %.2X %.2X %.2X %.2X %.2X\n",ucPattern[0],ucPattern[1],ucPattern[2],ucPattern[3],ucPattern[4]));
|
||||
DPRINT((0,"pattern2 = %.2X %.2X %.2X %.2X %.2X\n",pPatchAddress[0],pPatchAddress[1],pPatchAddress[2],pPatchAddress[3],pPatchAddress[4]));*/
|
||||
|
||||
countBytes++;
|
||||
pPatchAddress++;
|
||||
|
||||
ulOffset = (ULONG)old_handle_scancode - ((ULONG)pPatchAddress+sizeof(ULONG)+1);
|
||||
*pOffset = ulOffset;
|
||||
}
|
||||
//Get pointer to keyboard device
|
||||
if( !NT_SUCCESS( IoGetDeviceObjectPointer( &DevName, FILE_READ_ACCESS, &FO, &kbdDevice ) ) )
|
||||
return FALSE;
|
||||
|
||||
phkData = ExAllocatePool( PagedPool, sizeof( INTERNAL_I8042_HOOK_KEYBOARD ) );
|
||||
RtlZeroMemory( phkData, sizeof( INTERNAL_I8042_HOOK_KEYBOARD ) );
|
||||
|
||||
if(RtlCompareMemory(pPatchAddress,ucPattern,sizeof(ucPattern))==0)
|
||||
{
|
||||
DPRINT((0,"pattern found @ %x\n",pPatchAddress));
|
||||
phkData->IsrRoutine = (PI8042_KEYBOARD_ISR) PiceKbdIsr;
|
||||
phkData->Context = (PVOID) NULL; //DeviceObject;
|
||||
|
||||
//call keyboard device internal io control to hook keyboard input stream
|
||||
status = PiceSendIoctl( kbdDevice, IOCTL_INTERNAL_I8042_HOOK_KEYBOARD,
|
||||
phkData, sizeof( INTERNAL_I8042_HOOK_KEYBOARD ) );
|
||||
|
||||
|
||||
ulOffset = (ULONG)&pice_handle_scancode - ((ULONG)pPatchAddress+sizeof(ULONG)+1);
|
||||
ulOldOffset = *(PULONG)(pPatchAddress + 1);
|
||||
DPRINT((0,"old offset = %x new offset = %x\n",ulOldOffset,ulOffset));
|
||||
ObDereferenceObject(FO);
|
||||
ExFreePool(phkData);
|
||||
|
||||
LEAVE_FUNC();
|
||||
|
||||
save_flags(ulKeyPatchFlags);
|
||||
cli();
|
||||
*(PULONG)(pPatchAddress + 1) = ulOffset;
|
||||
|
||||
bPatched = TRUE;
|
||||
|
||||
restore_flags(ulKeyPatchFlags);
|
||||
DPRINT((0,"PatchKeyboardDriver(): SUCCESS!\n"));
|
||||
}
|
||||
|
||||
LEAVE_FUNC();
|
||||
|
||||
return bPatched;
|
||||
return NT_SUCCESS(status);
|
||||
}
|
||||
|
||||
void RestoreKeyboardDriver(void)
|
||||
{
|
||||
ENTER_FUNC();
|
||||
if(bPatched)
|
||||
{
|
||||
save_flags(ulKeyPatchFlags);
|
||||
cli();
|
||||
*(PULONG)(pPatchAddress + 1) = ulOldOffset;
|
||||
restore_flags(ulKeyPatchFlags);
|
||||
}
|
||||
LEAVE_FUNC();
|
||||
DbgPrint("RestoreKeyboardDriver: Not Implemented yet!!!\n");
|
||||
LEAVE_FUNC();
|
||||
}
|
||||
|
|
|
@ -39,7 +39,6 @@ Copyright notice:
|
|||
#include <asm/page.h>
|
||||
#include <asm/pgtable.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/vmalloc.h>
|
||||
#include <asm/uaccess.h>
|
||||
#include <asm/delay.h>
|
||||
#include <linux/interrupt.h>
|
||||
|
@ -386,4 +385,4 @@ void DeInstallIntEHook(void)
|
|||
UnmaskIrqs();
|
||||
|
||||
LEAVE_FUNC();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,11 +92,12 @@ NTSTATUS STDCALL pice_close(PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
|||
{
|
||||
DPRINT((0,"pice_close\n"));
|
||||
|
||||
CleanUpPICE(); // used to be in cleanup_module
|
||||
CleanUpPICE(); // used to be in cleanup_module
|
||||
|
||||
/* We're now ready for our next caller */
|
||||
bDeviceAlreadyOpen = FALSE;
|
||||
IoCompleteRequest (Irp, IO_NO_INCREMENT);
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -179,7 +180,7 @@ NTSTATUS STDCALL DriverEntry(PDRIVER_OBJECT DriverObject,
|
|||
|
||||
if(InitPICE()){
|
||||
DriverObject->MajorFunction[IRP_MJ_CREATE] = pice_open;
|
||||
DriverObject->MajorFunction[IRP_MJ_CLOSE] = pice_close;
|
||||
//ei unimplemented DriverObject->MajorFunction[IRP_MJ_CLOSE] = pice_close;
|
||||
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = pice_ioctl;
|
||||
|
||||
RtlInitUnicodeString(&DeviceName, L"\\Device\\Pice");
|
||||
|
|
|
@ -609,7 +609,7 @@ BOOLEAN ConsoleInitSerial(void)
|
|||
GLOBAL_SCREEN_WIDTH = 80;
|
||||
GLOBAL_SCREEN_HEIGHT = 60;
|
||||
|
||||
pScreenBufferSerial = vmalloc(FRAMEBUFFER_SIZE);
|
||||
pScreenBufferSerial = PICE_malloc(FRAMEBUFFER_SIZE, NONPAGEDPOOL);
|
||||
|
||||
if(pScreenBufferSerial)
|
||||
{
|
||||
|
@ -648,7 +648,7 @@ void ConsoleShutdownSerial(void)
|
|||
FlushSerialBuffer();
|
||||
|
||||
if(pScreenBufferSerial)
|
||||
vfree(pScreenBufferSerial);
|
||||
PICE_free(pScreenBufferSerial);
|
||||
|
||||
LEAVE_FUNC();
|
||||
}
|
||||
|
|
|
@ -28,8 +28,8 @@ Copyright notice:
|
|||
This file may be distributed under the terms of the GNU Public License.
|
||||
|
||||
--*/
|
||||
void InstallKeyboardHook(void);
|
||||
void DeInstallKeyboardHook(void);
|
||||
//void InstallKeyboardHook(void);
|
||||
//void DeInstallKeyboardHook(void);
|
||||
void InstallGlobalKeyboardHook(void);
|
||||
void DeInstallGlobalKeyboardHook(void);
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -242,6 +242,10 @@ UCHAR inportb(USHORT port);
|
|||
void outb_p(UCHAR data, USHORT port);
|
||||
UCHAR inb_p(USHORT port);
|
||||
|
||||
VOID outl(ULONG l, PULONG port);
|
||||
ULONG inl(PULONG port);
|
||||
|
||||
|
||||
#define save_flags(x) __asm__ __volatile__("pushfl ; popl %0":"=g" (x): /* no input */)
|
||||
#define restore_flags(x) __asm__ __volatile__("pushl %0 ; popfl": /* no output */ :"g" (x):"memory", "cc")
|
||||
#define cli() __asm__ __volatile__("cli": : :"memory")
|
||||
|
@ -253,3 +257,14 @@ extern unsigned long sys_call_table[];
|
|||
struct mm_struct *GetInitMm(void);
|
||||
|
||||
void EnablePassThrough(void);
|
||||
|
||||
#define PAGEDPOOL (1)
|
||||
#define NONPAGEDPOOL (0)
|
||||
|
||||
void * PICE_malloc( size_t numBytes, BOOLEAN fromPaged );
|
||||
void PICE_free( void* p );
|
||||
|
||||
HANDLE PICE_open (LPCWSTR lpPathName, int iReadWrite);
|
||||
long PICE_read(HANDLE hFile, LPVOID lpBuffer, long lBytes);
|
||||
int PICE_close (HANDLE hFile);
|
||||
size_t PICE_len( HANDLE hFile );
|
||||
|
|
|
@ -393,11 +393,11 @@ BOOLEAN ConsoleInitVga(void)
|
|||
|
||||
#ifdef LOCAL_CONSOLE
|
||||
// the real framebuffer
|
||||
pScreenBufferHardwareVga = ioremap(0xB8000,FRAMEBUFFER_SIZE);
|
||||
pScreenBufferHardwareVga = MmMapIoSpace(0xB8000,FRAMEBUFFER_SIZE,MmWriteCombined);
|
||||
// the console
|
||||
pScreenBufferVga = vmalloc(FRAMEBUFFER_SIZE);
|
||||
pScreenBufferVga = PICE_malloc(FRAMEBUFFER_SIZE,NONPAGEDPOOL);
|
||||
// the save area
|
||||
pScreenBufferTempVga = vmalloc(FRAMEBUFFER_SIZE);
|
||||
pScreenBufferTempVga = PICE_malloc(FRAMEBUFFER_SIZE,NONPAGEDPOOL);
|
||||
#else
|
||||
outb_p(0,0x3b8);
|
||||
outb_p(0,0x3bf);
|
||||
|
@ -410,7 +410,7 @@ BOOLEAN ConsoleInitVga(void)
|
|||
}
|
||||
outb_p(0x08,0x3b8);
|
||||
|
||||
pScreenBufferVga=ioremap(0xB0000,FRAMEBUFFER_SIZE);
|
||||
pScreenBufferVga=MmMapIoSpace(0xB0000,FRAMEBUFFER_SIZE,MmWriteCombined);
|
||||
#endif
|
||||
if(pScreenBufferVga)
|
||||
{
|
||||
|
@ -446,9 +446,9 @@ void ConsoleShutdownVga(void)
|
|||
#ifdef LOCAL_CONSOLE
|
||||
if(pScreenBufferVga)
|
||||
{
|
||||
vfree(pScreenBufferVga);
|
||||
vfree(pScreenBufferTempVga);
|
||||
iounmap(pScreenBufferHardwareVga);
|
||||
PICE_free(pScreenBufferVga);
|
||||
PICE_free(pScreenBufferTempVga);
|
||||
MmUnmapIoSpace(pScreenBufferHardwareVga,FRAMEBUFFER_SIZE);
|
||||
}
|
||||
#else
|
||||
// HERC video off
|
||||
|
@ -456,7 +456,7 @@ void ConsoleShutdownVga(void)
|
|||
outb_p(0,0x3bf);
|
||||
|
||||
if(pScreenBufferVga)
|
||||
iounmap(pScreenBufferVga);
|
||||
MmUnmapIoSpace(pScreenBufferVga,FRAMEBUFFER_SIZE);
|
||||
#endif
|
||||
|
||||
LEAVE_FUNC();
|
||||
|
|
Loading…
Reference in a new issue