spawn implemented.
[mit-jos.git] / kern / init.c
bloba2c18267e38d26a7f8c7baa61b877345ba6b7f7f
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>
13 #include <kern/sched.h>
14 #include <kern/picirq.h>
16 void
17 i386_init(void)
19 extern char edata[], end[];
21 // Before doing anything else, complete the ELF loading process.
22 // Clear the uninitialized global data (BSS) section of our program.
23 // This ensures that all static/global variables start out zero.
24 memset(edata, 0, end - edata);
26 // Initialize the console.
27 // Can't call cprintf until after we do this!
28 cons_init();
30 cprintf("6828 decimal is %o octal!\n", 6828);
32 // Lab 2 memory management initialization functions
33 i386_detect_memory();
34 i386_vm_init();
36 // Lab 3 user environment initialization functions
37 env_init();
38 idt_init();
40 // Lab 4 multitasking initialization functions
41 pic_init();
42 kclock_init();
44 // Should always have an idle process as first one.
45 ENV_CREATE(user_idle);
47 // Start fs.
48 ENV_CREATE(fs_fs);
50 // Start init
51 #if defined(TEST)
52 // Don't touch -- used by grading script!
53 ENV_CREATE2(TEST, TESTSIZE);
54 #else
55 // Touch all you want.
56 // ENV_CREATE(user_writemotd);
57 // ENV_CREATE(user_testfsipc);
58 // ENV_CREATE(user_icode);
59 #endif
61 // Schedule and run the first user environment!
62 sched_yield();
67 * Variable panicstr contains argument to first call to panic; used as flag
68 * to indicate that the kernel has already called panic.
70 static const char *panicstr;
73 * Panic is called on unresolvable fatal errors.
74 * It prints "panic: mesg", and then enters the kernel monitor.
76 void
77 _panic(const char *file, int line, const char *fmt,...)
79 va_list ap;
81 if (panicstr)
82 goto dead;
83 panicstr = fmt;
85 va_start(ap, fmt);
86 cprintf("kernel panic at %s:%d: ", file, line);
87 vcprintf(fmt, ap);
88 cprintf("\n");
89 va_end(ap);
91 dead:
92 /* break into the kernel monitor */
93 while (1)
94 monitor(NULL);
97 /* like panic, but don't */
98 void
99 _warn(const char *file, int line, const char *fmt,...)
101 va_list ap;
103 va_start(ap, fmt);
104 cprintf("kernel warning at %s:%d: ", file, line);
105 vcprintf(fmt, ap);
106 cprintf("\n");
107 va_end(ap);