term: Misc improvements for SERIAL=yes on EFI

This commit is contained in:
mintsuki 2022-10-06 05:29:13 +02:00
parent 33dac9b38a
commit ff145eb511
6 changed files with 25 additions and 40 deletions

View File

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

View File

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

View File

@ -36,6 +36,8 @@ noreturn void uefi_entry(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS status;
gST->ConOut->EnableCursor(gST->ConOut, false);
term_fallback();
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;
}
#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
&& term_backend == GTERM
&& fbinfo.default_res == true

View File

@ -219,6 +219,7 @@ out:
outb(0xe9, print_buf[i]);
}
#endif
#if defined (BIOS)
if ((!quiet && serial) || COM_OUTPUT) {
switch (print_buf[i]) {
case '\n':
@ -234,5 +235,6 @@ out:
}
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) {
(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];
string[0] = c;
string[1] = 0;
@ -229,9 +232,6 @@ void term_fallback(void) {
if (!efi_boot_services_exited) {
#endif
fallback_clear(NULL, true);
#if defined (UEFI)
gST->ConOut->EnableCursor(gST->ConOut, false);
#endif
term->raw_putchar = fallback_raw_putchar;
term->clear = fallback_clear;
term->set_cursor_pos = fallback_set_cursor_pos;