term: Misc improvements for SERIAL=yes on EFI

This commit is contained in:
mintsuki 2022-10-06 05:29:13 +02:00
parent 610a98d8b2
commit 7f09259c57
6 changed files with 25 additions and 40 deletions

View File

@ -1,12 +1,13 @@
#ifndef __DRIVERS__SERIAL_H__ #ifndef __DRIVERS__SERIAL_H__
#define __DRIVERS__SERIAL_H__ #define __DRIVERS__SERIAL_H__
#if defined (BIOS)
#include <stdint.h> #include <stdint.h>
void serial_out(uint8_t b); void serial_out(uint8_t b);
#if defined (BIOS)
int serial_in(void); int serial_in(void);
#endif #endif
#endif #endif

View File

@ -1,38 +1,19 @@
#if defined (BIOS)
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <stdbool.h> #include <stdbool.h>
#include <drivers/serial.h> #include <drivers/serial.h>
#include <sys/cpu.h> #include <sys/cpu.h>
#include <lib/misc.h> #include <lib/misc.h>
#if defined (UEFI)
# include <efi.h>
#endif
static bool serial_initialised = false; static bool serial_initialised = false;
#if defined (UEFI)
static EFI_SERIAL_IO_PROTOCOL *serial_protocol;
#endif
static void serial_initialise(void) { static void serial_initialise(void) {
if (serial_initialised) { if (serial_initialised) {
return; return;
} }
#if defined (UEFI)
EFI_STATUS status;
EFI_GUID serial_guid = EFI_SERIAL_IO_PROTOCOL_GUID;
status = gBS->LocateProtocol(&serial_guid, NULL, (void **)&serial_protocol);
if (status) {
return;
}
serial_protocol->Reset(serial_protocol);
#endif
#if defined (BIOS)
// Init com1 // Init com1
outb(0x3f8 + 3, 0x00); outb(0x3f8 + 3, 0x00);
outb(0x3f8 + 1, 0x00); outb(0x3f8 + 1, 0x00);
@ -42,30 +23,17 @@ static void serial_initialise(void) {
outb(0x3f8 + 3, 0x03); outb(0x3f8 + 3, 0x03);
outb(0x3f8 + 2, 0xc7); outb(0x3f8 + 2, 0xc7);
outb(0x3f8 + 4, 0x0b); outb(0x3f8 + 4, 0x0b);
#endif
serial_initialised = true; serial_initialised = true;
} }
void serial_out(uint8_t b) { void serial_out(uint8_t b) {
#if defined (UEFI)
if (efi_boot_services_exited) {
return;
}
#endif
serial_initialise(); serial_initialise();
#if defined (UEFI)
UINTN bsize = 1;
serial_protocol->Write(serial_protocol, &bsize, &b);
#elif defined (BIOS)
while ((inb(0x3f8 + 5) & 0x20) == 0); while ((inb(0x3f8 + 5) & 0x20) == 0);
outb(0x3f8, b); outb(0x3f8, b);
#endif
} }
#if defined (BIOS)
int serial_in(void) { int serial_in(void) {
serial_initialise(); serial_initialise();
@ -74,4 +42,5 @@ int serial_in(void) {
} }
return inb(0x3f8); return inb(0x3f8);
} }
#endif #endif

View File

@ -36,6 +36,8 @@ noreturn void uefi_entry(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS status; EFI_STATUS status;
gST->ConOut->EnableCursor(gST->ConOut, false);
term_fallback(); term_fallback();
status = gBS->SetWatchdogTimer(0, 0x10000, 0, NULL); status = gBS->SetWatchdogTimer(0, 0x10000, 0, NULL);

View File

@ -545,6 +545,17 @@ bool gterm_init(char *config, size_t width, size_t height) {
return false; return false;
} }
#if defined (UEFI)
if (serial || COM_OUTPUT) {
if (term != NULL) {
term->deinit(term, pmm_free);
term = NULL;
}
term_fallback();
return true;
}
#endif
if (term != NULL if (term != NULL
&& term_backend == GTERM && term_backend == GTERM
&& fbinfo.default_res == true && fbinfo.default_res == true

View File

@ -238,6 +238,7 @@ out:
outb(0xe9, print_buf[i]); outb(0xe9, print_buf[i]);
} }
#endif #endif
#if defined (BIOS)
if ((!quiet && serial) || COM_OUTPUT) { if ((!quiet && serial) || COM_OUTPUT) {
switch (print_buf[i]) { switch (print_buf[i]) {
case '\n': case '\n':
@ -253,5 +254,6 @@ out:
} }
serial_out(print_buf[i]); serial_out(print_buf[i]);
} }
#endif
} }
} }

View File

@ -182,7 +182,10 @@ static void fallback_scroll(struct term_context *ctx) {
} }
static void fallback_raw_putchar(struct term_context *ctx, uint8_t c) { static void fallback_raw_putchar(struct term_context *ctx, uint8_t c) {
(void)ctx; if (!ctx->scroll_enabled && cursor_x == term->cols - 1 && cursor_y == term->rows - 1) {
return;
}
gST->ConOut->EnableCursor(gST->ConOut, true);
CHAR16 string[2]; CHAR16 string[2];
string[0] = c; string[0] = c;
string[1] = 0; string[1] = 0;
@ -229,9 +232,6 @@ void term_fallback(void) {
if (!efi_boot_services_exited) { if (!efi_boot_services_exited) {
#endif #endif
fallback_clear(NULL, true); fallback_clear(NULL, true);
#if defined (UEFI)
gST->ConOut->EnableCursor(gST->ConOut, false);
#endif
term->raw_putchar = fallback_raw_putchar; term->raw_putchar = fallback_raw_putchar;
term->clear = fallback_clear; term->clear = fallback_clear;
term->set_cursor_pos = fallback_set_cursor_pos; term->set_cursor_pos = fallback_set_cursor_pos;