/[gxemul]/trunk/src/machine.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/machine.c

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

revision 28 by dpavlin, Mon Oct 8 16:20:26 2007 UTC revision 34 by dpavlin, Mon Oct 8 16:21:17 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2003-2006  Anders Gavare.  All rights reserved.   *  Copyright (C) 2003-2007  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: machine.c,v 1.679 2006/07/16 13:32:25 debug Exp $   *  $Id: machine.c,v 1.693 2007/01/28 14:15:29 debug Exp $
29   */   */
30    
31  #include <stdio.h>  #include <stdio.h>
# Line 45  Line 45 
45  #include "diskimage.h"  #include "diskimage.h"
46  #include "emul.h"  #include "emul.h"
47  #include "machine.h"  #include "machine.h"
 #include "machine_interrupts.h"  
48  #include "memory.h"  #include "memory.h"
49  #include "misc.h"  #include "misc.h"
50  #include "net.h"  #include "net.h"
51    #include "settings.h"
52  #include "symbol.h"  #include "symbol.h"
53    
54    
# Line 66  struct machine_entry *first_machine_entr Line 66  struct machine_entry *first_machine_entr
66   *   *
67   *  Returns a reasonably initialized struct machine.   *  Returns a reasonably initialized struct machine.
68   */   */
69  struct machine *machine_new(char *name, struct emul *emul)  struct machine *machine_new(char *name, struct emul *emul, int id)
70  {  {
71          struct machine *m;          struct machine *m;
72          m = malloc(sizeof(struct machine));          m = malloc(sizeof(struct machine));
# Line 77  struct machine *machine_new(char *name, Line 77  struct machine *machine_new(char *name,
77    
78          memset(m, 0, sizeof(struct machine));          memset(m, 0, sizeof(struct machine));
79    
80          /*  Back pointer:  */          /*  Pointer back to the emul object that this machine belongs to:  */
81          m->emul = emul;          m->emul = emul;
82    
83          m->name = strdup(name);          m->name = strdup(name);
84    
85            /*  Full path, e.g. "emul[0].machine[0]":  */
86            m->path = malloc(strlen(emul->path) + 20);
87            if (m->path == NULL) {
88                    fprintf(stderr, "out of memory\n");
89                    exit(1);
90            }
91            snprintf(m->path, strlen(emul->path) + 20, "%s.machine[%i]",
92                emul->path, id);
93    
94          /*  Sane default values:  */          /*  Sane default values:  */
95          m->serial_nr = 1;          m->serial_nr = 1;
96          m->machine_type = MACHINE_NONE;          m->machine_type = MACHINE_NONE;
# Line 93  struct machine *machine_new(char *name, Line 102  struct machine *machine_new(char *name,
102          m->byte_order_override = NO_BYTE_ORDER_OVERRIDE;          m->byte_order_override = NO_BYTE_ORDER_OVERRIDE;
103          m->boot_kernel_filename = "";          m->boot_kernel_filename = "";
104          m->boot_string_argument = NULL;          m->boot_string_argument = NULL;
         m->automatic_clock_adjustment = 1;  
105          m->x11_scaledown = 1;          m->x11_scaledown = 1;
106          m->x11_scaleup = 1;          m->x11_scaleup = 1;
107          m->n_gfx_cards = 1;          m->n_gfx_cards = 1;
# Line 101  struct machine *machine_new(char *name, Line 109  struct machine *machine_new(char *name,
109          m->show_symbolic_register_names = 1;          m->show_symbolic_register_names = 1;
110          symbol_init(&m->symbol_context);          symbol_init(&m->symbol_context);
111    
112            /*  Settings:  */
113            m->settings = settings_new();
114            settings_add(m->settings, "name", 0,
115                SETTINGS_TYPE_STRING, SETTINGS_FORMAT_STRING,
116                (void *) &m->name);
117            settings_add(m->settings, "serial_nr", 0,
118                SETTINGS_TYPE_INT, SETTINGS_FORMAT_DECIMAL,
119                (void *) &m->serial_nr);
120            settings_add(m->settings, "arch_pagesize", 0,
121                SETTINGS_TYPE_INT, SETTINGS_FORMAT_DECIMAL,
122                (void *) &m->arch_pagesize);
123            settings_add(m->settings, "prom_emulation", 0,
124                SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO,
125                (void *) &m->prom_emulation);
126            settings_add(m->settings, "allow_instruction_combinations", 0,
127                SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO,
128                (void *) &m->allow_instruction_combinations);
129            settings_add(m->settings, "n_gfx_cards", 0,
130                SETTINGS_TYPE_INT, SETTINGS_FORMAT_DECIMAL,
131                (void *) &m->n_gfx_cards);
132            settings_add(m->settings, "show_symbolic_register_names", 1,
133                SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO,
134                (void *) &m->show_symbolic_register_names);
135            settings_add(m->settings, "statistics_enabled", 1,
136                SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO,
137                (void *) &m->statistics_enabled);
138    
139          return m;          return m;
140  }  }
141    
142    
143  /*  /*
144     *  machine_destroy():
145     *
146     *  Destroys a machine object.
147     */
148    void machine_destroy(struct machine *machine)
149    {
150            int i;
151    
152            for (i=0; i<machine->ncpus; i++)
153                    cpu_destroy(machine->cpus[i]);
154    
155            if (machine->name != NULL)
156                    free(machine->name);
157    
158            if (machine->path != NULL)
159                    free(machine->path);
160    
161            /*  Remove any remaining level-1 settings:  */
162            settings_remove_all(machine->settings);
163            settings_destroy(machine->settings);
164    
165            free(machine);
166    }
167    
168    
169    /*
170   *  machine_name_to_type():   *  machine_name_to_type():
171   *   *
172   *  Take a type and a subtype as strings, and convert them into numeric   *  Take a type and a subtype as strings, and convert them into numeric
# Line 230  void machine_add_tickfunction(struct mac Line 291  void machine_add_tickfunction(struct mac
291          if (!machine->cycle_accurate) {          if (!machine->cycle_accurate) {
292                  /*                  /*
293                   *  The dyntrans subsystem wants to run code in relatively                   *  The dyntrans subsystem wants to run code in relatively
294                   *  large chunks without checking for external interrupts,                   *  large chunks without checking for external interrupts;
295                   *  so we cannot allow too low tickshifts:                   *  too low tickshifts are not allowed.
296                   */                   */
297                  if (tickshift < N_SAFE_DYNTRANS_LIMIT_SHIFT) {                  if (tickshift < N_SAFE_DYNTRANS_LIMIT_SHIFT) {
298                          fatal("ERROR! tickshift = %i, less than "                          fatal("ERROR! tickshift = %i, less than "
# Line 325  void machine_statistics_init(struct mach Line 386  void machine_statistics_init(struct mach
386    
387    
388  /*  /*
  *  machine_bus_register():  
  *  
  *  Registers a bus in a machine.  
  */  
 void machine_bus_register(struct machine *machine, char *busname,  
         void (*debug_dump)(void *), void *extra)  
 {  
         struct machine_bus *tmp, *last = NULL, *new;  
   
         new = zeroed_alloc(sizeof(struct machine_bus));  
         new->name = strdup(busname);  
         new->debug_dump = debug_dump;  
         new->extra = extra;  
   
         /*  Register last in the bus list:  */  
         tmp = machine->first_bus;  
         while (tmp != NULL) {  
                 last = tmp;  
                 tmp = tmp->next;  
         }  
   
         if (last == NULL)  
                 machine->first_bus = new;  
         else  
                 last->next = new;  
   
         machine->n_busses ++;  
 }  
   
   
 /*  
  *  machine_dump_bus_info():  
  *  
  *  Dumps info about registered busses.  
  */  
 void machine_dump_bus_info(struct machine *m)  
 {  
         struct machine_bus *bus = m->first_bus;  
         int iadd = DEBUG_INDENTATION;  
   
         if (m->n_busses > 0)  
                 debug("busses:\n");  
         debug_indentation(iadd);  
         while (bus != NULL) {  
                 bus->debug_dump(bus->extra);  
                 bus = bus->next;  
         }  
         debug_indentation(-iadd);  
 }  
   
   
 /*  
389   *  machine_dumpinfo():   *  machine_dumpinfo():
390   *   *
391   *  Dumps info about a machine in some kind of readable format. (Used by   *  Dumps info about a machine in some kind of readable format. (Used by
# Line 400  void machine_dumpinfo(struct machine *m) Line 409  void machine_dumpinfo(struct machine *m)
409                  debug(", dbe_on_nonexistant_memaccess");                  debug(", dbe_on_nonexistant_memaccess");
410          debug("\n");          debug("\n");
411    
         debug("clock: ");  
         if (m->automatic_clock_adjustment)  
                 debug("adjusted automatically");  
         else  
                 debug("fixed at %i Hz", m->emulated_hz);  
         debug("\n");  
   
412          if (!m->prom_emulation)          if (!m->prom_emulation)
413                  debug("PROM emulation disabled\n");                  debug("PROM emulation disabled\n");
414    
# Line 435  void machine_dumpinfo(struct machine *m) Line 437  void machine_dumpinfo(struct machine *m)
437                  debug("\n");                  debug("\n");
438          }          }
439    
         machine_dump_bus_info(m);  
   
440          diskimage_dump_info(m);          diskimage_dump_info(m);
441    
442          if (m->force_netboot)          if (m->force_netboot)
# Line 583  int store_64bit_word(struct cpu *cpu, ui Line 583  int store_64bit_word(struct cpu *cpu, ui
583  int store_32bit_word(struct cpu *cpu, uint64_t addr, uint64_t data32)  int store_32bit_word(struct cpu *cpu, uint64_t addr, uint64_t data32)
584  {  {
585          unsigned char data[4];          unsigned char data[4];
586    
587            /*  TODO: REMOVE THIS once everything is more stable!  */
588          if (cpu->machine->arch == ARCH_MIPS && (addr >> 32) == 0)          if (cpu->machine->arch == ARCH_MIPS && (addr >> 32) == 0)
589                  addr = (int64_t)(int32_t)addr;                  addr = (int64_t)(int32_t)addr;
590    
591          data[0] = (data32 >> 24) & 255;          data[0] = (data32 >> 24) & 255;
592          data[1] = (data32 >> 16) & 255;          data[1] = (data32 >> 16) & 255;
593          data[2] = (data32 >> 8) & 255;          data[2] = (data32 >> 8) & 255;
# Line 608  int store_32bit_word(struct cpu *cpu, ui Line 611  int store_32bit_word(struct cpu *cpu, ui
611  int store_16bit_word(struct cpu *cpu, uint64_t addr, uint64_t data16)  int store_16bit_word(struct cpu *cpu, uint64_t addr, uint64_t data16)
612  {  {
613          unsigned char data[2];          unsigned char data[2];
614    
615            /*  TODO: REMOVE THIS once everything is more stable!  */
616          if (cpu->machine->arch == ARCH_MIPS && (addr >> 32) == 0)          if (cpu->machine->arch == ARCH_MIPS && (addr >> 32) == 0)
617                  addr = (int64_t)(int32_t)addr;                  addr = (int64_t)(int32_t)addr;
618    
619          data[0] = (data16 >> 8) & 255;          data[0] = (data16 >> 8) & 255;
620          data[1] = (data16) & 255;          data[1] = (data16) & 255;
621          if (cpu->byte_order == EMUL_LITTLE_ENDIAN) {          if (cpu->byte_order == EMUL_LITTLE_ENDIAN) {
# Line 629  void store_buf(struct cpu *cpu, uint64_t Line 635  void store_buf(struct cpu *cpu, uint64_t
635  {  {
636          size_t psize = 1024;    /*  1024 256 64 16 4 1  */          size_t psize = 1024;    /*  1024 256 64 16 4 1  */
637    
638            /*  TODO: REMOVE THIS once everything is more stable!  */
639          if (cpu->machine->arch == ARCH_MIPS && (addr >> 32) == 0)          if (cpu->machine->arch == ARCH_MIPS && (addr >> 32) == 0)
640                  addr = (int64_t)(int32_t)addr;                  addr = (int64_t)(int32_t)addr;
641    
# Line 673  void store_pointer_and_advance(struct cp Line 680  void store_pointer_and_advance(struct cp
680    
681    
682  /*  /*
683     *  load_64bit_word():
684     *
685     *  Helper function. Emulated byte order is taken into account.
686     */
687    uint64_t load_64bit_word(struct cpu *cpu, uint64_t addr)
688    {
689            unsigned char data[8];
690    
691            cpu->memory_rw(cpu, cpu->mem,
692                addr, data, sizeof(data), MEM_READ, CACHE_DATA);
693    
694            if (cpu->byte_order == EMUL_LITTLE_ENDIAN) {
695                    int tmp = data[0]; data[0] = data[7]; data[7] = tmp;
696                    tmp = data[1]; data[1] = data[6]; data[6] = tmp;
697                    tmp = data[2]; data[2] = data[5]; data[5] = tmp;
698                    tmp = data[3]; data[3] = data[4]; data[4] = tmp;
699            }
700    
701            return
702                ((uint64_t)data[0] << 56) + ((uint64_t)data[1] << 48) +
703                ((uint64_t)data[2] << 40) + ((uint64_t)data[3] << 32) +
704                ((uint64_t)data[4] << 24) + ((uint64_t)data[5] << 16) +
705                ((uint64_t)data[6] << 8) + (uint64_t)data[7];
706    }
707    
708    
709    /*
710   *  load_32bit_word():   *  load_32bit_word():
711   *   *
712   *  Helper function.  Prints a warning and returns 0, if the read failed.   *  Helper function. Emulated byte order is taken into account.
  *  Emulated byte order is taken into account.  
713   */   */
714  uint32_t load_32bit_word(struct cpu *cpu, uint64_t addr)  uint32_t load_32bit_word(struct cpu *cpu, uint64_t addr)
715  {  {
716          unsigned char data[4];          unsigned char data[4];
717    
718            /*  TODO: REMOVE THIS once everything is more stable!  */
719          if (cpu->machine->arch == ARCH_MIPS && (addr >> 32) == 0)          if (cpu->machine->arch == ARCH_MIPS && (addr >> 32) == 0)
720                  addr = (int64_t)(int32_t)addr;                  addr = (int64_t)(int32_t)addr;
721    
722          cpu->memory_rw(cpu, cpu->mem,          cpu->memory_rw(cpu, cpu->mem,
723              addr, data, sizeof(data), MEM_READ, CACHE_DATA);              addr, data, sizeof(data), MEM_READ, CACHE_DATA);
724    
# Line 699  uint32_t load_32bit_word(struct cpu *cpu Line 734  uint32_t load_32bit_word(struct cpu *cpu
734  /*  /*
735   *  load_16bit_word():   *  load_16bit_word():
736   *   *
737   *  Helper function.  Prints a warning and returns 0, if the read failed.   *  Helper function. Emulated byte order is taken into account.
  *  Emulated byte order is taken into account.  
738   */   */
739  uint16_t load_16bit_word(struct cpu *cpu, uint64_t addr)  uint16_t load_16bit_word(struct cpu *cpu, uint64_t addr)
740  {  {
741          unsigned char data[2];          unsigned char data[2];
742    
743            /*  TODO: REMOVE THIS once everything is more stable!  */
744          if (cpu->machine->arch == ARCH_MIPS && (addr >> 32) == 0)          if (cpu->machine->arch == ARCH_MIPS && (addr >> 32) == 0)
745                  addr = (int64_t)(int32_t)addr;                  addr = (int64_t)(int32_t)addr;
746    
747          cpu->memory_rw(cpu, cpu->mem,          cpu->memory_rw(cpu, cpu->mem,
748              addr, data, sizeof(data), MEM_READ, CACHE_DATA);              addr, data, sizeof(data), MEM_READ, CACHE_DATA);
749    
# Line 851  void machine_setup(struct machine *machi Line 887  void machine_setup(struct machine *machi
887                  debug(" (%.2f MHz)", (float)machine->emulated_hz / 1000000);                  debug(" (%.2f MHz)", (float)machine->emulated_hz / 1000000);
888          debug("\n");          debug("\n");
889    
         /*  Default fake speed: 5 MHz  */  
         if (machine->emulated_hz < 1)  
                 machine->emulated_hz = 5000000;  
   
890          if (machine->bootstr != NULL) {          if (machine->bootstr != NULL) {
891                  debug("bootstring%s: %s", (machine->bootarg!=NULL &&                  debug("bootstring%s: %s", (machine->bootarg!=NULL &&
892                      strlen(machine->bootarg) >= 1)? "(+bootarg)" : "",                      strlen(machine->bootarg) >= 1)? "(+bootarg)" : "",
# Line 864  void machine_setup(struct machine *machi Line 896  void machine_setup(struct machine *machi
896                  debug("\n");                  debug("\n");
897          }          }
898    
         if (verbose >= 2)  
                 machine_dump_bus_info(machine);  
   
899          if (!machine->stable)          if (!machine->stable)
900                  fatal("!\n!  NOTE: This machine type is not implemented well"                  fatal("!\n!  NOTE: This machine type is not implemented well"
901                      " enough yet to run\n!  any real-world code!"                      " enough yet to run\n!  any real-world code!"

Legend:
Removed from v.28  
changed lines
  Added in v.34

  ViewVC Help
Powered by ViewVC 1.1.26