Initial revision
[reactos.git] / reactos / ntoskrnl / ke / main.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/ke/main.c
5 * PURPOSE: Initalizes the kernel
6 * PROGRAMMER: David Welch (welch@mcmail.com)
7 * UPDATE HISTORY:
8 * 28/05/98: Created
9 */
10
11 /* INCLUDES *****************************************************************/
12
13 #include <windows.h>
14 #include <coff.h>
15
16 #include <internal/kernel.h>
17 #include <internal/version.h>
18 #include <internal/mm.h>
19 #include <internal/string.h>
20 #include <internal/symbol.h>
21 #include <internal/module.h>
22
23 #include <internal/hal/page.h>
24 #include <internal/hal/segment.h>
25
26 #define NDEBUG
27 #include <internal/debug.h>
28
29 /* FUNCTIONS ****************************************************************/
30
31 void set_breakpoint(unsigned int i, unsigned int addr, unsigned int type,
32 unsigned int len)
33 /*
34 * FUNCTION: Sets a hardware breakpoint
35 * ARGUMENTS:
36 * i = breakpoint to set (0 to 3)
37 * addr = linear address to break on
38 * type = Type of access to break on
39 * len = length of the variable to watch
40 * NOTES:
41 * The variable to watch must be aligned to its length (i.e. a dword
42 * breakpoint must be aligned to a dword boundary)
43 *
44 * A fatal exception will be generated on the access to the variable.
45 * It is (at the moment) only really useful for catching undefined
46 * pointers if you know the variable effected but not the buggy
47 * routine.
48 *
49 * FIXME: Extend to call out to kernel debugger on breakpoint
50 * Add support for I/O breakpoints
51 * REFERENCES: See the i386 programmer manual for more details
52 */
53 {
54 unsigned int mask;
55
56 if (i>3)
57 {
58 printk("Invalid breakpoint index at %s:%d\n",__FILE__,__LINE__);
59 return;
60 }
61
62 /*
63 * Load the linear address
64 */
65 switch (i)
66 {
67 case 0:
68 __asm("movl %0,%%db0\n\t"
69 : /* no outputs */
70 : "d" (addr));
71 break;
72
73 case 1:
74 __asm__("movl %0,%%db1\n\t"
75 : /* no outputs */
76 : "d" (addr));
77 break;
78
79 case 2:
80 __asm__("movl %0,%%db2\n\t"
81 : /* no outputs */
82 : "d" (addr));
83 break;
84
85 case 3:
86 __asm__("movl %0,%%db3\n\t"
87 : /* no outputs */
88 : "d" (addr));
89 break;
90 }
91
92 /*
93 * Setup mask for dr7
94 */
95 mask = (len<<(16 + 2 + i*4)) + (type<<(16 + i*4)) + (1<<(i*2));
96 __asm__("movl %%db7,%%eax\n\t"
97 "orl %0,%%eax\n\t"
98 "movl %%eax,%%db7\n\t"
99 : /* no outputs */
100 : "d" (mask)
101 : "ax");
102 }
103
104 asmlinkage void _main(boot_param* _bp)
105 /*
106 * FUNCTION: Called by the boot loader to start the kernel
107 * ARGUMENTS:
108 * _bp = Pointer to boot parameters initialized by the boot loader
109 * NOTE: The boot parameters are stored in low memory which will become
110 * invalid after the memory managment is initialized so we make a local copy.
111 */
112 {
113 unsigned int i;
114 unsigned int start;
115
116 /*
117 * Copy the parameters to a local buffer because lowmem will go away
118 */
119 boot_param bp;
120 memcpy(&bp,_bp,sizeof(bp));
121
122 /*
123 * Initalize the console (before printing anything)
124 */
125 InitConsole(&bp);
126
127 printk("Starting ReactOS "KERNEL_VERSION"\n");
128
129 /*
130 * Initalize various critical subsystems
131 */
132 HalInit(&bp);
133 MmInitalize(&bp);
134 KeInitDpc();
135 KeInitializeBugCheck();
136 KeInitializeDispatcher();
137 InitializeTimer();
138
139 /*
140 * Allow interrupts
141 */
142 KeLowerIrql(PASSIVE_LEVEL);
143
144 KeCalibrateTimerLoop();
145 ObjNamespcInit();
146 PsMgrInit();
147 IoInit();
148
149 /*
150 * Initalize loaded modules
151 */
152 DPRINT("%d files loaded\n",bp.nr_files);
153
154
155 start = KERNEL_BASE + PAGE_ROUND_UP(bp.module_length[0]) +
156 PAGESIZE;
157 for (i=1;i<bp.nr_files;i++)
158 {
159 DPRINT("start %x length %d\n",start,bp.module_length[i]);
160 process_boot_module(start);
161 start=start+PAGE_ROUND_UP(bp.module_length[i])+PAGESIZE;
162 }
163
164
165 /*
166 * Enter shell
167 */
168 TstBegin();
169
170 /*
171 * Enter idle loop
172 */
173 printk("Finished main()\n");
174 for (;;);
175 }