[metal] Add a uprintf() routine, for non-emergency boot logging (#905)

* [metal] Add a uprintf() routine, for non-emergency boot logging
* [metal] _Really_ push forward timing of VGA TTY initialization
* [metal] Do something useful with uprintf()
* [metal] Locate some ACPI tables, for later hardware detection

Specifically the code now tries to find the ACPI RSDP,
RSDT/XSDT, FADT, & MADT tables, whether in legacy BIOS
bootup mode or in a UEFI bootup.  These are useful for
figuring out how to (re)enable asynchronous interrupts
in legacy 8259 PIC mode.
This commit is contained in:
tkchia 2023-10-26 05:32:20 +08:00 committed by GitHub
parent 062b2d776e
commit ed17d3008b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 999 additions and 36 deletions

View file

@ -91,12 +91,12 @@
vga_console:
.endobj vga_console,globl,hidden
.previous
.init.start 305,_init_vga
.init.start 101,_init_vga
push %rdi
push %rsi
call _vga_init
pop %rsi
pop %rdi
.init.end 305,_init_vga
.init.end 101,_init_vga
.yoink sys_writev_vga
.yoink sys_readv_vga

View file

@ -33,8 +33,8 @@
#ifdef __x86_64__
/*
* @fileoverview Instantiation of routines for emergency or system console
* output in graphical video modes.
* @fileoverview Instantiation of routines for emergency console output in
* graphical video modes.
*
* @see libc/vga/tty-graph.inc
*/

View file

@ -25,7 +25,10 @@
OTHER DEALINGS IN THE SOFTWARE.
*/
#include "libc/dce.h"
#include "libc/intrin/kprintf.h"
#include "libc/runtime/pc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/stack.h"
#include "libc/str/str.h"
#include "libc/vga/vga.internal.h"
@ -72,4 +75,47 @@ textstartup void _vga_init(void) {
}
}
#if !IsTiny()
/**
* Non-emergency console vprintf(), useful for dumping debugging or
* informational messages at program startup.
*
* @see uprintf()
*/
void uvprintf(const char *fmt, va_list v) {
if (!IsMetal()) {
kvprintf(fmt, v);
} else {
long size = __get_safe_size(8000, 3000);
char *buf = alloca(size);
CheckLargeStackAllocation(buf, size);
size_t count = kvsnprintf(buf, size, fmt, v);
if (count >= size) count = size - 1;
_TtyWrite(&_vga_tty, buf, count);
_klog_serial(buf, count);
}
}
/**
* Non-emergency console printf(), useful for dumping debugging or
* informational messages at program startup.
*
* uprintf() is similar to kprintf(), but on bare metal with VGA support, it
* uses the normal, fast graphical console, rather than initializing an
* emergency console. This makes uprintf() faster on bare metal at the
* expense of being less crash-proof.
*
* (The uprintf() function name comes from the FreeBSD kernel.)
*
* @see kprintf()
* @see https://man.freebsd.org/cgi/man.cgi?query=uprintf&sektion=9&n=1
*/
void uprintf(const char *fmt, ...) {
va_list v;
va_start(v, fmt);
uvprintf(fmt, v);
va_end(v);
}
#endif /* !IsTiny() */
#endif /* __x86_64__ */

View file

@ -255,8 +255,7 @@ void _TtyGraphMoveLineCells(struct Tty *, size_t, size_t, size_t, size_t,
size_t);
/*
* Routines that implement emergency or system console output in graphical
* video modes.
* Routines that implement emergency console output in graphical video modes.
*/
void _TtyKlog16Update(struct Tty *);
void _TtyKlog16DrawChar(struct Tty *, size_t, size_t, wchar_t);