2 * This file is part of the Palacios Virtual Machine Monitor developed
3 * by the V3VEE Project with funding from the United States National
4 * Science Foundation and the Department of Energy.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
10 * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu>
11 * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org>
12 * All rights reserved.
14 * Author: Jack Lange <jarusl@cs.northwestern.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
21 #include <palacios/vmm_inspector.h>
22 #include <palacios/vmm.h>
23 #include <palacios/vm_guest.h>
24 #include <palacios/vmm_sprintf.h>
26 // Note that v3_inspect_node_t is actuall a struct v3_mtree
27 // Its set as void for opaque portability
30 int v3_init_inspector(struct v3_vm_info * vm) {
31 struct v3_inspector_state * state = (struct v3_inspector_state *)&(vm->inspector);
33 memset(state, 0, sizeof(struct v3_inspector_state));
35 strncpy(state->state_tree.name, "vm->name", 50);
36 state->state_tree.subtree = 1;
42 int v3_init_inspector_core(struct guest_info * core) {
43 struct v3_inspector_state * vm_state = &(core->vm_info->inspector);
46 snprintf(core_name, 50, "core.%d", core->cpu_id);
49 struct v3_mtree * core_node = v3_mtree_create_subtree(&(vm_state->state_tree), core_name);
50 v3_inspect_64(core_node, "RIP", (uint64_t *)&(core->rip));
51 v3_inspect_64(core_node, "NUM_EXITS", (uint64_t *)&(core->num_exits));
52 // v3_inspect_buf(core_node, "EXEC_NAME", core->exec_name, sizeof(core->exec_name));
55 struct v3_mtree * gpr_node = v3_mtree_create_subtree(core_node, "GPRS");
56 v3_inspect_64(gpr_node, "RAX", (uint64_t *)&(core->vm_regs.rax));
57 v3_inspect_64(gpr_node, "RBX", (uint64_t *)&(core->vm_regs.rbx));
58 v3_inspect_64(gpr_node, "RCX", (uint64_t *)&(core->vm_regs.rcx));
59 v3_inspect_64(gpr_node, "RDX", (uint64_t *)&(core->vm_regs.rdx));
60 v3_inspect_64(gpr_node, "RSP", (uint64_t *)&(core->vm_regs.rsp));
61 v3_inspect_64(gpr_node, "RBP", (uint64_t *)&(core->vm_regs.rbp));
62 v3_inspect_64(gpr_node, "RSI", (uint64_t *)&(core->vm_regs.rsi));
63 v3_inspect_64(gpr_node, "RDI", (uint64_t *)&(core->vm_regs.rdi));
66 struct v3_mtree * cr_node = v3_mtree_create_subtree(core_node, "CTRL_REGS");
67 v3_inspect_64(cr_node, "CR0", (uint64_t *)&(core->ctrl_regs.cr0));
68 v3_inspect_64(cr_node, "CR2", (uint64_t *)&(core->ctrl_regs.cr2));
69 v3_inspect_64(cr_node, "CR3", (uint64_t *)&(core->ctrl_regs.cr3));
70 v3_inspect_64(cr_node, "CR4", (uint64_t *)&(core->ctrl_regs.cr4));
71 v3_inspect_64(cr_node, "RFLAGS", (uint64_t *)&(core->ctrl_regs.rflags));
72 v3_inspect_64(cr_node, "EFER", (uint64_t *)&(core->ctrl_regs.efer));
75 // struct v3_mtree * seg_node = v3_mtree_create_subtree(core_node, "SEGMENTS");
85 v3_inspect_node_t * v3_inspect_add_subtree(v3_inspect_node_t * root, char * name) {
86 return v3_mtree_create_subtree(root, name);
89 int v3_inspect_8(v3_inspect_node_t * node, char * name, uint8_t * val) {
90 v3_mtree_create_value(node, name, 1, val);
95 int v3_inspect_16(v3_inspect_node_t * node, char * name, uint16_t * val) {
96 v3_mtree_create_value(node, name, 2, val);
101 int v3_inspect_32(v3_inspect_node_t * node, char * name, uint32_t * val) {
102 v3_mtree_create_value(node, name, 4, val);
106 int v3_inspect_64(v3_inspect_node_t * node, char * name, uint64_t * val) {
107 v3_mtree_create_value(node, name, 8, val);
111 int v3_inspect_addr(v3_inspect_node_t * node, char * name, addr_t * val) {
112 v3_mtree_create_value(node, name, sizeof(addr_t), val);
116 int v3_inspect_buf(v3_inspect_node_t * node, char * name,
117 uint8_t * buf, uint64_t size) {
118 v3_mtree_create_value(node, name, size, buf);
127 int v3_find_inspection_value(v3_inspect_node_t * node, char * name,
128 struct v3_inspection_value * value) {
129 struct v3_mtree * mt_node = v3_mtree_find_node(node, name);
135 *value = v3_inspection_value(mt_node);
140 struct v3_inspection_value v3_inspection_value(v3_inspect_node_t * node) {
141 struct v3_mtree * mt_node = node;
142 struct v3_inspection_value value;
144 value.value = mt_node->value;
145 value.size = mt_node->size;
146 value.flags = mt_node->user_flags;
147 value.name = mt_node->name;
154 v3_inspect_node_t * v3_get_inspection_root(struct v3_vm_info * vm) {
155 return &(vm->inspector.state_tree);
158 v3_inspect_node_t * v3_get_inspection_subtree(v3_inspect_node_t * root, char * name) {
159 return v3_mtree_find_subtree(root, name);
163 v3_inspect_node_t * v3_inspection_node_next(v3_inspect_node_t * node) {
164 return v3_mtree_next_node(node);
167 v3_inspect_node_t * v3_inspection_first_child(v3_inspect_node_t * root) {
168 return v3_mtree_first_child(root);