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>
14 // Test the stack backtrace function (used in lab 1 only)
18 cprintf("entering test_backtrace %d\n", x
);
22 mon_backtrace(0, 0, 0);
23 cprintf("leaving test_backtrace %d\n", x
);
26 // Test kernel breakpoint functionality (used in lab 2 only)
27 static void test_kernel_breakpoint(void) __attribute__((noinline
));
29 test_kernel_breakpoint(void)
31 __asm__
__volatile__("int3");
32 // Then the breakpoint should return (after the user types 'exit')
33 cprintf("Breakpoint succeeded!\n");
39 extern char edata
[], end
[];
40 extern const uintptr_t sctors
[], ectors
[];
41 const uintptr_t *ctorva
;
43 // Initialize the console.
44 // Can't call cprintf until after we do this!
47 // Then call any global constructors (e.g., defined by C++).
48 // This relies on linker script magic to define the 'sctors' and
49 // 'ectors' symbols; see kern/kernel.ld.
50 // Call after cons_init() so we can cprintf() if necessary.
51 for (ctorva
= ectors
; ctorva
> sctors
; )
52 ((void(*)()) *--ctorva
)();
54 cprintf("6828 decimal is %o octal!\n", 6828);
56 // Lab 2 memory management initialization functions
59 // Lab 2 interrupt and gate descriptor initialization functions
62 // Lab 3 user environment initialization functions
65 // Temporary test code specific to LAB 3
67 // Don't touch -- used by grading script!
68 ENV_CREATE2(TEST
, TESTSIZE
);
70 // Touch all you want.
71 ENV_CREATE(user_hello
);
75 // We only have one user environment for now, so just run it.
78 // Test IDT (lab 2 only)
79 //test_kernel_breakpoint();
81 // Test the stack backtrace function (lab 1 only)
84 // Drop into the kernel monitor (lab 1-2 only; not reached later)
91 * Variable panicstr contains argument to first call to panic; used as flag
92 * to indicate that the kernel has already called panic.
94 static const char *panicstr
;
97 * Panic is called on unresolvable fatal errors.
98 * It prints "panic: mesg", and then enters the kernel monitor.
101 _panic(const char *file
, int line
, const char *fmt
, ...)
109 // Be extra sure that the machine is in as reasonable state
110 __asm
__volatile("cli; cld");
113 cprintf("kernel panic at %s:%d: ", file
, line
);
119 /* break into the kernel monitor */
124 /* like panic, but don't */
126 _warn(const char *file
, int line
, const char *fmt
, ...)
131 cprintf("kernel warning at %s:%d: ", file
, line
);