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.


adf9b067434f2fd042d3257fc18f106b6ea09377
[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 #include <devices/os_debug.h>
22 #include <palacios/vmm.h>
23
24 #define BUF_SIZE 1024
25
26 #define DEBUG_PORT1 0xc0c0
27
28
29 struct debug_state {
30     char debug_buf[BUF_SIZE];
31     uint_t debug_offset;
32
33 };
34
35
36 static int handle_gen_write(ushort_t port, void * src, uint_t length, struct vm_device * dev) {
37     struct debug_state * state = (struct debug_state *)dev->private_data;
38
39     state->debug_buf[state->debug_offset++] = *(char*)src;
40
41     if ((*(char*)src == 0xa) ||  (state->debug_offset == (BUF_SIZE - 1))) {
42         PrintDebug("VM_CONSOLE>%s", state->debug_buf);
43         memset(state->debug_buf, 0, BUF_SIZE);
44         state->debug_offset = 0;
45     }
46
47     return length;
48 }
49
50
51 static int debug_init(struct vm_device * dev) {
52     struct debug_state * state = (struct debug_state *)dev->private_data;
53
54     v3_dev_hook_io(dev, DEBUG_PORT1,  NULL, &handle_gen_write);
55
56     state->debug_offset = 0;
57     memset(state->debug_buf, 0, BUF_SIZE);
58   
59     return 0;
60 }
61
62 static int debug_deinit(struct vm_device * dev) {
63     v3_dev_unhook_io(dev, DEBUG_PORT1);
64
65
66     return 0;
67 };
68
69
70
71
72 static struct vm_device_ops dev_ops = {
73     .init = debug_init,
74     .deinit = debug_deinit,
75     .reset = NULL,
76     .start = NULL,
77     .stop = NULL,
78 };
79
80
81 struct vm_device * v3_create_os_debug() {
82     struct debug_state * state = NULL;
83
84     state = (struct debug_state *)V3_Malloc(sizeof(struct debug_state));
85
86     PrintDebug("Creating OS Debug Device\n");
87     struct vm_device * device = v3_create_device("OS Debug", &dev_ops, state);
88
89
90
91     return device;
92 }