1 /* See COPYRIGHT for copyright information. */
4 #include <inc/string.h>
5 #include <inc/assert.h>
7 #include <kern/monitor.h>
8 #include <kern/console.h>
10 #include <kern/kclock.h>
11 #include <kern/trap.h>
13 #include <kern/sched.h>
14 #include <kern/picirq.h>
16 // Test the stack backtrace function (used in lab 1 only)
20 cprintf("entering test_backtrace %d\n", x
);
24 mon_backtrace(0, 0, 0);
25 cprintf("leaving test_backtrace %d\n", x
);
28 // Test kernel breakpoint functionality (used in lab 2 only)
29 static void test_kernel_breakpoint(void) __attribute__((noinline
));
31 test_kernel_breakpoint(void)
33 __asm__
__volatile__("int3");
34 // Then the breakpoint should return (after the user types 'exit')
35 cprintf("Breakpoint succeeded!\n");
41 extern char edata
[], end
[];
42 extern const uintptr_t sctors
[], ectors
[];
43 const uintptr_t *ctorva
;
45 // Initialize the console.
46 // Can't call cprintf until after we do this!
49 // Then call any global constructors (e.g., defined by C++).
50 // This relies on linker script magic to define the 'sctors' and
51 // 'ectors' symbols; see kern/kernel.ld.
52 // Call after cons_init() so we can cprintf() if necessary.
53 for (ctorva
= ectors
; ctorva
> sctors
; )
54 ((void(*)()) *--ctorva
)();
56 cprintf("6828 decimal is %o octal!\n", 6828);
58 // Lab 2 memory management initialization functions
61 // Lab 2 interrupt and gate descriptor initialization functions
64 // Lab 3 user environment initialization functions
67 // Lab 4 multitasking initialization functions
71 // Should always have an idle process as first one.
72 ENV_CREATE(user_idle
);
75 // Don't touch -- used by grading script!
76 ENV_CREATE2(TEST
, TESTSIZE
);
78 // Touch all you want.
79 ENV_CREATE(user_primes
);
83 // Schedule and run the first user environment!
86 // Test IDT (lab 2 only)
87 //test_kernel_breakpoint();
89 // Test the stack backtrace function (lab 1 only)
92 // Drop into the kernel monitor (lab 1-2 only; not reached later)
99 * Variable panicstr contains argument to first call to panic; used as flag
100 * to indicate that the kernel has already called panic.
102 static const char *panicstr
;
105 * Panic is called on unresolvable fatal errors.
106 * It prints "panic: mesg", and then enters the kernel monitor.
109 _panic(const char *file
, int line
, const char *fmt
, ...)
117 // Be extra sure that the machine is in as reasonable state
118 __asm
__volatile("cli; cld");
121 cprintf("kernel panic at %s:%d: ", file
, line
);
127 /* break into the kernel monitor */
132 /* like panic, but don't */
134 _warn(const char *file
, int line
, const char *fmt
, ...)
139 cprintf("kernel warning at %s:%d: ", file
, line
);