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.


fixed null memory list bug in print_shadow_map
[palacios.releases.git] / palacios / src / devices / bochs_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 #include <devices/bochs_debug.h>
22 #include <palacios/vmm.h>
23
24 #define BUF_SIZE 1024
25
26 #define BOCHS_PORT1 0x400
27 #define BOCHS_PORT2 0x401
28 #define BOCHS_INFO_PORT 0x402
29 #define BOCHS_DEBUG_PORT 0x403
30
31 #define BOCHS_CONSOLE_PORT 0xe9
32
33
34 struct debug_state {
35     char debug_buf[BUF_SIZE];
36     uint_t debug_offset;
37
38     char info_buf[BUF_SIZE];
39     uint_t info_offset;
40
41     char cons_buf[BUF_SIZE];
42     uint_t cons_offset;
43 };
44
45 static int handle_info_write(ushort_t port, void * src, uint_t length, struct vm_device * dev) {
46     struct debug_state * state = (struct debug_state *)dev->private_data;
47
48     state->info_buf[state->info_offset++] = *(char*)src;
49
50     if ((*(char*)src == 0xa) ||  (state->info_offset == (BUF_SIZE - 1))) {
51         PrintDebug("BOCHSINFO>%s", state->info_buf);
52         memset(state->info_buf, 0, BUF_SIZE);
53         state->info_offset = 0;
54     }
55
56     return length;
57 }
58
59
60 static int handle_debug_write(ushort_t port, void * src, uint_t length, struct vm_device * dev) {
61     struct debug_state * state = (struct debug_state *)dev->private_data;
62
63     state->debug_buf[state->debug_offset++] = *(char*)src;
64
65     if ((*(char*)src == 0xa) ||  (state->debug_offset == (BUF_SIZE - 1))) {
66         PrintDebug("BOCHSDEBUG>%s", state->debug_buf);
67         memset(state->debug_buf, 0, BUF_SIZE);
68         state->debug_offset = 0;
69     }
70
71     return length;
72 }
73
74
75 static int handle_console_write(ushort_t port, void * src, uint_t length, struct vm_device * dev) {
76     struct debug_state * state = (struct debug_state *)dev->private_data;
77
78     state->cons_buf[state->cons_offset++] = *(char*)src;
79
80     if ((*(char*)src == 0xa) ||  (state->cons_offset == (BUF_SIZE - 1))) {
81         PrintDebug("BOCHSCONSOLE>%s", state->cons_buf);
82         memset(state->cons_buf, 0, BUF_SIZE);
83         state->cons_offset = 0;
84     }
85
86     return length;
87 }
88
89
90 static int handle_gen_write(ushort_t port, void * src, uint_t length, struct vm_device * dev) {
91
92     switch (length) {
93         case 1:
94             PrintDebug(">0x%.2x\n", *(uchar_t*)src);
95             break;
96         case 2:
97             PrintDebug(">0x%.4x\n", *(ushort_t*)src);
98             break;
99         case 4:
100             PrintDebug(">0x%.8x\n", *(uint_t*)src);
101             break;
102         default:
103             PrintError("Invalid length in handle_gen_write\n");
104             return -1;
105             break;
106     }
107
108     return length;
109 }
110
111
112 static int debug_init(struct vm_device * dev) {
113     struct debug_state * state = (struct debug_state *)dev->private_data;
114
115     state->debug_offset = 0;
116     state->info_offset = 0;
117     memset(state->debug_buf, 0, BUF_SIZE);
118     memset(state->info_buf, 0, BUF_SIZE);
119
120
121     v3_dev_hook_io(dev, BOCHS_PORT1,  NULL, &handle_gen_write);
122     v3_dev_hook_io(dev, BOCHS_PORT2, NULL, &handle_gen_write);
123     v3_dev_hook_io(dev, BOCHS_INFO_PORT, NULL, &handle_info_write);
124     v3_dev_hook_io(dev, BOCHS_DEBUG_PORT, NULL, &handle_debug_write);
125     v3_dev_hook_io(dev, BOCHS_CONSOLE_PORT, NULL, &handle_console_write);
126     
127   
128     return 0;
129 }
130
131 static int debug_deinit(struct vm_device * dev) {
132     v3_dev_unhook_io(dev, BOCHS_PORT1);
133     v3_dev_unhook_io(dev, BOCHS_PORT2);
134     v3_dev_unhook_io(dev, BOCHS_INFO_PORT);
135     v3_dev_unhook_io(dev, BOCHS_DEBUG_PORT);
136
137     return 0;
138 };
139
140
141
142
143 static struct vm_device_ops dev_ops = {
144     .init = debug_init,
145     .deinit = debug_deinit,
146     .reset = NULL,
147     .start = NULL,
148     .stop = NULL,
149 };
150
151
152 struct vm_device * v3_create_bochs_debug() {
153     struct debug_state * state = NULL;
154
155     state = (struct debug_state *)V3_Malloc(sizeof(struct debug_state));
156
157     V3_ASSERT(state != NULL);
158
159     PrintDebug("Creating Bochs Debug Device\n");
160     struct vm_device * device = v3_create_device("BOCHS Debug", &dev_ops, state);
161
162
163
164     return device;
165 }