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