ReactOS 0.4.15-dev-5666-gc548b97
init.c
Go to the documentation of this file.
1/*++
2
3Copyright (c) 1998-2001 Klaus P. Gerlicher
4
5Module Name:
6
7 init.c
8
9Abstract:
10
11 initialisation and cleanup of debugger kernel module
12
13Environment:
14
15 Kernel mode only
16
17Author:
18
19 Klaus P. Gerlicher
20
21Revision History:
22
23 25-Jan-1999: created
24 15-Nov-2000: general cleanup of source files
25
26Copyright notice:
27
28 This file may be distributed under the terms of the GNU Public License.
29
30--*/
31
33// INCLUDES
35#include "remods.h"
36#include "precomp.h"
37
39// GLOBALS
41char szBootParams[1024]="";
42char tempInit[256];
43
44PDIRECTORY_OBJECT *pNameSpaceRoot = NULL;
47PMADDRESS_SPACE mm_init_mm;
49
51
52extern void NewInt31Handler(void);
53//*************************************************************************
54// InitPICE()
55//
56//*************************************************************************
58{
59 ULONG ulHandleScancode=0,ulHandleKbdEvent=0;
60 ARGS Args;
61 KIRQL Dirql;
63 ULONG ulAddr;
64
65 ENTER_FUNC();
66
67 DPRINT((0,"InitPICE(): trace step 0.5\n"));
69 0,
70 0,
72 &Dirql,
73 &Affinity);
74 DPRINT((0,"KeyboardIRQL: %x\n", KeyboardIRQL));
75
76 DPRINT((0,"InitPICE(): trace step 1\n"));
77 // enable monochrome passthrough on BX type chipset
79
80 DPRINT((0,"InitPICE(): trace step 2\n"));
81 // now load all symbol files described in /etc/pice.conf
83 {
84 DPRINT((0,"InitPICE: LoadSymbolsFromConfig() failed\n"));
85 LEAVE_FUNC();
86 return FALSE;
87 }
88
89 DPRINT((0,"InitPICE(): trace step 3\n"));
90 // init the output console
91 // this might be one of the following depending setup
92 // a) monochrome card
93 // b) serial terminal (TODO)
94 if(!ConsoleInit())
95 {
96 DPRINT((0,"InitPICE: ConsoleInit() failed\n"));
98 LEAVE_FUNC();
99 return FALSE;
100 }
101
102 DPRINT((0,"InitPICE(): trace step 4\n"));
103 // print the initial screen template
105/*
106 DPRINT((0,"InitPICE(): trace step 5\n"));
107 // ask the user if he wants to abort the debugger load
108 if(!CheckLoadAbort())
109 {
110 Print(OUTPUT_WINDOW,"pICE: ABORT (abort by user)\n");
111 UnloadSymbols();
112 ConsoleShutdown();
113 LEAVE_FUNC();
114 return FALSE;
115 }
116*/
117
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!!!
121 if(!LoadExports())
122 {
123 Print(OUTPUT_WINDOW,"pICE: failed to load exports\n");
124 Print(OUTPUT_WINDOW,"press any key to continue...\n");
125 while(!GetKeyPolled());
128 LEAVE_FUNC();
129 return FALSE;
130 }
131
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));
136 if(!my_init_mm)
137 {
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());
145 LEAVE_FUNC();
146 return FALSE;
147 }
148
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));
153 if(!pModuleListHead)
154 {
155 Print(OUTPUT_WINDOW,"pICE: ABORT (pModuleListHead not found)\n");
156 Print(OUTPUT_WINDOW,"pICE: press any key to continue...\n");
157 while(!GetKeyPolled());
160 LEAVE_FUNC();
161 return FALSE;
162 }
163
164 DPRINT((0,"InitPICE(): trace step 7.2\n"));
165 ScanExports("_PsProcessListHead",&ulAddr);
167 DPRINT((0,"pPsProcessListHead @ %X\n",pPsProcessListHead));
169 {
170 Print(OUTPUT_WINDOW,"pICE: ABORT (PsProcessListHead not found)\n");
171 Print(OUTPUT_WINDOW,"pICE: press any key to continue...\n");
172 while(!GetKeyPolled());
175 LEAVE_FUNC();
176 return FALSE;
177 }
178
179 DPRINT((0,"InitPICE(): trace step 8\n"));
180 // end of the kernel
181 /*
182 ScanExports("_end",(PULONG)&kernel_end);
183 if(!kernel_end)
184 {
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());
188 UnloadExports();
189 UnloadSymbols();
190 ConsoleShutdown();
191 LEAVE_FUNC();
192 return FALSE;
193 }
194 */
195
196 DPRINT((0,"InitPICE(): trace step 9\n"));
197
198 // the loaded module list
199 ScanExports("_NameSpaceRoot", &ulAddr);
200 pNameSpaceRoot = (PDIRECTORY_OBJECT *)ulAddr;
201 DPRINT((0,"pNameSpaceRoot @ %X\n",pNameSpaceRoot));
202 if(!pNameSpaceRoot)
203 {
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());
210 LEAVE_FUNC();
211 return FALSE;
212 }
213
214 DPRINT((0,"InitPICE(): trace step 10\n"));
215 // setup a linked list for use in module parsing routines.
217 {
218 Print(OUTPUT_WINDOW,"pICE: ABORT (couldn't initialize kernel module list)\n");
219 Print(OUTPUT_WINDOW,"pICE: press any key to continue...\n");
221 while(!GetKeyPolled());
225 LEAVE_FUNC();
226 return FALSE;
227 }
229
230 DPRINT((0,"InitPICE(): trace step 11\n"));
231 // do a sanity check on exports
232 if(!SanityCheckExports())
233 {
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());
240 LEAVE_FUNC();
241 return FALSE;
242 }
243
244 DPRINT((0,"InitPICE(): trace step 12\n"));
245
246
247 DPRINT((0,"InitPICE(): trace step 13\n"));
248 // patch the keyboard driver
249
251 {
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());
258 LEAVE_FUNC();
259 return FALSE;
260 }
261
262 DPRINT((0,"InitPICE(): trace step 14\n"));
263 // partial init of shadow registers
266
268 __asm__("\n\t \
269 mov %%esp,%%eax\n\t \
270 mov %%eax,_CurrentESP\n\t \
271 ":::"eax");
272
273
274 // display version and symbol information
275 Ver(NULL);
276
277 // disable HW breakpoints
278 __asm__("\n\t \
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 \
285 mov %%dr3,%%eax"
286 :::"eax"
287 );
288
289 DPRINT((0,"InitPICE(): trace step 15\n"));
291
292 DPRINT((0,"InitPICE(): trace step 16\n"));
293 // install all hooks
302
303 DPRINT((0,"InitPICE(): trace step 16\n"));
305 {
306 DPRINT((0,"about to do initial break...\n"));
307
308 // simulate an initial break
309 __asm__("\n\t \
310 pushfl\n\t \
311 pushl %cs\n\t \
312 pushl $initialreturnpoint\n\t \
313 pushl $" STR(REASON_CTRLF) "\n\t \
314 jmp NewInt31Handler\n\t \
315initialreturnpoint:");
316 }
317 else
318 {
319 // display register contents
320 DisplayRegs();
321
322 // display data window
323 Args.Value[0]=CurrentDS;
324 Args.Value[1]=CurrentEIP;
325 Args.Count=2;
327
328 // disassembly from current address
329 Args.Value[0]=CurrentCS;
330 Args.Value[1]=CurrentEIP;
331 Args.Count=2;
332 Unassemble(&Args);
333 }
334
335 DPRINT((0,"InitPICE(): trace step 17\n"));
337
338 LEAVE_FUNC();
339 return TRUE;
340}
341
342//*************************************************************************
343// CleanUpPICE()
344//
345//*************************************************************************
346void CleanUpPICE(void)
347{
348 DPRINT((0,"CleanUpPICE(): trace step 1\n"));
350
351 DPRINT((0,"CleanUpPICE(): trace step 2\n"));
352 // de-install all hooks
361
362 DPRINT((0,"CleanUpPICE(): trace step 3\n"));
363 RestoreIdt();
364
365 DPRINT((0,"CleanUpPICE(): trace step 4\n"));
366 UnloadExports(); // don't use ScanExports() after this
368
369 DPRINT((0,"CleanUpPICE(): trace step 5\n"));
370 // restore patch of keyboard driver
372
373 DPRINT((0,"CleanUpPICE(): trace step 6\n"));
374 Print(OUTPUT_WINDOW,"pICE: shutting down...\n");
375
376 DPRINT((0,"CleanUpPICE(): trace step 7\n"));
377 // cleanup the console
379}
unsigned char BOOLEAN
char ** Args
Definition: acdebug.h:353
void DeInstallInt3Hook(void)
Definition: bp.c:736
__asm__("\n\t \ NewInt3Handler:\n\t \ pushl $" STR(REASON_INT3) "\n\t \ // call debugger loop\n\t \ jmp NewInt31Handler\n\t \ ")
void InstallInt3Hook(void)
Definition: bp.c:709
void DeInstallDblFltHook(void)
Definition: dblflt.c:117
void InstallDblFltHook(void)
Definition: dblflt.c:93
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
ULONG_PTR KAFFINITY
Definition: compat.h:85
NTHALAPI ULONG NTAPI HalGetInterruptVector(INTERFACE_TYPE, ULONG, ULONG, ULONG, PKIRQL, PKAFFINITY)
UCHAR KIRQL
Definition: env_spec_w32.h:591
void DeInstallGPFaultHook(void)
Definition: gpfault.c:126
void InstallGPFaultHook(void)
Definition: gpfault.c:102
#define DbgPrint
Definition: hal.h:12
void TakeIdtSnapshot(void)
Definition: hooks.c:131
void RestoreIdt(void)
Definition: hooks.c:156
@ Internal
Definition: hwresource.cpp:137
unsigned int ULONG
Definition: retypes.h:1
#define ENTER_FUNC()
Definition: debug.h:42
#define LEAVE_FUNC()
Definition: debug.h:43
BOOLEAN ConsoleInit(void)
Definition: hardware.c:924
UCHAR GetKeyPolled(void)
Definition: hardware.c:904
void PrintTemplate(void)
Definition: hardware.c:720
void ConsoleShutdown(void)
Definition: hardware.c:991
void Print(USHORT Window, LPSTR p)
Definition: hardware.c:776
@ OUTPUT_WINDOW
Definition: hardware.h:72
BOOLEAN InitPICE(void)
Definition: init.c:57
void CleanUpPICE(void)
Definition: init.c:346
LIST_ENTRY * pModuleListHead
Definition: symbols.c:100
ULONG ulDoInitialBreak
Definition: init.c:40
ULONG KeyboardIRQL
Definition: init.c:50
PDEBUG_MODULE pdebug_module_tail
Definition: init.c:45
void NewInt31Handler(void)
PMADDRESS_SPACE mm_init_mm
Definition: init.c:47
PDIRECTORY_OBJECT * pNameSpaceRoot
Definition: init.c:44
PDEBUG_MODULE pdebug_module_head
Definition: init.c:46
char tempInit[256]
Definition: init.c:42
char szBootParams[1024]
Definition: init.c:41
void DeInstallPrintkHook(void)
Definition: output.c:278
void InitPiceRunningTimer(void)
Definition: output.c:221
void RemovePiceRunningTimer(void)
Definition: output.c:243
void InstallPrintkHook(void)
Definition: output.c:252
BOOLEAN(* DisplayMemory)(PARGS)
Definition: parse.c:56
LIST_ENTRY * pPsProcessListHead
Definition: utils.h:301
void RestoreKeyboardDriver(void)
Definition: patch.c:230
BOOLEAN PatchKeyboardDriver(void)
Definition: patch.c:193
void RealIsr(ULONG dwReasonForBreak)
Definition: shell.c:1016
USHORT CurrentDS
Definition: shell.c:116
void DeInstallGlobalKeyboardHook(void)
Definition: shell.c:1677
USHORT CurrentCS
Definition: shell.c:116
ULONG CurrentEIP
Definition: shell.c:113
void InstallGlobalKeyboardHook(void)
Definition: shell.c:1657
USHORT CurrentSS
Definition: shell.c:116
void DeInstallTraceHook(void)
Definition: trace.c:80
BOOLEAN InstallTraceHook(void)
Definition: trace.c:42
void DisplayRegs(void)
Definition: utils.c:1097
void EnablePassThrough(void)
Definition: utils.c:2194
#define STR(x)
Definition: utils.h:34
PMADDRESS_SPACE my_init_mm
Definition: utils.h:300
#define GLOBAL_DATA_SEGMENT
Definition: utils.h:247
#define GLOBAL_CODE_SEGMENT
Definition: utils.h:246
void DeInstallIntEHook(void)
Definition: pgflt.c:389
void InstallIntEHook(void)
Definition: pgflt.c:365
#define DPRINT
Definition: sndvol32.h:71
Definition: parse.h:32
Definition: typedefs.h:120
BOOLEAN SanityCheckExports(void)
Definition: symbols.c:1860
void UnloadExports(void)
Definition: symbols.c:1974
void UnloadSymbols()
Definition: symbols.c:2093
BOOLEAN ScanExports(const char *pFind, PULONG pValue)
Definition: symbols.c:327
BOOLEAN LoadSymbolsFromConfig(BOOLEAN bIgnoreBootParams)
Definition: symbols.c:2116
BOOLEAN InitModuleList(PDEBUG_MODULE *ppmodule, ULONG len)
Definition: symbols.c:138
VOID FreeModuleList(PDEBUG_MODULE pm)
Definition: symbols.c:121
BOOLEAN LoadExports(void)
Definition: symbols.c:1909
void DeInstallSyscallHook(void)
Definition: syscall.c:218
void InstallSyscallHook(void)
Definition: syscall.c:194
#define KEYBOARD_IRQ
Definition: shell.h:91
#define REASON_CTRLF
Definition: shell.h:73
_In_ ULONG _In_ ULONG _In_ ULONG _Out_ PKIRQL _Out_ PKAFFINITY Affinity
Definition: halfuncs.h:174