Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* |
2 | * func.c, misc simulator functions. This file is part of SIS. | |
3 | * | |
4 | * SIS, SPARC instruction simulator V1.8 Copyright (C) 1995 Jiri Gaisler, | |
5 | * European Space Agency | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify it under | |
8 | * the terms of the GNU General Public License as published by the Free | |
3fd725ef | 9 | * Software Foundation; either version 3 of the License, or (at your option) |
c906108c SS |
10 | * any later version. |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
15 | * more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License along with | |
51b318de | 18 | * this program; if not, see <http://www.gnu.org/licenses/>. |
c906108c SS |
19 | * |
20 | */ | |
21 | ||
5272643f | 22 | #include "config.h" |
c906108c SS |
23 | #include <signal.h> |
24 | #include <string.h> | |
25 | #include <stdio.h> | |
26 | #include <stdlib.h> | |
27 | #include <ctype.h> | |
28 | #include "sis.h" | |
c906108c SS |
29 | #include <dis-asm.h> |
30 | #include "sim-config.h" | |
638fcdad | 31 | #include <inttypes.h> |
c906108c SS |
32 | |
33 | ||
34 | #define VAL(x) strtoul(x,(char **)NULL,0) | |
35 | ||
36 | extern int current_target_byte_order; | |
37 | struct disassemble_info dinfo; | |
38 | struct pstate sregs; | |
39 | extern struct estate ebase; | |
40 | int ctrl_c = 0; | |
41 | int sis_verbose = 0; | |
42 | char *sis_version = "2.7.5"; | |
43 | int nfp = 0; | |
44 | int ift = 0; | |
45 | int wrp = 0; | |
46 | int rom8 = 0; | |
47 | int uben = 0; | |
48 | int termsave; | |
49 | int sparclite = 0; /* emulating SPARClite instructions? */ | |
50 | int sparclite_board = 0; /* emulating SPARClite board RAM? */ | |
51 | char uart_dev1[128] = ""; | |
52 | char uart_dev2[128] = ""; | |
53 | extern int ext_irl; | |
54 | uint32 last_load_addr = 0; | |
55 | ||
56 | #ifdef ERRINJ | |
57 | uint32 errcnt = 0; | |
58 | uint32 errper = 0; | |
59 | uint32 errtt = 0; | |
60 | uint32 errftt = 0; | |
61 | uint32 errmec = 0; | |
62 | #endif | |
63 | ||
64 | /* Forward declarations */ | |
65 | ||
bdca5ee4 TT |
66 | static int batch (struct pstate *sregs, char *fname); |
67 | static void set_rega (struct pstate *sregs, char *reg, uint32 rval); | |
68 | static void disp_reg (struct pstate *sregs, char *reg); | |
69 | static uint32 limcalc (float32 freq); | |
70 | static void int_handler (int32 sig); | |
71 | static void init_event (void); | |
72 | static int disp_fpu (struct pstate *sregs); | |
73 | static void disp_regs (struct pstate *sregs, int cwp); | |
74 | static void disp_ctrl (struct pstate *sregs); | |
75 | static void disp_mem (uint32 addr, uint32 len); | |
c906108c SS |
76 | |
77 | static int | |
78 | batch(sregs, fname) | |
79 | struct pstate *sregs; | |
80 | char *fname; | |
81 | { | |
82 | FILE *fp; | |
b9f9ea2f JG |
83 | char *lbuf = NULL; |
84 | size_t len = 0; | |
85 | size_t slen; | |
c906108c SS |
86 | |
87 | if ((fp = fopen(fname, "r")) == NULL) { | |
88 | fprintf(stderr, "couldn't open batch file %s\n", fname); | |
5831e29b | 89 | return 0; |
c906108c | 90 | } |
b9f9ea2f JG |
91 | while (getline(&lbuf, &len, fp) > -1) { |
92 | slen = strlen(lbuf); | |
93 | if (slen && (lbuf[slen - 1] == '\n')) { | |
94 | lbuf[slen - 1] = 0; | |
95 | printf("sis> %s\n", lbuf); | |
96 | exec_cmd(sregs, lbuf); | |
97 | } | |
c906108c | 98 | } |
b9f9ea2f | 99 | free(lbuf); |
c906108c | 100 | fclose(fp); |
5831e29b | 101 | return 1; |
c906108c SS |
102 | } |
103 | ||
104 | void | |
105 | set_regi(sregs, reg, rval) | |
106 | struct pstate *sregs; | |
107 | int32 reg; | |
108 | uint32 rval; | |
109 | { | |
110 | uint32 cwp; | |
111 | ||
112 | cwp = ((sregs->psr & 0x7) << 4); | |
113 | if ((reg > 0) && (reg < 8)) { | |
114 | sregs->g[reg] = rval; | |
115 | } else if ((reg >= 8) && (reg < 32)) { | |
116 | sregs->r[(cwp + reg) & 0x7f] = rval; | |
117 | } else if ((reg >= 32) && (reg < 64)) { | |
118 | sregs->fsi[reg - 32] = rval; | |
119 | } else { | |
120 | switch (reg) { | |
121 | case 64: | |
122 | sregs->y = rval; | |
123 | break; | |
124 | case 65: | |
125 | sregs->psr = rval; | |
126 | break; | |
127 | case 66: | |
128 | sregs->wim = rval; | |
129 | break; | |
130 | case 67: | |
131 | sregs->tbr = rval; | |
132 | break; | |
133 | case 68: | |
134 | sregs->pc = rval; | |
135 | break; | |
136 | case 69: | |
137 | sregs->npc = rval; | |
138 | break; | |
139 | case 70: | |
140 | sregs->fsr = rval; | |
141 | set_fsr(rval); | |
142 | break; | |
143 | default:break; | |
144 | } | |
145 | } | |
146 | } | |
147 | ||
148 | void | |
149 | get_regi(struct pstate * sregs, int32 reg, char *buf) | |
150 | { | |
151 | uint32 cwp; | |
152 | uint32 rval = 0; | |
153 | ||
154 | cwp = ((sregs->psr & 0x7) << 4); | |
155 | if ((reg >= 0) && (reg < 8)) { | |
156 | rval = sregs->g[reg]; | |
157 | } else if ((reg >= 8) && (reg < 32)) { | |
158 | rval = sregs->r[(cwp + reg) & 0x7f]; | |
159 | } else if ((reg >= 32) && (reg < 64)) { | |
160 | rval = sregs->fsi[reg - 32]; | |
161 | } else { | |
162 | switch (reg) { | |
163 | case 64: | |
164 | rval = sregs->y; | |
165 | break; | |
166 | case 65: | |
167 | rval = sregs->psr; | |
168 | break; | |
169 | case 66: | |
170 | rval = sregs->wim; | |
171 | break; | |
172 | case 67: | |
173 | rval = sregs->tbr; | |
174 | break; | |
175 | case 68: | |
176 | rval = sregs->pc; | |
177 | break; | |
178 | case 69: | |
179 | rval = sregs->npc; | |
180 | break; | |
181 | case 70: | |
182 | rval = sregs->fsr; | |
183 | break; | |
184 | default:break; | |
185 | } | |
186 | } | |
187 | if (current_target_byte_order == BIG_ENDIAN) { | |
188 | buf[0] = (rval >> 24) & 0x0ff; | |
189 | buf[1] = (rval >> 16) & 0x0ff; | |
190 | buf[2] = (rval >> 8) & 0x0ff; | |
191 | buf[3] = rval & 0x0ff; | |
192 | } | |
193 | else { | |
194 | buf[3] = (rval >> 24) & 0x0ff; | |
195 | buf[2] = (rval >> 16) & 0x0ff; | |
196 | buf[1] = (rval >> 8) & 0x0ff; | |
197 | buf[0] = rval & 0x0ff; | |
198 | } | |
199 | } | |
200 | ||
201 | ||
202 | static void | |
203 | set_rega(sregs, reg, rval) | |
204 | struct pstate *sregs; | |
205 | char *reg; | |
206 | uint32 rval; | |
207 | { | |
208 | uint32 cwp; | |
209 | int32 err = 0; | |
210 | ||
211 | cwp = ((sregs->psr & 0x7) << 4); | |
212 | if (strcmp(reg, "psr") == 0) | |
213 | sregs->psr = (rval = (rval & 0x00f03fff)); | |
214 | else if (strcmp(reg, "tbr") == 0) | |
215 | sregs->tbr = (rval = (rval & 0xfffffff0)); | |
216 | else if (strcmp(reg, "wim") == 0) | |
217 | sregs->wim = (rval = (rval & 0x0ff)); | |
218 | else if (strcmp(reg, "y") == 0) | |
219 | sregs->y = rval; | |
220 | else if (strcmp(reg, "pc") == 0) | |
221 | sregs->pc = rval; | |
222 | else if (strcmp(reg, "npc") == 0) | |
223 | sregs->npc = rval; | |
224 | else if (strcmp(reg, "fsr") == 0) { | |
225 | sregs->fsr = rval; | |
226 | set_fsr(rval); | |
227 | } else if (strcmp(reg, "g0") == 0) | |
228 | err = 2; | |
229 | else if (strcmp(reg, "g1") == 0) | |
230 | sregs->g[1] = rval; | |
231 | else if (strcmp(reg, "g2") == 0) | |
232 | sregs->g[2] = rval; | |
233 | else if (strcmp(reg, "g3") == 0) | |
234 | sregs->g[3] = rval; | |
235 | else if (strcmp(reg, "g4") == 0) | |
236 | sregs->g[4] = rval; | |
237 | else if (strcmp(reg, "g5") == 0) | |
238 | sregs->g[5] = rval; | |
239 | else if (strcmp(reg, "g6") == 0) | |
240 | sregs->g[6] = rval; | |
241 | else if (strcmp(reg, "g7") == 0) | |
242 | sregs->g[7] = rval; | |
243 | else if (strcmp(reg, "o0") == 0) | |
244 | sregs->r[(cwp + 8) & 0x7f] = rval; | |
245 | else if (strcmp(reg, "o1") == 0) | |
246 | sregs->r[(cwp + 9) & 0x7f] = rval; | |
247 | else if (strcmp(reg, "o2") == 0) | |
248 | sregs->r[(cwp + 10) & 0x7f] = rval; | |
249 | else if (strcmp(reg, "o3") == 0) | |
250 | sregs->r[(cwp + 11) & 0x7f] = rval; | |
251 | else if (strcmp(reg, "o4") == 0) | |
252 | sregs->r[(cwp + 12) & 0x7f] = rval; | |
253 | else if (strcmp(reg, "o5") == 0) | |
254 | sregs->r[(cwp + 13) & 0x7f] = rval; | |
255 | else if (strcmp(reg, "o6") == 0) | |
256 | sregs->r[(cwp + 14) & 0x7f] = rval; | |
257 | else if (strcmp(reg, "o7") == 0) | |
258 | sregs->r[(cwp + 15) & 0x7f] = rval; | |
259 | else if (strcmp(reg, "l0") == 0) | |
260 | sregs->r[(cwp + 16) & 0x7f] = rval; | |
261 | else if (strcmp(reg, "l1") == 0) | |
262 | sregs->r[(cwp + 17) & 0x7f] = rval; | |
263 | else if (strcmp(reg, "l2") == 0) | |
264 | sregs->r[(cwp + 18) & 0x7f] = rval; | |
265 | else if (strcmp(reg, "l3") == 0) | |
266 | sregs->r[(cwp + 19) & 0x7f] = rval; | |
267 | else if (strcmp(reg, "l4") == 0) | |
268 | sregs->r[(cwp + 20) & 0x7f] = rval; | |
269 | else if (strcmp(reg, "l5") == 0) | |
270 | sregs->r[(cwp + 21) & 0x7f] = rval; | |
271 | else if (strcmp(reg, "l6") == 0) | |
272 | sregs->r[(cwp + 22) & 0x7f] = rval; | |
273 | else if (strcmp(reg, "l7") == 0) | |
274 | sregs->r[(cwp + 23) & 0x7f] = rval; | |
275 | else if (strcmp(reg, "i0") == 0) | |
276 | sregs->r[(cwp + 24) & 0x7f] = rval; | |
277 | else if (strcmp(reg, "i1") == 0) | |
278 | sregs->r[(cwp + 25) & 0x7f] = rval; | |
279 | else if (strcmp(reg, "i2") == 0) | |
280 | sregs->r[(cwp + 26) & 0x7f] = rval; | |
281 | else if (strcmp(reg, "i3") == 0) | |
282 | sregs->r[(cwp + 27) & 0x7f] = rval; | |
283 | else if (strcmp(reg, "i4") == 0) | |
284 | sregs->r[(cwp + 28) & 0x7f] = rval; | |
285 | else if (strcmp(reg, "i5") == 0) | |
286 | sregs->r[(cwp + 29) & 0x7f] = rval; | |
287 | else if (strcmp(reg, "i6") == 0) | |
288 | sregs->r[(cwp + 30) & 0x7f] = rval; | |
289 | else if (strcmp(reg, "i7") == 0) | |
290 | sregs->r[(cwp + 31) & 0x7f] = rval; | |
291 | else | |
292 | err = 1; | |
293 | switch (err) { | |
294 | case 0: | |
295 | printf("%s = %d (0x%08x)\n", reg, rval, rval); | |
296 | break; | |
297 | case 1: | |
298 | printf("no such regiser: %s\n", reg); | |
299 | break; | |
300 | case 2: | |
301 | printf("cannot set g0\n"); | |
302 | break; | |
303 | default: | |
304 | break; | |
305 | } | |
306 | ||
307 | } | |
308 | ||
309 | static void | |
310 | disp_reg(sregs, reg) | |
311 | struct pstate *sregs; | |
312 | char *reg; | |
313 | { | |
314 | if (strncmp(reg, "w",1) == 0) | |
315 | disp_regs(sregs, VAL(®[1])); | |
316 | } | |
317 | ||
318 | #ifdef ERRINJ | |
319 | ||
320 | void | |
321 | errinj() | |
322 | { | |
323 | int err; | |
324 | ||
325 | switch (err = (random() % 12)) { | |
326 | case 0: errtt = 0x61; break; | |
327 | case 1: errtt = 0x62; break; | |
328 | case 2: errtt = 0x63; break; | |
329 | case 3: errtt = 0x64; break; | |
330 | case 4: errtt = 0x65; break; | |
331 | case 5: | |
332 | case 6: | |
333 | case 7: errftt = err; | |
334 | break; | |
335 | case 8: errmec = 1; break; | |
336 | case 9: errmec = 2; break; | |
337 | case 10: errmec = 5; break; | |
338 | case 11: errmec = 6; break; | |
339 | } | |
340 | errcnt++; | |
341 | if (errper) event(errinj, 0, (random()%errper)); | |
342 | } | |
343 | ||
344 | void | |
345 | errinjstart() | |
346 | { | |
347 | if (errper) event(errinj, 0, (random()%errper)); | |
348 | } | |
349 | ||
350 | #endif | |
351 | ||
352 | static uint32 | |
353 | limcalc (freq) | |
354 | float32 freq; | |
355 | { | |
356 | uint32 unit, lim; | |
357 | double flim; | |
358 | char *cmd1, *cmd2; | |
359 | ||
360 | unit = 1; | |
361 | lim = -1; | |
362 | if ((cmd1 = strtok(NULL, " \t\n\r")) != NULL) { | |
363 | lim = VAL(cmd1); | |
364 | if ((cmd2 = strtok(NULL, " \t\n\r")) != NULL) { | |
365 | if (strcmp(cmd2,"us")==0) unit = 1; | |
366 | if (strcmp(cmd2,"ms")==0) unit = 1000; | |
367 | if (strcmp(cmd2,"s")==0) unit = 1000000; | |
368 | } | |
369 | flim = (double) lim * (double) unit * (double) freq + | |
370 | (double) ebase.simtime; | |
371 | if ((flim > ebase.simtime) && (flim < 4294967296.0)) { | |
372 | lim = (uint32) flim; | |
373 | } else { | |
374 | printf("error in expression\n"); | |
375 | lim = -1; | |
376 | } | |
377 | } | |
5831e29b | 378 | return lim; |
c906108c | 379 | } |
510d2751 | 380 | |
c906108c | 381 | int |
510d2751 | 382 | exec_cmd(struct pstate *sregs, const char *cmd) |
c906108c SS |
383 | { |
384 | char *cmd1, *cmd2; | |
385 | int32 stat; | |
386 | uint32 len, i, clen, j; | |
387 | static uint32 daddr = 0; | |
510d2751 | 388 | char *cmdsave, *cmdsave2 = NULL; |
c906108c SS |
389 | |
390 | stat = OK; | |
391 | cmdsave = strdup(cmd); | |
510d2751 JG |
392 | cmdsave2 = strdup (cmd); |
393 | if ((cmd1 = strtok (cmdsave2, " \t")) != NULL) { | |
c906108c SS |
394 | clen = strlen(cmd1); |
395 | if (strncmp(cmd1, "bp", clen) == 0) { | |
396 | for (i = 0; i < sregs->bptnum; i++) { | |
397 | printf(" %d : 0x%08x\n", i + 1, sregs->bpts[i]); | |
398 | } | |
399 | } else if (strncmp(cmd1, "+bp", clen) == 0) { | |
400 | if ((cmd1 = strtok(NULL, " \t\n\r")) != NULL) { | |
401 | sregs->bpts[sregs->bptnum] = VAL(cmd1) & ~0x3; | |
402 | printf("added breakpoint %d at 0x%08x\n", | |
403 | sregs->bptnum + 1, sregs->bpts[sregs->bptnum]); | |
404 | sregs->bptnum += 1; | |
405 | } | |
406 | } else if (strncmp(cmd1, "-bp", clen) == 0) { | |
407 | if ((cmd1 = strtok(NULL, " \t\n\r")) != NULL) { | |
408 | i = VAL(cmd1) - 1; | |
409 | if ((i >= 0) && (i < sregs->bptnum)) { | |
410 | printf("deleted breakpoint %d at 0x%08x\n", i + 1, | |
411 | sregs->bpts[i]); | |
412 | for (; i < sregs->bptnum - 1; i++) { | |
413 | sregs->bpts[i] = sregs->bpts[i + 1]; | |
414 | } | |
415 | sregs->bptnum -= 1; | |
416 | } | |
417 | } | |
418 | } else if (strncmp(cmd1, "batch", clen) == 0) { | |
419 | if ((cmd1 = strtok(NULL, " \t\n\r")) == NULL) { | |
420 | printf("no file specified\n"); | |
421 | } else { | |
422 | batch(sregs, cmd1); | |
423 | } | |
424 | } else if (strncmp(cmd1, "cont", clen) == 0) { | |
425 | if ((cmd1 = strtok(NULL, " \t\n\r")) == NULL) { | |
94110024 | 426 | stat = run_sim(sregs, UINT64_MAX, 0); |
c906108c SS |
427 | } else { |
428 | stat = run_sim(sregs, VAL(cmd1), 0); | |
429 | } | |
430 | daddr = sregs->pc; | |
431 | sim_halt(); | |
432 | } else if (strncmp(cmd1, "debug", clen) == 0) { | |
433 | if ((cmd1 = strtok(NULL, " \t\n\r")) != NULL) { | |
434 | sis_verbose = VAL(cmd1); | |
435 | } | |
436 | printf("Debug level = %d\n",sis_verbose); | |
437 | } else if (strncmp(cmd1, "dis", clen) == 0) { | |
438 | if ((cmd1 = strtok(NULL, " \t\n\r")) != NULL) { | |
439 | daddr = VAL(cmd1); | |
440 | } | |
441 | if ((cmd2 = strtok(NULL, " \t\n\r")) != NULL) { | |
442 | len = VAL(cmd2); | |
443 | } else | |
444 | len = 16; | |
445 | printf("\n"); | |
446 | dis_mem(daddr, len, &dinfo); | |
447 | printf("\n"); | |
448 | daddr += len * 4; | |
449 | } else if (strncmp(cmd1, "echo", clen) == 0) { | |
450 | if ((cmd1 = strtok(NULL, " \t\n\r")) != NULL) { | |
451 | printf("%s\n", (&cmdsave[clen+1])); | |
452 | } | |
453 | #ifdef ERRINJ | |
454 | } else if (strncmp(cmd1, "error", clen) == 0) { | |
455 | if ((cmd1 = strtok(NULL, " \t\n\r")) != NULL) { | |
456 | errper = VAL(cmd1); | |
457 | if (errper) { | |
458 | event(errinj, 0, (len = (random()%errper))); | |
459 | printf("Error injection started with period %d\n",len); | |
460 | } | |
461 | } else printf("Injected errors: %d\n",errcnt); | |
462 | #endif | |
463 | } else if (strncmp(cmd1, "float", clen) == 0) { | |
464 | stat = disp_fpu(sregs); | |
465 | } else if (strncmp(cmd1, "go", clen) == 0) { | |
466 | if ((cmd1 = strtok(NULL, " \t\n\r")) == NULL) { | |
467 | len = last_load_addr; | |
468 | } else { | |
469 | len = VAL(cmd1); | |
470 | } | |
471 | sregs->pc = len & ~3; | |
472 | sregs->npc = sregs->pc + 4; | |
20a0ffe3 JG |
473 | if ((sregs->pc != 0) && (ebase.simtime == 0)) |
474 | boot_init(); | |
c906108c SS |
475 | printf("resuming at 0x%08x\n",sregs->pc); |
476 | if ((cmd2 = strtok(NULL, " \t\n\r")) != NULL) { | |
477 | stat = run_sim(sregs, VAL(cmd2), 0); | |
478 | } else { | |
94110024 | 479 | stat = run_sim(sregs, UINT64_MAX, 0); |
c906108c SS |
480 | } |
481 | daddr = sregs->pc; | |
482 | sim_halt(); | |
483 | } else if (strncmp(cmd1, "help", clen) == 0) { | |
484 | gen_help(); | |
485 | } else if (strncmp(cmd1, "history", clen) == 0) { | |
486 | if ((cmd1 = strtok(NULL, " \t\n\r")) != NULL) { | |
487 | sregs->histlen = VAL(cmd1); | |
488 | if (sregs->histbuf != NULL) | |
489 | free(sregs->histbuf); | |
490 | sregs->histbuf = (struct histype *) calloc(sregs->histlen, sizeof(struct histype)); | |
491 | printf("trace history length = %d\n\r", sregs->histlen); | |
492 | sregs->histind = 0; | |
493 | ||
494 | } else { | |
495 | j = sregs->histind; | |
496 | for (i = 0; i < sregs->histlen; i++) { | |
497 | if (j >= sregs->histlen) | |
498 | j = 0; | |
499 | printf(" %8d ", sregs->histbuf[j].time); | |
500 | dis_mem(sregs->histbuf[j].addr, 1, &dinfo); | |
501 | j++; | |
502 | } | |
503 | } | |
504 | ||
505 | } else if (strncmp(cmd1, "load", clen) == 0) { | |
506 | if ((cmd1 = strtok(NULL, " \t\n\r")) != NULL) { | |
507 | last_load_addr = bfd_load(cmd1); | |
508 | while ((cmd1 = strtok(NULL, " \t\n\r")) != NULL) | |
509 | last_load_addr = bfd_load(cmd1); | |
510 | } else { | |
511 | printf("load: no file specified\n"); | |
512 | } | |
513 | } else if (strncmp(cmd1, "mem", clen) == 0) { | |
514 | if ((cmd1 = strtok(NULL, " \t\n\r")) != NULL) | |
515 | daddr = VAL(cmd1); | |
516 | if ((cmd2 = strtok(NULL, " \t\n\r")) != NULL) | |
517 | len = VAL(cmd2); | |
518 | else | |
519 | len = 64; | |
520 | disp_mem(daddr, len); | |
521 | daddr += len; | |
522 | } else if (strncmp(cmd1, "perf", clen) == 0) { | |
523 | cmd1 = strtok(NULL, " \t\n\r"); | |
524 | if ((cmd1 != NULL) && | |
525 | (strncmp(cmd1, "reset", strlen(cmd1)) == 0)) { | |
526 | reset_stat(sregs); | |
527 | } else | |
528 | show_stat(sregs); | |
529 | } else if (strncmp(cmd1, "quit", clen) == 0) { | |
530 | exit(0); | |
531 | } else if (strncmp(cmd1, "reg", clen) == 0) { | |
532 | cmd1 = strtok(NULL, " \t\n\r"); | |
533 | cmd2 = strtok(NULL, " \t\n\r"); | |
534 | if (cmd2 != NULL) | |
535 | set_rega(sregs, cmd1, VAL(cmd2)); | |
536 | else if (cmd1 != NULL) | |
537 | disp_reg(sregs, cmd1); | |
538 | else { | |
539 | disp_regs(sregs,sregs->psr); | |
540 | disp_ctrl(sregs); | |
541 | } | |
542 | } else if (strncmp(cmd1, "reset", clen) == 0) { | |
543 | ebase.simtime = 0; | |
544 | reset_all(); | |
545 | reset_stat(sregs); | |
546 | } else if (strncmp(cmd1, "run", clen) == 0) { | |
547 | ebase.simtime = 0; | |
548 | reset_all(); | |
549 | reset_stat(sregs); | |
550 | if ((cmd1 = strtok(NULL, " \t\n\r")) == NULL) { | |
94110024 | 551 | stat = run_sim(sregs, UINT64_MAX, 0); |
c906108c SS |
552 | } else { |
553 | stat = run_sim(sregs, VAL(cmd1), 0); | |
554 | } | |
555 | daddr = sregs->pc; | |
556 | sim_halt(); | |
557 | } else if (strncmp(cmd1, "shell", clen) == 0) { | |
558 | if ((cmd1 = strtok(NULL, " \t\n\r")) != NULL) { | |
b9f9ea2f JG |
559 | if (system(&cmdsave[clen])) { |
560 | /* Silence unused return value warning. */ | |
561 | } | |
c906108c SS |
562 | } |
563 | } else if (strncmp(cmd1, "step", clen) == 0) { | |
564 | stat = run_sim(sregs, 1, 1); | |
565 | daddr = sregs->pc; | |
566 | sim_halt(); | |
567 | } else if (strncmp(cmd1, "tcont", clen) == 0) { | |
568 | sregs->tlimit = limcalc(sregs->freq); | |
94110024 | 569 | stat = run_sim(sregs, UINT64_MAX, 0); |
c906108c SS |
570 | daddr = sregs->pc; |
571 | sim_halt(); | |
572 | } else if (strncmp(cmd1, "tgo", clen) == 0) { | |
573 | if ((cmd1 = strtok(NULL, " \t\n\r")) == NULL) { | |
574 | len = last_load_addr; | |
575 | } else { | |
576 | len = VAL(cmd1); | |
577 | sregs->tlimit = limcalc(sregs->freq); | |
578 | } | |
579 | sregs->pc = len & ~3; | |
580 | sregs->npc = sregs->pc + 4; | |
581 | printf("resuming at 0x%08x\n",sregs->pc); | |
94110024 | 582 | stat = run_sim(sregs, UINT64_MAX, 0); |
c906108c SS |
583 | daddr = sregs->pc; |
584 | sim_halt(); | |
585 | } else if (strncmp(cmd1, "tlimit", clen) == 0) { | |
586 | sregs->tlimit = limcalc(sregs->freq); | |
587 | if (sregs->tlimit != (uint32) -1) | |
588 | printf("simulation limit = %u (%.3f ms)\n",(uint32) sregs->tlimit, | |
589 | sregs->tlimit / sregs->freq / 1000); | |
590 | } else if (strncmp(cmd1, "tra", clen) == 0) { | |
591 | if ((cmd1 = strtok(NULL, " \t\n\r")) == NULL) { | |
94110024 | 592 | stat = run_sim(sregs, UINT64_MAX, 1); |
c906108c SS |
593 | } else { |
594 | stat = run_sim(sregs, VAL(cmd1), 1); | |
595 | } | |
596 | printf("\n"); | |
597 | daddr = sregs->pc; | |
598 | sim_halt(); | |
599 | } else if (strncmp(cmd1, "trun", clen) == 0) { | |
600 | ebase.simtime = 0; | |
601 | reset_all(); | |
602 | reset_stat(sregs); | |
603 | sregs->tlimit = limcalc(sregs->freq); | |
94110024 | 604 | stat = run_sim(sregs, UINT64_MAX, 0); |
c906108c SS |
605 | daddr = sregs->pc; |
606 | sim_halt(); | |
607 | } else | |
608 | printf("syntax error\n"); | |
609 | } | |
510d2751 JG |
610 | if (cmdsave2 != NULL) |
611 | free(cmdsave2); | |
c906108c SS |
612 | if (cmdsave != NULL) |
613 | free(cmdsave); | |
5831e29b | 614 | return stat; |
c906108c SS |
615 | } |
616 | ||
617 | ||
618 | void | |
619 | reset_stat(sregs) | |
620 | struct pstate *sregs; | |
621 | { | |
96d67095 | 622 | sregs->tottime = 0.0; |
c906108c SS |
623 | sregs->pwdtime = 0; |
624 | sregs->ninst = 0; | |
625 | sregs->fholdt = 0; | |
626 | sregs->holdt = 0; | |
627 | sregs->icntt = 0; | |
628 | sregs->finst = 0; | |
629 | sregs->nstore = 0; | |
630 | sregs->nload = 0; | |
631 | sregs->nbranch = 0; | |
632 | sregs->simstart = ebase.simtime; | |
633 | ||
634 | } | |
635 | ||
636 | void | |
637 | show_stat(sregs) | |
638 | struct pstate *sregs; | |
639 | { | |
640 | uint32 iinst; | |
96d67095 | 641 | uint32 stime; |
c906108c | 642 | |
96d67095 JG |
643 | if (sregs->tottime == 0.0) |
644 | sregs->tottime += 1E-6; | |
c906108c SS |
645 | stime = ebase.simtime - sregs->simstart; /* Total simulated time */ |
646 | #ifdef STAT | |
647 | ||
648 | iinst = sregs->ninst - sregs->finst - sregs->nload - sregs->nstore - | |
649 | sregs->nbranch; | |
650 | #endif | |
651 | ||
638fcdad JG |
652 | printf("\n Cycles : %9" PRIu64 "\n\r", ebase.simtime - sregs->simstart); |
653 | printf(" Instructions : %9" PRIu64 "\n", sregs->ninst); | |
c906108c SS |
654 | |
655 | #ifdef STAT | |
656 | printf(" integer : %9.2f %%\n", 100.0 * (float) iinst / (float) sregs->ninst); | |
657 | printf(" load : %9.2f %%\n", | |
658 | 100.0 * (float) sregs->nload / (float) sregs->ninst); | |
659 | printf(" store : %9.2f %%\n", | |
660 | 100.0 * (float) sregs->nstore / (float) sregs->ninst); | |
661 | printf(" branch : %9.2f %%\n", | |
662 | 100.0 * (float) sregs->nbranch / (float) sregs->ninst); | |
663 | printf(" float : %9.2f %%\n", | |
664 | 100.0 * (float) sregs->finst / (float) sregs->ninst); | |
665 | printf(" Integer CPI : %9.2f\n", | |
666 | ((float) (stime - sregs->pwdtime - sregs->fholdt - sregs->finst)) | |
667 | / | |
668 | (float) (sregs->ninst - sregs->finst)); | |
669 | printf(" Float CPI : %9.2f\n", | |
670 | ((float) sregs->fholdt / (float) sregs->finst) + 1.0); | |
671 | #endif | |
672 | printf(" Overall CPI : %9.2f\n", | |
673 | (float) (stime - sregs->pwdtime) / (float) sregs->ninst); | |
674 | printf("\n ERC32 performance (%4.1f MHz): %5.2f MOPS (%5.2f MIPS, %5.2f MFLOPS)\n", | |
675 | sregs->freq, sregs->freq * (float) sregs->ninst / (float) (stime - sregs->pwdtime), | |
676 | sregs->freq * (float) (sregs->ninst - sregs->finst) / | |
677 | (float) (stime - sregs->pwdtime), | |
678 | sregs->freq * (float) sregs->finst / (float) (stime - sregs->pwdtime)); | |
96d67095 JG |
679 | printf(" Simulated ERC32 time : %.2f s\n", |
680 | (float) (ebase.simtime - sregs->simstart) / 1000000.0 / sregs->freq); | |
681 | printf(" Processor utilisation : %.2f %%\n", | |
682 | 100.0 * (1.0 - ((float) sregs->pwdtime / (float) stime))); | |
683 | printf(" Real-time performance : %.2f %%\n", | |
684 | 100.0 / (sregs->tottime / ((double) (stime) / (sregs->freq * 1.0E6)))); | |
685 | printf(" Simulator performance : %.2f MIPS\n", | |
686 | (double)(sregs->ninst) / sregs->tottime / 1E6); | |
687 | printf(" Used time (sys + user) : %.2f s\n\n", sregs->tottime); | |
c906108c SS |
688 | } |
689 | ||
690 | ||
691 | ||
692 | void | |
693 | init_bpt(sregs) | |
694 | struct pstate *sregs; | |
695 | { | |
696 | sregs->bptnum = 0; | |
697 | sregs->histlen = 0; | |
698 | sregs->histind = 0; | |
699 | sregs->histbuf = NULL; | |
700 | sregs->tlimit = -1; | |
701 | } | |
702 | ||
703 | static void | |
704 | int_handler(sig) | |
705 | int32 sig; | |
706 | { | |
707 | if (sig != 2) | |
708 | printf("\n\n Signal handler error (%d)\n\n", sig); | |
709 | ctrl_c = 1; | |
710 | } | |
711 | ||
712 | void | |
713 | init_signals() | |
714 | { | |
715 | typedef void (*PFI) (); | |
716 | static PFI int_tab[2]; | |
717 | ||
718 | int_tab[0] = signal(SIGTERM, int_handler); | |
719 | int_tab[1] = signal(SIGINT, int_handler); | |
720 | } | |
721 | ||
722 | ||
723 | extern struct disassemble_info dinfo; | |
724 | ||
725 | struct estate ebase; | |
726 | struct evcell evbuf[EVENT_MAX]; | |
727 | struct irqcell irqarr[16]; | |
728 | ||
729 | static int | |
730 | disp_fpu(sregs) | |
731 | struct pstate *sregs; | |
732 | { | |
733 | ||
734 | int i; | |
735 | float t; | |
736 | ||
737 | printf("\n fsr: %08X\n\n", sregs->fsr); | |
738 | ||
9c5f41df | 739 | #ifdef HOST_LITTLE_ENDIAN |
c906108c SS |
740 | for (i = 0; i < 32; i++) |
741 | sregs->fdp[i ^ 1] = sregs->fs[i]; | |
742 | #endif | |
743 | ||
744 | for (i = 0; i < 32; i++) { | |
745 | t = sregs->fs[i]; | |
746 | printf(" f%02d %08x %14e ", i, sregs->fsi[i], sregs->fs[i]); | |
747 | if (!(i & 1)) | |
748 | printf("%14e\n", sregs->fd[i >> 1]); | |
749 | else | |
750 | printf("\n"); | |
751 | } | |
752 | printf("\n"); | |
5831e29b | 753 | return OK; |
c906108c SS |
754 | } |
755 | ||
756 | static void | |
757 | disp_regs(sregs,cwp) | |
758 | struct pstate *sregs; | |
759 | int cwp; | |
760 | { | |
761 | ||
762 | int i; | |
763 | ||
764 | cwp = ((cwp & 0x7) << 4); | |
765 | printf("\n\t INS LOCALS OUTS GLOBALS\n"); | |
766 | for (i = 0; i < 8; i++) { | |
767 | printf(" %d: %08X %08X %08X %08X\n", i, | |
768 | sregs->r[(cwp + i + 24) & 0x7f], | |
769 | sregs->r[(cwp + i + 16) & 0x7f], sregs->r[(cwp + i + 8) & 0x7f], | |
770 | sregs->g[i]); | |
771 | } | |
772 | } | |
773 | ||
53b5af48 JG |
774 | static void print_insn_sparc_sis(uint32 addr, struct disassemble_info *info) |
775 | { | |
776 | unsigned char i[4]; | |
777 | ||
778 | sis_memory_read(addr, i, 4); | |
779 | dinfo.buffer_vma = addr; | |
780 | dinfo.buffer_length = 4; | |
781 | dinfo.buffer = i; | |
782 | print_insn_sparc(addr, info); | |
783 | } | |
784 | ||
c906108c SS |
785 | static void |
786 | disp_ctrl(sregs) | |
787 | struct pstate *sregs; | |
788 | { | |
789 | ||
790 | unsigned char i[4]; | |
791 | ||
792 | printf("\n psr: %08X wim: %08X tbr: %08X y: %08X\n", | |
793 | sregs->psr, sregs->wim, sregs->tbr, sregs->y); | |
794 | sis_memory_read(sregs->pc, i, 4); | |
795 | printf("\n pc: %08X = %02X%02X%02X%02X ", sregs->pc,i[0],i[1],i[2],i[3]); | |
53b5af48 | 796 | print_insn_sparc_sis(sregs->pc, &dinfo); |
c906108c SS |
797 | sis_memory_read(sregs->npc, i, 4); |
798 | printf("\n npc: %08X = %02X%02X%02X%02X ",sregs->npc,i[0],i[1],i[2],i[3]); | |
53b5af48 | 799 | print_insn_sparc_sis(sregs->npc, &dinfo); |
c906108c SS |
800 | if (sregs->err_mode) |
801 | printf("\n IU in error mode"); | |
802 | printf("\n\n"); | |
803 | } | |
804 | ||
805 | static void | |
806 | disp_mem(addr, len) | |
807 | uint32 addr; | |
808 | uint32 len; | |
809 | { | |
810 | ||
811 | uint32 i; | |
812 | unsigned char data[4]; | |
813 | uint32 mem[4], j; | |
814 | char *p; | |
815 | ||
816 | for (i = addr & ~3; i < ((addr + len) & ~3); i += 16) { | |
817 | printf("\n %8X ", i); | |
818 | for (j = 0; j < 4; j++) { | |
819 | sis_memory_read((i + (j * 4)), data, 4); | |
820 | printf("%02x%02x%02x%02x ", data[0],data[1],data[2],data[3]); | |
821 | mem[j] = *((int *) &data); | |
822 | } | |
823 | printf(" "); | |
824 | p = (char *) mem; | |
825 | for (j = 0; j < 16; j++) { | |
826 | if (isprint(p[j])) | |
827 | putchar(p[j]); | |
828 | else | |
829 | putchar('.'); | |
830 | } | |
831 | } | |
832 | printf("\n\n"); | |
833 | } | |
834 | ||
835 | void | |
836 | dis_mem(addr, len, info) | |
837 | uint32 addr; | |
838 | uint32 len; | |
839 | struct disassemble_info *info; | |
840 | { | |
841 | uint32 i; | |
842 | unsigned char data[4]; | |
843 | ||
844 | for (i = addr & -3; i < ((addr & -3) + (len << 2)); i += 4) { | |
845 | sis_memory_read(i, data, 4); | |
846 | printf(" %08x %02x%02x%02x%02x ", i, data[0],data[1],data[2],data[3]); | |
53b5af48 | 847 | print_insn_sparc_sis(i, info); |
c906108c SS |
848 | if (i >= 0xfffffffc) break; |
849 | printf("\n"); | |
850 | } | |
851 | } | |
852 | ||
c906108c SS |
853 | /* Add event to event queue */ |
854 | ||
855 | void | |
856 | event(cfunc, arg, delta) | |
857 | void (*cfunc) (); | |
858 | int32 arg; | |
94110024 | 859 | uint64 delta; |
c906108c SS |
860 | { |
861 | struct evcell *ev1, *evins; | |
862 | ||
863 | if (ebase.freeq == NULL) { | |
864 | printf("Error, too many events in event queue\n"); | |
865 | return; | |
866 | } | |
867 | ev1 = &ebase.eq; | |
868 | delta += ebase.simtime; | |
869 | while ((ev1->nxt != NULL) && (ev1->nxt->time <= delta)) { | |
870 | ev1 = ev1->nxt; | |
871 | } | |
872 | if (ev1->nxt == NULL) { | |
873 | ev1->nxt = ebase.freeq; | |
874 | ebase.freeq = ebase.freeq->nxt; | |
875 | ev1->nxt->nxt = NULL; | |
876 | } else { | |
877 | evins = ebase.freeq; | |
878 | ebase.freeq = ebase.freeq->nxt; | |
879 | evins->nxt = ev1->nxt; | |
880 | ev1->nxt = evins; | |
881 | } | |
882 | ev1->nxt->time = delta; | |
883 | ev1->nxt->cfunc = cfunc; | |
884 | ev1->nxt->arg = arg; | |
885 | } | |
886 | ||
887 | #if 0 /* apparently not used */ | |
888 | void | |
889 | stop_event() | |
890 | { | |
891 | } | |
892 | #endif | |
893 | ||
894 | void | |
895 | init_event() | |
896 | { | |
897 | int32 i; | |
898 | ||
899 | ebase.eq.nxt = NULL; | |
900 | ebase.freeq = evbuf; | |
901 | for (i = 0; i < EVENT_MAX; i++) { | |
902 | evbuf[i].nxt = &evbuf[i + 1]; | |
903 | } | |
904 | evbuf[EVENT_MAX - 1].nxt = NULL; | |
905 | } | |
906 | ||
907 | void | |
908 | set_int(level, callback, arg) | |
909 | int32 level; | |
910 | void (*callback) (); | |
911 | int32 arg; | |
912 | { | |
913 | irqarr[level & 0x0f].callback = callback; | |
914 | irqarr[level & 0x0f].arg = arg; | |
915 | } | |
916 | ||
917 | /* Advance simulator time */ | |
918 | ||
919 | void | |
920 | advance_time(sregs) | |
921 | struct pstate *sregs; | |
922 | { | |
923 | ||
924 | struct evcell *evrem; | |
925 | void (*cfunc) (); | |
94110024 JS |
926 | uint32 arg; |
927 | uint64 endtime; | |
c906108c SS |
928 | |
929 | #ifdef STAT | |
930 | sregs->fholdt += sregs->fhold; | |
931 | sregs->holdt += sregs->hold; | |
932 | sregs->icntt += sregs->icnt; | |
933 | #endif | |
934 | ||
935 | endtime = ebase.simtime + sregs->icnt + sregs->hold + sregs->fhold; | |
936 | ||
937 | while ((ebase.eq.nxt->time <= (endtime)) && (ebase.eq.nxt != NULL)) { | |
938 | ebase.simtime = ebase.eq.nxt->time; | |
939 | cfunc = ebase.eq.nxt->cfunc; | |
940 | arg = ebase.eq.nxt->arg; | |
941 | evrem = ebase.eq.nxt; | |
942 | ebase.eq.nxt = ebase.eq.nxt->nxt; | |
943 | evrem->nxt = ebase.freeq; | |
944 | ebase.freeq = evrem; | |
945 | cfunc(arg); | |
946 | } | |
947 | ebase.simtime = endtime; | |
948 | ||
949 | } | |
950 | ||
951 | uint32 | |
952 | now() | |
953 | { | |
5831e29b | 954 | return ebase.simtime; |
c906108c SS |
955 | } |
956 | ||
957 | ||
958 | /* Advance time until an external interrupt is seen */ | |
959 | ||
960 | int | |
961 | wait_for_irq() | |
962 | { | |
963 | struct evcell *evrem; | |
964 | void (*cfunc) (); | |
94110024 JS |
965 | int32 arg; |
966 | uint64 endtime; | |
c906108c SS |
967 | |
968 | if (ebase.eq.nxt == NULL) | |
969 | printf("Warning: event queue empty - power-down mode not entered\n"); | |
970 | endtime = ebase.simtime; | |
971 | while (!ext_irl && (ebase.eq.nxt != NULL)) { | |
972 | ebase.simtime = ebase.eq.nxt->time; | |
973 | cfunc = ebase.eq.nxt->cfunc; | |
974 | arg = ebase.eq.nxt->arg; | |
975 | evrem = ebase.eq.nxt; | |
976 | ebase.eq.nxt = ebase.eq.nxt->nxt; | |
977 | evrem->nxt = ebase.freeq; | |
978 | ebase.freeq = evrem; | |
979 | cfunc(arg); | |
980 | if (ctrl_c) { | |
981 | printf("\bwarning: power-down mode interrupted\n"); | |
982 | break; | |
983 | } | |
984 | } | |
985 | sregs.pwdtime += ebase.simtime - endtime; | |
5831e29b | 986 | return ebase.simtime - endtime; |
c906108c SS |
987 | } |
988 | ||
989 | int | |
990 | check_bpt(sregs) | |
991 | struct pstate *sregs; | |
992 | { | |
993 | int32 i; | |
994 | ||
995 | if ((sregs->bphit) || (sregs->annul)) | |
5831e29b | 996 | return 0; |
c906108c SS |
997 | for (i = 0; i < (int32) sregs->bptnum; i++) { |
998 | if (sregs->pc == sregs->bpts[i]) | |
5831e29b | 999 | return BPT_HIT; |
c906108c | 1000 | } |
5831e29b | 1001 | return 0; |
c906108c SS |
1002 | } |
1003 | ||
1004 | void | |
1005 | reset_all() | |
1006 | { | |
1007 | init_event(); /* Clear event queue */ | |
1008 | init_regs(&sregs); | |
1009 | reset(); | |
1010 | #ifdef ERRINJ | |
1011 | errinjstart(); | |
1012 | #endif | |
1013 | } | |
1014 | ||
1015 | void | |
1016 | sys_reset() | |
1017 | { | |
1018 | reset_all(); | |
1019 | sregs.trap = 256; /* Force fake reset trap */ | |
1020 | } | |
1021 | ||
1022 | void | |
1023 | sys_halt() | |
1024 | { | |
1025 | sregs.trap = 257; /* Force fake halt trap */ | |
1026 | } | |
1027 | ||
1028 | #include "ansidecl.h" | |
1029 | ||
c906108c | 1030 | #include <stdarg.h> |
c906108c SS |
1031 | |
1032 | #include "libiberty.h" | |
1033 | #include "bfd.h" | |
1034 | ||
1035 | #define min(A, B) (((A) < (B)) ? (A) : (B)) | |
1036 | #define LOAD_ADDRESS 0 | |
1037 | ||
1038 | int | |
510d2751 | 1039 | bfd_load (const char *fname) |
c906108c SS |
1040 | { |
1041 | asection *section; | |
1042 | bfd *pbfd; | |
1043 | const bfd_arch_info_type *arch; | |
1044 | ||
1045 | pbfd = bfd_openr(fname, 0); | |
1046 | ||
1047 | if (pbfd == NULL) { | |
1048 | printf("open of %s failed\n", fname); | |
5831e29b | 1049 | return -1; |
c906108c SS |
1050 | } |
1051 | if (!bfd_check_format(pbfd, bfd_object)) { | |
1052 | printf("file %s doesn't seem to be an object file\n", fname); | |
5831e29b | 1053 | return -1; |
c906108c SS |
1054 | } |
1055 | ||
1056 | arch = bfd_get_arch_info (pbfd); | |
1057 | if (bfd_little_endian (pbfd) || arch->mach == bfd_mach_sparc_sparclite_le) | |
1058 | current_target_byte_order = LITTLE_ENDIAN; | |
1059 | else | |
1060 | current_target_byte_order = BIG_ENDIAN; | |
1061 | if (sis_verbose) | |
1062 | printf("file %s is %s-endian.\n", fname, | |
1063 | current_target_byte_order == BIG_ENDIAN ? "big" : "little"); | |
1064 | ||
1065 | if (sis_verbose) | |
1066 | printf("loading %s:", fname); | |
1067 | for (section = pbfd->sections; section; section = section->next) { | |
1068 | if (bfd_get_section_flags(pbfd, section) & SEC_ALLOC) { | |
1069 | bfd_vma section_address; | |
1070 | unsigned long section_size; | |
1071 | const char *section_name; | |
1072 | ||
1073 | section_name = bfd_get_section_name(pbfd, section); | |
1074 | ||
1075 | section_address = bfd_get_section_vma(pbfd, section); | |
1076 | /* | |
1077 | * Adjust sections from a.out files, since they don't carry their | |
1078 | * addresses with. | |
1079 | */ | |
1080 | if (bfd_get_flavour(pbfd) == bfd_target_aout_flavour) { | |
1081 | if (strcmp (section_name, ".text") == 0) | |
1082 | section_address = bfd_get_start_address (pbfd); | |
1083 | else if (strcmp (section_name, ".data") == 0) { | |
1084 | /* Read the first 8 bytes of the data section. | |
1085 | There should be the string 'DaTa' followed by | |
1086 | a word containing the actual section address. */ | |
1087 | struct data_marker | |
1088 | { | |
1089 | char signature[4]; /* 'DaTa' */ | |
1090 | unsigned char sdata[4]; /* &sdata */ | |
1091 | } marker; | |
1092 | bfd_get_section_contents (pbfd, section, &marker, 0, | |
1093 | sizeof (marker)); | |
1094 | if (strncmp (marker.signature, "DaTa", 4) == 0) | |
1095 | { | |
1096 | if (current_target_byte_order == BIG_ENDIAN) | |
1097 | section_address = bfd_getb32 (marker.sdata); | |
1098 | else | |
1099 | section_address = bfd_getl32 (marker.sdata); | |
1100 | } | |
1101 | } | |
1102 | } | |
1103 | ||
1104 | section_size = bfd_section_size(pbfd, section); | |
1105 | ||
1106 | if (sis_verbose) | |
1107 | printf("\nsection %s at 0x%08lx (0x%lx bytes)", | |
1108 | section_name, section_address, section_size); | |
1109 | ||
1110 | /* Text, data or lit */ | |
1111 | if (bfd_get_section_flags(pbfd, section) & SEC_LOAD) { | |
1112 | file_ptr fptr; | |
1113 | ||
1114 | fptr = 0; | |
1115 | ||
1116 | while (section_size > 0) { | |
1117 | char buffer[1024]; | |
1118 | int count; | |
1119 | ||
1120 | count = min(section_size, 1024); | |
1121 | ||
1122 | bfd_get_section_contents(pbfd, section, buffer, fptr, count); | |
1123 | ||
1124 | sis_memory_write(section_address, buffer, count); | |
1125 | ||
1126 | section_address += count; | |
1127 | fptr += count; | |
1128 | section_size -= count; | |
1129 | } | |
1130 | } else /* BSS */ | |
1131 | if (sis_verbose) | |
1132 | printf("(not loaded)"); | |
1133 | } | |
1134 | } | |
1135 | if (sis_verbose) | |
1136 | printf("\n"); | |
1137 | ||
5831e29b | 1138 | return bfd_get_start_address (pbfd); |
c906108c | 1139 | } |
96d67095 JG |
1140 | |
1141 | double get_time (void) | |
1142 | { | |
1143 | double usec; | |
1144 | ||
1145 | struct timeval tm; | |
1146 | ||
1147 | gettimeofday (&tm, NULL); | |
1148 | usec = ((double) tm.tv_sec) * 1E6 + ((double) tm.tv_usec); | |
5831e29b | 1149 | return usec / 1E6; |
96d67095 | 1150 | } |