3 Copyright (c) 1998-2001 Klaus P. Gerlicher
11 initialisation and cleanup of debugger kernel module
24 15-Nov-2000: general cleanup of source files
28 This file may be distributed under the terms of the GNU Public License.
32 ////////////////////////////////////////////////////
38 ////////////////////////////////////////////////////
40 ULONG ulDoInitialBreak
=1;
41 char szBootParams
[1024]="";
44 PDIRECTORY_OBJECT
*pNameSpaceRoot
= NULL
;
45 PDEBUG_MODULE pdebug_module_tail
= NULL
;
46 PDEBUG_MODULE pdebug_module_head
= NULL
;
47 PMADDRESS_SPACE mm_init_mm
;
48 extern LIST_ENTRY
*pModuleListHead
;
52 extern void NewInt31Handler(void);
53 //*************************************************************************
56 //*************************************************************************
57 BOOLEAN
InitPICE(void)
59 ULONG ulHandleScancode
=0,ulHandleKbdEvent
=0;
67 DPRINT((0,"InitPICE(): trace step 0.5\n"));
68 KeyboardIRQL
= HalGetInterruptVector(Internal
,
74 DPRINT((0,"KeyboardIRQL: %x\n", KeyboardIRQL
));
76 DPRINT((0,"InitPICE(): trace step 1\n"));
77 // enable monochrome passthrough on BX type chipset
80 DPRINT((0,"InitPICE(): trace step 2\n"));
81 // now load all symbol files described in /etc/pice.conf
82 if(!LoadSymbolsFromConfig(FALSE
))
84 DPRINT((0,"InitPICE: LoadSymbolsFromConfig() failed\n"));
89 DPRINT((0,"InitPICE(): trace step 3\n"));
90 // init the output console
91 // this might be one of the following depending setup
93 // b) serial terminal (TODO)
96 DPRINT((0,"InitPICE: ConsoleInit() failed\n"));
102 DPRINT((0,"InitPICE(): trace step 4\n"));
103 // print the initial screen template
106 DPRINT((0,"InitPICE(): trace step 5\n"));
107 // ask the user if he wants to abort the debugger load
108 if(!CheckLoadAbort())
110 Print(OUTPUT_WINDOW,"pICE: ABORT (abort by user)\n");
118 DPRINT((0,"InitPICE(): trace step 6\n"));
119 // load the file /boot/System.map.
120 // !!! It must be consistent with the current kernel at all cost!!!
123 Print(OUTPUT_WINDOW
,"pICE: failed to load exports\n");
124 Print(OUTPUT_WINDOW
,"press any key to continue...\n");
125 while(!GetKeyPolled());
132 DPRINT((0,"InitPICE(): trace step 7\n"));
133 ScanExports("_KernelAddressSpace", &ulAddr
);
134 my_init_mm
= (PMADDRESS_SPACE
) ulAddr
;
135 DPRINT((0,"init_mm %x @ %x\n",&my_init_mm
,my_init_mm
));
138 Print(OUTPUT_WINDOW
,"pICE: ABORT (initial memory map not found)\n");
139 Print(OUTPUT_WINDOW
,"pICE: press any key to continue...\n");
140 DbgPrint("pICE: ABORT (initial memory map not found)\n");
141 DbgPrint("pICE: press any key to continue...\n");
142 while(!GetKeyPolled());
149 DPRINT((0,"InitPICE(): trace step 7.1\n"));
150 ScanExports("_ModuleListHead",&ulAddr
);
151 pModuleListHead
= (LIST_ENTRY
*)ulAddr
;
152 DPRINT((0,"pModuleListHead @ %X\n",pModuleListHead
));
155 Print(OUTPUT_WINDOW
,"pICE: ABORT (pModuleListHead not found)\n");
156 Print(OUTPUT_WINDOW
,"pICE: press any key to continue...\n");
157 while(!GetKeyPolled());
164 DPRINT((0,"InitPICE(): trace step 7.2\n"));
165 ScanExports("_PsProcessListHead",&ulAddr
);
166 pPsProcessListHead
= (LIST_ENTRY
*)ulAddr
;
167 DPRINT((0,"pPsProcessListHead @ %X\n",pPsProcessListHead
));
168 if(!pPsProcessListHead
)
170 Print(OUTPUT_WINDOW
,"pICE: ABORT (PsProcessListHead not found)\n");
171 Print(OUTPUT_WINDOW
,"pICE: press any key to continue...\n");
172 while(!GetKeyPolled());
179 DPRINT((0,"InitPICE(): trace step 8\n"));
182 ScanExports("_end",(PULONG)&kernel_end);
185 Print(OUTPUT_WINDOW,"pICE: ABORT (kernel size is unknown)\n");
186 Print(OUTPUT_WINDOW,"pICE: press any key to continue...\n");
187 while(!GetKeyPolled());
196 DPRINT((0,"InitPICE(): trace step 9\n"));
198 // the loaded module list
199 ScanExports("_NameSpaceRoot", &ulAddr
);
200 pNameSpaceRoot
= (PDIRECTORY_OBJECT
*)ulAddr
;
201 DPRINT((0,"pNameSpaceRoot @ %X\n",pNameSpaceRoot
));
204 Print(OUTPUT_WINDOW
,"pICE: ABORT (couldn't retreive name space root)\n");
205 Print(OUTPUT_WINDOW
,"pICE: press any key to continue...\n");
206 while(!GetKeyPolled());
214 DPRINT((0,"InitPICE(): trace step 10\n"));
215 // setup a linked list for use in module parsing routines.
216 if(!InitModuleList(&pdebug_module_head
, 100))
218 Print(OUTPUT_WINDOW
,"pICE: ABORT (couldn't initialize kernel module list)\n");
219 Print(OUTPUT_WINDOW
,"pICE: press any key to continue...\n");
220 FreeModuleList( pdebug_module_head
);
221 while(!GetKeyPolled());
228 pdebug_module_tail
= pdebug_module_head
;
230 DPRINT((0,"InitPICE(): trace step 11\n"));
231 // do a sanity check on exports
232 if(!SanityCheckExports())
234 Print(OUTPUT_WINDOW
,"pICE: ABORT (exports are conflicting with kernel symbols)\n");
235 Print(OUTPUT_WINDOW
,"pICE: press any key to continue...\n");
236 while(!GetKeyPolled());
244 DPRINT((0,"InitPICE(): trace step 12\n"));
247 DPRINT((0,"InitPICE(): trace step 13\n"));
248 // patch the keyboard driver
250 if(!PatchKeyboardDriver())
252 Print(OUTPUT_WINDOW
,"pICE: ABORT (couldn't patch keyboard driver)\n");
253 Print(OUTPUT_WINDOW
,"pICE: press any key to continue...\n");
254 while(!GetKeyPolled());
262 DPRINT((0,"InitPICE(): trace step 14\n"));
263 // partial init of shadow registers
264 CurrentCS
= GLOBAL_CODE_SEGMENT
;
265 CurrentEIP
= (ULONG
)RealIsr
;
267 CurrentDS
= CurrentSS
= GLOBAL_DATA_SEGMENT
;
269 mov %%esp,%%eax\n\t \
270 mov %%eax,_CurrentESP\n\t \
274 // display version and symbol information
277 // disable HW breakpoints
279 xorl %%eax,%%eax\n\t \
280 mov %%eax,%%dr6\n\t \
281 mov %%eax,%%dr7\n\t \
282 mov %%dr0,%%eax\n\t \
283 mov %%dr1,%%eax\n\t \
284 mov %%dr2,%%eax\n\t \
289 DPRINT((0,"InitPICE(): trace step 15\n"));
292 DPRINT((0,"InitPICE(): trace step 16\n"));
295 InstallGlobalKeyboardHook();
296 InstallSyscallHook();
299 InstallGPFaultHook();
303 DPRINT((0,"InitPICE(): trace step 16\n"));
306 DPRINT((0,"about to do initial break...\n"));
308 // simulate an initial break
312 pushl $initialreturnpoint\n\t \
313 pushl $" STR(REASON_CTRLF
) "\n\t \
314 jmp NewInt31Handler\n\t \
315 initialreturnpoint:");
319 // display register contents
322 // display data window
323 Args
.Value
[0]=CurrentDS
;
324 Args
.Value
[1]=CurrentEIP
;
326 DisplayMemory(&Args
);
328 // disassembly from current address
329 Args
.Value
[0]=CurrentCS
;
330 Args
.Value
[1]=CurrentEIP
;
335 DPRINT((0,"InitPICE(): trace step 17\n"));
336 InitPiceRunningTimer();
342 //*************************************************************************
345 //*************************************************************************
346 void CleanUpPICE(void)
348 DPRINT((0,"CleanUpPICE(): trace step 1\n"));
349 RemovePiceRunningTimer();
351 DPRINT((0,"CleanUpPICE(): trace step 2\n"));
352 // de-install all hooks
353 DeInstallGlobalKeyboardHook();
354 DeInstallSyscallHook();
356 DeInstallPrintkHook();
357 DeInstallDblFltHook();
358 DeInstallGPFaultHook();
360 DeInstallTraceHook();
362 DPRINT((0,"CleanUpPICE(): trace step 3\n"));
365 DPRINT((0,"CleanUpPICE(): trace step 4\n"));
366 UnloadExports(); // don't use ScanExports() after this
369 DPRINT((0,"CleanUpPICE(): trace step 5\n"));
370 // restore patch of keyboard driver
371 RestoreKeyboardDriver();
373 DPRINT((0,"CleanUpPICE(): trace step 6\n"));
374 Print(OUTPUT_WINDOW
,"pICE: shutting down...\n");
376 DPRINT((0,"CleanUpPICE(): trace step 7\n"));
377 // cleanup the console