Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/MIPS/MIPSDebugInterface.h
3186 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
{
29
MIPSState *cpu;
30
public:
31
MIPSDebugInterface(MIPSState *_cpu) { cpu = _cpu; }
32
int getInstructionSize(int instruction) { return 4; }
33
bool isAlive();
34
bool isBreakpoint(unsigned int address);
35
void setBreakpoint(unsigned int address);
36
void clearBreakpoint(unsigned int address);
37
void clearAllBreakpoints();
38
void toggleBreakpoint(unsigned int address);
39
unsigned int readMemory(unsigned int address);
40
int getColor(unsigned int address, bool darkMode) const;
41
std::string getDescription(unsigned int address);
42
43
u32 GetGPR32Value(int reg) const override { return cpu->r[reg]; }
44
float GetFPR32Value(int reg) const { return cpu->f[reg]; }
45
void SetGPR32Value(int reg, u32 value) { cpu->r[reg] = value; }
46
47
u32 GetPC() const override { return cpu->pc; }
48
u32 GetRA() const override { return cpu->r[MIPS_REG_RA]; }
49
u32 GetFPCond() const override { return cpu->fpcond; }
50
void SetPC(u32 _pc) override { cpu->pc = _pc; }
51
52
static const char *GetCategoryName(int cat) {
53
static const char *const names[3] = { "GPR", "FPU", "VFPU" };
54
return names[cat];
55
}
56
static int GetNumCategories() { return 3; }
57
static constexpr int GetNumRegsInCategory(int cat) {
58
constexpr int r[3] = { 32, 32, 128 };
59
return r[cat];
60
}
61
static std::string GetRegName(int cat, int index);
62
63
void PrintRegValue(int cat, int index, char *out, size_t outSize) const override {
64
switch (cat) {
65
case 0: snprintf(out, outSize, "%08X", cpu->r[index]); break;
66
case 1: snprintf(out, outSize, "%f", cpu->f[index]); break;
67
case 2: snprintf(out, outSize, "N/A"); break;
68
}
69
}
70
71
u32 GetHi() const override {
72
return cpu->hi;
73
}
74
75
u32 GetLLBit() const override {
76
return cpu->llBit;
77
}
78
79
u32 GetLo() const override {
80
return cpu->lo;
81
}
82
83
void SetHi(u32 val) override {
84
cpu->hi = val;
85
}
86
87
void SetLo(u32 val) override {
88
cpu->lo = val;
89
}
90
91
u32 GetRegValue(int cat, int index) const override {
92
switch (cat) {
93
case 0:
94
return cpu->r[index];
95
96
case 1:
97
return cpu->fi[index];
98
99
case 2:
100
return cpu->vi[voffset[index]];
101
102
default:
103
return 0;
104
}
105
}
106
107
void SetRegValue(int cat, int index, u32 value) override {
108
switch (cat) {
109
case 0:
110
if (index != 0)
111
cpu->r[index] = value;
112
break;
113
114
case 1:
115
cpu->fi[index] = value;
116
break;
117
118
case 2:
119
cpu->vi[voffset[index]] = value;
120
break;
121
122
default:
123
break;
124
}
125
}
126
};
127
128
bool initExpression(const DebugInterface *debug, const char* exp, PostfixExpression& dest);
129
bool parseExpression(const DebugInterface *debug, PostfixExpression& exp, u32& dest);
130
void DisAsm(u32 pc, char *out, size_t outSize);
131
132