Files
LithosAnanake/include/starkernel/console.h
T
Robert Allan JamesandClaude Sonnet 5 b0f12710bb Console-VM + user-VM pair: real async message-passing relay
Console sessions now route through the same general VM-to-VM messaging
system (Phase C) any VM can already use for its own reasons -- not a
synchronous shortcut. Per direct instruction: real async MSG-SEND/
MSG-DELIVER (Option B), not a VM-EXEC-based synchronous relay, because
messaging is a general capability, not a console-specific mechanism.

New CONSOLE-CMD-EVENT message type (common:messaging.4th). New
sk_repl_dispatch_line() (repl.c), called from both sk_repl_step and
sk_repl_run in place of a direct vm_interpret(): if the active VM's own
name has a live "<name>~user" counterpart registered, the raw input
line is wrapped as an S"-embedded CONSOLE-CMD-EVENT MSG-SEND and
interpreted on the console VM instead of being run directly -- the
console's own next MSG-TICK (Hera's idle pump) delivers it into the
paired user VM via VM-EXEC, same mechanism every other message already
uses. Falls back to direct interpretation if there's no pairing, or if
the line contains a `"` (known v1 limitation, warned about explicitly
rather than silently mishandled).

New capsule_console_birth() (capsule_console.h/.c): a bare VM whose
only content is loading common:messaging.4th -- the console side of a
pairing, parallel in shape to RUNCAP's user-VM birth but with fixed
embedded content instead of a devblock read (no identity, no thumbdrive
involved). New PAIR-TEST diagnostic word (mama_forth_words.c, matches
RUNCAP-TEST's own precedent): births both halves of a pairing and
registers the "<name>~user" mapping. Not the real pairing call site --
that's the eventual attach/onboarding flow -- this exists to exercise
the relay live before that flow exists.

Found and fixed a real, serious bug live: console_set_vm_name() stored
the caller's raw pointer instead of copying it. mama_word_use() (USE)
passes a VMRegistryEntry field living on its own stack frame -- once
USE returns, that pointer dangles, corrupting every console tag after
the first USE (observed directly as garbled "[[]" / binary-looking
prefixes instead of "[CaptBob]"). Fixed at the source: console_set_
vm_name() now copies into internal storage. That surfaced a second,
related bug across every console_get_vm_name()-based save/restore call
site in mama_forth_words.c (BIRTH, VM-STEP, VM-EXEC, CONNECT-HERMES,
CONNECT-ARTEMIS): saving just a pointer into the single internal buffer
meant an intervening console_set_vm_name() call silently corrupted the
saved value before the restore ever ran. New console_save_vm_name()
copies into caller-owned storage; every save/restore site updated.

Verified end-to-end, live in QEMU: typed WELCOME at a paired console
VM -- it did not execute directly (no UNKNOWN WORD), printed ok
immediately (queued, async), and on the next idle tick
"[CaptBob~user] Minted identity -- default personality" appeared on
its own -- genuine delivery and execution in the paired user VM through
the real MSG-SEND/MSG-DELIVER pipeline. Console tags confirmed clean
(no garbling) across all three architectures' full regression boot.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019ZGkimpfyh63EZyRkNbkPD
2026-08-28 16:39:07 -04:00

174 lines
5.7 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
StarForth — Steady-State Virtual Machine Runtime
Copyright (c) 20232025 Robert A. James
All rights reserved.
This file is part of the StarForth project.
Licensed under the StarForth License, Version 1.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at:
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
express or implied, including but not limited to the warranties of
merchantability, fitness for a particular purpose, and noninfringement.
See the License for the specific language governing permissions and
limitations under the License.
StarForth — Steady-State Virtual Machine Runtime
Copyright (c) 20232025 Robert A. James
All rights reserved.
This file is part of the StarForth project.
Licensed under the StarForth License, Version 1.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at:
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
express or implied, including but not limited to the warranties of
merchantability, fitness for a particular purpose, and noninfringement.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* console.h - Serial console + framebuffer VT100 interface for StarKernel
*
* Output policy:
* - Serial UART is always active (initialized by console_init).
* - When console_fb_init() has been called and the framebuffer is ready,
* every character is also rendered through the VT100 terminal on screen.
* - Both outputs are always live simultaneously; serial cannot be disabled.
*/
#ifndef STARKERNEL_CONSOLE_H
#define STARKERNEL_CONSOLE_H
#include <stdint.h>
#include <stddef.h>
#include "uefi.h"
/**
* Initialize serial console (UART).
* Must be called once during early kernel boot.
*/
void console_init(void);
/**
* Initialize the framebuffer VT100 terminal.
* Call after UEFI boot services have been exited and the GOP framebuffer
* address is known (from BootInfo). Safe to call with info==NULL (no-op).
* fmt: FB_PIXEL_BGRX32 is correct for most QEMU / real hardware GOP.
*/
#include "framebuffer.h"
void console_fb_init(const FramebufferInfo *info, FbPixelFormat fmt);
/**
* FABRIC.md item 4.4j: switch the framebuffer console's glyph backend from
* font_8x16.c to TTF-TEXT's rasterizer. Thin wrapper over
* vt100_enable_ttf() -- see that function's doc comment for the full
* contract (lazy font load, cell-geometry/cols/rows recompute, screen
* clear, one-shot). No-op if the framebuffer console was never
* initialized (console_fb_init() not called, or it no-op'd on a NULL
* framebuffer).
*/
void console_fb_enable_ttf(void);
/**
* FABRIC.md item 4.4q: thin wrappers over vt100_scroll_back()/
* vt100_scroll_fwd() -- see those functions' doc comments for the full
* contract. No-op if the framebuffer console was never initialized.
*/
void console_fb_scroll_back(uint32_t n);
void console_fb_scroll_fwd(uint32_t n);
/**
* FABRIC.md item 4.4y-revised: thin wrapper over vt100_toggle_graphics()
* -- see that function's doc comment for the full contract (the
* Alt+TAB graphics/text state machine). No-op if the framebuffer console
* was never initialized.
*/
void console_fb_toggle_graphics(void);
/**
* Thin wrapper over vt100_draw_cursor() -- see that function's doc
* comment for the full contract (a static block cursor at the terminal's
* current position). No-op if the framebuffer console was never
* initialized.
*/
void console_fb_draw_cursor(void);
/**
* Thin wrapper over vt100_erase_cursor(). No-op if the framebuffer
* console was never initialized.
*/
void console_fb_erase_cursor(void);
/**
* Write a single character to serial console
*/
void console_putc(char c);
/**
* Write a null-terminated string to serial console
*/
void console_puts(const char *s);
/**
* Write a string with newline to serial console
*/
void console_println(const char *s);
/**
* Read a single character from serial console (non-blocking)
* Returns -1 if no character available
*/
int console_getc(void);
/**
* Check if character is available for reading
*/
int console_poll(void);
/**
* Set the active VM name shown as [Name] prefix on each output line.
* Pass NULL to suppress the prefix (kernel-only output before any VM).
* Copies into internal storage (FABRIC-3.md Phase F, 2026-08-28) -- the
* caller's own pointer does not need to remain valid afterward.
*/
void console_set_vm_name(const char *name);
const char *console_get_vm_name(void);
/**
* console_save_vm_name - Copy the current active-VM name into the
* caller's own buffer, for a later console_set_vm_name() restore.
*
* console_get_vm_name() alone is NOT safe for save-then-restore: it
* returns a pointer into the single internal buffer console_set_vm_name()
* copies into, so an intervening console_set_vm_name() call (the normal
* "switch, do work, switch back" pattern every BIRTH/VM-EXEC/CONNECT-*
* call site uses) overwrites the very bytes the saved pointer points at
* before the restore ever runs -- found live 2026-08-28, the restore
* silently no-ops. Copies at most cap-1 bytes plus a NUL terminator;
* writes "" if there was no active name (NULL) to save.
*
* @param out Caller-owned buffer.
* @param cap Its size in bytes.
*/
void console_save_vm_name(char *out, size_t cap);
/* Last FORTH word name set by the dispatcher before entry->func(vm).
* Printed by the #GP fault handler to identify the faulting word. */
extern volatile const char *g_sk_fault_word;
#endif /* STARKERNEL_CONSOLE_H */