stos: bootvid: Add boot console support

Signed-off-by: Chloe M. <chloe@mensia.org>
This commit is contained in:
Chloe M.
2026-06-22 03:40:34 +00:00
parent b2e4f35e9f
commit 26139ff1ab
5 changed files with 129 additions and 0 deletions
+85
View File
@@ -9,11 +9,64 @@
#include <drivers/bootvid/fbio.h> #include <drivers/bootvid/fbio.h>
#include <ke/bpal.h> #include <ke/bpal.h>
#include <ex/trace.h> #include <ex/trace.h>
#include <stdef.h>
#include "flanterm.h"
#include "flanterm_backends/fb.h"
#define DTRACE(Fmt, ...) \ #define DTRACE(Fmt, ...) \
TRACE("[ BOOTVID ]: " Fmt, ##__VA_ARGS__) TRACE("[ BOOTVID ]: " Fmt, ##__VA_ARGS__)
/* Bootcons attributes */
#define DEFAULT_BG 0x000000
#define DEFAULT_FG 0xFFB000
static BPAL_FRAMEBUFFER Framebuffer; static BPAL_FRAMEBUFFER Framebuffer;
static struct flanterm_context *FtCtx = NULL;
static BOOLEAN BootConsEnabled = false;
static BOOTCONS_ATTR DefaultConsAttr = {
.Foreground = DEFAULT_FG,
.Background = DEFAULT_BG
};
VOID
BootVidInitCons(BOOTCONS_ATTR *Attr)
{
if (BootConsEnabled) {
BootVidDeInitCons();
}
if (Attr == NULL) {
Attr = &DefaultConsAttr;
}
FtCtx = flanterm_fb_init(
NULL,
NULL,
Framebuffer.Address,
Framebuffer.Width,
Framebuffer.Height,
Framebuffer.Pitch,
Framebuffer.RedMaskSize,
Framebuffer.RedMaskShift,
Framebuffer.GreenMaskSize,
Framebuffer.GreenMaskShift,
Framebuffer.BlueMaskSize,
Framebuffer.BlueMaskShift,
NULL,
NULL,
NULL,
&Attr->Background,
&Attr->Foreground,
NULL,
NULL,
NULL,
0, 0, 0,
0, 0, 0, 0
);
BootConsEnabled = true;
DTRACE("bootcons enabled\n");
}
VOID VOID
BootVidInit(VOID) BootVidInit(VOID)
@@ -26,3 +79,35 @@ BootVidInit(VOID)
DTRACE("framebuffer width: %d\n", Framebuffer.Width); DTRACE("framebuffer width: %d\n", Framebuffer.Width);
DTRACE("framebuffer height: %d\n", Framebuffer.Height); DTRACE("framebuffer height: %d\n", Framebuffer.Height);
} }
VOID
BootVidConsWrite(const CHAR *String, USIZE Length)
{
if (String == NULL || Length == 0) {
return;
}
if (!BootConsEnabled) {
return;
}
flanterm_write(FtCtx, String, Length);
}
VOID
BootVidDeInitCons(VOID)
{
if (!BootConsEnabled) {
return;
}
flanterm_deinit(FtCtx, NULL);
FtCtx = NULL;
BootConsEnabled = false;
}
BOOLEAN
BootVidConsEn(VOID)
{
return BootConsEnabled;
}
+36
View File
@@ -11,9 +11,45 @@
#include <stdef.h> #include <stdef.h>
/*
* Boot console attributes
*
* @Background: Console background color
* @Foreground: Console foreground color
*/
typedef struct {
ULONG Background;
ULONG Foreground;
} BOOTCONS_ATTR;
/* /*
* Initialize the boot video driver * Initialize the boot video driver
*/ */
VOID BootVidInit(VOID); VOID BootVidInit(VOID);
/*
* Initialize the boot console
*
* @Attr: Attributes to set [NULL for default]
*/
VOID BootVidInitCons(BOOTCONS_ATTR *Attr);
/*
* Turn off the boot console
*/
VOID BootVidDeInitCons(VOID);
/*
* Write a string to the boot console
*
* @String: String to write
* @Length: Length of string to write
*/
VOID BootVidConsWrite(const CHAR *String, USIZE Length);
/*
* Returns true if the boot console is enabled
*/
BOOLEAN BootVidConsEn(VOID);
#endif /* !_BOOTVID_FBIO_H_ */ #endif /* !_BOOTVID_FBIO_H_ */
+3
View File
@@ -40,4 +40,7 @@ KiKernelEntry(VOID)
/* Initialize boot video */ /* Initialize boot video */
BootVidInit(); BootVidInit();
/* Init bootcons */
BootVidInitCons(NULL);
} }
+1
View File
@@ -24,6 +24,7 @@ CFLAGS = \
-MMD \ -MMD \
-DPRINTF_DISABLE_SUPPORT_PTRDIFF_T \ -DPRINTF_DISABLE_SUPPORT_PTRDIFF_T \
-DPRINTF_DISABLE_SUPPORT_FLOAT \ -DPRINTF_DISABLE_SUPPORT_FLOAT \
-I../xt/flanterm/src \
-I../head \ -I../head \
-I../target \ -I../target \
-I$(ST_PROJECT_ROOT)/paw/spkg/head \ -I$(ST_PROJECT_ROOT)/paw/spkg/head \
+4
View File
@@ -7,9 +7,13 @@
*/ */
#include <hal/serial.h> #include <hal/serial.h>
#include <drivers/bootvid/fbio.h>
void void
_putchar(char c) _putchar(char c)
{ {
HalSerialWrite(&c, 1); HalSerialWrite(&c, 1);
if (BootVidConsEn()) {
BootVidConsWrite(&c, 1);
}
} }