initial commit
[mit-jos.git] / kern / init.c
blob7ed151054dbdec15521692b25d351f9896f4633d
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>
10 // Test the stack backtrace function (lab 1 only)
11 void
12 test_backtrace(int x)
14 cprintf("entering test_backtrace %d\n", x);
15 if (x > 0)
16 test_backtrace(x-1);
17 else
18 mon_backtrace(0, 0, 0);
19 cprintf("leaving test_backtrace %d\n", x);
22 void
23 i386_init(void)
25 extern char edata[], end[];
27 // Before doing anything else, complete the ELF loading process.
28 // Clear the uninitialized global data (BSS) section of our program.
29 // This ensures that all static/global variables start out zero.
30 memset(edata, 0, end - edata);
32 // Initialize the console.
33 // Can't call cprintf until after we do this!
34 cons_init();
36 cprintf("6828 decimal is %o octal!\n", 6828);
44 // Test the stack backtrace function (lab 1 only)
45 test_backtrace(5);
47 // Drop into the kernel monitor.
48 while (1)
49 monitor(NULL);
54 * Variable panicstr contains argument to first call to panic; used as flag
55 * to indicate that the kernel has already called panic.
57 static const char *panicstr;
60 * Panic is called on unresolvable fatal errors.
61 * It prints "panic: mesg", and then enters the kernel monitor.
63 void
64 _panic(const char *file, int line, const char *fmt,...)
66 va_list ap;
68 if (panicstr)
69 goto dead;
70 panicstr = fmt;
72 va_start(ap, fmt);
73 cprintf("kernel panic at %s:%d: ", file, line);
74 vcprintf(fmt, ap);
75 cprintf("\n");
76 va_end(ap);
78 dead:
79 /* break into the kernel monitor */
80 while (1)
81 monitor(NULL);
84 /* like panic, but don't */
85 void
86 _warn(const char *file, int line, const char *fmt,...)
88 va_list ap;
90 va_start(ap, fmt);
91 cprintf("kernel warning at %s:%d: ", file, line);
92 vcprintf(fmt, ap);
93 cprintf("\n");
94 va_end(ap);