From ee55de05344ecbb8ef9c3c58951140924bae8231 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maksymilian=20Wilczy=C5=84ski?= Date: Mon, 15 Jun 2026 11:09:13 +0200 Subject: [PATCH] make usb.vhd if missing, fix clear behavior --- OVMF/OVMF_VARS_4M_d.fd | Bin 540672 -> 540672 bytes code/build/build.c | 31 ++++++++++++++++++++++++++++++- code/kernel/ke_display.c | 5 ++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/OVMF/OVMF_VARS_4M_d.fd b/OVMF/OVMF_VARS_4M_d.fd index a362ae000300a4fd8401e0cc0483232d156a1a90..8037eed2cbf649adb2ae2ef2d9c81f948caabec1 100644 GIT binary patch delta 62 zcmZo@P;6*W+`zYNvYe6A=743FxF%a!sBPY{U Rn*eK@09%^?`!WFz0|50M6?^~y delta 56 zcmZo@P;6*W+`zYN^1N+Mn*)|z;%eS>uzk}(Mj&R|zUd&dpWkMO;}Znh1X$VxSla~H M+635_32+zy0O9Wz!2kdN diff --git a/code/build/build.c b/code/build/build.c index 5bcbee4..deae697 100644 --- a/code/build/build.c +++ b/code/build/build.c @@ -71,16 +71,45 @@ Nob_Proc run_async(const char *cmd_str) { return proc; } +// Creates an empty USB image the first time the build sees a missing usb.vhd. +// The image is intentionally left unmounted and unpopulated after formatting so +// callers can use it as removable FAT32 storage without the build overwriting it. +bool create_usb_vhd_if_missing(void) { + if (nob_file_exists("usb.vhd")) return true; + + char vhd_path[MAX_PATH]; + GetFullPathNameA("usb.vhd", MAX_PATH, vhd_path, NULL); + + const char *diskpart_script = nob_temp_sprintf( + "create vdisk file=\"%s\" maximum=256 type=fixed\n" + "select vdisk file=\"%s\"\n" + "attach vdisk\n" + "convert gpt\n" + "create partition primary\n" + "format fs=fat32 quick\n" + "detach vdisk\n" + "exit\n", + vhd_path, vhd_path + ); + + nob_log(NOB_INFO, "usb.vhd missing, creating empty 256 MB FAT32 GPT image..."); + nob_write_entire_file("usb_mkimage.txt", diskpart_script, strlen(diskpart_script)); + bool ok = run_sync("diskpart /s usb_mkimage.txt"); + remove("usb_mkimage.txt"); + return ok; +} + // Runs the requested operation. int main(int argc, char **argv) { // The build tool rebuilds itself before doing any real work so the graph below matches the source. NOB_GO_REBUILD_URSELF(argc, argv); - // The disk image must exist before the build can copy fresh binaries into it. + // The boot image must exist before the build can copy fresh binaries into it. if (!nob_file_exists("disk.vhd")) { nob_log(NOB_INFO, "disk.vhd missing, calling mkimage.bat..."); if (!run_sync("mkimage.bat")) return 1; } + if (!create_usb_vhd_if_missing()) return 1; create_layout(); // Core images build sequentially because later images link against earlier import libraries. diff --git a/code/kernel/ke_display.c b/code/kernel/ke_display.c index 90c7bc2..afc0cd7 100644 --- a/code/kernel/ke_display.c +++ b/code/kernel/ke_display.c @@ -677,8 +677,11 @@ static KSTATUS KiDisplayClearLocked(uint32_t color) { return s; KiDisplayBeginDraw(); s = KiDisplayFillRectNoCursor(0, 0, (int)mode.Width, (int)mode.Height, color); - if (KSUCCESS(s)) + if (KSUCCESS(s)) { KiDisplayConsoleResetCellsLocked(); + gConsoleX = 0; + gConsoleY = 0; + } KSTATUS ps = KiDisplayEndDraw(); return KSUCCESS(s) ? ps : s; }