Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


7abdeb0533127b2000b9cd05df6049f9a2aaee67
[palacios.git] / palacios / src / devices / os_debug.c
1 /* 
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.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
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.
13  *
14  * Author: Jack Lange <jarusl@cs.northwestern.edu>
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
20
21
22 #include <palacios/vmm.h>
23 #include <palacios/vmm_dev_mgr.h>
24 #include <palacios/vm_guest_mem.h>
25
26 #define BUF_SIZE 1024
27
28 #define DEBUG_PORT1 0xc0c0
29 #define DEBUG_HCALL 0xc0c0
30
31 struct debug_state {
32     char debug_buf[BUF_SIZE];
33     uint_t debug_offset;
34
35 };
36
37
38 static int handle_gen_write(ushort_t port, void * src, uint_t length, struct vm_device * dev) {
39     struct debug_state * state = (struct debug_state *)dev->private_data;
40
41     state->debug_buf[state->debug_offset++] = *(char*)src;
42
43     if ((*(char*)src == 0xa) ||  (state->debug_offset == (BUF_SIZE - 1))) {
44         PrintDebug("VM_CONSOLE>%s", state->debug_buf);
45         memset(state->debug_buf, 0, BUF_SIZE);
46         state->debug_offset = 0;
47     }
48
49     return length;
50 }
51
52 static int handle_hcall(struct guest_info * info, uint_t hcall_id, void * priv_data) {
53     struct vm_device * dev = (struct vm_device *)priv_data;
54     struct debug_state * state = (struct debug_state *)dev->private_data;
55
56     int msg_len = info->vm_regs.rcx;
57     addr_t msg_gpa = info->vm_regs.rbx;
58     int buf_is_va = info->vm_regs.rdx;
59
60     if (msg_len >= BUF_SIZE) {
61         PrintError("Console message too large for buffer (len=%d)\n", msg_len);
62         return -1;
63     }
64
65     if (buf_is_va == 1) {
66         if (read_guest_va_memory(info, msg_gpa, msg_len, (uchar_t *)state->debug_buf) != msg_len) {
67             PrintError("Could not read debug message\n");
68             return -1;
69         }
70     } else {
71         if (read_guest_pa_memory(info, msg_gpa, msg_len, (uchar_t *)state->debug_buf) != msg_len) {
72             PrintError("Could not read debug message\n");
73             return -1;
74         }
75     }   
76
77     state->debug_buf[msg_len] = 0;
78
79     PrintDebug("VM_CONSOLE>%s\n", state->debug_buf);
80
81     return 0;
82 }
83
84
85
86 static int debug_free(struct vm_device * dev) {
87     v3_dev_unhook_io(dev, DEBUG_PORT1);
88
89
90     return 0;
91 };
92
93
94
95
96 static struct v3_device_ops dev_ops = {
97     .free = debug_free,
98     .reset = NULL,
99     .start = NULL,
100     .stop = NULL,
101 };
102
103
104
105
106 static int debug_init(struct guest_info * vm, void * cfg_data) {
107     struct debug_state * state = NULL;
108
109     state = (struct debug_state *)V3_Malloc(sizeof(struct debug_state));
110
111     PrintDebug("Creating OS Debug Device\n");
112
113     struct vm_device * dev = v3_allocate_device("OS_DEBUG", &dev_ops, state);
114
115
116     if (v3_attach_device(vm, dev) == -1) {
117         PrintError("Could not attach device %s\n", "OS_DEBUG");
118         return -1;
119     }
120
121     v3_dev_hook_io(dev, DEBUG_PORT1,  NULL, &handle_gen_write);
122     v3_register_hypercall(vm, DEBUG_HCALL, handle_hcall, dev);
123
124     state->debug_offset = 0;
125     memset(state->debug_buf, 0, BUF_SIZE);
126   
127     return 0;
128 }
129
130
131 device_register("OS_DEBUG", debug_init)