From ef93b483109ab59268f0864ed83c566fb21745a3 Mon Sep 17 00:00:00 2001 From: Eugene Ingerman Date: Thu, 6 Dec 2001 09:20:57 +0000 Subject: [PATCH] Porting pice. Added keyboard hook and some file functions. svn path=/trunk/; revision=2420 --- reactos/apps/utils/pice/module/hercules.c | 4 +- reactos/apps/utils/pice/module/init.c | 8 +- reactos/apps/utils/pice/module/parse.h | 2 +- reactos/apps/utils/pice/module/patch.c | 188 +++-- reactos/apps/utils/pice/module/pgflt.c | 3 +- reactos/apps/utils/pice/module/privateice.c | 5 +- reactos/apps/utils/pice/module/serial.c | 4 +- reactos/apps/utils/pice/module/shell.h | 4 +- reactos/apps/utils/pice/module/symbols.c | 724 ++++++++++---------- reactos/apps/utils/pice/module/utils.c | 670 ++++++++++-------- reactos/apps/utils/pice/module/utils.h | 15 + reactos/apps/utils/pice/module/vga.c | 16 +- 12 files changed, 902 insertions(+), 741 deletions(-) diff --git a/reactos/apps/utils/pice/module/hercules.c b/reactos/apps/utils/pice/module/hercules.c index 359e82c25e6..5dfcc021371 100644 --- a/reactos/apps/utils/pice/module/hercules.c +++ b/reactos/apps/utils/pice/module/hercules.c @@ -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(); } diff --git a/reactos/apps/utils/pice/module/init.c b/reactos/apps/utils/pice/module/init.c index 01ab2fb18ab..8a94134dd49 100644 --- a/reactos/apps/utils/pice/module/init.c +++ b/reactos/apps/utils/pice/module/init.c @@ -36,7 +36,6 @@ Copyright notice: #include "precomp.h" #include -#include #include #include #include @@ -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"); diff --git a/reactos/apps/utils/pice/module/parse.h b/reactos/apps/utils/pice/module/parse.h index 4352b56951f..92018750884 100644 --- a/reactos/apps/utils/pice/module/parse.h +++ b/reactos/apps/utils/pice/module/parse.h @@ -164,4 +164,4 @@ COMMAND_PROTOTYPE(ShowPCI); COMMAND_PROTOTYPE(SetKeyboardLayout); COMMAND_PROTOTYPE(ShowSysCallTable); COMMAND_PROTOTYPE(SetAltKey); -COMMAND_PROTOTYPE(ShowContext); \ No newline at end of file +COMMAND_PROTOTYPE(ShowContext); diff --git a/reactos/apps/utils/pice/module/patch.c b/reactos/apps/utils/pice/module/patch.c index 4d2967cad8b..3a6d0295322 100644 --- a/reactos/apps/utils/pice/module/patch.c +++ b/reactos/apps/utils/pice/module/patch.c @@ -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 +#include +#include + //////////////////////////////////////////////////// // 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(); } diff --git a/reactos/apps/utils/pice/module/pgflt.c b/reactos/apps/utils/pice/module/pgflt.c index 311f76d90ae..3397a234742 100644 --- a/reactos/apps/utils/pice/module/pgflt.c +++ b/reactos/apps/utils/pice/module/pgflt.c @@ -39,7 +39,6 @@ Copyright notice: #include #include #include -#include #include #include #include @@ -386,4 +385,4 @@ void DeInstallIntEHook(void) UnmaskIrqs(); LEAVE_FUNC(); -} \ No newline at end of file +} diff --git a/reactos/apps/utils/pice/module/privateice.c b/reactos/apps/utils/pice/module/privateice.c index 6bd24dfbaa1..2028976828c 100644 --- a/reactos/apps/utils/pice/module/privateice.c +++ b/reactos/apps/utils/pice/module/privateice.c @@ -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"); diff --git a/reactos/apps/utils/pice/module/serial.c b/reactos/apps/utils/pice/module/serial.c index 29b1516b300..b51c1fe1751 100644 --- a/reactos/apps/utils/pice/module/serial.c +++ b/reactos/apps/utils/pice/module/serial.c @@ -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(); } diff --git a/reactos/apps/utils/pice/module/shell.h b/reactos/apps/utils/pice/module/shell.h index 9900758d3e8..f1a8d1bbfad 100644 --- a/reactos/apps/utils/pice/module/shell.h +++ b/reactos/apps/utils/pice/module/shell.h @@ -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); diff --git a/reactos/apps/utils/pice/module/symbols.c b/reactos/apps/utils/pice/module/symbols.c index ab508e262a6..18cc66b2aa9 100644 --- a/reactos/apps/utils/pice/module/symbols.c +++ b/reactos/apps/utils/pice/module/symbols.c @@ -35,12 +35,10 @@ Copyright notice: #include #include "stab_gnu.h" -#include #include #include #include #include -#include #include #include #include @@ -85,16 +83,16 @@ ULONG ulNumStructMembers; BOOLEAN Expression(PVRET pvr); -//************************************************************************* -// InitFakeKernelModule() -// -//************************************************************************* +//************************************************************************* +// InitFakeKernelModule() +// +//************************************************************************* BOOLEAN InitFakeKernelModule(void) { struct module* pMod; ENTER_FUNC(); - + if(pmodule_list) { @@ -122,10 +120,10 @@ BOOLEAN InitFakeKernelModule(void) return FALSE; } -//************************************************************************* -// ScanExports() -// -//************************************************************************* +//************************************************************************* +// ScanExports() +// +//************************************************************************* BOOLEAN ScanExports(const char *pFind,PULONG pValue) { char temp[256]; @@ -164,14 +162,14 @@ nomatch: case 2: if(PICE_strcmp(p,pFind)!=0) { - pExp = pOldStr+1; + pExp = pOldStr+1; goto nomatch; } state = -1; bResult = TRUE; DPRINT((0,"%s @ %x\n",pFind,*pValue)); break; - + } state++; p = PICE_strtok(NULL," "); @@ -183,10 +181,10 @@ nomatch: return bResult; } -//************************************************************************* -// ReadHex() -// -//************************************************************************* +//************************************************************************* +// ReadHex() +// +//************************************************************************* BOOLEAN ReadHex(LPSTR p,PULONG pValue) { ULONG result=0,i; @@ -216,10 +214,10 @@ BOOLEAN ReadHex(LPSTR p,PULONG pValue) return TRUE; } -//************************************************************************* -// ScanExportLine() -// -//************************************************************************* +//************************************************************************* +// ScanExportLine() +// +//************************************************************************* BOOLEAN ScanExportLine(LPSTR p,PULONG ulValue,LPSTR* ppPtrToSymbol) { BOOLEAN bResult = FALSE; @@ -234,10 +232,10 @@ BOOLEAN ScanExportLine(LPSTR p,PULONG ulValue,LPSTR* ppPtrToSymbol) return bResult; } -//************************************************************************* -// ValidityCheckSymbols() -// -//************************************************************************* +//************************************************************************* +// ValidityCheckSymbols() +// +//************************************************************************* BOOLEAN ValidityCheckSymbols(PICE_SYMBOLFILE_HEADER* pSymbols) { BOOLEAN bRet; @@ -252,14 +250,14 @@ BOOLEAN ValidityCheckSymbols(PICE_SYMBOLFILE_HEADER* pSymbols) IsRangeValid((ULONG)pSymbols + pSymbols->ulOffsetToStabsStrings,pSymbols->ulSizeOfStabsStrings) ); DPRINT((0,"ValidityCheckSymbols(): symbols are %s\n",bRet?"VALID":"NOT VALID")); - + return bRet; } -//************************************************************************* -// FindModuleSymbols() -// -//************************************************************************* +//************************************************************************* +// FindModuleSymbols() +// +//************************************************************************* PICE_SYMBOLFILE_HEADER* FindModuleSymbols(ULONG addr) { struct module* pMod; @@ -318,10 +316,10 @@ PICE_SYMBOLFILE_HEADER* FindModuleSymbols(ULONG addr) return NULL; } -//************************************************************************* -// FindModuleFromAddress() -// -//************************************************************************* +//************************************************************************* +// FindModuleFromAddress() +// +//************************************************************************* struct module* FindModuleFromAddress(ULONG addr) { struct module* pMod; @@ -362,10 +360,10 @@ struct module* FindModuleFromAddress(ULONG addr) return NULL; } -//************************************************************************* -// FindModuleByName() -// -//************************************************************************* +//************************************************************************* +// FindModuleByName() +// +//************************************************************************* struct module* FindModuleByName(LPSTR modname) { struct module* pMod; @@ -398,10 +396,10 @@ struct module* FindModuleByName(LPSTR modname) return NULL; } -//************************************************************************* -// FindModuleSymbolsByModuleName() -// -//************************************************************************* +//************************************************************************* +// FindModuleSymbolsByModuleName() +// +//************************************************************************* PICE_SYMBOLFILE_HEADER* FindModuleSymbolsByModuleName(LPSTR modname) { ULONG i; @@ -416,10 +414,10 @@ PICE_SYMBOLFILE_HEADER* FindModuleSymbolsByModuleName(LPSTR modname) return NULL; } -//************************************************************************* -// ScanExportsByAddress() -// -//************************************************************************* +//************************************************************************* +// ScanExportsByAddress() +// +//************************************************************************* BOOLEAN ScanExportsByAddress(LPSTR *pFind,ULONG ulValue) { char temp[256]; @@ -475,7 +473,7 @@ BOOLEAN ScanExportsByAddress(LPSTR *pFind,ULONG ulValue) for(i=0;i<(pSymbols->ulSizeOfGlobals/sizeof(Elf32_Sym));i++) { if((ELF32_ST_BIND(pElfSym->st_info)==STB_GLOBAL || ELF32_ST_BIND(pElfSym->st_info)==STB_LOCAL || ELF32_ST_BIND(pElfSym->st_info)==STB_WEAK) && - (ELF32_ST_TYPE(pElfSym->st_info)==STT_OBJECT || ELF32_ST_TYPE(pElfSym->st_info)==STT_FUNC) && + (ELF32_ST_TYPE(pElfSym->st_info)==STT_OBJECT || ELF32_ST_TYPE(pElfSym->st_info)==STT_FUNC) && (pElfSym->st_shndxst_shndx==SHN_ABS || pElfSym->st_shndx==SHN_COMMON)) { LPSTR pName = &pElfStr[pElfSym->st_name]; @@ -675,10 +673,10 @@ BOOLEAN ScanExportsByAddress(LPSTR *pFind,ULONG ulValue) return bResult; } -//************************************************************************* -// FindFunctionByAddress() -// -//************************************************************************* +//************************************************************************* +// FindFunctionByAddress() +// +//************************************************************************* LPSTR FindFunctionByAddress(ULONG ulValue,PULONG pulstart,PULONG pulend) { Elf32_Sym* pElfSym; @@ -728,7 +726,7 @@ LPSTR FindFunctionByAddress(ULONG ulValue,PULONG pulstart,PULONG pulend) for(i=0;i<(pSymbols->ulSizeOfGlobals/sizeof(Elf32_Sym));i++) { if((ELF32_ST_BIND(pElfSym->st_info)==STB_GLOBAL || ELF32_ST_BIND(pElfSym->st_info)==STB_LOCAL || ELF32_ST_BIND(pElfSym->st_info)==STB_LOCAL)&& - ELF32_ST_TYPE(pElfSym->st_info)==STT_FUNC && + ELF32_ST_TYPE(pElfSym->st_info)==STT_FUNC && (pElfSym->st_shndxst_shndx==SHN_ABS || pElfSym->st_shndx==SHN_COMMON)) { LPSTR pName = &pElfStr[pElfSym->st_name]; @@ -774,7 +772,7 @@ LPSTR FindFunctionByAddress(ULONG ulValue,PULONG pulstart,PULONG pulend) DPRINT((0,"in section [%u] %8x value = %x module struct %x (%x)\n",pElfSym->st_shndx,pElfShdr[pElfSym->st_shndx].sh_offset,ulValue,sizeof(struct module),((sizeof(struct module)+0x10)&~0x0F))); DPRINT((0,"[%u] %32s %.8X %.8X %.8X %.8X %.8X %.8X\n",i,pName,pElfSym->st_name,pElfSym->st_value,pElfSym->st_info,pElfSym->st_other,pElfSym->st_size,pElfSym->st_shndx)); DPRINT((0,"start %x end %x\n",start,end)); - + if(pulstart) *pulstart = start; if(pulend) @@ -793,10 +791,10 @@ LPSTR FindFunctionByAddress(ULONG ulValue,PULONG pulstart,PULONG pulend) return NULL; } -//************************************************************************* -// FindDataSectionOffset() -// -//************************************************************************* +//************************************************************************* +// FindDataSectionOffset() +// +//************************************************************************* ULONG FindDataSectionOffset(Elf32_Shdr* pSHdr) { @@ -816,10 +814,10 @@ ULONG FindDataSectionOffset(Elf32_Shdr* pSHdr) return 0; } -//************************************************************************* -// FindFunctionInModuleByNameViaKsyms() -// -//************************************************************************* +//************************************************************************* +// FindFunctionInModuleByNameViaKsyms() +// +//************************************************************************* ULONG FindFunctionInModuleByNameViaKsyms(struct module* pMod,LPSTR szFunctionname) { ULONG i; @@ -846,10 +844,10 @@ ULONG FindFunctionInModuleByNameViaKsyms(struct module* pMod,LPSTR szFunctionnam return 0; } -//************************************************************************* -// FindFunctionInModuleByName() -// -//************************************************************************* +//************************************************************************* +// FindFunctionInModuleByName() +// +//************************************************************************* ULONG FindFunctionInModuleByName(LPSTR szFunctionname,struct module* pMod) { ULONG i,addr; @@ -888,7 +886,7 @@ ULONG FindFunctionInModuleByName(LPSTR szFunctionname,struct module* pMod) DPRINT((0,"FindFunctionInModuleByName(): BIND = %.8X TYPE = %.8X\n",ELF32_ST_BIND(pElfSym->st_info),ELF32_ST_TYPE(pElfSym->st_info))); if((ELF32_ST_BIND(pElfSym->st_info)==STB_GLOBAL || ELF32_ST_BIND(pElfSym->st_info)==STB_LOCAL || ELF32_ST_BIND(pElfSym->st_info)==STB_WEAK) && - (ELF32_ST_TYPE(pElfSym->st_info)==STT_FUNC || ELF32_ST_TYPE(pElfSym->st_info)==STT_OBJECT) && + (ELF32_ST_TYPE(pElfSym->st_info)==STT_FUNC || ELF32_ST_TYPE(pElfSym->st_info)==STT_OBJECT) && (pElfSym->st_shndxst_name]; @@ -940,10 +938,10 @@ ULONG FindFunctionInModuleByName(LPSTR szFunctionname,struct module* pMod) return FindFunctionInModuleByNameViaKsyms(pMod,szFunctionname); } -//************************************************************************* -// ExtractTypeNumber() -// -//************************************************************************* +//************************************************************************* +// ExtractTypeNumber() +// +//************************************************************************* ULONG ExtractTypeNumber(LPSTR p) { LPSTR pTypeNumber; @@ -970,10 +968,10 @@ ULONG ExtractTypeNumber(LPSTR p) return ulTypeNumber; } -//************************************************************************* -// FindTypeDefinitionForCombinedTypes() -// -//************************************************************************* +//************************************************************************* +// FindTypeDefinitionForCombinedTypes() +// +//************************************************************************* LPSTR FindTypeDefinitionForCombinedTypes(PICE_SYMBOLFILE_HEADER* pSymbols,ULONG ulTypeNumber,ULONG ulFileNumber) { ULONG i; @@ -1084,10 +1082,10 @@ LPSTR FindTypeDefinitionForCombinedTypes(PICE_SYMBOLFILE_HEADER* pSymbols,ULONG return NULL; } -//************************************************************************* -// FindTypeDefinition() -// -//************************************************************************* +//************************************************************************* +// FindTypeDefinition() +// +//************************************************************************* LPSTR FindTypeDefinition(PICE_SYMBOLFILE_HEADER* pSymbols,ULONG ulTypeNumber,ULONG ulFileNumber) { ULONG i; @@ -1200,10 +1198,10 @@ LPSTR FindTypeDefinition(PICE_SYMBOLFILE_HEADER* pSymbols,ULONG ulTypeNumber,ULO } -//************************************************************************* -// TruncateString() -// -//************************************************************************* +//************************************************************************* +// TruncateString() +// +//************************************************************************* LPSTR TruncateString(LPSTR p,char c) { static char temp[1024]; @@ -1219,12 +1217,12 @@ LPSTR TruncateString(LPSTR p,char c) return temp; } -//************************************************************************* -// FindLocalsByAddress() -// +//************************************************************************* +// FindLocalsByAddress() +// // find all locals for a given address by first looking up the function // and then it's locals -//************************************************************************* +//************************************************************************* PLOCAL_VARIABLE FindLocalsByAddress(ULONG addr) { ULONG i; @@ -1379,10 +1377,10 @@ PLOCAL_VARIABLE FindLocalsByAddress(ULONG addr) return NULL; } -//************************************************************************* -// FindSourceLineForAddress() -// -//************************************************************************* +//************************************************************************* +// FindSourceLineForAddress() +// +//************************************************************************* LPSTR FindSourceLineForAddress(ULONG addr,PULONG pulLineNumber,LPSTR* ppSrcStart,LPSTR* ppSrcEnd,LPSTR* ppFilename) { ULONG i; // index for walking through STABS @@ -1391,7 +1389,7 @@ LPSTR FindSourceLineForAddress(ULONG addr,PULONG pulLineNumber,LPSTR* ppSrcStart int nStabLen; // length of STAB section in bytes int nOffset=0,nNextOffset=0; // offset and next offset in string table PICE_SYMBOLFILE_HEADER* pSymbols; // pointer to module's STAB symbol table - static char szCurrentFunction[256]; + static char szCurrentFunction[256]; static char szCurrentPath[256]; static char szWantedPath[256]; LPSTR pFunctionName; // name of function that brackets the current address @@ -1588,10 +1586,10 @@ LPSTR FindSourceLineForAddress(ULONG addr,PULONG pulLineNumber,LPSTR* ppSrcStart return NULL; } -//************************************************************************* -// FindAddressForSourceLine() -// -//************************************************************************* +//************************************************************************* +// FindAddressForSourceLine() +// +//************************************************************************* BOOLEAN FindAddressForSourceLine(ULONG ulLineNumber,LPSTR pFilename,struct module* pMod,PULONG pValue) { ULONG i; @@ -1696,10 +1694,10 @@ BOOLEAN FindAddressForSourceLine(ULONG ulLineNumber,LPSTR pFilename,struct modul return bFound; } -//************************************************************************* -// ListSymbolStartingAt() -// -//************************************************************************* +//************************************************************************* +// ListSymbolStartingAt() +// +//************************************************************************* ULONG ListSymbolStartingAt(struct module* pMod,PICE_SYMBOLFILE_HEADER* pSymbols,ULONG index,LPSTR pOutput) { ULONG i; @@ -1723,7 +1721,7 @@ ULONG ListSymbolStartingAt(struct module* pMod,PICE_SYMBOLFILE_HEADER* pSymbols, DPRINT((0,"ListSymbolStartingAt(): [%u] %.8X %.8X %s\n",i,pElfSym->st_info,pElfSym->st_shndx,pName)); if((ELF32_ST_BIND(pElfSym->st_info)==STB_GLOBAL || ELF32_ST_BIND(pElfSym->st_info)==STB_LOCAL || ELF32_ST_BIND(pElfSym->st_info)==STB_WEAK) && - (ELF32_ST_TYPE(pElfSym->st_info)==STT_FUNC || ELF32_ST_TYPE(pElfSym->st_info)==STT_OBJECT)&& + (ELF32_ST_TYPE(pElfSym->st_info)==STT_FUNC || ELF32_ST_TYPE(pElfSym->st_info)==STT_OBJECT)&& (pElfSym->st_shndxst_shndx==SHN_ABS || pElfSym->st_shndx==SHN_COMMON) ) { ULONG section_flags = pElfShdr[pElfSym->st_shndx].sh_flags; @@ -1761,10 +1759,10 @@ ULONG ListSymbolStartingAt(struct module* pMod,PICE_SYMBOLFILE_HEADER* pSymbols, return 0; } -//************************************************************************* -// SanityCheckExports() -// -//************************************************************************* +//************************************************************************* +// SanityCheckExports() +// +//************************************************************************* BOOLEAN SanityCheckExports(void) { BOOLEAN bResult = FALSE; @@ -1808,64 +1806,60 @@ BOOLEAN SanityCheckExports(void) return bResult; } -//************************************************************************* -// LoadExports() -// -//************************************************************************* +//************************************************************************* +// LoadExports() +// +//************************************************************************* BOOLEAN LoadExports(void) { - struct file* pf; + HANDLE hf; BOOLEAN bResult = TRUE; ENTER_FUNC(); - - Print(OUTPUT_WINDOW,"pICE: loading exports...\n"); - pf = filp_open("/boot/System.map",O_RDONLY,S_IRUSR); - if(IS_ERR(pf)) + Print(OUTPUT_WINDOW,"pICE: loading exports...\n"); + hf = PICE_open(L"\\SystemRoot\\symbols\\ntoskrnl.sym",OF_READ); + /* + if(hf) { 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; 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,"pf->f_count = %x p->f_flags %x\n",pf->f_count,pf->f_flags)); + DPRINT((0,"file len = %d\n",len)); - len = pf->f_dentry->d_inode->i_size; - if(len) - { - DPRINT((0,"file len = %d\n",len)); + pExports = PICE_malloc(len+1,NONPAGEDPOOL); // maybe make pool setting an option - 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 { @@ -1879,91 +1873,87 @@ BOOLEAN LoadExports(void) return bResult; } -//************************************************************************* -// UnloadExports() -// -//************************************************************************* +//************************************************************************* +// UnloadExports() +// +//************************************************************************* void UnloadExports(void) { ENTER_FUNC(); if(pExports) - { + { DPRINT((0,"freeing %x\n",pExports)); - vfree(pExports); + PICE_free(pExports); pExports = NULL; } LEAVE_FUNC(); } -//************************************************************************* -// LoadSymbols() -// -//************************************************************************* +//************************************************************************* +// LoadSymbols() +// +//************************************************************************* PICE_SYMBOLFILE_HEADER* LoadSymbols(LPSTR filename) { - struct file* pf; + HANDLE hf; PICE_SYMBOLFILE_HEADER* pSymbols=NULL; ENTER_FUNC(); - + if(ulNumSymbolsLoadedf_op) + DPRINT((0,"hf = %x\n",hf)); + + 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)); - DPRINT((0,"pf->f_count = %x p->f_flags %x\n",pf->f_count,pf->f_flags)); + pSymbols = PICE_malloc(len+1,NONPAGEDPOOL); // maybe make pool setting an option + DPRINT((0,"pSymbols = %x\n",pSymbols)); - len = pf->f_dentry->d_inode->i_size; - DPRINT((0,"file len = %d\n",len)); - - if(len) - { - pSymbols = vmalloc(len+1); - DPRINT((0,"pSymbols = %x\n",pSymbols)); - - if(pSymbols) - { - 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) + { + //oldfs = get_fs(); set_fs(KERNEL_DS); + if(len == PICE_read(hf,(PVOID)pSymbols,len)) + { + DPRINT((0,"LoadSymbols(): success reading symbols!\n")); + DPRINT((0,"LoadSymbols(): pSymbols->magic = %X\n",pSymbols->magic)); + } + //set_fs(oldfs); - if(pSymbols->magic == PICE_MAGIC) - { - DPRINT((0,"magic = %X\n",pSymbols->magic)); - DPRINT((0,"name = %s\n",pSymbols->name));; - DPRINT((0,"ulOffsetToHeaders,ulSizeOfHeader = %X,%X\n",pSymbols->ulOffsetToHeaders,pSymbols->ulSizeOfHeader)); - DPRINT((0,"ulOffsetToGlobals,ulSizeOfGlobals = %X,%X\n",pSymbols->ulOffsetToGlobals,pSymbols->ulSizeOfGlobals)); - DPRINT((0,"ulOffsetToGlobalsStrings,ulSizeOfGlobalsStrings = %X,%X\n",pSymbols->ulOffsetToGlobalsStrings,pSymbols->ulSizeOfGlobalsStrings)); - DPRINT((0,"ulOffsetToStabs,ulSizeOfStabs = %X,%X\n",pSymbols->ulOffsetToStabs,pSymbols->ulSizeOfStabs)); - DPRINT((0,"ulOffsetToStabsStrings,ulSizeOfStabsStrings = %X,%X\n",pSymbols->ulOffsetToStabsStrings,pSymbols->ulSizeOfStabsStrings)); - DPRINT((0,"ulOffsetToSrcFiles,ulNumberOfSrcFiles = %X,%X\n",pSymbols->ulOffsetToSrcFiles,pSymbols->ulNumberOfSrcFiles)); - DPRINT((0,"pICE: symbols loaded for module \"%s\" @ %x\n",pSymbols->name,pSymbols)); - apSymbols[ulNumSymbolsLoaded++]=pSymbols; - } - else - { - DPRINT((0,"LoadSymbols(): freeing %x\n",pSymbols)); - DPRINT((0,"pICE: symbols file \"%s\" corrupt\n",filename)); - vfree(pSymbols); - } - } + if(pSymbols->magic == PICE_MAGIC) + { + DPRINT((0,"magic = %X\n",pSymbols->magic)); + DPRINT((0,"name = %s\n",pSymbols->name));; + DPRINT((0,"ulOffsetToHeaders,ulSizeOfHeader = %X,%X\n",pSymbols->ulOffsetToHeaders,pSymbols->ulSizeOfHeader)); + DPRINT((0,"ulOffsetToGlobals,ulSizeOfGlobals = %X,%X\n",pSymbols->ulOffsetToGlobals,pSymbols->ulSizeOfGlobals)); + DPRINT((0,"ulOffsetToGlobalsStrings,ulSizeOfGlobalsStrings = %X,%X\n",pSymbols->ulOffsetToGlobalsStrings,pSymbols->ulSizeOfGlobalsStrings)); + DPRINT((0,"ulOffsetToStabs,ulSizeOfStabs = %X,%X\n",pSymbols->ulOffsetToStabs,pSymbols->ulSizeOfStabs)); + DPRINT((0,"ulOffsetToStabsStrings,ulSizeOfStabsStrings = %X,%X\n",pSymbols->ulOffsetToStabsStrings,pSymbols->ulSizeOfStabsStrings)); + DPRINT((0,"ulOffsetToSrcFiles,ulNumberOfSrcFiles = %X,%X\n",pSymbols->ulOffsetToSrcFiles,pSymbols->ulNumberOfSrcFiles)); + DPRINT((0,"pICE: symbols loaded for module \"%s\" @ %x\n",pSymbols->name,pSymbols)); + apSymbols[ulNumSymbolsLoaded++]=pSymbols; + } + else + { + DPRINT((0,"LoadSymbols(): freeing %x\n",pSymbols)); + DPRINT((0,"pICE: symbols file \"%s\" corrupt\n",filename)); + PICE_free(pSymbols); + } + } - } } - filp_close(pf,0); + + PICE_close(hf); } else { @@ -1976,10 +1966,10 @@ PICE_SYMBOLFILE_HEADER* LoadSymbols(LPSTR filename) return pSymbols; } -//************************************************************************* -// ReloadSymbols() -// -//************************************************************************* +//************************************************************************* +// ReloadSymbols() +// +//************************************************************************* BOOLEAN ReloadSymbols(void) { BOOLEAN bResult; @@ -1987,7 +1977,7 @@ BOOLEAN ReloadSymbols(void) ENTER_FUNC(); UnloadSymbols(); - + bResult = LoadSymbolsFromConfig(TRUE); LEAVE_FUNC(); @@ -1995,10 +1985,10 @@ BOOLEAN ReloadSymbols(void) return bResult; } -//************************************************************************* -// UnloadSymbols() -// -//************************************************************************* +//************************************************************************* +// UnloadSymbols() +// +//************************************************************************* void UnloadSymbols() { ULONG i; @@ -2006,11 +1996,11 @@ void UnloadSymbols() ENTER_FUNC(); if(ulNumSymbolsLoaded) - { + { for(i=0;if_op) + DPRINT((0,"hf = %x\n",hf)); + + 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)); - DPRINT((0,"pf->f_count = %x p->f_flags %x\n",pf->f_count,pf->f_flags)); + pConfig = PICE_malloc(len+1,NONPAGEDPOOL); // maybe make pool setting an option + DPRINT((0,"pConfig = %x\n",pConfig)); + //oldfs = get_fs(); set_fs(KERNEL_DS); - len = pf->f_dentry->d_inode->i_size; - DPRINT((0,"file len = %d\n",len)); + if(len == PICE_read(pf,(PVOID)pConfig,len)) + { + //set_fs(oldfs); - if(len) - { - pConfig = vmalloc(len+1); - 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)) + pConfigEnd = pConfig + len; + + while(pConfig1) - { - 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")); - } + PICE_strcpy(szBootParams,temp+1); + DPRINT((0,"pICE: boot params = %s\n",szBootParams)); } 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 { - pSymbols = LoadSymbols(temp); - if(pSymbols) - { - PICE_SYMBOLFILE_SOURCE* pSrc; - LPSTR p; + DPRINT((0,"pICE: found option, but no value\n")); + } + } + // comment + 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); - pCurrentSymbols = pSymbols; - p = strrchr(pSrc->filename,'/'); - if(p) - { - PICE_strcpy(szCurrentFile,p+1); - } - else - { - PICE_strcpy(szCurrentFile,pSrc->filename); - } + pSrc = (PICE_SYMBOLFILE_SOURCE*)((ULONG)pSymbols + pSymbols->ulOffsetToSrcFiles); + pCurrentSymbols = pSymbols; + p = strrchr(pSrc->filename,'\\'); + if(p) + { + PICE_strcpy(szCurrentFile,p+1); + } + else + { + PICE_strcpy(szCurrentFile,pSrc->filename); } } - } - else - { - DPRINT((0,"invalid line [%u] in config!\n",line)); - } - line++; + } } - } - else - { - set_fs(oldfs); + else + { + DPRINT((0,"invalid line [%u] in config!\n",line)); + } + line++; } } + else + { + //set_fs(oldfs); + } } - filp_close(pf,0); + + PICE_close(hf); bResult = TRUE; } else { 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")); } @@ -2178,24 +2166,24 @@ BOOLEAN LoadSymbolsFromConfig(BOOLEAN bIgnoreBootParams) } -//************************************************************************* +//************************************************************************* // EVALUATION OF EXPRESSIONS -//************************************************************************* +//************************************************************************* -//************************************************************************* -// SkipSpaces() -// -//************************************************************************* +//************************************************************************* +// SkipSpaces() +// +//************************************************************************* void SkipSpaces(void) { while(pExpression[ulIndex]==' ') ulIndex++; }; -//************************************************************************* -// FindGlobalStabSymbol() -// -//************************************************************************* +//************************************************************************* +// FindGlobalStabSymbol() +// +//************************************************************************* BOOLEAN FindGlobalStabSymbol(LPSTR pExpression,PULONG pValue,PULONG pulTypeNumber,PULONG pulFileNumber) { ULONG i; @@ -2306,10 +2294,10 @@ BOOLEAN FindGlobalStabSymbol(LPSTR pExpression,PULONG pValue,PULONG pulTypeNumbe return FALSE; } -//************************************************************************* -// ExtractToken() -// -//************************************************************************* +//************************************************************************* +// ExtractToken() +// +//************************************************************************* void ExtractToken(LPSTR pStringToken) { while(isalpha(pExpression[ulIndex]) || isdigit(pExpression[ulIndex]) || pExpression[ulIndex]=='_') @@ -2319,10 +2307,10 @@ void ExtractToken(LPSTR pStringToken) } } -//************************************************************************* -// ExtractTypeName() -// -//************************************************************************* +//************************************************************************* +// ExtractTypeName() +// +//************************************************************************* LPSTR ExtractTypeName(LPSTR p) { static char temp[1024]; @@ -2343,10 +2331,10 @@ LPSTR ExtractTypeName(LPSTR p) return temp; } -//************************************************************************* -// ExtractNumber() -// -//************************************************************************* +//************************************************************************* +// ExtractNumber() +// +//************************************************************************* LONG ExtractNumber(LPSTR p) { LONG lMinus = 1,lBase; @@ -2376,7 +2364,7 @@ LONG ExtractNumber(LPSTR p) lBase = 10; else lBase = 8; - + if(!IsAddressValid((ULONG)p) ) { DPRINT((0,"ExtractNumber(): [3] invalid page %x hit!\n",p)); @@ -2398,10 +2386,10 @@ LONG ExtractNumber(LPSTR p) return (lNumber*lMinus); } -//************************************************************************* -// ExtractArray() -// -//************************************************************************* +//************************************************************************* +// ExtractArray() +// +//************************************************************************* BOOLEAN ExtractArray(PVRET pvr,LPSTR p) { ULONG index_typenumber,type_number; @@ -2447,10 +2435,10 @@ BOOLEAN ExtractArray(PVRET pvr,LPSTR p) return FALSE; } -//************************************************************************* -// ExtractStructMembers() -// -//************************************************************************* +//************************************************************************* +// ExtractStructMembers() +// +//************************************************************************* PVRET ExtractStructMembers(PVRET pvr,LPSTR p) { ULONG len; @@ -2480,7 +2468,7 @@ PVRET ExtractStructMembers(PVRET pvr,LPSTR p) DPRINT((0,"ExtractStructMembers(): type_number = %x\n",type_number)); vr.type = type_number; - + pEqual = PICE_strchr(p,')'); // see if it includes type def if(pEqual) @@ -2580,10 +2568,10 @@ PVRET ExtractStructMembers(PVRET pvr,LPSTR p) return &vr; } -//************************************************************************* -// EvaluateSymbol() -// -//************************************************************************* +//************************************************************************* +// EvaluateSymbol() +// +//************************************************************************* BOOLEAN EvaluateSymbol(PVRET pvr,LPSTR pToken) { LPSTR pTypeDef,pTypeName,pTypeBase,pSemiColon,pStructMembers; @@ -2751,7 +2739,7 @@ BOOLEAN EvaluateSymbol(PVRET pvr,LPSTR pToken) { DPRINT((0,"EvaluateSymbol(): ptr is now %s\n",pStructMembers)); // go back to where member name starts - while(*pStructMembers!=';') + while(*pStructMembers!=';') pStructMembers--; // if ';' present, go to next char if(pStructMembers) @@ -2781,11 +2769,11 @@ BOOLEAN EvaluateSymbol(PVRET pvr,LPSTR pToken) return FALSE; } -//************************************************************************* -// Symbol() -// +//************************************************************************* +// Symbol() +// // Symbol := v -//************************************************************************* +//************************************************************************* BOOLEAN Symbol(PVRET pvr) { char SymbolToken[128]; @@ -2797,11 +2785,11 @@ BOOLEAN Symbol(PVRET pvr) return EvaluateSymbol(pvr,SymbolToken); } -//************************************************************************* -// Expression() -// +//************************************************************************* +// Expression() +// // Expression := Symbol | Symbol->Symbol -//************************************************************************* +//************************************************************************* BOOLEAN Expression(PVRET pvr) { if(!Symbol(pvr)) @@ -2810,10 +2798,10 @@ BOOLEAN Expression(PVRET pvr) return TRUE; } -//************************************************************************* -// Evaluate() -// -//************************************************************************* +//************************************************************************* +// Evaluate() +// +//************************************************************************* void Evaluate(PICE_SYMBOLFILE_HEADER* pSymbols,LPSTR p) { ULONG i; diff --git a/reactos/apps/utils/pice/module/utils.c b/reactos/apps/utils/pice/module/utils.c index 282637ee60f..55017c0a889 100644 --- a/reactos/apps/utils/pice/module/utils.c +++ b/reactos/apps/utils/pice/module/utils.c @@ -7,7 +7,7 @@ Module Name: util.c Abstract: - + Environment: Kernel mode only @@ -36,13 +36,14 @@ Copyright notice: #include #include #include -#include #include #include #include #include #include +#include + //////////////////////////////////////////////////// // GLOBALS @@ -129,10 +130,10 @@ SCANTOASCII ucShiftScanToAscii_US[]= // FUNCTIONS //// -//************************************************************************* -// PICE_memset() -// -//************************************************************************* +//************************************************************************* +// PICE_memset() +// +//************************************************************************* void PICE_memset(void* p,unsigned char c,int sz) { unsigned char *p2 = (unsigned char *)p; @@ -140,19 +141,19 @@ void PICE_memset(void* p,unsigned char c,int sz) *p2++ = c; } -//************************************************************************* -// PICE_memcpy() -// -//************************************************************************* +//************************************************************************* +// PICE_memcpy() +// +//************************************************************************* void PICE_memcpy(void* t,void* s,int sz) { memcpy(t,s,sz); } -//************************************************************************* -// PICE_isprint() -// -//************************************************************************* +//************************************************************************* +// PICE_isprint() +// +//************************************************************************* BOOLEAN PICE_isprint(char c) { BOOLEAN bResult = FALSE; @@ -163,10 +164,10 @@ BOOLEAN PICE_isprint(char c) return bResult; } -//************************************************************************* -// PICE_strchr() -// -//************************************************************************* +//************************************************************************* +// PICE_strchr() +// +//************************************************************************* char* PICE_strchr(char* s,char c) { while(IsAddressValid((ULONG)s) && *s) @@ -187,10 +188,10 @@ char* PICE_strchr(char* s,char c) return NULL; } -//************************************************************************* -// PICE_strncpy() -// -//************************************************************************* +//************************************************************************* +// PICE_strncpy() +// +//************************************************************************* char* PICE_strncpy(char* s1,char* s2,int len) { ULONG len2 = PICE_strlen(s2); @@ -199,41 +200,41 @@ char* PICE_strncpy(char* s1,char* s2,int len) PICE_memcpy(s1,s2,len2+1); else PICE_memcpy(s1,s2,len); - + return s1; } -//************************************************************************* -// PICE_strcpy() -// -//************************************************************************* +//************************************************************************* +// PICE_strcpy() +// +//************************************************************************* char* PICE_strcpy(char* s1,char* s2) { ULONG len2 = PICE_strlen(s2); PICE_memcpy(s1,s2,len2+1); - + return s1; } -//************************************************************************* -// PICE_strcat() -// -//************************************************************************* +//************************************************************************* +// PICE_strcat() +// +//************************************************************************* char* PICE_strcat(char* s1,char* s2) { ULONG len1 = PICE_strlen(s1); ULONG len2 = PICE_strlen(s2); PICE_memcpy(&s1[len1],s2,len2+1); - + return s1; } -//************************************************************************* -// PICE_toupper() -// -//************************************************************************* +//************************************************************************* +// PICE_toupper() +// +//************************************************************************* char PICE_toupper(char c) { if(c>='a' && c<='z') @@ -312,7 +313,7 @@ char c; // PICE_strlen() // // my version of strlen() -// +// // does a page validity check on every character in th string //************************************************************************* USHORT PICE_strlen(char* s) @@ -337,7 +338,7 @@ LPSTR GetShortName(LPSTR p) { ULONG i; - // scan backwards till backslash or start + // scan backwards till backslash or start for(i=PICE_strlen(p);p[i]!='\\' && &p[i]!=p;i--); // it's not start, inc. counter if(&p[i]!=p)i++; @@ -367,12 +368,12 @@ ULONG j; } #endif // LINUX -//************************************************************************* -// IsAddressValid() -// -//************************************************************************* -BOOLEAN IsAddressValid(ULONG address) -{ +//************************************************************************* +// IsAddressValid() +// +//************************************************************************* +BOOLEAN IsAddressValid(ULONG address) +{ pgd_t * pPGD; pmd_t * pPMD; pte_t * pPTE; @@ -415,28 +416,28 @@ BOOLEAN IsAddressValid(ULONG address) } } } - // large page + // large page else { bResult = TRUE; } } } - + return bResult; -} +} -//************************************************************************* -// IsAddressWriteable() +//************************************************************************* +// IsAddressWriteable() // // returns: // TRUE if adress/page is writeable // FALSE if adress/page is not writeable -// -//************************************************************************* -BOOLEAN IsAddressWriteable(ULONG address) -{ +// +//************************************************************************* +BOOLEAN IsAddressWriteable(ULONG address) +{ pgd_t * pPGD; pmd_t * pPMD; pte_t * pPTE; @@ -475,7 +476,7 @@ BOOLEAN IsAddressWriteable(ULONG address) if(pPMD) { bResult |= pmd_val(*pPMD) & _PAGE_RW; - + pPTE = pte_offset(pPMD,address); if(pPTE) { @@ -484,24 +485,24 @@ BOOLEAN IsAddressWriteable(ULONG address) } } } - // large page + // large page else { bResult |= pgd_val(*pPGD) & _PAGE_RW; } } } - + return bResult; -} +} -//************************************************************************* +//************************************************************************* // SetAddressWriteable() -// -//************************************************************************* -BOOLEAN SetAddressWriteable(ULONG address,BOOLEAN bSet) -{ +// +//************************************************************************* +BOOLEAN SetAddressWriteable(ULONG address,BOOLEAN bSet) +{ pgd_t * pPGD; pmd_t * pPMD; pte_t * pPTE; @@ -551,7 +552,7 @@ BOOLEAN SetAddressWriteable(ULONG address,BOOLEAN bSet) } } } - // large page + // large page else { if( bSet ) @@ -562,9 +563,9 @@ BOOLEAN SetAddressWriteable(ULONG address,BOOLEAN bSet) } } } - + return bResult; -} +} //************************************************************************* // IsRangeValid() // @@ -592,24 +593,24 @@ ULONG i,NumPages,PageNum; return TRUE; } -//************************************************************************* -// IsModuleLoaded() -// -//************************************************************************* +//************************************************************************* +// IsModuleLoaded() +// +//************************************************************************* struct module* IsModuleLoaded(LPSTR p) { struct module* pMod; - DPRINT((0,"IsModuleLoaded(%s)\n",p)); + DPRINT((0,"IsModuleLoaded(%s)\n",p)); if(pmodule_list) { pMod = *pmodule_list; do { - DPRINT((0,"module (%x) %s\n",pMod->size,pMod->name)); + DPRINT((0,"module (%x) %s\n",pMod->size,pMod->name)); if(pMod->size && strcmp(p,(LPSTR)pMod->name) == 0) { - DPRINT((0,"module %s is loaded!\n",pMod->name)); + DPRINT((0,"module %s is loaded!\n",pMod->name)); return pMod; } }while((pMod = pMod->next)); @@ -618,86 +619,86 @@ struct module* IsModuleLoaded(LPSTR p) return NULL; } -//************************************************************************* -// GetGDTPtr() -// -// return flat address of GDT -//************************************************************************* -PGDT GetGDTPtr(void) -{ -ULONG gdtr[2]; -PGDT pGdt; - - ENTER_FUNC(); - - __asm__("sgdt %0;":"=m" (gdtr)); - pGdt=(PGDT)(((ULONG)(gdtr[1]<<16))|((ULONG)(gdtr[0]>>16))); - - LEAVE_FUNC(); - - return pGdt; -} - -//************************************************************************* -// GetLinearAddress() -// -// return flat address for SEGMENT:OFFSET -//************************************************************************* -ULONG GetLinearAddress(USHORT Segment,ULONG Offset) +//************************************************************************* +// GetGDTPtr() +// +// return flat address of GDT +//************************************************************************* +PGDT GetGDTPtr(void) { - PGDT pGdt; - ULONG result=0; - PDESCRIPTOR pSel; - USHORT OriginalSegment=Segment; - - ENTER_FUNC(); - - pSel=(struct tagDESCRIPTOR*)&Segment; - - // get GDT pointer - pGdt=GetGDTPtr(); - DPRINT((0,"GetLinearAddress(): pGDT = %.8X\n",pGdt)); - DPRINT((0,"GetLinearAddress(): original Segment:Offset = %.4X:%.8X\n",Segment,Offset)); - - // see if segment selector is in LDT - if(pSel->Ti) - { - DPRINT((0,"GetLinearAddress(): Segment is in LDT\n")); - // get LDT selector - __asm__(" - sldt %%ax +ULONG gdtr[2]; +PGDT pGdt; + + ENTER_FUNC(); + + __asm__("sgdt %0;":"=m" (gdtr)); + pGdt=(PGDT)(((ULONG)(gdtr[1]<<16))|((ULONG)(gdtr[0]>>16))); + + LEAVE_FUNC(); + + return pGdt; +} + +//************************************************************************* +// GetLinearAddress() +// +// return flat address for SEGMENT:OFFSET +//************************************************************************* +ULONG GetLinearAddress(USHORT Segment,ULONG Offset) +{ + PGDT pGdt; + ULONG result=0; + PDESCRIPTOR pSel; + USHORT OriginalSegment=Segment; + + ENTER_FUNC(); + + pSel=(struct tagDESCRIPTOR*)&Segment; + + // get GDT pointer + pGdt=GetGDTPtr(); + DPRINT((0,"GetLinearAddress(): pGDT = %.8X\n",pGdt)); + DPRINT((0,"GetLinearAddress(): original Segment:Offset = %.4X:%.8X\n",Segment,Offset)); + + // see if segment selector is in LDT + if(pSel->Ti) + { + DPRINT((0,"GetLinearAddress(): Segment is in LDT\n")); + // get LDT selector + __asm__(" + sldt %%ax mov %%ax,%0" :"=m" (Segment)); - if(Segment) - { - DPRINT((0,"GetLinearAddress(): no LDT\n")); - // get LDT selector - pGdt=(PGDT)((pGdt[pSel->Val].Base_31_24<<24)| - (pGdt[pSel->Val].Base_23_16<<16)| - (pGdt[pSel->Val].Base_15_0)); - if(!IsRangeValid((ULONG)pGdt,0x8) ) - pGdt=0; - } - else - { - pGdt=0; - } - } - - if(pGdt && Segment) - { - DPRINT((0,"GetLinearAddress(): Segment:Offset = %.4X:%.8X\n",Segment,Offset)); - result=pGdt[OriginalSegment>>3].Base_15_0| - (pGdt[OriginalSegment>>3].Base_23_16<<16)| - (pGdt[OriginalSegment>>3].Base_31_24<<24); - result+=Offset; - } - DPRINT((0,"GetLinearAddress(%.4X:%.8X)=%.8X\n",OriginalSegment,Offset,result)); - - LEAVE_FUNC(); - - return result; -} + if(Segment) + { + DPRINT((0,"GetLinearAddress(): no LDT\n")); + // get LDT selector + pGdt=(PGDT)((pGdt[pSel->Val].Base_31_24<<24)| + (pGdt[pSel->Val].Base_23_16<<16)| + (pGdt[pSel->Val].Base_15_0)); + if(!IsRangeValid((ULONG)pGdt,0x8) ) + pGdt=0; + } + else + { + pGdt=0; + } + } + + if(pGdt && Segment) + { + DPRINT((0,"GetLinearAddress(): Segment:Offset = %.4X:%.8X\n",Segment,Offset)); + result=pGdt[OriginalSegment>>3].Base_15_0| + (pGdt[OriginalSegment>>3].Base_23_16<<16)| + (pGdt[OriginalSegment>>3].Base_31_24<<24); + result+=Offset; + } + DPRINT((0,"GetLinearAddress(%.4X:%.8X)=%.8X\n",OriginalSegment,Offset,result)); + + LEAVE_FUNC(); + + return result; +} //************************************************************************* // ShowRunningMsg() @@ -735,11 +736,11 @@ void ShowStoppedMsg(void) LEAVE_FUNC(); } -//************************************************************************* -// SetHardwareBreakPoint() -// -//************************************************************************* -void SetHardwareBreakPoint(ULONG ulAddress,ULONG ulReg) +//************************************************************************* +// SetHardwareBreakPoint() +// +//************************************************************************* +void SetHardwareBreakPoint(ULONG ulAddress,ULONG ulReg) { ULONG mask = 0x300; ULONG enable_mask = 0x3; @@ -808,48 +809,48 @@ void SetHardwareBreakPoint(ULONG ulAddress,ULONG ulReg) } } -//************************************************************************* -// SetHardwareBreakPoints() -// -// install HW breakpoints -//************************************************************************* -void SetHardwareBreakPoints(void) -{ -ULONG i; -ULONG mask; -ULONG LinAddr0,LinAddr1,LinAddr2,LinAddr3; -PULONG LinAddr[4]={&LinAddr0,&LinAddr1,&LinAddr2,&LinAddr3}; - - ENTER_FUNC(); - - // cancel all debug activity - __asm__(" +//************************************************************************* +// SetHardwareBreakPoints() +// +// install HW breakpoints +//************************************************************************* +void SetHardwareBreakPoints(void) +{ +ULONG i; +ULONG mask; +ULONG LinAddr0,LinAddr1,LinAddr2,LinAddr3; +PULONG LinAddr[4]={&LinAddr0,&LinAddr1,&LinAddr2,&LinAddr3}; + + ENTER_FUNC(); + + // cancel all debug activity + __asm__(" pushl %eax - xorl %eax,%eax - mov %eax,%dr6 - mov %eax,%dr7 + xorl %eax,%eax + mov %eax,%dr6 + mov %eax,%dr7 popl %eax"); - // build DR7 mask - for(mask=0,i=0;i<4;i++) - { - mask<<=2; - if(Bp[i].Active && Bp[i].Used && !Bp[i].Virtual) - { - mask|=0x03; - *LinAddr[3-i]=Bp[i].LinearAddress; - DPRINT((0,"breakpoint %u at %.8X\n",i,Bp[i].LinearAddress)); - } - } - if(mask) - { + // build DR7 mask + for(mask=0,i=0;i<4;i++) + { + mask<<=2; + if(Bp[i].Active && Bp[i].Used && !Bp[i].Virtual) + { + mask|=0x03; + *LinAddr[3-i]=Bp[i].LinearAddress; + DPRINT((0,"breakpoint %u at %.8X\n",i,Bp[i].LinearAddress)); + } + } + if(mask) + { __asm__(" pushl %%eax - movl %0,%%eax - andl $0x000000FF,%%eax - orl $0x300,%%eax - mov %%eax,%%dr7 + movl %0,%%eax + andl $0x000000FF,%%eax + orl $0x300,%%eax + mov %%eax,%%dr7 mov %1,%%eax - mov %%eax,%%dr0 + mov %%eax,%%dr0 mov %2,%%eax mov %%eax,%%dr1 mov %3,%%eax @@ -859,15 +860,15 @@ PULONG LinAddr[4]={&LinAddr0,&LinAddr1,&LinAddr2,&LinAddr3}; popl %%eax" : :"m" (mask),"m" (LinAddr0),"m" (LinAddr1),"m" (LinAddr2),"m" (LinAddr3)); - } - - LEAVE_FUNC(); -} + } + + LEAVE_FUNC(); +} //************************************************************************* // IsCallInstrAtEIP() // -// check if instruction at CS:EIP changes program flow +// check if instruction at CS:EIP changes program flow //************************************************************************* BOOLEAN IsCallInstrAtEIP(void) { @@ -876,7 +877,7 @@ BOOLEAN result=FALSE; ENTER_FUNC(); DPRINT((0,"IsCallInstrAtEIP()\n")); - + linear=(PUCHAR)GetLinearAddress(CurrentCS,CurrentEIP); if(IsRangeValid((ULONG)linear,2)) { @@ -906,7 +907,7 @@ BOOLEAN IsRetAtEIP(void) ENTER_FUNC(); DPRINT((0,"IsRetAtEIP()\n")); - + linear=(PUCHAR)GetLinearAddress(CurrentCS,CurrentEIP); switch(*linear) @@ -1210,46 +1211,46 @@ void SaveOldRegs(void) LEAVE_FUNC(); } -//************************************************************************* -// GetKeyStatus() -// -//************************************************************************* -UCHAR GetKeyStatus(void) -{ - UCHAR ucRet; +//************************************************************************* +// GetKeyStatus() +// +//************************************************************************* +UCHAR GetKeyStatus(void) +{ + UCHAR ucRet; ucRet = inb_p(I8042_PHYSICAL_BASE + I8042_STATUS_REGISTER_OFFSET); - return ucRet; -} - -//************************************************************************* -// GetKeyData() -// -//************************************************************************* -UCHAR GetKeyData(void) -{ - UCHAR ucRet; + return ucRet; +} + +//************************************************************************* +// GetKeyData() +// +//************************************************************************* +UCHAR GetKeyData(void) +{ + UCHAR ucRet; ucRet = inb_p(I8042_PHYSICAL_BASE + I8042_DATA_REGISTER_OFFSET); - return ucRet; -} - -//************************************************************************* -// GetKeyPolled -// -//************************************************************************* -UCHAR KeyboardGetKeyPolled(void) -{ - UCHAR ucKey; - UCHAR ucStatus; + return ucRet; +} + +//************************************************************************* +// GetKeyPolled +// +//************************************************************************* +UCHAR KeyboardGetKeyPolled(void) +{ + UCHAR ucKey; + UCHAR ucStatus; static BOOLEAN bExtended = FALSE; - - while(ucKey=0,(ucStatus=GetKeyStatus())&OUTPUT_BUFFER_FULL) - { + + while(ucKey=0,(ucStatus=GetKeyStatus())&OUTPUT_BUFFER_FULL) + { ucKey = 0; - ucKey = GetKeyData(); - - if(ucStatus&MOUSE_OUTPUT_BUFFER_FULL) - continue; - + ucKey = GetKeyData(); + + if(ucStatus&MOUSE_OUTPUT_BUFFER_FULL) + continue; + DPRINT((1,"GetKeyPolled(): key = %x bExtended=%s\n",ucKey,bExtended?"TRUE":"FALSE")); if(SCANCODE_EXTENDED == ucKey) @@ -1260,57 +1261,57 @@ UCHAR KeyboardGetKeyPolled(void) } else { - if(!(ucKey&0x80)) // keypress - { + if(!(ucKey&0x80)) // keypress + { switch(ucKey&0x7f) { case SCANCODE_L_CTRL: case SCANCODE_R_CTRL: if(!bExtended) - bControl=TRUE; + bControl=TRUE; break; case SCANCODE_L_SHIFT: case SCANCODE_R_SHIFT: if(!bExtended) - bShift=TRUE; + bShift=TRUE; break; case SCANCODE_L_ALT: case SCANCODE_R_ALT: if(!bExtended) - bAlt=TRUE; + bAlt=TRUE; break; default: DPRINT((0,"GetKeyPolled(): control = %u shift = %u alt = %u\n",bControl,bShift,bAlt)); return ucKey; } - } - else - { + } + else + { switch(ucKey&0x7f) { case SCANCODE_L_CTRL: case SCANCODE_R_CTRL: if(!bExtended) - bControl=FALSE; + bControl=FALSE; break; case SCANCODE_L_SHIFT: case SCANCODE_R_SHIFT: if(!bExtended) - bShift=FALSE; + bShift=FALSE; break; case SCANCODE_L_ALT: case SCANCODE_R_ALT: if(!bExtended) - bAlt=FALSE; + bAlt=FALSE; break; } - } + } } bExtended=FALSE; - } - - return ucKey; -} + } + + return ucKey; +} //************************************************************************* // KeyboardFlushKeyboardQueue() @@ -1374,7 +1375,7 @@ load: tempUtil[0] = 0; FlushKeyboardQueue(); - + RestoreGraphicsState(); UnmaskIrqs(); @@ -1385,10 +1386,10 @@ load: -//************************************************************************* -// IntelStackWalk() -// -//************************************************************************* +//************************************************************************* +// IntelStackWalk() +// +//************************************************************************* void IntelStackWalk(ULONG pc,ULONG ebp,ULONG esp) { PULONG pFrame, pPrevFrame; @@ -1406,7 +1407,7 @@ void IntelStackWalk(ULONG pc,ULONG ebp,ULONG esp) ( (pFrame <= pPrevFrame) ) ) { DPRINT((0,"IntelStackWalk(): pFrame is either unaligned or not less than previous\n")); - if( !IsRangeValid((ULONG)pFrame, sizeof(PVOID)*2) ) + if( !IsRangeValid((ULONG)pFrame, sizeof(PVOID)*2) ) { DPRINT((0,"IntelStackWalk(): pFrame not valid pointer!\n")); break; @@ -1478,7 +1479,7 @@ pte_t * FindPteForLinearAddress(ULONG address) } } } - // large page + // large page else { LEAVE_FUNC(); @@ -1486,7 +1487,7 @@ pte_t * FindPteForLinearAddress(ULONG address) } } } - + LEAVE_FUNC(); return NULL; } @@ -1739,7 +1740,7 @@ int PICE_vsprintf(char *buf, const char *fmt, va_list args) *str++ = *fmt; continue; } - + /* process flags */ flags = 0; repeat: @@ -1751,7 +1752,7 @@ int PICE_vsprintf(char *buf, const char *fmt, va_list args) case '#': flags |= NUM_SPECIAL; goto repeat; case '0': flags |= NUM_ZEROPAD; goto repeat; } - + /* get field width */ field_width = -1; if (is_digit(*fmt)) @@ -1769,7 +1770,7 @@ int PICE_vsprintf(char *buf, const char *fmt, va_list args) /* get the precision */ precision = -1; if (*fmt == '.') { - ++fmt; + ++fmt; if (is_digit(*fmt)) precision = skip_atoi(&fmt); else if (*fmt == '*') { @@ -2006,14 +2007,20 @@ UCHAR AsciiToScan(UCHAR s) //************************************************************************ void outportb(USHORT port,UCHAR data) { - WRITE_PORT_UCHAR(data,port); + WRITE_PORT_UCHAR(port, data); } 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() // @@ -2022,17 +2029,22 @@ UCHAR inportb(USHORT port) { return READ_PORT_UCHAR(port); } - + UCHAR inb_p(USHORT port) { return READ_PORT_UCHAR(port); -} +} + +ULONG inl(PULONG port) +{ + return READ_PORT_ULONG(port); +} -//************************************************************************* -// GetInitMm() -// -//************************************************************************* +//************************************************************************* +// GetInitMm() +// +//************************************************************************* struct mm_struct *GetInitMm(void) { @@ -2046,7 +2058,7 @@ struct mm_struct *GetInitMm(void) struct task_struct *pt; ENTER_FUNC(); - + for (pt = current->next_task; pt != current; pt = pt->next_task) { if (pt->pid == 0) { LEAVE_FUNC(); @@ -2057,14 +2069,14 @@ struct mm_struct *GetInitMm(void) DPRINT((0,"GetInitMm(): failure\n")); LEAVE_FUNC(); return NULL; -#endif +#endif } -//************************************************************************* -// EnablePassThrough() -// +//************************************************************************* +// EnablePassThrough() +// // enable MDA passthrough on AGP chipset -//************************************************************************* +//************************************************************************* void EnablePassThrough(void) { ULONG oldCF8,flags; @@ -2079,3 +2091,109 @@ void EnablePassThrough(void) 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; +} + diff --git a/reactos/apps/utils/pice/module/utils.h b/reactos/apps/utils/pice/module/utils.h index 8d1753a5a33..34525205d9f 100644 --- a/reactos/apps/utils/pice/module/utils.h +++ b/reactos/apps/utils/pice/module/utils.h @@ -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 ); diff --git a/reactos/apps/utils/pice/module/vga.c b/reactos/apps/utils/pice/module/vga.c index 78a02de3f8d..7c9298f46c1 100644 --- a/reactos/apps/utils/pice/module/vga.c +++ b/reactos/apps/utils/pice/module/vga.c @@ -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();