Napojen printk na COM1, výstup se teď zrcadlí na VGA i sériový port
This commit is contained in:
+26
-13
@@ -15,6 +15,22 @@
|
||||
|
||||
#include "display.h"
|
||||
#include "printk.h"
|
||||
#include "serial.h"
|
||||
|
||||
static void printk_putc(char c) {
|
||||
display_putc(c);
|
||||
serial_write_char(c);
|
||||
}
|
||||
|
||||
static void printk_puts(const char *s) {
|
||||
if (!s) {
|
||||
s = "(null)";
|
||||
}
|
||||
|
||||
while (*s) {
|
||||
printk_putc(*s++);
|
||||
}
|
||||
}
|
||||
|
||||
static void print_u64(unsigned long long value, unsigned int base) {
|
||||
char buf[32];
|
||||
@@ -22,7 +38,7 @@ static void print_u64(unsigned long long value, unsigned int base) {
|
||||
int i = 0;
|
||||
|
||||
if (value == 0) {
|
||||
display_putc('0');
|
||||
printk_putc('0');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -32,12 +48,12 @@ static void print_u64(unsigned long long value, unsigned int base) {
|
||||
}
|
||||
|
||||
while (i > 0) {
|
||||
display_putc(buf[--i]);
|
||||
printk_putc(buf[--i]);
|
||||
}
|
||||
}
|
||||
|
||||
void aster_print(const char *text) {
|
||||
display_write(text);
|
||||
printk_puts(text);
|
||||
}
|
||||
|
||||
void printk(const char *fmt, ...) {
|
||||
@@ -47,32 +63,29 @@ void printk(const char *fmt, ...) {
|
||||
|
||||
while (*fmt) {
|
||||
if (*fmt != '%') {
|
||||
display_putc(*fmt++);
|
||||
printk_putc(*fmt++);
|
||||
continue;
|
||||
}
|
||||
|
||||
++fmt;
|
||||
switch (*fmt) {
|
||||
case '%':
|
||||
display_putc('%');
|
||||
printk_putc('%');
|
||||
break;
|
||||
case 'c': {
|
||||
int c = va_arg(args, int);
|
||||
display_putc((char)c);
|
||||
printk_putc((char)c);
|
||||
break;
|
||||
}
|
||||
case 's': {
|
||||
const char *s = va_arg(args, const char *);
|
||||
if (!s) {
|
||||
s = "(null)";
|
||||
}
|
||||
display_write(s);
|
||||
printk_puts(s);
|
||||
break;
|
||||
}
|
||||
case 'd': {
|
||||
long v = va_arg(args, int);
|
||||
if (v < 0) {
|
||||
display_putc('-');
|
||||
printk_putc('-');
|
||||
print_u64((unsigned long long)(-v), 10);
|
||||
} else {
|
||||
print_u64((unsigned long long)v, 10);
|
||||
@@ -91,12 +104,12 @@ void printk(const char *fmt, ...) {
|
||||
}
|
||||
case 'p': {
|
||||
unsigned long long v = (unsigned long long)va_arg(args, void *);
|
||||
display_write("0x");
|
||||
printk_puts("0x");
|
||||
print_u64(v, 16);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
display_putc('?');
|
||||
printk_putc('?');
|
||||
break;
|
||||
}
|
||||
++fmt;
|
||||
|
||||
Reference in New Issue
Block a user