2018-08-30 12:17:20 -07:00
|
|
|
/* See COPYRIGHT for copyright information. */
|
|
|
|
|
|
|
|
#include <inc/stdio.h>
|
|
|
|
#include <inc/string.h>
|
|
|
|
#include <inc/assert.h>
|
|
|
|
|
|
|
|
#include <kern/monitor.h>
|
|
|
|
#include <kern/console.h>
|
2018-09-12 11:55:07 -07:00
|
|
|
#include <kern/pmap.h>
|
|
|
|
#include <kern/kclock.h>
|
2018-08-30 12:17:20 -07:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
i386_init(void)
|
|
|
|
{
|
|
|
|
extern char edata[], end[];
|
|
|
|
|
|
|
|
// Before doing anything else, complete the ELF loading process.
|
|
|
|
// Clear the uninitialized global data (BSS) section of our program.
|
|
|
|
// This ensures that all static/global variables start out zero.
|
|
|
|
memset(edata, 0, end - edata);
|
|
|
|
|
|
|
|
// Initialize the console.
|
|
|
|
// Can't call cprintf until after we do this!
|
|
|
|
cons_init();
|
|
|
|
|
2019-03-31 23:09:16 -07:00
|
|
|
cprintf("444544 decimal is %o octal!\n", 444544);
|
2018-08-30 12:17:20 -07:00
|
|
|
|
2018-09-12 11:55:07 -07:00
|
|
|
// Lab 2 memory management initialization functions
|
|
|
|
mem_init();
|
2018-08-30 12:17:20 -07:00
|
|
|
|
2019-04-04 21:46:17 -07:00
|
|
|
// Test ANSI color escape codes
|
|
|
|
cprintf("\33[31m" "C"
|
|
|
|
"\33[33m" "o"
|
|
|
|
"\33[32m" "l"
|
|
|
|
"\33[36m" "o"
|
|
|
|
"\33[34m" "r"
|
|
|
|
"\33[0m" " Works!" "\n");
|
|
|
|
|
2018-08-30 12:17:20 -07:00
|
|
|
// Drop into the kernel monitor.
|
|
|
|
while (1)
|
|
|
|
monitor(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Variable panicstr contains argument to first call to panic; used as flag
|
|
|
|
* to indicate that the kernel has already called panic.
|
|
|
|
*/
|
|
|
|
const char *panicstr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Panic is called on unresolvable fatal errors.
|
|
|
|
* It prints "panic: mesg", and then enters the kernel monitor.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
_panic(const char *file, int line, const char *fmt,...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
if (panicstr)
|
|
|
|
goto dead;
|
|
|
|
panicstr = fmt;
|
|
|
|
|
|
|
|
// Be extra sure that the machine is in as reasonable state
|
|
|
|
asm volatile("cli; cld");
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
cprintf("kernel panic at %s:%d: ", file, line);
|
|
|
|
vcprintf(fmt, ap);
|
|
|
|
cprintf("\n");
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
dead:
|
|
|
|
/* break into the kernel monitor */
|
|
|
|
while (1)
|
|
|
|
monitor(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* like panic, but don't */
|
|
|
|
void
|
|
|
|
_warn(const char *file, int line, const char *fmt,...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
cprintf("kernel warning at %s:%d: ", file, line);
|
|
|
|
vcprintf(fmt, ap);
|
|
|
|
cprintf("\n");
|
|
|
|
va_end(ap);
|
|
|
|
}
|