Skip to content
Snippets Groups Projects
Commit bffb454c authored by adrian.spycher's avatar adrian.spycher
Browse files

feat: organise guest code with libs for each peri

parent f7fd33e6
No related branches found
No related tags found
No related merge requests found
#ifndef _CONSOLE_H_
#define _CONSOLE_H_
// --- DEFINE ---
// ...
// --- FUNCTION ---
void console_send_pv(char *str);
#endif // _CONSOLE_H_
#include "console.h"
#include "guest/utils.h"
#include "guest/pmio.h"
#include "shared/hypercall_params.h"
// --- DEFINE ---
// ...
// --- FUNCTION ---
void console_send_pv(char *str) {
hyper_virtual_console_params_t param_console;
param_console.msg = (uint64_t)str;
memcpy((void *)HYPERCALL_SHARED_ADDR, (void *)&param_console, sizeof(param_console));
outb(HYPERCALL_PMIO_ADDR, HYPERCALL_CODE_CONSOLE);
}
#ifndef _GFX_H_
#define _GFX_H_
#include <stdint.h>
// --- DEFINE ---
// ...
// --- FUNCTION ---
void gfx_pv_init(uint32_t width, uint32_t height);
void gfx_phys_init(uint32_t width, uint32_t height);
#endif // !_TIMER_H_
#include "gfx.h"
#include "guest/utils.h"
#include "guest/pmio.h"
#include "shared/hypercall_params.h"
// --- DEFINE ---
// ...
// --- FUNCTION ---
void gfx_phys_init(uint32_t width, uint32_t height) {
// TODO:
}
#include "gfx.h"
#include "guest/utils.h"
#include "guest/pmio.h"
#include "shared/hypercall_params.h"
// --- DEFINE ---
// ...
// --- FUNCTION ---
void gfx_pv_init(uint32_t width, uint32_t height) {
hyper_init_gfx_params_t param_gfx;
param_gfx.width = width;
param_gfx.height = height;
memcpy((void *)HYPERCALL_SHARED_ADDR, (void *)&param_gfx, sizeof(param_gfx));
outb(HYPERCALL_PMIO_ADDR, HYPERCALL_CODE_GFX_INIT);
}
......@@ -6,6 +6,11 @@
#include "pmio.h"
#include "shared/hypercall_params.h"
#include "ide/ide.h"
#include "gfx/gfx.h"
#include "timer/timer.h"
#include "console/console.h"
// If PV == 1 => uses paravirtualized drivers (when available)
// If PV == 0 => uses physical (hardware) drivers (when available)
#if PV == 1
......@@ -23,40 +28,22 @@ void guest_main() {
idt_init(); // Initialize interrupt subsystem
sti(); // Enable hardware interrupts
// paravirtualized console
char *str = "abcdefgh";
hyper_virtual_console_params_t param_console;
param_console.msg = (uint64_t)str;
memcpy((void *)HYPERCALL_SHARED_ADDR, (void *)&param_console, sizeof(param_console));
outb(HYPERCALL_PMIO_ADDR, HYPERCALL_CODE_CONSOLE);
// paravirtualized timer
hyper_timer_sleep_params_t param_timer;
param_timer.us = 1e6;
memcpy((void *)HYPERCALL_SHARED_ADDR, (void *)&param_timer, sizeof(param_timer));
// - pv console -
char *str = "Hi from the guest !";
console_send_pv(str);
outb(HYPERCALL_PMIO_ADDR, HYPERCALL_CODE_TIMER);
// - pv timer -
timer_pv_wait(1e6);
// emulated timer
// - phys timer -
timer_phys_wait(1e6);
outw(REG_TIMER_CMD, 20);
outd(REG_TIMER_DATA, 1e6);
// - pv gfx init -
gfx_pv_init(1920, 1080);
// paravirtualized gfx init
hyper_init_gfx_params_t param_gfx;
param_gfx.width = 1920;
param_gfx.height = 1080;
memcpy((void *)HYPERCALL_SHARED_ADDR, (void *)&param_gfx, sizeof(param_gfx));
outb(HYPERCALL_PMIO_ADDR, HYPERCALL_CODE_GFX_INIT);
// emulated gfx init
// TODO:
// - phys gfx init -
/* gfx_phys_init(1920, 1080); */
// timer_sleep(100000);
}
#ifndef _TIMER_H_
#define _TIMER_H_
#include <stdint.h>
// --- DEFINE ---
// ...
// --- FUNCTION ---
void timer_pv_wait(uint32_t us);
void timer_phys_wait(uint32_t us);
#endif // !_TIMER_H_
#include "timer.h"
#include "guest/pmio.h"
#include "shared/hypercall_params.h"
// --- DEFINE ---
// ...
// --- FUNCTION ---
void timer_phys_wait(uint32_t us) {
outw(REG_TIMER_CMD, 20);
outd(REG_TIMER_DATA, us);
}
#include "timer.h"
#include "guest/utils.h"
#include "guest/pmio.h"
#include "shared/hypercall_params.h"
// --- DEFINE ---
// ...
// --- FUNCTION ---
void timer_pv_wait(uint32_t us) {
hyper_timer_sleep_params_t param_timer;
param_timer.us = us;
memcpy((void *)HYPERCALL_SHARED_ADDR, (void *)&param_timer, sizeof(param_timer));
outb(HYPERCALL_PMIO_ADDR, HYPERCALL_CODE_TIMER);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment