1 // Copyright (c) 2018- 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 #include <cstdio>
19 #include "Core/HLE/sceKernelThread.h"
20 #include "Core/MIPS/MIPSDebugInterface.h"
21 
22 class KernelThreadDebugInterface : public MIPSDebugInterface {
23 public:
KernelThreadDebugInterface(MIPSState * c,PSPThreadContext & t)24 	KernelThreadDebugInterface(MIPSState *c, PSPThreadContext &t) : MIPSDebugInterface(c), ctx(t) {
25 	}
26 
getPC()27 	unsigned int getPC() override { return ctx.pc; }
setPC(unsigned int address)28 	void setPC(unsigned int address) override { ctx.pc = address; }
29 
GetGPR32Value(int reg)30 	u32 GetGPR32Value(int reg) override { return ctx.r[reg]; }
GetPC()31 	u32 GetPC() override { return ctx.pc; }
GetLR()32 	u32 GetLR() override { return ctx.r[MIPS_REG_RA]; }
SetPC(u32 _pc)33 	void SetPC(u32 _pc) override { ctx.pc = _pc; }
34 
PrintRegValue(int cat,int index,char * out)35 	void PrintRegValue(int cat, int index, char *out) override {
36 		switch (cat) {
37 		case 0: sprintf(out, "%08X", ctx.r[index]); break;
38 		case 1: sprintf(out, "%f", ctx.f[index]); break;
39 		case 2: sprintf(out, "N/A"); break;
40 		}
41 	}
42 
GetHi()43 	u32 GetHi() override {
44 		return ctx.hi;
45 	}
46 
GetLo()47 	u32 GetLo() override {
48 		return ctx.lo;
49 	}
50 
SetHi(u32 val)51 	void SetHi(u32 val) override {
52 		ctx.hi = val;
53 	}
54 
SetLo(u32 val)55 	void SetLo(u32 val) override {
56 		ctx.lo = val;
57 	}
58 
GetRegValue(int cat,int index)59 	u32 GetRegValue(int cat, int index) override {
60 		switch (cat) {
61 		case 0: return ctx.r[index];
62 		case 1: return ctx.fi[index];
63 		case 2: return ctx.vi[voffset[index]];
64 		default: return 0;
65 		}
66 	}
67 
SetRegValue(int cat,int index,u32 value)68 	void SetRegValue(int cat, int index, u32 value) override {
69 		switch (cat) {
70 		case 0:
71 			if (index != 0)
72 				ctx.r[index] = value;
73 			break;
74 
75 		case 1:
76 			ctx.fi[index] = value;
77 			break;
78 
79 		case 2:
80 			ctx.vi[voffset[index]] = value;
81 			break;
82 
83 		default:
84 			break;
85 		}
86 	}
87 
88 protected:
89 	PSPThreadContext &ctx;
90 };
91