From f448b518f874929dd219ed957c314889d5dbf0cf Mon Sep 17 00:00:00 2001 From: Noam Preil Date: Fri, 21 Aug 2020 18:19:23 -0400 Subject: [PATCH] SPU-II: use undefined1 as breakpoint --- lib/std/spu/interpreter.zig | 9 ++++++++- src-self-hosted/codegen.zig | 6 +++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/std/spu/interpreter.zig b/lib/std/spu/interpreter.zig index 66d75a5676..d008955a93 100644 --- a/lib/std/spu/interpreter.zig +++ b/lib/std/spu/interpreter.zig @@ -11,6 +11,9 @@ pub fn Interpreter(comptime Bus: type) type { /// This is set to true when we hit an undefined0 instruction, allowing it to /// be used as a trap for testing purposes undefined0: bool = false, + /// This is set to true when we hit an undefined1 instruction, allowing it to + /// be used as a trap for testing purposes. undefined1 is used as a breakpoint. + undefined1: bool = false, bus: Bus, pub fn ExecuteBlock(self: *@This(), comptime size: ?u32) !void { @@ -122,7 +125,11 @@ pub fn Interpreter(comptime Bus: type) type { // Break out of the loop, and let the caller decide what to do return; }, - .undefined1 => return error.BadInstruction, + .undefined1 => { + self.undefined1 = true; + // Break out of the loop, and let the caller decide what to do + return; + }, .signext => if ((val0 & 0x80) != 0) (val0 & 0xFF) | 0xFF00 else diff --git a/src-self-hosted/codegen.zig b/src-self-hosted/codegen.zig index aec4ea81e6..c3cb1fb8e2 100644 --- a/src-self-hosted/codegen.zig +++ b/src-self-hosted/codegen.zig @@ -1265,7 +1265,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { .riscv64 => { mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.ebreak.toU32()); }, - .spu_2 => {}, + .spu_2 => { + try self.code.resize(self.code.items.len + 2); + var instr = Instruction{ .condition = .always, .input0 = .zero, .input1 = .zero, .modify_flags = false, .output = .discard, .command = .undefined1 }; + mem.writeIntLittle(u16, self.code.items[self.code.items.len - 2 ..][0..2], @bitCast(u16, instr)); + }, else => return self.fail(src, "TODO implement @breakpoint() for {}", .{self.target.cpu.arch}), } return .none;