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 <windows.h>
#include <ddk/kefuncs.h>
//#include <winnt.h>
#include <sys/types.h>

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -35,11 +35,6 @@ Copyright notice:
#include "remods.h"
#include "precomp.h"
#include <linux/fs.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include <asm/delay.h>
////////////////////////////////////////////////////
// GLOBALS
ULONG ulDoInitialBreak=1;
@ -49,6 +44,9 @@ char tempInit[256];
PDIRECTORY_OBJECT *pNameSpaceRoot = NULL;
PDEBUG_MODULE pdebug_module_tail = NULL;
PDEBUG_MODULE pdebug_module_head = NULL;
PMADDRESS_SPACE mm_init_mm;
ULONG KeyboardIRQL;
//*************************************************************************
// InitPICE()
@ -58,9 +56,20 @@ BOOLEAN InitPICE(void)
{
ULONG ulHandleScancode=0,ulHandleKbdEvent=0;
ARGS Args;
KIRQL Dirql;
KAFFINITY Affinity;
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"));
// enable monochrome passthrough on BX type chipset
EnablePassThrough();
@ -103,8 +112,8 @@ BOOLEAN InitPICE(void)
}
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)
{
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,"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"));
// load the file /boot/System.map.
// !!! 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"));
// end of the kernel
/*
ScanExports("_end",(PULONG)&kernel_end);
if(!kernel_end)
{
@ -145,6 +170,7 @@ BOOLEAN InitPICE(void)
LEAVE_FUNC();
return FALSE;
}
*/
DPRINT((0,"InitPICE(): trace step 9\n"));

View file

@ -129,6 +129,7 @@ void PrintkCallback(void)
LPSTR fmt,args;
ULONG ulAddress;
ULONG countArgs,i,len;
PANSI_STRING temp;
bInPrintk = TRUE;
@ -138,7 +139,9 @@ void PrintkCallback(void)
{
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
if((len = PICE_strlen(fmt)) )
@ -222,7 +225,7 @@ void InitPiceRunningTimer(void)
LARGE_INTEGER Interval;
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 );
KeInitializeDpc( &PiceTimerDPC, PiceRunningTimer, NULL );
@ -231,6 +234,7 @@ void InitPiceRunningTimer(void)
KeSetTimerEx(&PiceTimer,
Interval, 1000000L,
&PiceTimerDpc);
#endif
LEAVE_FUNC();
}
@ -254,7 +258,7 @@ void InstallPrintkHook(void)
ScanExports("_KdpPrintString",(PULONG)&ulPrintk);
ASSERT( ulPrintk ); // temporary
assert( ulPrintk ); // temporary
if(ulPrintk)
{

View file

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

View file

@ -96,6 +96,7 @@ extern char szCurrentFile[256];
extern PDEBUG_MODULE pCurrentMod;
extern PICE_SYMBOLFILE_HEADER* pCurrentSymbols;
extern LONG ulCurrentlyDisplayedLineNumber;
extern LIST_ENTRY* pPsProcessListHead;
BOOLEAN AsciiToHex(LPSTR p,PULONG pValue);
void Parse(LPSTR pCmdLine,BOOLEAN bInvokedByFkey);
@ -165,3 +166,15 @@ COMMAND_PROTOTYPE(SetKeyboardLayout);
COMMAND_PROTOTYPE(ShowSysCallTable);
COMMAND_PROTOTYPE(SetAltKey);
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 "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
@ -63,9 +56,7 @@ BOOLEAN bInPageFaultHandler = FALSE;
//*************************************************************************
ULONG HandleInDebuggerFault(FRAME* ptr,ULONG address)
{
struct task_struct *tsk;
struct mm_struct *mm;
struct mm_struct *p = NULL;
PEPROCESS tsk;
ENTER_FUNC();
@ -88,10 +79,9 @@ ULONG HandleInDebuggerFault(FRAME* ptr,ULONG address)
// when we come here from DebuggerShell() we live on a different stack
// so the current task is different as well
tsk = (struct task_struct *)(0xFFFFE000 & ulRealStackPtr);
mm = tsk->mm;
tsk = IoGetCurrentProcess();
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,
ptr->cs,
ptr->eip,
@ -99,8 +89,7 @@ ULONG HandleInDebuggerFault(FRAME* ptr,ULONG address)
(ptr->error_code&1)?"PLP":"NP",
(ptr->error_code&2)?"WRITE":"READ",
(ptr->error_code&4)?"USER-MODE":"KERNEL-MODE",
(ULONG)tsk,
(ULONG)mm));
(ULONG)tsk);
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));
}
if(address < TASK_SIZE)
if(tsk)
{
p = mm;
}
else
{
p = my_init_mm;
}
PULONG pPGD;
PULONG pPTE;
if(p)
{
pgd_t * pPGD;
pmd_t * pPMD;
pte_t * pPTE;
pPGD = ADDR_TO_PDE(address);
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 && pgd_val(*pPGD)&_PAGE_PRESENT)
if(pPGD && (*pPGD)&_PAGE_PRESENT)
{
// not large page
if(!(pgd_val(*pPGD)&_PAGE_4M))
if(!((*pPGD)&_PAGE_4M))
{
pPMD = pmd_offset(pPGD,address);
if(pPMD)
{
pPTE = pte_offset(pPMD,address);
pPTE = ADDR_TO_PTE(address);
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 address;
struct task_struct *tsk;
struct mm_struct *mm;
struct vm_area_struct * vma;
PEPROCESS tsk;
PMADDRESS_SPACE vma;
PLIST_ENTRY current_entry;
MEMORY_AREA* current;
// get linear address of page fault
__asm__("movl %%cr2,%0":"=r" (address));
// current process
tsk = current;
tsk = IoGetCurrentProcess();
// there's something terribly wrong if we get a fault in our command handler
if(bInDebuggerShell)
@ -190,65 +165,28 @@ ULONG HandlePageFault(FRAME* ptr)
// remember error code so we can push it back on the stack
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
/*
if(in_interrupt())
{
Print(OUTPUT_WINDOW,"pICE: system is currently processing an interrupt!\n");
return 1;
}
*/
// lookup VMA for this address
vma = find_vma(mm, address);
if(!vma)
vma = &(my_current->AddressSpace);
current_entry = vma->MAreaListHead.Flink;
while(current_entry != &vma->MAreaListHead)
{
Print(OUTPUT_WINDOW,"pICE: no virtual memory arena at this address!\n");
return 1;
}
// address is greater than the start of this VMA
if (address >= vma->vm_start)
current = CONTAINING_RECORD(current_entry,
MEMORY_AREA,
Entry);
if( (address >= current->BaseAddress) && (address <= current->BaseAddress + current->Length ))
{
// WRITE ACCESS
// write bit set in error_code
if(error_code & 2)
{
// 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");
return 1;
@ -264,7 +202,7 @@ ULONG HandlePageFault(FRAME* ptr)
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");
return 1;
@ -273,16 +211,14 @@ ULONG HandlePageFault(FRAME* ptr)
// let the system handle it
return 0;
}
//
if (!(vma->vm_flags & VM_GROWSDOWN))
{
Print(OUTPUT_WINDOW,"pICE: virtual memory arena doesn't grow down!\n");
return 1;
current_entry = current_entry->Flink;
}
Print(OUTPUT_WINDOW,"pICE: no virtual memory arena at this address!\n");
return 1;
// let the system handle it
return 0;
// return 0;
}
//*************************************************************************

View file

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

View file

@ -36,8 +36,6 @@ Copyright notice:
////
#include "remods.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 ulCommandCurrentPos=0;
extern ULONG KeyboardIRQL;
//*************************************************************************
// GetLinesInCommandHistory()
//
@ -214,13 +215,11 @@ LPSTR GetFromCommandLineHistory(ULONG ulCurrentCommandPos)
//*************************************************************************
void ShowStatusLine(void)
{
struct task_struct* pCurrentProcess;
PEPROCESS pCurrentProcess = IoGetCurrentProcess();
LPSTR pProcessName;
ENTER_FUNC();
pCurrentProcess = (struct task_struct*)(0xFFFFE000&ulRealStackPtr);
if(IsAddressValid((ULONG)pCurrentProcess))
{
SetForegroundColor(COLOR_TEXT);
@ -228,7 +227,7 @@ void ShowStatusLine(void)
ClrLine(wWindow[OUTPUT_WINDOW].y-1);
pProcessName = pCurrentProcess->comm;
pProcessName = pCurrentProcess->ImageFileName;
if(IsAddressValid((ULONG)pProcessName) )
{
PICE_sprintf(tempShell,
@ -309,7 +308,7 @@ void DebuggerShell(void)
{
ARGS Args;
UCHAR speaker;
struct task_struct* pCurrentProcess;
PEPROCESS pCurrentProcess;
ENTER_FUNC();
@ -351,7 +350,7 @@ void DebuggerShell(void)
Unassemble(&Args);
// try to find current process's name
pCurrentProcess = (struct task_struct*)(0xFFFFE000&ulRealStackPtr);
pCurrentProcess = = IoGetCurrentProcess();
CurrentProcess = (ULONG)pCurrentProcess;
// display status line
@ -1255,17 +1254,18 @@ void RealIsr(ULONG dwReasonForBreak)
else
{
LPSTR pFind;
struct task_struct* my_current = (struct task_struct*)0xFFFFE000;
(ULONG)my_current &= ulRealStackPtr;
PEPROCESS my_current = IoGetCurrentProcess();
// 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
/*
#if REAL_LINUX_VERSION_CODE < 0x020400
if(ulAddress<TASK_SIZE && !(my_current->flags & PF_PTRACED) )
#else
if(ulAddress<TASK_SIZE && !(my_current->ptrace & PT_PTRACED) )
#endif
*/
if( ulAddress )
{
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
// but only when it's a user-mode address
/*
else
{
if(ulAddress<TASK_SIZE || !bInt3Here)
@ -1306,6 +1307,7 @@ void RealIsr(ULONG dwReasonForBreak)
CurrentEFL &= ~(1<<16); // clear resume flag
}
}
*/
// skip INT3
CurrentEIP++;
}
@ -1637,7 +1639,7 @@ void InstallGlobalKeyboardHook(void)
:"=r" (LocalNewGlobalInt31Handler)
:
:"eax");
OldGlobalInt31Handler=SetGlobalInt(0x21,(ULONG)LocalNewGlobalInt31Handler);
OldGlobalInt31Handler=SetGlobalInt(KeyboardIRQL,(ULONG)LocalNewGlobalInt31Handler);
}
UnmaskIrqs();
@ -1651,7 +1653,7 @@ void DeInstallGlobalKeyboardHook(void)
MaskIrqs();
if(OldGlobalInt31Handler)
{
SetGlobalInt(0x21,(ULONG)OldGlobalInt31Handler);
SetGlobalInt(KeyboardIRQL,(ULONG)OldGlobalInt31Handler);
OldGlobalInt31Handler=0;
}
UnmaskIrqs();

View file

@ -91,3 +91,5 @@ void ShowStatusLine(void);
#define USA (0)
#define GERMANY (1)
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)
{
while(isalpha(pExpression[ulIndex]) || isdigit(pExpression[ulIndex]) || pExpression[ulIndex]=='_')
while(isalpha(pExpression[ulIndex]) || PICE_isdigit(pExpression[ulIndex]) || pExpression[ulIndex]=='_')
{
*pStringToken++=pExpression[ulIndex++];
*pStringToken=0;
@ -2406,7 +2406,7 @@ LONG ExtractNumber(LPSTR p)
return 0;
}
while(isdigit(*p))
while(PICE_isdigit(*p))
{
lNumber *= lBase;
lNumber += *p-'0';
@ -2717,7 +2717,7 @@ BOOLEAN EvaluateSymbol(PVRET pvr,LPSTR pToken)
DPRINT((0,"%x struct size = %x\n",pvr->type,lLowerRange));
// skip over the digits
while(isdigit(*pTypeBase))
while(PICE_isdigit(*pTypeBase))
pTypeBase++;
// the structs address is is value

View file

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

View file

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

View file

@ -131,8 +131,6 @@ typedef struct tagPageDir
ULONG PTBase :20;
}PAGEDIR,*PPAGEDIR;
extern struct mm_struct* my_init_mm;
typedef struct tagGdt
{
ULONG Limit_15_0 :16;
@ -168,7 +166,6 @@ typedef struct tagDESCRIPTOR
USHORT Val :13; // index into table
}DESCRIPTOR,*PDESCRIPTOR;
extern struct module **pmodule_list;
void PICE_memset(void* p,unsigned char c,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_strncpy(char* s1,char* s2,int len);
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_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);
//////////////////////////////////////////////////////////////////
#define GLOBAL_CODE_SEGMENT (__KERNEL_CS)
#define GLOBAL_DATA_SEGMENT (__KERNEL_DS)
//segments defined in \include\napi\i386\segment.h
#define GLOBAL_CODE_SEGMENT (KERNEL_CS)
#define GLOBAL_DATA_SEGMENT (KERNEL_DS)
//#define OVR_CS .byte 0x2e
//#define OVR_FS .byte 0x64
@ -228,9 +229,15 @@ BOOLEAN CheckLoadAbort(void);
UCHAR KeyboardGetKeyPolled(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
#endif
UCHAR AsciiFromScan(UCHAR s);
UCHAR AsciiToScan(UCHAR s);
@ -251,9 +258,12 @@ ULONG inl(PULONG port);
#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);