move keyboard and mouse out of HAL into a standalone ps2.sys driver, implement usb stack with xhci controller discovery, hid keyboard/mouse, and bulk-only mass storage, add pci msi support with capability chain walking and software irq vector allocation (slots 16-23), rewrite user virtual memory as a USER_VA_REGION descriptor arena with per-process ownership tracking and guard page support, replacing the old bump allocator and top-down image region, add MmCreateUserRegion/MmDestroyAllUserRegions so process teardown reclaims all user va in one pass, allocate a pool-backed shadow framebuffer in hal_screen to fix cursor tearing and scroll corruption, reserve ap trampoline page below 1mb in uefi bootloader before boot services exit, rewrite memset/memcpy/memmove/memcmp with __stosq/__movsq intrinsics, promote driver flag literals to macros and add multi-tu STANDALONE_DRIVERS table to build.c, split rtl8139/rtl816x into header+source, rename KbReadScancode to KbReadKey, improve page fault output with MmDebugDescribeAddress and user region dump, fix %p to %016llX throughout.

This commit is contained in:
maksw committed 2026-06-02 00:01:20 +02:00
1 parent b970d7f59c
commit b838f8d83d
130 files changed
+8137 -2932

No files matched your search

+60 -65
View File
@@ -27,29 +27,21 @@
#define COL_CURSOR 0xE0E0E0u
#define COL_CURSORF 0x000000u
#define MOD_LSHIFT (1u << 0)
#define MOD_RSHIFT (1u << 1)
#define MOD_LCTRL (1u << 2)
#define MOD_RCTRL (1u << 3)
#define MOD_CAPS (1u << 6)
#define MOD_SHIFT (MOD_LSHIFT | MOD_RSHIFT)
#define MOD_CTRL (MOD_LCTRL | MOD_RCTRL)
#define SC_ESC 0x01u
#define SC_BACKSPACE 0x0Eu
#define SC_TAB 0x0Fu
#define SC_Q 0x10u
#define SC_S 0x1Fu
#define SC_ENTER 0x1Cu
#define SC_HOME 0x47u
#define SC_UP 0x48u
#define SC_PGUP 0x49u
#define SC_LEFT 0x4Bu
#define SC_RIGHT 0x4Du
#define SC_END 0x4Fu
#define SC_DOWN 0x50u
#define SC_PGDN 0x51u
#define SC_DEL 0x53u
#define EDIT_KEY_ESC INPUT_KEY_ESCAPE
#define EDIT_KEY_BACKSPACE INPUT_KEY_BACKSPACE
#define EDIT_KEY_TAB INPUT_KEY_TAB
#define EDIT_KEY_Q INPUT_KEY_Q
#define EDIT_KEY_S INPUT_KEY_S
#define EDIT_KEY_ENTER INPUT_KEY_ENTER
#define EDIT_KEY_HOME INPUT_KEY_HOME
#define EDIT_KEY_UP INPUT_KEY_UP
#define EDIT_KEY_PGUP INPUT_KEY_PAGE_UP
#define EDIT_KEY_LEFT INPUT_KEY_LEFT
#define EDIT_KEY_RIGHT INPUT_KEY_RIGHT
#define EDIT_KEY_END INPUT_KEY_END
#define EDIT_KEY_DOWN INPUT_KEY_DOWN
#define EDIT_KEY_PGDN INPUT_KEY_PAGE_DOWN
#define EDIT_KEY_DEL INPUT_KEY_DELETE
typedef struct LINE {
int len;
@@ -69,22 +61,6 @@ static bool gQuitArmed = false;
static char gFilename[PATH_MAX2] = "untitled.txt";
static char gMessage[MSG_MAX] = "ready";
static const char gUnshifted[128] = {
0, 0, '1','2','3','4','5','6','7','8','9','0','-','=','\b','\t',
'q','w','e','r','t','y','u','i','o','p','[',']','\n', 0, 'a','s',
'd','f','g','h','j','k','l',';','\'','`', 0, '\\','z','x','c','v',
'b','n','m',',','.','/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, '7','8','9','-', '4','5','6','+', '1','2','3','0','.'
};
static const char gShifted[128] = {
0, 0, '!','@','#','$','%','^','&','*','(',')','_','+','\b','\t',
'Q','W','E','R','T','Y','U','I','O','P','{','}','\n', 0, 'A','S',
'D','F','G','H','J','K','L',':','"','~', 0, '|','Z','X','C','V',
'B','N','M','<','>','?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, '7','8','9','-', '4','5','6','+', '1','2','3','0','.'
};
static void put_cell(int col, int row, char c, uint32_t fg, uint32_t bg) {
SysScreenPutChar(c ? c : ' ', col * GLYPH_W, row * GLYPH_H, fg, bg);
}
@@ -124,14 +100,33 @@ static void append_u32(char* b, size_t cap, size_t* p, uint32_t v) {
while (n > 0) append_char(b, cap, p, tmp[--n]);
}
static char key_to_char(uint8_t sc, uint32_t mods) {
if (sc >= 128) return 0;
bool shifted = (mods & MOD_SHIFT) != 0;
if (mods & MOD_CAPS) {
char base = gUnshifted[sc];
if (base >= 'a' && base <= 'z') shifted = !shifted;
static char key_to_char(INPUT_KEY key, uint32_t mods) {
if (key >= INPUT_KEY_A && key <= INPUT_KEY_Z) {
bool shifted = (mods & INPUT_MOD_SHIFT) != 0;
bool caps = (mods & INPUT_MOD_CAPS_LOCK) != 0;
char c = (char)('a' + (key - INPUT_KEY_A));
return (shifted ^ caps) ? (char)(c - 'a' + 'A') : c;
}
return shifted ? gShifted[sc] : gUnshifted[sc];
typedef struct { INPUT_KEY key; char normal; char shifted; } PAIR;
static const PAIR map[] = {
{ INPUT_KEY_1, '1', '!' }, { INPUT_KEY_2, '2', '@' },
{ INPUT_KEY_3, '3', '#' }, { INPUT_KEY_4, '4', '$' },
{ INPUT_KEY_5, '5', '%' }, { INPUT_KEY_6, '6', '^' },
{ INPUT_KEY_7, '7', '&' }, { INPUT_KEY_8, '8', '*' },
{ INPUT_KEY_9, '9', '(' }, { INPUT_KEY_0, '0', ')' },
{ INPUT_KEY_MINUS, '-', '_' }, { INPUT_KEY_EQUAL, '=', '+' },
{ INPUT_KEY_LEFT_BRACKET, '[', '{' }, { INPUT_KEY_RIGHT_BRACKET, ']', '}' },
{ INPUT_KEY_BACKSLASH, '\\', '|' }, { INPUT_KEY_SEMICOLON, ';', ':' },
{ INPUT_KEY_APOSTROPHE, '\'', '"' }, { INPUT_KEY_GRAVE, '`', '~' },
{ INPUT_KEY_COMMA, ',', '<' }, { INPUT_KEY_PERIOD, '.', '>' },
{ INPUT_KEY_SLASH, '/', '?' }, { INPUT_KEY_SPACE, ' ', ' ' },
};
bool shifted = (mods & INPUT_MOD_SHIFT) != 0;
for (size_t i = 0; i < sizeof(map) / sizeof(map[0]); i++) {
if (map[i].key == key) return shifted ? map[i].shifted : map[i].normal;
}
return 0;
}
static void clamp_cursor(void) {
@@ -423,11 +418,11 @@ static void editor_loop(void) {
while (true) {
render();
uint8_t sc = SysKbReadScancode();
INPUT_KEY key = SysKbReadKey();
uint32_t mods = SysKbGetModifiers();
bool ctrl = (mods & MOD_CTRL) != 0;
bool ctrl = (mods & INPUT_MOD_CTRL) != 0;
if (ctrl && sc == SC_Q) {
if (ctrl && key == EDIT_KEY_Q) {
if (gDirty && !gQuitArmed) {
gQuitArmed = true;
msg_set("unsaved changes: press Ctrl+Q again to quit");
@@ -438,38 +433,38 @@ static void editor_loop(void) {
gQuitArmed = false;
if (ctrl && sc == SC_S) { save_file(); continue; }
if (sc == SC_ESC) { msg_set("Ctrl+Q quits, Ctrl+S saves"); continue; }
if (ctrl && key == EDIT_KEY_S) { save_file(); continue; }
if (key == EDIT_KEY_ESC) { msg_set("Ctrl+Q quits, Ctrl+S saves"); continue; }
switch (sc) {
case SC_LEFT: move_left(); break;
case SC_RIGHT: move_right(); break;
case SC_UP: move_up(); break;
case SC_DOWN: move_down(); break;
case SC_HOME: gCx = 0; break;
case SC_END: gCx = gLines[gCy].len; break;
case SC_PGUP: {
switch (key) {
case EDIT_KEY_LEFT: move_left(); break;
case EDIT_KEY_RIGHT: move_right(); break;
case EDIT_KEY_UP: move_up(); break;
case EDIT_KEY_DOWN: move_down(); break;
case EDIT_KEY_HOME: gCx = 0; break;
case EDIT_KEY_END: gCx = gLines[gCy].len; break;
case EDIT_KEY_PGUP: {
int n = gRows - 2;
if (n < 1) n = 1;
gCy -= n;
clamp_cursor();
break;
}
case SC_PGDN: {
case EDIT_KEY_PGDN: {
int n = gRows - 2;
if (n < 1) n = 1;
gCy += n;
clamp_cursor();
break;
}
case SC_BACKSPACE: backspace_at_cursor(); break;
case SC_DEL: delete_at_cursor(); break;
case SC_ENTER: newline_at_cursor(); break;
case SC_TAB:
case EDIT_KEY_BACKSPACE: backspace_at_cursor(); break;
case EDIT_KEY_DEL: delete_at_cursor(); break;
case EDIT_KEY_ENTER: newline_at_cursor(); break;
case EDIT_KEY_TAB:
for (int i = 0; i < 4; i++) insert_char_at_cursor(' ');
break;
default: {
char c = key_to_char(sc, mods);
char c = key_to_char(key, mods);
if (!ctrl && c >= 0x20 && c <= 0x7E) insert_char_at_cursor(c);
break;
}