/* Dumps specified function to file (hex) */ unsigned long extract_function (char *out_fn, unsigned long start_addr) { FILE *fo; unsigned long a = start_addr; int x = 0; assert (fo = fopen (out_fn, "wt+")); do { unsigned long d = eval_direct32 (a, 0, 0); int index = insn_decode (d); assert (index >= 0); if (x) x++; if (strcmp (insn_name (index), "l.jr") == 0) x = 1; a += 4; fprintf (fo, "%08lx\n", d); } while (x < 2); fclose (fo); return a - 4; }
/*---------------------------------------------------------------------------*/ void disassemble_memory (oraddr_t from, oraddr_t to, int nl) { const int INSTR_LEN = 4; oraddr_t i; /* Row counter */ for (i = from; i < to; i += INSTR_LEN) { struct label_entry *entry = get_label (i); PRINTF ("%" PRIxADDR, i); if (NULL != entry) { int padding = 11 - strlen (entry->name); PRINTF (" <%s>: ", entry->name); PRINTF ("%*s ", padding < 0 ? 0 : padding, " "); } else { PRINTF (": "); } if (verify_memoryarea (i)) { uint32_t insn = eval_direct32 (i, 0, 0); int index = or1ksim_insn_decode (insn); PRINTF ("%08" PRIx32 " ", insn); if (index >= 0) { or1ksim_disassemble_insn (insn); PRINTF (" %s", or1ksim_disassembled); } else { PRINTF ("<invalid>"); } } else { /* Not a valid memory area. Print Xs as required */ PRINTF ("XXXXXXXX"); } if (nl) { PRINTF ("\n"); } } } /* disassemble_memory() */
void dumpverilog (char *verilog_modname, oraddr_t from, oraddr_t to) { unsigned int i, done = 0; struct label_entry *tmp; char dis[DISWIDTH + 100]; uint32_t insn; int index; PRINTF ("// This file was generated by or1ksim version %s\n", PACKAGE_VERSION); PRINTF (OR1K_MEM_VERILOG_HEADER (verilog_modname, from / DWQ, to / DWQ, (DISWIDTH * 8))); for (i = from; i < to; i++) { if (!(i & 3)) { insn = eval_direct32 (i, 0, 0); index = or1ksim_insn_decode (insn); if (index >= 0) { if (verify_memoryarea (i) && (tmp = get_label (i))) if (tmp) PRINTF ("\n//\t%s%s", tmp->name, LABELEND_CHAR); PRINTF ("\n\tmem['h%x] = %d'h%.8" PRIx32 ";", i / DWQ, DW, eval_direct32 (i, 0, 0)); or1ksim_disassemble_insn (insn); strcpy (dis, or1ksim_disassembled); if (strlen (dis) < DISWIDTH) memset (dis + strlen (dis), ' ', DISWIDTH); dis[DISWIDTH] = '\0'; PRINTF ("\n\tdis['h%x] = {\"%s\"};", i / DWQ, dis); dis[0] = '\0'; i += or1ksim_insn_len (index) - 1; done = 1; continue; } } if (i % 64 == 0) PRINTF ("\n"); PRINTF ("\n\tmem['h%x] = 'h%.2x;", i / DWQ, eval_direct8 (i, 0, 0)); done = 1; } if (done) { PRINTF (OR1K_MEM_VERILOG_FOOTER); return; } /* this needs to be fixed */ for (i = from; i < to; i++) { if (i % 8 == 0) PRINTF ("\n%.8x: ", i); /* don't print ascii chars below 0x20. */ if (eval_direct32 (i, 0, 0) < 0x20) PRINTF ("0x%.2x ", (uint8_t) eval_direct32 (i, 0, 0)); else PRINTF ("0x%.2x'%c' ", (uint8_t) eval_direct32 (i, 0, 0), (char) eval_direct32 (i, 0, 0)); } PRINTF (OR1K_MEM_VERILOG_FOOTER); }