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 3 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, see <http://www.gnu.org/licenses/>.
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 (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);
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],
762 static void print_insn_sparc_sis(uint32 addr, struct disassemble_info *info)
766 sis_memory_read(addr, i, 4);
767 dinfo.buffer_vma = addr;
768 dinfo.buffer_length = 4;
770 print_insn_sparc(addr, info);
775 struct pstate *sregs;
780 printf("\n psr: %08X wim: %08X tbr: %08X y: %08X\n",
781 sregs->psr, sregs->wim, sregs->tbr, sregs->y);
782 sis_memory_read(sregs->pc, i, 4);
783 printf("\n pc: %08X = %02X%02X%02X%02X ", sregs->pc,i[0],i[1],i[2],i[3]);
784 print_insn_sparc_sis(sregs->pc, &dinfo);
785 sis_memory_read(sregs->npc, i, 4);
786 printf("\n npc: %08X = %02X%02X%02X%02X ",sregs->npc,i[0],i[1],i[2],i[3]);
787 print_insn_sparc_sis(sregs->npc, &dinfo);
789 printf("\n IU in error mode");
800 unsigned char data[4];
804 for (i = addr & ~3; i < ((addr + len) & ~3); i += 16) {
805 printf("\n %8X ", i);
806 for (j = 0; j < 4; j++) {
807 sis_memory_read((i + (j * 4)), data, 4);
808 printf("%02x%02x%02x%02x ", data[0],data[1],data[2],data[3]);
809 mem[j] = *((int *) &data);
813 for (j = 0; j < 16; j++) {
824 dis_mem(addr, len, info)
827 struct disassemble_info *info;
830 unsigned char data[4];
832 for (i = addr & -3; i < ((addr & -3) + (len << 2)); i += 4) {
833 sis_memory_read(i, data, 4);
834 printf(" %08x %02x%02x%02x%02x ", i, data[0],data[1],data[2],data[3]);
835 print_insn_sparc_sis(i, info);
836 if (i >= 0xfffffffc) break;
841 /* Add event to event queue */
844 event(cfunc, arg, delta)
849 struct evcell *ev1, *evins;
851 if (ebase.freeq == NULL) {
852 printf("Error, too many events in event queue\n");
856 delta += ebase.simtime;
857 while ((ev1->nxt != NULL) && (ev1->nxt->time <= delta)) {
860 if (ev1->nxt == NULL) {
861 ev1->nxt = ebase.freeq;
862 ebase.freeq = ebase.freeq->nxt;
863 ev1->nxt->nxt = NULL;
866 ebase.freeq = ebase.freeq->nxt;
867 evins->nxt = ev1->nxt;
870 ev1->nxt->time = delta;
871 ev1->nxt->cfunc = cfunc;
875 #if 0 /* apparently not used */
889 for (i = 0; i < EVENT_MAX; i++) {
890 evbuf[i].nxt = &evbuf[i + 1];
892 evbuf[EVENT_MAX - 1].nxt = NULL;
896 set_int(level, callback, arg)
901 irqarr[level & 0x0f].callback = callback;
902 irqarr[level & 0x0f].arg = arg;
905 /* Advance simulator time */
909 struct pstate *sregs;
912 struct evcell *evrem;
918 sregs->fholdt += sregs->fhold;
919 sregs->holdt += sregs->hold;
920 sregs->icntt += sregs->icnt;
923 endtime = ebase.simtime + sregs->icnt + sregs->hold + sregs->fhold;
925 while ((ebase.eq.nxt->time <= (endtime)) && (ebase.eq.nxt != NULL)) {
926 ebase.simtime = ebase.eq.nxt->time;
927 cfunc = ebase.eq.nxt->cfunc;
928 arg = ebase.eq.nxt->arg;
929 evrem = ebase.eq.nxt;
930 ebase.eq.nxt = ebase.eq.nxt->nxt;
931 evrem->nxt = ebase.freeq;
935 ebase.simtime = endtime;
942 return(ebase.simtime);
946 /* Advance time until an external interrupt is seen */
951 struct evcell *evrem;
956 if (ebase.eq.nxt == NULL)
957 printf("Warning: event queue empty - power-down mode not entered\n");
958 endtime = ebase.simtime;
959 while (!ext_irl && (ebase.eq.nxt != NULL)) {
960 ebase.simtime = ebase.eq.nxt->time;
961 cfunc = ebase.eq.nxt->cfunc;
962 arg = ebase.eq.nxt->arg;
963 evrem = ebase.eq.nxt;
964 ebase.eq.nxt = ebase.eq.nxt->nxt;
965 evrem->nxt = ebase.freeq;
969 printf("\bwarning: power-down mode interrupted\n");
973 sregs.pwdtime += ebase.simtime - endtime;
974 return (ebase.simtime - endtime);
979 struct pstate *sregs;
983 if ((sregs->bphit) || (sregs->annul))
985 for (i = 0; i < (int32) sregs->bptnum; i++) {
986 if (sregs->pc == sregs->bpts[i])
995 init_event(); /* Clear event queue */
1007 sregs.trap = 256; /* Force fake reset trap */
1013 sregs.trap = 257; /* Force fake halt trap */
1016 #include "ansidecl.h"
1020 #include "libiberty.h"
1023 #define min(A, B) (((A) < (B)) ? (A) : (B))
1024 #define LOAD_ADDRESS 0
1032 const bfd_arch_info_type *arch;
1034 pbfd = bfd_openr(fname, 0);
1037 printf("open of %s failed\n", fname);
1040 if (!bfd_check_format(pbfd, bfd_object)) {
1041 printf("file %s doesn't seem to be an object file\n", fname);
1045 arch = bfd_get_arch_info (pbfd);
1046 if (bfd_little_endian (pbfd) || arch->mach == bfd_mach_sparc_sparclite_le)
1047 current_target_byte_order = LITTLE_ENDIAN;
1049 current_target_byte_order = BIG_ENDIAN;
1051 printf("file %s is %s-endian.\n", fname,
1052 current_target_byte_order == BIG_ENDIAN ? "big" : "little");
1055 printf("loading %s:", fname);
1056 for (section = pbfd->sections; section; section = section->next) {
1057 if (bfd_get_section_flags(pbfd, section) & SEC_ALLOC) {
1058 bfd_vma section_address;
1059 unsigned long section_size;
1060 const char *section_name;
1062 section_name = bfd_get_section_name(pbfd, section);
1064 section_address = bfd_get_section_vma(pbfd, section);
1066 * Adjust sections from a.out files, since they don't carry their
1069 if (bfd_get_flavour(pbfd) == bfd_target_aout_flavour) {
1070 if (strcmp (section_name, ".text") == 0)
1071 section_address = bfd_get_start_address (pbfd);
1072 else if (strcmp (section_name, ".data") == 0) {
1073 /* Read the first 8 bytes of the data section.
1074 There should be the string 'DaTa' followed by
1075 a word containing the actual section address. */
1078 char signature[4]; /* 'DaTa' */
1079 unsigned char sdata[4]; /* &sdata */
1081 bfd_get_section_contents (pbfd, section, &marker, 0,
1083 if (strncmp (marker.signature, "DaTa", 4) == 0)
1085 if (current_target_byte_order == BIG_ENDIAN)
1086 section_address = bfd_getb32 (marker.sdata);
1088 section_address = bfd_getl32 (marker.sdata);
1093 section_size = bfd_section_size(pbfd, section);
1096 printf("\nsection %s at 0x%08lx (0x%lx bytes)",
1097 section_name, section_address, section_size);
1099 /* Text, data or lit */
1100 if (bfd_get_section_flags(pbfd, section) & SEC_LOAD) {
1105 while (section_size > 0) {
1109 count = min(section_size, 1024);
1111 bfd_get_section_contents(pbfd, section, buffer, fptr, count);
1113 sis_memory_write(section_address, buffer, count);
1115 section_address += count;
1117 section_size -= count;
1121 printf("(not loaded)");
1127 return(bfd_get_start_address (pbfd));