debug_trans.c
4.74 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
/*
* Copyright (C) 1996-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.
*
*/
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <disassembler.h>
#include "mshade.h"
#include "cp0.h"
#include "tc.h"
#include "stats.h"
int trans_test_num_decoded;
/* Dummy Functions */
void callout(void) {}
void mem_ref_wrapper(void) {}
void phys_mem_ref_wrapper(void) {}
void do_periodic_callout(void) {}
void get_fc31(void){}
void compare_and_swap(unsigned u, unsigned u1, unsigned u2){}
void ReenterTC(void){}
void continue_run(void) {}
void continue_run_without_chaining(void) {}
void Clear_Translation_State(){}
void icache_coherence_flush( void ) {}
int icache_coherence_is_code( PA pAddr ) { return 1;}
void icache_coherence_mark_code( K0A start, K0A finish ) {}
void icache_coherence_check( PA start, PA finish, VA vAddr ) {}
void Embra_CX(void) {}
int hw_counter_start( HW_counter* count ) {}
int hw_counter_stop( HW_counter* count ) {}
double sqrt(double d) {}
K0A mem_ref( VA vAddr, int new_state ) {}
void qc_downgrade( VA vAddr, int new_state ) {}
void em_remap(void) {}
void UPperiodic_callout(void) {}
void CSpillFP(void) {}
void FlashliteConfigDefaults(void) {}
uint ICheckLevel;
typedef struct {
uint addr;
char* name;
}rout2name;
static rout2name r2n[] = {
{ (uint) callout, "callout" },
{ (uint) mem_ref_wrapper, "mem_ref_wrapper" },
{ (uint) phys_mem_ref_wrapper, "phys_mem_ref_wrapper" },
{ (uint) do_periodic_callout, "do_periodic_callout" },
{ (uint) compare_and_swap, "compare_and_swap" },
{ (uint) continue_run, "continue_run" },
{ (uint) continue_run_without_chaining, "continue_run_without_chaining"},
};
#define R2N_SIZE (sizeof(r2n)/sizeof(r2n[0]))
/* Dummy Globals */
int numCPUs;
stats_t em_stats;
/* Initialized globals */
TC realtc;
TC* tc = &realtc;
CPUType emode;
EmbraState PE_Space[1];
EmbraState* PE = PE_Space;
EmbraState* EMP = PE_Space;
int is_R4000;
int MPinUP;
int Simcp0MustRunCPU(void)
{
return 1;
}
K0A non_excepting_tv( int cpuNum, VA va )
{
return va;
}
K0A mem_translate( int cpuNum, VA vAddr )
{
return vAddr;
}
Result
Em_TranslateVirtual(int cpuNum, VA vAddr, PA *pAddr, Em_accesstype act)
{
*pAddr = vAddr;
return NORMAL_CODE;
}
main(int argc, char** argv)
{
int fd;
unsigned* instr;
long len;
unsigned g1, g2, g3;
char buf[100];
unsigned i;
unsigned* code_ptr;
uint* trans_ptr;
uint* trans_end_ptr;
int c;
extern int optind;
uint map_addr = 0;
is_R4000 = 1;
emode = EMBRA_PAGE;
EMP[0].outTC = 1;
MPinUP = 0;
while ((c = getopt(argc, argv, "pckum")) != EOF) {
switch (c) {
case 'p':
emode = EMBRA_PAGE;
break;
case 'm':
MPinUP = 1;
break;
case 'c':
emode = EMBRA_CACHE;
break;
case 'k':
map_addr = 0x60000000;
break;
case 'u':
map_addr = 0;
break;
default:
printf("Usage: %s -p (page) -c (cache) -u (user) -k (kernel) -m (MPinUP)\n", argv[0]);
}
}
SimConfigDefaults();
tc = TC_init();
DecoderInit();
Translator_Init();
pc_tc_init();
dis_init( 0, 0, 0, 1);
fd = open( argv[optind], O_RDWR, 0);
if( fd == -1 ) {
printf("Can't open %s\n", argv[optind]);
perror("open");
}
len = lseek(fd,0,SEEK_END);
if( map_addr ) {
instr = (unsigned*)mmap((void*)map_addr, len, (PROT_READ),
(MAP_PRIVATE|MAP_FIXED), fd, 0);
if( (int) instr != map_addr )
perror("mmap");
} else {
instr = (unsigned*)mmap((void*)0, len, (PROT_READ),
(MAP_PRIVATE), fd, 0);
if( (int) instr == -1 )
perror("mmap");
}
code_ptr = instr;
while( (unsigned)code_ptr < ((unsigned)instr+len) ) {
int junk;
Translate( 0, code_ptr, &junk );
code_ptr = (unsigned*)
((unsigned)code_ptr + (trans_test_num_decoded * sizeof(unsigned)));
}
if( map_addr ) {
trans_ptr = tc->kern_buf;
trans_end_ptr = (uint*)tc->kern_next;
} else {
trans_ptr = tc->exec_buf;
trans_end_ptr = (uint*)tc->next;
}
while( trans_ptr < trans_end_ptr ) {
int inst_type;
uint target;
inst_type = disasm( buf, (uint)trans_ptr, *trans_ptr, &g1, &target, &g3 );
trans_ptr++;
printf("%s", buf);
switch( inst_type ) {
case 1: {
int i;
for( i = 0; i < R2N_SIZE; i++ ) {
if( target == r2n[i].addr ) {
printf(" %s", r2n[i].name);
break;
}
}
}
break;
}
printf("\n");
}
}