Porting pice. Intermediate checkin.

svn path=/trunk/; revision=2502
This commit is contained in:
Eugene Ingerman 2002-01-13 08:47:32 +00:00
parent fd4d47ccfc
commit 2c1c5c45b1
19 changed files with 696 additions and 821 deletions

View file

@ -5,6 +5,7 @@
//#include <ddk/winnt.h> //#include <ddk/winnt.h>
#include <windows.h> #include <windows.h>
#include <ddk/kefuncs.h>
//#include <winnt.h> //#include <winnt.h>
#include <sys/types.h> #include <sys/types.h>

View file

@ -34,8 +34,6 @@ Copyright notice:
// INCLUDES // INCLUDES
//// ////
#include "remods.h" #include "remods.h"
#include <asm/delay.h>
#include "precomp.h" #include "precomp.h"
//////////////////////////////////////////////////// ////////////////////////////////////////////////////

View file

@ -37,7 +37,6 @@ Copyright notice:
#include "remods.h" #include "remods.h"
#include "precomp.h" #include "precomp.h"
#include <asm/io.h>
#include <stdarg.h> #include <stdarg.h>
#include "serial.h" #include "serial.h"
#include "serial_port.h" #include "serial_port.h"

View file

@ -33,8 +33,6 @@ Copyright notice:
// INCLUDES // INCLUDES
//// ////
#include "remods.h" #include "remods.h"
#include <asm/delay.h>
#include "precomp.h" #include "precomp.h"
//////////////////////////////////////////////////// ////////////////////////////////////////////////////

View file

@ -35,10 +35,6 @@ Copyright notice:
#include "remods.h" #include "remods.h"
#include "precomp.h" #include "precomp.h"
#include <asm/io.h>
#include <linux/ctype.h>
#include <asm/delay.h>
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
// PROTOTYPES // PROTOTYPES
//// ////
@ -210,7 +206,7 @@ BOOLEAN AddToRingBuffer(LPSTR p)
} }
// it's a debug print and the current line is starting with ':' // it's a debug print and the current line is starting with ':'
else if(aBuffers[ulInPos][0]==':' && else if(aBuffers[ulInPos][0]==':' &&
( (*p=='<' && isdigit(*(p+1)) && *(p+2)=='>') || bIsDebugPrint) ) ( (*p=='<' && PICE_isdigit(*(p+1)) && *(p+2)=='>') || bIsDebugPrint) )
{ {
if(j==1) if(j==1)
{ {
@ -232,7 +228,7 @@ BOOLEAN AddToRingBuffer(LPSTR p)
j = 0; j = 0;
} }
// it's a debug print // it's a debug print
else if(( (*p=='<' && isdigit(*(p+1)) && *(p+2)=='>') || bIsDebugPrint) ) else if(( (*p=='<' && PICE_isdigit(*(p+1)) && *(p+2)=='>') || bIsDebugPrint) )
{ {
p += 3; p += 3;
} }
@ -1017,7 +1013,7 @@ void ConsoleShutdown(void)
ENTER_FUNC(); ENTER_FUNC();
// sleep for a few seconds // sleep for a few seconds
__udelay(1000*5000); Sleep(1000*5000);
switch(eTerminalMode) switch(eTerminalMode)
{ {

View file

@ -34,10 +34,6 @@ Copyright notice:
//// ////
#include "remods.h" #include "remods.h"
#include "precomp.h" #include "precomp.h"
#include <linux/pci.h>
#include <asm/io.h>
#include <asm/delay.h>
#include <linux/ctype.h>
#include "charset.h" #include "charset.h"
#include "logo.h" #include "logo.h"
@ -373,7 +369,7 @@ void PrintCursorHercules(BOOLEAN bForce)
count=0; count=0;
} }
__udelay(2500); KeStallExecutionProcessor(2500);
} }
//************************************************************************* //*************************************************************************

View file

@ -35,8 +35,6 @@ Copyright notice:
#include "remods.h" #include "remods.h"
#include "precomp.h" #include "precomp.h"
#include <asm/io.h>
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
// PROTOTYPES // PROTOTYPES
//// ////

View file

@ -35,11 +35,6 @@ Copyright notice:
#include "remods.h" #include "remods.h"
#include "precomp.h" #include "precomp.h"
#include <linux/fs.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include <asm/delay.h>
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
// GLOBALS // GLOBALS
ULONG ulDoInitialBreak=1; ULONG ulDoInitialBreak=1;
@ -49,6 +44,9 @@ char tempInit[256];
PDIRECTORY_OBJECT *pNameSpaceRoot = NULL; PDIRECTORY_OBJECT *pNameSpaceRoot = NULL;
PDEBUG_MODULE pdebug_module_tail = NULL; PDEBUG_MODULE pdebug_module_tail = NULL;
PDEBUG_MODULE pdebug_module_head = NULL; PDEBUG_MODULE pdebug_module_head = NULL;
PMADDRESS_SPACE mm_init_mm;
ULONG KeyboardIRQL;
//************************************************************************* //*************************************************************************
// InitPICE() // InitPICE()
@ -58,9 +56,20 @@ BOOLEAN InitPICE(void)
{ {
ULONG ulHandleScancode=0,ulHandleKbdEvent=0; ULONG ulHandleScancode=0,ulHandleKbdEvent=0;
ARGS Args; ARGS Args;
KIRQL Dirql;
KAFFINITY Affinity;
ENTER_FUNC(); ENTER_FUNC();
DPRINT((0,"InitPICE(): trace step 0.5\n"));
KeyboardIRQL = HalGetInterruptVector(Internal,
0,
0,
KEYBOARD_IRQ,
&Dirql,
&Affinity);
DPRINT((0,"KeyboardIRQL: %x\n", KeyboardIRQL));
DPRINT((0,"InitPICE(): trace step 1\n")); DPRINT((0,"InitPICE(): trace step 1\n"));
// enable monochrome passthrough on BX type chipset // enable monochrome passthrough on BX type chipset
EnablePassThrough(); EnablePassThrough();
@ -103,8 +112,8 @@ BOOLEAN InitPICE(void)
} }
DPRINT((0,"InitPICE(): trace step 6\n")); DPRINT((0,"InitPICE(): trace step 6\n"));
// get kernel mm_struct
my_init_mm = GetInitMm(); ScanExport(_KernelAddressSpace,(PULONG)&mm_init_mm);
if(!my_init_mm) if(!my_init_mm)
{ {
Print(OUTPUT_WINDOW,"pICE: ABORT (initial memory map not found)\n"); Print(OUTPUT_WINDOW,"pICE: ABORT (initial memory map not found)\n");
@ -117,6 +126,21 @@ BOOLEAN InitPICE(void)
} }
DPRINT((0,"init_mm @ %X\n",my_init_mm)); DPRINT((0,"init_mm @ %X\n",my_init_mm));
DPRINT((0,"InitPICE(): trace step 6.1\n"));
ScanExport(_PsProcessListHead,(PULONG)&pPsProcessListHead);
if(!pPsProcessListHead)
{
Print(OUTPUT_WINDOW,"pICE: ABORT (PsProcessListHead not found)\n");
Print(OUTPUT_WINDOW,"pICE: press any key to continue...\n");
while(!GetKeyPolled());
UnloadSymbols();
ConsoleShutdown();
LEAVE_FUNC();
return FALSE;
}
DPRINT((0,"PsProcessListHead @ %X\n",pPsProcessListHead));
DPRINT((0,"InitPICE(): trace step 7\n")); DPRINT((0,"InitPICE(): trace step 7\n"));
// load the file /boot/System.map. // load the file /boot/System.map.
// !!! It must be consistent with the current kernel at all cost!!! // !!! It must be consistent with the current kernel at all cost!!!
@ -133,6 +157,7 @@ BOOLEAN InitPICE(void)
DPRINT((0,"InitPICE(): trace step 8\n")); DPRINT((0,"InitPICE(): trace step 8\n"));
// end of the kernel // end of the kernel
/*
ScanExports("_end",(PULONG)&kernel_end); ScanExports("_end",(PULONG)&kernel_end);
if(!kernel_end) if(!kernel_end)
{ {
@ -145,6 +170,7 @@ BOOLEAN InitPICE(void)
LEAVE_FUNC(); LEAVE_FUNC();
return FALSE; return FALSE;
} }
*/
DPRINT((0,"InitPICE(): trace step 9\n")); DPRINT((0,"InitPICE(): trace step 9\n"));

View file

@ -129,6 +129,7 @@ void PrintkCallback(void)
LPSTR fmt,args; LPSTR fmt,args;
ULONG ulAddress; ULONG ulAddress;
ULONG countArgs,i,len; ULONG countArgs,i,len;
PANSI_STRING temp;
bInPrintk = TRUE; bInPrintk = TRUE;
@ -138,7 +139,9 @@ void PrintkCallback(void)
{ {
if(IsAddressValid(ulAddress+sizeof(char *)) ) if(IsAddressValid(ulAddress+sizeof(char *)) )
{ {
fmt = (LPSTR)*(PULONG)(ulAddress+sizeof(char *)); //KdpPrintString has PANSI_STRING as a parameter
temp = (PANSI_STRING)*(PULONG)(ulAddress+sizeof(char *));
fmt = temp->Buffer;
// validate format string // validate format string
if((len = PICE_strlen(fmt)) ) if((len = PICE_strlen(fmt)) )
@ -222,7 +225,7 @@ void InitPiceRunningTimer(void)
LARGE_INTEGER Interval; LARGE_INTEGER Interval;
ENTER_FUNC(); ENTER_FUNC();
ÿÿ #if 0 //won't work. we have to intercept timer interrupt so dpc will never fire while we are in pice
KeInitializeTimer( &PiceTimer ); KeInitializeTimer( &PiceTimer );
KeInitializeDpc( &PiceTimerDPC, PiceRunningTimer, NULL ); KeInitializeDpc( &PiceTimerDPC, PiceRunningTimer, NULL );
@ -231,6 +234,7 @@ void InitPiceRunningTimer(void)
KeSetTimerEx(&PiceTimer, KeSetTimerEx(&PiceTimer,
Interval, 1000000L, Interval, 1000000L,
&PiceTimerDpc); &PiceTimerDpc);
#endif
LEAVE_FUNC(); LEAVE_FUNC();
} }
@ -254,7 +258,7 @@ void InstallPrintkHook(void)
ScanExports("_KdpPrintString",(PULONG)&ulPrintk); ScanExports("_KdpPrintString",(PULONG)&ulPrintk);
ASSERT( ulPrintk ); // temporary assert( ulPrintk ); // temporary
if(ulPrintk) if(ulPrintk)
{ {

View file

@ -36,14 +36,6 @@ Copyright notice:
#include "precomp.h" #include "precomp.h"
#include "pci_ids.h" #include "pci_ids.h"
#include <linux/sched.h>
#include <asm/io.h>
#include <asm/page.h>
#include <asm/pgtable.h>
#include <linux/utsname.h>
#include <linux/timer.h>
#include <linux/ctype.h>
/////////////////////////////////////////////////// ///////////////////////////////////////////////////
// GLOBALS // GLOBALS
@ -56,7 +48,7 @@ USHORT usOldDisasmSegment = 0;
ULONG ulOldDisasmOffset = 0; ULONG ulOldDisasmOffset = 0;
static ULONG ulCountForWaitKey = 0; static ULONG ulCountForWaitKey = 0;
extern unsigned long sys_call_table[]; //extern unsigned long sys_call_table[];
BOOLEAN (*DisplayMemory)(PARGS) = DisplayMemoryDword; BOOLEAN (*DisplayMemory)(PARGS) = DisplayMemoryDword;
@ -905,35 +897,17 @@ COMMAND_PROTOTYPE(ShowPageDirs)
{ {
ULONG i; ULONG i;
PPAGEDIR pPageDir; PPAGEDIR pPageDir;
pgd_t * pPGD; PULONG pPGD;
pmd_t * pPMD; PULONG pPTE;
pte_t * pPTE; PEPROCESS my_current = IoGetCurrentProcess();
struct mm_struct* mm;
struct task_struct* my_current = (struct task_struct*)0xFFFFE000;
ENTER_FUNC(); ENTER_FUNC();
// get current process pointer
(ULONG)my_current &= ulRealStackPtr;
DPRINT((0,"ShowPageDirs(): my_current = %.8X\n",(ULONG)my_current)); DPRINT((0,"ShowPageDirs(): my_current = %.8X\n",(ULONG)my_current));
// don't touch if not valid process // don't touch if not valid process
if(my_current) if(my_current)
{ {
if(my_current->mm)
{
pPageDir = (PPAGEDIR)pgd_offset(my_current->mm,0);
mm = my_current->mm;
DPRINT((0,"ShowPageDirs(): (1) pPageDir = %.8X\n",(ULONG)pPageDir));
}
else
{
mm = my_init_mm;
pPageDir = (PPAGEDIR)my_init_mm->pgd;
DPRINT((0,"ShowPageDirs(): (2) pPageDir = %.8X\n",(ULONG)pPageDir));
}
// no arguments supplied -> show all page directories // no arguments supplied -> show all page directories
if(!pArgs->Count) if(!pArgs->Count)
{ {
@ -943,13 +917,13 @@ COMMAND_PROTOTYPE(ShowPageDirs)
{ {
ULONG ulAddress = i<<22; ULONG ulAddress = i<<22;
// from the mm_struct get pointer to page directory for this address // from the mm_struct get pointer to page directory for this address
pPGD = pgd_offset(mm,ulAddress); pPGD = ADDR_TO_PDE(ulAddress);
if(pPGD)
{
// create a structurized pointer from PGD // create a structurized pointer from PGD
pPageDir = (PPAGEDIR)pPGD; pPageDir = (PPAGEDIR)pPGD;
if(pPageDir->PTBase)
{
PICE_sprintf(tempCmd,"%.8X-%.8X %.8X %s %s %s\n", PICE_sprintf(tempCmd,"%.8X-%.8X %.8X %s %s %s\n",
ulAddress, ulAddress + 0x400000, ulAddress, ulAddress + 0x400000,
(pPageDir->PTBase<<12), (pPageDir->PTBase<<12),
@ -962,18 +936,19 @@ COMMAND_PROTOTYPE(ShowPageDirs)
} }
} }
} }
// one arg supplied -> show individual page // one arg supplied -> show individual page
else if(pArgs->Count == 1) else if(pArgs->Count == 1)
{ {
pPGD = pgd_offset(mm,pArgs->Value[0]); pPGD = (ULONG)PAGEDIRECTORY_MAP+(((ULONG)pArgs->Value[0] / (1024 * 1024))&(~0x3));
DPRINT((0,"ShowPageDirs(): VA = %.8X\n",pArgs->Value[0])); DPRINT((0,"ShowPageDirs(): VA = %.8X\n",pArgs->Value[0]));
DPRINT((0,"ShowPageDirs(): pPGD = %.8X\n",(ULONG)pPGD)); DPRINT((0,"ShowPageDirs(): pPGD = %.8X\n",(ULONG)pPGD));
if(pPGD && pgd_val(*pPGD)&_PAGE_PRESENT) if(pPGD && ((*pPGD)&_PAGE_PRESENT))
{ {
// 4M page // 4M page
if(pgd_val(*pPGD)&_PAGE_4M) if((*pPGD)&_PAGE_4M)
{ {
PPAGEDIR pPage = (PPAGEDIR)pPGD; PPAGEDIR pPage = (PPAGEDIR)pPGD;
@ -989,15 +964,11 @@ COMMAND_PROTOTYPE(ShowPageDirs)
} }
else else
{ {
pPMD = pmd_offset(pPGD,pArgs->Value[0]); pPTE = ADDR_TO_PTE(pArgs->Value[0]);
DPRINT((0,"ShowPageDirs(): pPMD = %.8X\n",(ULONG)pPMD));
pPTE = pte_offset(pPMD,pArgs->Value[0]);
DPRINT((0,"ShowPageDirs(): pPTE = %.8X\n",(ULONG)pPTE)); DPRINT((0,"ShowPageDirs(): pPTE = %.8X\n",(ULONG)pPTE));
if(pPTE) if(pPTE)
{ {
PPAGEDIR pPage = (PPAGEDIR)pPTE; PPAGEDIR pPage = (PPAGEDIR)pPTE;
DPRINT((0,"ShowPageDirs(): pte_val = %.8X\n",(ULONG)pte_val(*pPTE)));
DPRINT((0,"ShowPageDirs(): pPage->PTBase = %.8X\n",(ULONG)pPage->PTBase)); DPRINT((0,"ShowPageDirs(): pPage->PTBase = %.8X\n",(ULONG)pPage->PTBase));
PutStatusText("Linear Physical Attributes"); PutStatusText("Linear Physical Attributes");
@ -1031,33 +1002,32 @@ COMMAND_PROTOTYPE(ShowPageDirs)
//************************************************************************* //*************************************************************************
COMMAND_PROTOTYPE(ShowProcesses) COMMAND_PROTOTYPE(ShowProcesses)
{ {
struct task_struct* p; PEPROCESS my_current = IoGetCurrentProcess();
struct task_struct* my_current = (struct task_struct*)0xFFFFE000; PLIST_ENTRY current_entry;
ULONG i; PEPROCESS currentps;
\
(ULONG)my_current &= ulRealStackPtr;
ENTER_FUNC(); ENTER_FUNC();
if(my_current) current_entry = pPsProcessListHead->Flink;
{
DPRINT((0,"current = %x current->prev_task = %x current->next_task = %x\n", if( current_entry ){
my_current,
my_current->prev_task,
my_current->next_task));
PutStatusText("NAME TASK PID"); PutStatusText("NAME TASK PID");
for(i=0,p = my_current; (p = p->next_task) != my_current;i++) while( current_entry != pPsProcessListHead ){
{ currentps = CONTAINING_RECORD(current_entry,
DPRINT((0,"p = %x\n",p)); EPROCESS,
PICE_sprintf(tempCmd,"%-16.16s %-12x %x\n",(LPSTR)&(p->comm),(ULONG)p,p->pid); ProcessListEntry);
DPRINT((0,"currentps = %x\n",currentps));
//ei would be nice to mark current process!
PICE_sprintf(tempCmd,"%-16.16s %-12x %x\n",currentps->ImageFileName,
(ULONG)currentps,currentps->UniqueProcessId);
Print(OUTPUT_WINDOW,tempCmd); Print(OUTPUT_WINDOW,tempCmd);
if(WaitForKey()==FALSE) if(WaitForKey()==FALSE)
break; break;
current_entry = current_entry->Flink;
} }
} }
LEAVE_FUNC(); LEAVE_FUNC();
return TRUE; return TRUE;
} }
@ -1904,6 +1874,7 @@ COMMAND_PROTOTYPE(ShowModules)
// DecodeVmFlags() // DecodeVmFlags()
// //
//************************************************************************* //*************************************************************************
//ei FIX THIS!!!!!!!!!!!!!!!!!!
LPSTR DecodeVmFlags(ULONG flags) LPSTR DecodeVmFlags(ULONG flags)
{ {
ULONG i; ULONG i;
@ -1961,44 +1932,48 @@ LPSTR DecodeVmFlags(ULONG flags)
//************************************************************************* //*************************************************************************
COMMAND_PROTOTYPE(ShowVirtualMemory) COMMAND_PROTOTYPE(ShowVirtualMemory)
{ {
struct task_struct* my_current = (struct task_struct*)0xFFFFE000; PEPROCESS my_current = IoGetCurrentProcess();
struct mm_struct *mm; PLIST_ENTRY current_entry;
struct vm_area_struct * vma; PMADDRESS_SPACE vma;
char filename[32]; MEMORY_AREA* current;
char filename[64];
DPRINT((0,"ShowVirtualMemory()\n")); DPRINT((0,"ShowVirtualMemory()\n"));
(ULONG)my_current &= ulRealStackPtr; vma = &(my_current->AddressSpace);
if(vma)
mm = my_current->mm;
if(mm != my_init_mm)
{ {
if(pArgs->Count == 0) if(pArgs->Count == 0)
{ {
PutStatusText("START END VMA FLAGS"); PutStatusText("START END LENGTH VMA TYPE ATTR");
for(vma = mm->mmap;vma;vma = vma->vm_next) current_entry = vma->MAreaListHead.Flink;
while (current_entry != &vma->MAreaListHead)
{ {
*filename = 0; *filename = 0;
current = CONTAINING_RECORD(current_entry,
MEMORY_AREA,
Entry);
// find the filename // find the filename
if((vma->vm_flags&VM_EXECUTABLE) && if(((current->Type == MEMORY_AREA_SECTION_VIEW_COMMIT) ||
vma->vm_file) (current->Type == MEMORY_AREA_SECTION_VIEW_RESERVE) )&&
current->Data.SectionData.Section->FileObject)
{ {
if (vma->vm_file->f_dentry) if(IsAddressValid((ULONG)current->Data.SectionData.Section->FileObject->FileName.Buffer) )
{ PICE_sprintf(filename,"%.64S",current->Data.SectionData.Section->FileObject->FileName.Buffer);
if(IsAddressValid((ULONG)vma->vm_file->f_dentry->d_iname) )
PICE_sprintf(filename,"%15s",vma->vm_file->f_dentry->d_iname);
}
} }
PICE_sprintf(tempCmd,"%.8X %.8X %.8X %s %s\n", PICE_sprintf(tempCmd,"%.8X %.8X %.8X %.8X %x %x %s\n",
(ULONG)vma->vm_start, (ULONG)current->BaseAddress,
(ULONG)vma->vm_end, (ULONG)current->BaseAddress+current->Length,
(ULONG)vma, current->Length,
DecodeVmFlags(vma->vm_flags), (ULONG)current,
current->Type, current->Attributes,//DecodeVmFlags(current->Type, current->Attributes),
filename); filename);
Print(OUTPUT_WINDOW,tempCmd); Print(OUTPUT_WINDOW,tempCmd);
if(WaitForKey()==FALSE)break; if(WaitForKey()==FALSE)break;
current_entry = current_entry->Flink;
} }
} }
} }
@ -2012,18 +1987,20 @@ COMMAND_PROTOTYPE(ShowVirtualMemory)
//************************************************************************* //*************************************************************************
COMMAND_PROTOTYPE(Ver) COMMAND_PROTOTYPE(Ver)
{ {
PICE_sprintf(tempCmd,"pICE: version %u.%u (build %u) for Linux kernel release %s\n", //ei add kernel version info??!!
PICE_sprintf(tempCmd,"pICE: version %u.%u (build %u) for Reactos\n",
PICE_MAJOR_VERSION, PICE_MAJOR_VERSION,
PICE_MINOR_VERSION, PICE_MINOR_VERSION,
PICE_BUILD, PICE_BUILD);
UTS_RELEASE);
Print(OUTPUT_WINDOW,tempCmd); Print(OUTPUT_WINDOW,tempCmd);
PICE_sprintf(tempCmd,"pICE: loaded on %s kernel release %s\n", /* PICE_sprintf(tempCmd,"pICE: loaded on %s kernel release %s\n",
system_utsname.sysname, system_utsname.sysname,
system_utsname.release); system_utsname.release);
*/
Print(OUTPUT_WINDOW,tempCmd); Print(OUTPUT_WINDOW,tempCmd);
Print(OUTPUT_WINDOW,"pICE: written by Klaus P. Gerlicher and Goran Devic\n"); Print(OUTPUT_WINDOW,"pICE: written by Klaus P. Gerlicher and Goran Devic. Ported to Reactos by Eugene Ingerman.\n");
return TRUE; return TRUE;
} }
@ -2106,7 +2083,6 @@ COMMAND_PROTOTYPE(I3here)
return TRUE; return TRUE;
} }
#ifndef LINUX
COMMAND_PROTOTYPE(I1here) COMMAND_PROTOTYPE(I1here)
{ {
if(pArgs->Count==1) if(pArgs->Count==1)
@ -2146,7 +2122,6 @@ COMMAND_PROTOTYPE(I1here)
// never gets here // never gets here
return TRUE; return TRUE;
} }
#endif // LINUX
COMMAND_PROTOTYPE(NextInstr) COMMAND_PROTOTYPE(NextInstr)
{ {
@ -2857,6 +2832,7 @@ COMMAND_PROTOTYPE(ClearScreen)
//************************************************************************* //*************************************************************************
COMMAND_PROTOTYPE(ShowMappings) COMMAND_PROTOTYPE(ShowMappings)
{ {
#if 0
ULONG ulPageDir; ULONG ulPageDir;
ULONG ulPageTable; ULONG ulPageTable;
ULONG address; ULONG address;
@ -2947,7 +2923,9 @@ COMMAND_PROTOTYPE(ShowMappings)
} }
} }
} }
#endif
PICE_sprintf(tempCmd,"Not implemented yet!\n");
Print(OUTPUT_WINDOW,tempCmd);
return TRUE; return TRUE;
} }
@ -3155,6 +3133,7 @@ COMMAND_PROTOTYPE(SetKeyboardLayout)
//************************************************************************* //*************************************************************************
COMMAND_PROTOTYPE(ShowSysCallTable) COMMAND_PROTOTYPE(ShowSysCallTable)
{ {
#if 0
LPSTR pName; LPSTR pName;
ULONG i; ULONG i;
@ -3198,7 +3177,9 @@ COMMAND_PROTOTYPE(ShowSysCallTable)
} }
LEAVE_FUNC(); LEAVE_FUNC();
#endif
PICE_sprintf(tempCmd,"Not implemented yet!\n");
Print(OUTPUT_WINDOW,tempCmd);
return TRUE; return TRUE;
} }

View file

@ -96,6 +96,7 @@ extern char szCurrentFile[256];
extern PDEBUG_MODULE pCurrentMod; extern PDEBUG_MODULE pCurrentMod;
extern PICE_SYMBOLFILE_HEADER* pCurrentSymbols; extern PICE_SYMBOLFILE_HEADER* pCurrentSymbols;
extern LONG ulCurrentlyDisplayedLineNumber; extern LONG ulCurrentlyDisplayedLineNumber;
extern LIST_ENTRY* pPsProcessListHead;
BOOLEAN AsciiToHex(LPSTR p,PULONG pValue); BOOLEAN AsciiToHex(LPSTR p,PULONG pValue);
void Parse(LPSTR pCmdLine,BOOLEAN bInvokedByFkey); void Parse(LPSTR pCmdLine,BOOLEAN bInvokedByFkey);
@ -165,3 +166,15 @@ COMMAND_PROTOTYPE(SetKeyboardLayout);
COMMAND_PROTOTYPE(ShowSysCallTable); COMMAND_PROTOTYPE(ShowSysCallTable);
COMMAND_PROTOTYPE(SetAltKey); COMMAND_PROTOTYPE(SetAltKey);
COMMAND_PROTOTYPE(ShowContext); COMMAND_PROTOTYPE(ShowContext);
//ei make sure the following correspond to ntoskrnl/mm/i386/page.c
#define PAGETABLE_MAP (0xf0000000)
#define PAGEDIRECTORY_MAP (0xf0000000 + (PAGETABLE_MAP / (1024)))
#define PAGE_SHIFT 12
#define PTRS_PER_PTE 1024
#define PAGE_SIZE (1UL << PAGE_SHIFT)
#define ADDR_TO_PAGE_TABLE(v) (((ULONG)(v)) / (4 * 1024 * 1024))
#define ADDR_TO_PDE(v) (PULONG)(PAGEDIRECTORY_MAP + \
(((ULONG)v / (1024 * 1024))&(~0x3)))
#define ADDR_TO_PTE(v) (PULONG)(PAGETABLE_MAP + ((((ULONG)v / 1024))&(~0x3)))
#define ADDR_TO_PDE_OFFSET(v) (((ULONG)v / (4 * 1024 * 1024)))

View file

@ -35,13 +35,6 @@ Copyright notice:
#include "remods.h" #include "remods.h"
#include "precomp.h" #include "precomp.h"
#include <asm/io.h>
#include <asm/page.h>
#include <asm/pgtable.h>
#include <linux/fs.h>
#include <asm/uaccess.h>
#include <asm/delay.h>
#include <linux/interrupt.h>
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
// GLOBALS // GLOBALS
@ -63,9 +56,7 @@ BOOLEAN bInPageFaultHandler = FALSE;
//************************************************************************* //*************************************************************************
ULONG HandleInDebuggerFault(FRAME* ptr,ULONG address) ULONG HandleInDebuggerFault(FRAME* ptr,ULONG address)
{ {
struct task_struct *tsk; PEPROCESS tsk;
struct mm_struct *mm;
struct mm_struct *p = NULL;
ENTER_FUNC(); ENTER_FUNC();
@ -88,10 +79,9 @@ ULONG HandleInDebuggerFault(FRAME* ptr,ULONG address)
// when we come here from DebuggerShell() we live on a different stack // when we come here from DebuggerShell() we live on a different stack
// so the current task is different as well // so the current task is different as well
tsk = (struct task_struct *)(0xFFFFE000 & ulRealStackPtr); tsk = IoGetCurrentProcess();
mm = tsk->mm;
DPRINT((0,"%.8X (%.4X:%.8X %.8X %s %s %s task=%.8X mm=%.8X)\n", DPRINT((0,"%.8X (%.4X:%.8X %.8X %s %s %s task=%.8X )\n",
address, address,
ptr->cs, ptr->cs,
ptr->eip, ptr->eip,
@ -99,8 +89,7 @@ ULONG HandleInDebuggerFault(FRAME* ptr,ULONG address)
(ptr->error_code&1)?"PLP":"NP", (ptr->error_code&1)?"PLP":"NP",
(ptr->error_code&2)?"WRITE":"READ", (ptr->error_code&2)?"WRITE":"READ",
(ptr->error_code&4)?"USER-MODE":"KERNEL-MODE", (ptr->error_code&4)?"USER-MODE":"KERNEL-MODE",
(ULONG)tsk, (ULONG)tsk);
(ULONG)mm));
if(!bInPrintk) if(!bInPrintk)
{ {
@ -111,39 +100,24 @@ ULONG HandleInDebuggerFault(FRAME* ptr,ULONG address)
DPRINT((0,"HandleInDebuggerFault(): unexpected pagefault in command handler while in PrintkCallback()!\n",address)); DPRINT((0,"HandleInDebuggerFault(): unexpected pagefault in command handler while in PrintkCallback()!\n",address));
} }
if(tsk)
if(address < TASK_SIZE)
{ {
p = mm; PULONG pPGD;
} PULONG pPTE;
else
{
p = my_init_mm;
}
if(p) pPGD = ADDR_TO_PDE(address);
{
pgd_t * pPGD;
pmd_t * pPMD;
pte_t * pPTE;
pPGD = pgd_offset(p,address); DPRINT((0,"PGD for %.8X @ %.8X = %.8X\n",address,(ULONG)pPGD,(ULONG)(*pPGD) ));
DPRINT((0,"PGD for %.8X @ %.8X = %.8X\n",address,(ULONG)pPGD,(ULONG)pgd_val(*pPGD) )); if(pPGD && (*pPGD)&_PAGE_PRESENT)
if(pPGD && pgd_val(*pPGD)&_PAGE_PRESENT)
{ {
// not large page // not large page
if(!(pgd_val(*pPGD)&_PAGE_4M)) if(!((*pPGD)&_PAGE_4M))
{ {
pPMD = pmd_offset(pPGD,address); pPTE = ADDR_TO_PTE(address);
if(pPMD)
{
pPTE = pte_offset(pPMD,address);
if(pPTE) if(pPTE)
{ {
DPRINT((0,"PTE for %.8X @ %.8X = %.8X\n",address,(ULONG)pPTE,(ULONG)pte_val(*pPTE) )); DPRINT((0,"PTE for %.8X @ %.8X = %.8X\n",address,(ULONG)pPTE,(ULONG)(*pPTE) ));
}
} }
} }
} }
@ -171,15 +145,16 @@ ULONG HandleInDebuggerFault(FRAME* ptr,ULONG address)
ULONG HandlePageFault(FRAME* ptr) ULONG HandlePageFault(FRAME* ptr)
{ {
ULONG address; ULONG address;
struct task_struct *tsk; PEPROCESS tsk;
struct mm_struct *mm; PMADDRESS_SPACE vma;
struct vm_area_struct * vma; PLIST_ENTRY current_entry;
MEMORY_AREA* current;
// get linear address of page fault // get linear address of page fault
__asm__("movl %%cr2,%0":"=r" (address)); __asm__("movl %%cr2,%0":"=r" (address));
// current process // current process
tsk = current; tsk = IoGetCurrentProcess();
// there's something terribly wrong if we get a fault in our command handler // there's something terribly wrong if we get a fault in our command handler
if(bInDebuggerShell) if(bInDebuggerShell)
@ -190,65 +165,28 @@ ULONG HandlePageFault(FRAME* ptr)
// remember error code so we can push it back on the stack // remember error code so we can push it back on the stack
error_code = ptr->error_code; error_code = ptr->error_code;
//////////////////////////////////////
// kernel page fault
// since LINUX kernel is not pageable this is death
// so call handler
if(address >= TASK_SIZE)
{
//
if(error_code & 4)
{
PICE_sprintf(tempPageFault,"pICE: kernel page fault from user-mode code (error code %x)!\n",error_code);
Print(OUTPUT_WINDOW,tempPageFault);
}
else
{
PICE_sprintf(tempPageFault,"pICE: kernel page fault from kernel-mode code (error code %x)!\n",error_code);
Print(OUTPUT_WINDOW,tempPageFault);
}
return 1;
}
// and it's memory environment
mm = tsk->mm;
//////////////////////////////////////
// user page fault
// fault address is below TASK_SIZE
// no user context, i.e. no pages below TASK_SIZE are mapped
if(mm == my_init_mm)
{
Print(OUTPUT_WINDOW,"pICE: there's no user context!\n");
return 1;
}
// interrupt handlers can't have page faults // interrupt handlers can't have page faults
/*
if(in_interrupt()) if(in_interrupt())
{ {
Print(OUTPUT_WINDOW,"pICE: system is currently processing an interrupt!\n"); Print(OUTPUT_WINDOW,"pICE: system is currently processing an interrupt!\n");
return 1; return 1;
} }
*/
// lookup VMA for this address // lookup VMA for this address
vma = find_vma(mm, address); vma = &(my_current->AddressSpace);
if(!vma) current_entry = vma->MAreaListHead.Flink;
while(current_entry != &vma->MAreaListHead)
{ {
Print(OUTPUT_WINDOW,"pICE: no virtual memory arena at this address!\n"); current = CONTAINING_RECORD(current_entry,
return 1; MEMORY_AREA,
} Entry);
if( (address >= current->BaseAddress) && (address <= current->BaseAddress + current->Length ))
// address is greater than the start of this VMA
if (address >= vma->vm_start)
{ {
// WRITE ACCESS
// write bit set in error_code
if(error_code & 2) if(error_code & 2)
{ {
// area was not writable // area was not writable
if(!(vma->vm_flags & VM_WRITE)) if(!(current->Attributes & PAGE_READONLY))
{ {
Print(OUTPUT_WINDOW,"pICE: virtual memory arena is not writeable!\n"); Print(OUTPUT_WINDOW,"pICE: virtual memory arena is not writeable!\n");
return 1; return 1;
@ -264,7 +202,7 @@ ULONG HandlePageFault(FRAME* ptr)
return 1; return 1;
} }
// //
if (!(vma->vm_flags & (VM_READ | VM_EXEC))) if (!(current->Attributes & PAGE_EXECUTE_READ))
{ {
Print(OUTPUT_WINDOW,"pICE: VMA is not readable!\n"); Print(OUTPUT_WINDOW,"pICE: VMA is not readable!\n");
return 1; return 1;
@ -273,16 +211,14 @@ ULONG HandlePageFault(FRAME* ptr)
// let the system handle it // let the system handle it
return 0; return 0;
} }
current_entry = current_entry->Flink;
//
if (!(vma->vm_flags & VM_GROWSDOWN))
{
Print(OUTPUT_WINDOW,"pICE: virtual memory arena doesn't grow down!\n");
return 1;
} }
Print(OUTPUT_WINDOW,"pICE: no virtual memory arena at this address!\n");
return 1;
// let the system handle it // let the system handle it
return 0; // return 0;
} }
//************************************************************************* //*************************************************************************

View file

@ -30,7 +30,6 @@ Copyright notice:
--*/ --*/
#include "remods.h" #include "remods.h"
#include <asm/io.h>
#include "precomp.h" #include "precomp.h"
#include "serial_port.h" #include "serial_port.h"

View file

@ -36,8 +36,6 @@ Copyright notice:
//// ////
#include "remods.h" #include "remods.h"
#include "precomp.h" #include "precomp.h"
#include <asm/io.h>
#include <linux/interrupt.h>
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
@ -135,6 +133,9 @@ char aszCommandLines[LINES_IN_COMMAND_BUFFER][sizeof(ucCommandBuffer)+2];
ULONG ulCommandInPos=0,ulCommandLastPos=0; ULONG ulCommandInPos=0,ulCommandLastPos=0;
ULONG ulCommandCurrentPos=0; ULONG ulCommandCurrentPos=0;
extern ULONG KeyboardIRQL;
//************************************************************************* //*************************************************************************
// GetLinesInCommandHistory() // GetLinesInCommandHistory()
// //
@ -214,13 +215,11 @@ LPSTR GetFromCommandLineHistory(ULONG ulCurrentCommandPos)
//************************************************************************* //*************************************************************************
void ShowStatusLine(void) void ShowStatusLine(void)
{ {
struct task_struct* pCurrentProcess; PEPROCESS pCurrentProcess = IoGetCurrentProcess();
LPSTR pProcessName; LPSTR pProcessName;
ENTER_FUNC(); ENTER_FUNC();
pCurrentProcess = (struct task_struct*)(0xFFFFE000&ulRealStackPtr);
if(IsAddressValid((ULONG)pCurrentProcess)) if(IsAddressValid((ULONG)pCurrentProcess))
{ {
SetForegroundColor(COLOR_TEXT); SetForegroundColor(COLOR_TEXT);
@ -228,7 +227,7 @@ void ShowStatusLine(void)
ClrLine(wWindow[OUTPUT_WINDOW].y-1); ClrLine(wWindow[OUTPUT_WINDOW].y-1);
pProcessName = pCurrentProcess->comm; pProcessName = pCurrentProcess->ImageFileName;
if(IsAddressValid((ULONG)pProcessName) ) if(IsAddressValid((ULONG)pProcessName) )
{ {
PICE_sprintf(tempShell, PICE_sprintf(tempShell,
@ -309,7 +308,7 @@ void DebuggerShell(void)
{ {
ARGS Args; ARGS Args;
UCHAR speaker; UCHAR speaker;
struct task_struct* pCurrentProcess; PEPROCESS pCurrentProcess;
ENTER_FUNC(); ENTER_FUNC();
@ -351,7 +350,7 @@ void DebuggerShell(void)
Unassemble(&Args); Unassemble(&Args);
// try to find current process's name // try to find current process's name
pCurrentProcess = (struct task_struct*)(0xFFFFE000&ulRealStackPtr); pCurrentProcess = = IoGetCurrentProcess();
CurrentProcess = (ULONG)pCurrentProcess; CurrentProcess = (ULONG)pCurrentProcess;
// display status line // display status line
@ -1255,17 +1254,18 @@ void RealIsr(ULONG dwReasonForBreak)
else else
{ {
LPSTR pFind; LPSTR pFind;
struct task_struct* my_current = (struct task_struct*)0xFFFFE000; PEPROCESS my_current = IoGetCurrentProcess();
(ULONG)my_current &= ulRealStackPtr;
// if no other debugger is running on this process and the address is // if no other debugger is running on this process and the address is
// above TASK_SIZE we assume this to be a hard embedded INT3 // above TASK_SIZE we assume this to be a hard embedded INT3
/*
#if REAL_LINUX_VERSION_CODE < 0x020400 #if REAL_LINUX_VERSION_CODE < 0x020400
if(ulAddress<TASK_SIZE && !(my_current->flags & PF_PTRACED) ) if(ulAddress<TASK_SIZE && !(my_current->flags & PF_PTRACED) )
#else #else
if(ulAddress<TASK_SIZE && !(my_current->ptrace & PT_PTRACED) ) if(ulAddress<TASK_SIZE && !(my_current->ptrace & PT_PTRACED) )
#endif #endif
*/
if( ulAddress )
{ {
if(ScanExportsByAddress(&pFind,GetLinearAddress(CurrentCS,CurrentEIP))) if(ScanExportsByAddress(&pFind,GetLinearAddress(CurrentCS,CurrentEIP)))
{ {
@ -1280,6 +1280,7 @@ void RealIsr(ULONG dwReasonForBreak)
} }
// well someone is already debugging this, we must pass the INT3 on to old handler // well someone is already debugging this, we must pass the INT3 on to old handler
// but only when it's a user-mode address // but only when it's a user-mode address
/*
else else
{ {
if(ulAddress<TASK_SIZE || !bInt3Here) if(ulAddress<TASK_SIZE || !bInt3Here)
@ -1306,6 +1307,7 @@ void RealIsr(ULONG dwReasonForBreak)
CurrentEFL &= ~(1<<16); // clear resume flag CurrentEFL &= ~(1<<16); // clear resume flag
} }
} }
*/
// skip INT3 // skip INT3
CurrentEIP++; CurrentEIP++;
} }
@ -1637,7 +1639,7 @@ void InstallGlobalKeyboardHook(void)
:"=r" (LocalNewGlobalInt31Handler) :"=r" (LocalNewGlobalInt31Handler)
: :
:"eax"); :"eax");
OldGlobalInt31Handler=SetGlobalInt(0x21,(ULONG)LocalNewGlobalInt31Handler); OldGlobalInt31Handler=SetGlobalInt(KeyboardIRQL,(ULONG)LocalNewGlobalInt31Handler);
} }
UnmaskIrqs(); UnmaskIrqs();
@ -1651,7 +1653,7 @@ void DeInstallGlobalKeyboardHook(void)
MaskIrqs(); MaskIrqs();
if(OldGlobalInt31Handler) if(OldGlobalInt31Handler)
{ {
SetGlobalInt(0x21,(ULONG)OldGlobalInt31Handler); SetGlobalInt(KeyboardIRQL,(ULONG)OldGlobalInt31Handler);
OldGlobalInt31Handler=0; OldGlobalInt31Handler=0;
} }
UnmaskIrqs(); UnmaskIrqs();

View file

@ -91,3 +91,5 @@ void ShowStatusLine(void);
#define USA (0) #define USA (0)
#define GERMANY (1) #define GERMANY (1)
extern UCHAR ucKeyboardLayout; extern UCHAR ucKeyboardLayout;
#define KEYBOARD_IRQ 1

View file

@ -2335,7 +2335,7 @@ BOOLEAN FindGlobalStabSymbol(LPSTR pExpression,PULONG pValue,PULONG pulTypeNumbe
//************************************************************************* //*************************************************************************
void ExtractToken(LPSTR pStringToken) void ExtractToken(LPSTR pStringToken)
{ {
while(isalpha(pExpression[ulIndex]) || isdigit(pExpression[ulIndex]) || pExpression[ulIndex]=='_') while(isalpha(pExpression[ulIndex]) || PICE_isdigit(pExpression[ulIndex]) || pExpression[ulIndex]=='_')
{ {
*pStringToken++=pExpression[ulIndex++]; *pStringToken++=pExpression[ulIndex++];
*pStringToken=0; *pStringToken=0;
@ -2406,7 +2406,7 @@ LONG ExtractNumber(LPSTR p)
return 0; return 0;
} }
while(isdigit(*p)) while(PICE_isdigit(*p))
{ {
lNumber *= lBase; lNumber *= lBase;
lNumber += *p-'0'; lNumber += *p-'0';
@ -2717,7 +2717,7 @@ BOOLEAN EvaluateSymbol(PVRET pvr,LPSTR pToken)
DPRINT((0,"%x struct size = %x\n",pvr->type,lLowerRange)); DPRINT((0,"%x struct size = %x\n",pvr->type,lLowerRange));
// skip over the digits // skip over the digits
while(isdigit(*pTypeBase)) while(PICE_isdigit(*pTypeBase))
pTypeBase++; pTypeBase++;
// the structs address is is value // the structs address is is value

View file

@ -33,14 +33,6 @@ Copyright notice:
#include "remods.h" #include "remods.h"
#include "precomp.h" #include "precomp.h"
#include <linux/sched.h>
#include <asm/io.h>
#include <asm/page.h>
#include <asm/pgtable.h>
#include <linux/utsname.h>
#include <linux/sched.h>
#include <asm/unistd.h>
char syscallTemp[1024]; char syscallTemp[1024];
typedef struct _FRAME_SYSCALL typedef struct _FRAME_SYSCALL
@ -75,10 +67,11 @@ void other_module_cleanup_module(void)
RevirtualizeBreakpointsForModule(pModJustFreed); RevirtualizeBreakpointsForModule(pModJustFreed);
} }
} }
#error fix that
void CSyscallHandler(FRAME_SYSCALL* ptr,ULONG ulSysCall,ULONG ebx) void CSyscallHandler(FRAME_SYSCALL* ptr,ULONG ulSysCall,ULONG ebx)
{ {
// DPRINT((0,"CSyscallHandler(): %.4X:%.8X (syscall = %u)\n",ptr->cs,ptr->eip,ulSysCall)); // DPRINT((0,"CSyscallHandler(): %.4X:%.8X (syscall = %u)\n",ptr->cs,ptr->eip,ulSysCall));
/*
switch(ulSysCall) switch(ulSysCall)
{ {
case 1: // sys_exit case 1: // sys_exit
@ -160,6 +153,7 @@ void CSyscallHandler(FRAME_SYSCALL* ptr,ULONG ulSysCall,ULONG ebx)
} }
break; break;
} }
*/
} }
__asm__ (" __asm__ ("
@ -202,7 +196,7 @@ void InstallSyscallHook(void)
ULONG LocalSyscallHandler; ULONG LocalSyscallHandler;
ENTER_FUNC(); ENTER_FUNC();
/*ei fix later
MaskIrqs(); MaskIrqs();
if(!OldSyscallHandler) if(!OldSyscallHandler)
{ {
@ -210,28 +204,28 @@ void InstallSyscallHook(void)
:"=r" (LocalSyscallHandler) :"=r" (LocalSyscallHandler)
: :
:"eax"); :"eax");
OldSyscallHandler=SetGlobalInt(0x80,(ULONG)LocalSyscallHandler); OldSyscallHandler=SetGlobalInt(0x2e,(ULONG)LocalSyscallHandler);
ScanExports("free_module",(PULONG)&ulFreeModule); ScanExports("free_module",(PULONG)&ulFreeModule);
DPRINT((0,"InstallSyscallHook(): free_module @ %x\n",ulFreeModule)); DPRINT((0,"InstallSyscallHook(): free_module @ %x\n",ulFreeModule));
} }
UnmaskIrqs(); UnmaskIrqs();
*/
LEAVE_FUNC(); LEAVE_FUNC();
} }
void DeInstallSyscallHook(void) void DeInstallSyscallHook(void)
{ {
ENTER_FUNC(); ENTER_FUNC();
/*ei
MaskIrqs(); MaskIrqs();
if(OldSyscallHandler) if(OldSyscallHandler)
{ {
SetGlobalInt(0x80,(ULONG)OldSyscallHandler); SetGlobalInt(0x2e,(ULONG)OldSyscallHandler);
(ULONG)OldSyscallHandler=0; (ULONG)OldSyscallHandler=0;
} }
UnmaskIrqs(); UnmaskIrqs();
*/
LEAVE_FUNC(); LEAVE_FUNC();
} }

View file

@ -32,16 +32,6 @@ Copyright notice:
//// ////
#include "remods.h" #include "remods.h"
#include "precomp.h" #include "precomp.h"
#include <asm/io.h>
#include <asm/page.h>
#include <asm/pgtable.h>
#include <linux/fs.h>
#include <asm/uaccess.h>
#include <asm/delay.h>
#include <linux/types.h>
#include <linux/string.h>
#include <linux/ctype.h>
#include <defines.h> #include <defines.h>
@ -52,8 +42,7 @@ Copyright notice:
char tempUtil[1024]; char tempUtil[1024];
char tempFlowChanges[256]; char tempFlowChanges[256];
struct mm_struct* my_init_mm=(struct mm_struct*)NULL; //PMADDRESS_SPACE my_init_mm=NULL;
struct module **pmodule_list=NULL;
ULONG TwoPagesForPhysMem[2*PAGE_SIZE]; ULONG TwoPagesForPhysMem[2*PAGE_SIZE];
@ -243,6 +232,21 @@ char PICE_toupper(char c)
return c; return c;
} }
int PICE_isdigit( int c )
{
return ((c>=0x30) && (c<=0x39));
}
int PICE_isxdigit( int c )
{
return (PICE_isdigit(c) || ((c>=0x41) && (c<=0x46)) || ((c>=0x61) && (c<=0x66)));
}
int PICE_islower( int c )
{
return ((c>=0x61) && (c<=0x7a));
}
//************************************************************************* //*************************************************************************
// PICE_strncmpi() // PICE_strncmpi()
// //
@ -401,46 +405,25 @@ ULONG j;
//************************************************************************* //*************************************************************************
BOOLEAN IsAddressValid(ULONG address) BOOLEAN IsAddressValid(ULONG address)
{ {
pgd_t * pPGD; PULONG pPGD;
pmd_t * pPMD; PULONG pPTE;
pte_t * pPTE;
BOOLEAN bResult = FALSE; BOOLEAN bResult = FALSE;
struct mm_struct* p = NULL; PEPROCESS my_current = IoGetCurrentProcess();
struct task_struct* my_current = (struct task_struct*)0xFFFFE000;
address &= (~(PAGE_SIZE-1)); address &= (~(PAGE_SIZE-1));
// if we're in DebuggerShell() we live on a different stack if(my_current)
if(bInDebuggerShell)
(ULONG)my_current &= ulRealStackPtr;
else
my_current = current;
if(address < TASK_SIZE)
{ {
p = my_current->mm; pPGD = ADDR_TO_PDE(address);
} if(pPGD && ((*pPGD)&_PAGE_PRESENT))
else
{
p = my_init_mm;
}
if(p)
{
pPGD = pgd_offset(p,address);
if(pPGD && pgd_val(*pPGD)&_PAGE_PRESENT)
{ {
// not large page // not large page
if(!(pgd_val(*pPGD)&_PAGE_4M)) if(!((*pPGD)&_PAGE_4M))
{ {
pPMD = pmd_offset(pPGD,address); pPTE = ADDR_TO_PTE(address);
if(pPMD)
{
pPTE = pte_offset(pPMD,address);
if(pPTE) if(pPTE)
{ {
bResult = pte_present(*pPTE); bResult = (*pPTE)&(_PAGE_PRESENT | _PAGE_PSE);
}
} }
} }
// large page // large page
@ -465,57 +448,34 @@ BOOLEAN IsAddressValid(ULONG address)
//************************************************************************* //*************************************************************************
BOOLEAN IsAddressWriteable(ULONG address) BOOLEAN IsAddressWriteable(ULONG address)
{ {
pgd_t * pPGD; PULONG pPGD;
pmd_t * pPMD; PULONG pPTE;
pte_t * pPTE;
BOOLEAN bResult = FALSE; BOOLEAN bResult = FALSE;
struct mm_struct* p = NULL; PEPROCESS my_current = IoGetCurrentProcess();
struct task_struct* my_current = (struct task_struct*)0xFFFFE000;
address &= (~(PAGE_SIZE-1)); address &= (~(PAGE_SIZE-1));
// if we're in DebuggerShell() we live on a different stack if(my_current)
if(bInDebuggerShell)
(ULONG)my_current &= ulRealStackPtr;
else
my_current = current;
if(address < TASK_SIZE)
{ {
p = my_current->mm; pPGD = ADDR_TO_PDE(address);
} if(pPGD && ((*pPGD)&_PAGE_PRESENT))
else
{
p = my_init_mm;
}
if(p)
{
pPGD = pgd_offset(p,address);
if(pPGD && pgd_val(*pPGD)&_PAGE_PRESENT)
{ {
// not large page // not large page
if(!(pgd_val(*pPGD)&_PAGE_4M)) if(!((*pPGD)&_PAGE_4M))
{ {
bResult |= pgd_val(*pPGD) & _PAGE_RW; bResult |= (*pPGD) & _PAGE_RW;
pPMD = pmd_offset(pPGD,address); pPTE = ADDR_TO_PTE(address);
if(pPMD)
{
bResult |= pmd_val(*pPMD) & _PAGE_RW;
pPTE = pte_offset(pPMD,address);
if(pPTE) if(pPTE)
{ {
if( pte_present(*pPTE) ) if( (*pPTE)&(_PAGE_PRESENT | _PAGE_PSE) )
bResult |= pte_write(*pPTE); bResult |= (*pPTE) & _PAGE_RW;
}
} }
} }
// large page // large page
else else
{ {
bResult |= pgd_val(*pPGD) & _PAGE_RW; bResult |= (*pPGD) & _PAGE_RW;
} }
} }
} }
@ -530,62 +490,41 @@ BOOLEAN IsAddressWriteable(ULONG address)
//************************************************************************* //*************************************************************************
BOOLEAN SetAddressWriteable(ULONG address,BOOLEAN bSet) BOOLEAN SetAddressWriteable(ULONG address,BOOLEAN bSet)
{ {
pgd_t * pPGD; PULONG pPGD;
pmd_t * pPMD; PULONG pPTE;
pte_t * pPTE;
BOOLEAN bResult = FALSE; BOOLEAN bResult = FALSE;
struct mm_struct* p = NULL; PEPROCESS my_current = IoGetCurrentProcess();
struct task_struct* my_current = (struct task_struct*)0xFFFFE000;
address &= (~(PAGE_SIZE-1)); address &= (~(PAGE_SIZE-1));
// if we're in DebuggerShell() we live on a different stack if(my_current)
if(bInDebuggerShell)
(ULONG)my_current &= ulRealStackPtr;
else
my_current = current;
if(address < TASK_SIZE)
{ {
p = my_current->mm; pPGD = ADDR_TO_PDE(address);
} if(pPGD && ((*pPGD)&_PAGE_PRESENT))
else
{
p = my_init_mm;
}
if(p)
{
pPGD = pgd_offset(p,address);
if(pPGD && pgd_val(*pPGD)&_PAGE_PRESENT)
{ {
// not large page // not large page
if(!(pgd_val(*pPGD)&_PAGE_4M)) if(!((*pPGD)&_PAGE_4M))
{ {
pPMD = pmd_offset(pPGD,address); pPTE = ADDR_TO_PTE(address);
if(pPMD)
{
pPTE = pte_offset(pPMD,address);
if(pPTE) if(pPTE)
{ {
if( pte_present(*pPTE) ) if( (*pPTE)&(_PAGE_PRESENT | _PAGE_PSE) )
{ {
if( bSet ) if( bSet )
pte_mkwrite(*pPTE); *pPTE |= _PAGE_RW;
else else
pte_wrprotect(*pPTE); *pPTE &= ~_PAGE_RW;
bResult = TRUE; bResult = TRUE;
} }
} }
} }
}
// large page // large page
else else
{ {
if( bSet ) if( bSet )
pgd_val(*pPGD) |= _PAGE_RW; *pPGD |= _PAGE_RW;
else else
pgd_val(*pPGD) &= ~_PAGE_RW; *pPGD &= ~_PAGE_RW;
bResult = TRUE; bResult = TRUE;
} }
} }
@ -1320,11 +1259,13 @@ UCHAR KeyboardGetKeyPolled(void)
//************************************************************************* //*************************************************************************
void KeyboardFlushKeyboardQueue(void) void KeyboardFlushKeyboardQueue(void)
{ {
__udelay(10); //__udelay(10);
KeStallExecutionProcessor(10);
while(GetKeyStatus()&OUTPUT_BUFFER_FULL) while(GetKeyStatus()&OUTPUT_BUFFER_FULL)
{ {
GetKeyData(); GetKeyData();
__udelay(10); //__udelay(10);
KeStallExecutionProcessor(10);
} }
} }
@ -1368,7 +1309,7 @@ UCHAR ucKey;
else else
goto load; goto load;
} }
__udelay(1000); Sleep(1000);
} }
load: load:
Clear(REGISTER_WINDOW); Clear(REGISTER_WINDOW);
@ -1436,50 +1377,30 @@ void IntelStackWalk(ULONG pc,ULONG ebp,ULONG esp)
//************************************************************************* //*************************************************************************
pte_t * FindPteForLinearAddress(ULONG address) pte_t * FindPteForLinearAddress(ULONG address)
{ {
pgd_t * pPGD; PULONG pPGD;
pmd_t * pPMD; PULONG pPTE;
pte_t * pPTE; BOOLEAN bResult = FALSE;
struct mm_struct* p = NULL; PEPROCESS my_current = IoGetCurrentProcess();
struct task_struct* my_current = (struct task_struct*)0xFFFFE000;
ENTER_FUNC(); ENTER_FUNC();
address &= (~(PAGE_SIZE-1)); address &= (~(PAGE_SIZE-1));
// if we're in DebuggerShell() we live on a different stack if(my_current)
if(bInDebuggerShell)
(ULONG)my_current &= ulRealStackPtr;
else
my_current = current;
if(address < TASK_SIZE)
{ {
p = my_current->mm; pPGD = ADDR_TO_PDE(address);
} if(pPGD && ((*pPGD)&_PAGE_PRESENT))
else
{
p = my_init_mm;
}
if(p)
{
pPGD = pgd_offset(p,address);
if(pPGD && pgd_val(*pPGD)&_PAGE_PRESENT)
{ {
// not large page // not large page
if(!(pgd_val(*pPGD)&_PAGE_4M)) if(!((*pPGD)&_PAGE_4M))
{ {
pPMD = pmd_offset(pPGD,address); pPTE = ADDR_TO_PTE(address);
if(pPMD)
{
pPTE = pte_offset(pPMD,address);
if(pPTE) if(pPTE)
{ {
LEAVE_FUNC(); LEAVE_FUNC();
return pPTE; return pPTE;
} }
} }
}
// large page // large page
else else
{ {
@ -1602,14 +1523,14 @@ unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base)
if (*cp == '0') { if (*cp == '0') {
base = 8; base = 8;
cp++; cp++;
if ((*cp == 'x') && isxdigit(cp[1])) { if ((*cp == 'x') && PICE_isxdigit(cp[1])) {
cp++; cp++;
base = 16; base = 16;
} }
} }
} }
while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp) while (PICE_isxdigit(*cp) && (value = PICE_isdigit(*cp) ? *cp-'0' : (PICE_islower(*cp)
? toupper(*cp) : *cp)-'A'+10) < base) { ? PICE_toupper(*cp) : *cp)-'A'+10) < base) {
result = result*base + value; result = result*base + value;
cp++; cp++;
} }
@ -2041,7 +1962,7 @@ ULONG inl(PULONG port)
return READ_PORT_ULONG(port); return READ_PORT_ULONG(port);
} }
#if 0
//************************************************************************* //*************************************************************************
// GetInitMm() // GetInitMm()
// //
@ -2072,6 +1993,7 @@ struct mm_struct *GetInitMm(void)
return NULL; return NULL;
#endif #endif
} }
#endif
//************************************************************************* //*************************************************************************
// EnablePassThrough() // EnablePassThrough()

View file

@ -131,8 +131,6 @@ typedef struct tagPageDir
ULONG PTBase :20; ULONG PTBase :20;
}PAGEDIR,*PPAGEDIR; }PAGEDIR,*PPAGEDIR;
extern struct mm_struct* my_init_mm;
typedef struct tagGdt typedef struct tagGdt
{ {
ULONG Limit_15_0 :16; ULONG Limit_15_0 :16;
@ -168,7 +166,6 @@ typedef struct tagDESCRIPTOR
USHORT Val :13; // index into table USHORT Val :13; // index into table
}DESCRIPTOR,*PDESCRIPTOR; }DESCRIPTOR,*PDESCRIPTOR;
extern struct module **pmodule_list;
void PICE_memset(void* p,unsigned char c,int sz); void PICE_memset(void* p,unsigned char c,int sz);
void PICE_memcpy(void* t,void* s,int sz); void PICE_memcpy(void* t,void* s,int sz);
@ -182,6 +179,9 @@ BOOLEAN PICE_isprint(char c);
char* PICE_strcpy(char* s1,char* s2); char* PICE_strcpy(char* s1,char* s2);
char* PICE_strncpy(char* s1,char* s2,int len); char* PICE_strncpy(char* s1,char* s2,int len);
char* PICE_strchr(char* s,char c); char* PICE_strchr(char* s,char c);
int PICE_isdigit( int c );
int PICE_isxdigit( int c );
int PICE_islower( int c );
int PICE_sprintf(char * buf, const char *fmt, ...); int PICE_sprintf(char * buf, const char *fmt, ...);
int PICE_vsprintf(char *buf, const char *fmt, va_list args); int PICE_vsprintf(char *buf, const char *fmt, va_list args);
@ -214,8 +214,9 @@ void SetHardwareBreakPoint(ULONG ulAddress,ULONG ulReg);
BOOLEAN Disasm(PULONG pOffset, PUCHAR pchDst); BOOLEAN Disasm(PULONG pOffset, PUCHAR pchDst);
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
#define GLOBAL_CODE_SEGMENT (__KERNEL_CS) //segments defined in \include\napi\i386\segment.h
#define GLOBAL_DATA_SEGMENT (__KERNEL_DS) #define GLOBAL_CODE_SEGMENT (KERNEL_CS)
#define GLOBAL_DATA_SEGMENT (KERNEL_DS)
//#define OVR_CS .byte 0x2e //#define OVR_CS .byte 0x2e
//#define OVR_FS .byte 0x64 //#define OVR_FS .byte 0x64
@ -228,9 +229,15 @@ BOOLEAN CheckLoadAbort(void);
UCHAR KeyboardGetKeyPolled(void); UCHAR KeyboardGetKeyPolled(void);
void KeyboardFlushKeyboardQueue(void); void KeyboardFlushKeyboardQueue(void);
#if REAL_LINUX_VERSION_CODE >= 0x020400 #define _PAGE_PRESENT 0x001
#define _PAGE_RW 0x002
#define _PAGE_USER 0x004
#define _PAGE_PWT 0x008
#define _PAGE_PCD 0x010
#define _PAGE_ACCESSED 0x020
#define _PAGE_DIRTY 0x040
#define _PAGE_PSE 0x080
#define _PAGE_4M _PAGE_PSE #define _PAGE_4M _PAGE_PSE
#endif
UCHAR AsciiFromScan(UCHAR s); UCHAR AsciiFromScan(UCHAR s);
UCHAR AsciiToScan(UCHAR s); UCHAR AsciiToScan(UCHAR s);
@ -251,9 +258,12 @@ ULONG inl(PULONG port);
#define sti() __asm__ __volatile__("sti": : :"memory") #define sti() __asm__ __volatile__("sti": : :"memory")
extern unsigned long sys_call_table[]; //extern unsigned long sys_call_table[];
struct mm_struct *GetInitMm(void); //struct mm_struct *GetInitMm(void);
PEPROCESS my_init_mm;
LIST_ENTRY* pPsProcessListHead;
void EnablePassThrough(void); void EnablePassThrough(void);