From: Jack Lange Date: Tue, 10 Jun 2008 19:12:34 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: boot386puppy-26-to-ide~25 X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=a4b341afa075a6620dd087ee3a8ed850730c05c7 *** empty log message *** --- diff --git a/palacios/include/palacios/vmm_emulate.h b/palacios/include/palacios/vmm_emulate.h index 26d4c6f..d4288a2 100644 --- a/palacios/include/palacios/vmm_emulate.h +++ b/palacios/include/palacios/vmm_emulate.h @@ -120,6 +120,20 @@ static inline int is_prefix_byte(char byte) { } +static inline v3_reg_t get_gpr_mask(struct guest_info * info) { + switch (info->cpu_mode) { + case REAL: + return 0xffff; + break; + case PROTECTED: + case PROTECTED_PG: + return 0xffffffff; + default: + V3_ASSERT(0); + return 0; + } +} + static inline addr_t get_addr_linear(struct guest_info * info, addr_t addr, struct v3_segment * seg) { switch (info->cpu_mode) { @@ -131,6 +145,7 @@ static inline addr_t get_addr_linear(struct guest_info * info, addr_t addr, stru return addr + seg->base; break; default: + V3_ASSERT(0); return 0; } } diff --git a/palacios/src/devices/8254.c b/palacios/src/devices/8254.c index 8dbe05e..60ae891 100644 --- a/palacios/src/devices/8254.c +++ b/palacios/src/devices/8254.c @@ -96,37 +96,50 @@ static int handle_crystal_tics(struct vm_device * dev, struct channel * ch, uint uint_t channel_cycles = 0; uint_t output_changed = 0; - PrintDebug("8254 PIT: %d crystal tics\n", oscillations); + // PrintDebug("8254 PIT: %d crystal tics\n", oscillations); if (ch->run_state == PENDING) { oscillations--; ch->counter = ch->reload_value; + + if (ch->op_mode == SQR_WAVE) { + ch->counter -= ch->counter % 2; + } + ch->run_state = RUNNING; } else if (ch->run_state != RUNNING) { return output_changed; } - + /* PrintDebug("8254 PIT: Channel Run State = %d, counter=", ch->run_state); PrintTraceLL(ch->counter); PrintDebug("\n"); - + */ + if (ch->op_mode == SQR_WAVE) { + oscillations *= 2; + } if (ch->counter > oscillations) { ch->counter -= oscillations; return output_changed; } else { + ushort_t reload_val = ch->reload_value; oscillations -= ch->counter; ch->counter = 0; channel_cycles = 1; - channel_cycles += oscillations / ch->reload_value; - oscillations = oscillations % ch->reload_value; + if (ch->op_mode == SQR_WAVE) { + reload_val -= reload_val % 2; + } + + channel_cycles += oscillations / reload_val; + oscillations = oscillations % reload_val; - ch->counter = ch->reload_value - oscillations; + ch->counter = reload_val - oscillations; } - PrintDebug("8254 PIT: Channel Cycles: %d\n", channel_cycles); + // PrintDebug("8254 PIT: Channel Cycles: %d\n", channel_cycles); @@ -150,10 +163,18 @@ static int handle_crystal_tics(struct vm_device * dev, struct channel * ch, uint } break; case SQR_WAVE: + ch->output_pin = (ch->output_pin + 1) % 2; + + if (ch->output_pin == 1) { + output_changed = 1; + } + break; case SW_STROBE: + return -1; break; case HW_STROBE: + return -1; break; default: break; @@ -254,20 +275,20 @@ static int handle_channel_write(struct channel * ch, char val) { case WAITING_LOBYTE: ch->reload_value &= 0xff00; ch->reload_value |= val; - + if (ch->access_mode == LOBYTE_HIBYTE) { ch->access_state = WAITING_HIBYTE; } else if ((ch->op_mode != RATE_GEN) || (ch->run_state != RUNNING)) { ch->run_state = PENDING; } - + PrintDebug("8254 PIT: updated channel counter: %d\n", ch->reload_value); PrintDebug("8254 PIT: Channel Run State=%d\n", ch->run_state); break; default: return -1; - } - + } + switch (ch->op_mode) { case IRQ_ON_TERM_CNT: @@ -279,8 +300,9 @@ static int handle_channel_write(struct channel * ch, char val) { case RATE_GEN: ch->output_pin = 1; break; - - + case SQR_WAVE: + ch->output_pin = 1; + break; default: return -1; break; diff --git a/palacios/src/devices/generic.c b/palacios/src/devices/generic.c index 40b6c00..35d8b9a 100644 --- a/palacios/src/devices/generic.c +++ b/palacios/src/devices/generic.c @@ -69,13 +69,17 @@ int generic_write_port(ushort_t port, uint_t i; GENERIC_DEBUG_PRINT("generic: writing 0x"); - for (i=0;ivm->vm_ops.raise_irq(dev->vm,irq); + dev->vm->vm_ops.raise_irq(dev->vm, irq); return 0; @@ -117,8 +125,8 @@ int generic_interrupt(uint_t irq, int generic_init_device(struct vm_device * dev) { - struct generic_internal *state = (struct generic_internal *) dev->private_data; - uint_t i,j; + struct generic_internal *state = (struct generic_internal *)(dev->private_data); + uint_t i, j; GENERIC_DEBUG_PRINT("generic: init_device\n"); @@ -126,12 +134,13 @@ int generic_init_device(struct vm_device * dev) generic_reset_device(dev); - for (i=0;inum_port_ranges;i++) { - GENERIC_DEBUG_PRINT("generic: hooking ports 0x%x to 0x%x\n",state->port_ranges[i][0],state->port_ranges[i][1]); + for (i = 0; i < state->num_port_ranges; i++) { + GENERIC_DEBUG_PRINT("generic: hooking ports 0x%x to 0x%x\n", state->port_ranges[i][0], state->port_ranges[i][1]); + #if PORT_HOOKS - for (j=state->port_ranges[i][0]; j<=state->port_ranges[i][1];j++) { + for (j = state->port_ranges[i][0]; j <= state->port_ranges[i][1]; j++) { if (dev_hook_io(dev, j, &generic_read_port, &generic_write_port)) { - GENERIC_DEBUG_PRINT("generic: can't hook port 0x%x (already hooked?)\n",j); + GENERIC_DEBUG_PRINT("generic: can't hook port 0x%x (already hooked?)\n", j); } } #else @@ -140,12 +149,13 @@ int generic_init_device(struct vm_device * dev) } - for (i=0;inum_address_ranges;i++) { + for (i = 0; i < state->num_address_ranges; i++) { GENERIC_DEBUG_PRINT("generic: hooking addresses 0x%x to 0x%x\n",state->address_ranges[i][0],state->address_ranges[i][1]); + #if MEM_HOOKS - if (dev_hook_mem(dev, state->address_ranges[i][0],state->address_ranges[i][1])) { + if (dev_hook_mem(dev, state->address_ranges[i][0], state->address_ranges[i][1])) { GENERIC_DEBUG_PRINT("generic: Can't hook addresses 0x%x to 0x%x (already hooked?)\n", - state->address_ranges[i][0],state->address_ranges[i][1]); + state->address_ranges[i][0], state->address_ranges[i][1]); } #else GENERIC_DEBUG_PRINT("generic: hooking addresses not supported\n"); @@ -153,17 +163,19 @@ int generic_init_device(struct vm_device * dev) } - for (i=0;inum_irq_ranges;i++) { + for (i = 0; i < state->num_irq_ranges; i++) { GENERIC_DEBUG_PRINT("generic: hooking irqs 0x%x to 0x%x\n",state->irq_ranges[i][0],state->irq_ranges[i][1]); + #if IRQ_HOOKS - for (j=state->irq_ranges[i][0]; j<=state->irq_ranges[i][1];j++) { - if (dev_hook_irq(dev, j, &generic_interrupt)) { - GENERIC_DEBUG_PRINT("generic: can't hook irq 0x%x (already hooked?)\n",j); + for (j = state->irq_ranges[i][0]; j <= state->irq_ranges[i][1]; j++) { + if (dev_hook_irq(dev, j, &generic_interrupt)) { + GENERIC_DEBUG_PRINT("generic: can't hook irq 0x%x (already hooked?)\n", j); } } #else GENERIC_DEBUG_PRINT("generic: hooking irqs not supported\n"); #endif + } return 0; @@ -171,15 +183,16 @@ int generic_init_device(struct vm_device * dev) int generic_deinit_device(struct vm_device *dev) { - struct generic_internal *state = (struct generic_internal *) dev->private_data; - uint_t i,j; + struct generic_internal *state = (struct generic_internal *)(dev->private_data); + uint_t i, j; GENERIC_DEBUG_PRINT("generic: deinit_device\n"); - for (i=0;inum_irq_ranges;i++) { - GENERIC_DEBUG_PRINT("generic: unhooking irqs 0x%x to 0x%x\n",state->irq_ranges[i][0],state->irq_ranges[i][1]); + for (i = 0; i < state->num_irq_ranges; i++) { + GENERIC_DEBUG_PRINT("generic: unhooking irqs 0x%x to 0x%x\n", state->irq_ranges[i][0], state->irq_ranges[i][1]); + #if IRQ_HOOKS - for (j=state->irq_ranges[i][0]; j<=state->irq_ranges[i][1];j++) { + for (j = state->irq_ranges[i][0]; j <= state->irq_ranges[i][1]; j++) { if (dev_unhook_irq(dev, j)) { GENERIC_DEBUG_PRINT("generic: can't unhook irq 0x%x (already unhooked?)\n",j); } @@ -190,24 +203,27 @@ int generic_deinit_device(struct vm_device *dev) } - for (i=0;inum_address_ranges;i++) { + for (i = 0; i < state->num_address_ranges; i++) { GENERIC_DEBUG_PRINT("generic: unhooking addresses 0x%x to 0x%x\n",state->address_ranges[i][0],state->address_ranges[i][1]); + #if MEM_HOOKS - if (dev_unhook_mem(dev, state->address_ranges[i][0],state->address_ranges[i][1])) { + if (dev_unhook_mem(dev, state->address_ranges[i][0], state->address_ranges[i][1])) { GENERIC_DEBUG_PRINT("generic: Can't unhook addresses 0x%x to 0x%x (already unhooked?)\n", - state->address_ranges[i][0],state->address_ranges[i][1]); + state->address_ranges[i][0], state->address_ranges[i][1]); } #else GENERIC_DEBUG_PRINT("generic: unhooking addresses not supported\n"); #endif + } - for (i=0;inum_port_ranges;i++) { + for (i = 0; i < state->num_port_ranges; i++) { GENERIC_DEBUG_PRINT("generic: unhooking ports 0x%x to 0x%x\n",state->port_ranges[i][0],state->port_ranges[i][1]); + #if PORT_HOOKS - for (j=state->port_ranges[i][0]; j<=state->port_ranges[i][1];j++) { + for (j = state->port_ranges[i][0]; j <= state->port_ranges[i][1]; j++) { if (dev_unhook_io(dev, j)) { - GENERIC_DEBUG_PRINT("generic: can't unhook port 0x%x (already unhooked?)\n",j); + GENERIC_DEBUG_PRINT("generic: can't unhook port 0x%x (already unhooked?)\n", j); } } #else @@ -245,27 +261,33 @@ struct vm_device *create_generic(generic_port_range_type port_ranges[], struct generic_internal * generic_state = (struct generic_internal *)V3_Malloc(sizeof(struct generic_internal)); - generic_state->num_port_ranges=num_port_ranges; - if (num_port_ranges>0) { - generic_state->port_ranges = V3_Malloc(sizeof(generic_address_range_type)*num_port_ranges); - memcpy(generic_state->port_ranges,port_ranges,sizeof(generic_port_range_type)*num_port_ranges); + generic_state->num_port_ranges = num_port_ranges; + + if (num_port_ranges > 0) { + generic_state->port_ranges = V3_Malloc(sizeof(generic_address_range_type) * num_port_ranges); + memcpy(generic_state->port_ranges, port_ranges, sizeof(generic_port_range_type) * num_port_ranges); } else { - generic_state->port_ranges=NULL; + generic_state->port_ranges = NULL; } - generic_state->num_address_ranges=num_address_ranges; - if (num_address_ranges>0) { - generic_state->address_ranges = V3_Malloc(sizeof(generic_address_range_type)*num_address_ranges); - memcpy(generic_state->address_ranges,address_ranges,sizeof(generic_address_range_type)*num_address_ranges); + + generic_state->num_address_ranges = num_address_ranges; + + if (num_address_ranges > 0) { + generic_state->address_ranges = V3_Malloc(sizeof(generic_address_range_type) * num_address_ranges); + memcpy(generic_state->address_ranges, address_ranges, sizeof(generic_address_range_type) * num_address_ranges); } else { - generic_state->address_ranges=NULL; + generic_state->address_ranges = NULL; } - generic_state->num_irq_ranges=num_irq_ranges; - if (num_irq_ranges>0) { - generic_state->irq_ranges = V3_Malloc(sizeof(generic_address_range_type)*num_irq_ranges); - memcpy(generic_state->irq_ranges,irq_ranges,sizeof(generic_irq_range_type)*num_port_ranges); + + + generic_state->num_irq_ranges = num_irq_ranges; + + if (num_irq_ranges > 0) { + generic_state->irq_ranges = V3_Malloc(sizeof(generic_address_range_type) * num_irq_ranges); + memcpy(generic_state->irq_ranges, irq_ranges, sizeof(generic_irq_range_type) * num_port_ranges); } else { - generic_state->irq_ranges=NULL; + generic_state->irq_ranges = NULL; } diff --git a/palacios/src/devices/keyboard.c b/palacios/src/devices/keyboard.c index 74d2096..3e8811e 100644 --- a/palacios/src/devices/keyboard.c +++ b/palacios/src/devices/keyboard.c @@ -14,18 +14,12 @@ #endif -extern struct vmm_os_hooks *os_hooks; - -extern void SerialPrint(const char *format, ...); - - - #define KEYBOARD_60H 0x60 // keyboard microcontroller #define KEYBOARD_64H 0x64 // onboard microcontroller #define KEYBOARD_DELAY_80H 0x80 // written for timing -#define KEYBOARD_IRQ 0x1 +#define KEYBOARD_IRQ 0x1 // extract bits for status byte @@ -50,7 +44,7 @@ extern void SerialPrint(const char *format, ...); #define CMD_RESERVED 0x80 // should be zero // The currently targetted keyboard -static struct vm_device *thekeyboard=NULL; +static struct vm_device *thekeyboard = NULL; struct keyboard_internal { @@ -105,12 +99,14 @@ struct keyboard_internal { // static int PushToOutputQueue(struct vm_device *dev, uchar_t value, uchar_t overwrite) { - struct keyboard_internal *state = (struct keyboard_internal *)dev->private_data; + struct keyboard_internal *state = (struct keyboard_internal *)(dev->private_data); - if (state->output_queue_len==0 || overwrite) { - state->output_queue=value; - state->output_queue_len=1; + if ((state->output_queue_len == 0) || overwrite) { + + state->output_queue = value; + state->output_queue_len = 1; state->status_byte |= STATUS_OUTPUT_BUFFER_FULL; + return 0; } else { KEYBOARD_DEBUG_PRINT("keyboard: PushToOutputQueue Failed - Queue Full\n"); @@ -123,13 +119,16 @@ static int PushToOutputQueue(struct vm_device *dev, uchar_t value, uchar_t overw // pull item from outputqueue // returns 0 if successful // -static int PullFromOutputQueue(struct vm_device *dev,uchar_t *value) +static int PullFromOutputQueue(struct vm_device *dev, uchar_t *value) { - struct keyboard_internal *state = (struct keyboard_internal *)dev->private_data; - if (state->output_queue_len==1) { - *value=state->output_queue; - state->output_queue_len=0; + struct keyboard_internal *state = (struct keyboard_internal *)(dev->private_data); + + if (state->output_queue_len == 1) { + + *value = state->output_queue; + state->output_queue_len = 0; state->status_byte &= ~STATUS_OUTPUT_BUFFER_FULL; + return 0; } else { KEYBOARD_DEBUG_PRINT("keyboard: PullFromOutputQueue Failed - Queue Empty\n"); @@ -145,11 +144,14 @@ static int PullFromOutputQueue(struct vm_device *dev,uchar_t *value) // static int PushToInputQueue(struct vm_device *dev, uchar_t value, uchar_t overwrite) { - struct keyboard_internal *state = (struct keyboard_internal *)dev->private_data; - if (state->input_queue_len==0 || overwrite) { - state->input_queue=value; - state->input_queue_len=1; + struct keyboard_internal *state = (struct keyboard_internal *)(dev->private_data); + + if ((state->input_queue_len == 0) || overwrite) { + + state->input_queue = value; + state->input_queue_len = 1; state->status_byte |= STATUS_INPUT_BUFFER_FULL; + return 0; } else { KEYBOARD_DEBUG_PRINT("keyboard: PushToOutputQueue Failed - Queue Full\n"); @@ -163,14 +165,18 @@ static int PushToInputQueue(struct vm_device *dev, uchar_t value, uchar_t overwr // static int PullFromInputQueue(struct vm_device *dev, uchar_t *value) { - struct keyboard_internal *state = (struct keyboard_internal *)dev->private_data; - if (state->input_queue_len==1) { - *value=state->input_queue; - state->input_queue_len=0; - state->status_byte &=~STATUS_INPUT_BUFFER_FULL; + struct keyboard_internal *state = (struct keyboard_internal *)(dev->private_data); + + if (state->input_queue_len == 1) { + + *value = state->input_queue; + state->input_queue_len = 0; + state->status_byte &= ~STATUS_INPUT_BUFFER_FULL; + return 0; } else { KEYBOARD_DEBUG_PRINT("keyboard: PullFromInputQueue Failed - Queue Empty\n"); + return -1; } } @@ -183,23 +189,22 @@ static struct vm_device *demultiplex_injected_key(uchar_t status, uchar_t scanco return thekeyboard; } -int keyboard_interrupt(uint_t irq,struct vm_device * dev); +int keyboard_interrupt(uint_t irq, struct vm_device * dev); void deliver_key_to_vmm(uchar_t status, uchar_t scancode) { - struct vm_device *dev = demultiplex_injected_key(status,scancode); + struct vm_device *dev = demultiplex_injected_key(status, scancode); + struct keyboard_internal *state = (struct keyboard_internal *)(dev->private_data); - struct keyboard_internal *state = (struct keyboard_internal *)dev->private_data; - - KEYBOARD_DEBUG_PRINT("keyboard: injected status 0x%x, and scancode 0x%x\n", status,scancode); + KEYBOARD_DEBUG_PRINT("keyboard: injected status 0x%x, and scancode 0x%x\n", status, scancode); - if ( (state->status_byte & STATUS_ENABLED) // onboard is enabled - && (!(state->cmd_byte & CMD_DISABLE))) { // keyboard is enabled + if ( (state->status_byte & STATUS_ENABLED) // onboard is enabled + && (!(state->cmd_byte & CMD_DISABLE)) ) { // keyboard is enabled - PushToOutputQueue(dev,scancode,1); + PushToOutputQueue(dev, scancode, 1); if (state->cmd_byte & CMD_INTR) { - keyboard_interrupt(KEYBOARD_IRQ,dev); + keyboard_interrupt(KEYBOARD_IRQ, dev); } } @@ -207,9 +212,9 @@ void deliver_key_to_vmm(uchar_t status, uchar_t scancode) int keyboard_reset_device(struct vm_device * dev) { - struct keyboard_internal *data = (struct keyboard_internal *) dev->private_data; + struct keyboard_internal *data = (struct keyboard_internal *)(dev->private_data); - memset(data,0,sizeof(struct keyboard_internal)); + memset(data, 0, sizeof(struct keyboard_internal)); data->cmd_byte = CMD_INTR // interrupts on @@ -250,11 +255,14 @@ int keyboard_write_delay(ushort_t port, uint_t length, struct vm_device * dev) { - if (length==1) { + + if (length == 1) { KEYBOARD_DEBUG_PRINT("keyboard: write of 0x%x to 80h\n", *((uchar_t*)src)); + return 1; } else { KEYBOARD_DEBUG_PRINT("keyboard: write of >1 byte to 80h\n", *((uchar_t*)src)); + return length; } } @@ -264,12 +272,16 @@ int keyboard_read_delay(ushort_t port, uint_t length, struct vm_device * dev) { - if (length==1) { + + if (length == 1) { *((uchar_t*)dest) = In_Byte(port); + KEYBOARD_DEBUG_PRINT("keyboard: read of 0x%x from 80h\n", *((uchar_t*)dest)); + return 1; } else { KEYBOARD_DEBUG_PRINT("keyboard: read of >1 byte from 80h\n"); + return length; } } @@ -284,97 +296,97 @@ int keyboard_write_command(ushort_t port, uint_t length, struct vm_device * dev) { - struct keyboard_internal *state = (struct keyboard_internal *) dev->private_data; + struct keyboard_internal *state = (struct keyboard_internal *)(dev->private_data); uchar_t cmd; // Should always be single byte write - if (length!=1) { - KEYBOARD_DEBUG_PRINT("keyboard: write of >1 bytes (%d) to 64h\n",length); + if (length != 1) { + KEYBOARD_DEBUG_PRINT("keyboard: write of >1 bytes (%d) to 64h\n", length); return -1; } - cmd = *((uchar_t*)src); + cmd = *((uchar_t*)src); - if (state->state!=NORMAL) { - KEYBOARD_DEBUG_PRINT("keyboard: warning - receiving command on 64h but state!=NORMAL\n"); + if (state->state != NORMAL) { + KEYBOARD_DEBUG_PRINT("keyboard: warning - receiving command on 64h but state != NORMAL\n"); } - KEYBOARD_DEBUG_PRINT("keyboard: command 0x%x on 64h\n",cmd); + KEYBOARD_DEBUG_PRINT("keyboard: command 0x%x on 64h\n", cmd); switch (cmd) { case 0x20: // READ COMMAND BYTE (returned in 60h) - PushToOutputQueue(dev,state->cmd_byte,1); - state->state=NORMAL; // the next read on 0x60 will get the right data + PushToOutputQueue(dev, state->cmd_byte, 1); + state->state = NORMAL; // the next read on 0x60 will get the right data break; case 0x60: // WRITE COMMAND BYTE (read from 60h) - state->state=WRITING_CMD_BYTE; // we need to make sure we send the next 0x60 byte appropriately + state->state = WRITING_CMD_BYTE; // we need to make sure we send the next 0x60 byte appropriately break; // case 0x90-9f - write to output port (?) case 0xa1: // Get version number - PushToOutputQueue(dev,0,1); - state->state=NORMAL; + PushToOutputQueue(dev, 0, 1); + state->state = NORMAL; break; case 0xa4: // is password installed? send result to 0x60 // we don't support passwords - PushToOutputQueue(dev,0xf1,1); - state->state=NORMAL; + PushToOutputQueue(dev, 0xf1, 1); + state->state = NORMAL; break; case 0xa5: // new password will arrive on 0x60 - state->state=TRANSMIT_PASSWD; + state->state = TRANSMIT_PASSWD; break; case 0xa6: // check passwd; // since we do not support passwords, we will simply ignore this // the implication is that any password check immediately succeeds // with a blank password - state->state=NORMAL; + state->state = NORMAL; break; case 0xa7: // disable mouse state->cmd_byte |= CMD_MOUSE_DISABLE; - state->state=NORMAL; + state->state = NORMAL; break; case 0xa8: // enable mouse state->cmd_byte &= ~CMD_MOUSE_DISABLE; - state->state=NORMAL; + state->state = NORMAL; break; case 0xa9: // mouse interface test (always succeeds) - PushToOutputQueue(dev,0,1); - state->state=NORMAL; + PushToOutputQueue(dev, 0, 1); + state->state = NORMAL; break; case 0xaa: // controller self test (always succeeds) - PushToOutputQueue(dev,0x55,1); - state->state=NORMAL; + PushToOutputQueue(dev, 0x55, 1); + state->state = NORMAL; break; case 0xab: // keyboard interface test (always succeeds) - PushToOutputQueue(dev,0,1); - state->state=NORMAL; + PushToOutputQueue(dev, 0, 1); + state->state = NORMAL; break; case 0xad: // disable keyboard state->cmd_byte |= CMD_DISABLE; - state->state=NORMAL; + state->state = NORMAL; break; case 0xae: // enable keyboard state->cmd_byte &= ~CMD_DISABLE; - state->state=NORMAL; + state->state = NORMAL; break; case 0xaf: // get version - PushToOutputQueue(dev,0x00,1); - state->state=NORMAL; + PushToOutputQueue(dev, 0x00, 1); + state->state = NORMAL; break; // case c0 read input port ? @@ -394,7 +406,7 @@ int keyboard_write_command(ushort_t port, default: KEYBOARD_DEBUG_PRINT("keyboard: ignoring command (unimplemented)\n"); - state->state=NORMAL; + state->state = NORMAL; break; } @@ -407,12 +419,16 @@ int keyboard_read_status(ushort_t port, uint_t length, struct vm_device * dev) { - struct keyboard_internal *state = (struct keyboard_internal *) dev->private_data; + struct keyboard_internal *state = (struct keyboard_internal *)(dev->private_data); + + if (length == 1) { - if (length==1) { KEYBOARD_DEBUG_PRINT("keyboard: read status (64h): "); - *((uchar_t*)dest)=state->status_byte; - KEYBOARD_DEBUG_PRINT("0x%x\n",*((uchar_t*)dest)); + + *((uchar_t*)dest) = state->status_byte; + + KEYBOARD_DEBUG_PRINT("0x%x\n", *((uchar_t*)dest)); + return 1; } else { KEYBOARD_DEBUG_PRINT("keyboard: >1 byte read for status (64h)\n"); @@ -425,59 +441,61 @@ int keyboard_write_output(ushort_t port, uint_t length, struct vm_device * dev) { - struct keyboard_internal *state = (struct keyboard_internal *) dev->private_data; + struct keyboard_internal *state = (struct keyboard_internal *)(dev->private_data); - if (length!=1) { + if (length != 1) { KEYBOARD_DEBUG_PRINT("keyboard: write of 60h with >1 byte\n"); return -1; } - uchar_t data=*((uchar_t*)src); + uchar_t data = *((uchar_t*)src); switch (state->state) { case WRITING_CMD_BYTE: - state->cmd_byte=data; - state->state=NORMAL; + state->cmd_byte = data; + state->state = NORMAL; break; case TRANSMIT_PASSWD: if (data) { //ignore passwd } else { // end of password - state->state=NORMAL; + state->state = NORMAL; } break; case NORMAL: - // command is being sent to keyboard controller - switch (data) { - case 0xff: // reset - PushToOutputQueue(dev,0xfa,1); // ack - state->state=RESET; - break; - case 0xf5: // disable scanning - case 0xf4: // enable scanning - // ack - PushToOutputQueue(dev,0xfa,1); - // should do something here... PAD - state->state=NORMAL; - break; - case 0xfe: // resend - case 0xfd: // set key type make - case 0xfc: // set key typ make/break - case 0xfb: // set key type typematic - case 0xfa: // set all typematic make/break/typematic - case 0xf9: // set all make - case 0xf8: // set all make/break - case 0xf7: // set all typemaktic - case 0xf6: // set defaults - case 0xf3: // set typematic delay/rate - default: - KEYBOARD_DEBUG_PRINT("keyboard: unhandled command 0x%x on output buffer (60h)\n",data); + { + // command is being sent to keyboard controller + switch (data) { + case 0xff: // reset + PushToOutputQueue(dev, 0xfa, 1); // ack + state->state = RESET; + break; + case 0xf5: // disable scanning + case 0xf4: // enable scanning + // ack + PushToOutputQueue(dev, 0xfa, 1); + // should do something here... PAD + state->state = NORMAL; + break; + case 0xfe: // resend + case 0xfd: // set key type make + case 0xfc: // set key typ make/break + case 0xfb: // set key type typematic + case 0xfa: // set all typematic make/break/typematic + case 0xf9: // set all make + case 0xf8: // set all make/break + case 0xf7: // set all typemaktic + case 0xf6: // set defaults + case 0xf3: // set typematic delay/rate + default: + KEYBOARD_DEBUG_PRINT("keyboard: unhandled command 0x%x on output buffer (60h)\n", data); + break; + } break; } - break; default: - KEYBOARD_DEBUG_PRINT("keyboard: unknown state %x on command 0x%x on output buffer (60h)\n",state->state, data); + KEYBOARD_DEBUG_PRINT("keyboard: unknown state %x on command 0x%x on output buffer (60h)\n", state->state, data); } return 1; @@ -488,21 +506,26 @@ int keyboard_read_input(ushort_t port, uint_t length, struct vm_device * dev) { - struct keyboard_internal *state = (struct keyboard_internal *) dev->private_data; + struct keyboard_internal *state = (struct keyboard_internal *)(dev->private_data); - if (length==1) { + if (length == 1) { uchar_t data; + KEYBOARD_DEBUG_PRINT("keyboard: read from input (60h): "); - PullFromOutputQueue(dev,&data); - if (state->state==RESET) { + + PullFromOutputQueue(dev, &data); + + if (state->state == RESET) { // We just delivered the ack for the reset // now we will ready ourselves to deliver the BAT code (success) - PushToOutputQueue(dev,0xaa,1); - state->state=NORMAL; + PushToOutputQueue(dev, 0xaa, 1); + state->state = NORMAL; } - KEYBOARD_DEBUG_PRINT("0x%x\n",data); - *((uchar_t*)dest)=data; + KEYBOARD_DEBUG_PRINT("0x%x\n", data); + + *((uchar_t*)dest) = data; + return 1; } else { KEYBOARD_DEBUG_PRINT("keyboard: unknown size read from input (60h)\n"); @@ -511,12 +534,11 @@ int keyboard_read_input(ushort_t port, } -int keyboard_interrupt(uint_t irq, - struct vm_device * dev) +int keyboard_interrupt(uint_t irq, struct vm_device * dev) { KEYBOARD_DEBUG_PRINT("keyboard: interrupt\n"); - dev->vm->vm_ops.raise_irq(dev->vm,irq); + dev->vm->vm_ops.raise_irq(dev->vm, irq); return 0; @@ -580,7 +602,7 @@ static struct vm_device_ops dev_ops = { struct vm_device *create_keyboard() { - if (thekeyboard!=NULL) { + if (thekeyboard != NULL) { KEYBOARD_DEBUG_PRINT("keyboard: creating >1 keyboard device. This will probably fail!\n"); } @@ -588,7 +610,7 @@ struct vm_device *create_keyboard() { struct vm_device *device = create_device("KEYBOARD", &dev_ops, keyboard_state); - thekeyboard=device; + thekeyboard = device; return device; } diff --git a/palacios/src/geekos/keyboard.c b/palacios/src/geekos/keyboard.c index 21987b9..44f0dfe 100644 --- a/palacios/src/geekos/keyboard.c +++ b/palacios/src/geekos/keyboard.c @@ -1,7 +1,7 @@ /* * Keyboard driver * Copyright (c) 2001,2004 David H. Hovemeyer - * $Revision: 1.5 $ + * $Revision: 1.6 $ * * This is free software. You are permitted to use, * redistribute, and modify it as specified in the file "COPYING". @@ -36,7 +36,11 @@ #include -static enum {TARGET_GEEKOS,TARGET_VMM} target=TARGET_VMM; + + + +static enum {TARGET_GEEKOS,TARGET_VMM} target = TARGET_VMM; + extern void deliver_key_to_vmm(uchar_t status, uchar_t scancode); @@ -176,6 +180,7 @@ static void Keyboard_Interrupt_Handler(struct Interrupt_State* state) //Print("Keyboard\n"); + status = In_Byte(KB_CMD); raw_status=status; diff --git a/palacios/src/geekos/lowlevel.asm b/palacios/src/geekos/lowlevel.asm index 1758b8f..1e2f409 100644 --- a/palacios/src/geekos/lowlevel.asm +++ b/palacios/src/geekos/lowlevel.asm @@ -2,7 +2,7 @@ ; Low level interrupt/thread handling code for GeekOS. ; Copyright (c) 2001,2003,2004 David H. Hovemeyer ; Copyright (c) 2003, Jeffrey K. Hollingsworth -; $Revision: 1.6 $ +; $Revision: 1.7 $ ; This is free software. You are permitted to use, ; redistribute, and modify it as specified in the file "COPYING". @@ -126,6 +126,7 @@ IMPORT Make_Runnable ; Function to activate a new user context (if needed). IMPORT Switch_To_User_Context +; Debug functions IMPORT SerialPrintHex IMPORT SerialPutChar @@ -424,6 +425,17 @@ Handle_Interrupt: mov esi, [esp+REG_SKIP] ; get interrupt number mov ebx, [eax+esi*4] ; get address of handler function + push esi + call SerialPrintHex + pop esi + + push eax + mov eax, 0xa + push eax + call SerialPutChar + pop eax + pop eax + ; Call the handler. ; The argument passed is a pointer to an Interrupt_State struct, ; which describes the stack layout for all interrupts. @@ -503,6 +515,21 @@ Handle_Interrupt: ; Restore registers Restore_Registers + + pusha + + mov eax, 0xaa + push eax + call SerialPrintHex + pop eax + + mov eax, 0xa + push eax + call SerialPutChar + pop eax + + popa + ; Return from the interrupt. iret diff --git a/palacios/src/geekos/timer.c b/palacios/src/geekos/timer.c index 34f752b..dbda61f 100644 --- a/palacios/src/geekos/timer.c +++ b/palacios/src/geekos/timer.c @@ -2,7 +2,7 @@ * GeekOS timer interrupt support * Copyright (c) 2001,2003 David H. Hovemeyer * Copyright (c) 2003, Jeffrey K. Hollingsworth - * $Revision: 1.5 $ + * $Revision: 1.6 $ * * This is free software. You are permitted to use, * redistribute, and modify it as specified in the file "COPYING". @@ -206,7 +206,7 @@ static void Timer_Interrupt_Handler(struct Interrupt_State* state) Begin_IRQ(state); - SerialPrintLevel(1,"Host Timer Interrupt Handler Running\n"); + SerialPrint("Host Timer Interrupt Handler running\n"); /* Update global and per-thread number of ticks */ ++g_numTicks; diff --git a/palacios/src/geekos/vm.c b/palacios/src/geekos/vm.c index 2a67e38..b080117 100644 --- a/palacios/src/geekos/vm.c +++ b/palacios/src/geekos/vm.c @@ -324,7 +324,7 @@ int RunVMM(struct Boot_Info * bootInfo) { //generic_port_range_type range = {0,1024} ; // hook first 1024 ports if not already hooked - //struct vm_device * generic = create_generic(&range,1,NULL,0,NULL,0); + //struct vm_device * generic = create_generic(&range, 1, NULL, 0, NULL, 0); attach_device(&(vm_info), nvram); @@ -343,13 +343,13 @@ int RunVMM(struct Boot_Info * bootInfo) { //hook_irq(&vm_info, 1); // give floppy controller to vm - hook_irq(&vm_info, 6); + //hook_irq(&vm_info, 6); // primary ide - hook_irq(&vm_info, 14); + //hook_irq(&vm_info, 14); // secondary ide - hook_irq(&vm_info, 15); + //hook_irq(&vm_info, 15); vm_info.rip = 0xfff0; diff --git a/palacios/src/geekos/vmm_stubs.c b/palacios/src/geekos/vmm_stubs.c index 15ae589..1e6a3a3 100644 --- a/palacios/src/geekos/vmm_stubs.c +++ b/palacios/src/geekos/vmm_stubs.c @@ -104,7 +104,11 @@ int hook_irq_stub(struct guest_info * info, int irq) { SerialPrint("Hooking IRQ: %d (vm=0x%x)\n", irq, info); irq_map[irq] = info; volatile void *foo = pic_intr_handler; - foo=0; + + /* This is disabled for the time being */ + foo = 0; + + Disable_IRQ(irq); Install_IRQ(irq, pic_intr_handler); Enable_IRQ(irq); diff --git a/palacios/src/palacios/svm.c b/palacios/src/palacios/svm.c index cbed250..057685d 100644 --- a/palacios/src/palacios/svm.c +++ b/palacios/src/palacios/svm.c @@ -250,14 +250,16 @@ static int start_svm_guest(struct guest_info *info) { CLGI(); + PrintDebug("SVM Entry...\n"); + rdtscll(info->time_state.cached_host_tsc); guest_ctrl->TSC_OFFSET = info->time_state.guest_tsc - info->time_state.cached_host_tsc; safe_svm_launch((vmcb_t*)(info->vmm_data), &(info->vm_regs)); rdtscll(tmp_tsc); + PrintDebug("SVM Returned\n"); - //PrintDebug("SVM Returned\n"); v3_update_time(info, tmp_tsc - info->time_state.cached_host_tsc); diff --git a/palacios/src/palacios/svm_handler.c b/palacios/src/palacios/svm_handler.c index 83f7628..f7916fc 100644 --- a/palacios/src/palacios/svm_handler.c +++ b/palacios/src/palacios/svm_handler.c @@ -38,10 +38,10 @@ int handle_svm_exit(struct guest_info * info) { // Disable printing io exits due to bochs debug messages - if (!((exit_code == VMEXIT_IOIO) && ((ushort_t)(guest_ctrl->exit_info1 >> 16) == 0x402))) { + //if (!((exit_code == VMEXIT_IOIO) && ((ushort_t)(guest_ctrl->exit_info1 >> 16) == 0x402))) { - PrintDebug("SVM Returned: Exit Code: %x \t\t(tsc=%ul)\n",exit_code, (uint_t)info->time_state.guest_tsc); - } + PrintDebug("SVM Returned: Exit Code: %x \t\t(tsc=%ul)\n",exit_code, (uint_t)info->time_state.guest_tsc); + // } // PrintDebugVMCB((vmcb_t*)(info->vmm_data)); @@ -197,6 +197,8 @@ int handle_svm_exit(struct guest_info * info) { guest_ctrl->guest_ctrl.V_IGN_TPR = 1; guest_ctrl->guest_ctrl.V_INTR_PRIO = 0xf; + PrintDebug("Injecting Interrupt %d (EIP=%x)\n", guest_ctrl->guest_ctrl.V_INTR_VECTOR, info->rip); + injecting_intr(info, irq, EXTERNAL_IRQ); break; @@ -217,6 +219,7 @@ int handle_svm_exit(struct guest_info * info) { guest_ctrl->EVENTINJ.vector = excp; + PrintDebug("Injecting Interrupt %d (EIP=%x)\n", guest_ctrl->EVENTINJ.vector, info->rip); injecting_intr(info, excp, EXCEPTION); break; } @@ -233,7 +236,6 @@ int handle_svm_exit(struct guest_info * info) { return -1; } - PrintDebug("Injecting Interrupt %d (EIP=%x)\n", guest_ctrl->EVENTINJ.vector, info->rip); } diff --git a/palacios/src/palacios/svm_io.c b/palacios/src/palacios/svm_io.c index d70be6f..38f0b8e 100644 --- a/palacios/src/palacios/svm_io.c +++ b/palacios/src/palacios/svm_io.c @@ -20,7 +20,7 @@ int handle_svm_io_in(struct guest_info * info) { return -1; } - //PrintDebug("IN on port %d (0x%x)\n", io_info->port, io_info->port); + PrintDebug("IN on port %d (0x%x)\n", io_info->port, io_info->port); if (io_info->sz8) { read_size = 1; @@ -80,17 +80,20 @@ int handle_svm_io_ins(struct guest_info * info) { return -1; } - //PrintDebug("INS on port %d (0x%x)\n", io_info->port, io_info->port); + PrintDebug("INS on port %d (0x%x)\n", io_info->port, io_info->port); - if (io_info->sz8) { + if (io_info->sz8) { read_size = 1; } else if (io_info->sz16) { read_size = 2; } else if (io_info->sz32) { read_size = 4; + } else { + PrintDebug("io_info Invalid Size\n"); + return -1; } - + if (io_info->addr16) { mask = 0xffff; } else if (io_info->addr32) { @@ -98,15 +101,17 @@ int handle_svm_io_ins(struct guest_info * info) { } else if (io_info->addr64) { mask = 0xffffffffffffffffLL; } else { - // should never happen - return -1; + // This value should be set depending on the host register size... + mask = get_gpr_mask(info); } if (io_info->rep) { - rep_num = info->vm_regs.rcx & mask; + // rep_num = info->vm_regs.rcx & mask; + rep_num = info->vm_regs.rcx; } + PrintDebug("INS size=%d for %d steps\n", read_size, rep_num); while (rep_num > 0) { addr_t host_addr; @@ -114,6 +119,8 @@ int handle_svm_io_ins(struct guest_info * info) { if (guest_va_to_host_va(info, dst_addr, &host_addr) == -1) { // either page fault or gpf... + PrintDebug("Could not convert Guest VA to host VA\n"); + return -1; } if (hook->read(io_info->port, (char*)host_addr, read_size, hook->priv_data) != read_size) { @@ -150,7 +157,7 @@ int handle_svm_io_out(struct guest_info * info) { return -1; } - //PrintDebug("OUT on port %d (0x%x)\n", io_info->port, io_info->port); + PrintDebug("OUT on port %d (0x%x)\n", io_info->port, io_info->port); if (io_info->sz8) { write_size = 1; @@ -208,7 +215,7 @@ int handle_svm_io_outs(struct guest_info * info) { return -1; } - //PrintDebug("OUTS on port %d (0x%x)\n", io_info->port, io_info->port); + PrintDebug("OUTS on port %d (0x%x)\n", io_info->port, io_info->port); if (io_info->sz8) { write_size = 1; @@ -227,6 +234,7 @@ int handle_svm_io_outs(struct guest_info * info) { mask = 0xffffffffffffffffLL; } else { // should never happen + PrintDebug("Invalid Address length\n"); return -1; } diff --git a/palacios/src/palacios/vmm_ctrl_regs.c b/palacios/src/palacios/vmm_ctrl_regs.c index a05f1b9..8f7f6fc 100644 --- a/palacios/src/palacios/vmm_ctrl_regs.c +++ b/palacios/src/palacios/vmm_ctrl_regs.c @@ -291,13 +291,14 @@ int handle_cr0_read(struct guest_info * info) { if (guest_pa_to_host_va(info, first_operand + (info->segments.ds.base << 4), &host_addr) == -1) { // gpf the guest + PrintDebug("Could not convert guest physical address to host virtual address\n"); return -1; } first_operand = host_addr; } else { - // error... don't know what to do - return -1; + // Register operand + // Should be ok?? } cr0_val = *(char*)cr0 & 0x0f;