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

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

upstream/dynamips-0.2.6-RC1/hv_vm.c revision 2 by dpavlin, Sat Oct 6 16:03:58 2007 UTC upstream/dynamips-0.2.7/hv_vm.c revision 10 by dpavlin, Sat Oct 6 16:29:14 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   * Cisco 7200 (Predator) 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   * Hypervisor generic VM routines.   * Hypervisor generic VM routines.
# Line 23  Line 23 
23  #include <arpa/inet.h>  #include <arpa/inet.h>
24  #include <pthread.h>  #include <pthread.h>
25    
26  #include "mips64.h"  #include "cpu.h"
27  #include "cp0.h"  #include "vm.h"
28  #include "dynamips.h"  #include "dynamips.h"
29  #include "device.h"  #include "device.h"
30  #include "dev_c7200.h"  #include "dev_c7200.h"
# Line 43  Line 43 
43  #include "registry.h"  #include "registry.h"
44  #include "hypervisor.h"  #include "hypervisor.h"
45    
46    /* Find the specified CPU */
47    static cpu_gen_t *find_cpu(hypervisor_conn_t *conn,vm_instance_t *vm,
48                               u_int cpu_id)
49    {
50       cpu_gen_t *cpu;
51    
52       cpu = cpu_group_find_id(vm->cpu_group,cpu_id);
53    
54       if (!cpu) {
55          vm_release(vm);
56          hypervisor_send_reply(conn,HSC_ERR_BAD_OBJ,1,"Bad CPU specified");
57          return NULL;
58       }
59      
60       return cpu;
61    }
62    
63  /* Set debugging level */  /* Set debugging level */
64  static int cmd_set_debug_level(hypervisor_conn_t *conn,int argc,char *argv[])  static int cmd_set_debug_level(hypervisor_conn_t *conn,int argc,char *argv[])
65  {  {
# Line 146  static int cmd_set_ram_mmap(hypervisor_c Line 163  static int cmd_set_ram_mmap(hypervisor_c
163     return(0);     return(0);
164  }  }
165    
166    /* Enable/disable use of sparse memory */
167    static int cmd_set_sparse_mem(hypervisor_conn_t *conn,int argc,char *argv[])
168    {
169       vm_instance_t *vm;
170    
171       if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
172          return(-1);
173    
174       vm->sparse_mem = atoi(argv[1]);
175    
176       vm_release(vm);
177       hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
178       return(0);
179    }
180    
181  /* Set the clock divisor */  /* Set the clock divisor */
182  static int cmd_set_clock_divisor(hypervisor_conn_t *conn,int argc,char *argv[])  static int cmd_set_clock_divisor(hypervisor_conn_t *conn,int argc,char *argv[])
183  {  {
# Line 163  static int cmd_set_clock_divisor(hypervi Line 195  static int cmd_set_clock_divisor(hypervi
195     return(0);     return(0);
196  }  }
197    
198    /* Enable/disable use of block direct jump (compatibility option) */
199    static int cmd_set_blk_direct_jump(hypervisor_conn_t *conn,
200                                       int argc,char *argv[])
201    {
202       vm_instance_t *vm;
203    
204       if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
205          return(-1);
206    
207       vm->exec_blk_direct_jump = atoi(argv[1]);
208    
209       vm_release(vm);
210       hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
211       return(0);
212    }
213    
214  /* Set the idle PC */  /* Set the idle PC */
215  static int cmd_set_idle_pc(hypervisor_conn_t *conn,int argc,char *argv[])  static int cmd_set_idle_pc(hypervisor_conn_t *conn,int argc,char *argv[])
216  {  {
# Line 178  static int cmd_set_idle_pc(hypervisor_co Line 226  static int cmd_set_idle_pc(hypervisor_co
226     return(0);     return(0);
227  }  }
228    
229    /* Set the idle PC value when the CPU is online */
230    static int cmd_set_idle_pc_online(hypervisor_conn_t *conn,
231                                      int argc,char *argv[])
232    {
233       vm_instance_t *vm;
234       cpu_gen_t *cpu;
235    
236       if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
237          return(-1);
238    
239       if (!(cpu = find_cpu(conn,vm,atoi(argv[1]))))
240          return(-1);
241    
242       cpu->set_idle_pc(cpu,strtoull(argv[2],NULL,0));
243    
244       vm_release(vm);
245       hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
246       return(0);
247    }
248    
249    /* Get the idle PC proposals */
250    static int cmd_get_idle_pc_prop(hypervisor_conn_t *conn,int argc,char *argv[])
251    {  
252       vm_instance_t *vm;
253       cpu_gen_t *cpu;
254       int i;
255    
256       if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
257          return(-1);
258    
259       if (!(cpu = find_cpu(conn,vm,atoi(argv[1]))))
260          return(-1);
261    
262       cpu->get_idling_pc(cpu);
263    
264       for(i=0;i<cpu->idle_pc_prop_count;i++) {
265          hypervisor_send_reply(conn,HSC_INFO_MSG,0,"0x%llx [%d]",
266                                cpu->idle_pc_prop[i].pc,
267                                cpu->idle_pc_prop[i].count);
268       }
269    
270       vm_release(vm);
271       hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
272       return(0);
273    }
274    
275    /* Dump the idle PC proposals */
276    static int cmd_show_idle_pc_prop(hypervisor_conn_t *conn,int argc,char *argv[])
277    {
278       vm_instance_t *vm;
279       cpu_gen_t *cpu;
280       int i;
281    
282       if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
283          return(-1);
284    
285       if (!(cpu = find_cpu(conn,vm,atoi(argv[1]))))
286          return(-1);
287    
288       for(i=0;i<cpu->idle_pc_prop_count;i++) {
289          hypervisor_send_reply(conn,HSC_INFO_MSG,0,"0x%llx [%d]",
290                                cpu->idle_pc_prop[i].pc,
291                                cpu->idle_pc_prop[i].count);
292       }
293    
294       vm_release(vm);
295       hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
296       return(0);
297    }
298    
299    /* Set CPU idle max value */
300    static int cmd_set_idle_max(hypervisor_conn_t *conn,int argc,char *argv[])
301    {
302       vm_instance_t *vm;
303       cpu_gen_t *cpu;
304    
305       if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
306          return(-1);
307    
308       if (!(cpu = find_cpu(conn,vm,atoi(argv[1]))))
309          return(-1);
310    
311       cpu->idle_max = atoi(argv[2]);
312    
313       vm_release(vm);
314       hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
315       return(0);
316    }
317    
318    /* Set CPU idle sleep time value */
319    static int cmd_set_idle_sleep_time(hypervisor_conn_t *conn,
320                                       int argc,char *argv[])
321    {
322       vm_instance_t *vm;
323       cpu_gen_t *cpu;
324    
325       if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
326          return(-1);
327    
328       if (!(cpu = find_cpu(conn,vm,atoi(argv[1]))))
329          return(-1);
330    
331       cpu->idle_sleep_time = atoi(argv[2]);
332    
333       vm_release(vm);
334       hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
335       return(0);
336    }
337    
338    /* Show info about potential timer drift */
339    static int cmd_show_timer_drift(hypervisor_conn_t *conn,
340                                    int argc,char *argv[])
341    {
342       vm_instance_t *vm;
343       cpu_gen_t *cpu;
344    
345       if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
346          return(-1);
347    
348       if (!(cpu = find_cpu(conn,vm,atoi(argv[1]))))
349          return(-1);
350    
351       if (cpu->type == CPU_TYPE_MIPS64) {
352          hypervisor_send_reply(conn,HSC_INFO_MSG,0,"Timer Drift: %u",
353                                CPU_MIPS64(cpu)->timer_drift);
354    
355          hypervisor_send_reply(conn,HSC_INFO_MSG,0,"Pending Timer IRQ: %u",
356                                CPU_MIPS64(cpu)->timer_irq_pending);      
357       }
358    
359       vm_release(vm);
360       hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
361       return(0);
362    }
363    
364  /* Set the exec area size */  /* Set the exec area size */
365  static int cmd_set_exec_area(hypervisor_conn_t *conn,int argc,char *argv[])  static int cmd_set_exec_area(hypervisor_conn_t *conn,int argc,char *argv[])
366  {  {
# Line 193  static int cmd_set_exec_area(hypervisor_ Line 376  static int cmd_set_exec_area(hypervisor_
376     return(0);     return(0);
377  }  }
378    
379    /* Set ghost RAM file */
380    static int cmd_set_ghost_file(hypervisor_conn_t *conn,int argc,char *argv[])
381    {
382       vm_instance_t *vm;
383    
384       if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
385          return(-1);
386    
387       vm->ghost_ram_filename = strdup(argv[1]);
388    
389       vm_release(vm);
390       hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
391       return(0);
392    }
393    
394    /* Set ghost RAM status */
395    static int cmd_set_ghost_status(hypervisor_conn_t *conn,int argc,char *argv[])
396    {
397       vm_instance_t *vm;
398    
399       if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
400          return(-1);
401    
402       vm->ghost_status = atoi(argv[1]);
403    
404       vm_release(vm);
405       hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
406       return(0);
407    }
408    
409    
410  /* Set PCMCIA ATA disk0 size */  /* Set PCMCIA ATA disk0 size */
411  static int cmd_set_disk0(hypervisor_conn_t *conn,int argc,char *argv[])  static int cmd_set_disk0(hypervisor_conn_t *conn,int argc,char *argv[])
412  {  {
# Line 358  static int cmd_push_config(hypervisor_co Line 572  static int cmd_push_config(hypervisor_co
572  static int cmd_show_cpu_info(hypervisor_conn_t *conn,int argc,char *argv[])  static int cmd_show_cpu_info(hypervisor_conn_t *conn,int argc,char *argv[])
573  {  {
574     vm_instance_t *vm;     vm_instance_t *vm;
575     cpu_mips_t *cpu;     cpu_gen_t *cpu;
576    
577     if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))     if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
578        return(-1);        return(-1);
# Line 366  static int cmd_show_cpu_info(hypervisor_ Line 580  static int cmd_show_cpu_info(hypervisor_
580     cpu = cpu_group_find_id(vm->cpu_group,atoi(argv[1]));     cpu = cpu_group_find_id(vm->cpu_group,atoi(argv[1]));
581    
582     if (cpu) {     if (cpu) {
583        mips64_dump_regs(cpu);        cpu->reg_dump(cpu);
584        tlb_dump(cpu);        cpu->mmu_dump(cpu);
585     }     }
586    
587     vm_release(vm);     vm_release(vm);
# Line 405  static int cmd_resume(hypervisor_conn_t Line 619  static int cmd_resume(hypervisor_conn_t
619     return(0);     return(0);
620  }  }
621    
622    /* Send a message on the console */
623    static int cmd_send_con_msg(hypervisor_conn_t *conn,int argc,char *argv[])
624    {
625       vm_instance_t *vm;
626    
627       if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
628          return(-1);
629    
630       vtty_store_str(vm->vtty_con,argv[1]);
631    
632       vm_release(vm);
633       hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
634       return(0);
635    }
636    
637    /* Send a message on the AUX port */
638    static int cmd_send_aux_msg(hypervisor_conn_t *conn,int argc,char *argv[])
639    {
640       vm_instance_t *vm;
641    
642       if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
643          return(-1);
644    
645       vtty_store_str(vm->vtty_aux,argv[1]);
646    
647       vm_release(vm);
648       hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
649       return(0);
650    }
651    
652  /* Show info about VM object */  /* Show info about VM object */
653  static void cmd_show_vm_list(registry_entry_t *entry,void *opt,int *err)  static void cmd_show_vm_list(registry_entry_t *entry,void *opt,int *err)
654  {  {
# Line 424  static int cmd_vm_list(hypervisor_conn_t Line 668  static int cmd_vm_list(hypervisor_conn_t
668     return(0);     return(0);
669  }  }
670    
671    /* Show console TCP port info about VM object */
672    static void cmd_show_vm_list_con_ports(registry_entry_t *entry,void *opt,
673                                           int *err)
674    {
675       hypervisor_conn_t *conn = opt;
676       vm_instance_t *vm = entry->data;
677    
678       if (vm->vtty_con_type == VTTY_TYPE_TCP)
679          hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%s (%d)",
680                                vm->name,vm->vtty_con_tcp_port);
681    }
682    
683    /* VM console TCP port list */
684    static int cmd_vm_list_con_ports(hypervisor_conn_t *conn,int argc,char *argv[])
685    {
686       int err = 0;
687       registry_foreach_type(OBJ_TYPE_VM,cmd_show_vm_list_con_ports,conn,&err);
688       hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
689       return(0);
690    }
691    
692  /* VM commands */  /* VM commands */
693  static hypervisor_cmd_t vm_cmd_array[] = {  static hypervisor_cmd_t vm_cmd_array[] = {
694     { "set_debug_level", 2, 2, cmd_set_debug_level, NULL },     { "set_debug_level", 2, 2, cmd_set_debug_level, NULL },
# Line 432  static hypervisor_cmd_t vm_cmd_array[] = Line 697  static hypervisor_cmd_t vm_cmd_array[] =
697     { "set_ram", 2, 2, cmd_set_ram, NULL },     { "set_ram", 2, 2, cmd_set_ram, NULL },
698     { "set_nvram", 2, 2, cmd_set_nvram, NULL },     { "set_nvram", 2, 2, cmd_set_nvram, NULL },
699     { "set_ram_mmap", 2, 2, cmd_set_ram_mmap, NULL },     { "set_ram_mmap", 2, 2, cmd_set_ram_mmap, NULL },
700       { "set_sparse_mem", 2, 2, cmd_set_sparse_mem, NULL },
701     { "set_clock_divisor", 2, 2, cmd_set_clock_divisor, NULL },     { "set_clock_divisor", 2, 2, cmd_set_clock_divisor, NULL },
702       { "set_blk_direct_jump", 2, 2, cmd_set_blk_direct_jump, NULL },
703     { "set_exec_area", 2, 2, cmd_set_exec_area, NULL },     { "set_exec_area", 2, 2, cmd_set_exec_area, NULL },
704     { "set_disk0", 2, 2, cmd_set_disk0, NULL },     { "set_disk0", 2, 2, cmd_set_disk0, NULL },
705     { "set_disk1", 2, 2, cmd_set_disk1, NULL },     { "set_disk1", 2, 2, cmd_set_disk1, NULL },
706     { "set_conf_reg", 2, 2, cmd_set_conf_reg, NULL },     { "set_conf_reg", 2, 2, cmd_set_conf_reg, NULL },
707     { "set_idle_pc", 2, 2, cmd_set_idle_pc, NULL },     { "set_idle_pc", 2, 2, cmd_set_idle_pc, NULL },
708       { "set_idle_pc_online", 3, 3, cmd_set_idle_pc_online, NULL },
709       { "get_idle_pc_prop", 2, 2, cmd_get_idle_pc_prop, NULL },
710       { "show_idle_pc_prop", 2, 2, cmd_show_idle_pc_prop, NULL },
711       { "set_idle_max", 3, 3, cmd_set_idle_max, NULL },
712       { "set_idle_sleep_time", 3, 3, cmd_set_idle_sleep_time, NULL },
713       { "show_timer_drift", 2, 2, cmd_show_timer_drift, NULL },
714       { "set_ghost_file", 2, 2, cmd_set_ghost_file, NULL },
715       { "set_ghost_status", 2, 2, cmd_set_ghost_status, NULL },
716     { "set_con_tcp_port", 2, 2, cmd_set_con_tcp_port, NULL },     { "set_con_tcp_port", 2, 2, cmd_set_con_tcp_port, NULL },
717     { "set_aux_tcp_port", 2, 2, cmd_set_aux_tcp_port, NULL },     { "set_aux_tcp_port", 2, 2, cmd_set_aux_tcp_port, NULL },
718     { "extract_config", 1, 1, cmd_extract_config, NULL },     { "extract_config", 1, 1, cmd_extract_config, NULL },
# Line 445  static hypervisor_cmd_t vm_cmd_array[] = Line 720  static hypervisor_cmd_t vm_cmd_array[] =
720     { "cpu_info", 2, 2, cmd_show_cpu_info, NULL },     { "cpu_info", 2, 2, cmd_show_cpu_info, NULL },
721     { "suspend", 1, 1, cmd_suspend, NULL },     { "suspend", 1, 1, cmd_suspend, NULL },
722     { "resume", 1, 1, cmd_resume, NULL },     { "resume", 1, 1, cmd_resume, NULL },
723       { "send_con_msg", 2, 2, cmd_send_con_msg, NULL },
724       { "send_aux_msg", 2, 2, cmd_send_aux_msg, NULL },
725     { "list", 0, 0, cmd_vm_list, NULL },     { "list", 0, 0, cmd_vm_list, NULL },
726       { "list_con_ports", 0, 0, cmd_vm_list_con_ports, NULL },
727     { NULL, -1, -1, NULL, NULL },     { NULL, -1, -1, NULL, NULL },
728  };  };
729    

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

  ViewVC Help
Powered by ViewVC 1.1.26