diff options
Diffstat (limited to 'console.c')
| -rw-r--r-- | console.c | 30 | 
1 files changed, 23 insertions, 7 deletions
| @@ -2,6 +2,8 @@  // Input is from the keyboard or serial port.  // Output is written to the screen and serial port. +#include <stdarg.h> +  #include "types.h"  #include "defs.h"  #include "param.h" @@ -24,10 +26,11 @@ static struct {    int locking;  } cons; +static char digits[] = "0123456789abcdef"; +  static void  printint(int xx, int base, int sign)  { -  static char digits[] = "0123456789abcdef";    char buf[16];    int i;    uint x; @@ -48,14 +51,25 @@ printint(int xx, int base, int sign)    while(--i >= 0)      consputc(buf[i]);  } + +static void +printptr(uint64 x) { +  int i; +  consputc('0'); +  consputc('x'); +  for (i = 0; i < (sizeof(uint64) * 2); i++, x <<= 4) +    consputc(digits[x >> (sizeof(uint64) * 8 - 4)]); +} + +  //PAGEBREAK: 50  // Print to the console. only understands %d, %x, %p, %s.  void  cprintf(char *fmt, ...)  { +  va_list ap;    int i, c, locking; -  uint *argp;    char *s;    locking = cons.locking; @@ -65,7 +79,7 @@ cprintf(char *fmt, ...)    if (fmt == 0)      panic("null fmt"); -  argp = (uint*)(void*)(&fmt + 1); +  va_start(ap, fmt);    for(i = 0; (c = fmt[i] & 0xff) != 0; i++){      if(c != '%'){        consputc(c); @@ -76,14 +90,16 @@ cprintf(char *fmt, ...)        break;      switch(c){      case 'd': -      printint(*argp++, 10, 1); +      printint(va_arg(ap, int), 10, 1);        break;      case 'x': +      printint(va_arg(ap, int), 16, 1); +      break;      case 'p': -      printint(*argp++, 16, 0); +      printptr(va_arg(ap, uint64));        break;      case 's': -      if((s = (char*)*argp++) == 0) +      if((s = va_arg(ap, char*)) == 0)          s = "(null)";        for(; *s; s++)          consputc(*s); @@ -107,7 +123,7 @@ void  panic(char *s)  {    int i; -  uint pcs[10]; +  uint64 pcs[10];    cli();    cons.locking = 0; | 
