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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6 - (hide annotations)
Sat Oct 6 16:09:07 2007 UTC (16 years, 5 months ago) by dpavlin
File MIME type: text/plain
File size: 7141 byte(s)
dynamips-0.2.6-RC5

1 dpavlin 2 /*
2     * Cisco 7200 (Predator) simulation platform.
3     * 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     #include "mips64.h"
27     #include "cp0.h"
28     #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     cpu_mips_t *cpu;
41    
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     mips64_dump_regs(cpu);
47    
48     vm_release(vm);
49     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
50     return(0);
51     }
52    
53     /* Show CPU TLB */
54     static int cmd_show_cpu_tlb(hypervisor_conn_t *conn,int argc,char *argv[])
55     {
56     vm_instance_t *vm;
57     cpu_mips_t *cpu;
58    
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     tlb_dump(cpu);
64    
65     vm_release(vm);
66     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
67     return(0);
68     }
69    
70     /* Set a CPU register*/
71     static int cmd_set_cpu_reg(hypervisor_conn_t *conn,int argc,char *argv[])
72     {
73     vm_instance_t *vm;
74     cpu_mips_t *cpu;
75     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     reg_index = cp0_get_reg_index(argv[2]);
82    
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     cpu->gpr[reg_index] = strtoull(argv[3],NULL,0);
91    
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     cpu_mips_t *cpu;
103     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     mips64_add_breakpoint(cpu,addr);
116    
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     cpu_mips_t *cpu;
128     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     mips64_remove_breakpoint(cpu,addr);
141    
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     cpu_mips_t *cpu;
152     m_uint64_t addr;
153     m_uint32_t value;
154    
155     if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
156     return(-1);
157    
158     cpu = cpu_group_find_id(vm->cpu_group,atoi(argv[1]));
159    
160     if (!cpu) {
161     vm_release(vm);
162     hypervisor_send_reply(conn,HSC_ERR_BAD_OBJ,1,"No CPU found.");
163     return(-1);
164     }
165    
166     /* Write word */
167     addr = strtoull(argv[2],NULL,0);
168     value = strtoul(argv[3],NULL,0);
169     physmem_copy_u32_to_vm(vm,addr,value);
170    
171     vm_release(vm);
172     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
173     return(0);
174     }
175    
176     /* Read a 32-bit memory word */
177     static int cmd_pmem_r32(hypervisor_conn_t *conn,int argc,char *argv[])
178     {
179     vm_instance_t *vm;
180     cpu_mips_t *cpu;
181     m_uint64_t addr;
182     m_uint32_t value;
183    
184     if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
185     return(-1);
186    
187     cpu = cpu_group_find_id(vm->cpu_group,atoi(argv[1]));
188    
189     if (!cpu) {
190     vm_release(vm);
191     hypervisor_send_reply(conn,HSC_ERR_BAD_OBJ,1,"No CPU found.");
192     return(-1);
193     }
194    
195     /* Write word */
196     addr = strtoull(argv[2],NULL,0);
197     value = physmem_copy_u32_from_vm(vm,addr);
198    
199     vm_release(vm);
200     hypervisor_send_reply(conn,HSC_INFO_OK,1,"0x%8.8x",value);
201     return(0);
202     }
203    
204     /* Write a 16-bit memory word */
205     static int cmd_pmem_w16(hypervisor_conn_t *conn,int argc,char *argv[])
206     {
207     vm_instance_t *vm;
208     cpu_mips_t *cpu;
209     m_uint64_t addr;
210     m_uint16_t value;
211    
212     if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
213     return(-1);
214    
215     cpu = cpu_group_find_id(vm->cpu_group,atoi(argv[1]));
216    
217     if (!cpu) {
218     vm_release(vm);
219     hypervisor_send_reply(conn,HSC_ERR_BAD_OBJ,1,"No CPU found.");
220     return(-1);
221     }
222    
223     /* Write word */
224     addr = strtoull(argv[2],NULL,0);
225     value = strtoul(argv[3],NULL,0);
226     physmem_copy_u16_to_vm(vm,addr,value);
227    
228     vm_release(vm);
229     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
230     return(0);
231     }
232    
233     /* Read a 16-bit memory word */
234     static int cmd_pmem_r16(hypervisor_conn_t *conn,int argc,char *argv[])
235     {
236     vm_instance_t *vm;
237     cpu_mips_t *cpu;
238     m_uint64_t addr;
239     m_uint16_t value;
240    
241     if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))
242     return(-1);
243    
244     cpu = cpu_group_find_id(vm->cpu_group,atoi(argv[1]));
245    
246     if (!cpu) {
247     vm_release(vm);
248     hypervisor_send_reply(conn,HSC_ERR_BAD_OBJ,1,"No CPU found.");
249     return(-1);
250     }
251    
252     /* Write word */
253     addr = strtoull(argv[2],NULL,0);
254     value = physmem_copy_u16_from_vm(vm,addr);
255    
256     vm_release(vm);
257     hypervisor_send_reply(conn,HSC_INFO_OK,1,"0x%4.4x",value);
258     return(0);
259     }
260    
261     /* VM debug commands */
262     static hypervisor_cmd_t vm_cmd_array[] = {
263     { "show_cpu_regs", 2, 2, cmd_show_cpu_regs, NULL },
264     { "show_cpu_tlb", 2, 2, cmd_show_cpu_tlb, NULL },
265     { "set_cpu_reg", 4, 4, cmd_set_cpu_reg, NULL },
266     { "add_cpu_breakpoint", 3, 3, cmd_add_cpu_breakpoint, NULL },
267     { "remove_cpu_breakpoint", 3, 3, cmd_remove_cpu_breakpoint, NULL },
268     { "pmem_w32", 4, 4, cmd_pmem_w32, NULL },
269     { "pmem_r32", 3, 3, cmd_pmem_r32, NULL },
270     { "pmem_w16", 4, 4, cmd_pmem_w16, NULL },
271     { "pmem_r16", 3, 3, cmd_pmem_r16, NULL },
272     { NULL, -1, -1, NULL, NULL },
273     };
274    
275     /* Hypervisor VM debugging initialization */
276     int hypervisor_vm_debug_init(void)
277     {
278     hypervisor_module_t *module;
279    
280     module = hypervisor_register_module("vm_debug");
281     assert(module != NULL);
282    
283     hypervisor_register_cmd_array(module,vm_cmd_array);
284     return(0);
285     }

  ViewVC Help
Powered by ViewVC 1.1.26