diff --git a/paw/stos/drivers/bootvid/fbio.c b/paw/stos/drivers/bootvid/fbio.c index 20c6b3d..9e2475a 100644 --- a/paw/stos/drivers/bootvid/fbio.c +++ b/paw/stos/drivers/bootvid/fbio.c @@ -9,11 +9,64 @@ #include #include #include +#include +#include "flanterm.h" +#include "flanterm_backends/fb.h" #define DTRACE(Fmt, ...) \ TRACE("[ BOOTVID ]: " Fmt, ##__VA_ARGS__) +/* Bootcons attributes */ +#define DEFAULT_BG 0x000000 +#define DEFAULT_FG 0xFFB000 + 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 BootVidInit(VOID) @@ -26,3 +79,35 @@ BootVidInit(VOID) DTRACE("framebuffer width: %d\n", Framebuffer.Width); 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; +} diff --git a/paw/stos/head/drivers/bootvid/fbio.h b/paw/stos/head/drivers/bootvid/fbio.h index 84431b4..2595d94 100644 --- a/paw/stos/head/drivers/bootvid/fbio.h +++ b/paw/stos/head/drivers/bootvid/fbio.h @@ -11,9 +11,45 @@ #include +/* + * Boot console attributes + * + * @Background: Console background color + * @Foreground: Console foreground color + */ +typedef struct { + ULONG Background; + ULONG Foreground; +} BOOTCONS_ATTR; + /* * Initialize the boot video driver */ 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_ */ diff --git a/paw/stos/init/init.c b/paw/stos/init/init.c index e1315f9..23c50fb 100644 --- a/paw/stos/init/init.c +++ b/paw/stos/init/init.c @@ -40,4 +40,7 @@ KiKernelEntry(VOID) /* Initialize boot video */ BootVidInit(); + + /* Init bootcons */ + BootVidInitCons(NULL); } diff --git a/paw/stos/ke/Makefile b/paw/stos/ke/Makefile index 6238440..778091b 100644 --- a/paw/stos/ke/Makefile +++ b/paw/stos/ke/Makefile @@ -24,6 +24,7 @@ CFLAGS = \ -MMD \ -DPRINTF_DISABLE_SUPPORT_PTRDIFF_T \ -DPRINTF_DISABLE_SUPPORT_FLOAT \ + -I../xt/flanterm/src \ -I../head \ -I../target \ -I$(ST_PROJECT_ROOT)/paw/spkg/head \ diff --git a/paw/stos/lib/_printf.c b/paw/stos/lib/_printf.c index 3f05fe6..a89a649 100644 --- a/paw/stos/lib/_printf.c +++ b/paw/stos/lib/_printf.c @@ -7,9 +7,13 @@ */ #include +#include void _putchar(char c) { HalSerialWrite(&c, 1); + if (BootVidConsEn()) { + BootVidConsWrite(&c, 1); + } }