From 0ef22830f508baa9d981f9e9bfdba4b4bf69bdf9 Mon Sep 17 00:00:00 2001
From: "adrian.spycher" <adrian.spycher@etu.hesge.ch>
Date: Sat, 2 Nov 2024 18:09:44 +0100
Subject: [PATCH] feat: handle run_pv and run_phys

---
 guest/console/console.h    |  2 +-
 guest/console/console_pv.c |  2 +-
 guest/guest_main.c         | 34 ++++++++++++----------------------
 vmm/operation.c            |  6 +++---
 4 files changed, 17 insertions(+), 27 deletions(-)

diff --git a/guest/console/console.h b/guest/console/console.h
index 64d693a..d8d494e 100644
--- a/guest/console/console.h
+++ b/guest/console/console.h
@@ -7,6 +7,6 @@
 
 // --- FUNCTION ---
 
-void console_send_pv(char *str);
+void console_pv_send(char *str);
 
 #endif // _CONSOLE_H_
diff --git a/guest/console/console_pv.c b/guest/console/console_pv.c
index 5a6b9de..d0616e0 100644
--- a/guest/console/console_pv.c
+++ b/guest/console/console_pv.c
@@ -10,7 +10,7 @@
 
 // --- FUNCTION ---
 
-void console_send_pv(char *str) {
+void console_pv_send(char *str) {
 
     hyper_virtual_console_params_t param_console;
     param_console.msg = (uint64_t)str;
diff --git a/guest/guest_main.c b/guest/guest_main.c
index be271eb..092e96f 100644
--- a/guest/guest_main.c
+++ b/guest/guest_main.c
@@ -1,12 +1,8 @@
 #include <stdint.h>
 
 #include "idt.h"
-#include "utils.h"
 #include "x86.h"
-#include "pmio.h"
-#include "shared/hypercall_params.h"
 
-#include "ide/ide.h"
 #include "gfx/gfx.h"
 #include "timer/timer.h"
 #include "console/console.h"
@@ -14,36 +10,30 @@
 // If PV == 1 => uses paravirtualized drivers (when available)
 // If PV == 0 => uses physical (hardware) drivers (when available)
 #if PV == 1
-#define timer_sleep timer_sleep_pv
+#define timer_wait    timer_pv_wait
+#define console_send  console_pv_send
+#define gfx_init      gfx_pv_init
 #else
-#define timer_sleep timer_sleep_phys
+#define timer_wait    timer_phys_wait
+#define console_send  console_pv_send
+#define gfx_init      gfx_phys_init
 #endif
 
-// Dummy examples
-// void timer_sleep_pv(int usec) {}
-// void timer_sleep_phys(int usec) {}
-
 void guest_main() {
 
     idt_init();  // Initialize interrupt subsystem
     sti();       // Enable hardware interrupts
 
-    // - pv console -
+    // - console -
     char *str = "Hi from the guest !";
-    console_send_pv(str);
-
-    // - pv timer -
-    timer_pv_wait(1e6);
+    console_send(str);
 
-    // - phys timer -
-    timer_phys_wait(1e6);
+    // - timer -
+    timer_wait(1e6);
 
-    // - pv gfx init -
+    // - gfx init -
     gfx_pv_init(1920, 1080);
 
-    // - phys gfx init -
-    /* gfx_phys_init(1920, 1080); */
-
-    // timer_sleep(100000);
+    timer_wait(1e7);
 }
 
diff --git a/vmm/operation.c b/vmm/operation.c
index 54035b2..e0f3406 100644
--- a/vmm/operation.c
+++ b/vmm/operation.c
@@ -44,7 +44,7 @@ void op_callback_console_conclude(void *addr) {
 
     hyper_virtual_console_params_t *p_consol = (hyper_virtual_console_params_t *)addr;
 
-    printf("hypercall : sending a message...\n");
+    printf("action : sending a message...\n");
     printf("%s\n", (char *)p_consol->msg);
 }
 
@@ -57,7 +57,7 @@ void op_callback_timer_conclude(void *addr) {
 
     hyper_timer_sleep_params_t *p_timer = (addr == NULL) ? &param_timer : (hyper_timer_sleep_params_t *)addr;
 
-    printf("hypercall : setting up a %dus timer...\n", p_timer->us);
+    printf("action : setting up a %dus timer...\n", p_timer->us);
     usleep(p_timer->us);
 }
 
@@ -75,7 +75,7 @@ void op_callback_gfx_init_conclude(void *addr) {
 
     hyper_init_gfx_params_t *p_gfx_init = (addr == NULL) ? &param_gfx_init : (hyper_init_gfx_params_t *)addr;
 
-    printf("hypercall : initializing gfx %dx%d...\n", p_gfx_init->width, p_gfx_init->height);
+    printf("action : initializing gfx %dx%d...\n", p_gfx_init->width, p_gfx_init->height);
     width_gfx = p_gfx_init->width;
     height_gfx = p_gfx_init->height;
     sem_post(&sem_gfx);
-- 
GitLab