[metal] Some minor fixes and tweaks (#933)

* [metal] Ensure DF is clear when calling C from exception handler
* [metal] Mark some internal routines and declarations as `@internal`
* [metal] Fix crash under UEFI when command line string is NULL
* [metal] Fix argc & argv[] setting, & VM page freeing, for UEFI

Part of the memory occupied by the argv[] contents was
erroneously used for page tables & then later erroneously
freed.  The symptom was that argv[0] would show up as an
empty string ("").
This commit is contained in:
tkchia 2023-11-15 07:26:59 +08:00 committed by GitHub
parent 1c2e7c1333
commit eea601f346
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 76 additions and 20 deletions

View file

@ -30,6 +30,7 @@
#include "libc/vga/vga.internal.h"
/**
* @internal
* @fileoverview Instantiation of routines for normal console output in
* graphical video modes.
*

View file

@ -31,6 +31,7 @@
#include "libc/vga/vga.internal.h"
/**
* @internal
* @fileoverview Template for routines to support output in graphical video
* modes for bare metal VGA.
*

View file

@ -33,6 +33,7 @@
#ifdef __x86_64__
/**
* @internal
* @fileoverview ECMA-48 / VT100 video terminal implementation for bare
* metal VGA.
*
@ -325,6 +326,7 @@ static void TtySetCodepage(struct Tty *tty, char id) {
}
/**
* @internal
* Map the given direct color value to one of the 16 basic foreground colors
* or one of the 16 background colors.
*
@ -344,6 +346,7 @@ static uint8_t TtyGetTextColor(TtyCanvasColor color) {
}
/**
* @internal
* Map the currently active foreground & background colors & terminal
* configuration to a VGA text character attribute byte.
*
@ -794,12 +797,18 @@ static void TtyCsiN(struct Tty *tty) {
}
}
/** Create a direct color pixel value. */
/**
* @internal
* Create a direct color pixel value.
*/
static TtyCanvasColor TtyMapTrueColor(uint8_t r, uint8_t g, uint8_t b) {
return (TtyCanvasColor){.bgr.r = r, .bgr.g = g, .bgr.b = b, .bgr.x = 0xff};
}
/** Map the given 256-color code to a direct color. */
/**
* @internal
* Map the given 256-color code to a direct color.
*/
static TtyCanvasColor TtyMapXtermColor(uint8_t color) {
uint8_t r, g, b;
if (color < 8) {
@ -822,7 +831,10 @@ static TtyCanvasColor TtyMapXtermColor(uint8_t color) {
return TtyMapTrueColor(r, g, b);
}
/** Map the given ECMA-48 / VT100 SGR color code to a direct color. */
/**
* @internal
* Map the given ECMA-48 / VT100 SGR color code to a direct color.
*/
static TtyCanvasColor TtyMapEcma48Color(uint8_t color) {
return TtyMapXtermColor(color % 16);
}

View file

@ -2,11 +2,20 @@
#define COSMOPOLITAN_LIBC_VGA_VGA_INTERNAL_H_
#include "libc/runtime/mman.internal.h"
/** Preferred width of the video screen, in character units. */
/**
* @internal
* Preferred width of the video screen, in character units.
*/
#define VGA_PREFER_TTY_HEIGHT 30
/** Preferred width of the video screen, in character units. */
/**
* @internal
* Preferred width of the video screen, in character units.
*/
#define VGA_PREFER_TTY_WIDTH 80
/** Assumed height of each character in pixels, in graphics modes. */
/**
* @internal
* Assumed height of each character in pixels, in graphics modes.
*/
#define VGA_ASSUME_CHAR_HEIGHT_PX 16
/** Assumed width of each character in pixels, in graphics modes. */
#define VGA_ASSUME_CHAR_WIDTH_PX 8
@ -18,6 +27,7 @@
*/
/**
* @internal
* If VGA_USE_WCS is defined, the tty code can maintain an array of the
* Unicode characters "underlying" the 8-bit (or 9-bit) characters that are
* actually displayed on the text screen. This Unicode character
@ -33,6 +43,7 @@
*/
#undef VGA_USE_WCS
/**
* @internal
* The VGA hardware can be configured via the IBM BIOS, or via port I/O
* to either support blinking characters, or support the use of bright
* background colors, but not both. There is a hardware setting that
@ -67,6 +78,7 @@
*/
#undef VGA_USE_BLINK
/**
* @internal
* If VGA_PERSNICKETY_STATUS is defined, then when deciding how to return
* status response codes (e.g. "\e[0n"), the tty code will pay attention to
* the terminal's termios mode (TODO). If undefined, the tty code will
@ -75,7 +87,10 @@
*/
#undef VGA_PERSNICKETY_STATUS
/* Flags which are passed to _StartTty(). */
/**
* @internal
* Flags which are passed to _StartTty().
*/
#define kTtyAllocWcs \
0x01 /* allocate Unicode character array \
(if VGA_USE_WCS also defined) */
@ -85,6 +100,7 @@
to show system messages */
/**
* @internal
* Flags for Tty::pr. These govern properties of individual character cells.
*/
#define kTtyFg 0x0001
@ -102,6 +118,7 @@
#define kTtyConceal 0x1000
/**
* @internal
* Flags for Tty::conf. These govern the current state of the teletypewriter
* as a whole.
*/
@ -153,6 +170,10 @@ typedef union {
typedef TtyBgrxColor TtyCanvasColor;
struct Tty;
/**
* @internal
* Video console object type.
*/
struct Tty {
/**
* Cursor position. (y, x) = (0, 0) means the cursor is on the top left