vxKernel/include/vhex/hypervisor.h

95 lines
2.3 KiB
C

#ifndef __VHEX_HYPERVISOR__
# define __VHEX_HYPERVISOR__
#include <stddef.h>
#include <stdint.h>
/* declare driver structure */
#include <vhex/driver.h>
/* real Vhex world with driver bitmap and meta information for the hypervisor */
struct vhex_world {
/* world driver information */
struct {
struct vhex_driver *context;
int flags;
} *driver;
/* internal information used by the hypervisor */
char const * name;
uint8_t status;
};
/* define world status states */
#define HYP_WORLD_STATUS_STATE_UNUSED (1 << 0)
#define HYP_WORLD_STATUS_STATE_UNINIT (1 << 1)
#define HYP_WORLD_STATUS_STATE_USED (1 << 2)
/* define world status flags */
#define HYP_WORLD_STATUS_FLAG_UNDELETABLE (1 << 0)
/* hypervisor world status helper */
#define HYP_WORLD_STATUS_SET(flags,state) \
(((flags & 0x0f) << 4) | ((state & 0x0f) << 0))
#define HYP_WORLD_STATUS_SET_STATE(status, state) \
do { \
status &= 0x0f; \
status |= (state & 0x0f) << 0; \
} while (0);
#define HYP_WORLD_STATUS_SET_FLAGS(status, flags) \
do { \
status &= 0xf0; \
status |= (state & 0x0f) << 4; \
} while (0);
/* hypervisor world status getter */
#define HYP_WORLD_STATUS_FLAGS(status) ((status & 0xf0) >> 4)
#define HYP_WORLD_STATUS_STATE(status) ((status & 0x0f) >> 0)
/* hypervisor driver status */
enum {
HYP_WORLD_DRV_UNUSED = VHEX_DRV_UNUSED,
HYP_WORLD_DRV_USED = VHEX_DRV_USED,
};
/* hyp_word_t : hypervisor world ID */
typedef int hyp_world_t;
//---
// User-level API
//---
/* possible returned value */
enum {
hyp_world_already_exists = -1,
hyp_world_not_found = -2,
hyp_world_bad_id = -3,
hyp_world_currently_in_use = -4,
hyp_world_undeletable = -5,
};
/* hypervisor_world_new() : create a new world with its name */
extern hyp_world_t hypervisor_world_new(
char const * const restrict name,
int flags
);
/* hypervisor_world_find() : find a world ID using its name */
extern hyp_world_t hypervisor_world_find(char const * const restrict name);
/* hypervisor_world_get() : get a word using its ID */
extern struct vhex_world *hypervisor_world_get(hyp_world_t id);
/* hypervisor_world_switch() : perform a world switch */
extern int hypervisor_world_switch(hyp_world_t out, hyp_world_t in);
/* hypervisor_world_delete() : remove world */
extern hyp_world_t hypervisor_world_delete(hyp_world_t id);
#endif /* __VHEX_HYPERVISOR__ */