From 7f14bcb05652926f2e2d6b66c8b7c90f0a7be962 Mon Sep 17 00:00:00 2001 From: kudasai <47227786+kudasaixc@users.noreply.github.com> Date: Sat, 4 Jul 2026 17:29:52 +0200 Subject: [PATCH] feat(shell): add poke command to write a byte to memory Complements the existing peek command. mmu_debug_poke mirrors mmu_debug_peek: it writes a byte through a volatile pointer and reports the result on both the VGA terminal and the serial log. The shell command reuses htoi for parsing and validates argc. Usage: poke Example: poke B8000 41 -> writes 'A' to the top-left VGA cell. --- src/include/mm.h | 1 + src/kernel/shell.c | 12 +++++++++++- src/mm/mmu.zig | 19 ++++++++++++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/include/mm.h b/src/include/mm.h index d0195c5..9bfb1dd 100644 --- a/src/include/mm.h +++ b/src/include/mm.h @@ -19,5 +19,6 @@ extern void mmu_map_page(uint32_t phys_addr, uint32_t virt_addr, bool is_writeab extern void mmu_view_mappings(void); extern void mmu_debug_peek(uint32_t addr); +extern void mmu_debug_poke(uint32_t addr, uint8_t value); #endif diff --git a/src/kernel/shell.c b/src/kernel/shell.c index 575ab67..6b7c6fc 100644 --- a/src/kernel/shell.c +++ b/src/kernel/shell.c @@ -93,6 +93,7 @@ static void shell_execute(char *cmd) { terminal_writestring("mia - force a Page Fault for MMU testing\n"); terminal_writestring("mmap - print current virtual memory mappings\n"); terminal_writestring("peek - read and print memory at a given hex address\n"); + terminal_writestring("poke - write a hex byte at a given hex address\n"); terminal_writestring("echo - repeats your input to the console\n"); terminal_writestring("crash - make the machine freeze (fun cmd)\n\n"); } @@ -247,7 +248,16 @@ static void shell_execute(char *cmd) { else if (strcmp(cmd_name, "peek") == 0) { uint32_t addr = htoi(args[1]); mmu_debug_peek(addr); - + + } + else if (strcmp(cmd_name, "poke") == 0) { + if (argc != 3) { + terminal_writestring("usage: poke \n"); + return; + } + uint32_t addr = htoi(args[1]); + uint8_t value = (uint8_t) htoi(args[2]); + mmu_debug_poke(addr, value); } else if (strcmp(cmd_name, "memtest") == 0) { char *a = malloc(32); diff --git a/src/mm/mmu.zig b/src/mm/mmu.zig index ded420f..96c49a6 100644 --- a/src/mm/mmu.zig +++ b/src/mm/mmu.zig @@ -202,7 +202,24 @@ export fn mmu_debug_peek(addr: usize) void { serial_write_string("Value found: "); print_hex(value); serial_write_string("\r\n"); - + +} + +export fn mmu_debug_poke(addr: usize, value: u8) void { + const ptr = @as(*volatile u8, @ptrFromInt(addr)); + ptr.* = value; + + terminal_writestring("Wrote "); + terminal_print_hex(value); + terminal_writestring(" at "); + terminal_print_hex(@as(u32, @truncate(addr))); + terminal_writestring("\n"); + + serial_write_string("\r\n[DEBUG] Poked "); + print_hex(value); + serial_write_string(" at "); + print_hex(addr); + serial_write_string("\r\n"); } export fn mmu_handle_page_fault(error_code: u32) void {