956d16a750844e47efd39fddcb65dbc44853c239
1 /* $Id: main.c,v 1.37 2000/02/27 02:10:09 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/module.h>
21 #include <internal/ldr.h>
22 #include <internal/ex.h>
23 #include <internal/ps.h>
25 #include <internal/mmhal.h>
26 #include <internal/i386/segment.h>
29 #include <internal/debug.h>
31 /* DATA *********************************************************************/
33 USHORT NtBuildNumber
= KERNEL_VERSION_BUILD
; /* EXPORTED */
35 ULONG NtGlobalFlag
= 0; /* FIXME: EXPORTED */
37 /* FUNCTIONS ****************************************************************/
39 void set_breakpoint(unsigned int i
, unsigned int addr
, unsigned int type
,
42 * FUNCTION: Sets a hardware breakpoint
44 * i = breakpoint to set (0 to 3)
45 * addr = linear address to break on
46 * type = Type of access to break on
47 * len = length of the variable to watch
49 * The variable to watch must be aligned to its length (i.e. a dword
50 * breakpoint must be aligned to a dword boundary)
52 * A fatal exception will be generated on the access to the variable.
53 * It is (at the moment) only really useful for catching undefined
54 * pointers if you know the variable effected but not the buggy
57 * FIXME: Extend to call out to kernel debugger on breakpoint
58 * Add support for I/O breakpoints
59 * REFERENCES: See the i386 programmer manual for more details
66 DbgPrint("Invalid breakpoint index at %s:%d\n",__FILE__
,__LINE__
);
71 * Load the linear address
76 __asm("movl %0,%%db0\n\t"
82 __asm__("movl %0,%%db1\n\t"
88 __asm__("movl %0,%%db2\n\t"
94 __asm__("movl %0,%%db3\n\t"
103 mask
= (len
<<(16 + 2 + i
*4)) + (type
<<(16 + i
*4)) + (1<<(i
*2));
104 __asm__("movl %%db7,%%eax\n\t"
106 "movl %%eax,%%db7\n\t"
116 static char * INIData
=
117 "[HKEY_LOCAL_MACHINE\\HARDWARE]\r\n"
119 "[HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP]\r\n"
121 "[HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\AtDisk]\r\n"
123 "[HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\AtDisk\\Controller 0]\r\n"
124 "Controller Address=dword:000001f0\r\n"
125 "Controller Interrupt=dword:0000000e\r\n"
132 unsigned int old_idt
[256][2];
133 //extern unsigned int idt[];
134 unsigned int old_idt_valid
= 1;
136 asmlinkage
void _main(boot_param
* _bp
)
138 * FUNCTION: Called by the boot loader to start the kernel
140 * _bp = Pointer to boot parameters initialized by the boot loader
141 * NOTE: The boot parameters are stored in low memory which will become
142 * invalid after the memory managment is initialized so we make a local copy.
149 unsigned int last_kernel_address
;
151 // memset((void *)&edata,0,((int)&end)-((int)&edata));
154 * Copy the parameters to a local buffer because lowmem will go away
156 memcpy(&bp
,_bp
,sizeof(boot_param
));
159 * Initalize the hal (Phase 0)
161 HalInitSystem (0, &bp
);
163 HalDisplayString("Starting ReactOS "KERNEL_VERSION_STR
" (Build "KERNEL_VERSION_BUILD_STR
")\n");
166 * Initialize the debug output
170 start
= KERNEL_BASE
+ PAGE_ROUND_UP(bp
.module_length
[0]);
171 if (start
< ((int)&end
))
173 DbgPrint("start %x end %x\n",start
,(int)&end
);
174 DbgPrint("Kernel booted incorrectly, aborting\n");
175 DbgPrint("Reduce the amount of uninitialized data\n");
178 start1
= start
+PAGE_ROUND_UP(bp
.module_length
[1]);
180 last_kernel_address
= KERNEL_BASE
;
181 for (i
=0; i
<=bp
.nr_files
; i
++)
183 last_kernel_address
= last_kernel_address
+
184 PAGE_ROUND_UP(bp
.module_length
[i
]);
188 * Initalize various critical subsystems
190 DPRINT("HalInitSystem()\n");
191 HalInitSystem (1, &bp
);
192 DPRINT("MmInitialize()\n");
193 MmInitialize(&bp
, last_kernel_address
);
194 DPRINT("KeInit()\n");
196 DPRINT("ExInit()\n");
198 DPRINT("ObInit()\n");
200 DPRINT("PsInit()\n");
201 PiInitProcessManager();
202 DPRINT("IoInit()\n");
204 DPRINT("LdrInitModuleManagement()\n");
205 LdrInitModuleManagement();
206 CmInitializeRegistry();
209 memcpy(old_idt
, KiIdt
, sizeof(old_idt
));
213 * Initalize services loaded at boot time
215 DPRINT1("%d files loaded\n",bp
.nr_files
);
217 /* Pass 1: load registry chunks passed in */
218 start
= KERNEL_BASE
+ PAGE_ROUND_UP(bp
.module_length
[0]);
219 for (i
= 1; i
< bp
.nr_files
; i
++)
221 if (!strcmp ((PCHAR
) start
, "REGEDIT4"))
223 DPRINT1("process registry chunk at %08lx\n", start
);
224 CmImportHive((PCHAR
) start
);
226 start
= start
+ bp
.module_length
[i
];
229 /* Pass 2: process boot loaded drivers */
230 start
= KERNEL_BASE
+ PAGE_ROUND_UP(bp
.module_length
[0]);
231 start1
= start
+ bp
.module_length
[1];
232 for (i
=1;i
<bp
.nr_files
;i
++)
234 if (strcmp ((PCHAR
) start
, "REGEDIT4"))
236 DPRINT1("process module at %08lx\n", start
);
237 LdrProcessDriver((PVOID
)start
);
239 start
= start
+ bp
.module_length
[i
];
243 * Load Auto configured drivers
246 LdrLoadAutoConfigDrivers();
249 * Launch initial process
252 LdrLoadInitialProcess();
257 DbgPrint("Finished main()\n");
258 PsTerminateSystemThread(STATUS_SUCCESS
);