Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/MIPS/MIPSDebugInterface.h
5671 views
1
// Copyright (c) 2012- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#pragma once
19
20
#include <string>
21
22
#include "Common/Math/expression_parser.h"
23
#include "Core/MIPS/MIPS.h"
24
#include "Core/Debugger/DebugInterface.h"
25
26
27
class MIPSDebugInterface : public DebugInterface {
28
MIPSState *cpu;
29
public:
30
MIPSDebugInterface(MIPSState *_cpu) { cpu = _cpu; }
31
int getInstructionSize(int instruction) { return 4; }
32
bool isAlive();
33
bool isBreakpoint(unsigned int address);
34
void setBreakpoint(unsigned int address);
35
void clearBreakpoint(unsigned int address);
36
void clearAllBreakpoints();
37
void toggleBreakpoint(unsigned int address);
38
unsigned int readMemory(unsigned int address);
39
int getColor(unsigned int address, bool darkMode) const;
40
std::string getDescription(unsigned int address);
41
42
u32 GetGPR32Value(int reg) const override { return cpu->r[reg]; }
43
float GetFPR32Value(int reg) const { return cpu->f[reg]; }
44
void SetGPR32Value(int reg, u32 value) { cpu->r[reg] = value; }
45
46
u32 GetPC() const override { return cpu->pc; }
47
u32 GetRA() const override { return cpu->r[MIPS_REG_RA]; }
48
u32 GetFPCond() const override { return cpu->fpcond; }
49
void SetPC(u32 _pc) override { cpu->pc = _pc; }
50
51
static const char *GetCategoryName(int cat) {
52
static const char *const names[3] = { "GPR", "FPU", "VFPU" };
53
return names[cat];
54
}
55
static int GetNumCategories() { return 3; }
56
static constexpr int GetNumRegsInCategory(int cat) {
57
constexpr int r[3] = { 32, 32, 128 };
58
return r[cat];
59
}
60
static std::string GetRegName(int cat, int index);
61
62
void PrintRegValue(int cat, int index, char *out, size_t outSize) const override {
63
switch (cat) {
64
case 0: snprintf(out, outSize, "%08X", cpu->r[index]); break;
65
case 1: snprintf(out, outSize, "%f", cpu->f[index]); break;
66
case 2: snprintf(out, outSize, "N/A"); break;
67
}
68
}
69
70
u32 GetHi() const override {
71
return cpu->hi;
72
}
73
74
u32 GetLLBit() const override {
75
return cpu->llBit;
76
}
77
78
u32 GetLo() const override {
79
return cpu->lo;
80
}
81
82
void SetHi(u32 val) override {
83
cpu->hi = val;
84
}
85
86
void SetLo(u32 val) override {
87
cpu->lo = val;
88
}
89
90
u32 GetRegValue(int cat, int index) const override {
91
switch (cat) {
92
case 0:
93
return cpu->r[index];
94
95
case 1:
96
return cpu->fi[index];
97
98
case 2:
99
return cpu->vi[voffset[index]];
100
101
default:
102
return 0;
103
}
104
}
105
106
void SetRegValue(int cat, int index, u32 value) override {
107
switch (cat) {
108
case 0:
109
if (index != 0)
110
cpu->r[index] = value;
111
break;
112
113
case 1:
114
cpu->fi[index] = value;
115
break;
116
117
case 2:
118
cpu->vi[voffset[index]] = value;
119
break;
120
121
default:
122
break;
123
}
124
}
125
};
126
127
bool initExpression(const DebugInterface *debug, const char* exp, PostfixExpression& dest);
128
bool parseExpression(const DebugInterface *debug, PostfixExpression& exp, u32& dest);
129
void DisAsm(u32 pc, char *out, size_t outSize);
130
131