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. |
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" |
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 |
{ |
{ |
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 |
{ |
{ |
210 |
return(0); |
return(0); |
211 |
} |
} |
212 |
|
|
213 |
|
/* Set the idle PC value when the CPU is online */ |
214 |
|
static int cmd_set_idle_pc_online(hypervisor_conn_t *conn, |
215 |
|
int argc,char *argv[]) |
216 |
|
{ |
217 |
|
vm_instance_t *vm; |
218 |
|
cpu_gen_t *cpu; |
219 |
|
|
220 |
|
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
221 |
|
return(-1); |
222 |
|
|
223 |
|
if (!(cpu = find_cpu(conn,vm,atoi(argv[1])))) |
224 |
|
return(-1); |
225 |
|
|
226 |
|
cpu->set_idle_pc(cpu,strtoull(argv[2],NULL,0)); |
227 |
|
|
228 |
|
vm_release(vm); |
229 |
|
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
230 |
|
return(0); |
231 |
|
} |
232 |
|
|
233 |
|
/* Get the idle PC proposals */ |
234 |
|
static int cmd_get_idle_pc_prop(hypervisor_conn_t *conn,int argc,char *argv[]) |
235 |
|
{ |
236 |
|
vm_instance_t *vm; |
237 |
|
cpu_gen_t *cpu; |
238 |
|
int i; |
239 |
|
|
240 |
|
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
241 |
|
return(-1); |
242 |
|
|
243 |
|
if (!(cpu = find_cpu(conn,vm,atoi(argv[1])))) |
244 |
|
return(-1); |
245 |
|
|
246 |
|
cpu->get_idling_pc(cpu); |
247 |
|
|
248 |
|
for(i=0;i<cpu->idle_pc_prop_count;i++) { |
249 |
|
hypervisor_send_reply(conn,HSC_INFO_MSG,0,"0x%llx [%d]", |
250 |
|
cpu->idle_pc_prop[i].pc, |
251 |
|
cpu->idle_pc_prop[i].count); |
252 |
|
} |
253 |
|
|
254 |
|
vm_release(vm); |
255 |
|
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
256 |
|
return(0); |
257 |
|
} |
258 |
|
|
259 |
|
/* Dump the idle PC proposals */ |
260 |
|
static int cmd_show_idle_pc_prop(hypervisor_conn_t *conn,int argc,char *argv[]) |
261 |
|
{ |
262 |
|
vm_instance_t *vm; |
263 |
|
cpu_gen_t *cpu; |
264 |
|
int i; |
265 |
|
|
266 |
|
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
267 |
|
return(-1); |
268 |
|
|
269 |
|
if (!(cpu = find_cpu(conn,vm,atoi(argv[1])))) |
270 |
|
return(-1); |
271 |
|
|
272 |
|
for(i=0;i<cpu->idle_pc_prop_count;i++) { |
273 |
|
hypervisor_send_reply(conn,HSC_INFO_MSG,0,"0x%llx [%d]", |
274 |
|
cpu->idle_pc_prop[i].pc, |
275 |
|
cpu->idle_pc_prop[i].count); |
276 |
|
} |
277 |
|
|
278 |
|
vm_release(vm); |
279 |
|
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
280 |
|
return(0); |
281 |
|
} |
282 |
|
|
283 |
|
/* Set CPU idle max value */ |
284 |
|
static int cmd_set_idle_max(hypervisor_conn_t *conn,int argc,char *argv[]) |
285 |
|
{ |
286 |
|
vm_instance_t *vm; |
287 |
|
cpu_gen_t *cpu; |
288 |
|
|
289 |
|
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
290 |
|
return(-1); |
291 |
|
|
292 |
|
if (!(cpu = find_cpu(conn,vm,atoi(argv[1])))) |
293 |
|
return(-1); |
294 |
|
|
295 |
|
cpu->idle_max = atoi(argv[2]); |
296 |
|
|
297 |
|
vm_release(vm); |
298 |
|
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
299 |
|
return(0); |
300 |
|
} |
301 |
|
|
302 |
|
/* Set CPU idle sleep time value */ |
303 |
|
static int cmd_set_idle_sleep_time(hypervisor_conn_t *conn, |
304 |
|
int argc,char *argv[]) |
305 |
|
{ |
306 |
|
vm_instance_t *vm; |
307 |
|
cpu_gen_t *cpu; |
308 |
|
|
309 |
|
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
310 |
|
return(-1); |
311 |
|
|
312 |
|
if (!(cpu = find_cpu(conn,vm,atoi(argv[1])))) |
313 |
|
return(-1); |
314 |
|
|
315 |
|
cpu->idle_sleep_time = atoi(argv[2]); |
316 |
|
|
317 |
|
vm_release(vm); |
318 |
|
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
319 |
|
return(0); |
320 |
|
} |
321 |
|
|
322 |
|
/* Show info about potential timer drift */ |
323 |
|
static int cmd_show_timer_drift(hypervisor_conn_t *conn, |
324 |
|
int argc,char *argv[]) |
325 |
|
{ |
326 |
|
vm_instance_t *vm; |
327 |
|
cpu_gen_t *cpu; |
328 |
|
|
329 |
|
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
330 |
|
return(-1); |
331 |
|
|
332 |
|
if (!(cpu = find_cpu(conn,vm,atoi(argv[1])))) |
333 |
|
return(-1); |
334 |
|
|
335 |
|
if (cpu->type == CPU_TYPE_MIPS64) { |
336 |
|
hypervisor_send_reply(conn,HSC_INFO_MSG,0,"Timer Drift: %u", |
337 |
|
CPU_MIPS64(cpu)->timer_drift); |
338 |
|
|
339 |
|
hypervisor_send_reply(conn,HSC_INFO_MSG,0,"Pending Timer IRQ: %u", |
340 |
|
CPU_MIPS64(cpu)->timer_irq_pending); |
341 |
|
} |
342 |
|
|
343 |
|
vm_release(vm); |
344 |
|
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
345 |
|
return(0); |
346 |
|
} |
347 |
|
|
348 |
/* Set the exec area size */ |
/* Set the exec area size */ |
349 |
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[]) |
350 |
{ |
{ |
360 |
return(0); |
return(0); |
361 |
} |
} |
362 |
|
|
363 |
|
/* Set ghost RAM file */ |
364 |
|
static int cmd_set_ghost_file(hypervisor_conn_t *conn,int argc,char *argv[]) |
365 |
|
{ |
366 |
|
vm_instance_t *vm; |
367 |
|
|
368 |
|
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
369 |
|
return(-1); |
370 |
|
|
371 |
|
vm->ghost_ram_filename = strdup(argv[1]); |
372 |
|
|
373 |
|
vm_release(vm); |
374 |
|
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
375 |
|
return(0); |
376 |
|
} |
377 |
|
|
378 |
|
/* Set ghost RAM status */ |
379 |
|
static int cmd_set_ghost_status(hypervisor_conn_t *conn,int argc,char *argv[]) |
380 |
|
{ |
381 |
|
vm_instance_t *vm; |
382 |
|
|
383 |
|
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
384 |
|
return(-1); |
385 |
|
|
386 |
|
vm->ghost_status = atoi(argv[1]); |
387 |
|
|
388 |
|
vm_release(vm); |
389 |
|
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
390 |
|
return(0); |
391 |
|
} |
392 |
|
|
393 |
|
|
394 |
/* Set PCMCIA ATA disk0 size */ |
/* Set PCMCIA ATA disk0 size */ |
395 |
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[]) |
396 |
{ |
{ |
556 |
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[]) |
557 |
{ |
{ |
558 |
vm_instance_t *vm; |
vm_instance_t *vm; |
559 |
cpu_mips_t *cpu; |
cpu_gen_t *cpu; |
560 |
|
|
561 |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
562 |
return(-1); |
return(-1); |
564 |
cpu = cpu_group_find_id(vm->cpu_group,atoi(argv[1])); |
cpu = cpu_group_find_id(vm->cpu_group,atoi(argv[1])); |
565 |
|
|
566 |
if (cpu) { |
if (cpu) { |
567 |
mips64_dump_regs(cpu); |
cpu->reg_dump(cpu); |
568 |
tlb_dump(cpu); |
cpu->mmu_dump(cpu); |
569 |
} |
} |
570 |
|
|
571 |
vm_release(vm); |
vm_release(vm); |
603 |
return(0); |
return(0); |
604 |
} |
} |
605 |
|
|
606 |
|
/* Send a message on the console */ |
607 |
|
static int cmd_send_con_msg(hypervisor_conn_t *conn,int argc,char *argv[]) |
608 |
|
{ |
609 |
|
vm_instance_t *vm; |
610 |
|
|
611 |
|
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
612 |
|
return(-1); |
613 |
|
|
614 |
|
vtty_store_str(vm->vtty_con,argv[1]); |
615 |
|
|
616 |
|
vm_release(vm); |
617 |
|
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
618 |
|
return(0); |
619 |
|
} |
620 |
|
|
621 |
|
/* Send a message on the AUX port */ |
622 |
|
static int cmd_send_aux_msg(hypervisor_conn_t *conn,int argc,char *argv[]) |
623 |
|
{ |
624 |
|
vm_instance_t *vm; |
625 |
|
|
626 |
|
if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) |
627 |
|
return(-1); |
628 |
|
|
629 |
|
vtty_store_str(vm->vtty_aux,argv[1]); |
630 |
|
|
631 |
|
vm_release(vm); |
632 |
|
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
633 |
|
return(0); |
634 |
|
} |
635 |
|
|
636 |
/* Show info about VM object */ |
/* Show info about VM object */ |
637 |
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) |
638 |
{ |
{ |
652 |
return(0); |
return(0); |
653 |
} |
} |
654 |
|
|
655 |
|
/* Show console TCP port info about VM object */ |
656 |
|
static void cmd_show_vm_list_con_ports(registry_entry_t *entry,void *opt, |
657 |
|
int *err) |
658 |
|
{ |
659 |
|
hypervisor_conn_t *conn = opt; |
660 |
|
vm_instance_t *vm = entry->data; |
661 |
|
|
662 |
|
if (vm->vtty_con_type == VTTY_TYPE_TCP) |
663 |
|
hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%s (%d)", |
664 |
|
vm->name,vm->vtty_con_tcp_port); |
665 |
|
} |
666 |
|
|
667 |
|
/* VM console TCP port list */ |
668 |
|
static int cmd_vm_list_con_ports(hypervisor_conn_t *conn,int argc,char *argv[]) |
669 |
|
{ |
670 |
|
int err = 0; |
671 |
|
registry_foreach_type(OBJ_TYPE_VM,cmd_show_vm_list_con_ports,conn,&err); |
672 |
|
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
673 |
|
return(0); |
674 |
|
} |
675 |
|
|
676 |
/* VM commands */ |
/* VM commands */ |
677 |
static hypervisor_cmd_t vm_cmd_array[] = { |
static hypervisor_cmd_t vm_cmd_array[] = { |
678 |
{ "set_debug_level", 2, 2, cmd_set_debug_level, NULL }, |
{ "set_debug_level", 2, 2, cmd_set_debug_level, NULL }, |
681 |
{ "set_ram", 2, 2, cmd_set_ram, NULL }, |
{ "set_ram", 2, 2, cmd_set_ram, NULL }, |
682 |
{ "set_nvram", 2, 2, cmd_set_nvram, NULL }, |
{ "set_nvram", 2, 2, cmd_set_nvram, NULL }, |
683 |
{ "set_ram_mmap", 2, 2, cmd_set_ram_mmap, NULL }, |
{ "set_ram_mmap", 2, 2, cmd_set_ram_mmap, NULL }, |
684 |
|
{ "set_sparse_mem", 2, 2, cmd_set_sparse_mem, NULL }, |
685 |
{ "set_clock_divisor", 2, 2, cmd_set_clock_divisor, NULL }, |
{ "set_clock_divisor", 2, 2, cmd_set_clock_divisor, NULL }, |
686 |
{ "set_exec_area", 2, 2, cmd_set_exec_area, NULL }, |
{ "set_exec_area", 2, 2, cmd_set_exec_area, NULL }, |
687 |
{ "set_disk0", 2, 2, cmd_set_disk0, NULL }, |
{ "set_disk0", 2, 2, cmd_set_disk0, NULL }, |
688 |
{ "set_disk1", 2, 2, cmd_set_disk1, NULL }, |
{ "set_disk1", 2, 2, cmd_set_disk1, NULL }, |
689 |
{ "set_conf_reg", 2, 2, cmd_set_conf_reg, NULL }, |
{ "set_conf_reg", 2, 2, cmd_set_conf_reg, NULL }, |
690 |
{ "set_idle_pc", 2, 2, cmd_set_idle_pc, NULL }, |
{ "set_idle_pc", 2, 2, cmd_set_idle_pc, NULL }, |
691 |
|
{ "set_idle_pc_online", 3, 3, cmd_set_idle_pc_online, NULL }, |
692 |
|
{ "get_idle_pc_prop", 2, 2, cmd_get_idle_pc_prop, NULL }, |
693 |
|
{ "show_idle_pc_prop", 2, 2, cmd_show_idle_pc_prop, NULL }, |
694 |
|
{ "set_idle_max", 3, 3, cmd_set_idle_max, NULL }, |
695 |
|
{ "set_idle_sleep_time", 3, 3, cmd_set_idle_sleep_time, NULL }, |
696 |
|
{ "show_timer_drift", 2, 2, cmd_show_timer_drift, NULL }, |
697 |
|
{ "set_ghost_file", 2, 2, cmd_set_ghost_file, NULL }, |
698 |
|
{ "set_ghost_status", 2, 2, cmd_set_ghost_status, NULL }, |
699 |
{ "set_con_tcp_port", 2, 2, cmd_set_con_tcp_port, NULL }, |
{ "set_con_tcp_port", 2, 2, cmd_set_con_tcp_port, NULL }, |
700 |
{ "set_aux_tcp_port", 2, 2, cmd_set_aux_tcp_port, NULL }, |
{ "set_aux_tcp_port", 2, 2, cmd_set_aux_tcp_port, NULL }, |
701 |
{ "extract_config", 1, 1, cmd_extract_config, NULL }, |
{ "extract_config", 1, 1, cmd_extract_config, NULL }, |
703 |
{ "cpu_info", 2, 2, cmd_show_cpu_info, NULL }, |
{ "cpu_info", 2, 2, cmd_show_cpu_info, NULL }, |
704 |
{ "suspend", 1, 1, cmd_suspend, NULL }, |
{ "suspend", 1, 1, cmd_suspend, NULL }, |
705 |
{ "resume", 1, 1, cmd_resume, NULL }, |
{ "resume", 1, 1, cmd_resume, NULL }, |
706 |
|
{ "send_con_msg", 2, 2, cmd_send_con_msg, NULL }, |
707 |
|
{ "send_aux_msg", 2, 2, cmd_send_aux_msg, NULL }, |
708 |
{ "list", 0, 0, cmd_vm_list, NULL }, |
{ "list", 0, 0, cmd_vm_list, NULL }, |
709 |
|
{ "list_con_ports", 0, 0, cmd_vm_list_con_ports, NULL }, |
710 |
{ NULL, -1, -1, NULL, NULL }, |
{ NULL, -1, -1, NULL, NULL }, |
711 |
}; |
}; |
712 |
|
|