/*-1* Copyright (c) 2011 Doug Rabson2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND14* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE17* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23* SUCH DAMAGE.24*/2526/*27* USERBOOT interface versions28*/29#define USERBOOT_VERSION_1 130#define USERBOOT_VERSION_2 231#define USERBOOT_VERSION_3 33233/*34* Version 4 added more generic callbacks for setting up35* registers and descriptors. The callback structure is36* backward compatible (new callbacks have been added at37* the tail end).38*/39#define USERBOOT_VERSION_4 44041/*42* Version 5 added a callback for indicating that the guest43* should be restarted with a different interpreter. The callback44* structure is still backward compatible.45*/46#define USERBOOT_VERSION_5 54748/*49* Exit codes from the loader50*/51#define USERBOOT_EXIT_QUIT 152#define USERBOOT_EXIT_REBOOT 25354struct loader_callbacks {55/*56* Console i/o57*/5859/*60* Wait until a key is pressed on the console and then return it61*/62int (*getc)(void *arg);6364/*65* Write the character ch to the console66*/67void (*putc)(void *arg, int ch);6869/*70* Return non-zero if a key can be read from the console71*/72int (*poll)(void *arg);7374/*75* Host filesystem i/o76*/7778/*79* Open a file in the host filesystem80*/81int (*open)(void *arg, const char *filename, void **h_return);8283/*84* Close a file85*/86int (*close)(void *arg, void *h);8788/*89* Return non-zero if the file is a directory90*/91int (*isdir)(void *arg, void *h);9293/*94* Read size bytes from a file. The number of bytes remaining95* in dst after reading is returned in *resid_return96*/97int (*read)(void *arg, void *h, void *dst, size_t size,98size_t *resid_return);99100/*101* Read an entry from a directory. The entry's inode number is102* returned in *fileno_return, its type in *type_return and103* the name length in *namelen_return. The name itself is104* copied to the buffer name which must be at least PATH_MAX105* in size.106*/107int (*readdir)(void *arg, void *h, uint32_t *fileno_return,108uint8_t *type_return, size_t *namelen_return, char *name);109110/*111* Seek to a location within an open file112*/113int (*seek)(void *arg, void *h, uint64_t offset,114int whence);115116/*117* Return some stat(2) related information about the file118*/119int (*stat)(void *arg, void *h, struct stat *stp);120121/*122* Disk image i/o123*/124125/*126* Read from a disk image at the given offset127*/128int (*diskread)(void *arg, int unit, uint64_t offset,129void *dst, size_t size, size_t *resid_return);130131/*132* Write to a disk image at the given offset133*/134int (*diskwrite)(void *arg, int unit, uint64_t offset,135void *src, size_t size, size_t *resid_return);136137/*138* Guest virtual machine i/o139*/140141/*142* Copy to the guest address space143*/144int (*copyin)(void *arg, const void *from,145uint64_t to, size_t size);146147/*148* Copy from the guest address space149*/150int (*copyout)(void *arg, uint64_t from,151void *to, size_t size);152153/*154* Set a guest register value155*/156void (*setreg)(void *arg, int, uint64_t);157158/*159* Set a guest MSR value160*/161void (*setmsr)(void *arg, int, uint64_t);162163/*164* Set a guest CR value165*/166void (*setcr)(void *arg, int, uint64_t);167168/*169* Set the guest GDT address170*/171void (*setgdt)(void *arg, uint64_t, size_t);172173/*174* Transfer control to the guest at the given address175*/176void (*exec)(void *arg, uint64_t pc);177178/*179* Misc180*/181182/*183* Sleep for usec microseconds184*/185void (*delay)(void *arg, int usec);186187/*188* Exit with the given exit code189*/190void (*exit)(void *arg, int v);191192/*193* Return guest physical memory map details194*/195void (*getmem)(void *arg, uint64_t *lowmem,196uint64_t *highmem);197198/*199* ioctl interface to the disk device200*/201int (*diskioctl)(void *arg, int unit, u_long cmd,202void *data);203204/*205* Returns an environment variable in the form "name=value".206*207* If there are no more variables that need to be set in the208* loader environment then return NULL.209*210* 'num' is used as a handle for the callback to identify which211* environment variable to return next. It will begin at 0 and212* each invocation will add 1 to the previous value of 'num'.213*/214char * (*getenv)(void *arg, int num);215216/*217* Version 4 additions.218*/219int (*vm_set_register)(void *arg, int vcpu, int reg, uint64_t val);220int (*vm_set_desc)(void *arg, int vcpu, int reg, uint64_t base,221u_int limit, u_int access);222223/*224* Version 5 addition.225*/226void (*swap_interpreter)(void *arg, const char *interp);227};228229230