1 /* $Id: main.c,v 1.34 2000/01/17 21:01:16 ekohl Exp $
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)
12 /* INCLUDES *****************************************************************/
14 #include <ddk/ntddk.h>
15 #include <internal/ntoskrnl.h>
16 #include <reactos/buildno.h>
17 #include <internal/mm.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>
26 #include <internal/mmhal.h>
27 #include <internal/i386/segment.h>
30 #include <internal/debug.h>
32 /* FUNCTIONS ****************************************************************/
34 void set_breakpoint(unsigned int i
, unsigned int addr
, unsigned int type
,
37 * FUNCTION: Sets a hardware breakpoint
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
44 * The variable to watch must be aligned to its length (i.e. a dword
45 * breakpoint must be aligned to a dword boundary)
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
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
61 DbgPrint("Invalid breakpoint index at %s:%d\n",__FILE__
,__LINE__
);
66 * Load the linear address
71 __asm("movl %0,%%db0\n\t"
77 __asm__("movl %0,%%db1\n\t"
83 __asm__("movl %0,%%db2\n\t"
89 __asm__("movl %0,%%db3\n\t"
98 mask
= (len
<<(16 + 2 + i
*4)) + (type
<<(16 + i
*4)) + (1<<(i
*2));
99 __asm__("movl %%db7,%%eax\n\t"
101 "movl %%eax,%%db7\n\t"
111 static char * INIData
=
112 "[HKEY_LOCAL_MACHINE\\HARDWARE]\r\n"
114 "[HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP]\r\n"
116 "[HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\AtDisk]\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"
127 unsigned int old_idt
[256][2];
128 //extern unsigned int idt[];
129 unsigned int old_idt_valid
= 1;
131 asmlinkage
void _main(boot_param
* _bp
)
133 * FUNCTION: Called by the boot loader to start the kernel
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.
144 unsigned int last_kernel_address
;
146 // memset((void *)&edata,0,((int)&end)-((int)&edata));
149 * Copy the parameters to a local buffer because lowmem will go away
151 memcpy(&bp
,_bp
,sizeof(boot_param
));
154 * Initalize the hal (Phase 0)
156 HalInitSystem (0, &bp
);
158 HalDisplayString("Starting ReactOS "KERNEL_VERSION_STR
" (Build "KERNEL_VERSION_BUILD_STR
")\n");
161 * Initialize the debug output
165 start
= KERNEL_BASE
+ PAGE_ROUND_UP(bp
.module_length
[0]);
166 if (start
< ((int)&end
))
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");
173 start1
= start
+PAGE_ROUND_UP(bp
.module_length
[1]);
175 last_kernel_address
= KERNEL_BASE
;
176 for (i
=0; i
<=bp
.nr_files
; i
++)
178 last_kernel_address
= last_kernel_address
+
179 PAGE_ROUND_UP(bp
.module_length
[i
]);
183 * Initalize various critical subsystems
185 DPRINT("HalInitSystem()\n");
186 HalInitSystem (1, &bp
);
187 DPRINT("MmInitialize()\n");
188 MmInitialize(&bp
, last_kernel_address
);
189 DPRINT("KeInit()\n");
191 DPRINT("ExInit()\n");
193 DPRINT("ObInit()\n");
195 DPRINT("PsInit()\n");
196 PiInitProcessManager();
197 DPRINT("IoInit()\n");
199 DPRINT("LdrInitModuleManagement()\n");
200 LdrInitModuleManagement();
201 CmInitializeRegistry();
204 memcpy(old_idt
, KiIdt
, sizeof(old_idt
));
208 * Initalize services loaded at boot time
210 DPRINT1("%d files loaded\n",bp
.nr_files
);
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
++)
216 if (!strcmp ((PCHAR
) start
, "REGEDIT4"))
218 DPRINT1("process registry chunk at %08lx\n", start
);
219 CmImportHive((PCHAR
) start
);
221 start
= start
+ bp
.module_length
[i
];
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
++)
229 if (strcmp ((PCHAR
) start
, "REGEDIT4"))
231 DPRINT1("process module at %08lx\n", start
);
232 LdrProcessDriver((PVOID
)start
);
234 start
= start
+ bp
.module_length
[i
];
238 * Load Auto configured drivers
241 LdrLoadAutoConfigDrivers();
244 * Launch initial process
247 LdrLoadInitialProcess();
252 DbgPrint("Finished main()\n");
253 PsTerminateSystemThread(STATUS_SUCCESS
);