From 1f4eabc49b8a7db960569196e8b0a277f92e6f13 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 15 Dec 2023 00:49:29 -0600 Subject: [PATCH] tmp: progress towards gdb stub --- .gitmodules | 3 +++ build.zig | 4 +++- lib/zba-gdbstub | 1 + src/gdb.zig | 42 ++++++++++++++++++++++++++++++++++++++++++ src/main.zig | 1 + 5 files changed, 50 insertions(+), 1 deletion(-) create mode 160000 lib/zba-gdbstub create mode 100644 src/gdb.zig 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..479319e --- /dev/null +++ b/lib/zba-gdbstub @@ -0,0 +1 @@ +Subproject commit 479319e7cad78c3fd38b6865c56e9fe9e78d495c 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 \\ );