1 /* This file is part of SIS (SPARC instruction simulator)
3 Copyright (C) 1995-2019 Free Software Foundation, Inc.
4 Contributed by Jiri Gaisler, European Space Agency
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 #include "sim-config.h"
30 #define VAL(x) strtoul(x,(char **)NULL,0)
32 struct disassemble_info dinfo
;
34 extern struct estate ebase
;
37 char *sis_version
= "2.7.5";
44 int sparclite
= 0; /* emulating SPARClite instructions? */
45 int sparclite_board
= 0; /* emulating SPARClite board RAM? */
46 char uart_dev1
[128] = "";
47 char uart_dev2
[128] = "";
49 uint32 last_load_addr
= 0;
59 /* Forward declarations */
61 static int batch (struct pstate
*sregs
, char *fname
);
62 static void set_rega (struct pstate
*sregs
, char *reg
, uint32 rval
);
63 static void disp_reg (struct pstate
*sregs
, char *reg
);
64 static uint32
limcalc (float32 freq
);
65 static void int_handler (int32 sig
);
66 static void init_event (void);
67 static int disp_fpu (struct pstate
*sregs
);
68 static void disp_regs (struct pstate
*sregs
, int cwp
);
69 static void disp_ctrl (struct pstate
*sregs
);
70 static void disp_mem (uint32 addr
, uint32 len
);
82 if ((fp
= fopen(fname
, "r")) == NULL
) {
83 fprintf(stderr
, "couldn't open batch file %s\n", fname
);
86 while (getline(&lbuf
, &len
, fp
) > -1) {
88 if (slen
&& (lbuf
[slen
- 1] == '\n')) {
90 printf("sis> %s\n", lbuf
);
91 exec_cmd(sregs
, lbuf
);
100 set_regi(sregs
, reg
, rval
)
101 struct pstate
*sregs
;
107 cwp
= ((sregs
->psr
& 0x7) << 4);
108 if ((reg
> 0) && (reg
< 8)) {
109 sregs
->g
[reg
] = rval
;
110 } else if ((reg
>= 8) && (reg
< 32)) {
111 sregs
->r
[(cwp
+ reg
) & 0x7f] = rval
;
112 } else if ((reg
>= 32) && (reg
< 64)) {
113 sregs
->fsi
[reg
- 32] = rval
;
144 get_regi(struct pstate
* sregs
, int32 reg
, char *buf
)
149 cwp
= ((sregs
->psr
& 0x7) << 4);
150 if ((reg
>= 0) && (reg
< 8)) {
151 rval
= sregs
->g
[reg
];
152 } else if ((reg
>= 8) && (reg
< 32)) {
153 rval
= sregs
->r
[(cwp
+ reg
) & 0x7f];
154 } else if ((reg
>= 32) && (reg
< 64)) {
155 rval
= sregs
->fsi
[reg
- 32];
182 buf
[0] = (rval
>> 24) & 0x0ff;
183 buf
[1] = (rval
>> 16) & 0x0ff;
184 buf
[2] = (rval
>> 8) & 0x0ff;
185 buf
[3] = rval
& 0x0ff;
190 set_rega(sregs
, reg
, rval
)
191 struct pstate
*sregs
;
198 cwp
= ((sregs
->psr
& 0x7) << 4);
199 if (strcmp(reg
, "psr") == 0)
200 sregs
->psr
= (rval
= (rval
& 0x00f03fff));
201 else if (strcmp(reg
, "tbr") == 0)
202 sregs
->tbr
= (rval
= (rval
& 0xfffffff0));
203 else if (strcmp(reg
, "wim") == 0)
204 sregs
->wim
= (rval
= (rval
& 0x0ff));
205 else if (strcmp(reg
, "y") == 0)
207 else if (strcmp(reg
, "pc") == 0)
209 else if (strcmp(reg
, "npc") == 0)
211 else if (strcmp(reg
, "fsr") == 0) {
214 } else if (strcmp(reg
, "g0") == 0)
216 else if (strcmp(reg
, "g1") == 0)
218 else if (strcmp(reg
, "g2") == 0)
220 else if (strcmp(reg
, "g3") == 0)
222 else if (strcmp(reg
, "g4") == 0)
224 else if (strcmp(reg
, "g5") == 0)
226 else if (strcmp(reg
, "g6") == 0)
228 else if (strcmp(reg
, "g7") == 0)
230 else if (strcmp(reg
, "o0") == 0)
231 sregs
->r
[(cwp
+ 8) & 0x7f] = rval
;
232 else if (strcmp(reg
, "o1") == 0)
233 sregs
->r
[(cwp
+ 9) & 0x7f] = rval
;
234 else if (strcmp(reg
, "o2") == 0)
235 sregs
->r
[(cwp
+ 10) & 0x7f] = rval
;
236 else if (strcmp(reg
, "o3") == 0)
237 sregs
->r
[(cwp
+ 11) & 0x7f] = rval
;
238 else if (strcmp(reg
, "o4") == 0)
239 sregs
->r
[(cwp
+ 12) & 0x7f] = rval
;
240 else if (strcmp(reg
, "o5") == 0)
241 sregs
->r
[(cwp
+ 13) & 0x7f] = rval
;
242 else if (strcmp(reg
, "o6") == 0)
243 sregs
->r
[(cwp
+ 14) & 0x7f] = rval
;
244 else if (strcmp(reg
, "o7") == 0)
245 sregs
->r
[(cwp
+ 15) & 0x7f] = rval
;
246 else if (strcmp(reg
, "l0") == 0)
247 sregs
->r
[(cwp
+ 16) & 0x7f] = rval
;
248 else if (strcmp(reg
, "l1") == 0)
249 sregs
->r
[(cwp
+ 17) & 0x7f] = rval
;
250 else if (strcmp(reg
, "l2") == 0)
251 sregs
->r
[(cwp
+ 18) & 0x7f] = rval
;
252 else if (strcmp(reg
, "l3") == 0)
253 sregs
->r
[(cwp
+ 19) & 0x7f] = rval
;
254 else if (strcmp(reg
, "l4") == 0)
255 sregs
->r
[(cwp
+ 20) & 0x7f] = rval
;
256 else if (strcmp(reg
, "l5") == 0)
257 sregs
->r
[(cwp
+ 21) & 0x7f] = rval
;
258 else if (strcmp(reg
, "l6") == 0)
259 sregs
->r
[(cwp
+ 22) & 0x7f] = rval
;
260 else if (strcmp(reg
, "l7") == 0)
261 sregs
->r
[(cwp
+ 23) & 0x7f] = rval
;
262 else if (strcmp(reg
, "i0") == 0)
263 sregs
->r
[(cwp
+ 24) & 0x7f] = rval
;
264 else if (strcmp(reg
, "i1") == 0)
265 sregs
->r
[(cwp
+ 25) & 0x7f] = rval
;
266 else if (strcmp(reg
, "i2") == 0)
267 sregs
->r
[(cwp
+ 26) & 0x7f] = rval
;
268 else if (strcmp(reg
, "i3") == 0)
269 sregs
->r
[(cwp
+ 27) & 0x7f] = rval
;
270 else if (strcmp(reg
, "i4") == 0)
271 sregs
->r
[(cwp
+ 28) & 0x7f] = rval
;
272 else if (strcmp(reg
, "i5") == 0)
273 sregs
->r
[(cwp
+ 29) & 0x7f] = rval
;
274 else if (strcmp(reg
, "i6") == 0)
275 sregs
->r
[(cwp
+ 30) & 0x7f] = rval
;
276 else if (strcmp(reg
, "i7") == 0)
277 sregs
->r
[(cwp
+ 31) & 0x7f] = rval
;
282 printf("%s = %d (0x%08x)\n", reg
, rval
, rval
);
285 printf("no such regiser: %s\n", reg
);
288 printf("cannot set g0\n");
298 struct pstate
*sregs
;
301 if (strncmp(reg
, "w",1) == 0)
302 disp_regs(sregs
, VAL(®
[1]));
312 switch (err
= (random() % 12)) {
313 case 0: errtt
= 0x61; break;
314 case 1: errtt
= 0x62; break;
315 case 2: errtt
= 0x63; break;
316 case 3: errtt
= 0x64; break;
317 case 4: errtt
= 0x65; break;
320 case 7: errftt
= err
;
322 case 8: errmec
= 1; break;
323 case 9: errmec
= 2; break;
324 case 10: errmec
= 5; break;
325 case 11: errmec
= 6; break;
328 if (errper
) event(errinj
, 0, (random()%errper
));
334 if (errper
) event(errinj
, 0, (random()%errper
));
349 if ((cmd1
= strtok(NULL
, " \t\n\r")) != NULL
) {
351 if ((cmd2
= strtok(NULL
, " \t\n\r")) != NULL
) {
352 if (strcmp(cmd2
,"us")==0) unit
= 1;
353 if (strcmp(cmd2
,"ms")==0) unit
= 1000;
354 if (strcmp(cmd2
,"s")==0) unit
= 1000000;
356 flim
= (double) lim
* (double) unit
* (double) freq
+
357 (double) ebase
.simtime
;
358 if ((flim
> ebase
.simtime
) && (flim
< 4294967296.0)) {
361 printf("error in expression\n");
369 exec_cmd(struct pstate
*sregs
, const char *cmd
)
373 uint32 len
, i
, clen
, j
;
374 static uint32 daddr
= 0;
375 char *cmdsave
, *cmdsave2
= NULL
;
378 cmdsave
= strdup(cmd
);
379 cmdsave2
= strdup (cmd
);
380 if ((cmd1
= strtok (cmdsave2
, " \t")) != NULL
) {
382 if (strncmp(cmd1
, "bp", clen
) == 0) {
383 for (i
= 0; i
< sregs
->bptnum
; i
++) {
384 printf(" %d : 0x%08x\n", i
+ 1, sregs
->bpts
[i
]);
386 } else if (strncmp(cmd1
, "+bp", clen
) == 0) {
387 if ((cmd1
= strtok(NULL
, " \t\n\r")) != NULL
) {
388 sregs
->bpts
[sregs
->bptnum
] = VAL(cmd1
) & ~0x3;
389 printf("added breakpoint %d at 0x%08x\n",
390 sregs
->bptnum
+ 1, sregs
->bpts
[sregs
->bptnum
]);
393 } else if (strncmp(cmd1
, "-bp", clen
) == 0) {
394 if ((cmd1
= strtok(NULL
, " \t\n\r")) != NULL
) {
396 if ((i
>= 0) && (i
< sregs
->bptnum
)) {
397 printf("deleted breakpoint %d at 0x%08x\n", i
+ 1,
399 for (; i
< sregs
->bptnum
- 1; i
++) {
400 sregs
->bpts
[i
] = sregs
->bpts
[i
+ 1];
405 } else if (strncmp(cmd1
, "batch", clen
) == 0) {
406 if ((cmd1
= strtok(NULL
, " \t\n\r")) == NULL
) {
407 printf("no file specified\n");
411 } else if (strncmp(cmd1
, "cont", clen
) == 0) {
412 if ((cmd1
= strtok(NULL
, " \t\n\r")) == NULL
) {
413 stat
= run_sim(sregs
, UINT64_MAX
, 0);
415 stat
= run_sim(sregs
, VAL(cmd1
), 0);
419 } else if (strncmp(cmd1
, "debug", clen
) == 0) {
420 if ((cmd1
= strtok(NULL
, " \t\n\r")) != NULL
) {
421 sis_verbose
= VAL(cmd1
);
423 printf("Debug level = %d\n",sis_verbose
);
424 } else if (strncmp(cmd1
, "dis", clen
) == 0) {
425 if ((cmd1
= strtok(NULL
, " \t\n\r")) != NULL
) {
428 if ((cmd2
= strtok(NULL
, " \t\n\r")) != NULL
) {
433 dis_mem(daddr
, len
, &dinfo
);
436 } else if (strncmp(cmd1
, "echo", clen
) == 0) {
437 if ((cmd1
= strtok(NULL
, " \t\n\r")) != NULL
) {
438 printf("%s\n", (&cmdsave
[clen
+1]));
441 } else if (strncmp(cmd1
, "error", clen
) == 0) {
442 if ((cmd1
= strtok(NULL
, " \t\n\r")) != NULL
) {
445 event(errinj
, 0, (len
= (random()%errper
)));
446 printf("Error injection started with period %d\n",len
);
448 } else printf("Injected errors: %d\n",errcnt
);
450 } else if (strncmp(cmd1
, "float", clen
) == 0) {
451 stat
= disp_fpu(sregs
);
452 } else if (strncmp(cmd1
, "go", clen
) == 0) {
453 if ((cmd1
= strtok(NULL
, " \t\n\r")) == NULL
) {
454 len
= last_load_addr
;
458 sregs
->pc
= len
& ~3;
459 sregs
->npc
= sregs
->pc
+ 4;
460 if ((sregs
->pc
!= 0) && (ebase
.simtime
== 0))
462 printf("resuming at 0x%08x\n",sregs
->pc
);
463 if ((cmd2
= strtok(NULL
, " \t\n\r")) != NULL
) {
464 stat
= run_sim(sregs
, VAL(cmd2
), 0);
466 stat
= run_sim(sregs
, UINT64_MAX
, 0);
470 } else if (strncmp(cmd1
, "help", clen
) == 0) {
472 } else if (strncmp(cmd1
, "history", clen
) == 0) {
473 if ((cmd1
= strtok(NULL
, " \t\n\r")) != NULL
) {
474 sregs
->histlen
= VAL(cmd1
);
475 if (sregs
->histbuf
!= NULL
)
476 free(sregs
->histbuf
);
477 sregs
->histbuf
= (struct histype
*) calloc(sregs
->histlen
, sizeof(struct histype
));
478 printf("trace history length = %d\n\r", sregs
->histlen
);
483 for (i
= 0; i
< sregs
->histlen
; i
++) {
484 if (j
>= sregs
->histlen
)
486 printf(" %8d ", sregs
->histbuf
[j
].time
);
487 dis_mem(sregs
->histbuf
[j
].addr
, 1, &dinfo
);
492 } else if (strncmp(cmd1
, "load", clen
) == 0) {
493 if ((cmd1
= strtok(NULL
, " \t\n\r")) != NULL
) {
494 last_load_addr
= bfd_load(cmd1
);
495 while ((cmd1
= strtok(NULL
, " \t\n\r")) != NULL
)
496 last_load_addr
= bfd_load(cmd1
);
498 printf("load: no file specified\n");
500 } else if (strncmp(cmd1
, "mem", clen
) == 0) {
501 if ((cmd1
= strtok(NULL
, " \t\n\r")) != NULL
)
503 if ((cmd2
= strtok(NULL
, " \t\n\r")) != NULL
)
507 disp_mem(daddr
, len
);
509 } else if (strncmp(cmd1
, "perf", clen
) == 0) {
510 cmd1
= strtok(NULL
, " \t\n\r");
511 if ((cmd1
!= NULL
) &&
512 (strncmp(cmd1
, "reset", strlen(cmd1
)) == 0)) {
516 } else if (strncmp(cmd1
, "quit", clen
) == 0) {
518 } else if (strncmp(cmd1
, "reg", clen
) == 0) {
519 cmd1
= strtok(NULL
, " \t\n\r");
520 cmd2
= strtok(NULL
, " \t\n\r");
522 set_rega(sregs
, cmd1
, VAL(cmd2
));
523 else if (cmd1
!= NULL
)
524 disp_reg(sregs
, cmd1
);
526 disp_regs(sregs
,sregs
->psr
);
529 } else if (strncmp(cmd1
, "reset", clen
) == 0) {
533 } else if (strncmp(cmd1
, "run", clen
) == 0) {
537 if ((cmd1
= strtok(NULL
, " \t\n\r")) == NULL
) {
538 stat
= run_sim(sregs
, UINT64_MAX
, 0);
540 stat
= run_sim(sregs
, VAL(cmd1
), 0);
544 } else if (strncmp(cmd1
, "shell", clen
) == 0) {
545 if ((cmd1
= strtok(NULL
, " \t\n\r")) != NULL
) {
546 if (system(&cmdsave
[clen
])) {
547 /* Silence unused return value warning. */
550 } else if (strncmp(cmd1
, "step", clen
) == 0) {
551 stat
= run_sim(sregs
, 1, 1);
554 } else if (strncmp(cmd1
, "tcont", clen
) == 0) {
555 sregs
->tlimit
= limcalc(sregs
->freq
);
556 stat
= run_sim(sregs
, UINT64_MAX
, 0);
559 } else if (strncmp(cmd1
, "tgo", clen
) == 0) {
560 if ((cmd1
= strtok(NULL
, " \t\n\r")) == NULL
) {
561 len
= last_load_addr
;
564 sregs
->tlimit
= limcalc(sregs
->freq
);
566 sregs
->pc
= len
& ~3;
567 sregs
->npc
= sregs
->pc
+ 4;
568 printf("resuming at 0x%08x\n",sregs
->pc
);
569 stat
= run_sim(sregs
, UINT64_MAX
, 0);
572 } else if (strncmp(cmd1
, "tlimit", clen
) == 0) {
573 sregs
->tlimit
= limcalc(sregs
->freq
);
574 if (sregs
->tlimit
!= (uint32
) -1)
575 printf("simulation limit = %u (%.3f ms)\n",(uint32
) sregs
->tlimit
,
576 sregs
->tlimit
/ sregs
->freq
/ 1000);
577 } else if (strncmp(cmd1
, "tra", clen
) == 0) {
578 if ((cmd1
= strtok(NULL
, " \t\n\r")) == NULL
) {
579 stat
= run_sim(sregs
, UINT64_MAX
, 1);
581 stat
= run_sim(sregs
, VAL(cmd1
), 1);
586 } else if (strncmp(cmd1
, "trun", clen
) == 0) {
590 sregs
->tlimit
= limcalc(sregs
->freq
);
591 stat
= run_sim(sregs
, UINT64_MAX
, 0);
595 printf("syntax error\n");
597 if (cmdsave2
!= NULL
)
607 struct pstate
*sregs
;
609 sregs
->tottime
= 0.0;
619 sregs
->simstart
= ebase
.simtime
;
625 struct pstate
*sregs
;
630 if (sregs
->tottime
== 0.0)
631 sregs
->tottime
+= 1E-6;
632 stime
= ebase
.simtime
- sregs
->simstart
; /* Total simulated time */
635 iinst
= sregs
->ninst
- sregs
->finst
- sregs
->nload
- sregs
->nstore
-
639 printf("\n Cycles : %9" PRIu64
"\n\r", ebase
.simtime
- sregs
->simstart
);
640 printf(" Instructions : %9" PRIu64
"\n", sregs
->ninst
);
643 printf(" integer : %9.2f %%\n", 100.0 * (float) iinst
/ (float) sregs
->ninst
);
644 printf(" load : %9.2f %%\n",
645 100.0 * (float) sregs
->nload
/ (float) sregs
->ninst
);
646 printf(" store : %9.2f %%\n",
647 100.0 * (float) sregs
->nstore
/ (float) sregs
->ninst
);
648 printf(" branch : %9.2f %%\n",
649 100.0 * (float) sregs
->nbranch
/ (float) sregs
->ninst
);
650 printf(" float : %9.2f %%\n",
651 100.0 * (float) sregs
->finst
/ (float) sregs
->ninst
);
652 printf(" Integer CPI : %9.2f\n",
653 ((float) (stime
- sregs
->pwdtime
- sregs
->fholdt
- sregs
->finst
))
655 (float) (sregs
->ninst
- sregs
->finst
));
656 printf(" Float CPI : %9.2f\n",
657 ((float) sregs
->fholdt
/ (float) sregs
->finst
) + 1.0);
659 printf(" Overall CPI : %9.2f\n",
660 (float) (stime
- sregs
->pwdtime
) / (float) sregs
->ninst
);
661 printf("\n ERC32 performance (%4.1f MHz): %5.2f MOPS (%5.2f MIPS, %5.2f MFLOPS)\n",
662 sregs
->freq
, sregs
->freq
* (float) sregs
->ninst
/ (float) (stime
- sregs
->pwdtime
),
663 sregs
->freq
* (float) (sregs
->ninst
- sregs
->finst
) /
664 (float) (stime
- sregs
->pwdtime
),
665 sregs
->freq
* (float) sregs
->finst
/ (float) (stime
- sregs
->pwdtime
));
666 printf(" Simulated ERC32 time : %.2f s\n",
667 (float) (ebase
.simtime
- sregs
->simstart
) / 1000000.0 / sregs
->freq
);
668 printf(" Processor utilisation : %.2f %%\n",
669 100.0 * (1.0 - ((float) sregs
->pwdtime
/ (float) stime
)));
670 printf(" Real-time performance : %.2f %%\n",
671 100.0 / (sregs
->tottime
/ ((double) (stime
) / (sregs
->freq
* 1.0E6
))));
672 printf(" Simulator performance : %.2f MIPS\n",
673 (double)(sregs
->ninst
) / sregs
->tottime
/ 1E6
);
674 printf(" Used time (sys + user) : %.2f s\n\n", sregs
->tottime
);
681 struct pstate
*sregs
;
686 sregs
->histbuf
= NULL
;
695 printf("\n\n Signal handler error (%d)\n\n", sig
);
702 typedef void (*PFI
) ();
703 static PFI int_tab
[2];
705 int_tab
[0] = signal(SIGTERM
, int_handler
);
706 int_tab
[1] = signal(SIGINT
, int_handler
);
710 extern struct disassemble_info dinfo
;
713 struct evcell evbuf
[EVENT_MAX
];
714 struct irqcell irqarr
[16];
718 struct pstate
*sregs
;
724 printf("\n fsr: %08X\n\n", sregs
->fsr
);
726 #ifdef HOST_LITTLE_ENDIAN
727 for (i
= 0; i
< 32; i
++)
728 sregs
->fdp
[i
^ 1] = sregs
->fs
[i
];
731 for (i
= 0; i
< 32; i
++) {
733 printf(" f%02d %08x %14e ", i
, sregs
->fsi
[i
], sregs
->fs
[i
]);
735 printf("%14e\n", sregs
->fd
[i
>> 1]);
745 struct pstate
*sregs
;
751 cwp
= ((cwp
& 0x7) << 4);
752 printf("\n\t INS LOCALS OUTS GLOBALS\n");
753 for (i
= 0; i
< 8; i
++) {
754 printf(" %d: %08X %08X %08X %08X\n", i
,
755 sregs
->r
[(cwp
+ i
+ 24) & 0x7f],
756 sregs
->r
[(cwp
+ i
+ 16) & 0x7f], sregs
->r
[(cwp
+ i
+ 8) & 0x7f],
761 static void print_insn_sparc_sis(uint32 addr
, struct disassemble_info
*info
)
765 sis_memory_read(addr
, i
, 4);
766 dinfo
.buffer_vma
= addr
;
767 dinfo
.buffer_length
= 4;
769 print_insn_sparc(addr
, info
);
774 struct pstate
*sregs
;
779 printf("\n psr: %08X wim: %08X tbr: %08X y: %08X\n",
780 sregs
->psr
, sregs
->wim
, sregs
->tbr
, sregs
->y
);
781 sis_memory_read (sregs
->pc
, (char *) &i
, 4);
782 printf ("\n pc: %08X = %08X ", sregs
->pc
, i
);
783 print_insn_sparc_sis(sregs
->pc
, &dinfo
);
784 sis_memory_read (sregs
->npc
, (char *) &i
, 4);
785 printf ("\n npc: %08X = %08X ", sregs
->npc
, i
);
786 print_insn_sparc_sis(sregs
->npc
, &dinfo
);
788 printf("\n IU in error mode");
806 for (i
= addr
& ~3; i
< ((addr
+ len
) & ~3); i
+= 16) {
807 printf("\n %8X ", i
);
808 for (j
= 0; j
< 4; j
++) {
809 sis_memory_read ((i
+ (j
* 4)), data
.u8
, 4);
810 printf ("%08x ", data
.u32
);
815 for (j
= 0; j
< 16; j
++) {
816 if (isprint (p
[j
^ EBT
]))
817 putchar (p
[j
^ EBT
]);
826 dis_mem(addr
, len
, info
)
829 struct disassemble_info
*info
;
837 for (i
= addr
& -3; i
< ((addr
& -3) + (len
<< 2)); i
+= 4) {
838 sis_memory_read (i
, data
.u8
, 4);
839 printf (" %08x %08x ", i
, data
.u32
);
840 print_insn_sparc_sis(i
, info
);
841 if (i
>= 0xfffffffc) break;
846 /* Add event to event queue */
849 event(cfunc
, arg
, delta
)
854 struct evcell
*ev1
, *evins
;
856 if (ebase
.freeq
== NULL
) {
857 printf("Error, too many events in event queue\n");
861 delta
+= ebase
.simtime
;
862 while ((ev1
->nxt
!= NULL
) && (ev1
->nxt
->time
<= delta
)) {
865 if (ev1
->nxt
== NULL
) {
866 ev1
->nxt
= ebase
.freeq
;
867 ebase
.freeq
= ebase
.freeq
->nxt
;
868 ev1
->nxt
->nxt
= NULL
;
871 ebase
.freeq
= ebase
.freeq
->nxt
;
872 evins
->nxt
= ev1
->nxt
;
875 ev1
->nxt
->time
= delta
;
876 ev1
->nxt
->cfunc
= cfunc
;
880 #if 0 /* apparently not used */
894 for (i
= 0; i
< EVENT_MAX
; i
++) {
895 evbuf
[i
].nxt
= &evbuf
[i
+ 1];
897 evbuf
[EVENT_MAX
- 1].nxt
= NULL
;
901 set_int(level
, callback
, arg
)
906 irqarr
[level
& 0x0f].callback
= callback
;
907 irqarr
[level
& 0x0f].arg
= arg
;
910 /* Advance simulator time */
914 struct pstate
*sregs
;
917 struct evcell
*evrem
;
923 sregs
->fholdt
+= sregs
->fhold
;
924 sregs
->holdt
+= sregs
->hold
;
925 sregs
->icntt
+= sregs
->icnt
;
928 endtime
= ebase
.simtime
+ sregs
->icnt
+ sregs
->hold
+ sregs
->fhold
;
930 while ((ebase
.eq
.nxt
->time
<= (endtime
)) && (ebase
.eq
.nxt
!= NULL
)) {
931 ebase
.simtime
= ebase
.eq
.nxt
->time
;
932 cfunc
= ebase
.eq
.nxt
->cfunc
;
933 arg
= ebase
.eq
.nxt
->arg
;
934 evrem
= ebase
.eq
.nxt
;
935 ebase
.eq
.nxt
= ebase
.eq
.nxt
->nxt
;
936 evrem
->nxt
= ebase
.freeq
;
940 ebase
.simtime
= endtime
;
947 return ebase
.simtime
;
951 /* Advance time until an external interrupt is seen */
956 struct evcell
*evrem
;
961 if (ebase
.eq
.nxt
== NULL
)
962 printf("Warning: event queue empty - power-down mode not entered\n");
963 endtime
= ebase
.simtime
;
964 while (!ext_irl
&& (ebase
.eq
.nxt
!= NULL
)) {
965 ebase
.simtime
= ebase
.eq
.nxt
->time
;
966 cfunc
= ebase
.eq
.nxt
->cfunc
;
967 arg
= ebase
.eq
.nxt
->arg
;
968 evrem
= ebase
.eq
.nxt
;
969 ebase
.eq
.nxt
= ebase
.eq
.nxt
->nxt
;
970 evrem
->nxt
= ebase
.freeq
;
974 printf("\bwarning: power-down mode interrupted\n");
978 sregs
.pwdtime
+= ebase
.simtime
- endtime
;
979 return ebase
.simtime
- endtime
;
984 struct pstate
*sregs
;
988 if ((sregs
->bphit
) || (sregs
->annul
))
990 for (i
= 0; i
< (int32
) sregs
->bptnum
; i
++) {
991 if (sregs
->pc
== sregs
->bpts
[i
])
1000 init_event(); /* Clear event queue */
1012 sregs
.trap
= 256; /* Force fake reset trap */
1018 sregs
.trap
= 257; /* Force fake halt trap */
1021 #include "ansidecl.h"
1025 #include "libiberty.h"
1028 #define min(A, B) (((A) < (B)) ? (A) : (B))
1029 #define LOAD_ADDRESS 0
1032 bfd_load (const char *fname
)
1036 const bfd_arch_info_type
*arch
;
1039 pbfd
= bfd_openr(fname
, 0);
1042 printf("open of %s failed\n", fname
);
1045 if (!bfd_check_format(pbfd
, bfd_object
)) {
1046 printf("file %s doesn't seem to be an object file\n", fname
);
1050 arch
= bfd_get_arch_info (pbfd
);
1052 printf("loading %s:", fname
);
1053 for (section
= pbfd
->sections
; section
; section
= section
->next
) {
1054 if (bfd_get_section_flags(pbfd
, section
) & SEC_ALLOC
) {
1055 bfd_vma section_address
;
1056 unsigned long section_size
;
1057 const char *section_name
;
1059 section_name
= bfd_get_section_name(pbfd
, section
);
1061 section_address
= bfd_get_section_vma(pbfd
, section
);
1063 * Adjust sections from a.out files, since they don't carry their
1066 if (bfd_get_flavour(pbfd
) == bfd_target_aout_flavour
) {
1067 if (strcmp (section_name
, ".text") == 0)
1068 section_address
= bfd_get_start_address (pbfd
);
1069 else if (strcmp (section_name
, ".data") == 0) {
1070 /* Read the first 8 bytes of the data section.
1071 There should be the string 'DaTa' followed by
1072 a word containing the actual section address. */
1075 char signature
[4]; /* 'DaTa' */
1076 unsigned char sdata
[4]; /* &sdata */
1078 bfd_get_section_contents (pbfd
, section
, &marker
, 0,
1080 if (strncmp (marker
.signature
, "DaTa", 4) == 0)
1082 section_address
= bfd_getb32 (marker
.sdata
);
1087 section_size
= bfd_section_size(pbfd
, section
);
1090 printf("\nsection %s at 0x%08lx (0x%lx bytes)",
1091 section_name
, section_address
, section_size
);
1093 /* Text, data or lit */
1094 if (bfd_get_section_flags(pbfd
, section
) & SEC_LOAD
) {
1099 while (section_size
> 0) {
1103 count
= min(section_size
, 1024);
1105 bfd_get_section_contents(pbfd
, section
, buffer
, fptr
, count
);
1107 for (i
= 0; i
< count
; i
++)
1108 sis_memory_write ((section_address
+ i
) ^ EBT
, &buffer
[i
], 1);
1110 section_address
+= count
;
1112 section_size
-= count
;
1116 printf("(not loaded)");
1122 return bfd_get_start_address (pbfd
);
1125 double get_time (void)
1131 gettimeofday (&tm
, NULL
);
1132 usec
= ((double) tm
.tv_sec
) * 1E6
+ ((double) tm
.tv_usec
);