Porting pice. Added keyboard hook and some file functions.

svn path=/trunk/; revision=2420
This commit is contained in:
Eugene Ingerman 2001-12-06 09:20:57 +00:00
parent 8c3f4003e7
commit ef93b48310
12 changed files with 902 additions and 741 deletions

View file

@ -444,7 +444,7 @@ BOOLEAN ConsoleInitHercules(void)
attr.u.Asuchar = 0x07; 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)); DPRINT((0,"VGA memory phys. 0xb0000 mapped to virt. 0x%x\n",pScreenBufferHercules));
@ -483,7 +483,7 @@ void ConsoleShutdownHercules(void)
outb_p(0,0x3bf); outb_p(0,0x3bf);
if(pScreenBufferHercules) if(pScreenBufferHercules)
iounmap(pScreenBufferHercules); MmUnmapIoSpace(pScreenBufferHercules,FRAMEBUFFER_SIZE);
LEAVE_FUNC(); LEAVE_FUNC();
} }

View file

@ -36,7 +36,6 @@ Copyright notice:
#include "precomp.h" #include "precomp.h"
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/vmalloc.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <asm/io.h> #include <asm/io.h>
#include <asm/delay.h> #include <asm/delay.h>
@ -187,13 +186,12 @@ BOOLEAN InitPICE(void)
} }
DPRINT((0,"InitPICE(): trace step 12\n")); 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")); DPRINT((0,"InitPICE(): trace step 13\n"));
// patch the keyboard driver // 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: ABORT (couldn't patch keyboard driver)\n");
Print(OUTPUT_WINDOW,"pICE: press any key to continue...\n"); Print(OUTPUT_WINDOW,"pICE: press any key to continue...\n");

View file

@ -17,11 +17,13 @@ Environment:
Author: Author:
Klaus P. Gerlicher Klaus P. Gerlicher
Reactos Port: Eugene Ingerman
Revision History: Revision History:
10-Jul-1999: created 10-Jul-1999: created
15-Nov-2000: general cleanup of source files 15-Nov-2000: general cleanup of source files
12/1/2001 reactos port
Copyright notice: Copyright notice:
@ -37,6 +39,9 @@ Copyright notice:
#include <asm/system.h> #include <asm/system.h>
#include <ddk/ntddkbd.h>
#include <ddk/ntdd8042.h>
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
// GLOBALS // GLOBALS
//// ////
@ -44,7 +49,7 @@ Copyright notice:
static PUCHAR pPatchAddress; static PUCHAR pPatchAddress;
static ULONG ulOldOffset = 0; static ULONG ulOldOffset = 0;
static ULONG ulKeyPatchFlags; static ULONG ulKeyPatchFlags;
BOOLEAN bPatched = FALSE;
void (*old_handle_scancode)(UCHAR,int); void (*old_handle_scancode)(UCHAR,int);
char tempPatch[256]; char tempPatch[256];
UCHAR ucBreakKey = 'D'; // key that will break into debugger in combination with CTRL 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 // 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; 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(); ENTER_FUNC();
// 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));
DPRINT((0,"pice_handle_scancode(%x,%u)\n",scancode,bKeyPressed)); if(isDown)
DPRINT((0,"pice_handle_scancode(1): bControl = %u bForward = %u bEnterNow = %u\n",bControl,bForward,bEnterNow));
if(bKeyPressed)
{ {
// CTRL pressed // CTRL pressed
if(ucKey==0x1d) if(ucKey==0x1d)
{ {
bControl=TRUE; 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 // fake a CTRL-D release call
old_handle_scancode(0x1d|0x80,FALSE);
old_handle_scancode(AsciiToScan(ucBreakKey)|0x80,FALSE);
bForward=FALSE; bForward=FALSE;
bEnterNow=TRUE; bEnterNow=TRUE;
bControl=FALSE; bControl=FALSE;
@ -98,80 +118,102 @@ void pice_handle_scancode(UCHAR scancode,int bKeyPressed)
bForward=FALSE; bForward=FALSE;
} }
} }
*ContinueProcessing = bForward;
if(bForward)
{
DPRINT((0,"pice_handle_scancode(): forwarding key stroke\n"));
old_handle_scancode(scancode,bKeyPressed);
}
LEAVE_FUNC(); LEAVE_FUNC();
return TRUE;
} }
BOOLEAN PatchKeyboardDriver(ULONG AddrOfKbdEvent,ULONG AddrOfScancode) //***********************************************************************************
// 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)
{ {
UCHAR ucPattern[5] = {0xE8,0x0,0x0,0x0,0x0}; KEVENT event;
PULONG pOffset = (PULONG)&ucPattern[1]; NTSTATUS status = STATUS_SUCCESS;
ULONG ulOffset,countBytes = 0; IO_STATUS_BLOCK iosb;
PIRP irp;
ENTER_FUNC(); KeInitializeEvent(&event,
NotificationEvent,
FALSE
);
(void*)old_handle_scancode = AddrOfScancode; if (NULL == (irp = IoBuildDeviceIoControlRequest(Ioctl,
DPRINT((0,"handle_scancode = %X\n",AddrOfScancode)); Target,
InputBuffer,
InputBufferLength,
0,
0,
TRUE,
&event,
&iosb))) {
return STATUS_INSUFFICIENT_RESOURCES;
}
pPatchAddress = (PUCHAR)AddrOfKbdEvent; // handle_kbd_event status = IoCallDriver(Target, irp);
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) && if (STATUS_PENDING == status) {
(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++; status = KeWaitForSingleObject(&event,
pPatchAddress++; Executive,
KernelMode,
FALSE,
NULL);
ulOffset = (ULONG)old_handle_scancode - ((ULONG)pPatchAddress+sizeof(ULONG)+1); assert(STATUS_SUCCESS == status);
*pOffset = ulOffset; status = iosb.Status;
} }
if(RtlCompareMemory(pPatchAddress,ucPattern,sizeof(ucPattern))==0) return status;
{ }
DPRINT((0,"pattern found @ %x\n",pPatchAddress));
ulOffset = (ULONG)&pice_handle_scancode - ((ULONG)pPatchAddress+sizeof(ULONG)+1); //**************************************************
ulOldOffset = *(PULONG)(pPatchAddress + 1); // PatchKeyboardDriver - set keyboard driver hook.
DPRINT((0,"old offset = %x new offset = %x\n",ulOldOffset,ulOffset)); // We use interface supported by standard keyboard drivers.
//**************************************************
BOOLEAN PatchKeyboardDriver(void)
{
PINTERNAL_I8042_HOOK_KEYBOARD phkData;
UNICODE_STRING DevName;
PDEVICE_OBJECT kbdDevice = NULL;
PFILE_OBJECT FO = NULL;
NTSTATUS status;
save_flags(ulKeyPatchFlags); ENTER_FUNC();
cli(); //When we have i8042 driver this should be changed!!!!!!!
*(PULONG)(pPatchAddress + 1) = ulOffset; RtlInitUnicodeString(&DevName, L"\\Device\\Keyboard");
bPatched = TRUE; //Get pointer to keyboard device
if( !NT_SUCCESS( IoGetDeviceObjectPointer( &DevName, FILE_READ_ACCESS, &FO, &kbdDevice ) ) )
return FALSE;
restore_flags(ulKeyPatchFlags); phkData = ExAllocatePool( PagedPool, sizeof( INTERNAL_I8042_HOOK_KEYBOARD ) );
DPRINT((0,"PatchKeyboardDriver(): SUCCESS!\n")); RtlZeroMemory( phkData, sizeof( INTERNAL_I8042_HOOK_KEYBOARD ) );
}
LEAVE_FUNC(); phkData->IsrRoutine = (PI8042_KEYBOARD_ISR) PiceKbdIsr;
phkData->Context = (PVOID) NULL; //DeviceObject;
return bPatched; //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 ) );
ObDereferenceObject(FO);
ExFreePool(phkData);
LEAVE_FUNC();
return NT_SUCCESS(status);
} }
void RestoreKeyboardDriver(void) void RestoreKeyboardDriver(void)
{ {
ENTER_FUNC(); ENTER_FUNC();
if(bPatched) DbgPrint("RestoreKeyboardDriver: Not Implemented yet!!!\n");
{ LEAVE_FUNC();
save_flags(ulKeyPatchFlags);
cli();
*(PULONG)(pPatchAddress + 1) = ulOldOffset;
restore_flags(ulKeyPatchFlags);
}
LEAVE_FUNC();
} }

View file

@ -39,7 +39,6 @@ Copyright notice:
#include <asm/page.h> #include <asm/page.h>
#include <asm/pgtable.h> #include <asm/pgtable.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/vmalloc.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <asm/delay.h> #include <asm/delay.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>

View file

@ -92,11 +92,12 @@ NTSTATUS STDCALL pice_close(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{ {
DPRINT((0,"pice_close\n")); 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 */ /* We're now ready for our next caller */
bDeviceAlreadyOpen = FALSE; bDeviceAlreadyOpen = FALSE;
IoCompleteRequest (Irp, IO_NO_INCREMENT); IoCompleteRequest (Irp, IO_NO_INCREMENT);
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
@ -179,7 +180,7 @@ NTSTATUS STDCALL DriverEntry(PDRIVER_OBJECT DriverObject,
if(InitPICE()){ if(InitPICE()){
DriverObject->MajorFunction[IRP_MJ_CREATE] = pice_open; 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; DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = pice_ioctl;
RtlInitUnicodeString(&DeviceName, L"\\Device\\Pice"); RtlInitUnicodeString(&DeviceName, L"\\Device\\Pice");

View file

@ -609,7 +609,7 @@ BOOLEAN ConsoleInitSerial(void)
GLOBAL_SCREEN_WIDTH = 80; GLOBAL_SCREEN_WIDTH = 80;
GLOBAL_SCREEN_HEIGHT = 60; GLOBAL_SCREEN_HEIGHT = 60;
pScreenBufferSerial = vmalloc(FRAMEBUFFER_SIZE); pScreenBufferSerial = PICE_malloc(FRAMEBUFFER_SIZE, NONPAGEDPOOL);
if(pScreenBufferSerial) if(pScreenBufferSerial)
{ {
@ -648,7 +648,7 @@ void ConsoleShutdownSerial(void)
FlushSerialBuffer(); FlushSerialBuffer();
if(pScreenBufferSerial) if(pScreenBufferSerial)
vfree(pScreenBufferSerial); PICE_free(pScreenBufferSerial);
LEAVE_FUNC(); LEAVE_FUNC();
} }

View file

@ -28,8 +28,8 @@ Copyright notice:
This file may be distributed under the terms of the GNU Public License. This file may be distributed under the terms of the GNU Public License.
--*/ --*/
void InstallKeyboardHook(void); //void InstallKeyboardHook(void);
void DeInstallKeyboardHook(void); //void DeInstallKeyboardHook(void);
void InstallGlobalKeyboardHook(void); void InstallGlobalKeyboardHook(void);
void DeInstallGlobalKeyboardHook(void); void DeInstallGlobalKeyboardHook(void);

View file

@ -35,12 +35,10 @@ Copyright notice:
#include <linux/elf.h> #include <linux/elf.h>
#include "stab_gnu.h" #include "stab_gnu.h"
#include <linux/vmalloc.h>
#include <asm/io.h> #include <asm/io.h>
#include <asm/page.h> #include <asm/page.h>
#include <asm/pgtable.h> #include <asm/pgtable.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/vmalloc.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <asm/delay.h> #include <asm/delay.h>
#include <linux/ctype.h> #include <linux/ctype.h>
@ -1814,58 +1812,54 @@ BOOLEAN SanityCheckExports(void)
//************************************************************************* //*************************************************************************
BOOLEAN LoadExports(void) BOOLEAN LoadExports(void)
{ {
struct file* pf; HANDLE hf;
BOOLEAN bResult = TRUE; BOOLEAN bResult = TRUE;
ENTER_FUNC(); ENTER_FUNC();
Print(OUTPUT_WINDOW,"pICE: loading exports...\n"); Print(OUTPUT_WINDOW,"pICE: loading exports...\n");
pf = filp_open("/boot/System.map",O_RDONLY,S_IRUSR); hf = PICE_open(L"\\SystemRoot\\symbols\\ntoskrnl.sym",OF_READ);
/*
if(IS_ERR(pf)) if(hf)
{ {
Print(OUTPUT_WINDOW,"pICE: no System.map in /boot\n"); Print(OUTPUT_WINDOW,"pICE: no System.map in /boot\n");
pf = filp_open("/System.map",O_RDONLY,S_IRUSR); hf = PICE_open("/System.map",OF_READ);
} }
*/
if(!IS_ERR(pf)) if(hf)
{ {
mm_segment_t oldfs; mm_segment_t oldfs;
size_t len; size_t len;
if(pf->f_op) len = PICE_len(hf);
if(len)
{ {
DPRINT((0,"pf = %x pf->f_op->read @ %x\n",(ULONG)pf,(ULONG)pf->f_op->read)); DPRINT((0,"file len = %d\n",len));
DPRINT((0,"pf->f_count = %x p->f_flags %x\n",pf->f_count,pf->f_flags));
len = pf->f_dentry->d_inode->i_size; pExports = PICE_malloc(len+1,NONPAGEDPOOL); // maybe make pool setting an option
if(len)
{
DPRINT((0,"file len = %d\n",len));
pExports = vmalloc(len+1); DPRINT((0,"pExports = %x\n",pExports));
DPRINT((0,"pExports = %x\n",pExports)); if(pExports)
{
//oldfs = get_fs(); set_fs(KERNEL_DS);
ulExportLen = len;
((PUCHAR)pExports)[len]=0;
if(len == PICE_read(hf,pExports,len))
{
DPRINT((0,"success reading system map!\n"));
PICE_sprintf(tempSym,"pICE: ntoskrnl.sym @ %x (size %x)\n",pExports,len);
Print(OUTPUT_WINDOW,tempSym);
}
else
DbgPrint("error reading ntoskrnl map!\n");
//set_fs(oldfs);
}
PICE_sprintf(tempSym,"pICE: exports loaded @ %x (size %x)\n",pExports,len);
Print(OUTPUT_WINDOW,tempSym);
if(pExports)
{
oldfs = get_fs(); set_fs(KERNEL_DS);
ulExportLen = len;
((PUCHAR)pExports)[len]=0;
if(len == pf->f_op->read(pf,pExports,len,&pf->f_pos))
{
DPRINT((0,"success reading system map!\n"));
}
set_fs(oldfs);
}
}
} }
filp_close(pf,0); PICE_close(hf);
} }
else else
{ {
@ -1889,7 +1883,7 @@ void UnloadExports(void)
if(pExports) if(pExports)
{ {
DPRINT((0,"freeing %x\n",pExports)); DPRINT((0,"freeing %x\n",pExports));
vfree(pExports); PICE_free(pExports);
pExports = NULL; pExports = NULL;
} }
LEAVE_FUNC(); LEAVE_FUNC();
@ -1901,69 +1895,65 @@ void UnloadExports(void)
//************************************************************************* //*************************************************************************
PICE_SYMBOLFILE_HEADER* LoadSymbols(LPSTR filename) PICE_SYMBOLFILE_HEADER* LoadSymbols(LPSTR filename)
{ {
struct file* pf; HANDLE hf;
PICE_SYMBOLFILE_HEADER* pSymbols=NULL; PICE_SYMBOLFILE_HEADER* pSymbols=NULL;
ENTER_FUNC(); ENTER_FUNC();
if(ulNumSymbolsLoaded<DIM(apSymbols)) if(ulNumSymbolsLoaded<DIM(apSymbols))
{ {
pf = filp_open(filename,O_RDONLY,S_IRUSR); hf = PICE_open(filename,OF_READ);
if(!IS_ERR(pf)) if(hf)
{ {
mm_segment_t oldfs; //mm_segment_t oldfs;
size_t len; size_t len;
DPRINT((0,"pf = %x\n",pf)); DPRINT((0,"hf = %x\n",hf));
if(pf->f_op)
len = PICE_len(hf);
DPRINT((0,"file len = %d\n",len));
if(len)
{ {
DPRINT((0,"pf = %x pf->f_op->read @ %x\n",(ULONG)pf,(ULONG)pf->f_op->read)); pSymbols = PICE_malloc(len+1,NONPAGEDPOOL); // maybe make pool setting an option
DPRINT((0,"pf->f_count = %x p->f_flags %x\n",pf->f_count,pf->f_flags)); DPRINT((0,"pSymbols = %x\n",pSymbols));
len = pf->f_dentry->d_inode->i_size; if(pSymbols)
DPRINT((0,"file len = %d\n",len)); {
//oldfs = get_fs(); set_fs(KERNEL_DS);
if(len) if(len == PICE_read(hf,(PVOID)pSymbols,len))
{ {
pSymbols = vmalloc(len+1); DPRINT((0,"LoadSymbols(): success reading symbols!\n"));
DPRINT((0,"pSymbols = %x\n",pSymbols)); DPRINT((0,"LoadSymbols(): pSymbols->magic = %X\n",pSymbols->magic));
}
if(pSymbols) //set_fs(oldfs);
{
oldfs = get_fs(); set_fs(KERNEL_DS);
if(len == pf->f_op->read(pf,(PVOID)pSymbols,len,&pf->f_pos))
{
DPRINT((0,"LoadSymbols(): success reading symbols!\n"));
DPRINT((0,"LoadSymbols(): pSymbols->magic = %X\n",pSymbols->magic));
}
set_fs(oldfs);
if(pSymbols->magic == PICE_MAGIC) if(pSymbols->magic == PICE_MAGIC)
{ {
DPRINT((0,"magic = %X\n",pSymbols->magic)); DPRINT((0,"magic = %X\n",pSymbols->magic));
DPRINT((0,"name = %s\n",pSymbols->name));; DPRINT((0,"name = %s\n",pSymbols->name));;
DPRINT((0,"ulOffsetToHeaders,ulSizeOfHeader = %X,%X\n",pSymbols->ulOffsetToHeaders,pSymbols->ulSizeOfHeader)); DPRINT((0,"ulOffsetToHeaders,ulSizeOfHeader = %X,%X\n",pSymbols->ulOffsetToHeaders,pSymbols->ulSizeOfHeader));
DPRINT((0,"ulOffsetToGlobals,ulSizeOfGlobals = %X,%X\n",pSymbols->ulOffsetToGlobals,pSymbols->ulSizeOfGlobals)); DPRINT((0,"ulOffsetToGlobals,ulSizeOfGlobals = %X,%X\n",pSymbols->ulOffsetToGlobals,pSymbols->ulSizeOfGlobals));
DPRINT((0,"ulOffsetToGlobalsStrings,ulSizeOfGlobalsStrings = %X,%X\n",pSymbols->ulOffsetToGlobalsStrings,pSymbols->ulSizeOfGlobalsStrings)); DPRINT((0,"ulOffsetToGlobalsStrings,ulSizeOfGlobalsStrings = %X,%X\n",pSymbols->ulOffsetToGlobalsStrings,pSymbols->ulSizeOfGlobalsStrings));
DPRINT((0,"ulOffsetToStabs,ulSizeOfStabs = %X,%X\n",pSymbols->ulOffsetToStabs,pSymbols->ulSizeOfStabs)); DPRINT((0,"ulOffsetToStabs,ulSizeOfStabs = %X,%X\n",pSymbols->ulOffsetToStabs,pSymbols->ulSizeOfStabs));
DPRINT((0,"ulOffsetToStabsStrings,ulSizeOfStabsStrings = %X,%X\n",pSymbols->ulOffsetToStabsStrings,pSymbols->ulSizeOfStabsStrings)); DPRINT((0,"ulOffsetToStabsStrings,ulSizeOfStabsStrings = %X,%X\n",pSymbols->ulOffsetToStabsStrings,pSymbols->ulSizeOfStabsStrings));
DPRINT((0,"ulOffsetToSrcFiles,ulNumberOfSrcFiles = %X,%X\n",pSymbols->ulOffsetToSrcFiles,pSymbols->ulNumberOfSrcFiles)); DPRINT((0,"ulOffsetToSrcFiles,ulNumberOfSrcFiles = %X,%X\n",pSymbols->ulOffsetToSrcFiles,pSymbols->ulNumberOfSrcFiles));
DPRINT((0,"pICE: symbols loaded for module \"%s\" @ %x\n",pSymbols->name,pSymbols)); DPRINT((0,"pICE: symbols loaded for module \"%s\" @ %x\n",pSymbols->name,pSymbols));
apSymbols[ulNumSymbolsLoaded++]=pSymbols; apSymbols[ulNumSymbolsLoaded++]=pSymbols;
} }
else else
{ {
DPRINT((0,"LoadSymbols(): freeing %x\n",pSymbols)); DPRINT((0,"LoadSymbols(): freeing %x\n",pSymbols));
DPRINT((0,"pICE: symbols file \"%s\" corrupt\n",filename)); DPRINT((0,"pICE: symbols file \"%s\" corrupt\n",filename));
vfree(pSymbols); PICE_free(pSymbols);
} }
} }
}
} }
filp_close(pf,0);
PICE_close(hf);
} }
else else
{ {
@ -2010,7 +2000,7 @@ void UnloadSymbols()
for(i=0;i<ulNumSymbolsLoaded;i++) for(i=0;i<ulNumSymbolsLoaded;i++)
{ {
DPRINT((0,"freeing [%u] %x\n",i,apSymbols[i])); DPRINT((0,"freeing [%u] %x\n",i,apSymbols[i]));
vfree(apSymbols[i]); PICE_free(apSymbols[i]);
apSymbols[i] = NULL; apSymbols[i] = NULL;
} }
ulNumSymbolsLoaded = 0; ulNumSymbolsLoaded = 0;
@ -2024,7 +2014,7 @@ void UnloadSymbols()
//************************************************************************* //*************************************************************************
BOOLEAN LoadSymbolsFromConfig(BOOLEAN bIgnoreBootParams) BOOLEAN LoadSymbolsFromConfig(BOOLEAN bIgnoreBootParams)
{ {
struct file* pf; HANDLE hf;
LPSTR pConfig,pConfigEnd,pTemp; LPSTR pConfig,pConfigEnd,pTemp;
char temp[256]; char temp[256];
ULONG line = 1; ULONG line = 1;
@ -2032,143 +2022,141 @@ BOOLEAN LoadSymbolsFromConfig(BOOLEAN bIgnoreBootParams)
ENTER_FUNC(); ENTER_FUNC();
pf = filp_open("/etc/pice.conf",O_RDONLY,0600); hf = PICE_open("L"\\SystemRoot\\symbols\\pice.conf",OF_READ);
if(!IS_ERR(pf)) if(hf)
{ {
mm_segment_t oldfs; //mm_segment_t oldfs;
size_t len; size_t len;
DPRINT((0,"pf = %x\n",pf)); DPRINT((0,"hf = %x\n",hf));
if(pf->f_op)
len = PICE_len(hf);
DPRINT((0,"file len = %d\n",len));
if(len)
{ {
DPRINT((0,"pf = %x pf->f_op->read @ %x\n",(ULONG)pf,(ULONG)pf->f_op->read)); pConfig = PICE_malloc(len+1,NONPAGEDPOOL); // maybe make pool setting an option
DPRINT((0,"pf->f_count = %x p->f_flags %x\n",pf->f_count,pf->f_flags)); DPRINT((0,"pConfig = %x\n",pConfig));
//oldfs = get_fs(); set_fs(KERNEL_DS);
len = pf->f_dentry->d_inode->i_size; if(len == PICE_read(pf,(PVOID)pConfig,len))
DPRINT((0,"file len = %d\n",len)); {
//set_fs(oldfs);
if(len) pConfigEnd = pConfig + len;
{
pConfig = vmalloc(len+1); while(pConfig<pConfigEnd)
DPRINT((0,"pConfig = %x\n",pConfig));
oldfs = get_fs(); set_fs(KERNEL_DS);
if(len == pf->f_op->read(pf,(PVOID)pConfig,len,&pf->f_pos))
{ {
set_fs(oldfs); // skip leading spaces
while(*pConfig==' ' && pConfig<pConfigEnd)
pConfig++;
// get ptr to temporary
pTemp = temp;
// fill in temporary with symbol path
while(*pConfig!=0 && *pConfig!=0x0a && *pConfig!=0x0d && pConfig<pConfigEnd)
*pTemp++ = *pConfig++;
// finish up symbol path string
*pTemp = 0;
// skip any line ends
while((*pConfig==0x0a || *pConfig==0x0d) && pConfig<pConfigEnd)
pConfig++;
pConfigEnd = pConfig + len; // finally try to load the symbols
if(PICE_strlen(temp))
while(pConfig<pConfigEnd)
{ {
// skip leading spaces PICE_SYMBOLFILE_HEADER *pSymbols;
while(*pConfig==' ' && pConfig<pConfigEnd)
pConfig++;
// get ptr to temporary
pTemp = temp;
// fill in temporary with symbol path
while(*pConfig!=0 && *pConfig!=0x0a && *pConfig!=0x0d && pConfig<pConfigEnd)
*pTemp++ = *pConfig++;
// finish up symbol path string
*pTemp = 0;
// skip any line ends
while((*pConfig==0x0a || *pConfig==0x0d) && pConfig<pConfigEnd)
pConfig++;
// finally try to load the symbols // boot parameter
if(PICE_strlen(temp)) if(*temp == '!')
{ {
PICE_SYMBOLFILE_HEADER *pSymbols; if(!bIgnoreBootParams)
// boot parameter
if(*temp == '!')
{ {
if(!bIgnoreBootParams) if(!PICE_strlen(szBootParams))
{ {
if(!PICE_strlen(szBootParams)) PICE_strcpy(szBootParams,temp+1);
{ DPRINT((0,"pICE: boot params = %s\n",szBootParams));
PICE_strcpy(szBootParams,temp+1);
DPRINT((0,"pICE: boot params = %s\n",szBootParams));
}
else
{
DPRINT((0,"pICE: boot params already exist! ignoring...\n",szBootParams));
}
}
}
// options
else if(*temp == '+')
{
if(PICE_strlen(temp)>1)
{
if(PICE_strcmp(temp,"+vga")==0)
{
eTerminalMode = TERMINAL_MODE_VGA_TEXT;
DPRINT((0,"pICE: eTerminalMode = TERMINAL_MODE_VGA_TEXT\n"));
}
else if(PICE_strcmp(temp,"+hercules")==0)
{
eTerminalMode = TERMINAL_MODE_HERCULES_GRAPHICS;
DPRINT((0,"pICE: eTerminalMode = TERMINAL_MODE_HERCULES_GRAPHICS\n"));
}
else if(PICE_strcmp(temp,"+serial")==0)
{
eTerminalMode = TERMINAL_MODE_SERIAL;
DPRINT((0,"pICE: eTerminalMode = TERMINAL_MODE_SERIAL\n"));
}
} }
else else
{ {
DPRINT((0,"pICE: found option, but no value\n")); DPRINT((0,"pICE: boot params already exist! ignoring...\n",szBootParams));
} }
} }
// comment }
else if(*temp == '#') // options
else if(*temp == '+')
{
if(PICE_strlen(temp)>1)
{ {
DPRINT((0,"comment out\n")); if(PICE_strcmp(temp,"+vga")==0)
{
eTerminalMode = TERMINAL_MODE_VGA_TEXT;
DPRINT((0,"pICE: eTerminalMode = TERMINAL_MODE_VGA_TEXT\n"));
}
else if(PICE_strcmp(temp,"+hercules")==0)
{
eTerminalMode = TERMINAL_MODE_HERCULES_GRAPHICS;
DPRINT((0,"pICE: eTerminalMode = TERMINAL_MODE_HERCULES_GRAPHICS\n"));
}
else if(PICE_strcmp(temp,"+serial")==0)
{
eTerminalMode = TERMINAL_MODE_SERIAL;
DPRINT((0,"pICE: eTerminalMode = TERMINAL_MODE_SERIAL\n"));
}
} }
// symbol file name/path
else else
{ {
pSymbols = LoadSymbols(temp); DPRINT((0,"pICE: found option, but no value\n"));
if(pSymbols) }
{ }
PICE_SYMBOLFILE_SOURCE* pSrc; // comment
LPSTR p; else if(*temp == '#')
{
DPRINT((0,"comment out\n"));
}
// symbol file name/path
else
{
DPRINT((0,"Load symbols from file %s\n", temp));
pSymbols = LoadSymbols(temp);
if(pSymbols)
{
PICE_SYMBOLFILE_SOURCE* pSrc;
LPSTR p;
pSrc = (PICE_SYMBOLFILE_SOURCE*)((ULONG)pSymbols + pSymbols->ulOffsetToSrcFiles); pSrc = (PICE_SYMBOLFILE_SOURCE*)((ULONG)pSymbols + pSymbols->ulOffsetToSrcFiles);
pCurrentSymbols = pSymbols; pCurrentSymbols = pSymbols;
p = strrchr(pSrc->filename,'/'); p = strrchr(pSrc->filename,'\\');
if(p) if(p)
{ {
PICE_strcpy(szCurrentFile,p+1); PICE_strcpy(szCurrentFile,p+1);
} }
else else
{ {
PICE_strcpy(szCurrentFile,pSrc->filename); PICE_strcpy(szCurrentFile,pSrc->filename);
}
} }
} }
} }
else
{
DPRINT((0,"invalid line [%u] in config!\n",line));
}
line++;
} }
} else
else {
{ DPRINT((0,"invalid line [%u] in config!\n",line));
set_fs(oldfs); }
line++;
} }
} }
else
{
//set_fs(oldfs);
}
} }
filp_close(pf,0);
PICE_close(hf);
bResult = TRUE; bResult = TRUE;
} }
else else
{ {
DPRINT((0,"pICE: config file not found! No symbols loaded.\n")); DPRINT((0,"pICE: config file not found! No symbols loaded.\n"));
DPRINT((0,"pICE: Please make sure to create a file /etc/pice.conf\n")); DPRINT((0,"pICE: Please make sure to create a file \\systemroot\\symbols\\pice.conf\n"));
DPRINT((0,"pICE: if you want to have symbols for any module loaded.\n")); DPRINT((0,"pICE: if you want to have symbols for any module loaded.\n"));
} }

View file

@ -36,13 +36,14 @@ Copyright notice:
#include <asm/page.h> #include <asm/page.h>
#include <asm/pgtable.h> #include <asm/pgtable.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/vmalloc.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <asm/delay.h> #include <asm/delay.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/ctype.h> #include <linux/ctype.h>
#include <defines.h>
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
// GLOBALS // GLOBALS
@ -2006,14 +2007,20 @@ UCHAR AsciiToScan(UCHAR s)
//************************************************************************ //************************************************************************
void outportb(USHORT port,UCHAR data) void outportb(USHORT port,UCHAR data)
{ {
WRITE_PORT_UCHAR(data,port); WRITE_PORT_UCHAR(port, data);
} }
void outb_p(UCHAR data, USHORT port) void outb_p(UCHAR data, USHORT port)
{ {
WRITE_PORT_UCHAR(data,port); WRITE_PORT_UCHAR(port, data);
} }
VOID outl(ULONG data, PULONG port)
{
WRITE_PORT_ULONG(port, data);
}
//************************************************************************ //************************************************************************
// inportb() // inportb()
// //
@ -2028,6 +2035,11 @@ UCHAR inb_p(USHORT port)
return READ_PORT_UCHAR(port); return READ_PORT_UCHAR(port);
} }
ULONG inl(PULONG port)
{
return READ_PORT_ULONG(port);
}
//************************************************************************* //*************************************************************************
// GetInitMm() // GetInitMm()
@ -2079,3 +2091,109 @@ void EnablePassThrough(void)
restore_flags(flags); restore_flags(flags);
} }
//***********************************************************************************
// Pice_malloc - allocate memory from paged or non-paged pool
//***********************************************************************************
void * PICE_malloc( size_t numBytes, BOOLEAN fromPaged )
{
void* res = ExAllocatePool( (fromPaged)?PagedPool:NonPagedPool, numBytes );
assert(res);
return res;
}
//***********************************************************************************
// PICE_free - free memory allocated by PICE_malloc
//***********************************************************************************
void PICE_free( void* p )
{
assert( p );
ExFreePool( p );
}
long PICE_read(HANDLE hFile, LPVOID lpBuffer, long lBytes)
{
DWORD NumberOfBytesRead;
IO_STATUS_BLOCK iosb;
assert( lpBuffer );
if (!NT_SUCCESS(NtReadFile(
(HANDLE) hFile,
NULL, NULL, NULL, &iosb,
(LPVOID) lpBuffer,
(DWORD) lBytes,
NULL,
NULL
)))
{
return -1;
}
NumberOfBytesRead = iosb.Information;
return NumberOfBytesRead;
}
HANDLE PICE_open (LPCWSTR lpPathName, int iReadWrite)
{
DWORD dwAccessMask = 0;
DWORD dwShareMode = 0;
UNICODE_STRING TmpFileName;
OBJECT_ATTRIBUTES ObjectAttributes;
HANDLE hfile;
NTSTATUS status;
if ( (iReadWrite & OF_READWRITE ) == OF_READWRITE )
dwAccessMask = GENERIC_READ | GENERIC_WRITE;
else if ( (iReadWrite & OF_READ ) == OF_READ )
dwAccessMask = GENERIC_READ;
else if ( (iReadWrite & OF_WRITE ) == OF_WRITE )
dwAccessMask = GENERIC_WRITE;
if ((iReadWrite & OF_SHARE_COMPAT) == OF_SHARE_COMPAT )
dwShareMode = FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE;
else if ((iReadWrite & OF_SHARE_DENY_NONE) == OF_SHARE_DENY_NONE)
dwShareMode = FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE;
else if ((iReadWrite & OF_SHARE_DENY_READ) == OF_SHARE_DENY_READ)
dwShareMode = FILE_SHARE_WRITE | FILE_SHARE_DELETE;
else if ((iReadWrite & OF_SHARE_DENY_WRITE) == OF_SHARE_DENY_WRITE )
dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE;
else if ((iReadWrite & OF_SHARE_EXCLUSIVE) == OF_SHARE_EXCLUSIVE)
dwShareMode = 0;
RtlInitUnicodeString (&TmpFileName, lpPathName);
InitializeObjectAttributes(&ObjectAttributes,
&TmpFileName,
0,
NULL,
NULL);
status = NtOpenFile( &hfile,
dwAccessMask,
&ObjectAttributes,
NULL, dwShareMode, 0);
//BUG BUG check status!!!
return hfile;
}
int PICE_close (HANDLE hFile)
{
if (NT_SUCCESS( ZwClose((HANDLE)hFile)))
{
return 0;
}
DbgPrint("ZwClose failed:\n");
return -1;
}
size_t PICE_len( HANDLE hFile )
{
FILE_STANDARD_INFORMATION fs;
IO_STATUS_BLOCK iosb;
NTSTATUS status;
status = ZwQueryInformationFile( hFile, &iosb, &fs, sizeof fs, FileStandardInformation );
assert(fs.EndOfFile.HighPart == 0);
return (size_t)fs.EndOfFile.LowPart;
}

View file

@ -242,6 +242,10 @@ UCHAR inportb(USHORT port);
void outb_p(UCHAR data, USHORT port); void outb_p(UCHAR data, USHORT port);
UCHAR inb_p(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 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 restore_flags(x) __asm__ __volatile__("pushl %0 ; popfl": /* no output */ :"g" (x):"memory", "cc")
#define cli() __asm__ __volatile__("cli": : :"memory") #define cli() __asm__ __volatile__("cli": : :"memory")
@ -253,3 +257,14 @@ extern unsigned long sys_call_table[];
struct mm_struct *GetInitMm(void); struct mm_struct *GetInitMm(void);
void EnablePassThrough(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 );

View file

@ -393,11 +393,11 @@ BOOLEAN ConsoleInitVga(void)
#ifdef LOCAL_CONSOLE #ifdef LOCAL_CONSOLE
// the real framebuffer // the real framebuffer
pScreenBufferHardwareVga = ioremap(0xB8000,FRAMEBUFFER_SIZE); pScreenBufferHardwareVga = MmMapIoSpace(0xB8000,FRAMEBUFFER_SIZE,MmWriteCombined);
// the console // the console
pScreenBufferVga = vmalloc(FRAMEBUFFER_SIZE); pScreenBufferVga = PICE_malloc(FRAMEBUFFER_SIZE,NONPAGEDPOOL);
// the save area // the save area
pScreenBufferTempVga = vmalloc(FRAMEBUFFER_SIZE); pScreenBufferTempVga = PICE_malloc(FRAMEBUFFER_SIZE,NONPAGEDPOOL);
#else #else
outb_p(0,0x3b8); outb_p(0,0x3b8);
outb_p(0,0x3bf); outb_p(0,0x3bf);
@ -410,7 +410,7 @@ BOOLEAN ConsoleInitVga(void)
} }
outb_p(0x08,0x3b8); outb_p(0x08,0x3b8);
pScreenBufferVga=ioremap(0xB0000,FRAMEBUFFER_SIZE); pScreenBufferVga=MmMapIoSpace(0xB0000,FRAMEBUFFER_SIZE,MmWriteCombined);
#endif #endif
if(pScreenBufferVga) if(pScreenBufferVga)
{ {
@ -446,9 +446,9 @@ void ConsoleShutdownVga(void)
#ifdef LOCAL_CONSOLE #ifdef LOCAL_CONSOLE
if(pScreenBufferVga) if(pScreenBufferVga)
{ {
vfree(pScreenBufferVga); PICE_free(pScreenBufferVga);
vfree(pScreenBufferTempVga); PICE_free(pScreenBufferTempVga);
iounmap(pScreenBufferHardwareVga); MmUnmapIoSpace(pScreenBufferHardwareVga,FRAMEBUFFER_SIZE);
} }
#else #else
// HERC video off // HERC video off
@ -456,7 +456,7 @@ void ConsoleShutdownVga(void)
outb_p(0,0x3bf); outb_p(0,0x3bf);
if(pScreenBufferVga) if(pScreenBufferVga)
iounmap(pScreenBufferVga); MmUnmapIoSpace(pScreenBufferVga,FRAMEBUFFER_SIZE);
#endif #endif
LEAVE_FUNC(); LEAVE_FUNC();