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 "display.h"
|
||||||
#include "printk.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) {
|
static void print_u64(unsigned long long value, unsigned int base) {
|
||||||
char buf[32];
|
char buf[32];
|
||||||
@@ -22,7 +38,7 @@ static void print_u64(unsigned long long value, unsigned int base) {
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
if (value == 0) {
|
if (value == 0) {
|
||||||
display_putc('0');
|
printk_putc('0');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,12 +48,12 @@ static void print_u64(unsigned long long value, unsigned int base) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (i > 0) {
|
while (i > 0) {
|
||||||
display_putc(buf[--i]);
|
printk_putc(buf[--i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void aster_print(const char *text) {
|
void aster_print(const char *text) {
|
||||||
display_write(text);
|
printk_puts(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void printk(const char *fmt, ...) {
|
void printk(const char *fmt, ...) {
|
||||||
@@ -47,32 +63,29 @@ void printk(const char *fmt, ...) {
|
|||||||
|
|
||||||
while (*fmt) {
|
while (*fmt) {
|
||||||
if (*fmt != '%') {
|
if (*fmt != '%') {
|
||||||
display_putc(*fmt++);
|
printk_putc(*fmt++);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
++fmt;
|
++fmt;
|
||||||
switch (*fmt) {
|
switch (*fmt) {
|
||||||
case '%':
|
case '%':
|
||||||
display_putc('%');
|
printk_putc('%');
|
||||||
break;
|
break;
|
||||||
case 'c': {
|
case 'c': {
|
||||||
int c = va_arg(args, int);
|
int c = va_arg(args, int);
|
||||||
display_putc((char)c);
|
printk_putc((char)c);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 's': {
|
case 's': {
|
||||||
const char *s = va_arg(args, const char *);
|
const char *s = va_arg(args, const char *);
|
||||||
if (!s) {
|
printk_puts(s);
|
||||||
s = "(null)";
|
|
||||||
}
|
|
||||||
display_write(s);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'd': {
|
case 'd': {
|
||||||
long v = va_arg(args, int);
|
long v = va_arg(args, int);
|
||||||
if (v < 0) {
|
if (v < 0) {
|
||||||
display_putc('-');
|
printk_putc('-');
|
||||||
print_u64((unsigned long long)(-v), 10);
|
print_u64((unsigned long long)(-v), 10);
|
||||||
} else {
|
} else {
|
||||||
print_u64((unsigned long long)v, 10);
|
print_u64((unsigned long long)v, 10);
|
||||||
@@ -91,12 +104,12 @@ void printk(const char *fmt, ...) {
|
|||||||
}
|
}
|
||||||
case 'p': {
|
case 'p': {
|
||||||
unsigned long long v = (unsigned long long)va_arg(args, void *);
|
unsigned long long v = (unsigned long long)va_arg(args, void *);
|
||||||
display_write("0x");
|
printk_puts("0x");
|
||||||
print_u64(v, 16);
|
print_u64(v, 16);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
display_putc('?');
|
printk_putc('?');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
++fmt;
|
++fmt;
|
||||||
|
|||||||
Reference in New Issue
Block a user