CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/MIPS/MIPSDebugInterface.h
Views: 1401
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
#include <cstring>
22
#include <cstdio>
23
#include "Core/MIPS/MIPS.h"
24
#include "Core/Debugger/DebugInterface.h"
25
26
class MIPSDebugInterface : public DebugInterface
27
{
28
MIPSState *cpu;
29
public:
30
MIPSDebugInterface(MIPSState *_cpu) { cpu = _cpu; }
31
int getInstructionSize(int instruction) override { return 4; }
32
bool isAlive() override;
33
bool isBreakpoint(unsigned int address) override;
34
void setBreakpoint(unsigned int address) override;
35
void clearBreakpoint(unsigned int address) override;
36
void clearAllBreakpoints() override;
37
void toggleBreakpoint(unsigned int address) override;
38
unsigned int readMemory(unsigned int address) override;
39
unsigned int getPC() override { return cpu->pc; }
40
void setPC(unsigned int address) override { cpu->pc = address; }
41
void step() override {}
42
void runToBreakpoint() override;
43
int getColor(unsigned int address) override;
44
std::string getDescription(unsigned int address) override;
45
bool initExpression(const char* exp, PostfixExpression& dest) override;
46
bool parseExpression(PostfixExpression& exp, u32& dest) override;
47
48
//overridden functions
49
const char *GetName() override;
50
u32 GetGPR32Value(int reg) override { return cpu->r[reg]; }
51
u32 GetPC() override { return cpu->pc; }
52
u32 GetLR() override { return cpu->r[MIPS_REG_RA]; }
53
void DisAsm(u32 pc, char *out, size_t outSize) override;
54
void SetPC(u32 _pc) override { cpu->pc = _pc; }
55
56
const char *GetCategoryName(int cat) override {
57
static const char *const names[3] = { "GPR", "FPU", "VFPU" };
58
return names[cat];
59
}
60
int GetNumCategories() override { return 3; }
61
int GetNumRegsInCategory(int cat) override {
62
static int r[3] = { 32, 32, 128 };
63
return r[cat];
64
}
65
std::string GetRegName(int cat, int index) override;
66
67
void PrintRegValue(int cat, int index, char *out, size_t outSize) override {
68
switch (cat) {
69
case 0: snprintf(out, outSize, "%08X", cpu->r[index]); break;
70
case 1: snprintf(out, outSize, "%f", cpu->f[index]); break;
71
case 2: snprintf(out, outSize, "N/A"); break;
72
}
73
}
74
75
u32 GetHi() override {
76
return cpu->hi;
77
}
78
79
u32 GetLo() 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) 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