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

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

upstream/dynamips-0.2.6-RC5/dev_c3725.c revision 6 by dpavlin, Sat Oct 6 16:09:07 2007 UTC upstream/dynamips-0.2.7-RC2/dev_c3725.c revision 8 by dpavlin, Sat Oct 6 16:24:54 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   * Cisco 3725 simulation platform.   * Cisco router simulation platform.
3   * Copyright (c) 2006 Christophe Fillot (cf@utc.fr)   * Copyright (c) 2006 Christophe Fillot (cf@utc.fr)
4   *   *
5   * Generic Cisco 3725 routines and definitions (EEPROM,...).   * Generic Cisco 3725 routines and definitions (EEPROM,...).
# Line 12  Line 12 
12  #include <sys/types.h>  #include <sys/types.h>
13  #include <assert.h>  #include <assert.h>
14    
15  #include "mips64.h"  #include "cpu.h"
16    #include "vm.h"
17  #include "dynamips.h"  #include "dynamips.h"
18  #include "memory.h"  #include "memory.h"
19  #include "device.h"  #include "device.h"
20  #include "pci_io.h"  #include "pci_io.h"
21  #include "dev_gt.h"  #include "dev_gt.h"
22  #include "cisco_eeprom.h"  #include "cisco_eeprom.h"
23    #include "dev_rom.h"
24  #include "dev_c3725.h"  #include "dev_c3725.h"
25    #include "dev_c3725_iofpga.h"
26  #include "dev_vtty.h"  #include "dev_vtty.h"
27  #include "registry.h"  #include "registry.h"
28    
# Line 328  void c3725_save_config_all(FILE *fd) Line 331  void c3725_save_config_all(FILE *fd)
331     registry_foreach_type(OBJ_TYPE_VM,c3725_reg_save_config,fd,NULL);     registry_foreach_type(OBJ_TYPE_VM,c3725_reg_save_config,fd,NULL);
332  }  }
333    
334    /* Get slot/port corresponding to specified network IRQ */
335    static inline void
336    c3725_net_irq_get_slot_port(u_int irq,u_int *slot,u_int *port)
337    {
338       irq -= C3725_NETIO_IRQ_BASE;
339       *port = irq & C3725_NETIO_IRQ_PORT_MASK;
340       *slot = irq >> C3725_NETIO_IRQ_PORT_BITS;
341    }
342    
343    /* Get network IRQ for specified slot/port */
344    u_int c3725_net_irq_for_slot_port(u_int slot,u_int port)
345    {
346       u_int irq;
347    
348       irq = (slot << C3725_NETIO_IRQ_PORT_BITS) + port;
349       irq += C3725_NETIO_IRQ_BASE;
350    
351       return(irq);
352    }
353    
354  /* Get PCI device for the specified NM bay */  /* Get PCI device for the specified NM bay */
355  int c3725_nm_get_pci_device(u_int nm_bay)  int c3725_nm_get_pci_device(u_int nm_bay)
356  {  {
# Line 697  int c3725_nm_init(c3725_t *router,u_int Line 720  int c3725_nm_init(c3725_t *router,u_int
720     snprintf(bay->dev_name,len,"%s(%u)",bay->dev_type,nm_bay);     snprintf(bay->dev_name,len,"%s(%u)",bay->dev_type,nm_bay);
721    
722     /* Initialize NM driver */     /* Initialize NM driver */
723     if (bay->nm_driver->nm_init(router,bay->dev_name,nm_bay) == 1) {     if (bay->nm_driver->nm_init(router,bay->dev_name,nm_bay) == -1) {
724        vm_error(router->vm,"unable to initialize NM %u.\n",nm_bay);        vm_error(router->vm,"unable to initialize NM %u.\n",nm_bay);
725        return(-1);        return(-1);
726     }     }
# Line 1020  static int c3725_init_gt96100(c3725_t *r Line 1043  static int c3725_init_gt96100(c3725_t *r
1043     }     }
1044        
1045     return(dev_gt96100_init(vm,"gt96100",C3725_GT96K_ADDR,0x200000,     return(dev_gt96100_init(vm,"gt96100",C3725_GT96K_ADDR,0x200000,
1046                             C3725_GT96K_IRQ,C3725_NETIO_IRQ));                             C3725_GT96K_IRQ,c3725_net_irq_for_slot_port(0,0)));
1047  }  }
1048    
1049  /* Initialize a Cisco 3725 */  /* Initialize a Cisco 3725 */
# Line 1029  static int c3725_init(c3725_t *router) Line 1052  static int c3725_init(c3725_t *router)
1052     vm_instance_t *vm = router->vm;     vm_instance_t *vm = router->vm;
1053    
1054     /* Set the processor type: R7000 */     /* Set the processor type: R7000 */
1055     mips64_set_prid(vm->boot_cpu,MIPS_PRID_R7000);     mips64_set_prid(CPU_MIPS64(vm->boot_cpu),MIPS_PRID_R7000);
1056    
1057     /* Initialize the Galileo GT-96100 PCI controller */     /* Initialize the Galileo GT-96100 PCI controller */
1058     if (c3725_init_gt96100(router) == -1)     if (c3725_init_gt96100(router) == -1)
# Line 1105  void c3725_init_defaults(c3725_t *router Line 1128  void c3725_init_defaults(c3725_t *router
1128  /* Initialize the C3725 Platform */  /* Initialize the C3725 Platform */
1129  int c3725_init_platform(c3725_t *router)  int c3725_init_platform(c3725_t *router)
1130  {  {
    extern m_uint8_t microcode[];  
    extern ssize_t microcode_len;  
1131     vm_instance_t *vm = router->vm;     vm_instance_t *vm = router->vm;
1132     struct c3725_nm_bay *nm_bay;     struct c3725_nm_bay *nm_bay;
1133     cpu_mips_t *cpu;     cpu_mips_t *cpu;
1134       cpu_gen_t *gen;
1135     vm_obj_t *obj;     vm_obj_t *obj;
1136     int i;     int i;
1137    
# Line 1123  int c3725_init_platform(c3725_t *router) Line 1145  int c3725_init_platform(c3725_t *router)
1145     vm->cpu_group = cpu_group_create("System CPU");     vm->cpu_group = cpu_group_create("System CPU");
1146    
1147     /* Initialize the virtual MIPS processor */     /* Initialize the virtual MIPS processor */
1148     if (!(cpu = cpu_create(vm,0))) {     if (!(gen = cpu_create(vm,CPU_TYPE_MIPS64,0))) {
1149        vm_error(vm,"unable to create CPU!\n");        vm_error(vm,"unable to create CPU!\n");
1150        return(-1);        return(-1);
1151     }     }
1152    
1153       cpu = CPU_MIPS64(gen);
1154    
1155     /* Add this CPU to the system CPU group */     /* Add this CPU to the system CPU group */
1156     cpu_group_add(vm->cpu_group,cpu);     cpu_group_add(vm->cpu_group,gen);
1157     vm->boot_cpu = cpu;     vm->boot_cpu = gen;
1158    
1159       /* Initialize the IRQ routing vectors */
1160       vm->set_irq = mips64_vm_set_irq;
1161       vm->clear_irq = mips64_vm_clear_irq;
1162    
1163     /* Mark the Network IO interrupt as high priority */     /* Mark the Network IO interrupt as high priority */
1164     cpu->irq_idle_preempt[C3725_NETIO_IRQ] = TRUE;     cpu->irq_idle_preempt[C3725_NETIO_IRQ] = TRUE;
# Line 1147  int c3725_init_platform(c3725_t *router) Line 1175  int c3725_init_platform(c3725_t *router)
1175     dev_remote_control_init(vm,0x16000000,0x1000);     dev_remote_control_init(vm,0x16000000,0x1000);
1176    
1177     /* Specific Storage Area (SSA) */     /* Specific Storage Area (SSA) */
1178     dev_ram_init(vm,"ssa",TRUE,FALSE,NULL,0x16001000ULL,0x7000);     dev_ram_init(vm,"ssa",TRUE,FALSE,NULL,FALSE,0x16001000ULL,0x7000);
1179    
1180     /* IO FPGA */     /* IO FPGA */
1181     if (dev_c3725_iofpga_init(router,C3725_IOFPGA_ADDR,0x40000) == -1)     if (dev_c3725_iofpga_init(router,C3725_IOFPGA_ADDR,0x40000) == -1)
1182        return(-1);        return(-1);
1183    
1184       if (!(obj = vm_object_find(router->vm,"io_fpga")))
1185          return(-1);
1186    
1187       router->iofpga_data = obj->data;
1188    
1189  #if 0  #if 0
1190     /* PCI IO space */     /* PCI IO space */
1191     if (!(vm->pci_io_space = pci_io_data_init(vm,C3725_PCI_IO_ADDR)))     if (!(vm->pci_io_space = pci_io_data_init(vm,C3725_PCI_IO_ADDR)))
# Line 1170  int c3725_init_platform(c3725_t *router) Line 1203  int c3725_init_platform(c3725_t *router)
1203     if (!(obj = dev_flash_init(vm,"rom",C3725_ROM_ADDR,vm->rom_size*1048576)))     if (!(obj = dev_flash_init(vm,"rom",C3725_ROM_ADDR,vm->rom_size*1048576)))
1204        return(-1);        return(-1);
1205    
1206     dev_flash_copy_data(obj,0,microcode,microcode_len);     dev_flash_copy_data(obj,0,mips64_microcode,mips64_microcode_len);
1207     c3725_nvram_check_empty_config(vm);     c3725_nvram_check_empty_config(vm);
1208    
1209     /* Initialize the NS16552 DUART */     /* Initialize the NS16552 DUART */
# Line 1211  int c3725_init_platform(c3725_t *router) Line 1244  int c3725_init_platform(c3725_t *router)
1244  int c3725_boot_ios(c3725_t *router)  int c3725_boot_ios(c3725_t *router)
1245  {    {  
1246     vm_instance_t *vm = router->vm;     vm_instance_t *vm = router->vm;
1247       cpu_mips_t *cpu;
1248    
1249     if (!vm->boot_cpu)     if (!vm->boot_cpu)
1250        return(-1);        return(-1);
# Line 1225  int c3725_boot_ios(c3725_t *router) Line 1259  int c3725_boot_ios(c3725_t *router)
1259     }     }
1260    
1261     /* Reset the boot CPU */     /* Reset the boot CPU */
1262     mips64_reset(vm->boot_cpu);     cpu = CPU_MIPS64(vm->boot_cpu);
1263       mips64_reset(cpu);
1264    
1265     /* Load IOS image */     /* Load IOS image */
1266     if (mips64_load_elf_image(vm->boot_cpu,vm->ios_image,     if (mips64_load_elf_image(cpu,vm->ios_image,
1267                               (vm->ghost_status == VM_GHOST_RAM_USE),                               (vm->ghost_status == VM_GHOST_RAM_USE),
1268                               &vm->ios_entry_point) < 0)                               &vm->ios_entry_point) < 0)
1269     {     {
# Line 1239  int c3725_boot_ios(c3725_t *router) Line 1274  int c3725_boot_ios(c3725_t *router)
1274     /* Launch the simulation */     /* Launch the simulation */
1275     printf("\nC3725 '%s': starting simulation (CPU0 PC=0x%llx), "     printf("\nC3725 '%s': starting simulation (CPU0 PC=0x%llx), "
1276            "JIT %sabled.\n",            "JIT %sabled.\n",
1277            vm->name,vm->boot_cpu->pc,vm->jit_use ? "en":"dis");            vm->name,cpu->pc,vm->jit_use ? "en":"dis");
1278    
1279     vm_log(vm,"C3725_BOOT",     vm_log(vm,"C3725_BOOT",
1280            "starting instance (CPU0 PC=0x%llx,idle_pc=0x%llx,JIT %s)\n",            "starting instance (CPU0 PC=0x%llx,idle_pc=0x%llx,JIT %s)\n",
1281            vm->boot_cpu->pc,vm->boot_cpu->idle_pc,vm->jit_use ? "on":"off");            cpu->pc,cpu->idle_pc,vm->jit_use ? "on":"off");
1282    
1283     /* Start main CPU */     /* Start main CPU */
1284     if (vm->ghost_status != VM_GHOST_RAM_GENERATE) {     if (vm->ghost_status != VM_GHOST_RAM_GENERATE) {
# Line 1255  int c3725_boot_ios(c3725_t *router) Line 1290  int c3725_boot_ios(c3725_t *router)
1290     return(0);     return(0);
1291  }  }
1292    
1293    /* Set an IRQ */
1294    static void c3725_set_irq(vm_instance_t *vm,u_int irq)
1295    {
1296       c3725_t *router = VM_C3725(vm);
1297       cpu_mips_t *cpu0 = CPU_MIPS64(vm->boot_cpu);
1298       u_int slot,port;
1299    
1300       switch(irq) {
1301          case 0 ... 7:
1302             mips64_set_irq(cpu0,irq);
1303    
1304             if (cpu0->irq_idle_preempt[irq])
1305                cpu_idle_break_wait(cpu0->gen);
1306             break;
1307    
1308          case C3725_NETIO_IRQ_BASE ... C3725_NETIO_IRQ_END:
1309             c3725_net_irq_get_slot_port(irq,&slot,&port);
1310             dev_c3725_iofpga_net_set_irq(router->iofpga_data,slot,port);
1311             break;
1312       }
1313    }
1314    
1315    /* Clear an IRQ */
1316    static void c3725_clear_irq(vm_instance_t *vm,u_int irq)
1317    {
1318       c3725_t *router = VM_C3725(vm);
1319       cpu_mips_t *cpu0 = CPU_MIPS64(vm->boot_cpu);
1320       u_int slot,port;
1321    
1322       switch(irq) {
1323          case 0 ... 7:
1324             mips64_clear_irq(cpu0,irq);
1325             break;
1326    
1327          case C3725_NETIO_IRQ_BASE ... C3725_NETIO_IRQ_END:
1328             c3725_net_irq_get_slot_port(irq,&slot,&port);
1329             dev_c3725_iofpga_net_clear_irq(router->iofpga_data,slot,port);
1330             break;
1331       }
1332    }
1333    
1334  /* Initialize a Cisco 3725 instance */  /* Initialize a Cisco 3725 instance */
1335  int c3725_init_instance(c3725_t *router)  int c3725_init_instance(c3725_t *router)
1336  {    {  
# Line 1273  int c3725_init_instance(c3725_t *router) Line 1349  int c3725_init_instance(c3725_t *router)
1349        return(-1);        return(-1);
1350     }     }
1351    
1352       /* IRQ routing */
1353       vm->set_irq = c3725_set_irq;
1354       vm->clear_irq = c3725_clear_irq;
1355    
1356     /* Load IOS configuration file */     /* Load IOS configuration file */
1357     if (vm->ios_config != NULL) {     if (vm->ios_config != NULL) {
1358        vm_nvram_push_config(vm,vm->ios_config);        vm_nvram_push_config(vm,vm->ios_config);
# Line 1280  int c3725_init_instance(c3725_t *router) Line 1360  int c3725_init_instance(c3725_t *router)
1360     }     }
1361    
1362     /* Load ROM (ELF image or embedded) */     /* Load ROM (ELF image or embedded) */
1363     cpu0 = vm->boot_cpu;     cpu0 = CPU_MIPS64(vm->boot_cpu);
1364     rom_entry_point = (m_uint32_t)MIPS_ROM_PC;     rom_entry_point = (m_uint32_t)MIPS_ROM_PC;
1365    
1366     if ((vm->rom_filename != NULL) &&     if ((vm->rom_filename != NULL) &&

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

  ViewVC Help
Powered by ViewVC 1.1.26