-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathpsp-emu.c
More file actions
163 lines (139 loc) · 4.72 KB
/
Copy pathpsp-emu.c
File metadata and controls
163 lines (139 loc) · 4.72 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/** @file
* PSP Emulator - Entry point.
*/
/*
* Copyright (C) 2020 Alexander Eichner <alexander.eichner@campus.tu-berlin.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <errno.h>
#include <libpspproxy.h>
#include <common/cdefs.h>
#include <common/status.h>
#include <psp-fw/boot-rom-svc-page.h>
#include <psp-ccd.h>
#include <psp-cfg.h>
#include <psp-dbg.h>
#include <psp-proxy.h>
#include <psp-iolog-replay.h>
#include <psp-x86-ice.h>
/**
* Executes the given CCD under debugger control.
*
* @returns Status code.
* @param hCcd The CCD instance to run in a debugger.
* @param pCfg The configuration.
*/
static int pspEmuDbgRun(PSPCCD hCcd, PCPSPEMUCFG pCfg)
{
PSPCORE hPspCore = NULL;
int rc = PSPEmuCcdQueryCore(hCcd, &hPspCore);
if (!rc)
{
/*
* Execute one instruction to initialize the CPU state properly
* so the debugger has valid values to work with.
*/
int rc = PSPEmuCoreExecRun(hPspCore, PSPEMU_CORE_EXEC_F_DEFAULT, 1, PSPEMU_CORE_EXEC_INDEFINITE);
if (!rc)
{
PSPDBG hDbg = NULL;
rc = PSPEmuDbgCreate(&hDbg, pCfg->uDbgPort, pCfg->cDbgInsnStep, pCfg->PspAddrDbgRunUpTo,
&hCcd, 1, pCfg->hDbgHlp);
if (!rc)
{
printf("Debugger is listening on port %u...\n", pCfg->uDbgPort);
rc = PSPEmuDbgRunloop(hDbg);
}
}
}
return rc;
}
int main(int argc, char *argv[])
{
PSPEMUCFG Cfg;
PSPCfgInit(&Cfg);
/* Parse the config first. */
int rc = PSPCfgParse(&Cfg, argc, (const char * const *)&argv[0]);
if (STS_SUCCESS(rc))
{
/* Create a debug helper module if the debugger is going to be used. */
if (Cfg.uDbgPort)
rc = PSPEmuDbgHlpCreate(&Cfg.hDbgHlp);
if (STS_SUCCESS(rc))
{
PSPCCD hCcd = NULL;
if ( Cfg.idSocketSingle != UINT32_MAX
&& Cfg.idCcdSingle != UINT32_MAX)
rc = PSPEmuCcdCreate(&hCcd, Cfg.idSocketSingle, Cfg.idCcdSingle, &Cfg);
else
rc = PSPEmuCcdCreate(&hCcd, 0, 0, &Cfg);
if (!rc)
{
PSPPROXY hProxy = NULL;
PSPX86ICE hX86Ice = NULL;
PSPIOLOGREPLAY hIoLogReplay = NULL;
/* Setup the proxy if configured. */
if (Cfg.pszPspProxyAddr)
{
rc = PSPProxyCreate(&hProxy, &Cfg);
if (!rc)
rc = PSPProxyCcdRegister(hProxy, hCcd);
if ( STS_SUCCESS(rc)
&& Cfg.uX86IcePort)
{
rc = PSPX86IceCreate(&hX86Ice, Cfg.uX86IcePort);
if (STS_SUCCESS(rc))
{
/* Register the ICE bridge with the proxy. */
rc = PSPProxyX86IceRegister(hProxy, hX86Ice);
}
}
}
else if (Cfg.pszIoLogReplay)
{
rc = PSPIoLogReplayCreate(&hIoLogReplay, Cfg.pszIoLogReplay);
if (STS_SUCCESS(rc))
rc = PSPIoLogReplayCcdRegister(hIoLogReplay, hCcd);
}
if (!rc)
{
if (Cfg.uDbgPort)
rc = pspEmuDbgRun(hCcd, &Cfg);
else
rc = PSPEmuCcdRun(hCcd);
}
if (hProxy)
{
PSPProxyCcdDeregister(hProxy, hCcd);
PSPProxyDestroy(hProxy);
}
if (hIoLogReplay)
{
PSPIoLogReplayCcdDeregister(hIoLogReplay, hCcd);
PSPIoLogReplayDestroy(hIoLogReplay);
}
PSPEmuCcdDestroy(hCcd);
}
}
PSPCfgFree(&Cfg);
}
else
fprintf(stderr, "Parsing arguments failed with %d\n", rc);
return 0;
}