Changed debug output to use INT 2D
[reactos.git] / reactos / ntoskrnl / ke / main.c
1 /* $Id: main.c,v 1.34 2000/01/17 21:01:16 ekohl Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/ke/main.c
6 * PURPOSE: Initalizes the kernel
7 * PROGRAMMER: David Welch (welch@cwcom.net)
8 * UPDATE HISTORY:
9 * 28/05/98: Created
10 */
11
12 /* INCLUDES *****************************************************************/
13
14 #include <ddk/ntddk.h>
15 #include <internal/ntoskrnl.h>
16 #include <reactos/buildno.h>
17 #include <internal/mm.h>
18 #include <string.h>
19 #include <internal/string.h>
20 #include <internal/symbol.h>
21 #include <internal/module.h>
22 #include <internal/ldr.h>
23 #include <internal/ex.h>
24 #include <internal/ps.h>
25
26 #include <internal/mmhal.h>
27 #include <internal/i386/segment.h>
28
29 #define NDEBUG
30 #include <internal/debug.h>
31
32 /* FUNCTIONS ****************************************************************/
33
34 void set_breakpoint(unsigned int i, unsigned int addr, unsigned int type,
35 unsigned int len)
36 /*
37 * FUNCTION: Sets a hardware breakpoint
38 * ARGUMENTS:
39 * i = breakpoint to set (0 to 3)
40 * addr = linear address to break on
41 * type = Type of access to break on
42 * len = length of the variable to watch
43 * NOTES:
44 * The variable to watch must be aligned to its length (i.e. a dword
45 * breakpoint must be aligned to a dword boundary)
46 *
47 * A fatal exception will be generated on the access to the variable.
48 * It is (at the moment) only really useful for catching undefined
49 * pointers if you know the variable effected but not the buggy
50 * routine.
51 *
52 * FIXME: Extend to call out to kernel debugger on breakpoint
53 * Add support for I/O breakpoints
54 * REFERENCES: See the i386 programmer manual for more details
55 */
56 {
57 unsigned int mask;
58
59 if (i>3)
60 {
61 DbgPrint("Invalid breakpoint index at %s:%d\n",__FILE__,__LINE__);
62 return;
63 }
64
65 /*
66 * Load the linear address
67 */
68 switch (i)
69 {
70 case 0:
71 __asm("movl %0,%%db0\n\t"
72 : /* no outputs */
73 : "d" (addr));
74 break;
75
76 case 1:
77 __asm__("movl %0,%%db1\n\t"
78 : /* no outputs */
79 : "d" (addr));
80 break;
81
82 case 2:
83 __asm__("movl %0,%%db2\n\t"
84 : /* no outputs */
85 : "d" (addr));
86 break;
87
88 case 3:
89 __asm__("movl %0,%%db3\n\t"
90 : /* no outputs */
91 : "d" (addr));
92 break;
93 }
94
95 /*
96 * Setup mask for dr7
97 */
98 mask = (len<<(16 + 2 + i*4)) + (type<<(16 + i*4)) + (1<<(i*2));
99 __asm__("movl %%db7,%%eax\n\t"
100 "orl %0,%%eax\n\t"
101 "movl %%eax,%%db7\n\t"
102 : /* no outputs */
103 : "d" (mask)
104 : "ax");
105 }
106
107 extern int edata;
108 extern int end;
109
110 #if 0
111 static char * INIData =
112 "[HKEY_LOCAL_MACHINE\\HARDWARE]\r\n"
113 "\r\n"
114 "[HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP]\r\n"
115 "\r\n"
116 "[HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\AtDisk]\r\n"
117 "\r\n"
118 "[HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\AtDisk\\Controller 0]\r\n"
119 "Controller Address=dword:000001f0\r\n"
120 "Controller Interrupt=dword:0000000e\r\n"
121 "\r\n"
122 "\r\n"
123 "\r\n"
124 "";
125 #endif
126
127 unsigned int old_idt[256][2];
128 //extern unsigned int idt[];
129 unsigned int old_idt_valid = 1;
130
131 asmlinkage void _main(boot_param* _bp)
132 /*
133 * FUNCTION: Called by the boot loader to start the kernel
134 * ARGUMENTS:
135 * _bp = Pointer to boot parameters initialized by the boot loader
136 * NOTE: The boot parameters are stored in low memory which will become
137 * invalid after the memory managment is initialized so we make a local copy.
138 */
139 {
140 unsigned int i;
141 unsigned int start;
142 unsigned int start1;
143 boot_param bp;
144 unsigned int last_kernel_address;
145
146 // memset((void *)&edata,0,((int)&end)-((int)&edata));
147
148 /*
149 * Copy the parameters to a local buffer because lowmem will go away
150 */
151 memcpy(&bp,_bp,sizeof(boot_param));
152
153 /*
154 * Initalize the hal (Phase 0)
155 */
156 HalInitSystem (0, &bp);
157
158 HalDisplayString("Starting ReactOS "KERNEL_VERSION_STR" (Build "KERNEL_VERSION_BUILD_STR")\n");
159
160 /*
161 * Initialize the debug output
162 */
163 KdInitSystem ();
164
165 start = KERNEL_BASE + PAGE_ROUND_UP(bp.module_length[0]);
166 if (start < ((int)&end))
167 {
168 DbgPrint("start %x end %x\n",start,(int)&end);
169 DbgPrint("Kernel booted incorrectly, aborting\n");
170 DbgPrint("Reduce the amount of uninitialized data\n");
171 for(;;);
172 }
173 start1 = start+PAGE_ROUND_UP(bp.module_length[1]);
174
175 last_kernel_address = KERNEL_BASE;
176 for (i=0; i<=bp.nr_files; i++)
177 {
178 last_kernel_address = last_kernel_address +
179 PAGE_ROUND_UP(bp.module_length[i]);
180 }
181
182 /*
183 * Initalize various critical subsystems
184 */
185 DPRINT("HalInitSystem()\n");
186 HalInitSystem (1, &bp);
187 DPRINT("MmInitialize()\n");
188 MmInitialize(&bp, last_kernel_address);
189 DPRINT("KeInit()\n");
190 KeInit();
191 DPRINT("ExInit()\n");
192 ExInit();
193 DPRINT("ObInit()\n");
194 ObInit();
195 DPRINT("PsInit()\n");
196 PiInitProcessManager();
197 DPRINT("IoInit()\n");
198 IoInit();
199 DPRINT("LdrInitModuleManagement()\n");
200 LdrInitModuleManagement();
201 CmInitializeRegistry();
202 NtInit();
203
204 memcpy(old_idt, KiIdt, sizeof(old_idt));
205 old_idt_valid = 0;
206
207 /*
208 * Initalize services loaded at boot time
209 */
210 DPRINT1("%d files loaded\n",bp.nr_files);
211
212 /* Pass 1: load registry chunks passed in */
213 start = KERNEL_BASE + PAGE_ROUND_UP(bp.module_length[0]);
214 for (i = 1; i < bp.nr_files; i++)
215 {
216 if (!strcmp ((PCHAR) start, "REGEDIT4"))
217 {
218 DPRINT1("process registry chunk at %08lx\n", start);
219 CmImportHive((PCHAR) start);
220 }
221 start = start + bp.module_length[i];
222 }
223
224 /* Pass 2: process boot loaded drivers */
225 start = KERNEL_BASE + PAGE_ROUND_UP(bp.module_length[0]);
226 start1 = start + bp.module_length[1];
227 for (i=1;i<bp.nr_files;i++)
228 {
229 if (strcmp ((PCHAR) start, "REGEDIT4"))
230 {
231 DPRINT1("process module at %08lx\n", start);
232 LdrProcessDriver((PVOID)start);
233 }
234 start = start + bp.module_length[i];
235 }
236
237 /*
238 * Load Auto configured drivers
239 */
240 CHECKPOINT;
241 LdrLoadAutoConfigDrivers();
242
243 /*
244 * Launch initial process
245 */
246 CHECKPOINT;
247 LdrLoadInitialProcess();
248
249 /*
250 * Enter idle loop
251 */
252 DbgPrint("Finished main()\n");
253 PsTerminateSystemThread(STATUS_SUCCESS);
254 }
255
256
257 /* EOF */