From ad0bab89be500697f9a0e1f20d7cec8b4f008ffe Mon Sep 17 00:00:00 2001 From: Edgaru089 Date: Fri, 5 Nov 2021 14:29:48 +0800 Subject: [PATCH] main, runtime: init serial at EFI boot stage, use serial as output --- main.c | 3 +++ runtime/stdio.c | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/main.c b/main.c index 0e16eac..fc5c2ba 100644 --- a/main.c +++ b/main.c @@ -7,6 +7,7 @@ #include "graphics/graphics.h" #include "graphics/unifont.h" #include "memory/memory.h" +#include "driver/irq/pic/serial/serial.h" FASTCALL_ABI EFI_STATUS efiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) { @@ -22,6 +23,8 @@ FASTCALL_ABI EFI_STATUS efiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *System // disable the watchdog timer so that the application does not reset after 5mins efiBootServices->SetWatchdogTimer(0, 0, 0, NULL); + pic_serial_Init(&pic_serial_COM1, 115200, 0); + io_WriteConsole(PROJECT_NAME "\r\n\r\nAWAITING FOR USER INPUT"); // wait for a user keypress diff --git a/runtime/stdio.c b/runtime/stdio.c index 74a0e16..26bd79e 100644 --- a/runtime/stdio.c +++ b/runtime/stdio.c @@ -4,6 +4,7 @@ #include "printf.h" #include "../memory/memory.h" #include "../graphics/graphics.h" +#include "../driver/irq/pic/serial/serial.h" #include #include @@ -11,6 +12,8 @@ // printf wants this void _putchar(char c) { + pic_serial_Write(&pic_serial_COM1, &c, 1); + if (!graphics_Framebuffer) { UINT16 buf[2] = {c, 0}; efiStdout->OutputString(efiStdout, buf); @@ -43,6 +46,8 @@ void io_WriteConsole(const char *str) { int size = 0; // don't include the \0 at the end here int len = strlen(str); // left the \0 out here too + pic_serial_Write(&pic_serial_COM1, str, len); + for (int i = 0; i < len; i += utf8_Decode(str + i, len - i, NULL), size++) {} @@ -64,6 +69,8 @@ void io_WriteConsole(const char *str) { } void io_WriteConsoleASCII(const char *str) { + pic_serial_Write(&pic_serial_COM1, str, 0); + if (!graphics_Framebuffer) { int len = strlen(str); __io_WriteConsole_ResizeBuffer(len + 1);