diff --git a/.gitmodules b/.gitmodules index d8e4271..0fc3ea0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "lib/arm32"] path = lib/arm32 url = https://git.musuka.dev/paoda/arm32.git +[submodule "lib/zba-gdbstub"] + path = lib/zba-gdbstub + url = https://git.musuka.dev/paoda/zba-gdbstub diff --git a/build.zig b/build.zig index 2127a05..10e4ee3 100644 --- a/build.zig +++ b/build.zig @@ -1,8 +1,9 @@ const std = @import("std"); -const Sdk = @import("lib/SDL.zig/Sdk.zig"); +const Sdk = @import("lib/SDL.zig/build.zig"); const zgui = @import("lib/zgui/build.zig"); const arm32 = @import("lib/arm32/build.zig"); +const gdbstub = @import("lib/zba-gdbstub/build.zig"); // Although this function looks imperative, note that its job is to // declaratively construct a build graph that will be executed by an external @@ -29,6 +30,7 @@ pub fn build(b: *std.Build) void { }); exe.addModule("arm32", arm32.module(b)); + exe.addModule("gdbstub", gdbstub.module(b)); exe.addModule("zig-clap", b.dependency("zig-clap", .{}).module("clap")); exe.addAnonymousModule("bitfield", .{ .source_file = .{ .path = "lib/bitfield.zig" } }); // https://github.com/FlorenceOS/ diff --git a/lib/zba-gdbstub b/lib/zba-gdbstub new file mode 160000 index 0000000..5947747 --- /dev/null +++ b/lib/zba-gdbstub @@ -0,0 +1 @@ +Subproject commit 5947747533ec9ee63b4598455a281edd5e55b4a9 diff --git a/src/gdb.zig b/src/gdb.zig new file mode 100644 index 0000000..e978ebe --- /dev/null +++ b/src/gdb.zig @@ -0,0 +1,42 @@ +const std = @import("std"); +const Server = @import("gdbstub").Server; +const Interface = @import("gdbstub").Emulator; +const System = @import("core/emu.zig").System; +const Scheduler = @import("core/Scheduler.zig"); + +const Allocator = std.mem.Allocator; + +pub const TurboWrapper = struct { + system: System, + scheduler: *Scheduler, + + pub fn init(system: System, scheduler: *Scheduler) @This() { + return .{ .system = system, .scheduler = scheduler }; + } + + pub fn interface(self: *@This(), allocator: Allocator) Interface { + return Interface.init(allocator, self); + } + + pub fn read(self: *const @This(), addr: u32) u8 { + return self.cpu.bus.dbgRead(u8, addr); + } + + pub fn write(self: *@This(), addr: u32, value: u8) void { + self.cpu.bus.dbgWrite(u8, addr, value); + } + + pub fn registers(self: *const @This()) *[16]u32 { + return &self.cpu.r; + } + + pub fn cpsr(self: *const @This()) u32 { + return self.cpu.cpsr.raw; + } + + pub fn step(self: *@This()) void { + _ = self; + + @panic("TODO: Handle ARM7 and ARM9 lol"); + } +}; diff --git a/src/main.zig b/src/main.zig index 8a8f696..d7e5a57 100644 --- a/src/main.zig +++ b/src/main.zig @@ -14,6 +14,7 @@ const ClapResult = clap.Result(clap.Help, &cli_params, clap.parsers.default); const cli_params = clap.parseParamsComptime( \\-h, --help Display this help and exit. \\-f, --firm Path to NDS Firmware Directory + \\--gdb Run Turbo in GDB Mode \\ Path to the NDS ROM \\ );