/[dynamips]/upstream/dynamips-0.2.7-RC1/dev_c7200_sram.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 /upstream/dynamips-0.2.7-RC1/dev_c7200_sram.c

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

upstream/dynamips-0.2.6-RC5/dev_c7200_sram.c revision 6 by dpavlin, Sat Oct 6 16:09:07 2007 UTC upstream/dynamips-0.2.7-RC1/dev_c7200_sram.c revision 7 by dpavlin, Sat Oct 6 16:23:47 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   * Cisco 7200 (Predator) simulation platform.   * Cisco router simulation platform.
3   * Copyright (c) 2005,2006 Christophe Fillot (cf@utc.fr)   * Copyright (c) 2005,2006 Christophe Fillot (cf@utc.fr)
4   *   *
5   * Packet SRAM. This is a fast memory zone for packets on NPE150/NPE200.   * Packet SRAM. This is a fast memory zone for packets on NPE150/NPE200.
# Line 11  Line 11 
11  #include <unistd.h>  #include <unistd.h>
12  #include <assert.h>  #include <assert.h>
13    
14  #include "mips64.h"  #include "cpu.h"
15    #include "vm.h"
16  #include "dynamips.h"  #include "dynamips.h"
17  #include "memory.h"  #include "memory.h"
18  #include "device.h"  #include "device.h"
# Line 33  struct sram_data { Line 34  struct sram_data {
34    
35     /* Byte-swapped device */     /* Byte-swapped device */
36     char *bs_dev_name;     char *bs_dev_name;
37     struct vdevice *bs_dev;     vm_obj_t *bs_obj;
38    
39     /* PCI device */     /* PCI device */
40     struct pci_device *pci_dev;     struct pci_device *pci_dev;
# Line 42  struct sram_data { Line 43  struct sram_data {
43     char *filename;     char *filename;
44  };  };
45    
 /*  
  * SRAM byte swapped access.  
  */  
 static void *dev_sram_bs_access(cpu_mips_t *cpu,struct vdevice *dev,  
                                 m_uint32_t offset,u_int op_size,u_int op_type,  
                                 m_uint64_t *data)  
 {  
    void *ptr = (u_char *)dev->host_addr + offset;  
   
    switch(op_size) {  
       case 1:  
          return(ptr);  
   
       case 2:  
          if (op_type == MTS_READ)  
             *data = swap16(htovm16(*(m_uint16_t *)ptr));  
          else  
             *(m_uint16_t *)ptr = vmtoh16(swap16(*data));  
          break;  
   
       case 4:  
          if (op_type == MTS_READ)  
             *data = swap32(htovm32(*(m_uint32_t *)ptr));  
          else  
             *(m_uint32_t *)ptr = vmtoh32(swap32(*data));  
          break;  
   
       case 8:  
          if (op_type == MTS_READ)  
             *data = swap64(htovm64(*(m_uint64_t *)ptr));  
          else  
             *(m_uint64_t *)ptr = vmtoh64(swap64(*data));  
          break;  
    }  
   
    return NULL;  
 }  
   
46  /* Shutdown an SRAM device */  /* Shutdown an SRAM device */
47  void dev_c7200_sram_shutdown(vm_instance_t *vm,struct sram_data *d)  void dev_c7200_sram_shutdown(vm_instance_t *vm,struct sram_data *d)
48  {  {
# Line 87  void dev_c7200_sram_shutdown(vm_instance Line 50  void dev_c7200_sram_shutdown(vm_instance
50        /* Remove the PCI device */        /* Remove the PCI device */
51        pci_dev_remove(d->pci_dev);        pci_dev_remove(d->pci_dev);
52    
53        /* Remove the alias, the byte-swapped and the main device */        /* Remove the byte-swapped device */
54          vm_object_remove(vm,d->bs_obj);
55    
56          /* Remove the alias and the main device */
57        dev_remove(vm,d->alias_dev);        dev_remove(vm,d->alias_dev);
       dev_remove(vm,d->bs_dev);  
58        dev_remove(vm,d->dev);        dev_remove(vm,d->dev);
59    
60        /* Free devices */        /* Free devices */
61        free(d->alias_dev);        free(d->alias_dev);
       free(d->bs_dev);  
62        free(d->dev);        free(d->dev);
63                
64        /* Free device names */        /* Free device names */
# Line 144  int dev_c7200_sram_init(vm_instance_t *v Line 108  int dev_c7200_sram_init(vm_instance_t *v
108     alias_paddr = 0x100000000ULL + paddr;     alias_paddr = 0x100000000ULL + paddr;
109        
110     /* create the standard RAM zone */     /* create the standard RAM zone */
111     if (!(d->dev = dev_create_ram(vm,name,d->filename,paddr,len))) {     if (!(d->dev = dev_create_ram(vm,name,FALSE,d->filename,paddr,len))) {
112        fprintf(stderr,"dev_c7200_sram_init: unable to create '%s' file.\n",        fprintf(stderr,"dev_c7200_sram_init: unable to create '%s' file.\n",
113                d->filename);                d->filename);
114        return(-1);        return(-1);
# Line 170  int dev_c7200_sram_init(vm_instance_t *v Line 134  int dev_c7200_sram_init(vm_instance_t *v
134        return(-1);        return(-1);
135     }     }
136    
137     if (!(d->bs_dev = dev_create(d->bs_dev_name))) {     if (dev_bswap_init(vm,d->bs_dev_name,paddr+0x800000,len,paddr) == -1) {
138        fprintf(stderr,"dev_c7200_sram_init: unable to create BS device.\n");        fprintf(stderr,"dev_c7200_sram_init: unable to create BS device.\n");
139        return(-1);        return(-1);
140     }     }
141      
142     d->bs_dev->phys_addr = paddr + 0x800000;     d->bs_obj = vm_object_find(vm,d->bs_dev_name);
    d->bs_dev->phys_len  = len;  
    d->bs_dev->handler   = dev_sram_bs_access;  
    d->bs_dev->host_addr = (m_iptr_t)d->dev->host_addr;  
    d->bs_dev->flags     = VDEVICE_FLAG_NO_MTS_MMAP|VDEVICE_FLAG_CACHING;  
    d->bs_dev->flags    |= VDEVICE_FLAG_REMAP;  
    vm_bind_device(vm,d->bs_dev);  
    vm_object_add(vm,&d->vm_obj);  
143     return(0);     return(0);
144  }      }    

Legend:
Removed from v.6  
changed lines
  Added in v.7

  ViewVC Help
Powered by ViewVC 1.1.26