/[dynamips]/trunk/dev_c7200.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/dev_c7200.c

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

upstream/dynamips-0.2.6-RC2/dev_c7200.c revision 3 by dpavlin, Sat Oct 6 16:05:34 2007 UTC upstream/dynamips-0.2.6-RC3/dev_c7200.c revision 4 by dpavlin, Sat Oct 6 16:06:49 2007 UTC
# Line 17  Line 17 
17  #include "memory.h"  #include "memory.h"
18  #include "device.h"  #include "device.h"
19  #include "pci_io.h"  #include "pci_io.h"
20    #include "dev_gt.h"
21  #include "cisco_eeprom.h"  #include "cisco_eeprom.h"
22  #include "dev_c7200.h"  #include "dev_c7200.h"
23  #include "dev_vtty.h"  #include "dev_vtty.h"
# Line 168  static struct c7200_pa_driver *pa_driver Line 169  static struct c7200_pa_driver *pa_driver
169     &dev_c7200_pa_8t_driver,     &dev_c7200_pa_8t_driver,
170     &dev_c7200_pa_a1_driver,     &dev_c7200_pa_a1_driver,
171     &dev_c7200_pa_pos_oc3_driver,     &dev_c7200_pa_pos_oc3_driver,
172     &dev_c7200_pa_4b_driver,     &dev_c7200_pa_4b_driver,  
173       &dev_c7200_pa_mc8te1_driver,
174     NULL,     NULL,
175  };  };
176    
# Line 207  static struct c7200_npe_driver npe_drive Line 209  static struct c7200_npe_driver npe_drive
209  /* Directly extract the configuration from the NVRAM device */  /* Directly extract the configuration from the NVRAM device */
210  ssize_t c7200_nvram_extract_config(vm_instance_t *vm,char **buffer)  ssize_t c7200_nvram_extract_config(vm_instance_t *vm,char **buffer)
211  {    {  
212       u_char *base_ptr,*ios_ptr,*cfg_ptr,*end_ptr;
213       m_uint32_t start,end,nvlen,clen;
214       m_uint16_t magic1,magic2;
215     struct vdevice *nvram_dev;     struct vdevice *nvram_dev;
216     m_uint32_t start,end,clen,nvlen;     m_uint64_t nvram_addr;
217     m_uint16_t magic1,magic2;     off_t nvram_size;
218     m_uint64_t addr;     int fd;
219    
220     if (!(nvram_dev = dev_get_by_name(vm,"nvram")))     if ((nvram_dev = dev_get_by_name(vm,"nvram")))
221          dev_sync(nvram_dev);
222    
223       fd = vm_mmap_open_file(vm,"nvram",&base_ptr,&nvram_size);
224    
225       if (fd == -1)
226        return(-1);        return(-1);
227    
228     addr = nvram_dev->phys_addr + vm->nvram_rom_space;     nvram_addr = VM_C7200(vm)->npe_driver->nvram_addr;
229     magic1 = physmem_copy_u16_from_vm(vm,addr+0x06);     ios_ptr = base_ptr + vm->nvram_rom_space;
230     magic2 = physmem_copy_u16_from_vm(vm,addr+0x08);     end_ptr = base_ptr + nvram_size;
231    
232       if ((ios_ptr + 0x30) >= end_ptr) {
233          vm_error(vm,"NVRAM file too small\n");
234          return(-1);
235       }
236    
237       magic1  = ntohs(*PTR_ADJUST(m_uint16_t *,ios_ptr,0x06));
238       magic2  = ntohs(*PTR_ADJUST(m_uint16_t *,ios_ptr,0x08));
239    
240     if ((magic1 != 0xF0A5) || (magic2 != 0xABCD)) {     if ((magic1 != 0xF0A5) || (magic2 != 0xABCD)) {
241        vm_error(vm,"unable to find IOS magic numbers (0x%x,0x%x)!\n",        vm_error(vm,"unable to find IOS magic numbers (0x%x,0x%x)!\n",
# Line 225  ssize_t c7200_nvram_extract_config(vm_in Line 243  ssize_t c7200_nvram_extract_config(vm_in
243        return(-1);        return(-1);
244     }     }
245    
246     start = physmem_copy_u32_from_vm(vm,addr+0x10) + 1;     start = ntohl(*PTR_ADJUST(m_uint32_t *,ios_ptr,0x10)) + 1;
247     end   = physmem_copy_u32_from_vm(vm,addr+0x14);     end   = ntohl(*PTR_ADJUST(m_uint32_t *,ios_ptr,0x14));
248     nvlen = physmem_copy_u32_from_vm(vm,addr+0x18);     nvlen = ntohl(*PTR_ADJUST(m_uint32_t *,ios_ptr,0x18));
249     clen  = end - start;     clen  = end - start;
250    
251     if ((clen + 1) != nvlen) {     if ((clen + 1) != nvlen) {
# Line 235  ssize_t c7200_nvram_extract_config(vm_in Line 253  ssize_t c7200_nvram_extract_config(vm_in
253        return(-1);        return(-1);
254     }     }
255    
256     if ((start <= nvram_dev->phys_addr) || (end <= nvram_dev->phys_addr) ||     if (!(*buffer = malloc(clen+1))) {
257         (end <= start))        vm_error(vm,"unable to allocate config buffer (%u bytes)\n",clen);
    {  
       vm_error(vm,"invalid configuration markers (start=0x%x,end=0x%x)\n",  
                start,end);  
258        return(-1);        return(-1);
259     }     }
260    
261     if (!(*buffer = malloc(clen+1))) {     cfg_ptr = base_ptr + (start - nvram_addr);
262        vm_error(vm,"unable to allocate config buffer (%u bytes)\n",clen);  
263       if ((start < nvram_addr) || ((cfg_ptr + clen) > end_ptr)) {
264          vm_error(vm,"NVRAM file too small\n");
265        return(-1);        return(-1);
266     }     }
267    
268     physmem_copy_from_vm(vm,*buffer,start,clen);     memcpy(*buffer,cfg_ptr,clen);
269     (*buffer)[clen] = 0;     (*buffer)[clen] = 0;
270     return(clen);     return(clen);
271  }  }
272    
273  /* Directly push the IOS configuration to the NVRAM device */  /* Directly push the IOS configuration to the NVRAM device */
274  int c7200_nvram_push_config(vm_instance_t *vm,char *buffer,size_t len)  int c7200_nvram_push_config(vm_instance_t *vm,char *buffer,size_t len)
275  {  {  
276     struct vdevice *nvram_dev;     u_char *base_ptr,*ios_ptr,*cfg_ptr;
277     m_uint64_t addr,cfg_addr;     m_uint32_t cfg_addr,cfg_offset;
278     m_uint32_t cklen;     m_uint32_t nvram_addr,cklen;
279     m_uint16_t cksum;     m_uint16_t cksum;
280       int fd;
281    
282       fd = vm_mmap_create_file(vm,"nvram",vm->nvram_size*1024,&base_ptr);
283    
284     if (!(nvram_dev = dev_get_by_name(vm,"nvram")))     if (fd == -1)
285        return(-1);        return(-1);
286    
287     addr = nvram_dev->phys_addr + vm->nvram_rom_space;     cfg_offset = 0x2c;
288     cfg_addr = addr + 0x2c;     ios_ptr = base_ptr + vm->nvram_rom_space;
289       cfg_ptr = ios_ptr  + cfg_offset;
290    
291       nvram_addr = VM_C7200(vm)->npe_driver->nvram_addr;
292       cfg_addr = nvram_addr + vm->nvram_rom_space + cfg_offset;
293    
294     /* Write IOS tag, uncompressed config... */     /* Write IOS tag, uncompressed config... */
295     physmem_copy_u16_to_vm(vm,addr+0x06,0xF0A5);     *PTR_ADJUST(m_uint16_t *,ios_ptr,0x06) = htons(0xF0A5);
296     physmem_copy_u16_to_vm(vm,addr+0x08,0xABCD);      /* Magic number */     *PTR_ADJUST(m_uint16_t *,ios_ptr,0x08) = htons(0xABCD);
297     physmem_copy_u16_to_vm(vm,addr+0x0a,0x0001);      /* ??? */     *PTR_ADJUST(m_uint16_t *,ios_ptr,0x0a) = htons(0x0001);
298     physmem_copy_u16_to_vm(vm,addr+0x0c,0x0000);      /* zero */     *PTR_ADJUST(m_uint16_t *,ios_ptr,0x0c) = htons(0x0000);
299     physmem_copy_u16_to_vm(vm,addr+0x0e,0x0000);      /* IOS version */     *PTR_ADJUST(m_uint16_t *,ios_ptr,0x0e) = htons(0x0000);
300    
301     /* Store file contents to NVRAM */     /* Store file contents to NVRAM */
302     physmem_copy_to_vm(vm,buffer,cfg_addr,len);     memcpy(cfg_ptr,buffer,len);
303    
304     /* Write config addresses + size */     /* Write config addresses + size */
305     physmem_copy_u32_to_vm(vm,addr+0x10,cfg_addr);     *PTR_ADJUST(m_uint32_t *,ios_ptr,0x10) = htonl(cfg_addr);
306     physmem_copy_u32_to_vm(vm,addr+0x14,cfg_addr + len);     *PTR_ADJUST(m_uint32_t *,ios_ptr,0x14) = htonl(cfg_addr + len);
307     physmem_copy_u32_to_vm(vm,addr+0x18,len);     *PTR_ADJUST(m_uint32_t *,ios_ptr,0x18) = htonl(len);
308    
309     /* Compute the checksum */     /* Compute the checksum */
310     cklen = nvram_dev->phys_len - (vm->nvram_rom_space + 0x08);     cklen = (vm->nvram_size*1024) - (vm->nvram_rom_space + 0x08);
311     cksum = nvram_cksum(vm,addr+0x08,cklen);     cksum = nvram_cksum((m_uint16_t *)(ios_ptr+0x08),cklen);
312     physmem_copy_u16_to_vm(vm,addr+0x0c,cksum);     *PTR_ADJUST(m_uint16_t *,ios_ptr,0x0c) = htons(cksum);
313    
314       vm_mmap_close_file(fd,base_ptr,vm->nvram_size*1024);
315     return(0);     return(0);
316  }  }
317    
# Line 1620  int c7200_init_npe300(c7200_t *router) Line 1646  int c7200_init_npe300(c7200_t *router)
1646    
1647     /* 32 Mb of I/O memory */     /* 32 Mb of I/O memory */
1648     vm->iomem_size = 32;     vm->iomem_size = 32;
1649     dev_ram_init(vm,"iomem",vm->ram_mmap,C7200_IOMEM_ADDR,32*1048576);     dev_ram_init(vm,"iomem",vm->ram_mmap,TRUE,NULL,C7200_IOMEM_ADDR,32*1048576);
1650    
1651     /* Initialize the two Galileo GT-64120 system controllers */     /* Initialize the two Galileo GT-64120 system controllers */
1652     if (c7200_init_dual_gt64120(router) == -1)     if (c7200_init_dual_gt64120(router) == -1)
# Line 1677  int c7200_init_npe400(c7200_t *router) Line 1703  int c7200_init_npe400(c7200_t *router)
1703     if (vm->ram_size > C7200_BASE_RAM_LIMIT) {     if (vm->ram_size > C7200_BASE_RAM_LIMIT) {
1704        vm->iomem_size = vm->ram_size - C7200_BASE_RAM_LIMIT;        vm->iomem_size = vm->ram_size - C7200_BASE_RAM_LIMIT;
1705        vm->ram_size = C7200_BASE_RAM_LIMIT;        vm->ram_size = C7200_BASE_RAM_LIMIT;
1706        dev_ram_init(vm,"ram1",vm->ram_mmap,        dev_ram_init(vm,"ram1",vm->ram_mmap,TRUE,NULL,
1707                     C7200_IOMEM_ADDR,vm->iomem_size*1048576);                     C7200_IOMEM_ADDR,vm->iomem_size*1048576);
1708     }     }
1709    
# Line 1805  void c7200_init_defaults(c7200_t *router Line 1831  void c7200_init_defaults(c7200_t *router
1831    
1832     /* Generate a chassis MAC address based on the instance ID */     /* Generate a chassis MAC address based on the instance ID */
1833     m = &router->mac_addr;     m = &router->mac_addr;
1834     m->eth_addr_byte[0] = 0xCA;     m->eth_addr_byte[0] = vm_get_mac_addr_msb(vm);
1835     m->eth_addr_byte[1] = vm->instance_id & 0xFF;     m->eth_addr_byte[1] = vm->instance_id & 0xFF;
1836     m->eth_addr_byte[2] = pid >> 8;     m->eth_addr_byte[2] = pid >> 8;
1837     m->eth_addr_byte[3] = pid & 0xFF;     m->eth_addr_byte[3] = pid & 0xFF;
# Line 1827  void c7200_init_defaults(c7200_t *router Line 1853  void c7200_init_defaults(c7200_t *router
1853    
1854     vm->pcmcia_disk_size[0] = C7200_DEFAULT_DISK0_SIZE;     vm->pcmcia_disk_size[0] = C7200_DEFAULT_DISK0_SIZE;
1855     vm->pcmcia_disk_size[1] = C7200_DEFAULT_DISK1_SIZE;     vm->pcmcia_disk_size[1] = C7200_DEFAULT_DISK1_SIZE;
1856    
1857       /* Enable NVRAM operations to load/store configs */
1858       vm->nvram_extract_config = c7200_nvram_extract_config;
1859       vm->nvram_push_config = c7200_nvram_push_config;
1860  }  }
1861    
1862  /* Run the checklist */  /* Run the checklist */
# Line 1884  int c7200_init_platform(c7200_t *router) Line 1914  int c7200_init_platform(c7200_t *router)
1914    
1915     /* Mark the Network IO interrupt as high priority */     /* Mark the Network IO interrupt as high priority */
1916     cpu0->irq_idle_preempt[C7200_NETIO_IRQ] = TRUE;     cpu0->irq_idle_preempt[C7200_NETIO_IRQ] = TRUE;
1917       cpu0->irq_idle_preempt[C7200_GT64K_IRQ] = TRUE;
1918    
1919     /* Copy some parameters from VM to CPU0 (idle PC, ...) */     /* Copy some parameters from VM to CPU0 (idle PC, ...) */
1920     cpu0->idle_pc = vm->idle_pc;     cpu0->idle_pc = vm->idle_pc;
# Line 1922  int c7200_init_platform(c7200_t *router) Line 1953  int c7200_init_platform(c7200_t *router)
1953        return(-1);        return(-1);
1954    
1955     /* Initialize RAM */     /* Initialize RAM */
1956     dev_ram_init(vm,"ram",vm->ram_mmap,0x00000000ULL,vm->ram_size*1048576);     vm_ram_init(vm,0x00000000ULL);
1957    
1958     /* Initialize ROM */     /* Initialize ROM */
1959     if (!vm->rom_filename) {     if (!vm->rom_filename) {
# Line 1930  int c7200_init_platform(c7200_t *router) Line 1961  int c7200_init_platform(c7200_t *router)
1961        dev_rom_init(vm,"rom",C7200_ROM_ADDR,vm->rom_size*1048576);        dev_rom_init(vm,"rom",C7200_ROM_ADDR,vm->rom_size*1048576);
1962     } else {     } else {
1963        /* use alternate ROM */        /* use alternate ROM */
1964        dev_ram_init(vm,"rom",TRUE,C7200_ROM_ADDR,vm->rom_size*1048576);        dev_ram_init(vm,"rom",TRUE,TRUE,NULL,
1965                       C7200_ROM_ADDR,vm->rom_size*1048576);
1966     }     }
1967    
1968     /* PCI IO space */     /* PCI IO space */
# Line 1962  int c7200_init_platform(c7200_t *router) Line 1994  int c7200_init_platform(c7200_t *router)
1994        c7200_pa_init(router,0);        c7200_pa_init(router,0);
1995     }     }
1996    
    /* Enable NVRAM operations to load/store configs */  
    vm->nvram_extract_config = c7200_nvram_extract_config;  
    vm->nvram_push_config = c7200_nvram_push_config;  
   
1997     /* Verify the check list */     /* Verify the check list */
1998     if (c7200_checklist(router) == -1)     if (c7200_checklist(router) == -1)
1999        return(-1);        return(-1);
# Line 1997  int c7200_boot_ios(c7200_t *router) Line 2025  int c7200_boot_ios(c7200_t *router)
2025    
2026     /* Load IOS image */     /* Load IOS image */
2027     if (mips64_load_elf_image(vm->boot_cpu,vm->ios_image,     if (mips64_load_elf_image(vm->boot_cpu,vm->ios_image,
2028                               &vm->ios_entry_point) < 0)                               (vm->ghost_status == VM_GHOST_RAM_USE),
2029                                 &vm->ios_entry_point) < 0)
2030     {     {
2031        vm_error(vm,"failed to load Cisco IOS image '%s'.\n",vm->ios_image);        vm_error(vm,"failed to load Cisco IOS image '%s'.\n",vm->ios_image);
2032        return(-1);        return(-1);
# Line 2013  int c7200_boot_ios(c7200_t *router) Line 2042  int c7200_boot_ios(c7200_t *router)
2042            vm->boot_cpu->pc,vm->boot_cpu->idle_pc,vm->jit_use ? "on":"off");            vm->boot_cpu->pc,vm->boot_cpu->idle_pc,vm->jit_use ? "on":"off");
2043        
2044     /* Start main CPU */     /* Start main CPU */
2045     vm->status = VM_STATUS_RUNNING;     if (vm->ghost_status != VM_GHOST_RAM_GENERATE) {
2046     cpu_start(vm->boot_cpu);        vm->status = VM_STATUS_RUNNING;
2047          cpu_start(vm->boot_cpu);
2048       } else {
2049          vm->status = VM_STATUS_SHUTDOWN;
2050       }
2051     return(0);     return(0);
2052  }  }
2053    
# Line 2042  int c7200_init_instance(c7200_t *router) Line 2075  int c7200_init_instance(c7200_t *router)
2075     rom_entry_point = (m_uint32_t)MIPS_ROM_PC;     rom_entry_point = (m_uint32_t)MIPS_ROM_PC;
2076        
2077     if ((vm->rom_filename != NULL) &&     if ((vm->rom_filename != NULL) &&
2078         (mips64_load_elf_image(cpu0,vm->rom_filename,&rom_entry_point) < 0))         (mips64_load_elf_image(cpu0,vm->rom_filename,0,&rom_entry_point) < 0))
2079     {     {
2080        vm_error(vm,"unable to load alternate ROM '%s', "        vm_error(vm,"unable to load alternate ROM '%s', "
2081                 "fallback to embedded ROM.\n\n",vm->rom_filename);                 "fallback to embedded ROM.\n\n",vm->rom_filename);

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

  ViewVC Help
Powered by ViewVC 1.1.26