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

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

revision 12 by dpavlin, Mon Oct 8 16:18:38 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: memory.c,v 1.175 2005/08/14 15:47:36 debug Exp $   *  $Id: memory.c,v 1.182 2005/11/22 16:26:36 debug Exp $
29   *   *
30   *  Functions for handling the memory of an emulated machine.   *  Functions for handling the memory of an emulated machine.
31   */   */
# Line 59  extern volatile int single_step; Line 59  extern volatile int single_step;
59   */   */
60  uint64_t memory_readmax64(struct cpu *cpu, unsigned char *buf, int len)  uint64_t memory_readmax64(struct cpu *cpu, unsigned char *buf, int len)
61  {  {
62          int i;          int i, byte_order = cpu->byte_order;
63          uint64_t x = 0;          uint64_t x = 0;
64    
65            if (len & MEM_PCI_LITTLE_ENDIAN) {
66                    len &= ~MEM_PCI_LITTLE_ENDIAN;
67                    byte_order = EMUL_LITTLE_ENDIAN;
68            }
69    
70          /*  Switch byte order for incoming data, if necessary:  */          /*  Switch byte order for incoming data, if necessary:  */
71          if (cpu->byte_order == EMUL_BIG_ENDIAN)          if (byte_order == EMUL_BIG_ENDIAN)
72                  for (i=0; i<len; i++) {                  for (i=0; i<len; i++) {
73                          x <<= 8;                          x <<= 8;
74                          x |= buf[i];                          x |= buf[i];
# Line 89  uint64_t memory_readmax64(struct cpu *cp Line 94  uint64_t memory_readmax64(struct cpu *cp
94  void memory_writemax64(struct cpu *cpu, unsigned char *buf, int len,  void memory_writemax64(struct cpu *cpu, unsigned char *buf, int len,
95          uint64_t data)          uint64_t data)
96  {  {
97          int i;          int i, byte_order = cpu->byte_order;
98    
99            if (len & MEM_PCI_LITTLE_ENDIAN) {
100                    len &= ~MEM_PCI_LITTLE_ENDIAN;
101                    byte_order = EMUL_LITTLE_ENDIAN;
102            }
103    
104          if (cpu->byte_order == EMUL_LITTLE_ENDIAN)          if (byte_order == EMUL_LITTLE_ENDIAN)
105                  for (i=0; i<len; i++) {                  for (i=0; i<len; i++) {
106                          buf[i] = data & 255;                          buf[i] = data & 255;
107                          data >>= 8;                          data >>= 8;
# Line 290  void memory_device_dyntrans_access(struc Line 300  void memory_device_dyntrans_access(struc
300                          /*  Invalidate any pages of this device that might                          /*  Invalidate any pages of this device that might
301                              be in the dyntrans load/store cache, by marking                              be in the dyntrans load/store cache, by marking
302                              the pages read-only.  */                              the pages read-only.  */
303                          if (cpu->invalidate_translation_caches_paddr != NULL) {                          if (cpu->invalidate_translation_caches != NULL) {
304                                  for (s=0; s<mem->dev_length[i];                                  for (s=0; s<mem->dev_length[i];
305                                      s+=cpu->machine->arch_pagesize)                                      s+=cpu->machine->arch_pagesize)
306                                          cpu->invalidate_translation_caches_paddr                                          cpu->invalidate_translation_caches
307                                              (cpu, mem->dev_baseaddr[i] + s);                                              (cpu, mem->dev_baseaddr[i] + s,
308                                                JUST_MARK_AS_NON_WRITABLE
309                                                | INVALIDATE_PADDR);
310                          }                          }
311    
312                          if (cpu->machine->arch == ARCH_MIPS) {                          if (cpu->machine->arch == ARCH_MIPS) {
# Line 386  void memory_device_register(struct memor Line 398  void memory_device_register(struct memor
398          debug("device %2i at 0x%010llx: %s",          debug("device %2i at 0x%010llx: %s",
399              mem->n_mmapped_devices, (long long)baseaddr, device_name);              mem->n_mmapped_devices, (long long)baseaddr, device_name);
400    
401          if (flags & (MEM_DYNTRANS_OK | MEM_DYNTRANS_WRITE_OK)          if (flags & (DM_DYNTRANS_OK | DM_DYNTRANS_WRITE_OK)
402              && (baseaddr & mem->dev_dyntrans_alignment) != 0) {              && (baseaddr & mem->dev_dyntrans_alignment) != 0) {
403                  fatal("\nWARNING: Device dyntrans access, but unaligned"                  fatal("\nWARNING: Device dyntrans access, but unaligned"
404                      " baseaddr 0x%llx.\n", (long long)baseaddr);                      " baseaddr 0x%llx.\n", (long long)baseaddr);
405          }          }
406    
407          if (flags & (MEM_DYNTRANS_OK | MEM_DYNTRANS_WRITE_OK)) {          if (flags & (DM_DYNTRANS_OK | DM_DYNTRANS_WRITE_OK)) {
408                  debug(" (dyntrans %s)",                  debug(" (dyntrans %s)",
409                      (flags & MEM_DYNTRANS_WRITE_OK)? "R/W" : "R");                      (flags & DM_DYNTRANS_WRITE_OK)? "R/W" : "R");
410          }          }
411          debug("\n");          debug("\n");
412    
413          mem->dev_name[mem->n_mmapped_devices] = strdup(device_name);          mem->dev_name[mem->n_mmapped_devices] = strdup(device_name);
414          mem->dev_baseaddr[mem->n_mmapped_devices] = baseaddr;          mem->dev_baseaddr[mem->n_mmapped_devices] = baseaddr;
415            mem->dev_endaddr[mem->n_mmapped_devices] = baseaddr + len;
416          mem->dev_length[mem->n_mmapped_devices] = len;          mem->dev_length[mem->n_mmapped_devices] = len;
417          mem->dev_flags[mem->n_mmapped_devices] = flags;          mem->dev_flags[mem->n_mmapped_devices] = flags;
418          mem->dev_dyntrans_data[mem->n_mmapped_devices] = dyntrans_data;          mem->dev_dyntrans_data[mem->n_mmapped_devices] = dyntrans_data;
# Line 409  void memory_device_register(struct memor Line 422  void memory_device_register(struct memor
422                  exit(1);                  exit(1);
423          }          }
424    
425          if (flags & (MEM_DYNTRANS_OK | MEM_DYNTRANS_WRITE_OK)          if (flags & (DM_DYNTRANS_OK | DM_DYNTRANS_WRITE_OK)
426              && dyntrans_data == NULL) {              && !(flags & DM_EMULATED_RAM) && dyntrans_data == NULL) {
427                  fatal("\nERROR: Device dyntrans access, but dyntrans_data"                  fatal("\nERROR: Device dyntrans access, but dyntrans_data"
428                      " = NULL!\n");                      " = NULL!\n");
429                  exit(1);                  exit(1);
430          }          }
431    
432          if ((size_t)dyntrans_data & 7) {          if ((size_t)dyntrans_data & (sizeof(void *) - 1)) {
433                  fprintf(stderr, "memory_device_register():"                  fprintf(stderr, "memory_device_register():"
434                      " dyntrans_data not aligned correctly (%p)\n",                      " dyntrans_data not aligned correctly (%p)\n",
435                      dyntrans_data);                      dyntrans_data);

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

  ViewVC Help
Powered by ViewVC 1.1.26