diff --git a/core/vcpu.c b/core/vcpu.c index 47a261e..65cd6a4 100644 --- a/core/vcpu.c +++ b/core/vcpu.c @@ -40,7 +40,7 @@ static uint64_t read_aux_mu(struct vm* _vm, uint64_t addr){ if(_vm->cpu.aux_regs.aux_mu_lcr_reg & AUX_MU_LCR_DLAB){ return _vm->cpu.aux_regs.aux_mu_baud_reg & 0xff; }else{ - return console_pop(&_vm->output_console); + return console_pop(&_vm->input_console); } case AUX_MU_IER_REG: if(_vm->cpu.aux_regs.aux_mu_lcr_reg & AUX_MU_LCR_DLAB){ diff --git a/drivers/uart.c b/drivers/uart.c index 40b4940..f6aacd3 100644 --- a/drivers/uart.c +++ b/drivers/uart.c @@ -10,9 +10,11 @@ #include "stdio.h" #include "shell/shell.h" #include +#include "core/vm.h" +#include "core/console.h" uint8_t vm_connected_to_uart = VMID_SHELL; // initially only hypervisor shell is connected to physical UART. - +extern struct vm* vmlist[CONFIG_MAX_VMs]; void uart_init(){ mm_w(AUX_ENABLES, mm_r(AUX_ENABLES) | 0x1); @@ -93,4 +95,28 @@ void uart_write_hex(unsigned long long x){ void uart_handler(){ if(vm_connected_to_uart == VMID_SHELL) shell_run(); + else{ + char input = mm_r32(AUX_MU_IO_REG) & 0xff; + static int escape_char_pressed = 0; + if(input == '!'){ + escape_char_pressed = 1; + }else{ + + if(escape_char_pressed){ + if(input == '1'){ + vm_connected_to_uart = VMID_SHELL; + } + + escape_char_pressed = 0; + }else{ + if(vmlist[vm_connected_to_uart]->state == VM_RUNNING){ + console_push(&vmlist[vm_connected_to_uart]->input_console, input); + } + } + + + } + + + } } \ No newline at end of file diff --git a/shell/shell.c b/shell/shell.c index 5e809e1..165a303 100644 --- a/shell/shell.c +++ b/shell/shell.c @@ -58,7 +58,7 @@ static void add_shell_command(char command[], void (*command_handler)){ void shell_run(){ if(!SHELL_ACTIVE_BEFORE){ - printf(">>> "); + printf("deltaV >>> "); SHELL_ACTIVE_BEFORE = 1; } char shell_input[CONFIG_MAX_SHELL_COMMAND_SIZE]; @@ -74,7 +74,7 @@ void shell_run(){ } if(!command_recognised) printf("command not recognised.\n"); - printf(">>> "); + if(vm_connected_to_uart == VMID_SHELL) printf("deltaV >>> "); } void shell_init(){ @@ -112,13 +112,19 @@ void enter(){ return; } - printf("Inside VM %d", vmid); - printf("\n"); + printf("Inside VM %d\n", vmid); + printf("Press !1 to exit.\n"); printf("\n"); printf("\n"); vm_connected_to_uart = vmid; - console_print(&vmlist[vmid]->output_console); + console_flush(&vmlist[vm_connected_to_uart]->output_console); + + if(vmlist[vm_connected_to_uart]->state == VM_RUNNING){ + console_flush(&vmlist[vm_connected_to_uart]->output_console); + } + + return; }