1223695Sdfr/*- 2223695Sdfr * Copyright (c) 2011 Doug Rabson 3223695Sdfr * All rights reserved. 4223695Sdfr * 5223695Sdfr * Redistribution and use in source and binary forms, with or without 6223695Sdfr * modification, are permitted provided that the following conditions 7223695Sdfr * are met: 8223695Sdfr * 1. Redistributions of source code must retain the above copyright 9223695Sdfr * notice, this list of conditions and the following disclaimer. 10223695Sdfr * 2. Redistributions in binary form must reproduce the above copyright 11223695Sdfr * notice, this list of conditions and the following disclaimer in the 12223695Sdfr * documentation and/or other materials provided with the distribution. 13223695Sdfr * 14223695Sdfr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15223695Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16223695Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17223695Sdfr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18223695Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19223695Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20223695Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21223695Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22223695Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23223695Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24223695Sdfr * SUCH DAMAGE. 25223695Sdfr * 26223695Sdfr * $FreeBSD$ 27223695Sdfr */ 28223695Sdfr 29223695Sdfr/* 30223695Sdfr * USERBOOT interface versions 31223695Sdfr */ 32223695Sdfr#define USERBOOT_VERSION_1 1 33239073Sae#define USERBOOT_VERSION_2 2 34242935Sneel#define USERBOOT_VERSION_3 3 35223695Sdfr 36223695Sdfr/* 37223695Sdfr * Exit codes from the loader 38223695Sdfr */ 39223695Sdfr#define USERBOOT_EXIT_QUIT 1 40223695Sdfr#define USERBOOT_EXIT_REBOOT 2 41223695Sdfr 42241164Saestruct loader_callbacks { 43223695Sdfr /* 44223695Sdfr * Console i/o 45223695Sdfr */ 46223695Sdfr 47223695Sdfr /* 48223695Sdfr * Wait until a key is pressed on the console and then return it 49223695Sdfr */ 50223695Sdfr int (*getc)(void *arg); 51223695Sdfr 52223695Sdfr /* 53223695Sdfr * Write the character ch to the console 54223695Sdfr */ 55223695Sdfr void (*putc)(void *arg, int ch); 56223695Sdfr 57223695Sdfr /* 58223695Sdfr * Return non-zero if a key can be read from the console 59223695Sdfr */ 60223695Sdfr int (*poll)(void *arg); 61223695Sdfr 62223695Sdfr /* 63223695Sdfr * Host filesystem i/o 64223695Sdfr */ 65223695Sdfr 66223695Sdfr /* 67223695Sdfr * Open a file in the host filesystem 68223695Sdfr */ 69223695Sdfr int (*open)(void *arg, const char *filename, void **h_return); 70223695Sdfr 71223695Sdfr /* 72223695Sdfr * Close a file 73223695Sdfr */ 74223695Sdfr int (*close)(void *arg, void *h); 75223695Sdfr 76223695Sdfr /* 77223695Sdfr * Return non-zero if the file is a directory 78223695Sdfr */ 79223695Sdfr int (*isdir)(void *arg, void *h); 80223695Sdfr 81223695Sdfr /* 82223695Sdfr * Read size bytes from a file. The number of bytes remaining 83223695Sdfr * in dst after reading is returned in *resid_return 84223695Sdfr */ 85223695Sdfr int (*read)(void *arg, void *h, void *dst, size_t size, 86223695Sdfr size_t *resid_return); 87223695Sdfr 88223695Sdfr /* 89223695Sdfr * Read an entry from a directory. The entry's inode number is 90223695Sdfr * returned in *fileno_return, its type in *type_return and 91223695Sdfr * the name length in *namelen_return. The name itself is 92223695Sdfr * copied to the buffer name which must be at least PATH_MAX 93223695Sdfr * in size. 94223695Sdfr */ 95223695Sdfr int (*readdir)(void *arg, void *h, uint32_t *fileno_return, 96223695Sdfr uint8_t *type_return, size_t *namelen_return, char *name); 97223695Sdfr 98223695Sdfr /* 99223695Sdfr * Seek to a location within an open file 100223695Sdfr */ 101223695Sdfr int (*seek)(void *arg, void *h, uint64_t offset, 102223695Sdfr int whence); 103223695Sdfr 104223695Sdfr /* 105223695Sdfr * Return some stat(2) related information about the file 106223695Sdfr */ 107223695Sdfr int (*stat)(void *arg, void *h, int *mode_return, 108223695Sdfr int *uid_return, int *gid_return, uint64_t *size_return); 109223695Sdfr 110223695Sdfr /* 111223695Sdfr * Disk image i/o 112223695Sdfr */ 113223695Sdfr 114223695Sdfr /* 115223695Sdfr * Read from a disk image at the given offset 116223695Sdfr */ 117223695Sdfr int (*diskread)(void *arg, int unit, uint64_t offset, 118223695Sdfr void *dst, size_t size, size_t *resid_return); 119223695Sdfr 120223695Sdfr /* 121223695Sdfr * Guest virtual machine i/o 122223695Sdfr */ 123223695Sdfr 124223695Sdfr /* 125223695Sdfr * Copy to the guest address space 126223695Sdfr */ 127223695Sdfr int (*copyin)(void *arg, const void *from, 128223695Sdfr uint64_t to, size_t size); 129223695Sdfr 130223695Sdfr /* 131223695Sdfr * Copy from the guest address space 132223695Sdfr */ 133223695Sdfr int (*copyout)(void *arg, uint64_t from, 134223695Sdfr void *to, size_t size); 135223695Sdfr 136223695Sdfr /* 137223695Sdfr * Set a guest register value 138223695Sdfr */ 139223695Sdfr void (*setreg)(void *arg, int, uint64_t); 140223695Sdfr 141223695Sdfr /* 142223695Sdfr * Set a guest MSR value 143223695Sdfr */ 144223695Sdfr void (*setmsr)(void *arg, int, uint64_t); 145223695Sdfr 146223695Sdfr /* 147223695Sdfr * Set a guest CR value 148223695Sdfr */ 149223695Sdfr void (*setcr)(void *arg, int, uint64_t); 150223695Sdfr 151223695Sdfr /* 152223695Sdfr * Set the guest GDT address 153223695Sdfr */ 154223695Sdfr void (*setgdt)(void *arg, uint64_t, size_t); 155223695Sdfr 156223695Sdfr /* 157223695Sdfr * Transfer control to the guest at the given address 158223695Sdfr */ 159223695Sdfr void (*exec)(void *arg, uint64_t pc); 160223695Sdfr 161223695Sdfr /* 162223695Sdfr * Misc 163223695Sdfr */ 164223695Sdfr 165223695Sdfr /* 166223695Sdfr * Sleep for usec microseconds 167223695Sdfr */ 168223695Sdfr void (*delay)(void *arg, int usec); 169223695Sdfr 170223695Sdfr /* 171223695Sdfr * Exit with the given exit code 172223695Sdfr */ 173223695Sdfr void (*exit)(void *arg, int v); 174223695Sdfr 175223695Sdfr /* 176223695Sdfr * Return guest physical memory map details 177223695Sdfr */ 178223695Sdfr void (*getmem)(void *arg, uint64_t *lowmem, 179223695Sdfr uint64_t *highmem); 180242935Sneel 181239058Sae /* 182239058Sae * ioctl interface to the disk device 183239058Sae */ 184239058Sae int (*diskioctl)(void *arg, int unit, u_long cmd, 185239058Sae void *data); 186242935Sneel 187242935Sneel /* 188242935Sneel * Returns an environment variable in the form "name=value". 189242935Sneel * 190242935Sneel * If there are no more variables that need to be set in the 191242935Sneel * loader environment then return NULL. 192242935Sneel * 193242935Sneel * 'num' is used as a handle for the callback to identify which 194242935Sneel * environment variable to return next. It will begin at 0 and 195242935Sneel * each invocation will add 1 to the previous value of 'num'. 196242935Sneel */ 197242935Sneel const char * (*getenv)(void *arg, int num); 198223695Sdfr}; 199