]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - sys/boot/userboot/userboot.h
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / sys / boot / userboot / userboot.h
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 #define USERBOOT_VERSION_3      3
35
36 /*
37  * Exit codes from the loader
38  */
39 #define USERBOOT_EXIT_QUIT      1
40 #define USERBOOT_EXIT_REBOOT    2
41
42 struct loader_callbacks {
43         /*
44          * Console i/o
45          */
46
47         /*
48          * Wait until a key is pressed on the console and then return it
49          */
50         int             (*getc)(void *arg);
51
52         /*
53          * Write the character ch to the console
54          */
55         void            (*putc)(void *arg, int ch);
56
57         /*
58          * Return non-zero if a key can be read from the console
59          */
60         int             (*poll)(void *arg);
61
62         /*
63          * Host filesystem i/o
64          */
65
66         /*
67          * Open a file in the host filesystem
68          */
69         int             (*open)(void *arg, const char *filename, void **h_return);
70
71         /*
72          * Close a file
73          */
74         int             (*close)(void *arg, void *h);
75
76         /*
77          * Return non-zero if the file is a directory
78          */
79         int             (*isdir)(void *arg, void *h);
80
81         /*
82          * Read size bytes from a file. The number of bytes remaining
83          * in dst after reading is returned in *resid_return
84          */
85         int             (*read)(void *arg, void *h, void *dst, size_t size,
86             size_t *resid_return);
87
88         /*
89          * Read an entry from a directory. The entry's inode number is
90          * returned in *fileno_return, its type in *type_return and
91          * the name length in *namelen_return. The name itself is
92          * copied to the buffer name which must be at least PATH_MAX
93          * in size.
94          */
95         int             (*readdir)(void *arg, void *h, uint32_t *fileno_return,
96             uint8_t *type_return, size_t *namelen_return, char *name);
97
98         /*
99          * Seek to a location within an open file
100          */
101         int             (*seek)(void *arg, void *h, uint64_t offset,
102             int whence);
103
104         /*
105          * Return some stat(2) related information about the file
106          */
107         int             (*stat)(void *arg, void *h, int *mode_return,
108             int *uid_return, int *gid_return, uint64_t *size_return);
109
110         /*
111          * Disk image i/o
112          */
113
114         /*
115          * Read from a disk image at the given offset
116          */
117         int             (*diskread)(void *arg, int unit, uint64_t offset,
118             void *dst, size_t size, size_t *resid_return);
119
120         /*
121          * Guest virtual machine i/o
122          */
123
124         /*
125          * Copy to the guest address space
126          */
127         int             (*copyin)(void *arg, const void *from,
128             uint64_t to, size_t size);
129
130         /*
131          * Copy from the guest address space
132          */
133         int             (*copyout)(void *arg, uint64_t from,
134             void *to, size_t size);
135
136         /*
137          * Set a guest register value
138          */
139         void            (*setreg)(void *arg, int, uint64_t);
140
141         /*
142          * Set a guest MSR value
143          */
144         void            (*setmsr)(void *arg, int, uint64_t);
145
146         /*
147          * Set a guest CR value
148          */
149         void            (*setcr)(void *arg, int, uint64_t);
150
151         /*
152          * Set the guest GDT address
153          */
154         void            (*setgdt)(void *arg, uint64_t, size_t);
155
156         /*
157          * Transfer control to the guest at the given address
158          */
159         void            (*exec)(void *arg, uint64_t pc);
160
161         /*
162          * Misc
163          */
164
165         /*
166          * Sleep for usec microseconds
167          */
168         void            (*delay)(void *arg, int usec);
169
170         /*
171          * Exit with the given exit code
172          */
173         void            (*exit)(void *arg, int v);
174
175         /*
176          * Return guest physical memory map details
177          */
178         void            (*getmem)(void *arg, uint64_t *lowmem,
179             uint64_t *highmem);
180
181         /*
182          * ioctl interface to the disk device
183          */
184         int             (*diskioctl)(void *arg, int unit, u_long cmd,
185             void *data);
186
187         /*
188          * Returns an environment variable in the form "name=value".
189          *
190          * If there are no more variables that need to be set in the
191          * loader environment then return NULL.
192          *
193          * 'num' is used as a handle for the callback to identify which
194          * environment variable to return next. It will begin at 0 and
195          * each invocation will add 1 to the previous value of 'num'.
196          */
197         const char *    (*getenv)(void *arg, int num);
198 };