-
Notifications
You must be signed in to change notification settings - Fork 1
/
xdinfmt.c
198 lines (187 loc) · 6.3 KB
/
xdinfmt.c
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
/*
* Code to read the extended ascii "din" format for Dinero IV.
* Written by Jan Edler
*
* Copyright (C) 1997 NEC Research Institute, Inc. and Mark D. Hill.
* All rights reserved.
* Copyright (C) 1985, 1989 Mark D. Hill. All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and
* its associated documentation for non-commercial purposes is hereby
* granted (for commercial purposes see below), provided that the above
* copyright notice appears in all copies, derivative works or modified
* versions of the software and any portions thereof, and that both the
* copyright notice and this permission notice appear in the documentation.
* NEC Research Institute Inc. and Mark D. Hill shall be given a copy of
* any such derivative work or modified version of the software and NEC
* Research Institute Inc. and any of its affiliated companies (collectively
* referred to as NECI) and Mark D. Hill shall be granted permission to use,
* copy, modify, and distribute the software for internal use and research.
* The name of NEC Research Institute Inc. and its affiliated companies
* shall not be used in advertising or publicity related to the distribution
* of the software, without the prior written consent of NECI. All copies,
* derivative works, or modified versions of the software shall be exported
* or reexported in accordance with applicable laws and regulations relating
* to export control. This software is experimental. NECI and Mark D. Hill
* make no representations regarding the suitability of this software for
* any purpose and neither NECI nor Mark D. Hill will support the software.
*
* Use of this software for commercial purposes is also possible, but only
* if, in addition to the above requirements for non-commercial use, written
* permission for such use is obtained by the commercial user from NECI or
* Mark D. Hill prior to the fabrication and distribution of the software.
*
* THE SOFTWARE IS PROVIDED AS IS. NECI AND MARK D. HILL DO NOT MAKE
* ANY WARRANTEES EITHER EXPRESS OR IMPLIED WITH REGARD TO THE SOFTWARE.
* NECI AND MARK D. HILL ALSO DISCLAIM ANY WARRANTY THAT THE SOFTWARE IS
* FREE OF INFRINGEMENT OF ANY INTELLECTUAL PROPERTY RIGHTS OF OTHERS.
* NO OTHER LICENSE EXPRESS OR IMPLIED IS HEREBY GRANTED. NECI AND MARK
* D. HILL SHALL NOT BE LIABLE FOR ANY DAMAGES, INCLUDING GENERAL, SPECIAL,
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, ARISING OUT OF THE USE OR INABILITY
* TO USE THE SOFTWARE.
*
* $Header: /home/edler/dinero/d4/RCS/xdinfmt.c,v 1.4 1997/12/12 20:36:39 edler Exp $
*/
#include <stddef.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "d4.h"
#include "cmdd4.h"
#include "tracein.h"
/*
* Read in ASCII from standard input
* Expect 3 significant fields per line:
* accesstype address size
* The rest of the data input line is ignored so it may be used for comments.
*
* Accesstype is
* r read
* w write
* i instruction fetch
* m miscellaneous (like a read but won't generate prefetch)
* c copyback (no invalidate implied)
* v invalidate (no copyback implied)
* Address and size are hexadecimal, with optional 0x or 0X prefix.
*/
d4memref
tracein_xdin()
{
static double tcount = 1; /* double to increase range */
static char badatype[] = "xdin format error on trace record %.0f: unknown atype: %s"
"Consider -informat d for Dinero III input format\n";
static char badaddr[] = "xdin format error on trace record %.0f: non hex digit (code 0x%x) in address\n";
static char shortline[] = "xdin format error on trace record %.0f: short line\n";
static char badsize[] = "xdin format error on trace record %.0f: non hex digit (code 0x%x) in size\n";
static char nosize[] = "xdin format error on trace record %.0f: missing size\n";
char errline[128];
d4addr addr;
int size, atype;
d4memref r;
int c, cc;
/* skip initial whitespace */
do {
c = getchar();
} while (c == ' ' || c == '\t');
if (c == EOF) {
r.address = 0;
r.size = 0;
r.accesstype = D4TRACE_END;
return r; /* this will trigger normal termination */
}
if (c == '\n')
die (shortline, tcount);
/* the accesstype is just 1 char */
switch (c) {
default: {
char __attribute__((unused)) *ptr;
errline[0] = c;
ptr = fgets (errline+1, sizeof(errline)-1, stdin);
errline[strlen(errline)-1] = '\n'; /* ensure trailing \n */
die (badatype, tcount, errline);
/* no return */
}
case 'r':
case 'R':
atype = D4XREAD;
break;
case 'w':
case 'W':
atype = D4XWRITE;
break;
case 'i':
case 'I':
atype = D4XINSTRN;
break;
case 'm':
case 'M':
atype = D4XMISC;
break;
case 'c':
case 'C':
atype = D4XCOPYB;
break;
case 'v':
case 'V':
atype = D4XINVAL;
break;
}
cc = getchar();
if (cc == '\n')
die (shortline, tcount);
if (cc != ' ' && cc != '\t') {
char __attribute__((unused)) *ptr;
errline[0] = c;
errline[1] = cc;
ptr = fgets (errline+2, sizeof(errline)-2, stdin);
errline[strlen(errline)-1] = '\n'; /* ensure trailing \n */
die (badatype, tcount, errline);
}
/* skip whitespace between atype and address */
do {
c = getchar();
} while (c == ' ' || c == '\t');
if (c == '\n' || c == EOF)
die (shortline, tcount);
/* now get the address */
if (!isxdigit(c))
die (badaddr, tcount, c);
addr = c - (isdigit(c) ? '0' : ((islower(c) ? 'a' : 'A') - 10));
c = getchar();
if ((c == 'x' || c == 'X') && addr == 0)
c = getchar(); /* ignore leading 0x or 0X */
while (isxdigit(c)) {
addr *= 16;
addr += c - (isdigit(c) ? '0' : ((islower(c) ? 'a' : 'A') - 10));
c = getchar();
}
if (c != EOF && c != '\n' && c != ' ' && c != '\t')
die (badaddr, tcount, c);
/* skip whitespace between addr and size */
while (c == ' ' || c == '\t')
c = getchar();
if (c == EOF || c == '\n')
die (nosize, tcount);
/* now get the size */
if (!isxdigit(c))
die (badsize, tcount, c);
size = c - (isdigit(c) ? '0' : ((islower(c) ? 'a' : 'A') - 10));
c = getchar();
if ((c == 'x' || c == 'X') && size == 0)
c = getchar(); /* ignore leading 0x or 0X */
while (isxdigit(c)) {
size *= 16;
size += c - (isdigit(c) ? '0' : ((islower(c) ? 'a' : 'A') - 10));
c = getchar();
}
if (c != EOF && c != '\n' && c != ' ' && c != '\t')
die (badsize, tcount, c);
/* skip rest of line */
while (c != '\n' && c != EOF)
c = getchar();
r.accesstype = atype;
r.address = addr;
r.size = size;
tcount += 1;
return r;
}