Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/include/mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 11 additions & 1 deletion src/kernel/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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 <hex address> <hex value>\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);
Expand Down
19 changes: 18 additions & 1 deletion src/mm/mmu.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading