xref: /illumos-gate/usr/src/boot/userboot/userboot.h (revision 10a869258e300c530ae56b29aa3bf43461ca98ff)
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 
27 #ifndef USERBOOT_H
28 #define	USERBOOT_H
29 
30 /*
31  * USERBOOT interface versions
32  */
33 #define	USERBOOT_VERSION_1	1
34 #define	USERBOOT_VERSION_2	2
35 #define	USERBOOT_VERSION_3	3
36 
37 /*
38  * Version 4 added more generic callbacks for setting up
39  * registers and descriptors. The callback structure is
40  * backward compatible (new callbacks have been added at
41  * the tail end).
42  */
43 #define	USERBOOT_VERSION_4	4
44 
45 /*
46  * Version 5 added a callback for indicating that the guest
47  * should be restarted with a different interpreter.  The callback
48  * structure is still backward compatible.
49  */
50 #define	USERBOOT_VERSION_5	5
51 
52 /*
53  * Exit codes from the loader
54  */
55 #define	USERBOOT_EXIT_QUIT	1
56 #define	USERBOOT_EXIT_REBOOT	2
57 
58 struct loader_callbacks {
59 	/*
60 	 * Console i/o
61 	 */
62 
63 	/*
64 	 * Wait until a key is pressed on the console and then return it
65 	 */
66 	int		(*getc)(void *arg);
67 
68 	/*
69 	 * Write the character ch to the console
70 	 */
71 	void		(*putc)(void *arg, int ch);
72 
73 	/*
74 	 * Return non-zero if a key can be read from the console
75 	 */
76 	int		(*poll)(void *arg);
77 
78 	/*
79 	 * Host filesystem i/o
80 	 */
81 
82 	/*
83 	 * Open a file in the host filesystem
84 	 */
85 	int		(*open)(void *arg, const char *filename,
86 	    void **h_return);
87 
88 	/*
89 	 * Close a file
90 	 */
91 	int		(*close)(void *arg, void *h);
92 
93 	/*
94 	 * Return non-zero if the file is a directory
95 	 */
96 	int		(*isdir)(void *arg, void *h);
97 
98 	/*
99 	 * Read size bytes from a file. The number of bytes remaining
100 	 * in dst after reading is returned in *resid_return
101 	 */
102 	int		(*read)(void *arg, void *h, void *dst, size_t size,
103 	    size_t *resid_return);
104 
105 	/*
106 	 * Read an entry from a directory. The entry's inode number is
107 	 * returned in *fileno_return, its type in *type_return and
108 	 * the name length in *namelen_return. The name itself is
109 	 * copied to the buffer name which must be at least PATH_MAX
110 	 * in size.
111 	 */
112 	int		(*readdir)(void *arg, void *h, uint32_t *fileno_return,
113 	    uint8_t *type_return, size_t *namelen_return, char *name);
114 
115 	/*
116 	 * Seek to a location within an open file
117 	 */
118 	int		(*seek)(void *arg, void *h, uint64_t offset,
119 	    int whence);
120 
121 	/*
122 	 * Return some stat(2) related information about the file
123 	 */
124 	int		(*stat)(void *arg, void *h, int *mode_return,
125 	    int *uid_return, int *gid_return, uint64_t *size_return);
126 
127 	/*
128 	 * Disk image i/o
129 	 */
130 
131 	/*
132 	 * Read from a disk image at the given offset
133 	 */
134 	int		(*diskread)(void *arg, int unit, uint64_t offset,
135 	    void *dst, size_t size, size_t *resid_return);
136 
137 	/*
138 	 * Write to a disk image at the given offset
139 	 */
140 	int		(*diskwrite)(void *arg, int unit, uint64_t offset,
141 	    void *src, size_t size, size_t *resid_return);
142 
143 	/*
144 	 * Guest virtual machine i/o
145 	 */
146 
147 	/*
148 	 * Copy to the guest address space
149 	 */
150 	int		(*copyin)(void *arg, const void *from,
151 	    uint64_t to, size_t size);
152 
153 	/*
154 	 * Copy from the guest address space
155 	 */
156 	int		(*copyout)(void *arg, uint64_t from,
157 	    void *to, size_t size);
158 
159 	/*
160 	 * Set a guest register value
161 	 */
162 	void		(*setreg)(void *arg, int, uint64_t);
163 
164 	/*
165 	 * Set a guest MSR value
166 	 */
167 	void		(*setmsr)(void *arg, int, uint64_t);
168 
169 	/*
170 	 * Set a guest CR value
171 	 */
172 	void		(*setcr)(void *arg, int, uint64_t);
173 
174 	/*
175 	 * Set the guest GDT address
176 	 */
177 	void		(*setgdt)(void *arg, uint64_t, size_t);
178 
179 	/*
180 	 * Transfer control to the guest at the given address
181 	 */
182 	void		(*exec)(void *arg, uint64_t pc);
183 
184 	/*
185 	 * Misc
186 	 */
187 
188 	/*
189 	 * Sleep for usec microseconds
190 	 */
191 	void		(*delay)(void *arg, int usec);
192 
193 	/*
194 	 * Exit with the given exit code
195 	 */
196 	void		(*exit)(void *arg, int v);
197 
198 	/*
199 	 * Return guest physical memory map details
200 	 */
201 	void		(*getmem)(void *arg, uint64_t *lowmem,
202 	    uint64_t *highmem);
203 
204 	/*
205 	 * ioctl interface to the disk device
206 	 */
207 	int		(*diskioctl)(void *arg, int unit, ulong_t cmd,
208 	    void *data);
209 
210 	/*
211 	 * Returns an environment variable in the form "name=value".
212 	 *
213 	 * If there are no more variables that need to be set in the
214 	 * loader environment then return NULL.
215 	 *
216 	 * 'num' is used as a handle for the callback to identify which
217 	 * environment variable to return next. It will begin at 0 and
218 	 * each invocation will add 1 to the previous value of 'num'.
219 	 */
220 	char		*(*getenv)(void *arg, int num);
221 
222 	/*
223 	 * Version 4 additions.
224 	 */
225 	int	(*vm_set_register)(void *arg, int vcpu, int reg, uint64_t val);
226 	int	(*vm_set_desc)(void *arg, int vcpu, int reg, uint64_t base,
227 	    uint_t limit, uint_t access);
228 
229 	/*
230 	 * Version 5 addition.
231 	 */
232 	void	(*swap_interpreter)(void *arg, const char *interp);
233 };
234 
235 #endif	/* USERBOOT_H */
236