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 // Test the stack backtrace function (used in lab 1 only)
17 cprintf("entering test_backtrace %d\n", x
);
21 mon_backtrace(0, 0, 0);
22 cprintf("leaving test_backtrace %d\n", x
);
25 // Test kernel breakpoint functionality (used in lab 2 only)
26 static void test_kernel_breakpoint(void) __attribute__((noinline
));
28 test_kernel_breakpoint(void)
30 __asm__
__volatile__("int3");
31 // Then the breakpoint should return (after the user types 'exit')
32 cprintf("Breakpoint succeeded!\n");
38 extern char edata
[], end
[];
39 extern const uintptr_t sctors
[], ectors
[];
40 const uintptr_t *ctorva
;
42 // Initialize the console.
43 // Can't call cprintf until after we do this!
46 // Then call any global constructors (e.g., defined by C++).
47 // This relies on linker script magic to define the 'sctors' and
48 // 'ectors' symbols; see kern/kernel.ld.
49 // Call after cons_init() so we can cprintf() if necessary.
50 for (ctorva
= ectors
; ctorva
> sctors
; )
51 ((void(*)()) *--ctorva
)();
53 cprintf("6828 decimal is %o octal!\n", 6828);
55 // Lab 2 memory management initialization functions
58 // Lab 2 interrupt and gate descriptor initialization functions
64 // Test IDT (lab 2 only)
65 test_kernel_breakpoint();
67 // Test the stack backtrace function (lab 1 only)
70 // Drop into the kernel monitor.
77 * Variable panicstr contains argument to first call to panic; used as flag
78 * to indicate that the kernel has already called panic.
80 static const char *panicstr
;
83 * Panic is called on unresolvable fatal errors.
84 * It prints "panic: mesg", and then enters the kernel monitor.
87 _panic(const char *file
, int line
, const char *fmt
, ...)
95 // Be extra sure that the machine is in as reasonable state
96 __asm
__volatile("cli; cld");
99 cprintf("kernel panic at %s:%d: ", file
, line
);
105 /* break into the kernel monitor */
110 /* like panic, but don't */
112 _warn(const char *file
, int line
, const char *fmt
, ...)
117 cprintf("kernel warning at %s:%d: ", file
, line
);