Merge branch 'lab1' into lab2
This commit is contained in:
commit
d7a96eb60f
|
@ -17,6 +17,7 @@ KERN_SRCFILES := kern/entry.S \
|
|||
kern/entrypgdir.c \
|
||||
kern/init.c \
|
||||
kern/console.c \
|
||||
kern/ansi.c \
|
||||
kern/monitor.c \
|
||||
kern/pmap.c \
|
||||
kern/env.c \
|
||||
|
|
49
kern/ansi.c
Normal file
49
kern/ansi.c
Normal file
|
@ -0,0 +1,49 @@
|
|||
#include <kern/ansi.h>
|
||||
|
||||
uint8_t vga_colors[8] = {
|
||||
[0] = 0,
|
||||
[1] = 4,
|
||||
[2] = 2,
|
||||
[3] = 6,
|
||||
[4] = 1,
|
||||
[5] = 5,
|
||||
[6] = 3,
|
||||
[7] = 7
|
||||
};
|
||||
|
||||
void
|
||||
ansi_step(void (*putcf)(int), int c, struct AttrState* s) {
|
||||
switch(s->state) {
|
||||
case NORMAL:
|
||||
if(c != 27) putcf(c | (s->cattrs << 8));
|
||||
else s->state = ESC;
|
||||
return;
|
||||
case ESC:
|
||||
s->state = (c == '[') ? BRACKET : NORMAL;
|
||||
return;
|
||||
case BRACKET:
|
||||
if(c == '3') {
|
||||
s->state = COLOR_FG;
|
||||
} else if(c == '0') {
|
||||
s->state = COLOR;
|
||||
s->attrs = 0;
|
||||
} else {
|
||||
s->state = NORMAL;
|
||||
}
|
||||
return;
|
||||
case COLOR_FG:
|
||||
if(c >= '0' && c <= '9') {
|
||||
s->attrs = (s->attrs & ~(0x07)) | vga_colors[c - '0'];
|
||||
c |= ((c - '0') << 8);
|
||||
s->state = COLOR;
|
||||
} else {
|
||||
s->state = NORMAL;
|
||||
}
|
||||
return;
|
||||
case COLOR:
|
||||
s->state = (c == ';') ? BRACKET : NORMAL;
|
||||
if(c == 'm') s->cattrs = s->attrs;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
20
kern/ansi.h
Normal file
20
kern/ansi.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef _ANSI_H_
|
||||
#define _ANSI_H_
|
||||
|
||||
#include <inc/types.h>
|
||||
|
||||
struct AttrState {
|
||||
uint8_t cattrs;
|
||||
uint8_t attrs;
|
||||
enum {
|
||||
NORMAL,
|
||||
ESC,
|
||||
BRACKET,
|
||||
COLOR_FG,
|
||||
COLOR
|
||||
} state;
|
||||
};
|
||||
|
||||
void ansi_step(void (*putcf)(int), int c, struct AttrState* s);
|
||||
|
||||
#endif
|
|
@ -7,6 +7,7 @@
|
|||
#include <inc/assert.h>
|
||||
|
||||
#include <kern/console.h>
|
||||
#include <kern/ansi.h>
|
||||
|
||||
static void cons_intr(int (*proc)(void));
|
||||
static void cons_putc(int c);
|
||||
|
@ -128,6 +129,7 @@ lpt_putc(int c)
|
|||
static unsigned addr_6845;
|
||||
static uint16_t *crt_buf;
|
||||
static uint16_t crt_pos;
|
||||
static struct AttrState attst;
|
||||
|
||||
static void
|
||||
cga_init(void)
|
||||
|
@ -136,6 +138,10 @@ cga_init(void)
|
|||
uint16_t was;
|
||||
unsigned pos;
|
||||
|
||||
attst.cattrs = 0;
|
||||
attst.attrs = 0;
|
||||
attst.state = NORMAL;
|
||||
|
||||
cp = (uint16_t*) (KERNBASE + CGA_BUF);
|
||||
was = *cp;
|
||||
*cp = (uint16_t) 0xA55A;
|
||||
|
@ -157,10 +163,15 @@ cga_init(void)
|
|||
crt_pos = pos;
|
||||
}
|
||||
|
||||
|
||||
static void cga_putc_internal(int c);
|
||||
|
||||
static void
|
||||
cga_putc(int c)
|
||||
cga_putc(int c){
|
||||
ansi_step(cga_putc_internal, c, &attst);
|
||||
}
|
||||
|
||||
static void
|
||||
cga_putc_internal(int c)
|
||||
{
|
||||
// if no attribute given, then use black on white
|
||||
if (!(c & ~0xFF))
|
||||
|
|
|
@ -29,6 +29,14 @@ i386_init(void)
|
|||
// Lab 2 memory management initialization functions
|
||||
mem_init();
|
||||
|
||||
// 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");
|
||||
|
||||
// Drop into the kernel monitor.
|
||||
while (1)
|
||||
monitor(NULL);
|
||||
|
|
|
@ -171,7 +171,8 @@ debuginfo_eip(uintptr_t addr, struct Eipdebuginfo *info)
|
|||
|
||||
|
||||
// Search within [lline, rline] for the line number stab.
|
||||
// If found, set info->eip_line to the right line number.
|
||||
// If found, set info->eip_line to the correct line number.
|
||||
// e.g., info->eip_line = stabs[lline].n_desc
|
||||
// If not found, return -1.
|
||||
//
|
||||
// Hint:
|
||||
|
@ -179,6 +180,12 @@ debuginfo_eip(uintptr_t addr, struct Eipdebuginfo *info)
|
|||
// Look at the STABS documentation and <inc/stab.h> to find
|
||||
// which one.
|
||||
// Your code here.
|
||||
stab_binsearch(stabs, &lline, &rline, N_SLINE, addr);
|
||||
if(lline <= rline) {
|
||||
info->eip_line = stabs[lline].n_desc;
|
||||
} else {
|
||||
info->eip_line = -1;
|
||||
}
|
||||
|
||||
|
||||
// Search backwards from the line number for the relevant filename
|
||||
|
|
|
@ -25,6 +25,7 @@ struct Command {
|
|||
static struct Command commands[] = {
|
||||
{ "help", "Display this list of commands", mon_help },
|
||||
{ "kerninfo", "Display information about the kernel", mon_kerninfo },
|
||||
{ "backtrace", "Display current backtrace", mon_backtrace }
|
||||
};
|
||||
|
||||
/***** Implementations of basic kernel monitor commands *****/
|
||||
|
@ -61,6 +62,25 @@ mon_backtrace(int argc, char **argv, struct Trapframe *tf)
|
|||
// LAB 1: Your code here.
|
||||
// HINT 1: use read_ebp().
|
||||
// HINT 2: print the current ebp on the first line (not current_ebp[0])
|
||||
uint32_t* ebp;
|
||||
uint32_t eip;
|
||||
struct Eipdebuginfo info;
|
||||
|
||||
ebp = (uint32_t*) read_ebp();
|
||||
cprintf("Stack backtrace:\n");
|
||||
while(ebp) {
|
||||
eip = ebp[1];
|
||||
cprintf(" ebp %08x eip %08x args %08x %08x %08x %08x %08x\n",
|
||||
ebp, eip, ebp[2], ebp[3], ebp[4], ebp[5], ebp[6]);
|
||||
ebp = (uint32_t*) ebp[0];
|
||||
|
||||
debuginfo_eip(eip, &info);
|
||||
cprintf(" %s:%d: %.*s+%d\n",
|
||||
info.eip_file, info.eip_line,
|
||||
info.eip_fn_namelen, info.eip_fn_name,
|
||||
eip - info.eip_fn_addr);
|
||||
};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -205,11 +205,9 @@ vprintfmt(void (*putch)(int, void*), void *putdat, const char *fmt, va_list ap)
|
|||
|
||||
// (unsigned) octal
|
||||
case 'o':
|
||||
// LAB 1: Replace this with your code.
|
||||
putch('X', putdat);
|
||||
putch('X', putdat);
|
||||
putch('X', putdat);
|
||||
break;
|
||||
num = getuint(&ap, lflag);
|
||||
base = 8;
|
||||
goto number;
|
||||
|
||||
// pointer
|
||||
case 'p':
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
OSU ID (xxx-yyy-zzz) : 933456789
|
||||
FLIP ID (e.g., jangye) : jangye
|
||||
Name : Yeongjin Jang
|
||||
OSU ID (xxx-yyy-zzz) : 932700867
|
||||
FLIP ID (e.g., jangye) : fedorind
|
||||
Name : Danila Fedorin
|
||||
CS 444/544 ? : 444
|
||||
Lab Class # : Lab 1
|
||||
Lab Class # : Lab 2
|
||||
|
|
Loading…
Reference in New Issue
Block a user