1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
//! Render Memory Around Fault
const serial = @import("../../drivers/serial/serial.zig");
pub fn render_around_address(address: u64, bytes_before: usize, bytes_after: usize) void {
if (address == 0) return;
const start = if (address >= bytes_before) address - bytes_before else 0;
const total_bytes = bytes_before + bytes_after;
serial.printf("Memory around %x:\n", .{address});
const mem_ptr: [*]const u8 = @ptrFromInt(start);
var offset: usize = 0;
while (offset < total_bytes) {
serial.printf(" %x: ", .{start + offset});
for (0..16) |i| {
if (offset + i < total_bytes) {
serial.printf("%x ", .{mem_ptr[offset + i]});
} else {
serial.printf(" ", .{});
}
}
serial.printf(" |", .{});
for (0..16) |i| {
if (offset + i < total_bytes) {
const c = mem_ptr[offset + i];
if (c >= 0x20 and c < 0x7F) {
serial.printf("%s", .{&[_]u8{c}});
} else {
serial.printf(".", .{});
}
}
}
serial.printf("|\n", .{});
offset += 16;
}
serial.printf("\n", .{});
}
pub fn render_instruction_bytes(rip: u64, count: usize) void {
serial.printf("Instruction bytes at %x:\n ", .{rip});
const code_ptr: [*]const u8 = @ptrFromInt(rip);
for (0..count) |i| {
serial.printf("%x ", .{code_ptr[i]});
}
serial.printf("\n\n", .{});
}
|