/[gxemul]/trunk/src/emul.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/src/emul.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 20 by dpavlin, Mon Oct 8 16:19:23 2007 UTC revision 22 by dpavlin, Mon Oct 8 16:19:37 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2003-2005  Anders Gavare.  All rights reserved.   *  Copyright (C) 2003-2006  Anders Gavare.  All rights reserved.
3   *   *
4   *  Redistribution and use in source and binary forms, with or without   *  Redistribution and use in source and binary forms, with or without
5   *  modification, are permitted provided that the following conditions are met:   *  modification, are permitted provided that the following conditions are met:
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: emul.c,v 1.238 2005/11/19 18:53:06 debug Exp $   *  $Id: emul.c,v 1.247 2006/02/04 12:27:12 debug Exp $
29   *   *
30   *  Emulation startup and misc. routines.   *  Emulation startup and misc. routines.
31   */   */
# Line 70  extern struct diskimage *diskimages[]; Line 70  extern struct diskimage *diskimages[];
70  static char *diskimage_types[] = DISKIMAGE_TYPES;  static char *diskimage_types[] = DISKIMAGE_TYPES;
71    
72    
73    static void print_separator(void)
74    {
75            int i = 79;
76            while (i-- > 0)
77                    debug("-");
78            debug("\n");
79    }
80    
81    
82  /*  /*
83   *  add_dump_points():   *  add_dump_points():
84   *   *
# Line 152  static int iso_load_bootblock(struct mac Line 161  static int iso_load_bootblock(struct mac
161          int *n_loadp, char ***load_namesp)          int *n_loadp, char ***load_namesp)
162  {  {
163          char str[35];          char str[35];
164          int filenr, i, ofs, dirlen, res = 0, res2, iadd = 4;          int filenr, i, ofs, dirlen, res = 0, res2, iadd = DEBUG_INDENTATION;
165          int found_dir;          int found_dir;
166          uint64_t dirofs;          uint64_t dirofs;
167          uint64_t fileofs, filelen;          uint64_t fileofs, filelen;
# Line 161  static int iso_load_bootblock(struct mac Line 170  static int iso_load_bootblock(struct mac
170          char *p, *filename_orig;          char *p, *filename_orig;
171          char *filename = strdup(cpu->machine->boot_kernel_filename);          char *filename = strdup(cpu->machine->boot_kernel_filename);
172          unsigned char *filebuf = NULL;          unsigned char *filebuf = NULL;
173          char *tmpfilename = NULL;          char *tmpfname = NULL;
174          char **new_array;          char **new_array;
175          int tmpfile_handle;          int tmpfile_handle;
176    
# Line 207  static int iso_load_bootblock(struct mac Line 216  static int iso_load_bootblock(struct mac
216                  fatal("WARNING: Root directory length mismatch?\n");                  fatal("WARNING: Root directory length mismatch?\n");
217    
218          dirofs = (int64_t)(buf[0x8c] + (buf[0x8d] << 8) + (buf[0x8e] << 16) +          dirofs = (int64_t)(buf[0x8c] + (buf[0x8d] << 8) + (buf[0x8e] << 16) +
219              (buf[0x8f] << 24)) * 2048;              ((uint64_t)buf[0x8f] << 24)) * 2048;
220    
221          /*  debug("root = %i bytes at 0x%llx\n", dirlen, (long long)dirofs);  */          /*  debug("root = %i bytes at 0x%llx\n", dirlen, (long long)dirofs);  */
222    
# Line 228  static int iso_load_bootblock(struct mac Line 237  static int iso_load_bootblock(struct mac
237          dp = dirbuf; filenr = 1;          dp = dirbuf; filenr = 1;
238          p = NULL;          p = NULL;
239          while (dp < dirbuf + dirlen) {          while (dp < dirbuf + dirlen) {
240                  int i, nlen = dp[0];                  size_t i, nlen = dp[0];
241                  int x = dp[2] + (dp[3] << 8) + (dp[4] << 16) + (dp[5] << 24);                  int x = dp[2] + (dp[3] << 8) + (dp[4] << 16) +
242                        ((uint64_t)dp[5] << 24);
243                  int y = dp[6] + (dp[7] << 8);                  int y = dp[6] + (dp[7] << 8);
244                  char direntry[65];                  char direntry[65];
245    
# Line 299  static int iso_load_bootblock(struct mac Line 309  static int iso_load_bootblock(struct mac
309          }          }
310    
311          for (;;) {          for (;;) {
312                  int len, i;                  size_t len, i;
313    
314                  /*  Too close to another sector? Then realign.  */                  /*  Too close to another sector? Then realign.  */
315                  if ((dirofs & 2047) + 70 > 2047) {                  if ((dirofs & 2047) + 70 > 2047) {
# Line 364  static int iso_load_bootblock(struct mac Line 374  static int iso_load_bootblock(struct mac
374          }          }
375    
376          fileofs = match_entry[2] + (match_entry[3] << 8) +          fileofs = match_entry[2] + (match_entry[3] << 8) +
377              (match_entry[4] << 16) + (match_entry[5] << 24);              (match_entry[4] << 16) + ((uint64_t)match_entry[5] << 24);
378          filelen = match_entry[10] + (match_entry[11] << 8) +          filelen = match_entry[10] + (match_entry[11] << 8) +
379              (match_entry[12] << 16) + (match_entry[13] << 24);              (match_entry[12] << 16) + ((uint64_t)match_entry[13] << 24);
380          fileofs *= 2048;          fileofs *= 2048;
381    
382          /*  debug("filelen=%llx fileofs=%llx\n", (long long)filelen,          /*  debug("filelen=%llx fileofs=%llx\n", (long long)filelen,
# Line 379  static int iso_load_bootblock(struct mac Line 389  static int iso_load_bootblock(struct mac
389                  goto ret;                  goto ret;
390          }          }
391    
392          tmpfilename = strdup("/tmp/gxemul.XXXXXXXXXXXX");          tmpfname = strdup("/tmp/gxemul.XXXXXXXXXXXX");
   
         debug("extracting %lli bytes into %s\n",  
             (long long)filelen, tmpfilename);  
393    
394          res2 = diskimage_access(m, disk_id, disk_type, 0, fileofs, filebuf,          res2 = diskimage_access(m, disk_id, disk_type, 0, fileofs, filebuf,
395              filelen);              filelen);
# Line 391  static int iso_load_bootblock(struct mac Line 398  static int iso_load_bootblock(struct mac
398                  goto ret;                  goto ret;
399          }          }
400    
401          tmpfile_handle = mkstemp(tmpfilename);          tmpfile_handle = mkstemp(tmpfname);
402          if (tmpfile_handle < 0) {          if (tmpfile_handle < 0) {
403                  fatal("could not create %s\n", tmpfilename);                  fatal("could not create %s\n", tmpfname);
404                  exit(1);                  exit(1);
405          }          }
406          write(tmpfile_handle, filebuf, filelen);          write(tmpfile_handle, filebuf, filelen);
407          close(tmpfile_handle);          close(tmpfile_handle);
408    
409            debug("extracted %lli bytes into %s\n", (long long)filelen, tmpfname);
410    
411          /*  Add the temporary filename to the load_namesp array:  */          /*  Add the temporary filename to the load_namesp array:  */
412          (*n_loadp)++;          (*n_loadp)++;
413          new_array = malloc(sizeof(char *) * (*n_loadp));          new_array = malloc(sizeof(char *) * (*n_loadp));
# Line 412  static int iso_load_bootblock(struct mac Line 421  static int iso_load_bootblock(struct mac
421          /*  This adds a Backspace char in front of the filename; this          /*  This adds a Backspace char in front of the filename; this
422              is a special hack which causes the file to be removed once              is a special hack which causes the file to be removed once
423              it has been loaded.  */              it has been loaded.  */
424          tmpfilename = realloc(tmpfilename, strlen(tmpfilename) + 2);          tmpfname = realloc(tmpfname, strlen(tmpfname) + 2);
425          memmove(tmpfilename + 1, tmpfilename, strlen(tmpfilename) + 1);          memmove(tmpfname + 1, tmpfname, strlen(tmpfname) + 1);
426          tmpfilename[0] = 8;          tmpfname[0] = 8;
427    
428          (*load_namesp)[*n_loadp - 1] = tmpfilename;          (*load_namesp)[*n_loadp - 1] = tmpfname;
429    
430          res = 1;          res = 1;
431    
# Line 469  static int apple_load_bootblock(struct m Line 478  static int apple_load_bootblock(struct m
478                  int ofs = 0x200 * (partnr + 1);                  int ofs = 0x200 * (partnr + 1);
479                  if (partnr == 0)                  if (partnr == 0)
480                          n_partitions = buf[ofs + 7];                          n_partitions = buf[ofs + 7];
481                  start = (buf[ofs + 8] << 24) + (buf[ofs + 9] << 16) +                  start = ((uint64_t)buf[ofs + 8] << 24) + (buf[ofs + 9] << 16) +
482                      (buf[ofs + 10] << 8) + buf[ofs + 11];                      (buf[ofs + 10] << 8) + buf[ofs + 11];
483                  length = (buf[ofs + 12] << 24) + (buf[ofs + 13] << 16) +                  length = ((uint64_t)buf[ofs+12] << 24) + (buf[ofs + 13] << 16) +
484                      (buf[ofs + 14] << 8) + buf[ofs + 15];                      (buf[ofs + 14] << 8) + buf[ofs + 15];
485    
486                  debug("partition %i: '%s', type '%s', start %i, length %i\n",                  debug("partition %i: '%s', type '%s', start %i, length %i\n",
# Line 526  static int load_bootblock(struct machine Line 535  static int load_bootblock(struct machine
535                  return 0;                  return 0;
536    
537          switch (m->machine_type) {          switch (m->machine_type) {
538          case MACHINE_DEC:          case MACHINE_PMAX:
539                  /*                  /*
540                   *  The first few bytes of a disk contains information about                   *  The first few bytes of a disk contains information about
541                   *  where the bootblock(s) are located. (These are all 32-bit                   *  where the bootblock(s) are located. (These are all 32-bit
# Line 547  static int load_bootblock(struct machine Line 556  static int load_bootblock(struct machine
556                      minibuf, sizeof(minibuf));                      minibuf, sizeof(minibuf));
557    
558                  bootblock_loadaddr = minibuf[0x10] + (minibuf[0x11] << 8)                  bootblock_loadaddr = minibuf[0x10] + (minibuf[0x11] << 8)
559                    + (minibuf[0x12] << 16) + (minibuf[0x13] << 24);                    + (minibuf[0x12] << 16) + ((uint64_t)minibuf[0x13] << 24);
560    
561                  /*  Convert loadaddr to uncached:  */                  /*  Convert loadaddr to uncached:  */
562                  if ((bootblock_loadaddr & 0xf0000000ULL) != 0x80000000 &&                  if ((bootblock_loadaddr & 0xf0000000ULL) != 0x80000000 &&
# Line 558  static int load_bootblock(struct machine Line 567  static int load_bootblock(struct machine
567                  bootblock_loadaddr |= 0xffffffffa0000000ULL;                  bootblock_loadaddr |= 0xffffffffa0000000ULL;
568    
569                  bootblock_pc = minibuf[0x14] + (minibuf[0x15] << 8)                  bootblock_pc = minibuf[0x14] + (minibuf[0x15] << 8)
570                    + (minibuf[0x16] << 16) + (minibuf[0x17] << 24);                    + (minibuf[0x16] << 16) + ((uint64_t)minibuf[0x17] << 24);
571    
572                  bootblock_pc &= 0x0fffffffULL;                  bootblock_pc &= 0x0fffffffULL;
573                  bootblock_pc |= 0xffffffffa0000000ULL;                  bootblock_pc |= 0xffffffffa0000000ULL;
# Line 579  static int load_bootblock(struct machine Line 588  static int load_bootblock(struct machine
588                          }                          }
589    
590                          n_blocks = minibuf[0] + (minibuf[1] << 8)                          n_blocks = minibuf[0] + (minibuf[1] << 8)
591                            + (minibuf[2] << 16) + (minibuf[3] << 24);                            + (minibuf[2] << 16) + ((uint64_t)minibuf[3] << 24);
592    
593                          bootblock_offset = (minibuf[4] + (minibuf[5] << 8)                          bootblock_offset = (minibuf[4] + (minibuf[5] << 8) +
594                            + (minibuf[6] << 16) + (minibuf[7] << 24)) * 512;                            (minibuf[6]<<16) + ((uint64_t)minibuf[7]<<24)) * 512;
595    
596                          if (n_blocks < 1)                          if (n_blocks < 1)
597                                  break;                                  break;
# Line 903  static void add_arc_components(struct ma Line 912  static void add_arc_components(struct ma
912  void emul_machine_setup(struct machine *m, int n_load, char **load_names,  void emul_machine_setup(struct machine *m, int n_load, char **load_names,
913          int n_devices, char **device_names)          int n_devices, char **device_names)
914  {  {
         struct emul *emul;  
915          struct cpu *cpu;          struct cpu *cpu;
916          int i, iadd=4;          int i, iadd = DEBUG_INDENTATION;
917          uint64_t memory_amount, entrypoint = 0, gp = 0, toc = 0;          uint64_t memory_amount, entrypoint = 0, gp = 0, toc = 0;
918          int byte_order;          int byte_order;
919    
         emul = m->emul;  
   
920          debug("machine \"%s\":\n", m->name);          debug("machine \"%s\":\n", m->name);
921          debug_indentation(iadd);          debug_indentation(iadd);
922    
# Line 1063  void emul_machine_setup(struct machine * Line 1069  void emul_machine_setup(struct machine *
1069          }          }
1070    
1071          diskimage_dump_info(m);          diskimage_dump_info(m);
1072            console_debug_dump(m);
1073    
1074          /*  Load files (ROM code, boot code, ...) into memory:  */          /*  Load files (ROM code, boot code, ...) into memory:  */
1075          if (n_load == 0) {          if (n_load == 0) {
# Line 1341  void emul_machine_setup(struct machine * Line 1348  void emul_machine_setup(struct machine *
1348          add_dump_points(m);          add_dump_points(m);
1349    
1350          /*  TODO: This is MIPS-specific!  */          /*  TODO: This is MIPS-specific!  */
1351          if (m->machine_type == MACHINE_DEC &&          if (m->machine_type == MACHINE_PMAX &&
1352              cpu->cd.mips.cpu_type.mmu_model == MMU3K)              cpu->cd.mips.cpu_type.mmu_model == MMU3K)
1353                  add_symbol_name(&m->symbol_context,                  add_symbol_name(&m->symbol_context,
1354                      0x9fff0000, 0x10000, "r2k3k_cache", 0, 0);                      0x9fff0000, 0x10000, "r2k3k_cache", 0, 0);
# Line 1357  void emul_machine_setup(struct machine * Line 1364  void emul_machine_setup(struct machine *
1364              m->machine_type == MACHINE_SGI) && m->prom_emulation)              m->machine_type == MACHINE_SGI) && m->prom_emulation)
1365                  add_arc_components(m);                  add_arc_components(m);
1366    
   
 #if 0  
 if (m->machine_type == MACHINE_IQ80321) {  
         store_32bit_word(cpu, 0xc0200000, 0);  
         store_32bit_word(cpu, 0xc0200004, 0xd0000000);  
 }  
 #endif  
   
   
1367          debug("starting cpu%i at ", m->bootstrap_cpu);          debug("starting cpu%i at ", m->bootstrap_cpu);
1368          switch (m->arch) {          switch (m->arch) {
1369    
# Line 1409  if (m->machine_type == MACHINE_IQ80321) Line 1407  if (m->machine_type == MACHINE_IQ80321)
1407                  break;                  break;
1408    
1409          default:          default:
1410                  debug("0x%016llx", (long long)cpu->pc);                  if (cpu->is_32bit)
1411                            debug("0x%08x", (int)cpu->pc);
1412                    else
1413                            debug("0x%016llx", (long long)cpu->pc);
1414          }          }
1415          debug("\n");          debug("\n");
1416    
# Line 1424  if (m->machine_type == MACHINE_IQ80321) Line 1425  if (m->machine_type == MACHINE_IQ80321)
1425   */   */
1426  void emul_dumpinfo(struct emul *e)  void emul_dumpinfo(struct emul *e)
1427  {  {
1428          int j, nm, iadd = 4;          int j, nm, iadd = DEBUG_INDENTATION;
1429    
1430          if (e->net != NULL)          if (e->net != NULL)
1431                  net_dumpinfo(e->net);                  net_dumpinfo(e->net);
# Line 1453  void emul_dumpinfo(struct emul *e) Line 1454  void emul_dumpinfo(struct emul *e)
1454   */   */
1455  void emul_simple_init(struct emul *emul)  void emul_simple_init(struct emul *emul)
1456  {  {
1457          int iadd=4;          int iadd = DEBUG_INDENTATION;
1458          struct machine *m;          struct machine *m;
1459    
1460          if (emul->n_machines != 1) {          if (emul->n_machines != 1) {
# Line 1490  void emul_simple_init(struct emul *emul) Line 1491  void emul_simple_init(struct emul *emul)
1491   */   */
1492  struct emul *emul_create_from_configfile(char *fname)  struct emul *emul_create_from_configfile(char *fname)
1493  {  {
1494          int iadd = 4;          int iadd = DEBUG_INDENTATION;
1495          struct emul *e = emul_new(fname);          struct emul *e = emul_new(fname);
1496          FILE *f;          FILE *f;
1497          char buf[128];          char buf[128];
# Line 1544  void emul_run(struct emul **emuls, int n Line 1545  void emul_run(struct emul **emuls, int n
1545    
1546          atexit(fix_console);          atexit(fix_console);
1547    
         i = 79;  
         while (i-- > 0)  
                 debug("-");  
         debug("\n\n");  
   
1548          /*  Initialize the interactive debugger:  */          /*  Initialize the interactive debugger:  */
1549          debugger_init(emuls, n_emuls);          debugger_init(emuls, n_emuls);
1550    
1551            /*  Run any additional debugger commands before starting:  */
1552            for (i=0; i<n_emuls; i++) {
1553                    struct emul *emul = emuls[i];
1554                    if (emul->n_debugger_cmds > 0) {
1555                            int j;
1556                            if (i == 0)
1557                                    print_separator();
1558                            for (j = 0; j < emul->n_debugger_cmds; j ++) {
1559                                    debug("> %s\n", emul->debugger_cmds[j]);
1560                                    debugger_execute_cmd(emul->debugger_cmds[j],
1561                                        strlen(emul->debugger_cmds[j]));
1562                            }
1563                    }
1564            }
1565    
1566            print_separator();
1567            debug("\n");
1568    
1569    
1570          /*          /*
1571           *  console_init_main() makes sure that the terminal is in a           *  console_init_main() makes sure that the terminal is in a
1572           *  reasonable state.           *  reasonable state.

Legend:
Removed from v.20  
changed lines
  Added in v.22

  ViewVC Help
Powered by ViewVC 1.1.26