diff --git a/src/hulk/hulk.d b/src/hulk/hulk.d index e702673..101be91 100644 --- a/src/hulk/hulk.d +++ b/src/hulk/hulk.d @@ -21,6 +21,7 @@ import hulk.pic; import hulk.acpi; import hulk.apic; import hulk.rtc; +import hulk.serial; extern extern(C) __gshared ubyte _hulk_bss_size; @@ -56,6 +57,7 @@ void hulk_start() { cli(); initialize_cpu(); + Serial.initialize(); Gdt.initialize(); Idt.initialize(); Fb.initialize(cast(uint *)Hurl.HULK_FRAMEBUFFER, diff --git a/src/hulk/klog.d b/src/hulk/klog.d index aaa1618..283f0b3 100644 --- a/src/hulk/klog.d +++ b/src/hulk/klog.d @@ -58,7 +58,7 @@ struct Klog } /** - * Write a formatted string and newline to the console. + * Write a formatted string and newline to the kernel log. * * @param s Format string. */ diff --git a/src/hulk/serial.d b/src/hulk/serial.d new file mode 100644 index 0000000..6249ae4 --- /dev/null +++ b/src/hulk/serial.d @@ -0,0 +1,74 @@ +/** + * Serial port access. + */ +module hulk.serial; + +import hulk.cpu; +import core.stdc.stdarg; +static import hulk.writef; + +struct Serial +{ + enum BASE_PORT = 0x3F8; + + /** + * Initialize the serial module. + */ + static void initialize() + { + } + + /** + * Write a character to the serial port. + * + * @param ch Character to write. + */ + static void write(ubyte ch) + { + if (ch == '\n') + { + out8(BASE_PORT, '\r'); + } + out8(BASE_PORT, ch); + } + + /** + * Write a formatted string to the serial port. + * + * @param s Format string. + * @param args Variable arguments structure. + */ + public static void writef(string s, va_list args) + { + hulk.writef.writef(s, args, function void(ubyte ch) { + Serial.write(ch); + }); + } + + /** + * Write a formatted string to the serial port. + * + * @param s Format string. + */ + public static extern (C) void writef(string s, ...) + { + va_list args; + va_start(args, s); + writef(s, args); + va_end(args); + } + + /** + * Write a formatted string and newline to the serial port. + * + * @param s Format string. + */ + public static extern (C) void writefln(string s, ...) + { + va_list args; + va_start(args, s); + writef(s, args); + writef("\n", args); + va_end(args); + } +}