lab3 finished
[mit-jos.git] / kern / init.c
blobec2a36c7d5791f5c126826f0206398aba8c1af93
1 /* See COPYRIGHT for copyright information. */
3 #include <inc/stdio.h>
4 #include <inc/string.h>
5 #include <inc/assert.h>
7 #include <kern/monitor.h>
8 #include <kern/console.h>
9 #include <kern/pmap.h>
10 #include <kern/kclock.h>
11 #include <kern/env.h>
12 #include <kern/trap.h>
14 void
15 i386_init(void)
17 extern char edata[], end[];
19 // Before doing anything else, complete the ELF loading process.
20 // Clear the uninitialized global data (BSS) section of our program.
21 // This ensures that all static/global variables start out zero.
22 memset(edata, 0, end - edata);
24 // Initialize the console.
25 // Can't call cprintf until after we do this!
26 cons_init();
28 cprintf("6828 decimal is %o octal!\n", 6828);
30 // Lab 2 memory management initialization functions
31 i386_detect_memory();
32 i386_vm_init();
34 // Lab 3 user environment initialization functions
35 env_init();
36 idt_init();
38 // Temporary test code specific to LAB 3
39 #if defined(TEST)
40 // Don't touch -- used by grading script!
41 ENV_CREATE2(TEST, TESTSIZE);
42 #else
43 // Touch all you want.
44 ENV_CREATE(user_hello);
45 #endif // TEST*
47 // We only have one user environment for now, so just run it.
48 env_run(&envs[0]);
53 * Variable panicstr contains argument to first call to panic; used as flag
54 * to indicate that the kernel has already called panic.
56 static const char *panicstr;
59 * Panic is called on unresolvable fatal errors.
60 * It prints "panic: mesg", and then enters the kernel monitor.
62 void
63 _panic(const char *file, int line, const char *fmt,...)
65 va_list ap;
67 if (panicstr)
68 goto dead;
69 panicstr = fmt;
71 va_start(ap, fmt);
72 cprintf("kernel panic at %s:%d: ", file, line);
73 vcprintf(fmt, ap);
74 cprintf("\n");
75 va_end(ap);
77 dead:
78 /* break into the kernel monitor */
79 while (1)
80 monitor(NULL);
83 /* like panic, but don't */
84 void
85 _warn(const char *file, int line, const char *fmt,...)
87 va_list ap;
89 va_start(ap, fmt);
90 cprintf("kernel warning at %s:%d: ", file, line);
91 vcprintf(fmt, ap);
92 cprintf("\n");
93 va_end(ap);