Skip to content

Commit

Permalink
added guestOS shell i/o from hypervisor shell.
Browse files Browse the repository at this point in the history
  • Loading branch information
yuvraj1803 committed Nov 2, 2023
1 parent b0eeb66 commit 8f262fa
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
2 changes: 1 addition & 1 deletion core/vcpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
28 changes: 27 additions & 1 deletion drivers/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
#include "stdio.h"
#include "shell/shell.h"
#include <stdint.h>
#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);
Expand Down Expand Up @@ -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);
}
}


}


}
}
16 changes: 11 additions & 5 deletions shell/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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(){
Expand Down Expand Up @@ -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;

}

Expand Down

0 comments on commit 8f262fa

Please sign in to comment.