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.


Release 1.0
[palacios.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
32
33 struct debug_state {
34   char debug_buf[BUF_SIZE];
35   uint_t debug_offset;
36
37   char info_buf[BUF_SIZE];
38   uint_t info_offset;
39 };
40
41 static int handle_info_write(ushort_t port, void * src, uint_t length, struct vm_device * dev) {
42   struct debug_state * state = (struct debug_state *)dev->private_data;
43
44   state->info_buf[state->info_offset++] = *(char*)src;
45
46   if ((*(char*)src == 0xa) ||  (state->info_offset == (BUF_SIZE - 1))) {
47     PrintDebug("BOCHSINFO>%s", state->info_buf);
48     memset(state->info_buf, 0, BUF_SIZE);
49     state->info_offset = 0;
50   }
51
52   return length;
53 }
54
55
56 static int handle_debug_write(ushort_t port, void * src, uint_t length, struct vm_device * dev) {
57   struct debug_state * state = (struct debug_state *)dev->private_data;
58
59   state->debug_buf[state->debug_offset++] = *(char*)src;
60
61   if ((*(char*)src == 0xa) ||  (state->debug_offset == (BUF_SIZE - 1))) {
62     PrintDebug("BOCHSDEBUG>%s", state->debug_buf);
63     memset(state->debug_buf, 0, BUF_SIZE);
64     state->debug_offset = 0;
65   }
66
67   return length;
68 }
69
70
71 static int handle_gen_write(ushort_t port, void * src, uint_t length, struct vm_device * dev) {
72
73   switch (length) {
74   case 1:
75     PrintDebug(">0x%.2x\n", *(uchar_t*)src);
76     break;
77   case 2:
78     PrintDebug(">0x%.4x\n", *(ushort_t*)src);
79     break;
80   case 4:
81     PrintDebug(">0x%.8x\n", *(uint_t*)src);
82     break;
83   default:
84     PrintError("Invalid length in handle_gen_write\n");
85     return -1;
86     break;
87   }
88
89   return length;
90 }
91
92
93 static int debug_init(struct vm_device * dev) {
94   struct debug_state * state = (struct debug_state *)dev->private_data;
95
96   state->debug_offset = 0;
97   state->info_offset = 0;
98   memset(state->debug_buf, 0, BUF_SIZE);
99   memset(state->info_buf, 0, BUF_SIZE);
100
101
102   v3_dev_hook_io(dev, BOCHS_PORT1,  NULL, &handle_gen_write);
103   v3_dev_hook_io(dev, BOCHS_PORT2, NULL, &handle_gen_write);
104   v3_dev_hook_io(dev, BOCHS_INFO_PORT, NULL, &handle_info_write);
105   v3_dev_hook_io(dev, BOCHS_DEBUG_PORT, NULL, &handle_debug_write);
106   
107   return 0;
108 }
109
110 static int debug_deinit(struct vm_device * dev) {
111   v3_dev_unhook_io(dev, BOCHS_PORT1);
112   v3_dev_unhook_io(dev, BOCHS_PORT2);
113   v3_dev_unhook_io(dev, BOCHS_INFO_PORT);
114   v3_dev_unhook_io(dev, BOCHS_DEBUG_PORT);
115
116   return 0;
117 };
118
119
120
121
122 static struct vm_device_ops dev_ops = {
123   .init = debug_init,
124   .deinit = debug_deinit,
125   .reset = NULL,
126   .start = NULL,
127   .stop = NULL,
128 };
129
130
131 struct vm_device * v3_create_bochs_debug() {
132   struct debug_state * state = NULL;
133
134   state = (struct debug_state *)V3_Malloc(sizeof(struct debug_state));
135
136   V3_ASSERT(state != NULL);
137
138   PrintDebug("Creating Bochs Debug Device\n");
139   struct vm_device * device = v3_create_device("BOCHS Debug", &dev_ops, state);
140
141
142
143   return device;
144 }