2 * func.c, misc simulator functions. This file is part of SIS.
4 * SIS, SPARC instruction simulator V1.8 Copyright (C) 1995 Jiri Gaisler,
5 * European Space Agency
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
9 * Software Foundation; either version 2 of the License, or (at your option)
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
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 675
19 * Mass Ave, Cambridge, MA 02139, USA.
31 #include "sim-config.h"
34 #define VAL(x) strtoul(x,(char **)NULL,0)
36 extern int current_target_byte_order
;
37 struct disassemble_info dinfo
;
39 extern struct estate ebase
;
42 char *sis_version
= "2.7.5";
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] = "";
54 uint32 last_load_addr
= 0;
64 /* Forward declarations */
66 static int batch
PARAMS ((struct pstate
*sregs
, char *fname
));
67 static void set_rega
PARAMS ((struct pstate
*sregs
, char *reg
, uint32 rval
));
68 static void disp_reg
PARAMS ((struct pstate
*sregs
, char *reg
));
69 static uint32 limcalc
PARAMS ((float32 freq
));
70 static void int_handler
PARAMS ((int32 sig
));
71 static void init_event
PARAMS ((void));
72 static int disp_fpu
PARAMS ((struct pstate
*sregs
));
73 static void disp_regs
PARAMS ((struct pstate
*sregs
, int cwp
));
74 static void disp_ctrl
PARAMS ((struct pstate
*sregs
));
75 static void disp_mem
PARAMS ((uint32 addr
, uint32 len
));
85 if ((fp
= fopen(fname
, "r")) == NULL
) {
86 fprintf(stderr
, "couldn't open batch file %s\n", fname
);
91 fgets(lbuf
, 1023, fp
);
92 if ((strlen(lbuf
) > 0) && (lbuf
[strlen(lbuf
) - 1] == '\n'))
93 lbuf
[strlen(lbuf
) - 1] = 0;
94 printf("sis> %s\n", lbuf
);
95 exec_cmd(sregs
, lbuf
);
102 set_regi(sregs
, reg
, rval
)
103 struct pstate
*sregs
;
109 cwp
= ((sregs
->psr
& 0x7) << 4);
110 if ((reg
> 0) && (reg
< 8)) {
111 sregs
->g
[reg
] = rval
;
112 } else if ((reg
>= 8) && (reg
< 32)) {
113 sregs
->r
[(cwp
+ reg
) & 0x7f] = rval
;
114 } else if ((reg
>= 32) && (reg
< 64)) {
115 sregs
->fsi
[reg
- 32] = rval
;
146 get_regi(struct pstate
* sregs
, int32 reg
, char *buf
)
151 cwp
= ((sregs
->psr
& 0x7) << 4);
152 if ((reg
>= 0) && (reg
< 8)) {
153 rval
= sregs
->g
[reg
];
154 } else if ((reg
>= 8) && (reg
< 32)) {
155 rval
= sregs
->r
[(cwp
+ reg
) & 0x7f];
156 } else if ((reg
>= 32) && (reg
< 64)) {
157 rval
= sregs
->fsi
[reg
- 32];
184 if (current_target_byte_order
== BIG_ENDIAN
) {
185 buf
[0] = (rval
>> 24) & 0x0ff;
186 buf
[1] = (rval
>> 16) & 0x0ff;
187 buf
[2] = (rval
>> 8) & 0x0ff;
188 buf
[3] = rval
& 0x0ff;
191 buf
[3] = (rval
>> 24) & 0x0ff;
192 buf
[2] = (rval
>> 16) & 0x0ff;
193 buf
[1] = (rval
>> 8) & 0x0ff;
194 buf
[0] = rval
& 0x0ff;
200 set_rega(sregs
, reg
, rval
)
201 struct pstate
*sregs
;
208 cwp
= ((sregs
->psr
& 0x7) << 4);
209 if (strcmp(reg
, "psr") == 0)
210 sregs
->psr
= (rval
= (rval
& 0x00f03fff));
211 else if (strcmp(reg
, "tbr") == 0)
212 sregs
->tbr
= (rval
= (rval
& 0xfffffff0));
213 else if (strcmp(reg
, "wim") == 0)
214 sregs
->wim
= (rval
= (rval
& 0x0ff));
215 else if (strcmp(reg
, "y") == 0)
217 else if (strcmp(reg
, "pc") == 0)
219 else if (strcmp(reg
, "npc") == 0)
221 else if (strcmp(reg
, "fsr") == 0) {
224 } else if (strcmp(reg
, "g0") == 0)
226 else if (strcmp(reg
, "g1") == 0)
228 else if (strcmp(reg
, "g2") == 0)
230 else if (strcmp(reg
, "g3") == 0)
232 else if (strcmp(reg
, "g4") == 0)
234 else if (strcmp(reg
, "g5") == 0)
236 else if (strcmp(reg
, "g6") == 0)
238 else if (strcmp(reg
, "g7") == 0)
240 else if (strcmp(reg
, "o0") == 0)
241 sregs
->r
[(cwp
+ 8) & 0x7f] = rval
;
242 else if (strcmp(reg
, "o1") == 0)
243 sregs
->r
[(cwp
+ 9) & 0x7f] = rval
;
244 else if (strcmp(reg
, "o2") == 0)
245 sregs
->r
[(cwp
+ 10) & 0x7f] = rval
;
246 else if (strcmp(reg
, "o3") == 0)
247 sregs
->r
[(cwp
+ 11) & 0x7f] = rval
;
248 else if (strcmp(reg
, "o4") == 0)
249 sregs
->r
[(cwp
+ 12) & 0x7f] = rval
;
250 else if (strcmp(reg
, "o5") == 0)
251 sregs
->r
[(cwp
+ 13) & 0x7f] = rval
;
252 else if (strcmp(reg
, "o6") == 0)
253 sregs
->r
[(cwp
+ 14) & 0x7f] = rval
;
254 else if (strcmp(reg
, "o7") == 0)
255 sregs
->r
[(cwp
+ 15) & 0x7f] = rval
;
256 else if (strcmp(reg
, "l0") == 0)
257 sregs
->r
[(cwp
+ 16) & 0x7f] = rval
;
258 else if (strcmp(reg
, "l1") == 0)
259 sregs
->r
[(cwp
+ 17) & 0x7f] = rval
;
260 else if (strcmp(reg
, "l2") == 0)
261 sregs
->r
[(cwp
+ 18) & 0x7f] = rval
;
262 else if (strcmp(reg
, "l3") == 0)
263 sregs
->r
[(cwp
+ 19) & 0x7f] = rval
;
264 else if (strcmp(reg
, "l4") == 0)
265 sregs
->r
[(cwp
+ 20) & 0x7f] = rval
;
266 else if (strcmp(reg
, "l5") == 0)
267 sregs
->r
[(cwp
+ 21) & 0x7f] = rval
;
268 else if (strcmp(reg
, "l6") == 0)
269 sregs
->r
[(cwp
+ 22) & 0x7f] = rval
;
270 else if (strcmp(reg
, "l7") == 0)
271 sregs
->r
[(cwp
+ 23) & 0x7f] = rval
;
272 else if (strcmp(reg
, "i0") == 0)
273 sregs
->r
[(cwp
+ 24) & 0x7f] = rval
;
274 else if (strcmp(reg
, "i1") == 0)
275 sregs
->r
[(cwp
+ 25) & 0x7f] = rval
;
276 else if (strcmp(reg
, "i2") == 0)
277 sregs
->r
[(cwp
+ 26) & 0x7f] = rval
;
278 else if (strcmp(reg
, "i3") == 0)
279 sregs
->r
[(cwp
+ 27) & 0x7f] = rval
;
280 else if (strcmp(reg
, "i4") == 0)
281 sregs
->r
[(cwp
+ 28) & 0x7f] = rval
;
282 else if (strcmp(reg
, "i5") == 0)
283 sregs
->r
[(cwp
+ 29) & 0x7f] = rval
;
284 else if (strcmp(reg
, "i6") == 0)
285 sregs
->r
[(cwp
+ 30) & 0x7f] = rval
;
286 else if (strcmp(reg
, "i7") == 0)
287 sregs
->r
[(cwp
+ 31) & 0x7f] = rval
;
292 printf("%s = %d (0x%08x)\n", reg
, rval
, rval
);
295 printf("no such regiser: %s\n", reg
);
298 printf("cannot set g0\n");
308 struct pstate
*sregs
;
311 if (strncmp(reg
, "w",1) == 0)
312 disp_regs(sregs
, VAL(®
[1]));
322 switch (err
= (random() % 12)) {
323 case 0: errtt
= 0x61; break;
324 case 1: errtt
= 0x62; break;
325 case 2: errtt
= 0x63; break;
326 case 3: errtt
= 0x64; break;
327 case 4: errtt
= 0x65; break;
330 case 7: errftt
= err
;
332 case 8: errmec
= 1; break;
333 case 9: errmec
= 2; break;
334 case 10: errmec
= 5; break;
335 case 11: errmec
= 6; break;
338 if (errper
) event(errinj
, 0, (random()%errper
));
344 if (errper
) event(errinj
, 0, (random()%errper
));
359 if ((cmd1
= strtok(NULL
, " \t\n\r")) != NULL
) {
361 if ((cmd2
= strtok(NULL
, " \t\n\r")) != NULL
) {
362 if (strcmp(cmd2
,"us")==0) unit
= 1;
363 if (strcmp(cmd2
,"ms")==0) unit
= 1000;
364 if (strcmp(cmd2
,"s")==0) unit
= 1000000;
366 flim
= (double) lim
* (double) unit
* (double) freq
+
367 (double) ebase
.simtime
;
368 if ((flim
> ebase
.simtime
) && (flim
< 4294967296.0)) {
371 printf("error in expression\n");
381 struct pstate
*sregs
;
385 uint32 len
, i
, clen
, j
;
386 static uint32 daddr
= 0;
390 cmdsave
= strdup(cmd
);
391 if ((cmd1
= strtok(cmd
, " \t")) != NULL
) {
393 if (strncmp(cmd1
, "bp", clen
) == 0) {
394 for (i
= 0; i
< sregs
->bptnum
; i
++) {
395 printf(" %d : 0x%08x\n", i
+ 1, sregs
->bpts
[i
]);
397 } else if (strncmp(cmd1
, "+bp", clen
) == 0) {
398 if ((cmd1
= strtok(NULL
, " \t\n\r")) != NULL
) {
399 sregs
->bpts
[sregs
->bptnum
] = VAL(cmd1
) & ~0x3;
400 printf("added breakpoint %d at 0x%08x\n",
401 sregs
->bptnum
+ 1, sregs
->bpts
[sregs
->bptnum
]);
404 } else if (strncmp(cmd1
, "-bp", clen
) == 0) {
405 if ((cmd1
= strtok(NULL
, " \t\n\r")) != NULL
) {
407 if ((i
>= 0) && (i
< sregs
->bptnum
)) {
408 printf("deleted breakpoint %d at 0x%08x\n", i
+ 1,
410 for (; i
< sregs
->bptnum
- 1; i
++) {
411 sregs
->bpts
[i
] = sregs
->bpts
[i
+ 1];
416 } else if (strncmp(cmd1
, "batch", clen
) == 0) {
417 if ((cmd1
= strtok(NULL
, " \t\n\r")) == NULL
) {
418 printf("no file specified\n");
422 } else if (strncmp(cmd1
, "cont", clen
) == 0) {
423 if ((cmd1
= strtok(NULL
, " \t\n\r")) == NULL
) {
424 stat
= run_sim(sregs
, UINT64_MAX
, 0);
426 stat
= run_sim(sregs
, VAL(cmd1
), 0);
430 } else if (strncmp(cmd1
, "debug", clen
) == 0) {
431 if ((cmd1
= strtok(NULL
, " \t\n\r")) != NULL
) {
432 sis_verbose
= VAL(cmd1
);
434 printf("Debug level = %d\n",sis_verbose
);
435 } else if (strncmp(cmd1
, "dis", clen
) == 0) {
436 if ((cmd1
= strtok(NULL
, " \t\n\r")) != NULL
) {
439 if ((cmd2
= strtok(NULL
, " \t\n\r")) != NULL
) {
444 dis_mem(daddr
, len
, &dinfo
);
447 } else if (strncmp(cmd1
, "echo", clen
) == 0) {
448 if ((cmd1
= strtok(NULL
, " \t\n\r")) != NULL
) {
449 printf("%s\n", (&cmdsave
[clen
+1]));
452 } else if (strncmp(cmd1
, "error", clen
) == 0) {
453 if ((cmd1
= strtok(NULL
, " \t\n\r")) != NULL
) {
456 event(errinj
, 0, (len
= (random()%errper
)));
457 printf("Error injection started with period %d\n",len
);
459 } else printf("Injected errors: %d\n",errcnt
);
461 } else if (strncmp(cmd1
, "float", clen
) == 0) {
462 stat
= disp_fpu(sregs
);
463 } else if (strncmp(cmd1
, "go", clen
) == 0) {
464 if ((cmd1
= strtok(NULL
, " \t\n\r")) == NULL
) {
465 len
= last_load_addr
;
469 sregs
->pc
= len
& ~3;
470 sregs
->npc
= sregs
->pc
+ 4;
471 printf("resuming at 0x%08x\n",sregs
->pc
);
472 if ((cmd2
= strtok(NULL
, " \t\n\r")) != NULL
) {
473 stat
= run_sim(sregs
, VAL(cmd2
), 0);
475 stat
= run_sim(sregs
, UINT64_MAX
, 0);
479 } else if (strncmp(cmd1
, "help", clen
) == 0) {
481 } else if (strncmp(cmd1
, "history", clen
) == 0) {
482 if ((cmd1
= strtok(NULL
, " \t\n\r")) != NULL
) {
483 sregs
->histlen
= VAL(cmd1
);
484 if (sregs
->histbuf
!= NULL
)
485 free(sregs
->histbuf
);
486 sregs
->histbuf
= (struct histype
*) calloc(sregs
->histlen
, sizeof(struct histype
));
487 printf("trace history length = %d\n\r", sregs
->histlen
);
492 for (i
= 0; i
< sregs
->histlen
; i
++) {
493 if (j
>= sregs
->histlen
)
495 printf(" %8d ", sregs
->histbuf
[j
].time
);
496 dis_mem(sregs
->histbuf
[j
].addr
, 1, &dinfo
);
501 } else if (strncmp(cmd1
, "load", clen
) == 0) {
502 if ((cmd1
= strtok(NULL
, " \t\n\r")) != NULL
) {
503 last_load_addr
= bfd_load(cmd1
);
504 while ((cmd1
= strtok(NULL
, " \t\n\r")) != NULL
)
505 last_load_addr
= bfd_load(cmd1
);
507 printf("load: no file specified\n");
509 } else if (strncmp(cmd1
, "mem", clen
) == 0) {
510 if ((cmd1
= strtok(NULL
, " \t\n\r")) != NULL
)
512 if ((cmd2
= strtok(NULL
, " \t\n\r")) != NULL
)
516 disp_mem(daddr
, len
);
518 } else if (strncmp(cmd1
, "perf", clen
) == 0) {
519 cmd1
= strtok(NULL
, " \t\n\r");
520 if ((cmd1
!= NULL
) &&
521 (strncmp(cmd1
, "reset", strlen(cmd1
)) == 0)) {
525 } else if (strncmp(cmd1
, "quit", clen
) == 0) {
527 } else if (strncmp(cmd1
, "reg", clen
) == 0) {
528 cmd1
= strtok(NULL
, " \t\n\r");
529 cmd2
= strtok(NULL
, " \t\n\r");
531 set_rega(sregs
, cmd1
, VAL(cmd2
));
532 else if (cmd1
!= NULL
)
533 disp_reg(sregs
, cmd1
);
535 disp_regs(sregs
,sregs
->psr
);
538 } else if (strncmp(cmd1
, "reset", clen
) == 0) {
542 } else if (strncmp(cmd1
, "run", clen
) == 0) {
546 if ((cmd1
= strtok(NULL
, " \t\n\r")) == NULL
) {
547 stat
= run_sim(sregs
, UINT64_MAX
, 0);
549 stat
= run_sim(sregs
, VAL(cmd1
), 0);
553 } else if (strncmp(cmd1
, "shell", clen
) == 0) {
554 if ((cmd1
= strtok(NULL
, " \t\n\r")) != NULL
) {
555 system(&cmdsave
[clen
]);
557 } else if (strncmp(cmd1
, "step", clen
) == 0) {
558 stat
= run_sim(sregs
, 1, 1);
561 } else if (strncmp(cmd1
, "tcont", clen
) == 0) {
562 sregs
->tlimit
= limcalc(sregs
->freq
);
563 stat
= run_sim(sregs
, UINT64_MAX
, 0);
566 } else if (strncmp(cmd1
, "tgo", clen
) == 0) {
567 if ((cmd1
= strtok(NULL
, " \t\n\r")) == NULL
) {
568 len
= last_load_addr
;
571 sregs
->tlimit
= limcalc(sregs
->freq
);
573 sregs
->pc
= len
& ~3;
574 sregs
->npc
= sregs
->pc
+ 4;
575 printf("resuming at 0x%08x\n",sregs
->pc
);
576 stat
= run_sim(sregs
, UINT64_MAX
, 0);
579 } else if (strncmp(cmd1
, "tlimit", clen
) == 0) {
580 sregs
->tlimit
= limcalc(sregs
->freq
);
581 if (sregs
->tlimit
!= (uint32
) -1)
582 printf("simulation limit = %u (%.3f ms)\n",(uint32
) sregs
->tlimit
,
583 sregs
->tlimit
/ sregs
->freq
/ 1000);
584 } else if (strncmp(cmd1
, "tra", clen
) == 0) {
585 if ((cmd1
= strtok(NULL
, " \t\n\r")) == NULL
) {
586 stat
= run_sim(sregs
, UINT64_MAX
, 1);
588 stat
= run_sim(sregs
, VAL(cmd1
), 1);
593 } else if (strncmp(cmd1
, "trun", clen
) == 0) {
597 sregs
->tlimit
= limcalc(sregs
->freq
);
598 stat
= run_sim(sregs
, UINT64_MAX
, 0);
602 printf("syntax error\n");
612 struct pstate
*sregs
;
624 sregs
->simstart
= ebase
.simtime
;
630 struct pstate
*sregs
;
633 uint32 stime
, tottime
;
635 if (sregs
->tottime
== 0) tottime
= 1; else tottime
= sregs
->tottime
;
636 stime
= ebase
.simtime
- sregs
->simstart
; /* Total simulated time */
639 iinst
= sregs
->ninst
- sregs
->finst
- sregs
->nload
- sregs
->nstore
-
643 printf("\n Cycles : %9d\n\r", ebase
.simtime
- sregs
->simstart
);
644 printf(" Instructions : %9d\n", sregs
->ninst
);
647 printf(" integer : %9.2f %%\n", 100.0 * (float) iinst
/ (float) sregs
->ninst
);
648 printf(" load : %9.2f %%\n",
649 100.0 * (float) sregs
->nload
/ (float) sregs
->ninst
);
650 printf(" store : %9.2f %%\n",
651 100.0 * (float) sregs
->nstore
/ (float) sregs
->ninst
);
652 printf(" branch : %9.2f %%\n",
653 100.0 * (float) sregs
->nbranch
/ (float) sregs
->ninst
);
654 printf(" float : %9.2f %%\n",
655 100.0 * (float) sregs
->finst
/ (float) sregs
->ninst
);
656 printf(" Integer CPI : %9.2f\n",
657 ((float) (stime
- sregs
->pwdtime
- sregs
->fholdt
- sregs
->finst
))
659 (float) (sregs
->ninst
- sregs
->finst
));
660 printf(" Float CPI : %9.2f\n",
661 ((float) sregs
->fholdt
/ (float) sregs
->finst
) + 1.0);
663 printf(" Overall CPI : %9.2f\n",
664 (float) (stime
- sregs
->pwdtime
) / (float) sregs
->ninst
);
665 printf("\n ERC32 performance (%4.1f MHz): %5.2f MOPS (%5.2f MIPS, %5.2f MFLOPS)\n",
666 sregs
->freq
, sregs
->freq
* (float) sregs
->ninst
/ (float) (stime
- sregs
->pwdtime
),
667 sregs
->freq
* (float) (sregs
->ninst
- sregs
->finst
) /
668 (float) (stime
- sregs
->pwdtime
),
669 sregs
->freq
* (float) sregs
->finst
/ (float) (stime
- sregs
->pwdtime
));
670 printf(" Simulated ERC32 time : %5.2f ms\n", (float) (ebase
.simtime
- sregs
->simstart
) / 1000.0 / sregs
->freq
);
671 printf(" Processor utilisation : %5.2f %%\n", 100.0 * (1.0 - ((float) sregs
->pwdtime
/ (float) stime
)));
672 printf(" Real-time / simulator-time : 1/%.2f \n",
673 ((float) sregs
->tottime
) / ((float) (stime
) / (sregs
->freq
* 1.0E6
)));
674 printf(" Simulator performance : %d KIPS\n",sregs
->ninst
/tottime
/1000);
675 printf(" Used time (sys + user) : %3d s\n\n", sregs
->tottime
);
682 struct pstate
*sregs
;
687 sregs
->histbuf
= NULL
;
696 printf("\n\n Signal handler error (%d)\n\n", sig
);
703 typedef void (*PFI
) ();
704 static PFI int_tab
[2];
706 int_tab
[0] = signal(SIGTERM
, int_handler
);
707 int_tab
[1] = signal(SIGINT
, int_handler
);
711 extern struct disassemble_info dinfo
;
714 struct evcell evbuf
[EVENT_MAX
];
715 struct irqcell irqarr
[16];
719 struct pstate
*sregs
;
725 printf("\n fsr: %08X\n\n", sregs
->fsr
);
727 #ifdef HOST_LITTLE_ENDIAN_FLOAT
728 for (i
= 0; i
< 32; i
++)
729 sregs
->fdp
[i
^ 1] = sregs
->fs
[i
];
732 for (i
= 0; i
< 32; i
++) {
734 printf(" f%02d %08x %14e ", i
, sregs
->fsi
[i
], sregs
->fs
[i
]);
736 printf("%14e\n", sregs
->fd
[i
>> 1]);
746 struct pstate
*sregs
;
752 cwp
= ((cwp
& 0x7) << 4);
753 printf("\n\t INS LOCALS OUTS GLOBALS\n");
754 for (i
= 0; i
< 8; i
++) {
755 printf(" %d: %08X %08X %08X %08X\n", i
,
756 sregs
->r
[(cwp
+ i
+ 24) & 0x7f],
757 sregs
->r
[(cwp
+ i
+ 16) & 0x7f], sregs
->r
[(cwp
+ i
+ 8) & 0x7f],
764 struct pstate
*sregs
;
769 printf("\n psr: %08X wim: %08X tbr: %08X y: %08X\n",
770 sregs
->psr
, sregs
->wim
, sregs
->tbr
, sregs
->y
);
771 sis_memory_read(sregs
->pc
, i
, 4);
772 printf("\n pc: %08X = %02X%02X%02X%02X ", sregs
->pc
,i
[0],i
[1],i
[2],i
[3]);
773 print_insn_sparc(sregs
->pc
, &dinfo
);
774 sis_memory_read(sregs
->npc
, i
, 4);
775 printf("\n npc: %08X = %02X%02X%02X%02X ",sregs
->npc
,i
[0],i
[1],i
[2],i
[3]);
776 print_insn_sparc(sregs
->npc
, &dinfo
);
778 printf("\n IU in error mode");
789 unsigned char data
[4];
793 for (i
= addr
& ~3; i
< ((addr
+ len
) & ~3); i
+= 16) {
794 printf("\n %8X ", i
);
795 for (j
= 0; j
< 4; j
++) {
796 sis_memory_read((i
+ (j
* 4)), data
, 4);
797 printf("%02x%02x%02x%02x ", data
[0],data
[1],data
[2],data
[3]);
798 mem
[j
] = *((int *) &data
);
802 for (j
= 0; j
< 16; j
++) {
813 dis_mem(addr
, len
, info
)
816 struct disassemble_info
*info
;
819 unsigned char data
[4];
821 for (i
= addr
& -3; i
< ((addr
& -3) + (len
<< 2)); i
+= 4) {
822 sis_memory_read(i
, data
, 4);
823 printf(" %08x %02x%02x%02x%02x ", i
, data
[0],data
[1],data
[2],data
[3]);
824 print_insn_sparc(i
, info
);
825 if (i
>= 0xfffffffc) break;
830 /* Add event to event queue */
833 event(cfunc
, arg
, delta
)
838 struct evcell
*ev1
, *evins
;
840 if (ebase
.freeq
== NULL
) {
841 printf("Error, too many events in event queue\n");
845 delta
+= ebase
.simtime
;
846 while ((ev1
->nxt
!= NULL
) && (ev1
->nxt
->time
<= delta
)) {
849 if (ev1
->nxt
== NULL
) {
850 ev1
->nxt
= ebase
.freeq
;
851 ebase
.freeq
= ebase
.freeq
->nxt
;
852 ev1
->nxt
->nxt
= NULL
;
855 ebase
.freeq
= ebase
.freeq
->nxt
;
856 evins
->nxt
= ev1
->nxt
;
859 ev1
->nxt
->time
= delta
;
860 ev1
->nxt
->cfunc
= cfunc
;
864 #if 0 /* apparently not used */
878 for (i
= 0; i
< EVENT_MAX
; i
++) {
879 evbuf
[i
].nxt
= &evbuf
[i
+ 1];
881 evbuf
[EVENT_MAX
- 1].nxt
= NULL
;
885 set_int(level
, callback
, arg
)
890 irqarr
[level
& 0x0f].callback
= callback
;
891 irqarr
[level
& 0x0f].arg
= arg
;
894 /* Advance simulator time */
898 struct pstate
*sregs
;
901 struct evcell
*evrem
;
907 sregs
->fholdt
+= sregs
->fhold
;
908 sregs
->holdt
+= sregs
->hold
;
909 sregs
->icntt
+= sregs
->icnt
;
912 endtime
= ebase
.simtime
+ sregs
->icnt
+ sregs
->hold
+ sregs
->fhold
;
914 while ((ebase
.eq
.nxt
->time
<= (endtime
)) && (ebase
.eq
.nxt
!= NULL
)) {
915 ebase
.simtime
= ebase
.eq
.nxt
->time
;
916 cfunc
= ebase
.eq
.nxt
->cfunc
;
917 arg
= ebase
.eq
.nxt
->arg
;
918 evrem
= ebase
.eq
.nxt
;
919 ebase
.eq
.nxt
= ebase
.eq
.nxt
->nxt
;
920 evrem
->nxt
= ebase
.freeq
;
924 ebase
.simtime
= endtime
;
931 return(ebase
.simtime
);
935 /* Advance time until an external interrupt is seen */
940 struct evcell
*evrem
;
945 if (ebase
.eq
.nxt
== NULL
)
946 printf("Warning: event queue empty - power-down mode not entered\n");
947 endtime
= ebase
.simtime
;
948 while (!ext_irl
&& (ebase
.eq
.nxt
!= NULL
)) {
949 ebase
.simtime
= ebase
.eq
.nxt
->time
;
950 cfunc
= ebase
.eq
.nxt
->cfunc
;
951 arg
= ebase
.eq
.nxt
->arg
;
952 evrem
= ebase
.eq
.nxt
;
953 ebase
.eq
.nxt
= ebase
.eq
.nxt
->nxt
;
954 evrem
->nxt
= ebase
.freeq
;
958 printf("\bwarning: power-down mode interrupted\n");
962 sregs
.pwdtime
+= ebase
.simtime
- endtime
;
963 return (ebase
.simtime
- endtime
);
968 struct pstate
*sregs
;
972 if ((sregs
->bphit
) || (sregs
->annul
))
974 for (i
= 0; i
< (int32
) sregs
->bptnum
; i
++) {
975 if (sregs
->pc
== sregs
->bpts
[i
])
984 init_event(); /* Clear event queue */
996 sregs
.trap
= 256; /* Force fake reset trap */
1002 sregs
.trap
= 257; /* Force fake halt trap */
1005 #include "ansidecl.h"
1009 #include "libiberty.h"
1012 #define min(A, B) (((A) < (B)) ? (A) : (B))
1013 #define LOAD_ADDRESS 0
1021 const bfd_arch_info_type
*arch
;
1023 pbfd
= bfd_openr(fname
, 0);
1026 printf("open of %s failed\n", fname
);
1029 if (!bfd_check_format(pbfd
, bfd_object
)) {
1030 printf("file %s doesn't seem to be an object file\n", fname
);
1034 arch
= bfd_get_arch_info (pbfd
);
1035 if (bfd_little_endian (pbfd
) || arch
->mach
== bfd_mach_sparc_sparclite_le
)
1036 current_target_byte_order
= LITTLE_ENDIAN
;
1038 current_target_byte_order
= BIG_ENDIAN
;
1040 printf("file %s is %s-endian.\n", fname
,
1041 current_target_byte_order
== BIG_ENDIAN
? "big" : "little");
1044 printf("loading %s:", fname
);
1045 for (section
= pbfd
->sections
; section
; section
= section
->next
) {
1046 if (bfd_get_section_flags(pbfd
, section
) & SEC_ALLOC
) {
1047 bfd_vma section_address
;
1048 unsigned long section_size
;
1049 const char *section_name
;
1051 section_name
= bfd_get_section_name(pbfd
, section
);
1053 section_address
= bfd_get_section_vma(pbfd
, section
);
1055 * Adjust sections from a.out files, since they don't carry their
1058 if (bfd_get_flavour(pbfd
) == bfd_target_aout_flavour
) {
1059 if (strcmp (section_name
, ".text") == 0)
1060 section_address
= bfd_get_start_address (pbfd
);
1061 else if (strcmp (section_name
, ".data") == 0) {
1062 /* Read the first 8 bytes of the data section.
1063 There should be the string 'DaTa' followed by
1064 a word containing the actual section address. */
1067 char signature
[4]; /* 'DaTa' */
1068 unsigned char sdata
[4]; /* &sdata */
1070 bfd_get_section_contents (pbfd
, section
, &marker
, 0,
1072 if (strncmp (marker
.signature
, "DaTa", 4) == 0)
1074 if (current_target_byte_order
== BIG_ENDIAN
)
1075 section_address
= bfd_getb32 (marker
.sdata
);
1077 section_address
= bfd_getl32 (marker
.sdata
);
1082 section_size
= bfd_section_size(pbfd
, section
);
1085 printf("\nsection %s at 0x%08lx (0x%lx bytes)",
1086 section_name
, section_address
, section_size
);
1088 /* Text, data or lit */
1089 if (bfd_get_section_flags(pbfd
, section
) & SEC_LOAD
) {
1094 while (section_size
> 0) {
1098 count
= min(section_size
, 1024);
1100 bfd_get_section_contents(pbfd
, section
, buffer
, fptr
, count
);
1102 sis_memory_write(section_address
, buffer
, count
);
1104 section_address
+= count
;
1106 section_size
-= count
;
1110 printf("(not loaded)");
1116 return(bfd_get_start_address (pbfd
));