X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Fcga.c;h=6c82c585dffe3e48f4ecfd58bac894cabe7d9adb;hp=aabe81072351e785a9829fec4bdbe90751ccfd25;hb=c09d92dc256363c742ca2a4bef685ed79575bf22;hpb=b54cbe1dbbe15ed228de7472ea284df96ecce909 diff --git a/palacios/src/devices/cga.c b/palacios/src/devices/cga.c index aabe810..6c82c58 100644 --- a/palacios/src/devices/cga.c +++ b/palacios/src/devices/cga.c @@ -24,16 +24,16 @@ #include #include -#include +#include + -/* #ifndef DEBUG_CGA #undef PrintDebug #define PrintDebug(fmt, args...) #endif -*/ + #define START_ADDR 0xB8000 #define END_ADDR 0xC0000 @@ -58,9 +58,11 @@ struct video_internal { uint8_t crtc_index_reg; // io port 3D4 uint8_t crtc_data_regs[25]; // io port 3D5 - + + /* IMPORTANT: These are column offsets _NOT_ byte offsets */ uint16_t screen_offset; // relative to the framebuffer uint16_t cursor_offset; // relative to the framebuffer + /* ** */ // updating the screen offset is not atomic, // so we need a temp variable to hold the partial update @@ -118,6 +120,7 @@ static int video_write_mem(addr_t guest_addr, void * dest, uint_t length, void * struct video_internal * state = (struct video_internal *)dev->private_data; uint_t fb_offset = guest_addr - START_ADDR; uint_t screen_byte_offset = state->screen_offset * BYTES_PER_COL; + uint_t screen_length; PrintDebug("Guest address: %p length = %d, fb_offset=%d, screen_offset=%d\n", (void *)guest_addr, length, fb_offset, screen_byte_offset); @@ -134,7 +137,11 @@ static int video_write_mem(addr_t guest_addr, void * dest, uint_t length, void * if (state->ops) { PrintDebug("\tcalling update_screen()\n"); - state->ops->update_screen(x, y, length, state->private_data); + + /* avoid updates past end of screen */ + screen_length = SCREEN_SIZE - screen_byte_offset; + if (screen_length > length) screen_length = length; + state->ops->update_screen(x, y, screen_length, state->private_data); } } @@ -308,18 +315,20 @@ static struct v3_device_ops dev_ops = { .stop = NULL, }; -static int cga_init(struct guest_info * vm, void * cfg_data) { +static int cga_init(struct guest_info * vm, v3_cfg_tree_t * cfg) { struct video_internal * video_state = (struct video_internal *)V3_Malloc(sizeof(struct video_internal)); addr_t frame_buf_pa = 0; - uint32_t enable_passthrough = (uint32_t)(addr_t)cfg_data; + int enable_passthrough = 0; + char * name = v3_cfg_val(cfg, "name"); + enable_passthrough = (strcasecmp(v3_cfg_val(cfg, "passthrough"), "enable") == 0) ? 1 : 0; PrintDebug("video: init_device\n"); - struct vm_device * dev = v3_allocate_device("CGA_VIDEO", &dev_ops, video_state); + struct vm_device * dev = v3_allocate_device(name, &dev_ops, video_state); if (v3_attach_device(vm, dev) == -1) { - PrintError("Could not attach device %s\n", "CGA_VIDEO"); + PrintError("Could not attach device %s\n", name); return -1; }