rmonregs.c
20.3 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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
/*
* ==========================================================================
* Copyright (c) 1994, Silicon Graphics, Inc. All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied
* or duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc. handleSelectExceptions
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished
* rights reserved under the Copyright Laws of the United States.
* ==========================================================================
*/
/************************************************************************
Program: rmon (reality monitor) in-circuit target monitor
File: regs.c
Author: Kenneth F. Greenberg
Purpose: The register access functions
Revision history:
94.10.24 Original
************************************************************************/
#ifndef _FINALROM
#include "dbgdefs.h" /* definitions needed by the following file */
#include "dbgproto.h" /* standard protocol definitions */
#ifdef __sgi__
#include "sys/types.h"
#endif
#include "rmonint.h" /* needs info in above files */
#include "rcp.h"
#include <rdb.h>
/*
When a breakpoint is encountered, the general registers are
copied into a static array and the monitor general registers
are restored. The register contents are swapped back when the
application is dispatched. The array holds the general registers
only. Some of the CP0 registers are also returned and set as
part of the general register commands in the protocol. These
occupy slots 32..36 in the register data messages. Thus, the
register contents look like:
$0
$1
.
.
$31
LO
HI
CAUSE
PC
SR
*/
static u32 RCPpc, oldIMEMvalue, DMEMbuffer[4];
#define READOP 0x2b /* |~2B */
#define WRITEOP 0x23 /* LW */
#define VREADOP 0x3a /* SWc2 */
#define VWRITEOP 0x32 /* LWc2 */
#define SCALAROP 0
#define VECTOROP 1
typedef union {
u32 everything;
struct {
int opcode: 6;
int base: 5;
int rt: 5;
int offset: 16;
} scalarop;
struct {
int opcode: 6;
int base: 5;
int rt: 5;
int size: 5;
int element: 4;
int offset: 7;
} vectorop;
} INSTRUCTION;
/************************************************************************
Function: (static) LoadStoreSU
Args:
int opcode - the opcode to use in the generated instruction
int regno - the number of the register of interest
Type: void
Purpose: This function performs a "microcode injection" of an instruction
(into IMEM) that loads or stores a word into DMEM in the RSP. It
is assumed that the contents of IMEM and DMEM have already been
preserved elsewhere. The instruction is built in memory from the
specified opcode (either load or store word, usually) and a
register number. All instructions are placed at location zero
in IMEM and data is placed at location zero in DMEM. The PC of
the RCP is set to zero as part of this function.
************************************************************************/
static void LoadStoreSU( int opcode, int regno )
{
INSTRUCTION inst;
inst.everything = 0;
inst.scalarop.opcode = opcode;
inst.scalarop.rt = regno;
__rmonWriteWordTo( (u32 *) IMEM_START, inst.everything );
__rmonWriteWordTo( (u32 *) SP_PC_REG, 0 );
}
/************************************************************************
Function: (static) LoadStoreVU
Args:
int opcode - the opcode to use in the generated instruction
int regno - the number of the register of interest
Type: void
Purpose: This function performs a "microcode injection" of an instruction
(into IMEM) that loads or stores a word into DMEM in the RSP. It
is assumed that the contents of IMEM and DMEM have already been
preserved elsewhere. The instruction is built in memory from the
specified opcode (either load or store word, usually) and a register
number. All instructions are placed at location zero in IMEM
and use memory starting at location zero in DMEM. The PC of the RCP
is set to zero as part of this function.
************************************************************************/
static void LoadStoreVU( int opcode, int regno )
{
INSTRUCTION inst;
inst.everything = 0;
inst.vectorop.opcode = opcode;
inst.vectorop.rt = regno;
inst.vectorop.size = 4; /* quad */
__rmonWriteWordTo( (u32 *) IMEM_START, inst.everything );
__rmonWriteWordTo( (u32 *) SP_PC_REG, 0 );
}
/************************************************************************
Function: (static) SetUpForRCPop
Args: int isVector - true if more space needs to be cleared in DMEM
Type: void
Purpose: This function sets up the PCP for a "microcode injection" op.
We need to do this to get at register contents, since they can
only be accessed by the RCP itself, not the R4200B. In this
function, we save enough of the RCP state to put it back where
it was when we were done.
************************************************************************/
static void SetUpForRCPop( int isVector )
{
RCPpc = __rmonReadWordAt( (u32 *) SP_PC_REG );
oldIMEMvalue = __rmonReadWordAt( (u32 *) IMEM_START );
DMEMbuffer[0] = __rmonReadWordAt( (u32 *) DMEM_START );
if ( isVector )
{
DMEMbuffer[1] = __rmonReadWordAt( (u32 *) DMEM_START+1 );
DMEMbuffer[2] = __rmonReadWordAt( (u32 *) DMEM_START+2 );
DMEMbuffer[3] = __rmonReadWordAt( (u32 *) DMEM_START+3 );
}
}
/************************************************************************
Function: (static) CleanupFromRCPop
Args: int isVector - true if more space needs to be restored in DMEM
Type: void
Purpose: This function restores the state of the RCP.
************************************************************************/
static void CleanupFromRCPop( int isVector )
{
__rmonWriteWordTo( (u32 *) DMEM_START, DMEMbuffer[0] );
if ( isVector )
{
__rmonWriteWordTo( (u32 *) DMEM_START+1, DMEMbuffer[1] );
__rmonWriteWordTo( (u32 *) DMEM_START+2, DMEMbuffer[2] );
__rmonWriteWordTo( (u32 *) DMEM_START+3, DMEMbuffer[2] );
}
__rmonWriteWordTo( (u32 *) IMEM_START, oldIMEMvalue );
__rmonWriteWordTo( (u32 *) SP_PC_REG, RCPpc );
}
/************************************************************************
Function: __rmonGetGRegisters
Args: KKHeader * req - address of the standard protocol structure for
reading general registers disguised as a header.
Type: int - returns 0 if successful, otherwise error type
Purpose: This function returns the value of the application's general
registers.
************************************************************************/
int __rmonGetGRegisters( KKHeader * req )
{
register KKObjectRequest * request = (KKObjectRequest *) req;
KKGregEvent reply;
Debug( "GetGRegisters\n" );
reply.tid = request->object;
reply.header.code = request->header.code;
reply.header.error = TV_ERROR_NO_ERROR;
if ( request->header.method == METHOD_NORMAL )
{
OSThread * tptr = __rmonGetTCB( request->object );
u64 * tcbregptr;
register int i;
if ( !tptr )
return TV_ERROR_INVALID_ID;
for ( i = 1, tcbregptr = &tptr->context.at; i < 26; ++i, ++tcbregptr )
reply.registers.gregs[i] = (u32) (*tcbregptr);
for ( i = 28, tcbregptr = &tptr->context.gp; i < 34; ++i, ++tcbregptr )
reply.registers.gregs[i] = (u32) (*tcbregptr);
reply.registers.gregs[34] = tptr->context.cause;
reply.registers.gregs[35] = tptr->context.pc;
reply.registers.gregs[36] = tptr->context.sr;
reply.registers.gregs[0] = 0;
}
else
return TV_ERROR_INVALID_ID;
__rmonSendReply( (KKHeader * const) &reply, sizeof( KKGregEvent ), _KK_REPLY );
return 0;
}
/************************************************************************
Function: __rmonSetGRegisters
Args: KKHeader * req - address of the standard protocol structure for
reading general registers disguised as a header.
Type: int - returns 0 if successful, otherwise error type
Purpose: This function changes the value of the application's general
registers.
************************************************************************/
int __rmonSetGRegisters( KKHeader * req )
{
register KKGRegsetRequest * request = (KKGRegsetRequest *) req;
KKObjectEvent reply;
Debug( "SetGRegisters\n" );
if ( request->header.method == METHOD_NORMAL ) /* set R4300 gen regs */
{
OSThread * tptr = __rmonGetTCB( request->tid );
u64 * tcbregptr;
register int i;
if ( !tptr )
return TV_ERROR_INVALID_ID;
for ( i = 1, tcbregptr = &tptr->context.at; i < 26; ++i, ++tcbregptr )
*tcbregptr = (u64) ((s32)(request->registers.gregs[i]));
for ( i = 28, tcbregptr = &tptr->context.gp; i < 34; ++i, ++tcbregptr )
*tcbregptr = (u64) ((s32)(request->registers.gregs[i]));
tptr->context.cause = request->registers.gregs[34];
tptr->context.pc = request->registers.gregs[35];
tptr->context.sr = request->registers.gregs[36];
}
else
return TV_ERROR_INVALID_ID;
/* Worked OK, send ack */
reply.object = request->tid;
reply.header.code = request->header.code;
reply.header.error = TV_ERROR_NO_ERROR;
__rmonSendReply( (KKHeader * const) &reply, sizeof( KKObjectEvent ), _KK_REPLY );
return 0;
}
/************************************************************************
Function: __rmonGetFRegisters
Args: KKHeader * req - address of the standard protocol structure for
reading floating point registers disguised as a header.
Type: int - returns 0 if successful, otherwise error type
Purpose: This function returns the value of the application's floating
point registers.
************************************************************************/
int __rmonGetFRegisters( KKHeader * req )
{
register KKObjectRequest * request = (KKObjectRequest *) req;
KKFPregEvent reply;
OSThread * tptr;
volatile float f;
Debug( "GetFRegisters\n" );
if ( req->method != METHOD_NORMAL )
return TV_ERROR_INVALID_ID;
/*
* Touch a floating point register to become the owner of the floating
* point unit (and force the previous owner to save its registers.
*/
f = 0.0F;
tptr = __rmonGetTCB( request->object );
if ( !tptr )
return TV_ERROR_INVALID_ID;
__rmonCopyWords( (u32 *) &reply.registers,
(u32 *) &tptr->context.fp0, 32 );
reply.registers.fpcsr = tptr->context.fpcsr;
reply.header.code = request->header.code;
reply.header.error = TV_ERROR_NO_ERROR;
reply.tid = request->object;
__rmonSendReply( (KKHeader * const) &reply, sizeof( KKFPregEvent ), _KK_REPLY );
return 0;
}
/************************************************************************
Function: __rmonSetFRegisters
Args: KKHeader * req - address of the standard protocol structure for
writing floating point registers disguised as a header.
Type: int - returns 0 if successful, otherwise error type
Purpose: This function changes the value of the application's floating
point registers.
************************************************************************/
int __rmonSetFRegisters( KKHeader * req )
{
register KKFPRegsetRequest * request = (KKFPRegsetRequest *) req;
KKObjectEvent reply;
OSThread * tptr;
volatile float f;
Debug( "SetFRegisters\n" );
if ( req->method != METHOD_NORMAL )
return TV_ERROR_INVALID_ID;
/*
* Touch a floating point register to become the owner of the floating
* point unit (and force the previous owner to save its registers.
*/
f = 0.0F;
tptr = __rmonGetTCB( request->tid );
if ( !tptr )
return TV_ERROR_INVALID_ID;
__rmonCopyWords( (u32 *) &tptr->context.fp0,
(u32 *) request->registers.fpregs.fregs, 32 );
tptr->context.fpcsr = request->registers.fpcsr;
reply.object = request->tid;
reply.header.code = request->header.code;
reply.header.error = TV_ERROR_NO_ERROR;
__rmonSendReply( (KKHeader * const) &reply, sizeof( KKObjectEvent ), _KK_REPLY );
return 0;
}
/************************************************************************
Function: (static) rmonGetRcpRegister
Args: int regNumber - which one
Type: u32 - register contents
Purpose: This function returns the value of one RCP scalar register.
It is only called when calculating a branch target where the branch
is a jump to register contents.
************************************************************************/
static u32 rmonGetRcpRegister( int regNumber )
{
u32 contents;
if ( __rmonRCPrunning() )
return 0; /* can't do much here, but very unlikely */
SetUpForRCPop( SCALAROP );
LoadStoreSU( READOP, regNumber );
__rmonStepRCP();
contents = __rmonReadWordAt( (u32 *) DMEM_START );
CleanupFromRCPop( SCALAROP );
return contents;
}
/************************************************************************
Function: __rmonGetSRegisters
Args: KKHeader * req - address of the standard protocol structure for
reading scalar registers disguised as a header.
Type: int - returns 0 if successful, otherwise error type
Purpose: This function returns the value of the RCP scalar and some CP0
registers.
************************************************************************/
int __rmonGetSRegs( KKHeader * req )
{
register KKObjectRequest * request = (KKObjectRequest *) req;
KKCpSregEvent reply;
register int i;
Debug( "GetSRegisters\n" );
if ( __rmonRCPrunning() )
return TV_ERROR_OP_PROTECTED;
reply.tid = request->object;
reply.header.code = request->header.code;
reply.header.error = TV_ERROR_NO_ERROR;
/*
To read the scalar registers in the RSP, one
just goes through the following simple 12-step
process...
1) Halt the RCP if it is running.
2) Read and save the program counter;
3) Read and save a block of IMEM where the
code to read regs can be written.
4) Read and save a block of DMEM where the
register contents will be written.
5) Write code to the saved IMEM area
6) Set the PC to the start of the saved IMEM
area.
7) Single step the processor through the code.
8) Copy the contents of DMEM
9) Restore the contents of IMEM
10) Restore the contents of DMEM
11) Restore the PC
12) If the RCP was running, restart it.
*/
SetUpForRCPop( SCALAROP );
/* Loop 32 times, getting a register */
for ( i = 0; i < 32; ++i )
{
LoadStoreSU( READOP, i );
__rmonStepRCP();
reply.registers.sregs[i] =
__rmonReadWordAt( (u32 *) DMEM_START );
}
CleanupFromRCPop( SCALAROP );
reply.registers.sregs[32] = __rmonReadWordAt( (u32 *)SP_DRAM_ADDR_REG );
reply.registers.sregs[33] = __rmonReadWordAt( (u32 *)SP_MEM_ADDR_REG );
reply.registers.sregs[34] = __rmonReadWordAt( (u32 *)SP_RD_LEN_REG );
reply.registers.sregs[35] =
__rmonReadWordAt( (u32 *) SP_PC_REG ) + IMEM_START;
reply.registers.sregs[36] = __rmonReadWordAt( (u32 *)SP_WR_LEN_REG );
reply.registers.sregs[37] = __rmonReadWordAt( (u32 *)SP_STATUS_REG );
reply.registers.sregs[38] = __rmonReadWordAt( (u32 *)SP_DMA_FULL_REG );
reply.registers.sregs[39] = __rmonReadWordAt( (u32 *)SP_DMA_BUSY_REG );
__rmonSendReply( (KKHeader * const) &reply, sizeof( KKCpSregEvent ), _KK_REPLY );
return 0;
}
/************************************************************************
Function: __rmonSetSRegisters
Args: KKHeader * req - address of the standard protocol structure for
setting scalar registers disguised as a header.
Type: int - returns 0 if successful, otherwise error type
Purpose: This function changes the value of the application's scalar
and CP0 registers.
************************************************************************/
int __rmonSetSRegs( KKHeader * req )
{
register KKCpScalarRegsetRequest * request =
(KKCpScalarRegsetRequest *) req;
KKObjectEvent reply;
register int i;
Debug( "SetSRegisters\n" );
if ( __rmonRCPrunning() )
return TV_ERROR_OP_PROTECTED;
SetUpForRCPop( SCALAROP );
/* Loop 32 times, loading a register */
for ( i = 0; i < 32; ++i )
{
__rmonWriteWordTo( (u32 *) DMEM_START,
request->registers.sregs[i] );
LoadStoreSU( WRITEOP, i );
__rmonStepRCP();
}
CleanupFromRCPop( SCALAROP );
__rmonWriteWordTo( (u32 *)SP_DRAM_ADDR_REG, request->registers.sregs[32] );
__rmonWriteWordTo( (u32 *)SP_MEM_ADDR_REG, request->registers.sregs[33] );
__rmonWriteWordTo( (u32 *) SP_PC_REG,
request->registers.sregs[35] & 0xfff );
__rmonWriteWordTo( (u32 *)SP_WR_LEN_REG, request->registers.sregs[36] );
__rmonWriteWordTo( (u32 *)SP_STATUS_REG, request->registers.sregs[37] );
reply.object = request->tid;
reply.header.code = request->header.code;
reply.header.error = TV_ERROR_NO_ERROR;
__rmonSendReply( (KKHeader * const) &reply, sizeof( KKObjectEvent ), _KK_REPLY );
return 0;
}
/************************************************************************
Function: __rmonGetVRegisters
Args: KKHeader * req - address of the standard protocol structure for
reading vector registers disguised as a header.
Type: int - returns 0 if successful, otherwise error type
Purpose: This function returns the value of the RCP vector
registers.
************************************************************************/
int __rmonGetVRegs( KKHeader * req )
{
unsigned char *cPtr;
int sent;
int dataSize;
register KKObjectRequest * request = (KKObjectRequest *) req;
KKCpVregEvent reply;
register int i;
Debug( "GetVRegisters\n" );
if ( __rmonRCPrunning() )
return TV_ERROR_OP_PROTECTED;
reply.tid = request->object;
reply.header.code = request->header.code;
reply.header.error = TV_ERROR_NO_ERROR;
reply.header.length = sizeof( KKCpVregEvent );
dataSize = sizeof( KKHeader ) + sizeof( TVid ) + (32 * 16);
cPtr = (unsigned char*)&dataSize;
/* send the size of the transfer */
sent = 0;
while(sent < 4)
sent += __osRdbSend(&cPtr[sent],4-sent,RDB_TYPE_GtoH_DEBUG);
__rmonSendHeader( (KKHeader * const) &reply,
sizeof( KKHeader ) + sizeof( TVid ), _KK_REPLY );
SetUpForRCPop( VECTOROP );
/*
Loop 32 times, getting a register at
a time into DMEM and sending its value
to the host debugger.
*/
for ( i = 0; i < 32; ++i )
{
LoadStoreVU( VREADOP, i );
__rmonStepRCP();
__rmonSendData( (const char *) DMEM_START, 16 );
}
CleanupFromRCPop( VECTOROP );
return 0;
}
/************************************************************************
Function: __rmonSetVRegisters
Args: KKHeader * req - address of the standard protocol structure for
setting vector registers disguised as a header.
Type: int - returns 0 if successful, otherwise error type
Purpose: This function changes the value of the application's vector
registers.
************************************************************************/
int __rmonSetVRegs( KKHeader * req )
{
register KKCpVectorRegsetRequest * request =
(KKCpVectorRegsetRequest *) req;
KKObjectEvent reply;
register int i;
Debug( "SetVRegs\n" );
if ( __rmonRCPrunning() )
return TV_ERROR_OP_PROTECTED;
SetUpForRCPop( VECTOROP );
/*
Loop 32 times, getting a register at
a time into DMEM.
*/
for ( i = 0; i < 32; ++i )
{
__rmonCopyWords( (u32 *) DMEM_START,
(u32 *) &request->registers.vregs[i],
4 );
LoadStoreVU( VWRITEOP, i );
__rmonStepRCP();
}
CleanupFromRCPop( VECTOROP );
reply.object = request->tid;
reply.header.code = request->header.code;
reply.header.error = TV_ERROR_NO_ERROR;
__rmonSendReply( (KKHeader * const) &reply, sizeof( KKObjectEvent ), _KK_REPLY );
return 0;
}
/************************************************************************
Function: __rmonGetRegisterContents
Args:
int method - which processor is of interest
int threadNumber - which thread to use for reg info
int regNumber - which register to return
Type: u32 - returns the contents of the register
Purpose: This function obtains the contents of the register specifed from
either the static application register storage area or the Thread
Control Block. This function is called by the routine that sets
breakpoints for stepping through a jump to register contents inst.
************************************************************************/
u32 __rmonGetRegisterContents( int method, int threadNumber, int regNumber )
{
if ( method == METHOD_NORMAL )
{
u32 * regPointer;
OSThread * tptr;
if ( regNumber >= 1 && regNumber <= 25 )
regNumber -= 1; /* no stored 0 */
else if ( regNumber >= 28 && regNumber <= 31 )
regNumber -= 3; /* no stored 0, 26, 27 */
else
return 0; /* not available */
tptr = __rmonGetTCB( threadNumber );
if ( !tptr )
return 0;
regPointer = (u32 *) &tptr->context;
regPointer += regNumber;
return *regPointer;
}
else /* is a coprocessor register */
return rmonGetRcpRegister( regNumber );
}
#endif /* #ifndef _FINALROM */