fxBoot/include/fxBoot/hypervisor.h

178 lines
4.4 KiB
C

#ifndef __FXBOOT_LOADER_H__
# define __FXBOOT_LOADER_H__
#include <stddef.h>
#include <stdint.h>
/* define smemfs_*() pirmitive */
#include "fxBoot/fs/smemfs.h"
/* define tsession */
#include <gintrace/tracer.h>
#define HYPERVISOR_BSS __attribute__((section(".hypervisor.bss")))
//---
// World switch structure
// TODO: move me !
//--
/* Define the SuperH CPU hardware context */
struct cpuctx {
uintptr_t reg[16];
uintptr_t gbr;
uintptr_t macl;
uintptr_t mach;
uintptr_t ssr;
uintptr_t spc;
uintptr_t pr;
};
#define HYPERVISOR_STACK_KERNEL_SIZE (2 * 1024)
#define HYPERVISOR_STACK_USER_SIZE (10 * 1024)
/* hworld: Wolrd context, used by the hypervisor
Be careful, many information are completely hardcoded in some assembly
sources. So, if you may change or update this structur, check all assembly
file. */
struct hworld {
/* stack information (NEVER CHANGE THE ORDER )*/
struct {
void *kernel;
void *user;
} stack;
/* hardware context (NEVER CHANGE THE ORDER OF "drivers" AND "cpu") */
struct {
void *drivers;
struct cpuctx cpu;
} context;
/* memory information */
struct {
struct {
void *start;
size_t size;
struct {
uintptr_t vmin;
uintptr_t vmax;
} elf;
} program;
struct {
void *kernel;
void *user;
struct {
size_t kernel;
size_t user;
} size;
} stack;
} memory;
/* private information (used by the hypeviseur) */
struct {
struct smemfs_inode *inode;
struct hworld *next;
enum {
HYPERVISOR_STATUS_CREATED = 0,
HYPERVISOR_STATUS_INIT = 1,
HYPERVISOR_STATUS_RUNNING = 2,
HYPERVISOR_STATUS_DEAD = 3,
} status;
enum {
HYPERVISOR_ENV_GINT = 0,
HYPERVISOR_ENV_CASIO = 1,
} env;
struct {
struct tsession *tracer;
} debug;
} private;
};
struct himage {
const char *name;
void *private;
struct himage *next;
};
//---
// Loader interface
//---
/* hypervisor_loader(): Load the IMAGE into memory.
The loader will relocalise the IMAGE that is an ELF program compiled in PIE.
The fact that if the image use Gint as a shared librarie then the loader
will automatically resolve missing symbols.
Note that the hypervisor does not support shared libraries "on-calc" because
GCC cannot generate shared libraries for the SuperH archtiecture. Gint is
only possible because the hypervisor known where is located the kernel and
all of these symbols name is hardcoded to allow symbols resolving.
@params
(in) image hypervisor image that can be get using the
"hypervisor_loader_list()" function
@return
0 if successfully loaded
negative if error occur */
extern int hypervisor_loader(struct himage *image);
/* hypervisor_loader_list(): Generate the list all loadable image
The hypervisor will scan all files into the SMEM storage memory and will
check if the file is an ELF format with PIE encoding.
Note that the generated list should be destroyed using the
"hypervisor_loader_list_destroy()" function.
@param
(out) list list that will be generated
@return
possitive The number of valid file
0 No file can be loadable
negative if error occur */
extern int hypervisor_loader_list(struct himage **list);
/* hypervisor_loader_list_destroy(): Destroy the image list
This function will destroy the list generates by the
"hypervisor_loader_list()" function.
@params
(out) list List that will be destroyed and set to NULL */
extern void hypervisor_loader_list_destroy(struct himage **list);
//---
// World interface
//---
extern struct hworld *hypervisor_wswitch_create(void);
extern int hypervisor_wswitch(struct hworld *world);
extern int hypervisor_wswitch_destroy(struct hworld *world);
extern int hypervisor_wswitch_queue_register(struct hworld *world);
extern int hypervisor_wswitch_queue_unregister(struct hworld *world);
extern struct hworld *hypervisor_wswitch_queue_get(void);
extern struct hworld *hypervisor_wswitch_world_alloc(void);
extern void hypervisor_wswitch_world_free(struct hworld **world);
//---
// Environment interface
//---
extern int hypervisor_env_set(struct hworld *hworld);
//---
// Installer interface
//---
extern int hypervisor_install(void);
//---
// "Kernel" interface
//---
//extern int hypervisor_kernel_world_yield(struct hworld*c, struct hworld *n);
//extern int hypervisor_kernel_world_switch(struct hworld*c, struct hworld *n);
#endif /*__FXBOOT_LOADER_H__*/