feat: implement gdb memory map
This commit is contained in:
parent
400e155502
commit
8a58251ef6
@ -1,9 +1,11 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const target = @import("Server.zig").target;
|
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
const Emulator = @import("lib.zig").Emulator;
|
const Emulator = @import("lib.zig").Emulator;
|
||||||
|
|
||||||
|
const target = @import("Server.zig").target;
|
||||||
|
const memory_map = @import("Server.zig").memory_map;
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
const log = std.log.scoped(.Packet);
|
const log = std.log.scoped(.Packet);
|
||||||
pub const max_len: usize = 0x1000;
|
pub const max_len: usize = 0x1000;
|
||||||
@ -143,7 +145,7 @@ pub fn parse(self: *Self, allocator: Allocator, emu: Emulator) !String {
|
|||||||
|
|
||||||
if (substr(self.contents[1..], "Xfer:features:read")) {
|
if (substr(self.contents[1..], "Xfer:features:read")) {
|
||||||
var tokens = std.mem.tokenize(u8, self.contents[1..], ":,");
|
var tokens = std.mem.tokenize(u8, self.contents[1..], ":,");
|
||||||
_ = tokens.next(); // qXfer
|
_ = tokens.next(); // Xfer
|
||||||
_ = tokens.next(); // features
|
_ = tokens.next(); // features
|
||||||
_ = tokens.next(); // read
|
_ = tokens.next(); // read
|
||||||
const annex = tokens.next() orelse return .{ .static = "E00" };
|
const annex = tokens.next() orelse return .{ .static = "E00" };
|
||||||
@ -174,6 +176,27 @@ pub fn parse(self: *Self, allocator: Allocator, emu: Emulator) !String {
|
|||||||
return .{ .static = "" };
|
return .{ .static = "" };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (substr(self.contents[1..], "Xfer:memory-map:read")) {
|
||||||
|
var tokens = std.mem.tokenize(u8, self.contents[1..], ":,");
|
||||||
|
_ = tokens.next(); // Xfer
|
||||||
|
_ = tokens.next(); // memory-map
|
||||||
|
_ = tokens.next(); // read
|
||||||
|
const offset_str = tokens.next() orelse return .{ .static = "E9999" };
|
||||||
|
const length_str = tokens.next() orelse return .{ .static = "E9999" };
|
||||||
|
|
||||||
|
const offset = try std.fmt.parseInt(usize, offset_str, 16);
|
||||||
|
const length = try std.fmt.parseInt(usize, length_str, 16);
|
||||||
|
|
||||||
|
// see above
|
||||||
|
const len = @min(length, (memory_map.len + 1) - offset);
|
||||||
|
const ret = try allocator.alloc(u8, len);
|
||||||
|
|
||||||
|
ret[0] = if (ret.len < length) 'l' else 'm';
|
||||||
|
std.mem.copy(u8, ret[1..], memory_map[offset..]);
|
||||||
|
|
||||||
|
return .{ .alloc = ret };
|
||||||
|
}
|
||||||
|
|
||||||
log.warn("Unimplemented: {s}", .{self.contents});
|
log.warn("Unimplemented: {s}", .{self.contents});
|
||||||
return .{ .static = "" };
|
return .{ .static = "" };
|
||||||
},
|
},
|
||||||
|
@ -36,6 +36,28 @@ pub const target: []const u8 =
|
|||||||
\\</target>
|
\\</target>
|
||||||
;
|
;
|
||||||
|
|
||||||
|
// Game Pak SRAM isn't included
|
||||||
|
// TODO: Can i be more specific here?
|
||||||
|
pub const memory_map: []const u8 =
|
||||||
|
\\ <?xml version="1.0"?>
|
||||||
|
\\ <!DOCTYPE memory-map
|
||||||
|
\\ PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
|
||||||
|
\\ "http://sourceware.org/gdb/gdb-memory-map.dtd">
|
||||||
|
\\
|
||||||
|
\\ <memory-map>
|
||||||
|
\\ <memory type="rom" start="0" length="4000">
|
||||||
|
\\ <memory type="ram" start="2000000" length="40000">
|
||||||
|
\\ <memory type="ram" start="3000000" length="8000">
|
||||||
|
\\ <memory type="ram" start="4000000" length="400">
|
||||||
|
\\ <memory type="ram" start="5000000" length="400">
|
||||||
|
\\ <memory type="ram" start="6000000" length="18000">
|
||||||
|
\\ <memory type="ram" start="7000000" length="400">
|
||||||
|
\\ <memory type="rom" start="8000000" length="20000000">
|
||||||
|
\\ <memory type="rom" start="A000000" length="20000000">
|
||||||
|
\\ <memory type="rom" start="C000000" length="20000000">
|
||||||
|
\\ </memory-map>;
|
||||||
|
;
|
||||||
|
|
||||||
// FIXME: Shouldn't this be a Packet Struct?
|
// FIXME: Shouldn't this be a Packet Struct?
|
||||||
pkt_cache: ?[]const u8 = null,
|
pkt_cache: ?[]const u8 = null,
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user