cpu_interface.c
9.62 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
/*
* Copyright (C) 1998 by the Board of Trustees
* of Leland Stanford Junior University.
* Copyright (C) 1998 Digital Equipment Corporation
*
* This file is part of the SimOS distribution.
* See LICENSE file for terms of the license.
*
*/
/*
* Copyright (C) 1998 by the Board of Trustees
* of Leland Stanford Junior University.
*
* This file is part of the SimOS distribution.
* See LICENSE file for terms of the license.
*
*/
/*****************************************************************
* cpu_interface.c
*****************************************************************/
#include <sys/signal.h>
#include "syslimits.h"
#include "simtypes.h"
#include "cpu_interface.h"
#include "checkpoint.h"
#include "alpha.h"
#include "gamma.h"
#include "tcl_init.h"
#include "machine_params.h"
#include "sim_error.h"
#include "gdb_interface.h"
#include "alpha_gdb.h"
#include "ev5.h"
#include "addr_layout.h"
static CPUStatus GammaCPUStatus(int cpunum);
static void GammaHandleDebugSignal(int cpuid, int sigusr); /* Defined in debug.c */
static VA GammaCurrentPC(int);
extern void GammaExitSimulator( CPUType toSim );
static int GammaCurrentCpuNum(void);
static Inst GammaCurrentInstruction(int);
static Result GammaGetReg(int cpunum, int regnum, Reg *val);
static void GammaClearLockFlag(int cpunum);
static bool GammaGetLockFlag(int cpunum);
static PA GammaGetLockAddr(int cpu);
static Result GammaGetMem(int cpunum, VA vAddr, uint nbytes, char *buf);
static Result GammaTranslateVirtualNoSE(int cpunum, VA vAddr, PA *paddr);
static void GammaInstallMemAnnotation(VA);
static void GammaDMAInval(int machine, PA* k0list);
static void GammaLaunchSlaveCPU(int cpuNum);
static void GammaDoCheckpoint(int cpuNum);
bool tookCheckpoint = FALSE;
char *
GammaPAToHostAddr(int cpu, PA pAddr, VA vAddr)
{
#ifndef SOLO
return (PHYS_TO_MEMADDR(M_FROM_CPU(cpu),pAddr) +
(IS_REMAPPED_PADDR(pAddr,cpu) ? remapVec->NodeAddr[cpu] : 0));
#endif
#ifdef SOLO
return (char *)(vAddr);
#endif
}
extern void GammaFinishMemRequests(void);
/*****************************************************************
* CPUVectorInit
*****************************************************************/
void
GammaCPUVectorInit(void)
{
CPUVec.Handle_Debug_Signal = GammaHandleDebugSignal;
CPUVec.GetRegister = GammaGetReg;
CPUVec.PutRegister = GammaPutReg;
CPUVec.ClearLockFlag = GammaClearLockFlag;
CPUVec.GetLockFlag = GammaGetLockFlag;
CPUVec.GetLockAddr = GammaGetLockAddr;
CPUVec.GetMemory = GammaGetMem;
CPUVec.PutMemory = GammaPutMem;
CPUVec.TranslateVirtualNoSE = GammaTranslateVirtualNoSE;
CPUVec.InstallMemAnnotation = GammaInstallMemAnnotation;
CPUVec.Unstall = GammaUnstall;
CPUVec.CPUstatus = GammaCPUStatus;
CPUVec.CycleCount = GammaCycleCount;
CPUVec.DMAInval = GammaDMAInval;
CPUVec.ExitSimulator = GammaExitSimulator;
CPUVec.CurrentCpuNum = GammaCurrentCpuNum;
CPUVec.CurrentPC = GammaCurrentPC;
CPUVec.CurrentInstruction = GammaCurrentInstruction;
CPUVec.InstrCount = GammaInstructionCount;
CPUVec.DoCheckpoint = GammaDoCheckpoint;
#if 0
CPUVec.TakeBusError = GammaTakeBusError;
#endif
CPUVec.useMemRef = FALSE;
CPUVec.singleEventQueue = TRUE;
CPUVec.PAToHostAddr = GammaPAToHostAddr;
CPUVec.LaunchSlaveCPU = GammaLaunchSlaveCPU;
}
/*
*/
int
GammaCurrentCpuNum(void)
{
return curPE->myNum;
}
VA
GammaCurrentPC(int cpu)
{
return PE[cpu]->PC;
}
Inst GammaCurrentInstruction(int cpu)
{
return PE[cpu]->instr.word;
}
Result GammaGetReg(int cpu, int regnum, Reg *val)
{
AlphaState *P = PE[cpu];
if (regnum >=0 && regnum < 32) {
*val = P->reg[regnum];
return SUCCESS;
}
if (regnum >= 32 && regnum < 64) {
Reg *regP = (Reg *)&P->fp[regnum-32];
*val = *regP;
return SUCCESS;
}
/* shadow registers */
if (regnum >= SHADOW_REGNUM && regnum < (SHADOW_REGNUM+8)) {
int shadowset = 8;
Reg *regP;
if (EV5_ShadowRegistersUsed(P, P->PC)) {
/* return the saved register value */
shadowset = 0;
} else {
/* return the shadow register value */
shadowset = 8;
}
regP = (Reg *)&P->shadowRegs[regnum-67+shadowset];
*val = *regP;
return SUCCESS;
}
switch (regnum) {
case INSTR_REGNUM: *val = P->instr.word; break;
case PC_REGNUM: *val = P->PC; break;
case FPCR_REGNUM: *val = P->fpcr; break;
default:
CPUError("GammaGetReg: gdb register %d not defined \n",regnum);
}
return SUCCESS;
}
Result GammaPutReg(int cpu, int regnum, Reg val)
{
AlphaState *P = PE[cpu];
if (regnum >=0 && regnum < 32) {
P->reg[regnum] = val;
return SUCCESS;
}
if (regnum >= 32 && regnum < 64) {
P->fp[regnum-32] = val;
return SUCCESS;
}
switch (regnum) {
case PC_REGNUM: P->PC = val; break;
case FPCR_REGNUM: P->fpcr = val; break;
default:
CPUError("GammaGetReg: gdb register %d not defined \n",regnum);
}
return SUCCESS;
}
static void GammaClearLockFlag(int cpu)
{
AlphaState *P = PE[cpu];
P->lock_flag = 0;
}
static bool GammaGetLockFlag(int cpu)
{
AlphaState *P = PE[cpu];
return P->lock_flag;
}
static PA GammaGetLockAddr(int cpu)
{
AlphaState *P = PE[cpu];
return P->locked_addr;
}
Result GammaGetMem(int cpunum, VA vAddr, uint nbytes, char *buf)
{
int i;
PA pA=0;
buf[0] = 0;
for (i=0;i<nbytes;i++) {
if (EV5_DTranslateVirtual(PE[cpunum],vAddr+i,0,0,&pA)==MMU_SUCCESS) {
buf[i] = *(char *)PHYS_TO_MEMADDR(0,pA);
} else {
return FAILURE;
}
}
return SUCCESS;
}
Result GammaPutMem(int cpunum, VA vAddr, uint nbytes, char *buf)
{
int i;
PA pA=0;
CPUWarning("Put mem size %d addr 0x%lx buf 0x%x (flush cache) \n",nbytes,vAddr,*(uint32*)buf);
for (i=0;i<nbytes;i++) {
if (EV5_DTranslateVirtual(PE[cpunum],vAddr+i,0,0,&pA)==MMU_SUCCESS) {
*(char*)PHYS_TO_MEMADDR(0,pA) = buf[i];
} else {
return FAILURE;
}
}
return SUCCESS;
}
Result GammaTranslateVirtualNoSE(int cpunum, VA vAddr, PA *pAddr)
{
if (EV5_DTranslateVirtual(PE[cpunum],vAddr,0,0,pAddr)==MMU_SUCCESS) {
return SUCCESS;
} else {
return FAILURE;
}
}
/*****************************************************************
* GammaDebug
*
* Main entry point into the debugger from normal execution.
*
* NOTE: the second argument is_break_instruction is set when
* we call in due to a single-step trap (from cpu.c) even though
* there is no break instruction at the PC. We need to send
* the SIGTRAP to gdb in this case. If we send a SIGUSR2 it
* stops single-stepping immediately even though we may not
* have yet reached the next line boundary (for 'n' or 's').
*
* Return value 0 means nothing has changed, go through normal
* instruction completion (pc = npc, npc += 4, annotations, etc).
*
* Return value 1 means PC has changed or instruction at PC has
* been overwritten. If you entered the debugger between instructions
* abort anything you have read about the next instruction and restart.
* If you entered the debugger from a breakpoint, reexecute the
* instruction at that PC.
*
*****************************************************************/
int
GammaDebug(int cpunum, int is_break_instruction)
{
Simdebug_result res;
res = Simdebug_run(is_break_instruction ? SIGTRAP : SIGUSR2, cpunum);
switch (res) {
case SD_CONTINUE:
gamma_break_nexti = GAMMA_NOBREAK;
gamma_debug_mode = 0;
break;
case SD_NEXTI_ANYCPU:
gamma_break_nexti = GAMMA_BREAKANYCPU;
gamma_debug_mode = 1;
break;
default:
gamma_break_nexti = res;
gamma_debug_mode = 1;
break;
}
return 1;
}
/*****************************************************************
* HandleDebugSignal
*****************************************************************/
static void
GammaHandleDebugSignal(int cpuid, int sigusr)
{
gamma_debug_mode = 1;
if (sigusr) {
gamma_sigusr = 1;
} else {
if (cpuid == -1) {
gamma_break_nexti = GAMMA_BREAKANYCPU;
} else {
gamma_break_nexti = cpuid;
}
}
}
static CPUStatus GammaCPUStatus(int cpunum)
{
return PE[cpunum]->cpuState;
}
static void GammaInstallMemAnnotation(VA vA)
{ ;
}
void GammaDMAInval(int machine, PA* k0list)
{
;
}
/*****************************************************************
* HandleDebugSignal
*****************************************************************/
void GammaLaunchSlaveCPU(int cpuNum)
{
CPUWarning("GAMMA: launching cpu %d \n",cpuNum);
PE[cpuNum]->cpuState = cpu_running;
}
static void GammaDoCheckpoint(int cpuNum)
{
int i;
VA oldPC[SIM_MAXCPUS];
for(i=0;i<TOTAL_CPUS;i++) {
oldPC[i] = PE[i]->PC;
}
if (AnnFMLookup(PE[cpuNum]->PC,ANNFM_PC_TYPE)) {
/* most likely a post-pc annotation --> increment unless branch */
uint32 inst = CPUVec.CurrentInstruction(cpuNum);
union alpha_instruction ainst = (union alpha_instruction) inst;
switch (ainst.common.opcode) {
case op_call_pal:
case op_br:
case op_bsr:
case op_blbc:
case op_beq:
case op_blt:
case op_ble:
case op_blbs:
case op_bne:
case op_bge:
case op_bgt:
case op_fbeq:
case op_fblt:
case op_fble:
case op_fbne:
case op_fbge:
case op_fbgt:
case op_jsr:
break;
default:
PE[cpuNum]->PC += 4;
}
}
Simcpt_Checkpoint(CPT_SAVE,"");
for(i=0;i<TOTAL_CPUS;i++) {
PE[i]->PC = oldPC[i];
}
}