/[dynamips]/upstream/dynamips-0.2.6-RC5/vm.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-RC5/vm.c

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

upstream/dynamips-0.2.6-RC1/vm.c revision 2 by dpavlin, Sat Oct 6 16:03:58 2007 UTC upstream/dynamips-0.2.6-RC3/vm.c revision 4 by dpavlin, Sat Oct 6 16:06:49 2007 UTC
# Line 11  Line 11 
11  #include <stdlib.h>  #include <stdlib.h>
12  #include <string.h>  #include <string.h>
13  #include <unistd.h>  #include <unistd.h>
14    #include <errno.h>
15  #include <fcntl.h>  #include <fcntl.h>
16  #include <sys/types.h>  #include <sys/types.h>
17  #include <assert.h>  #include <assert.h>
# Line 53  void vm_object_remove(vm_instance_t *vm, Line 54  void vm_object_remove(vm_instance_t *vm,
54     if (obj->next)     if (obj->next)
55        obj->next->pprev = obj->pprev;        obj->next->pprev = obj->pprev;
56     *(obj->pprev) = obj->next;     *(obj->pprev) = obj->next;
57    
58       obj->shutdown(vm,obj->data);
59  }  }
60    
61  /* Find an object given its name */  /* Find an object given its name */
# Line 118  char *vm_get_type(vm_instance_t *vm) Line 121  char *vm_get_type(vm_instance_t *vm)
121        case VM_TYPE_C7200:        case VM_TYPE_C7200:
122           machine = "c7200";           machine = "c7200";
123           break;           break;
124          case VM_TYPE_C2691:
125             machine = "c2691";
126             break;
127          case VM_TYPE_C3725:
128             machine = "c3725";
129             break;
130         case VM_TYPE_C3745:
131             machine = "c3745";
132             break;
133        default:        default:
134           machine = "unknown";           machine = "unknown";
135           break;           break;
# Line 137  char *vm_get_platform_type(vm_instance_t Line 149  char *vm_get_platform_type(vm_instance_t
149           break;           break;
150        case VM_TYPE_C7200:        case VM_TYPE_C7200:
151           machine = "C7200";           machine = "C7200";
152             break;    
153          case VM_TYPE_C2691:
154             machine = "C2691";
155             break;
156          case VM_TYPE_C3725:
157             machine = "C3725";
158             break;
159          case VM_TYPE_C3745:
160             machine = "C3745";
161           break;           break;
162        default:        default:
163           machine = "VM";           machine = "VM";
# Line 146  char *vm_get_platform_type(vm_instance_t Line 167  char *vm_get_platform_type(vm_instance_t
167     return machine;     return machine;
168  }  }
169    
170    /* Get MAC address MSB */
171    u_int vm_get_mac_addr_msb(vm_instance_t *vm)
172    {
173       switch(vm->type) {
174          case VM_TYPE_C3600:
175             return(0xCC);
176    
177          case VM_TYPE_C7200:
178             return(0xCA);
179    
180          case VM_TYPE_C2691:
181             return(0xC0);
182    
183          case VM_TYPE_C3725:
184             return(0xC2);
185    
186          case VM_TYPE_C3745:
187             return(0xC4);
188    
189          default:
190             return(0xC6);
191       }
192    }
193    
194  /* Generate a filename for use by the instance */  /* Generate a filename for use by the instance */
195  char *vm_build_filename(vm_instance_t *vm,char *name)  char *vm_build_filename(vm_instance_t *vm,char *name)
196  {  {
# Line 404  void vm_free(vm_instance_t *vm) Line 449  void vm_free(vm_instance_t *vm)
449        vm_release_lock(vm,TRUE);        vm_release_lock(vm,TRUE);
450    
451        /* Free various elements */        /* Free various elements */
452          free(vm->ghost_ram_filename);
453        free(vm->sym_filename);        free(vm->sym_filename);
454        free(vm->ios_image);        free(vm->ios_image);
455        free(vm->ios_config);        free(vm->ios_config);
# Line 425  int vm_release(vm_instance_t *vm) Line 471  int vm_release(vm_instance_t *vm)
471     return(registry_unref(vm->name,OBJ_TYPE_VM));     return(registry_unref(vm->name,OBJ_TYPE_VM));
472  }  }
473    
474    /* Initialize RAM */
475    int vm_ram_init(vm_instance_t *vm,m_uint64_t paddr)
476    {
477       m_uint32_t len;
478    
479       len = vm->ram_size * 1048576;
480    
481       if (vm->ghost_status == VM_GHOST_RAM_USE)
482          return(dev_ram_ghost_init(vm,"ram",vm->ghost_ram_filename,paddr,len));
483    
484       return(dev_ram_init(vm,"ram",vm->ram_mmap,
485                           (vm->ghost_status != VM_GHOST_RAM_GENERATE),
486                           vm->ghost_ram_filename,paddr,len));
487    }
488    
489  /* Initialize VTTY */  /* Initialize VTTY */
490  int vm_init_vtty(vm_instance_t *vm)  int vm_init_vtty(vm_instance_t *vm)
491  {  {
# Line 597  void vm_monitor(vm_instance_t *vm) Line 658  void vm_monitor(vm_instance_t *vm)
658        usleep(200000);        usleep(200000);
659  }  }
660    
661    /* Open a VM file and map it in memory */
662    int vm_mmap_open_file(vm_instance_t *vm,char *name,
663                          u_char **ptr,off_t *fsize)
664    {
665       char *filename;
666       int fd;
667    
668       if (!(filename = vm_build_filename(vm,name))) {
669          fprintf(stderr,"vm_mmap_open_file: unable to create filename (%s)\n",
670                  name);
671          return(-1);
672       }
673    
674       if ((fd = memzone_open_file(filename,ptr,fsize)) == -1)
675          fprintf(stderr,"vm_mmap_open_file: unable to open file '%s' (%s)\n",
676                  filename,strerror(errno));
677    
678       free(filename);
679       return(fd);
680    }
681    
682    /* Open/Create a VM file and map it in memory */
683    int vm_mmap_create_file(vm_instance_t *vm,char *name,size_t len,u_char **ptr)
684    {
685       char *filename;
686       int fd;
687    
688       if (!(filename = vm_build_filename(vm,name))) {
689          fprintf(stderr,"vm_mmap_create_file: unable to create filename (%s)\n",
690                  name);
691          return(-1);
692       }
693    
694       if ((fd = memzone_create_file(filename,len,ptr)) == -1)
695          fprintf(stderr,"vm_mmap_create_file: unable to open file '%s' (%s)\n",
696                  filename,strerror(errno));
697    
698       free(filename);
699       return(fd);
700    }
701    
702    /* Close a memory mapped file */
703    int vm_mmap_close_file(int fd,u_char *ptr,size_t len)
704    {
705       if (ptr != NULL)
706          munmap(ptr,len);
707      
708       if (fd != -1)
709          close(fd);
710      
711       return(0);
712    }
713    
714  /* Save the Cisco IOS configuration from NVRAM */  /* Save the Cisco IOS configuration from NVRAM */
715  int vm_ios_save_config(vm_instance_t *vm)  int vm_ios_save_config(vm_instance_t *vm)
716  {  {

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

  ViewVC Help
Powered by ViewVC 1.1.26