pagetable lab initialized
This commit is contained in:
@ -26,13 +26,13 @@ static struct {
|
||||
static char digits[] = "0123456789abcdef";
|
||||
|
||||
static void
|
||||
printint(int xx, int base, int sign)
|
||||
printint(long long xx, int base, int sign)
|
||||
{
|
||||
char buf[16];
|
||||
int i;
|
||||
uint x;
|
||||
unsigned long long x;
|
||||
|
||||
if(sign && (sign = xx < 0))
|
||||
if(sign && (sign = (xx < 0)))
|
||||
x = -xx;
|
||||
else
|
||||
x = xx;
|
||||
@ -59,30 +59,71 @@ printptr(uint64 x)
|
||||
consputc(digits[x >> (sizeof(uint64) * 8 - 4)]);
|
||||
}
|
||||
|
||||
// Print to the console. only understands %d, %x, %p, %s.
|
||||
void
|
||||
// Print to the console.
|
||||
int
|
||||
printf(char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int i, c, locking;
|
||||
int i, cx, c0, c1, c2, locking;
|
||||
char *s;
|
||||
|
||||
locking = pr.locking;
|
||||
if(locking)
|
||||
acquire(&pr.lock);
|
||||
|
||||
if (fmt == 0)
|
||||
panic("null fmt");
|
||||
|
||||
va_start(ap, fmt);
|
||||
for(i = 0; (c = fmt[i] & 0xff) != 0; i++){
|
||||
if(c != '%'){
|
||||
consputc(c);
|
||||
for(i = 0; (cx = fmt[i] & 0xff) != 0; i++){
|
||||
if(cx != '%'){
|
||||
consputc(cx);
|
||||
continue;
|
||||
}
|
||||
c = fmt[++i] & 0xff;
|
||||
if(c == 0)
|
||||
i++;
|
||||
c0 = fmt[i+0] & 0xff;
|
||||
c1 = c2 = 0;
|
||||
if(c0) c1 = fmt[i+1] & 0xff;
|
||||
if(c1) c2 = fmt[i+2] & 0xff;
|
||||
if(c0 == 'd'){
|
||||
printint(va_arg(ap, int), 10, 1);
|
||||
} else if(c0 == 'l' && c1 == 'd'){
|
||||
printint(va_arg(ap, uint64), 10, 1);
|
||||
i += 1;
|
||||
} else if(c0 == 'l' && c1 == 'l' && c2 == 'd'){
|
||||
printint(va_arg(ap, uint64), 10, 1);
|
||||
i += 2;
|
||||
} else if(c0 == 'u'){
|
||||
printint(va_arg(ap, int), 10, 0);
|
||||
} else if(c0 == 'l' && c1 == 'u'){
|
||||
printint(va_arg(ap, uint64), 10, 0);
|
||||
i += 1;
|
||||
} else if(c0 == 'l' && c1 == 'l' && c2 == 'u'){
|
||||
printint(va_arg(ap, uint64), 10, 0);
|
||||
i += 2;
|
||||
} else if(c0 == 'x'){
|
||||
printint(va_arg(ap, int), 16, 0);
|
||||
} else if(c0 == 'l' && c1 == 'x'){
|
||||
printint(va_arg(ap, uint64), 16, 0);
|
||||
i += 1;
|
||||
} else if(c0 == 'l' && c1 == 'l' && c2 == 'x'){
|
||||
printint(va_arg(ap, uint64), 16, 0);
|
||||
i += 2;
|
||||
} else if(c0 == 'p'){
|
||||
printptr(va_arg(ap, uint64));
|
||||
} else if(c0 == 's'){
|
||||
if((s = va_arg(ap, char*)) == 0)
|
||||
s = "(null)";
|
||||
for(; *s; s++)
|
||||
consputc(*s);
|
||||
} else if(c0 == '%'){
|
||||
consputc('%');
|
||||
} else if(c0 == 0){
|
||||
break;
|
||||
} else {
|
||||
// Print unknown % sequence to draw attention.
|
||||
consputc('%');
|
||||
consputc(c0);
|
||||
}
|
||||
|
||||
#if 0
|
||||
switch(c){
|
||||
case 'd':
|
||||
printint(va_arg(ap, int), 10, 1);
|
||||
@ -108,11 +149,14 @@ printf(char *fmt, ...)
|
||||
consputc(c);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
if(locking)
|
||||
release(&pr.lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
@ -120,8 +164,7 @@ panic(char *s)
|
||||
{
|
||||
pr.locking = 0;
|
||||
printf("panic: ");
|
||||
printf(s);
|
||||
printf("\n");
|
||||
printf("%s\n", s);
|
||||
panicked = 1; // freeze uart output from other CPUs
|
||||
for(;;)
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user