diff --git a/guest/guest_main.c b/guest/guest_main.c index fb9eec6c3364c0fd7c9aa5fcec4e7442048c70cf..e12e6d1fd18fb4904404e5ac92483bfda0d95d6e 100644 --- a/guest/guest_main.c +++ b/guest/guest_main.c @@ -7,20 +7,27 @@ #include "gfx/gfx.h" #include "ide/ide.h" #include "timer/timer.h" +#include "sprite/sprite.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 -#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 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 #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 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 #endif void guest_main() { @@ -42,6 +49,11 @@ void guest_main() { char data[SECTOR_SIZE] = "here are my data !\n"; ide_write(0, data); + // - sprite - + sprite_init(0, 0x123, 200, 100); + sprite_visibility(0, 1); + sprite_position(0, 50, 50); + halt(); } diff --git a/guest/sprite/sprite.h b/guest/sprite/sprite.h new file mode 100644 index 0000000000000000000000000000000000000000..34f8f1747a750f015871c209cdbd107d57ed427f --- /dev/null +++ b/guest/sprite/sprite.h @@ -0,0 +1,24 @@ +#ifndef _SPRITE_H_ +#define _SPRITE_H_ + +#include <stdint.h> + +// --- DEFINE --- + +// ... + +// --- FUNCTION --- + +void sprite_pv_init(uint8_t id, uint64_t data, uint32_t width, uint32_t height); + +void sprite_pv_visibility(uint8_t id, uint8_t toggle); + +void sprite_pv_position(uint8_t id, uint32_t x, uint32_t y); + +void sprite_phys_init(uint8_t id, uint64_t data, uint32_t width, uint32_t height); + +void sprite_phys_visibility(uint8_t id, uint8_t toggle); + +void sprite_phys_position(uint8_t id, uint32_t x, uint32_t y); + +#endif // !_SPRITE_H_ diff --git a/guest/sprite/sprite_phys.c b/guest/sprite/sprite_phys.c new file mode 100644 index 0000000000000000000000000000000000000000..b3b6fad3d584ee51045214b514516492a214beae --- /dev/null +++ b/guest/sprite/sprite_phys.c @@ -0,0 +1,25 @@ +#include "sprite.h" + +#include <stdint.h> +#include "shared/hypercall_params.h" + +// --- DEFINE --- + +// ... + +// --- FUNCTION --- + +// void gfx_phys_init(uint32_t width, uint32_t height) { +// +// while (*(uint32_t *)REG_GFX_INIT_ST == 42); +// +// *(uint32_t *)REG_GFX_INIT_CMD = 5; +// *(uint32_t *)REG_GFX_INIT_DATA = width; +// *(uint32_t *)REG_GFX_INIT_DATA = height; +// } + +void sprite_phys_init(uint8_t id, uint64_t data, uint32_t width, uint32_t height) { } + +void sprite_phys_visibility(uint8_t id, uint8_t toggle) { } + +void sprite_phys_position(uint8_t id, uint32_t x, uint32_t y) { } diff --git a/guest/sprite/sprite_pv.c b/guest/sprite/sprite_pv.c new file mode 100644 index 0000000000000000000000000000000000000000..204142acdcde6a339463a8969b8eab4c914c79f0 --- /dev/null +++ b/guest/sprite/sprite_pv.c @@ -0,0 +1,44 @@ +#include "sprite.h" + +#include "guest/utils.h" +#include "guest/pmio.h" +#include "shared/hypercall_params.h" + +// --- DEFINE --- + +// ... + +// --- FUNCTION --- + +void sprite_pv_init(uint8_t id, uint64_t data, uint32_t width, uint32_t height) { + + hyper_sprite_init_params_t param_sprite_init; + param_sprite_init.id = id; + param_sprite_init.data = data; + param_sprite_init.width = width; + param_sprite_init.height = height; + memcpy((void *)HYPERCALL_SHARED_ADDR, (void *)¶m_sprite_init, sizeof(param_sprite_init)); + + outb(HYPERCALL_PMIO_ADDR, HYPERCALL_CODE_SPRITE_INIT); +} + +void sprite_pv_visibility(uint8_t id, uint8_t toggle) { + + hyper_sprite_visibility_params_t param_sprite_vis; + param_sprite_vis.id = id; + param_sprite_vis.toggle = toggle; + memcpy((void *)HYPERCALL_SHARED_ADDR, (void *)¶m_sprite_vis, sizeof(param_sprite_vis)); + + outb(HYPERCALL_PMIO_ADDR, HYPERCALL_CODE_SPRITE_VISI); +} + +void sprite_pv_position(uint8_t id, uint32_t x, uint32_t y) { + + hyper_sprite_position_params_t param_sprite_pos; + param_sprite_pos.id = id; + param_sprite_pos.x = x; + param_sprite_pos.y = y; + memcpy((void *)HYPERCALL_SHARED_ADDR, (void *)¶m_sprite_pos, sizeof(param_sprite_pos)); + + outb(HYPERCALL_PMIO_ADDR, HYPERCALL_CODE_SPRITE_POS); +} diff --git a/shared/hypercall_params.h b/shared/hypercall_params.h index b58c333c0d9fc52bcb33ed76d55b165a217f444f..17ab1e09504de866786531d8e3fa2d9d0509fc77 100644 --- a/shared/hypercall_params.h +++ b/shared/hypercall_params.h @@ -10,10 +10,13 @@ #define HYPERCALL_SHARED_ADDR 0xC0000000 #define HYPERCALL_BUFF_SIZE 4096 -#define HYPERCALL_CODE_CONSOLE 1 -#define HYPERCALL_CODE_TIMER 2 -#define HYPERCALL_CODE_GFX_INIT 3 -#define HYPERCALL_CODE_IDE 4 +#define HYPERCALL_CODE_CONSOLE 1 +#define HYPERCALL_CODE_TIMER 2 +#define HYPERCALL_CODE_GFX_INIT 3 +#define HYPERCALL_CODE_IDE 4 +#define HYPERCALL_CODE_SPRITE_INIT 5 +#define HYPERCALL_CODE_SPRITE_VISI 6 +#define HYPERCALL_CODE_SPRITE_POS 7 #define REG_TIMER_CMD 0x43 #define REG_TIMER_DATA 0x40 @@ -46,6 +49,27 @@ typedef struct { uint64_t data; // address of data to write (512 bytes) } __attribute__((packed)) hyper_ide_params_t; +typedef struct { + + uint8_t id; // sprite identifier + uint64_t data; // data address + uint32_t width; // width in pixels + uint32_t height; // height in pixels +} __attribute__((packed)) hyper_sprite_init_params_t; + +typedef struct { + + uint8_t id; // sprite identifier + uint8_t toggle; // visibility (1 = visible , 0 = not visible ) +} __attribute__((packed)) hyper_sprite_visibility_params_t; + +typedef struct { + + uint8_t id; // sprite identifier + uint32_t x; // x position + uint32_t y; // y position +} __attribute__((packed)) hyper_sprite_position_params_t; + // --- FUNCTION --- // ... diff --git a/vmm/handler.c b/vmm/handler.c index a67e00ffb559f1af70e50a8149d4b2ab6f28d246..07c8cfbba2fbed530a79910ac194f1b72a9493e9 100644 --- a/vmm/handler.c +++ b/vmm/handler.c @@ -258,6 +258,26 @@ static void wrapper_op_ide(uint8_t *shared_buf, uint8_t *mem) { op_callback_ide_conclude(p_ide); } +static void wrapper_op_sprite_init(uint8_t *shared_buf, uint8_t *mem) { + + hyper_sprite_init_params_t *p_sprite = (hyper_sprite_init_params_t *)shared_buf; + p_sprite->data = p_sprite->data + (uint64_t)mem; + + op_callback_sprite_init_conclude(p_sprite); +} + +static void wrapper_op_sprite_visibility(uint8_t *shared_buf) { + + hyper_sprite_visibility_params_t *p_sprite = (hyper_sprite_visibility_params_t *)shared_buf; + op_callback_sprite_visibility_conclude(p_sprite); +} + +static void wrapper_op_sprite_position(uint8_t *shared_buf) { + + hyper_sprite_position_params_t *p_sprite = (hyper_sprite_position_params_t *)shared_buf; + op_callback_sprite_position_conclude(p_sprite); +} + // --- FUNCTION --- // - VMM EXIT REASON HANDLER - @@ -356,6 +376,18 @@ void handle_hypercall(uint32_t code, uint8_t *shared_buf, uint8_t *mem) { wrapper_op_ide(shared_buf, mem); break; + case HYPERCALL_CODE_SPRITE_INIT: + wrapper_op_sprite_init(shared_buf, mem); + break; + + case HYPERCALL_CODE_SPRITE_VISI: + wrapper_op_sprite_visibility(shared_buf); + break; + + case HYPERCALL_CODE_SPRITE_POS: + wrapper_op_sprite_position(shared_buf); + break; + default: errx(1, "Unsupported hypercall code.\n"); break; diff --git a/vmm/operation.c b/vmm/operation.c index d68c7c0a9f92ede1b57838170c329daaceb4e8af..f1eba0556ffb87acceb28af8474027387da7a6e0 100644 --- a/vmm/operation.c +++ b/vmm/operation.c @@ -55,6 +55,9 @@ bool flag_stop_loop = false; static hyper_timer_sleep_params_t param_timer; static hyper_init_gfx_params_t param_gfx_init; static hyper_ide_params_t param_ide; +static hyper_sprite_init_params_t param_sprite_init; +static hyper_sprite_visibility_params_t param_sprite_vis; +static hyper_sprite_position_params_t param_sprite_pos; // store the index of the actual loop static uint32_t loop_ide_data = MAX_LOOP_IDE_DATA; @@ -177,3 +180,28 @@ void op_callback_ide_conclude(void *addr) { fclose(disk); } + +void op_callback_sprite_init_conclude(void *addr) { + + hyper_sprite_init_params_t *p_sprite_init = (addr == NULL) ? ¶m_sprite_init : (hyper_sprite_init_params_t *)addr; + + printf("OPERATION : initializing sprite %d of size %dx%d...\n", p_sprite_init->id, p_sprite_init->width, p_sprite_init->height); + // TODO: +} + +void op_callback_sprite_visibility_conclude(void *addr) { + + hyper_sprite_visibility_params_t *p_sprite_vis = (addr == NULL) ? ¶m_sprite_vis : (hyper_sprite_visibility_params_t *)addr; + + printf("OPERATION : setting the visibility of the sprite %d at %d...\n", p_sprite_vis->id, p_sprite_vis->toggle); + // TODO: +} + +void op_callback_sprite_position_conclude(void *addr) { + + hyper_sprite_position_params_t *p_sprite_pos = (addr == NULL) ? ¶m_sprite_pos : (hyper_sprite_position_params_t *)addr; + + printf("OPERATION : setting the poistion of the sprite %d at (%d, %d)...\n", p_sprite_pos->id, p_sprite_pos->x, p_sprite_pos->y); + // TODO: +} + diff --git a/vmm/operation.h b/vmm/operation.h index b9e009c481874c1acff30130b0cf758c1eef6868..8970df9a0b56325c6b9c939f59c08328c539faa8 100644 --- a/vmm/operation.h +++ b/vmm/operation.h @@ -139,4 +139,10 @@ void op_callback_ide_store_data(void *addr); */ void op_callback_ide_conclude(void *addr); +void op_callback_sprite_init_conclude(void *addr); + +void op_callback_sprite_visibility_conclude(void *addr); + +void op_callback_sprite_position_conclude(void *addr); + #endif // _OPERATION_H_