/[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 4 by dpavlin, Mon Oct 8 16:18:00 2007 UTC revision 20 by dpavlin, Mon Oct 8 16:19:23 2007 UTC
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: emul.c,v 1.184 2005/04/20 04:43:52 debug Exp $   *  $Id: emul.c,v 1.238 2005/11/19 18:53:06 debug Exp $
29   *   *
30   *  Emulation startup and misc. routines.   *  Emulation startup and misc. routines.
31   */   */
# Line 46  Line 46 
46  #include "debugger.h"  #include "debugger.h"
47  #include "device.h"  #include "device.h"
48  #include "diskimage.h"  #include "diskimage.h"
49    #include "exec_elf.h"
50  #include "machine.h"  #include "machine.h"
51  #include "memory.h"  #include "memory.h"
52  #include "mips_cpu_types.h"  #include "mips_cpu_types.h"
# Line 66  extern int quiet_mode; Line 67  extern int quiet_mode;
67  extern struct emul *debugger_emul;  extern struct emul *debugger_emul;
68  extern struct diskimage *diskimages[];  extern struct diskimage *diskimages[];
69    
70    static char *diskimage_types[] = DISKIMAGE_TYPES;
71    
72    
73  /*  /*
74   *  add_dump_points():   *  add_dump_points():
# Line 109  static void add_dump_points(struct machi Line 112  static void add_dump_points(struct machi
112                   *  were automatically converted into the correct address.                   *  were automatically converted into the correct address.
113                   */                   */
114    
115                  if ((dp >> 32) == 0 && ((dp >> 31) & 1))                  if (m->arch == ARCH_MIPS) {
116                          dp |= 0xffffffff00000000ULL;                          if ((dp >> 32) == 0 && ((dp >> 31) & 1))
117                                    dp |= 0xffffffff00000000ULL;
118                    }
119    
120                  m->breakpoint_addr[i] = dp;                  m->breakpoint_addr[i] = dp;
121    
122                  debug("breakpoint %i: 0x%016llx", i, (long long)dp);                  debug("breakpoint %i: 0x%llx", i, (long long)dp);
123                  if (string_flag)                  if (string_flag)
124                          debug(" (%s)", m->breakpoint_string[i]);                          debug(" (%s)", m->breakpoint_string[i]);
125                  debug("\n");                  debug("\n");
# Line 131  static void fix_console(void) Line 137  static void fix_console(void)
137    
138    
139  /*  /*
140     *  iso_load_bootblock():
141     *
142     *  Try to load a kernel from an ISO 9660 disk image. iso_type is 1 for
143     *  "CD001" (standard), 2 for "CDW01" (ECMA), and 3 for "CDROM" (Sierra).
144     *
145     *  TODO: This function uses too many magic offsets and so on; it should be
146     *  cleaned up some day.
147     *
148     *  Returns 1 on success, 0 on failure.
149     */
150    static int iso_load_bootblock(struct machine *m, struct cpu *cpu,
151            int disk_id, int disk_type, int iso_type, unsigned char *buf,
152            int *n_loadp, char ***load_namesp)
153    {
154            char str[35];
155            int filenr, i, ofs, dirlen, res = 0, res2, iadd = 4;
156            int found_dir;
157            uint64_t dirofs;
158            uint64_t fileofs, filelen;
159            unsigned char *dirbuf = NULL, *dp;
160            unsigned char *match_entry = NULL;
161            char *p, *filename_orig;
162            char *filename = strdup(cpu->machine->boot_kernel_filename);
163            unsigned char *filebuf = NULL;
164            char *tmpfilename = NULL;
165            char **new_array;
166            int tmpfile_handle;
167    
168            if (filename == NULL) {
169                    fatal("out of memory\n");
170                    exit(1);
171            }
172            filename_orig = filename;
173    
174            debug("ISO9660 boot:\n");
175            debug_indentation(iadd);
176    
177            /*  Volume ID:  */
178            ofs = iso_type == 3? 48 : 40;
179            memcpy(str, buf + ofs, sizeof(str));
180            str[32] = '\0';  i = 31;
181            while (i >= 0 && str[i]==' ')
182                    str[i--] = '\0';
183            if (str[0])
184                    debug("\"%s\"", str);
185            else {
186                    /*  System ID:  */
187                    ofs = iso_type == 3? 16 : 8;
188                    memcpy(str, buf + ofs, sizeof(str));
189                    str[32] = '\0';  i = 31;
190                    while (i >= 0 && str[i]==' ')
191                            str[i--] = '\0';
192                    if (str[0])
193                            debug("\"%s\"", str);
194                    else
195                            debug("(no ID)");
196            }
197    
198            debug(":%s\n", filename);
199    
200    
201            /*
202             *  Traverse the directory structure to find the kernel.
203             */
204    
205            dirlen = buf[0x84] + 256*buf[0x85] + 65536*buf[0x86];
206            if (dirlen != buf[0x8b] + 256*buf[0x8a] + 65536*buf[0x89])
207                    fatal("WARNING: Root directory length mismatch?\n");
208    
209            dirofs = (int64_t)(buf[0x8c] + (buf[0x8d] << 8) + (buf[0x8e] << 16) +
210                (buf[0x8f] << 24)) * 2048;
211    
212            /*  debug("root = %i bytes at 0x%llx\n", dirlen, (long long)dirofs);  */
213    
214            dirbuf = malloc(dirlen);
215            if (dirbuf == NULL) {
216                    fatal("out of memory in iso_load_bootblock()\n");
217                    exit(1);
218            }
219    
220            res2 = diskimage_access(m, disk_id, disk_type, 0, dirofs, dirbuf,
221                dirlen);
222            if (!res2) {
223                    fatal("Couldn't read the disk image. Aborting.\n");
224                    goto ret;
225            }
226    
227            found_dir = 1;  /*  Assume root dir  */
228            dp = dirbuf; filenr = 1;
229            p = NULL;
230            while (dp < dirbuf + dirlen) {
231                    int i, nlen = dp[0];
232                    int x = dp[2] + (dp[3] << 8) + (dp[4] << 16) + (dp[5] << 24);
233                    int y = dp[6] + (dp[7] << 8);
234                    char direntry[65];
235    
236                    dp += 8;
237    
238                    /*
239                     *  As long as there is an \ or / in the filename, then we
240                     *  have not yet found the directory.
241                     */
242                    p = strchr(filename, '/');
243                    if (p == NULL)
244                            p = strchr(filename, '\\');
245    
246                    /*  debug("%i%s: %i, %i, \"", filenr, filenr == found_dir?
247                        " [CURRENT]" : "", x, y);  */
248                    for (i=0; i<nlen && i<sizeof(direntry)-1; i++)
249                            if (dp[i]) {
250                                    direntry[i] = dp[i];
251                                    /*  debug("%c", dp[i]);  */
252                            } else
253                                    break;
254                    /*  debug("\"\n");  */
255                    direntry[i] = '\0';
256    
257                    /*  A directory name match?  */
258                    if (p != NULL && strncasecmp(filename, direntry, nlen) == 0
259                        && nlen == (size_t)p - (size_t)filename && found_dir == y) {
260                            found_dir = filenr;
261                            filename = p+1;
262                            dirofs = 2048 * (int64_t)x;
263                    }
264    
265                    dp += nlen;
266    
267                    /*  16-bit aligned lenght:  */
268                    if (nlen & 1)
269                            dp ++;
270    
271                    filenr ++;
272            }
273    
274            p = strchr(filename, '/');
275            if (p == NULL)
276                    p = strchr(filename, '\\');
277    
278            if (p != NULL) {
279                    char *blah = filename_orig;
280    
281                    fatal("could not find '%s' in /", filename);
282    
283                    /*  Print the first part of the filename:  */
284                    while (blah != filename)
285                            fatal("%c", *blah++);
286                    
287                    fatal("\n");
288                    goto ret;
289            }
290    
291            /*  debug("dirofs = 0x%llx\n", (long long)dirofs);  */
292    
293            /*  Free the old dirbuf, and allocate a new one:  */
294            free(dirbuf);
295            dirbuf = malloc(512);
296            if (dirbuf == NULL) {
297                    fatal("out of memory in iso_load_bootblock()\n");
298                    exit(1);
299            }
300    
301            for (;;) {
302                    int len, i;
303    
304                    /*  Too close to another sector? Then realign.  */
305                    if ((dirofs & 2047) + 70 > 2047) {
306                            dirofs = (dirofs | 2047) + 1;
307                            /*  debug("realign dirofs = 0x%llx\n", dirofs);  */
308                    }
309    
310                    res2 = diskimage_access(m, disk_id, disk_type, 0, dirofs,
311                        dirbuf, 256);
312                    if (!res2) {
313                            fatal("Couldn't read the disk image. Aborting.\n");
314                            goto ret;
315                    }
316    
317                    dp = dirbuf;
318                    len = dp[0];
319                    if (len < 2)
320                            break;
321    
322                    /*
323                     *  TODO: Actually parse the directory entry!
324                     *
325                     *  Haha, this must be rewritten.
326                     */
327                    for (i=32; i<len; i++) {
328                            if (i < len - strlen(filename))
329                                    if (strncasecmp(filename, (char *)dp + i,
330                                        strlen(filename)) == 0) {
331                                            /*  The filename was found somewhere
332                                                in the directory entry.  */
333                                            if (match_entry != NULL) {
334                                                    fatal("TODO: I'm too lazy to"
335                                                        " implement a correct "
336                                                        "directory parser right "
337                                                        "now... (BUG)\n");
338                                                    exit(1);
339                                            }
340                                            match_entry = malloc(512);
341                                            if (match_entry == NULL) {
342                                                    fatal("out of memory\n");
343                                                    exit(1);
344                                            }
345                                            memcpy(match_entry, dp, 512);
346                                            break;
347                                    }
348                    }
349    
350                    dirofs += len;
351            }
352    
353            if (match_entry == NULL) {
354                    char *blah = filename_orig;
355    
356                    fatal("could not find '%s' in /", filename);
357    
358                    /*  Print the first part of the filename:  */
359                    while (blah != filename)
360                            fatal("%c", *blah++);
361                    
362                    fatal("\n");
363                    goto ret;
364            }
365    
366            fileofs = match_entry[2] + (match_entry[3] << 8) +
367                (match_entry[4] << 16) + (match_entry[5] << 24);
368            filelen = match_entry[10] + (match_entry[11] << 8) +
369                (match_entry[12] << 16) + (match_entry[13] << 24);
370            fileofs *= 2048;
371    
372            /*  debug("filelen=%llx fileofs=%llx\n", (long long)filelen,
373                (long long)fileofs);  */
374    
375            filebuf = malloc(filelen);
376            if (filebuf == NULL) {
377                    fatal("could not allocate %lli bytes to read the file"
378                        " from the disk image!\n", (long long)filelen);
379                    goto ret;
380            }
381    
382            tmpfilename = strdup("/tmp/gxemul.XXXXXXXXXXXX");
383    
384            debug("extracting %lli bytes into %s\n",
385                (long long)filelen, tmpfilename);
386    
387            res2 = diskimage_access(m, disk_id, disk_type, 0, fileofs, filebuf,
388                filelen);
389            if (!res2) {
390                    fatal("could not read the file from the disk image!\n");
391                    goto ret;
392            }
393    
394            tmpfile_handle = mkstemp(tmpfilename);
395            if (tmpfile_handle < 0) {
396                    fatal("could not create %s\n", tmpfilename);
397                    exit(1);
398            }
399            write(tmpfile_handle, filebuf, filelen);
400            close(tmpfile_handle);
401    
402            /*  Add the temporary filename to the load_namesp array:  */
403            (*n_loadp)++;
404            new_array = malloc(sizeof(char *) * (*n_loadp));
405            if (new_array == NULL) {
406                    fatal("out of memory\n");
407                    exit(1);
408            }
409            memcpy(new_array, *load_namesp, sizeof(char *) * (*n_loadp));
410            *load_namesp = new_array;
411    
412            /*  This adds a Backspace char in front of the filename; this
413                is a special hack which causes the file to be removed once
414                it has been loaded.  */
415            tmpfilename = realloc(tmpfilename, strlen(tmpfilename) + 2);
416            memmove(tmpfilename + 1, tmpfilename, strlen(tmpfilename) + 1);
417            tmpfilename[0] = 8;
418    
419            (*load_namesp)[*n_loadp - 1] = tmpfilename;
420    
421            res = 1;
422    
423    ret:
424            if (dirbuf != NULL)
425                    free(dirbuf);
426    
427            if (filebuf != NULL)
428                    free(filebuf);
429    
430            if (match_entry != NULL)
431                    free(match_entry);
432    
433            free(filename_orig);
434    
435            debug_indentation(-iadd);
436            return res;
437    }
438    
439    
440    /*
441     *  apple_load_bootblock():
442     *
443     *  Try to load a kernel from a disk image with an Apple Partition Table.
444     *
445     *  TODO: This function uses too many magic offsets and so on; it should be
446     *  cleaned up some day. See http://www.awprofessional.com/articles/
447     *      article.asp?p=376123&seqNum=3&rl=1  for some info on the Apple
448     *  partition format.
449     *
450     *  Returns 1 on success, 0 on failure.
451     */
452    static int apple_load_bootblock(struct machine *m, struct cpu *cpu,
453            int disk_id, int disk_type, int *n_loadp, char ***load_namesp)
454    {
455            unsigned char buf[0x8000];
456            int res, partnr, n_partitions = 0, n_hfs_partitions = 0;
457            uint64_t hfs_start, hfs_length;
458    
459            res = diskimage_access(m, disk_id, disk_type, 0, 0x0, buf, sizeof(buf));
460            if (!res) {
461                    fatal("apple_load_bootblock: couldn't read the disk "
462                        "image. Aborting.\n");
463                    return 0;
464            }
465    
466            partnr = 0;
467            do {
468                    int start, length;
469                    int ofs = 0x200 * (partnr + 1);
470                    if (partnr == 0)
471                            n_partitions = buf[ofs + 7];
472                    start = (buf[ofs + 8] << 24) + (buf[ofs + 9] << 16) +
473                        (buf[ofs + 10] << 8) + buf[ofs + 11];
474                    length = (buf[ofs + 12] << 24) + (buf[ofs + 13] << 16) +
475                        (buf[ofs + 14] << 8) + buf[ofs + 15];
476    
477                    debug("partition %i: '%s', type '%s', start %i, length %i\n",
478                        partnr, buf + ofs + 0x10, buf + ofs + 0x30,
479                        start, length);
480    
481                    if (strcmp((char *)buf + ofs + 0x30, "Apple_HFS") == 0) {
482                            n_hfs_partitions ++;
483                            hfs_start = 512 * start;
484                            hfs_length = 512 * length;
485                    }
486    
487                    /*  Any more partitions?  */
488                    partnr ++;
489            } while (partnr < n_partitions);
490    
491            if (n_hfs_partitions == 0) {
492                    fatal("Error: No HFS partition found! TODO\n");
493                    return 0;
494            }
495            if (n_hfs_partitions >= 2) {
496                    fatal("Error: Too many HFS partitions found! TODO\n");
497                    return 0;
498            }
499    
500            return 0;
501    }
502    
503    
504    /*
505   *  load_bootblock():   *  load_bootblock():
506   *   *
507   *  For some emulation modes, it is possible to boot from a harddisk image by   *  For some emulation modes, it is possible to boot from a harddisk image by
508   *  loading a bootblock from a specific disk offset into memory, and executing   *  loading a bootblock from a specific disk offset into memory, and executing
509   *  that, instead of requiring a separate kernel file.  It is then up to the   *  that, instead of requiring a separate kernel file.  It is then up to the
510   *  bootblock to load a kernel.   *  bootblock to load a kernel.
511     *
512     *  Returns 1 on success, 0 on failure.
513   */   */
514  static void load_bootblock(struct machine *m, struct cpu *cpu)  static int load_bootblock(struct machine *m, struct cpu *cpu,
515            int *n_loadp, char ***load_namesp)
516  {  {
517          int boot_disk_id;          int boot_disk_id, boot_disk_type = 0, n_blocks, res, readofs,
518                iso_type, retval = 0;
519          unsigned char minibuf[0x20];          unsigned char minibuf[0x20];
520          unsigned char *bootblock_buf;          unsigned char *bootblock_buf;
521          uint64_t bootblock_offset;          uint64_t bootblock_offset;
522          uint64_t bootblock_loadaddr, bootblock_pc;          uint64_t bootblock_loadaddr, bootblock_pc;
         int n_blocks, res, readofs;  
523    
524          boot_disk_id = diskimage_bootdev(m);          boot_disk_id = diskimage_bootdev(m, &boot_disk_type);
525          if (boot_disk_id < 0)          if (boot_disk_id < 0)
526                  return;                  return 0;
527    
528          switch (m->machine_type) {          switch (m->machine_type) {
529          case MACHINE_DEC:          case MACHINE_DEC:
# Line 169  static void load_bootblock(struct machin Line 543  static void load_bootblock(struct machin
543                   *  nr of blocks to read and offset are repeated until nr of                   *  nr of blocks to read and offset are repeated until nr of
544                   *  blocks to read is zero.                   *  blocks to read is zero.
545                   */                   */
546                  res = diskimage_access(m, boot_disk_id, 0, 0,                  res = diskimage_access(m, boot_disk_id, boot_disk_type, 0, 0,
547                      minibuf, sizeof(minibuf));                      minibuf, sizeof(minibuf));
548    
549                  bootblock_loadaddr = minibuf[0x10] + (minibuf[0x11] << 8)                  bootblock_loadaddr = minibuf[0x10] + (minibuf[0x11] << 8)
# Line 196  static void load_bootblock(struct machin Line 570  static void load_bootblock(struct machin
570                  readofs = 0x18;                  readofs = 0x18;
571    
572                  for (;;) {                  for (;;) {
573                          res = diskimage_access(m, boot_disk_id, 0, readofs,                          res = diskimage_access(m, boot_disk_id, boot_disk_type,
574                              minibuf, sizeof(minibuf));                              0, readofs, minibuf, sizeof(minibuf));
575                          if (!res) {                          if (!res) {
576                                  printf("couldn't read disk?\n");                                  fatal("Couldn't read the disk image. "
577                                  exit(1);                                      "Aborting.\n");
578                                    return 0;
579                          }                          }
580    
581                          n_blocks = minibuf[0] + (minibuf[1] << 8)                          n_blocks = minibuf[0] + (minibuf[1] << 8)
# Line 225  static void load_bootblock(struct machin Line 600  static void load_bootblock(struct machin
600                                  exit(1);                                  exit(1);
601                          }                          }
602    
603                          res = diskimage_access(m, boot_disk_id, 0,                          res = diskimage_access(m, boot_disk_id, boot_disk_type,
604                              bootblock_offset, bootblock_buf, n_blocks * 512);                              0, bootblock_offset, bootblock_buf, n_blocks * 512);
605                          if (!res) {                          if (!res) {
606                                  fatal("WARNING: could not load bootblocks from"                                  fatal("WARNING: could not load bootblocks from"
607                                      " disk offset 0x%llx\n",                                      " disk offset 0x%llx\n",
# Line 242  static void load_bootblock(struct machin Line 617  static void load_bootblock(struct machin
617                  }                  }
618    
619                  debug(readofs == 0x18? ": no blocks?\n" : " blocks\n");                  debug(readofs == 0x18? ": no blocks?\n" : " blocks\n");
620                  break;                  return 1;
621    
622          case MACHINE_X86:          case MACHINE_X86:
623                  cpu->cd.x86.mode = 16;                  /*  TODO: "El Torito" etc?  */
624                  cpu->pc = 0x7c00;                  if (diskimage_is_a_cdrom(cpu->machine, boot_disk_id,
625                        boot_disk_type))
626                            break;
627    
628                  bootblock_buf = malloc(512);                  bootblock_buf = malloc(512);
629                  if (bootblock_buf == NULL) {                  if (bootblock_buf == NULL) {
# Line 254  static void load_bootblock(struct machin Line 631  static void load_bootblock(struct machin
631                          exit(1);                          exit(1);
632                  }                  }
633    
634                  res = diskimage_access(m, boot_disk_id, 0, 0,                  debug("loading PC bootsector from %s id %i\n",
635                        diskimage_types[boot_disk_type], boot_disk_id);
636    
637                    res = diskimage_access(m, boot_disk_id, boot_disk_type, 0, 0,
638                      bootblock_buf, 512);                      bootblock_buf, 512);
639                  if (!res) {                  if (!res) {
640                          printf("Couldn't read the disk image. Aborting.\n");                          fatal("Couldn't read the disk image. Aborting.\n");
641                          exit(1);                          return 0;
642                  }                  }
643    
                 debug("loading PC bootsector from disk %i\n", boot_disk_id);  
644                  if (bootblock_buf[510] != 0x55 || bootblock_buf[511] != 0xaa)                  if (bootblock_buf[510] != 0x55 || bootblock_buf[511] != 0xaa)
645                          debug("WARNING! The 0x55,0xAA marker is missing! "                          debug("WARNING! The 0x55,0xAA marker is missing! "
646                              "Booting anyway.\n");                              "Booting anyway.\n");
647                  store_buf(cpu, 0x7c00, (char *)bootblock_buf, 512);                  store_buf(cpu, 0x7c00, (char *)bootblock_buf, 512);
648                  free(bootblock_buf);                  free(bootblock_buf);
                 break;  
649    
650          default:                  return 1;
651                  fatal("Booting from disk without a separate kernel "          }
652                      "doesn't work in this emulation mode.\n");  
653    
654            /*
655             *  Try reading a kernel manually from the disk. The code here
656             *  does not rely on machine-dependent boot blocks etc.
657             */
658            /*  ISO9660: (0x800 bytes at 0x8000)  */
659            bootblock_buf = malloc(0x800);
660            if (bootblock_buf == NULL) {
661                    fprintf(stderr, "Out of memory.\n");
662                  exit(1);                  exit(1);
663          }          }
664    
665            res = diskimage_access(m, boot_disk_id, boot_disk_type,
666                0, 0x8000, bootblock_buf, 0x800);
667            if (!res) {
668                    fatal("Couldn't read the disk image. Aborting.\n");
669                    return 0;
670            }
671    
672            iso_type = 0;
673            if (strncmp((char *)bootblock_buf+1, "CD001", 5) == 0)
674                    iso_type = 1;
675            if (strncmp((char *)bootblock_buf+1, "CDW01", 5) == 0)
676                    iso_type = 2;
677            if (strncmp((char *)bootblock_buf+1, "CDROM", 5) == 0)
678                    iso_type = 3;
679    
680            if (iso_type != 0) {
681                    /*  We can't load a kernel if the name
682                        isn't specified.  */
683                    if (cpu->machine->boot_kernel_filename == NULL ||
684                        cpu->machine->boot_kernel_filename[0] == '\0')
685                            fatal("\nISO9660 filesystem, but no kernel "
686                                "specified? (Use the -j option.)\n");
687                    else
688                            retval = iso_load_bootblock(m, cpu, boot_disk_id,
689                                boot_disk_type, iso_type, bootblock_buf,
690                                n_loadp, load_namesp);
691            }
692    
693            if (retval != 0)
694                    goto ret_ok;
695    
696            /*  Apple parition table:  */
697            res = diskimage_access(m, boot_disk_id, boot_disk_type,
698                0, 0x0, bootblock_buf, 0x800);
699            if (!res) {
700                    fatal("Couldn't read the disk image. Aborting.\n");
701                    return 0;
702            }
703            if (bootblock_buf[0x000] == 'E' && bootblock_buf[0x001] == 'R' &&
704                bootblock_buf[0x200] == 'P' && bootblock_buf[0x201] == 'M') {
705                    /*  We can't load a kernel if the name
706                        isn't specified.  */
707                    if (cpu->machine->boot_kernel_filename == NULL ||
708                        cpu->machine->boot_kernel_filename[0] == '\0')
709                            fatal("\nApple partition table, but no kernel "
710                                "specified? (Use the -j option.)\n");
711                    else
712                            retval = apple_load_bootblock(m, cpu, boot_disk_id,
713                                boot_disk_type, n_loadp, load_namesp);
714            }
715    
716    ret_ok:
717            free(bootblock_buf);
718            return retval;
719  }  }
720    
721    
# Line 295  struct emul *emul_new(char *name) Line 737  struct emul *emul_new(char *name)
737    
738          /*  Sane default values:  */          /*  Sane default values:  */
739          e->n_machines = 0;          e->n_machines = 0;
740            e->next_serial_nr = 1;
741    
742          if (name != NULL) {          if (name != NULL) {
743                  e->name = strdup(name);                  e->name = strdup(name);
# Line 357  static void add_arc_components(struct ma Line 800  static void add_arc_components(struct ma
800    
801          len += 1048576 * m->memory_offset_in_mb;          len += 1048576 * m->memory_offset_in_mb;
802    
803          /*  NOTE/TODO: magic 12MB end of load program area  */          /*
804             *  NOTE/TODO: magic 12MB end of load program area
805             *
806             *  Hm. This breaks the old FreeBSD/MIPS snapshots...
807             */
808    #if 0
809          arcbios_add_memory_descriptor(cpu,          arcbios_add_memory_descriptor(cpu,
810              0x60000 + m->memory_offset_in_mb * 1048576,              0x60000 + m->memory_offset_in_mb * 1048576,
811              start-0x60000 - m->memory_offset_in_mb * 1048576,              start-0x60000 - m->memory_offset_in_mb * 1048576,
812              ARCBIOS_MEM_FreeMemory);              ARCBIOS_MEM_FreeMemory);
813    #endif
814          arcbios_add_memory_descriptor(cpu,          arcbios_add_memory_descriptor(cpu,
815              start, len, ARCBIOS_MEM_LoadedProgram);              start, len, ARCBIOS_MEM_LoadedProgram);
816    
817          scsicontroller = arcbios_get_scsicontroller();          scsicontroller = arcbios_get_scsicontroller(m);
818          if (scsicontroller == 0)          if (scsicontroller == 0)
819                  return;                  return;
820    
# Line 413  static void add_arc_components(struct ma Line 862  static void add_arc_components(struct ma
862                                  snprintf(component_string,                                  snprintf(component_string,
863                                      sizeof(component_string),                                      sizeof(component_string),
864                                      "scsi(0)cdrom(%i)", d->id);                                      "scsi(0)cdrom(%i)", d->id);
865                                  arcbios_add_string_to_component(                                  arcbios_add_string_to_component(m,
866                                      component_string, scsidevice);                                      component_string, scsidevice);
867    
868                                  snprintf(component_string,                                  snprintf(component_string,
869                                      sizeof(component_string),                                      sizeof(component_string),
870                                      "scsi(0)cdrom(%i)fdisk(0)", d->id);                                      "scsi(0)cdrom(%i)fdisk(0)", d->id);
871                                  arcbios_add_string_to_component(                                  arcbios_add_string_to_component(m,
872                                      component_string, scsidisk);                                      component_string, scsidisk);
873                          } else {                          } else {
874                                  snprintf(component_string,                                  snprintf(component_string,
875                                      sizeof(component_string),                                      sizeof(component_string),
876                                      "scsi(0)disk(%i)", d->id);                                      "scsi(0)disk(%i)", d->id);
877                                  arcbios_add_string_to_component(                                  arcbios_add_string_to_component(m,
878                                      component_string, scsidevice);                                      component_string, scsidevice);
879    
880                                  snprintf(component_string,                                  snprintf(component_string,
881                                      sizeof(component_string),                                      sizeof(component_string),
882                                      "scsi(0)disk(%i)rdisk(0)", d->id);                                      "scsi(0)disk(%i)rdisk(0)", d->id);
883                                  arcbios_add_string_to_component(                                  arcbios_add_string_to_component(m,
884                                      component_string, scsidisk);                                      component_string, scsidisk);
885                          }                          }
886                  }                  }
# Line 457  void emul_machine_setup(struct machine * Line 906  void emul_machine_setup(struct machine *
906          struct emul *emul;          struct emul *emul;
907          struct cpu *cpu;          struct cpu *cpu;
908          int i, iadd=4;          int i, iadd=4;
909          uint64_t addr, memory_amount, entrypoint = 0, gp = 0, toc = 0;          uint64_t memory_amount, entrypoint = 0, gp = 0, toc = 0;
910          int byte_order;          int byte_order;
911    
912          emul = m->emul;          emul = m->emul;
# Line 482  void emul_machine_setup(struct machine * Line 931  void emul_machine_setup(struct machine *
931    
932          m->cpu_family = cpu_family_ptr_by_number(m->arch);          m->cpu_family = cpu_family_ptr_by_number(m->arch);
933    
934            if (m->arch == ARCH_ALPHA)
935                    m->arch_pagesize = 8192;
936    
937            if (m->arch != ARCH_MIPS)
938                    m->bintrans_enable = 0;
939    
940          machine_memsize_fix(m);          machine_memsize_fix(m);
941    
942          /*          /*
# Line 502  void emul_machine_setup(struct machine * Line 957  void emul_machine_setup(struct machine *
957                  debug(" (offset by %iMB)", m->memory_offset_in_mb);                  debug(" (offset by %iMB)", m->memory_offset_in_mb);
958                  memory_amount += 1048576 * m->memory_offset_in_mb;                  memory_amount += 1048576 * m->memory_offset_in_mb;
959          }          }
960          m->memory = memory_new(memory_amount);          m->memory = memory_new(memory_amount, m->arch);
961          if (m->machine_type != MACHINE_USERLAND)          if (m->machine_type != MACHINE_USERLAND)
962                  debug("\n");                  debug("\n");
963    
# Line 544  void emul_machine_setup(struct machine * Line 999  void emul_machine_setup(struct machine *
999          }          }
1000          debug("\n");          debug("\n");
1001    
1002    #if 0
1003            /*  Special case: The Playstation Portable has an additional CPU:  */
1004            if (m->machine_type == MACHINE_PSP) {
1005                    debug("cpu%i: ", m->ncpus);
1006                    m->cpus[m->ncpus] = cpu_new(m->memory, m,
1007                        0  /*  use 0 here to show info with debug()  */,
1008                        "Allegrex" /*  TODO  */);
1009                    if (m->bintrans_enable)
1010                            bintrans_init_cpu(m->cpus[m->ncpus]);
1011                    debug("\n");
1012                    m->ncpus ++;
1013            }
1014    #endif
1015    
1016          if (m->use_random_bootstrap_cpu)          if (m->use_random_bootstrap_cpu)
1017                  m->bootstrap_cpu = random() % m->ncpus;                  m->bootstrap_cpu = random() % m->ncpus;
1018          else          else
# Line 555  void emul_machine_setup(struct machine * Line 1024  void emul_machine_setup(struct machine *
1024          if (m->userland_emul != NULL) {          if (m->userland_emul != NULL) {
1025                  useremul_name_to_useremul(cpu,                  useremul_name_to_useremul(cpu,
1026                      m->userland_emul, NULL, NULL, NULL);                      m->userland_emul, NULL, NULL, NULL);
1027                  cpu->memory_rw = userland_memory_rw;  
1028                    switch (m->arch) {
1029    #ifdef ENABLE_ALPHA
1030                    case ARCH_ALPHA:
1031                            cpu->memory_rw = alpha_userland_memory_rw;
1032                            break;
1033    #endif
1034                    default:cpu->memory_rw = userland_memory_rw;
1035                    }
1036          }          }
1037    
1038          if (m->use_x11)          if (m->use_x11)
1039                  x11_init(m);                  x11_init(m);
1040    
1041          /*  Fill memory with random bytes:  */          /*  Fill memory with random bytes:  */
         /*  TODO: This is MIPS-specific!  */  
1042          if (m->random_mem_contents) {          if (m->random_mem_contents) {
1043                  for (i=0; i<m->physical_ram_in_mb * 1048576; i+=256) {                  for (i=0; i<m->physical_ram_in_mb * 1048576; i+=256) {
1044                          unsigned char data[256];                          unsigned char data[256];
1045                          unsigned int j;                          unsigned int j;
1046                          for (j=0; j<sizeof(data); j++)                          for (j=0; j<sizeof(data); j++)
1047                                  data[j] = random() & 255;                                  data[j] = random() & 255;
1048                          addr = 0xffffffff80000000ULL + i;                          cpu->memory_rw(cpu, m->memory, i, data, sizeof(data),
1049                          cpu->memory_rw(cpu, m->memory, addr, data, sizeof(data),                              MEM_WRITE, CACHE_NONE | NO_EXCEPTIONS | PHYSICAL);
                             MEM_WRITE, CACHE_NONE | NO_EXCEPTIONS);  
1050                  }                  }
1051          }          }
1052    
         if ((m->machine_type == MACHINE_ARC ||  
             m->machine_type == MACHINE_SGI) && m->prom_emulation)  
                 arcbios_init();  
   
1053          if (m->userland_emul != NULL) {          if (m->userland_emul != NULL) {
1054                  /*                  /*
1055                   *  For userland-only emulation, no machine emulation                   *  For userland-only emulation, no machine emulation
# Line 595  void emul_machine_setup(struct machine * Line 1066  void emul_machine_setup(struct machine *
1066    
1067          /*  Load files (ROM code, boot code, ...) into memory:  */          /*  Load files (ROM code, boot code, ...) into memory:  */
1068          if (n_load == 0) {          if (n_load == 0) {
1069                  if (m->first_diskimage != NULL)                  if (m->first_diskimage != NULL) {
1070                          load_bootblock(m, cpu);                          if (!load_bootblock(m, cpu, &n_load, &load_names)) {
1071                  else {                                  fprintf(stderr, "\nNo executable files were"
1072                                        " specified, and booting directly from disk"
1073                                        " failed.\n");
1074                                    exit(1);
1075                            }
1076                    } else {
1077                          fprintf(stderr, "No executable file(s) loaded, and "                          fprintf(stderr, "No executable file(s) loaded, and "
1078                              "we are not booting directly from a disk image."                              "we are not booting directly from a disk image."
1079                              "\nAborting.\n");                              "\nAborting.\n");
# Line 606  void emul_machine_setup(struct machine * Line 1082  void emul_machine_setup(struct machine *
1082          }          }
1083    
1084          while (n_load > 0) {          while (n_load > 0) {
1085                    FILE *tmp_f;
1086                    char *name_to_load = *load_names;
1087                    int remove_after_load = 0;
1088    
1089                    /*  Special hack for removing temporary files:  */
1090                    if (name_to_load[0] == 8) {
1091                            name_to_load ++;
1092                            remove_after_load = 1;
1093                    }
1094    
1095                    /*
1096                     *  gzipped files are automagically gunzipped:
1097                     *  NOTE/TODO: This isn't secure. system() is used.
1098                     */
1099                    tmp_f = fopen(name_to_load, "r");
1100                    if (tmp_f != NULL) {
1101                            unsigned char buf[2];           /*  gzip header  */
1102                            memset(buf, 0, sizeof(buf));
1103                            fread(buf, 1, sizeof(buf), tmp_f);
1104                            if (buf[0]==0x1f && buf[1]==0x8b) {
1105                                    size_t zzlen = strlen(name_to_load)*2 + 100;
1106                                    char *zz = malloc(zzlen);
1107                                    debug("gunziping %s\n", name_to_load);
1108                                    /*
1109                                     *  gzip header found.  If this was a file
1110                                     *  extracted from, say, a CDROM image, then it
1111                                     *  already has a temporary name. Otherwise we
1112                                     *  have to gunzip into a temporary file.
1113                                     */
1114                                    if (remove_after_load) {
1115                                            snprintf(zz, zzlen, "mv %s %s.gz",
1116                                                name_to_load, name_to_load);
1117                                            system(zz);
1118                                            snprintf(zz, zzlen, "gunzip %s.gz",
1119                                                name_to_load);
1120                                            system(zz);
1121                                    } else {
1122                                            /*  gunzip into new temp file:  */
1123                                            int tmpfile_handle;
1124                                            char *new_temp_name =
1125                                                strdup("/tmp/gxemul.XXXXXXXXXXXX");
1126                                            tmpfile_handle = mkstemp(new_temp_name);
1127                                            close(tmpfile_handle);
1128                                            snprintf(zz, zzlen, "gunzip -c '%s' > "
1129                                                "%s", name_to_load, new_temp_name);
1130                                            system(zz);
1131                                            name_to_load = new_temp_name;
1132                                            remove_after_load = 1;
1133                                    }
1134                                    free(zz);
1135                            }
1136                            fclose(tmp_f);
1137                    }
1138    
1139                    /*
1140                     *  Ugly (but usable) hack for Playstation Portable:  If the
1141                     *  filename ends with ".pbp" and the file contains an ELF
1142                     *  header, then extract the ELF file into a temporary file.
1143                     */
1144                    if (strlen(name_to_load) > 4 && strcasecmp(name_to_load +
1145                        strlen(name_to_load) - 4, ".pbp") == 0 &&
1146                        (tmp_f = fopen(name_to_load, "r")) != NULL) {
1147                            off_t filesize, j, found=0;
1148                            unsigned char *buf;
1149                            fseek(tmp_f, 0, SEEK_END);
1150                            filesize = ftello(tmp_f);
1151                            fseek(tmp_f, 0, SEEK_SET);
1152                            buf = malloc(filesize);
1153                            if (buf == NULL) {
1154                                    fprintf(stderr, "out of memory while trying"
1155                                        " to read %s\n", name_to_load);
1156                                    exit(1);
1157                            }
1158                            fread(buf, 1, filesize, tmp_f);
1159                            fclose(tmp_f);
1160                            /*  Search for the ELF header, from offset 1 (!):  */
1161                            for (j=1; j<filesize - 4; j++)
1162                                    if (memcmp(buf + j, ELFMAG, SELFMAG) == 0) {
1163                                            found = j;
1164                                            break;
1165                                    }
1166                            if (found != 0) {
1167                                    int tmpfile_handle;
1168                                    char *new_temp_name =
1169                                        strdup("/tmp/gxemul.XXXXXXXXXXXX");
1170                                    debug("extracting ELF from %s (offset 0x%x)\n",
1171                                        name_to_load, (int)found);
1172                                    tmpfile_handle = mkstemp(new_temp_name);
1173                                    write(tmpfile_handle, buf + found,
1174                                        filesize - found);
1175                                    close(tmpfile_handle);
1176                                    name_to_load = new_temp_name;
1177                                    remove_after_load = 1;
1178                            }
1179                    }
1180    
1181                    /*  Special things required _before_ loading the file:  */
1182                    switch (m->arch) {
1183                    case ARCH_X86:
1184                            /*
1185                             *  X86 machines normally don't need to load any files,
1186                             *  they can boot from disk directly. Therefore, an x86
1187                             *  machine usually boots up in 16-bit real mode. When
1188                             *  loading a 32-bit (or even 64-bit) ELF, that's not
1189                             *  very nice, hence this special case.
1190                             */
1191                            pc_bios_simple_pmode_setup(cpu);
1192                            break;
1193                    }
1194    
1195                  byte_order = NO_BYTE_ORDER_OVERRIDE;                  byte_order = NO_BYTE_ORDER_OVERRIDE;
1196    
1197                  file_load(m, m->memory, *load_names, &entrypoint,                  /*
1198                     *  Load the file:  :-)
1199                     */
1200                    file_load(m, m->memory, name_to_load, &entrypoint,
1201                      m->arch, &gp, &byte_order, &toc);                      m->arch, &gp, &byte_order, &toc);
1202    
1203                    if (remove_after_load) {
1204                            debug("removing %s\n", name_to_load);
1205                            unlink(name_to_load);
1206                    }
1207    
1208                  if (byte_order != NO_BYTE_ORDER_OVERRIDE)                  if (byte_order != NO_BYTE_ORDER_OVERRIDE)
1209                          cpu->byte_order = byte_order;                          cpu->byte_order = byte_order;
1210    
1211                  cpu->pc = entrypoint;                  cpu->pc = entrypoint;
1212    
1213                  switch (m->arch) {                  switch (m->arch) {
1214    
1215                    case ARCH_ALPHA:
1216                            /*  For position-independent code:  */
1217                            cpu->cd.alpha.r[ALPHA_T12] = cpu->pc;
1218                            break;
1219    
1220                    case ARCH_ARM:
1221                            if (cpu->pc & 3) {
1222                                    fatal("ARM: lowest bits of pc set: TODO\n");
1223                                    exit(1);
1224                            }
1225                            cpu->pc &= 0xfffffffc;
1226                            break;
1227    
1228                    case ARCH_AVR:
1229                            cpu->pc &= 0xfffff;
1230                            if (cpu->pc & 1) {
1231                                    fatal("AVR: lowest bit of pc set: TODO\n");
1232                                    exit(1);
1233                            }
1234                            break;
1235    
1236                    case ARCH_HPPA:
1237                            break;
1238    
1239                    case ARCH_I960:
1240                            break;
1241    
1242                    case ARCH_IA64:
1243                            break;
1244    
1245                    case ARCH_M68K:
1246                            break;
1247    
1248                  case ARCH_MIPS:                  case ARCH_MIPS:
1249                          if ((cpu->pc >> 32) == 0                          if ((cpu->pc >> 32) == 0 && (cpu->pc & 0x80000000ULL))
                             && (cpu->pc & 0x80000000ULL))  
1250                                  cpu->pc |= 0xffffffff00000000ULL;                                  cpu->pc |= 0xffffffff00000000ULL;
1251    
1252                          cpu->cd.mips.gpr[MIPS_GPR_GP] = gp;                          cpu->cd.mips.gpr[MIPS_GPR_GP] = gp;
# Line 631  void emul_machine_setup(struct machine * Line 1258  void emul_machine_setup(struct machine *
1258                          break;                          break;
1259    
1260                  case ARCH_PPC:                  case ARCH_PPC:
1261                            /*  See http://www.linuxbase.org/spec/ELF/ppc64/
1262                                spec/x458.html for more info.  */
1263                          cpu->cd.ppc.gpr[2] = toc;                          cpu->cd.ppc.gpr[2] = toc;
1264                            /*  TODO  */
1265                            if (cpu->cd.ppc.bits == 32)
1266                                    cpu->pc &= 0xffffffffULL;
1267                            break;
1268    
1269                    case ARCH_SH:
1270                            if (cpu->cd.sh.bits == 32)
1271                                    cpu->pc &= 0xffffffffULL;
1272                            cpu->pc &= ~1;
1273                          break;                          break;
1274    
                 case ARCH_ALPHA:  
                 case ARCH_HPPA:  
1275                  case ARCH_SPARC:                  case ARCH_SPARC:
                 case ARCH_URISC:  
1276                          break;                          break;
1277    
1278                  case ARCH_X86:                  case ARCH_X86:
1279                          /*                          /*
1280                           *  NOTE: The toc field is used to indicate an ELF64                           *  NOTE: The toc field is used to indicate an ELF32
1281                           *  load, on AMD64!                           *  or ELF64 load.
1282                           */                           */
1283                          if (toc != 0) {                          switch (toc) {
1284                                  cpu->cd.x86.mode = 64;                          case 0: /*  16-bit? TODO  */
1285                          } else                                  cpu->pc &= 0xffffffffULL;
1286                                    break;
1287                            case 1: /*  32-bit.  */
1288                                  cpu->pc &= 0xffffffffULL;                                  cpu->pc &= 0xffffffffULL;
1289                                    break;
1290                            case 2: /*  64-bit:  TODO  */
1291                                    fatal("64-bit x86 load. TODO\n");
1292                                    exit(1);
1293                            }
1294                          break;                          break;
1295    
1296                  default:                  default:
# Line 702  void emul_machine_setup(struct machine * Line 1344  void emul_machine_setup(struct machine *
1344          if (m->machine_type == MACHINE_DEC &&          if (m->machine_type == MACHINE_DEC &&
1345              cpu->cd.mips.cpu_type.mmu_model == MMU3K)              cpu->cd.mips.cpu_type.mmu_model == MMU3K)
1346                  add_symbol_name(&m->symbol_context,                  add_symbol_name(&m->symbol_context,
1347                      0x9fff0000, 0x10000, "r2k3k_cache", 0);                      0x9fff0000, 0x10000, "r2k3k_cache", 0, 0);
1348    
1349          symbol_recalc_sizes(&m->symbol_context);          symbol_recalc_sizes(&m->symbol_context);
1350    
# Line 715  void emul_machine_setup(struct machine * Line 1357  void emul_machine_setup(struct machine *
1357              m->machine_type == MACHINE_SGI) && m->prom_emulation)              m->machine_type == MACHINE_SGI) && m->prom_emulation)
1358                  add_arc_components(m);                  add_arc_components(m);
1359    
1360    
1361    #if 0
1362    if (m->machine_type == MACHINE_IQ80321) {
1363            store_32bit_word(cpu, 0xc0200000, 0);
1364            store_32bit_word(cpu, 0xc0200004, 0xd0000000);
1365    }
1366    #endif
1367    
1368    
1369          debug("starting cpu%i at ", m->bootstrap_cpu);          debug("starting cpu%i at ", m->bootstrap_cpu);
1370          switch (m->arch) {          switch (m->arch) {
1371    
1372            case ARCH_ARM:
1373                    /*  ARM cpus aren't 64-bit:  */
1374                    debug("0x%08x", (int)entrypoint);
1375                    break;
1376    
1377            case ARCH_AVR:
1378                    /*  Atmel AVR uses a 16-bit or 22-bit program counter:  */
1379                    debug("0x%04x", (int)entrypoint);
1380                    break;
1381    
1382          case ARCH_MIPS:          case ARCH_MIPS:
1383                  if (cpu->cd.mips.cpu_type.isa_level < 3 ||                  if (cpu->is_32bit) {
                     cpu->cd.mips.cpu_type.isa_level == 32) {  
1384                          debug("0x%08x", (int)m->cpus[                          debug("0x%08x", (int)m->cpus[
1385                              m->bootstrap_cpu]->pc);                              m->bootstrap_cpu]->pc);
1386                          if (cpu->cd.mips.gpr[MIPS_GPR_GP] != 0)                          if (cpu->cd.mips.gpr[MIPS_GPR_GP] != 0)
# Line 734  void emul_machine_setup(struct machine * Line 1395  void emul_machine_setup(struct machine *
1395                                      cpu->cd.mips.gpr[MIPS_GPR_GP]);                                      cpu->cd.mips.gpr[MIPS_GPR_GP]);
1396                  }                  }
1397                  break;                  break;
1398    
1399          case ARCH_PPC:          case ARCH_PPC:
1400                  if (cpu->cd.ppc.bits == 32)                  if (cpu->cd.ppc.bits == 32)
1401                          debug("0x%08x", (int)entrypoint);                          debug("0x%08x", (int)entrypoint);
1402                  else                  else
1403                          debug("0x%016llx", (long long)entrypoint);                          debug("0x%016llx", (long long)entrypoint);
1404                  break;                  break;
1405          case ARCH_URISC:  
                 {  
                         char tmps[100];  
                         unsigned char buf[sizeof(uint64_t)];  
   
                         cpu->memory_rw(cpu, m->memory, 0, buf, sizeof(buf),  
                             MEM_READ, CACHE_NONE | NO_EXCEPTIONS);  
   
                         entrypoint = 0;  
                         for (i=0; i<cpu->cd.urisc.wordlen/8; i++) {  
                                 entrypoint <<= 8;  
                                 if (cpu->byte_order == EMUL_BIG_ENDIAN)  
                                         entrypoint += buf[i];  
                                 else  
                                         entrypoint += buf[cpu->  
                                             cd.urisc.wordlen/8 - 1 - i];  
                         }  
   
                         sprintf(tmps, "0x%%0%illx", cpu->cd.urisc.wordlen / 4);  
                         debug(tmps, (long long)entrypoint);  
                         cpu->pc = entrypoint;  
                 }  
                 break;  
1406          case ARCH_X86:          case ARCH_X86:
1407                  if (cpu->cd.x86.mode == 16)                  debug("0x%04x:0x%llx", cpu->cd.x86.s[X86_S_CS],
1408                          debug("0x%04x:0x%04x", cpu->cd.x86.s[X86_S_CS],                      (long long)cpu->pc);
                             (int)cpu->pc);  
                 else if (cpu->cd.x86.mode == 32)  
                         debug("0x%08x", (int)cpu->pc);  
                 else  
                         debug("0x%016llx", (long long)cpu->pc);  
1409                  break;                  break;
1410    
1411          default:          default:
1412                  debug("0x%016llx", (long long)cpu->pc);                  debug("0x%016llx", (long long)cpu->pc);
1413          }          }
# Line 831  void emul_simple_init(struct emul *emul) Line 1467  void emul_simple_init(struct emul *emul)
1467                  debug("Simple setup...\n");                  debug("Simple setup...\n");
1468                  debug_indentation(iadd);                  debug_indentation(iadd);
1469    
1470                  /*  Create a network:  */                  /*  Create a simple network:  */
1471                  emul->net = net_init(emul, NET_INIT_FLAG_GATEWAY,                  emul->net = net_init(emul, NET_INIT_FLAG_GATEWAY,
1472                      "10.0.0.0", 8);                      "10.0.0.0", 8, NULL, 0, 0);
1473          } else {          } else {
1474                  /*  Userland pseudo-machine:  */                  /*  Userland pseudo-machine:  */
1475                  debug("Syscall emulation (userland-only) setup...\n");                  debug("Syscall emulation (userland-only) setup...\n");
# Line 940  void emul_run(struct emul **emuls, int n Line 1576  void emul_run(struct emul **emuls, int n
1576                  if (e == NULL)                  if (e == NULL)
1577                          continue;                          continue;
1578                  for (j=0; j<e->n_machines; j++)                  for (j=0; j<e->n_machines; j++)
1579                          cpu_run_init(e, e->machines[j]);                          cpu_run_init(e->machines[j]);
1580          }          }
1581    
1582            /*  TODO: Generalize:  */
1583            if (emuls[0]->machines[0]->show_trace_tree)
1584                    cpu_functioncall_trace(emuls[0]->machines[0]->cpus[0],
1585                        emuls[0]->machines[0]->cpus[0]->pc);
1586    
1587          /*          /*
1588           *  MAIN LOOP:           *  MAIN LOOP:
1589           *           *
# Line 975  void emul_run(struct emul **emuls, int n Line 1616  void emul_run(struct emul **emuls, int n
1616                  if (e == NULL)                  if (e == NULL)
1617                          continue;                          continue;
1618                  for (j=0; j<e->n_machines; j++)                  for (j=0; j<e->n_machines; j++)
1619                          cpu_run_deinit(e, e->machines[j]);                          cpu_run_deinit(e->machines[j]);
1620          }          }
1621    
1622          /*  force_debugger_at_exit flag set? Then enter the debugger:  */          /*  force_debugger_at_exit flag set? Then enter the debugger:  */

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

  ViewVC Help
Powered by ViewVC 1.1.26