1/*- 2 * Copyright (c) 2011 Doug Rabson 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $FreeBSD$ 27 */ 28 29/* 30 * USERBOOT interface versions 31 */ 32#define USERBOOT_VERSION_1 1 33#define USERBOOT_VERSION_2 2 34 35/* 36 * Exit codes from the loader 37 */ 38#define USERBOOT_EXIT_QUIT 1 39#define USERBOOT_EXIT_REBOOT 2 40 41struct loader_callbacks { 42 /* 43 * Console i/o 44 */ 45 46 /* 47 * Wait until a key is pressed on the console and then return it 48 */ 49 int (*getc)(void *arg); 50 51 /* 52 * Write the character ch to the console 53 */ 54 void (*putc)(void *arg, int ch); 55 56 /* 57 * Return non-zero if a key can be read from the console 58 */ 59 int (*poll)(void *arg); 60 61 /* 62 * Host filesystem i/o 63 */ 64 65 /* 66 * Open a file in the host filesystem 67 */ 68 int (*open)(void *arg, const char *filename, void **h_return); 69 70 /* 71 * Close a file 72 */ 73 int (*close)(void *arg, void *h); 74 75 /* 76 * Return non-zero if the file is a directory 77 */ 78 int (*isdir)(void *arg, void *h); 79 80 /* 81 * Read size bytes from a file. The number of bytes remaining 82 * in dst after reading is returned in *resid_return 83 */ 84 int (*read)(void *arg, void *h, void *dst, size_t size, 85 size_t *resid_return); 86 87 /* 88 * Read an entry from a directory. The entry's inode number is 89 * returned in *fileno_return, its type in *type_return and 90 * the name length in *namelen_return. The name itself is 91 * copied to the buffer name which must be at least PATH_MAX 92 * in size. 93 */ 94 int (*readdir)(void *arg, void *h, uint32_t *fileno_return, 95 uint8_t *type_return, size_t *namelen_return, char *name); 96 97 /* 98 * Seek to a location within an open file 99 */ 100 int (*seek)(void *arg, void *h, uint64_t offset, 101 int whence); 102 103 /* 104 * Return some stat(2) related information about the file 105 */ 106 int (*stat)(void *arg, void *h, int *mode_return, 107 int *uid_return, int *gid_return, uint64_t *size_return); 108 109 /* 110 * Disk image i/o 111 */ 112 113 /* 114 * Read from a disk image at the given offset 115 */ 116 int (*diskread)(void *arg, int unit, uint64_t offset, 117 void *dst, size_t size, size_t *resid_return); 118 119 /* 120 * Guest virtual machine i/o 121 */ 122 123 /* 124 * Copy to the guest address space 125 */ 126 int (*copyin)(void *arg, const void *from, 127 uint64_t to, size_t size); 128 129 /* 130 * Copy from the guest address space 131 */ 132 int (*copyout)(void *arg, uint64_t from, 133 void *to, size_t size); 134 135 /* 136 * Set a guest register value 137 */ 138 void (*setreg)(void *arg, int, uint64_t); 139 140 /* 141 * Set a guest MSR value 142 */ 143 void (*setmsr)(void *arg, int, uint64_t); 144 145 /* 146 * Set a guest CR value 147 */ 148 void (*setcr)(void *arg, int, uint64_t); 149 150 /* 151 * Set the guest GDT address 152 */ 153 void (*setgdt)(void *arg, uint64_t, size_t); 154 155 /* 156 * Transfer control to the guest at the given address 157 */ 158 void (*exec)(void *arg, uint64_t pc); 159 160 /* 161 * Misc 162 */ 163 164 /* 165 * Sleep for usec microseconds 166 */ 167 void (*delay)(void *arg, int usec); 168 169 /* 170 * Exit with the given exit code 171 */ 172 void (*exit)(void *arg, int v); 173 174 /* 175 * Return guest physical memory map details 176 */ 177 void (*getmem)(void *arg, uint64_t *lowmem, 178 uint64_t *highmem); 179 /* 180 * ioctl interface to the disk device 181 */ 182 int (*diskioctl)(void *arg, int unit, u_long cmd, 183 void *data); 184}; 185