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 <devices/bochs_debug.h>
22 #include <palacios/vmm.h>
26 #define BOCHS_PORT1 0x400
27 #define BOCHS_PORT2 0x401
28 #define BOCHS_INFO_PORT 0x402
29 #define BOCHS_DEBUG_PORT 0x403
34 char debug_buf[BUF_SIZE];
37 char info_buf[BUF_SIZE];
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;
44 state->info_buf[state->info_offset++] = *(char*)src;
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;
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;
59 state->debug_buf[state->debug_offset++] = *(char*)src;
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;
71 static int handle_gen_write(ushort_t port, void * src, uint_t length, struct vm_device * dev) {
75 PrintDebug(">0x%.2x\n", *(uchar_t*)src);
78 PrintDebug(">0x%.4x\n", *(ushort_t*)src);
81 PrintDebug(">0x%.8x\n", *(uint_t*)src);
84 PrintError("Invalid length in handle_gen_write\n");
93 static int debug_init(struct vm_device * dev) {
94 struct debug_state * state = (struct debug_state *)dev->private_data;
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);
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);
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);
122 static struct vm_device_ops dev_ops = {
124 .deinit = debug_deinit,
131 struct vm_device * v3_create_bochs_debug() {
132 struct debug_state * state = NULL;
134 state = (struct debug_state *)V3_Malloc(sizeof(struct debug_state));
136 V3_ASSERT(state != NULL);
138 PrintDebug("Creating Bochs Debug Device\n");
139 struct vm_device * device = v3_create_device("BOCHS Debug", &dev_ops, state);