/[dynamips]/upstream/dynamips-0.2.6-RC3/dev_c3600.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.6-RC3/dev_c3600.c

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

upstream/dynamips-0.2.6-RC2/dev_c3600.c revision 3 by dpavlin, Sat Oct 6 16:05:34 2007 UTC upstream/dynamips-0.2.6-RC3/dev_c3600.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_c3600.h"  #include "dev_c3600.h"
23  #include "dev_c3600_bay.h"  #include "dev_c3600_bay.h"
# Line 114  static struct c3600_nm_driver *nm_driver Line 115  static struct c3600_nm_driver *nm_driver
115    
116  /* Directly extract the configuration from the NVRAM device */  /* Directly extract the configuration from the NVRAM device */
117  ssize_t c3600_nvram_extract_config(vm_instance_t *vm,char **buffer)  ssize_t c3600_nvram_extract_config(vm_instance_t *vm,char **buffer)
118  {    {
119     struct vdevice *nvram_dev;     u_char *base_ptr,*ios_ptr,*cfg_ptr,*end_ptr;
120     m_uint32_t start,nvlen;     m_uint32_t start,nvlen;
121     m_uint16_t magic1,magic2;     m_uint16_t magic1,magic2;
122     m_uint64_t addr;     struct vdevice *nvram_dev;
123       off_t nvram_size;
124       int fd;
125    
126       if ((nvram_dev = dev_get_by_name(vm,"nvram")))
127          dev_sync(nvram_dev);
128    
129       fd = vm_mmap_open_file(vm,"nvram",&base_ptr,&nvram_size);
130    
131       if (fd == -1)
132          return(-1);
133    
134       ios_ptr = base_ptr + vm->nvram_rom_space;
135       end_ptr = base_ptr + nvram_size;
136    
137     if (!(nvram_dev = dev_get_by_name(vm,"nvram")))     if ((ios_ptr + 0x30) >= end_ptr) {
138          vm_error(vm,"NVRAM file too small\n");
139        return(-1);        return(-1);
140       }
141    
142     addr = nvram_dev->phys_addr + vm->nvram_rom_space;     magic1  = ntohs(*PTR_ADJUST(m_uint16_t *,ios_ptr,0x06));
143     magic1 = physmem_copy_u16_from_vm(vm,addr+0x06);     magic2  = ntohs(*PTR_ADJUST(m_uint16_t *,ios_ptr,0x08));
    magic2 = physmem_copy_u16_from_vm(vm,addr+0x08);  
144    
145     if ((magic1 != 0xF0A5) || (magic2 != 0xABCD)) {     if ((magic1 != 0xF0A5) || (magic2 != 0xABCD)) {
146        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 133  ssize_t c3600_nvram_extract_config(vm_in Line 148  ssize_t c3600_nvram_extract_config(vm_in
148        return(-1);        return(-1);
149     }     }
150    
151     start = physmem_copy_u32_from_vm(vm,addr+0x10) + 1;     start = ntohl(*PTR_ADJUST(m_uint32_t *,ios_ptr,0x10)) + 1;
152     nvlen = physmem_copy_u32_from_vm(vm,addr+0x18);     nvlen = ntohl(*PTR_ADJUST(m_uint32_t *,ios_ptr,0x18));
153    
154     if (nvlen <= 10) {     if (!(*buffer = malloc(nvlen+1))) {
155        vm_error(vm,"invalid configuration size (0x%x)\n",nvlen);        vm_error(vm,"unable to allocate config buffer (%u bytes)\n",nvlen);
156        return(-1);        return(-1);
157     }     }
158    
159     if (!(*buffer = malloc(nvlen+1))) {     cfg_ptr = ios_ptr + start + 0x08;
160        vm_error(vm,"unable to allocate config buffer (%u bytes)\n",nvlen);  
161       if ((cfg_ptr + nvlen) > end_ptr) {
162          vm_error(vm,"NVRAM file too small\n");
163        return(-1);        return(-1);
164     }     }
165    
166     physmem_copy_from_vm(vm,*buffer,addr+start+0x08,nvlen-1);     memcpy(*buffer,cfg_ptr,nvlen-1);
167     (*buffer)[nvlen-1] = 0;     (*buffer)[nvlen-1] = 0;
168     return(nvlen-1);     return(nvlen-1);
169  }  }
# Line 154  ssize_t c3600_nvram_extract_config(vm_in Line 171  ssize_t c3600_nvram_extract_config(vm_in
171  /* Directly push the IOS configuration to the NVRAM device */  /* Directly push the IOS configuration to the NVRAM device */
172  int c3600_nvram_push_config(vm_instance_t *vm,char *buffer,size_t len)  int c3600_nvram_push_config(vm_instance_t *vm,char *buffer,size_t len)
173  {  {
174     struct vdevice *nvram_dev;     u_char *base_ptr,*ios_ptr,*cfg_ptr;
175     m_uint64_t addr,cfg_addr;     m_uint32_t cfg_offset,cklen,tmp;
    m_uint32_t tmp,cfg_offset;  
    m_uint32_t cklen;  
176     m_uint16_t cksum;     m_uint16_t cksum;
177       int fd;
178    
179     if (!(nvram_dev = dev_get_by_name(vm,"nvram")))     fd = vm_mmap_create_file(vm,"nvram",vm->nvram_size*1024,&base_ptr);
180    
181       if (fd == -1)
182        return(-1);        return(-1);
183    
    addr = nvram_dev->phys_addr + vm->nvram_rom_space;  
184     cfg_offset = 0x2c;     cfg_offset = 0x2c;
185     cfg_addr   = addr + cfg_offset;     ios_ptr = base_ptr + vm->nvram_rom_space;
186       cfg_ptr = ios_ptr  + cfg_offset;
187    
188     /* Write IOS tag, uncompressed config... */     /* Write IOS tag, uncompressed config... */
189     physmem_copy_u16_to_vm(vm,addr+0x06,0xF0A5);     *PTR_ADJUST(m_uint16_t *,ios_ptr,0x06) = htons(0xF0A5);
190     physmem_copy_u16_to_vm(vm,addr+0x08,0xABCD);      /* Magic number */     *PTR_ADJUST(m_uint16_t *,ios_ptr,0x08) = htons(0xABCD);
191     physmem_copy_u16_to_vm(vm,addr+0x0a,0x0001);      /* ??? */     *PTR_ADJUST(m_uint16_t *,ios_ptr,0x0a) = htons(0x0001);
192     physmem_copy_u16_to_vm(vm,addr+0x0c,0x0000);      /* Checksum */     *PTR_ADJUST(m_uint16_t *,ios_ptr,0x0c) = htons(0x0000);
193     physmem_copy_u16_to_vm(vm,addr+0x0e,0x0c04);      /* IOS version */     *PTR_ADJUST(m_uint16_t *,ios_ptr,0x0e) = htons(0x0c04);
194    
195     /* Store file contents to NVRAM */     /* Store file contents to NVRAM */
196     physmem_copy_to_vm(vm,buffer,cfg_addr,len);     memcpy(cfg_ptr,buffer,len);
197    
198     /* Write config addresses + size */     /* Write config addresses + size */
199     tmp = cfg_addr - addr - 0x08;     tmp = cfg_offset - 0x08;
200    
201     physmem_copy_u32_to_vm(vm,addr+0x10,tmp);     *PTR_ADJUST(m_uint32_t *,ios_ptr,0x10) = htonl(tmp);
202     physmem_copy_u32_to_vm(vm,addr+0x14,tmp + len);     *PTR_ADJUST(m_uint32_t *,ios_ptr,0x14) = htonl(tmp + len);
203     physmem_copy_u32_to_vm(vm,addr+0x18,len);     *PTR_ADJUST(m_uint32_t *,ios_ptr,0x18) = htonl(len);
204    
205     /* Compute the checksum */     /* Compute the checksum */
206     cklen = nvram_dev->phys_len - (vm->nvram_rom_space + 0x08);     cklen = (vm->nvram_size*1024) - (vm->nvram_rom_space + 0x08);
207     cksum = nvram_cksum(vm,addr+0x08,cklen);     cksum = nvram_cksum((m_uint16_t *)(ios_ptr+0x08),cklen);
208     physmem_copy_u16_to_vm(vm,addr+0x0c,cksum);     *PTR_ADJUST(m_uint16_t *,ios_ptr,0x0c) = htons(cksum);
209    
210       vm_mmap_close_file(fd,base_ptr,vm->nvram_size*1024);
211     return(0);     return(0);
212  }  }
213    
# Line 1212  void c3600_init_defaults(c3600_t *router Line 1232  void c3600_init_defaults(c3600_t *router
1232    
1233     /* Generate a chassis MAC address based on the instance ID */     /* Generate a chassis MAC address based on the instance ID */
1234     m = &router->mac_addr;     m = &router->mac_addr;
1235     m->eth_addr_byte[0] = 0xCC;     m->eth_addr_byte[0] = vm_get_mac_addr_msb(vm);
1236     m->eth_addr_byte[1] = vm->instance_id & 0xFF;     m->eth_addr_byte[1] = vm->instance_id & 0xFF;
1237     m->eth_addr_byte[2] = pid >> 8;     m->eth_addr_byte[2] = pid >> 8;
1238     m->eth_addr_byte[3] = pid & 0xFF;     m->eth_addr_byte[3] = pid & 0xFF;
# Line 1226  void c3600_init_defaults(c3600_t *router Line 1246  void c3600_init_defaults(c3600_t *router
1246     vm->ram_size          = C3600_DEFAULT_RAM_SIZE;     vm->ram_size          = C3600_DEFAULT_RAM_SIZE;
1247     vm->rom_size          = C3600_DEFAULT_ROM_SIZE;     vm->rom_size          = C3600_DEFAULT_ROM_SIZE;
1248     vm->nvram_size        = C3600_DEFAULT_NVRAM_SIZE;     vm->nvram_size        = C3600_DEFAULT_NVRAM_SIZE;
1249     vm->conf_reg          = C3600_DEFAULT_CONF_REG;     vm->conf_reg_setup    = C3600_DEFAULT_CONF_REG;
1250     vm->clock_divisor     = C3600_DEFAULT_CLOCK_DIV;     vm->clock_divisor     = C3600_DEFAULT_CLOCK_DIV;
1251     vm->nvram_rom_space   = C3600_NVRAM_ROM_RES_SIZE;     vm->nvram_rom_space   = C3600_NVRAM_ROM_RES_SIZE;
1252     router->nm_iomem_size = C3600_DEFAULT_IOMEM_SIZE;     router->nm_iomem_size = C3600_DEFAULT_IOMEM_SIZE;
1253    
1254     vm->pcmcia_disk_size[0] = C3600_DEFAULT_DISK0_SIZE;     vm->pcmcia_disk_size[0] = C3600_DEFAULT_DISK0_SIZE;
1255     vm->pcmcia_disk_size[1] = C3600_DEFAULT_DISK1_SIZE;     vm->pcmcia_disk_size[1] = C3600_DEFAULT_DISK1_SIZE;
1256    
1257       /* Enable NVRAM operations to load/store configs */
1258       vm->nvram_extract_config = c3600_nvram_extract_config;
1259       vm->nvram_push_config = c3600_nvram_push_config;
1260  }  }
1261    
1262  /* Initialize the C3600 Platform */  /* Initialize the C3600 Platform */
# Line 1264  int c3600_init_platform(c3600_t *router) Line 1288  int c3600_init_platform(c3600_t *router)
1288    
1289     /* Mark the Network IO interrupt as high priority */     /* Mark the Network IO interrupt as high priority */
1290     cpu->irq_idle_preempt[C3600_NETIO_IRQ] = TRUE;     cpu->irq_idle_preempt[C3600_NETIO_IRQ] = TRUE;
1291       cpu->irq_idle_preempt[C3600_GT64K_IRQ] = TRUE;
1292     cpu->irq_idle_preempt[C3600_DUART_IRQ] = TRUE;     cpu->irq_idle_preempt[C3600_DUART_IRQ] = TRUE;
1293    
1294     /* Copy some parameters from VM to CPU (idle PC, ...) */     /* Copy some parameters from VM to CPU (idle PC, ...) */
# Line 1304  int c3600_init_platform(c3600_t *router) Line 1329  int c3600_init_platform(c3600_t *router)
1329        return(-1);        return(-1);
1330    
1331     /* Initialize RAM */     /* Initialize RAM */
1332     dev_ram_init(vm,"ram",vm->ram_mmap,0x00000000ULL,vm->ram_size*1048576);     vm_ram_init(vm,0x00000000ULL);
1333    
1334     /* Initialize ROM */     /* Initialize ROM */
1335     if (!vm->rom_filename) {     if (!vm->rom_filename) {
# Line 1312  int c3600_init_platform(c3600_t *router) Line 1337  int c3600_init_platform(c3600_t *router)
1337        dev_rom_init(vm,"rom",C3600_ROM_ADDR,vm->rom_size*1048576);        dev_rom_init(vm,"rom",C3600_ROM_ADDR,vm->rom_size*1048576);
1338     } else {     } else {
1339        /* use alternate ROM */        /* use alternate ROM */
1340        dev_ram_init(vm,"rom",TRUE,C3600_ROM_ADDR,vm->rom_size*1048576);        dev_ram_init(vm,"rom",TRUE,TRUE,NULL,
1341                       C3600_ROM_ADDR,vm->rom_size*1048576);
1342     }     }
1343    
1344     /* Initialize the NS16552 DUART */     /* Initialize the NS16552 DUART */
# Line 1336  int c3600_init_platform(c3600_t *router) Line 1362  int c3600_init_platform(c3600_t *router)
1362        }        }
1363     }     }
1364    
    /* Enable NVRAM operations to load/store configs */  
    vm->nvram_extract_config = c3600_nvram_extract_config;  
    vm->nvram_push_config = c3600_nvram_push_config;  
   
1365     /* Show device list */     /* Show device list */
1366     c3600_show_hardware(router);     c3600_show_hardware(router);
1367     return(0);     return(0);
# Line 1367  int c3600_boot_ios(c3600_t *router) Line 1389  int c3600_boot_ios(c3600_t *router)
1389    
1390     /* Load IOS image */     /* Load IOS image */
1391     if (mips64_load_elf_image(vm->boot_cpu,vm->ios_image,     if (mips64_load_elf_image(vm->boot_cpu,vm->ios_image,
1392                                 (vm->ghost_status == VM_GHOST_RAM_USE),
1393                               &vm->ios_entry_point) < 0)                               &vm->ios_entry_point) < 0)
1394     {     {
1395        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);
# Line 1383  int c3600_boot_ios(c3600_t *router) Line 1406  int c3600_boot_ios(c3600_t *router)
1406            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");
1407    
1408     /* Start main CPU */     /* Start main CPU */
1409     vm->status = VM_STATUS_RUNNING;     if (vm->ghost_status != VM_GHOST_RAM_GENERATE) {
1410     cpu_start(vm->boot_cpu);        vm->status = VM_STATUS_RUNNING;
1411          cpu_start(vm->boot_cpu);
1412       } else {
1413          vm->status = VM_STATUS_SHUTDOWN;
1414       }
1415     return(0);     return(0);
1416  }  }
1417    
# Line 1417  int c3600_init_instance(c3600_t *router) Line 1444  int c3600_init_instance(c3600_t *router)
1444     rom_entry_point = (m_uint32_t)MIPS_ROM_PC;     rom_entry_point = (m_uint32_t)MIPS_ROM_PC;
1445    
1446     if ((vm->rom_filename != NULL) &&     if ((vm->rom_filename != NULL) &&
1447         (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))
1448     {     {
1449        vm_error(vm,"unable to load alternate ROM '%s', "        vm_error(vm,"unable to load alternate ROM '%s', "
1450                 "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