/[dynamips]/trunk/hv_vm_debug.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

Annotation of /trunk/hv_vm_debug.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (hide annotations)
Sat Oct 6 16:33:40 2007 UTC (16 years, 5 months ago) by dpavlin
Original Path: upstream/dynamips-0.2.8-RC1/hv_vm_debug.c
File MIME type: text/plain
File size: 6185 byte(s)
dynamips-0.2.8-RC1

1 dpavlin 2 /*
2 dpavlin 7 * Cisco router simulation platform.
3 dpavlin 2 * Copyright (c) 2006 Christophe Fillot (cf@utc.fr)
4     *
5     * Hypervisor routines for VM debugging.
6     */
7    
8     #include <stdio.h>
9     #include <stdlib.h>
10     #include <unistd.h>
11     #include <string.h>
12     #include <sys/types.h>
13     #include <sys/stat.h>
14     #include <sys/mman.h>
15     #include <signal.h>
16     #include <fcntl.h>
17     #include <errno.h>
18     #include <assert.h>
19     #include <stdarg.h>
20     #include <sys/ioctl.h>
21     #include <sys/types.h>
22     #include <sys/socket.h>
23     #include <arpa/inet.h>
24     #include <pthread.h>
25    
26 dpavlin 7 #include "cpu.h"
27     #include "vm.h"
28 dpavlin 2 #include "dynamips.h"
29     #include "device.h"
30     #include "dev_c7200.h"
31     #include "dev_vtty.h"
32     #include "utils.h"
33     #include "registry.h"
34     #include "hypervisor.h"
35    
36     /* Show CPU registers */
37     static int cmd_show_cpu_regs(hypervisor_conn_t *conn,int argc,char *argv[])
38     {
39     vm_instance_t *vm;
40 dpavlin 7 cpu_gen_t *cpu;
41 dpavlin 2
42     if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
43     return(-1);
44    
45     if ((cpu = cpu_group_find_id(vm->cpu_group,atoi(argv[1]))) != NULL)
46 dpavlin 7 cpu->reg_dump(cpu);
47 dpavlin 2
48     vm_release(vm);
49     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
50     return(0);
51     }
52    
53 dpavlin 7 /* Show CPU MMU info */
54     static int cmd_show_cpu_mmu(hypervisor_conn_t *conn,int argc,char *argv[])
55 dpavlin 2 {
56     vm_instance_t *vm;
57 dpavlin 7 cpu_gen_t *cpu;
58 dpavlin 2
59     if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
60     return(-1);
61    
62     if ((cpu = cpu_group_find_id(vm->cpu_group,atoi(argv[1]))) != NULL)
63 dpavlin 7 cpu->mmu_dump(cpu);
64 dpavlin 2
65     vm_release(vm);
66     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
67     return(0);
68     }
69    
70 dpavlin 7 /* Set a CPU register */
71 dpavlin 2 static int cmd_set_cpu_reg(hypervisor_conn_t *conn,int argc,char *argv[])
72     {
73     vm_instance_t *vm;
74 dpavlin 7 cpu_gen_t *cpu;
75 dpavlin 2 int reg_index;
76    
77     if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
78     return(-1);
79    
80     cpu = cpu_group_find_id(vm->cpu_group,atoi(argv[1]));
81 dpavlin 7 reg_index = atoi(argv[2]);
82 dpavlin 2
83     if (!cpu || (reg_index < 1)) {
84     vm_release(vm);
85     hypervisor_send_reply(conn,HSC_ERR_BAD_OBJ,1,"Bad CPU or register");
86     return(-1);
87     }
88    
89     /* Set register value */
90 dpavlin 7 cpu->reg_set(cpu,reg_index,strtoull(argv[3],NULL,0));
91 dpavlin 2
92     vm_release(vm);
93     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
94     return(0);
95     }
96    
97     /* Add a breakpoint */
98     static int cmd_add_cpu_breakpoint(hypervisor_conn_t *conn,
99     int argc,char *argv[])
100     {
101     vm_instance_t *vm;
102 dpavlin 7 cpu_gen_t *cpu;
103 dpavlin 2 m_uint64_t addr;
104    
105     if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
106     return(-1);
107    
108     if (!(cpu = cpu_group_find_id(vm->cpu_group,atoi(argv[1])))) {
109     vm_release(vm);
110     hypervisor_send_reply(conn,HSC_ERR_BAD_OBJ,1,"Bad CPU");
111     return(-1);
112     }
113    
114     addr = strtoull(argv[2],NULL,0);
115 dpavlin 7 cpu->add_breakpoint(cpu,addr);
116 dpavlin 2
117     vm_release(vm);
118     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
119     return(0);
120     }
121    
122     /* Remove a breakpoint */
123     static int cmd_remove_cpu_breakpoint(hypervisor_conn_t *conn,
124     int argc,char *argv[])
125     {
126     vm_instance_t *vm;
127 dpavlin 7 cpu_gen_t *cpu;
128 dpavlin 2 m_uint64_t addr;
129    
130     if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
131     return(-1);
132    
133     if (!(cpu = cpu_group_find_id(vm->cpu_group,atoi(argv[1])))) {
134     vm_release(vm);
135     hypervisor_send_reply(conn,HSC_ERR_BAD_OBJ,1,"Bad CPU");
136     return(-1);
137     }
138    
139     addr = strtoull(argv[2],NULL,0);
140 dpavlin 7 cpu->remove_breakpoint(cpu,addr);
141 dpavlin 2
142     vm_release(vm);
143     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
144     return(0);
145     }
146    
147     /* Write a 32-bit memory word in physical memory */
148     static int cmd_pmem_w32(hypervisor_conn_t *conn,int argc,char *argv[])
149     {
150     vm_instance_t *vm;
151     m_uint64_t addr;
152     m_uint32_t value;
153    
154     if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
155     return(-1);
156    
157     /* Write word */
158     addr = strtoull(argv[2],NULL,0);
159     value = strtoul(argv[3],NULL,0);
160     physmem_copy_u32_to_vm(vm,addr,value);
161    
162     vm_release(vm);
163     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
164     return(0);
165     }
166    
167     /* Read a 32-bit memory word */
168     static int cmd_pmem_r32(hypervisor_conn_t *conn,int argc,char *argv[])
169     {
170     vm_instance_t *vm;
171     m_uint64_t addr;
172     m_uint32_t value;
173    
174     if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
175     return(-1);
176    
177     /* Write word */
178     addr = strtoull(argv[2],NULL,0);
179     value = physmem_copy_u32_from_vm(vm,addr);
180    
181     vm_release(vm);
182     hypervisor_send_reply(conn,HSC_INFO_OK,1,"0x%8.8x",value);
183     return(0);
184     }
185    
186     /* Write a 16-bit memory word */
187     static int cmd_pmem_w16(hypervisor_conn_t *conn,int argc,char *argv[])
188     {
189     vm_instance_t *vm;
190     m_uint64_t addr;
191     m_uint16_t value;
192    
193     if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
194     return(-1);
195    
196     /* Write word */
197     addr = strtoull(argv[2],NULL,0);
198     value = strtoul(argv[3],NULL,0);
199     physmem_copy_u16_to_vm(vm,addr,value);
200    
201     vm_release(vm);
202     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
203     return(0);
204     }
205    
206     /* Read a 16-bit memory word */
207     static int cmd_pmem_r16(hypervisor_conn_t *conn,int argc,char *argv[])
208     {
209     vm_instance_t *vm;
210     m_uint64_t addr;
211     m_uint16_t value;
212    
213     if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
214     return(-1);
215    
216     /* Write word */
217     addr = strtoull(argv[2],NULL,0);
218     value = physmem_copy_u16_from_vm(vm,addr);
219    
220     vm_release(vm);
221     hypervisor_send_reply(conn,HSC_INFO_OK,1,"0x%4.4x",value);
222     return(0);
223     }
224    
225     /* VM debug commands */
226     static hypervisor_cmd_t vm_cmd_array[] = {
227     { "show_cpu_regs", 2, 2, cmd_show_cpu_regs, NULL },
228 dpavlin 7 { "show_cpu_mmu", 2, 2, cmd_show_cpu_mmu, NULL },
229 dpavlin 2 { "set_cpu_reg", 4, 4, cmd_set_cpu_reg, NULL },
230     { "add_cpu_breakpoint", 3, 3, cmd_add_cpu_breakpoint, NULL },
231     { "remove_cpu_breakpoint", 3, 3, cmd_remove_cpu_breakpoint, NULL },
232     { "pmem_w32", 4, 4, cmd_pmem_w32, NULL },
233     { "pmem_r32", 3, 3, cmd_pmem_r32, NULL },
234     { "pmem_w16", 4, 4, cmd_pmem_w16, NULL },
235     { "pmem_r16", 3, 3, cmd_pmem_r16, NULL },
236     { NULL, -1, -1, NULL, NULL },
237     };
238    
239     /* Hypervisor VM debugging initialization */
240     int hypervisor_vm_debug_init(void)
241     {
242     hypervisor_module_t *module;
243    
244 dpavlin 11 module = hypervisor_register_module("vm_debug",NULL);
245 dpavlin 2 assert(module != NULL);
246    
247     hypervisor_register_cmd_array(module,vm_cmd_array);
248     return(0);
249     }

  ViewVC Help
Powered by ViewVC 1.1.26