-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbreakpoint_instruction.cpp
More file actions
56 lines (43 loc) · 1.58 KB
/
Copy pathbreakpoint_instruction.cpp
File metadata and controls
56 lines (43 loc) · 1.58 KB
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
#include <ctype.h>
#include "breakpoint_instruction.h"
#include "cpu.h"
#include "utils.h"
breakpoint_instruction::breakpoint_instruction(bus *const b, const std::pair<uint16_t, uint16_t> instr_mask, const bp_action action):
breakpoint(b, action),
instruction(instr_mask.first),
mask(instr_mask.second)
{
}
breakpoint_instruction::~breakpoint_instruction()
{
}
std::optional<std::string> breakpoint_instruction::is_triggered() const
{
uint16_t cur_pc = b->getCpu()->getPC();
auto cur_instr = b->peek_word(b->getCpu()->getPSW_runmode(), cur_pc);
if (cur_instr.has_value() == false)
return { };
if ((cur_instr.value() & mask) == instruction)
return format("instr[%06o]=%06o", mask, cur_instr.value());
return { };
}
std::pair<breakpoint_instruction *, std::optional<std::string> > breakpoint_instruction::parse(bus *const b, const std::string & in, const bp_action action)
{
auto parts = split(in, "=");
if (parts.size() != 2)
return { nullptr, "instruction: key or value missing" };
uint16_t instruction = std::stoi(parts.at(1), nullptr, 8);
auto key = parts.at(0);
if (key.size() < 7 || (key.substr(0, 5) != "INSTR" && key.substr(0, 5) != "instr"))
return { nullptr, { } };
uint16_t mask = 65535;
int len = key.size() - (6 + 1);
std::string mask_str = len > 0 ? key.substr(6, len) : "";
if (mask_str.empty() == false)
mask = std::stoi(mask_str, nullptr, 8);
return { new breakpoint_instruction(b, { instruction, mask }, action), { } };
}
std::string breakpoint_instruction::emit() const
{
return format("instr[%06o]=%06o", mask, instruction);
}