diff --git a/guest/guest_main.c b/guest/guest_main.c index 1d0cfed8841b0af4a69df8d046ae7bed3a813542..920f4e52947248fec356524e357243d693ebde0f 100644 --- a/guest/guest_main.c +++ b/guest/guest_main.c @@ -13,6 +13,7 @@ #include "timer/timer.h" #include "sprite/sprite.h" #include "console/console.h" +#include "keyboard/keyboard.h" #include "guest/resources/resources.h" @@ -21,21 +22,23 @@ // If PV == 1 => uses paravirtualized drivers (when available) // If PV == 0 => uses physical (hardware) drivers (when available) #if PV == 1 -#define timer_wait timer_pv_wait -#define console_send console_pv_send -#define gfx_init gfx_pv_init -#define ide_write ide_pv_write_sector -#define sprite_init sprite_pv_init -#define sprite_visibility sprite_pv_visibility -#define sprite_position sprite_pv_position +#define timer_wait timer_pv_wait +#define console_send console_pv_send +#define gfx_init gfx_pv_init +#define ide_write ide_pv_write_sector +#define sprite_init sprite_pv_init +#define sprite_visibility sprite_pv_visibility +#define sprite_position sprite_pv_position +#define keyboard_get_keycode keyboard_pv_get_keycode #else -#define timer_wait timer_phys_wait -#define console_send console_pv_send -#define gfx_init gfx_phys_init -#define ide_write ide_phys_write_sector -#define sprite_init sprite_phys_init -#define sprite_visibility sprite_phys_visibility -#define sprite_position sprite_phys_position +#define timer_wait timer_phys_wait +#define console_send console_pv_send +#define gfx_init gfx_phys_init +#define ide_write ide_phys_write_sector +#define sprite_init sprite_phys_init +#define sprite_visibility sprite_phys_visibility +#define sprite_position sprite_phys_position +#define keyboard_get_keycode keyboard_pv_get_keycode #endif uint32_t x = 50; @@ -47,16 +50,12 @@ void keyboard_handler(void) { #if PV == 1 - hyper_keyboard_params_t *p_keyboard = (hyper_keyboard_params_t *)HYPERCALL_SHARED_ADDR; - char key = (char)p_keyboard->key; + char key = (char)keyboard_get_keycode(); #else char key = (char)ind(REG_KEYBOARD_DATA); #endif - // char str[125]; snprintf(str, 125, "key received : %c\n", key); - // console_send(str); - switch (key) { case 'w': diff --git a/guest/keyboard/keaboard_pv.c b/guest/keyboard/keaboard_pv.c new file mode 100644 index 0000000000000000000000000000000000000000..fdcd80dd885ca483c76b341c90f84880e77bfd3d --- /dev/null +++ b/guest/keyboard/keaboard_pv.c @@ -0,0 +1,24 @@ +#include "keyboard.h" + +#include <stdint.h> + +#include "guest/utils.h" +#include "guest/pmio.h" +#include "shared/hypercall_params.h" + +// --- DEFINE --- + +// ... + +// --- FUNCTION --- + +uint32_t keyboard_pv_get_keycode(void) { + + hyper_keyboard_params_t param_keyboard; + memcpy((void *)HYPERCALL_SHARED_ADDR, (void *)¶m_keyboard, sizeof(param_keyboard)); + + outb(HYPERCALL_PMIO_ADDR, HYPERCALL_CODE_KEYBOARD); + + hyper_keyboard_params_t *p_keyboard = (hyper_keyboard_params_t *)HYPERCALL_SHARED_ADDR; + return p_keyboard->key; +} diff --git a/guest/keyboard/keyboard.h b/guest/keyboard/keyboard.h new file mode 100644 index 0000000000000000000000000000000000000000..c933347a2c1bbeb3207528f379694078d3e3cd59 --- /dev/null +++ b/guest/keyboard/keyboard.h @@ -0,0 +1,14 @@ +#ifndef _KEYBOARD_H_ +#define _KEYBOARD_H_ + +#include <stdint.h> + +// --- DEFINE --- + +// ... + +// --- FUNCTION --- + +uint32_t keyboard_pv_get_keycode(void); + +#endif // _KEYBOARD_H_ diff --git a/vmm/handler.c b/vmm/handler.c index 957b38bf825af34b13ac0f0fc392356a5e9ce746..24ef1ed0edf88634328c59aeb6c0dc37506af4b7 100644 --- a/vmm/handler.c +++ b/vmm/handler.c @@ -396,6 +396,11 @@ void handle_hypercall(uint32_t code, uint8_t *shared_buf, uint8_t *mem) { wrapper_op_sprite_position(shared_buf); break; + case HYPERCALL_CODE_KEYBOARD: + // WARNING: It doesn't have any wrapper as the phys call is quite special (no conclud func) + op_keyboard_pv_send_code(shared_buf, last_key_pressed); + break; + default: errx(1, "Unsupported hypercall code.\n"); break; diff --git a/vmm/operation.c b/vmm/operation.c index e5d63364373d22fe0179b626f7e1d881a9ea650b..3fc1107319161d8e06dc4b0e1aa8d236264c464a 100644 --- a/vmm/operation.c +++ b/vmm/operation.c @@ -10,6 +10,7 @@ #include <unistd.h> #include <semaphore.h> +#include "vmm/handler.h" #include "shared/ide_regs.h" #include "shared/hypercall_params.h" @@ -351,8 +352,8 @@ void op_callback_sprite_position_conclude(void *addr) { void op_keyboard_pv_send_code(void *shared_buf, uint32_t key) { - hyper_keyboard_params_t param_key; - param_key.key = key; + printf("OPERATION : updating %d (%c) as the keycode of the shared buffer...\n", key, (char)key); - memcpy(shared_buf, (void *)¶m_key, sizeof(param_key)); + hyper_keyboard_params_t *p_keyboard = (hyper_keyboard_params_t *)shared_buf; + p_keyboard->key = key; } diff --git a/vmm/vmm_main.c b/vmm/vmm_main.c index e4f08a86b89f9f32fb66a7c5978c63b8699d0195..e3a1e2f4adaaea63f1051d738154f576ddfc51ed 100644 --- a/vmm/vmm_main.c +++ b/vmm/vmm_main.c @@ -74,7 +74,7 @@ int main(int argc, char* argv[]) int32_t mmap_size; // -- 0. Handle Args -- - if (argc != 3) err(1, "Number of args invalide"); + if (argc != 3) errx(1, "Number of args invalide"); char *file_path = argv[1]; disk_path = argv[2]; @@ -234,9 +234,6 @@ int main(int argc, char* argv[]) // - write key code to guest - last_key_pressed = (uint32_t)key; - // WARNING: no need to do it in emulation, but whatever... - op_keyboard_pv_send_code(shared_buf, last_key_pressed); - // - trigger interrupt - struct kvm_irq_level irq_level; irq_level.irq = 1; // 1 -> key interrupt