userboot.h revision 223695
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: head/sys/boot/userboot/userboot.h 223695 2011-06-30 16:08:56Z dfr $
27 */
28
29/*
30 * USERBOOT interface versions
31 */
32#define	USERBOOT_VERSION_1      1
33
34/*
35 * Exit codes from the loader
36 */
37#define	USERBOOT_EXIT_QUIT      1
38#define	USERBOOT_EXIT_REBOOT    2
39
40struct loader_callbacks_v1 {
41	/*
42	 * Console i/o
43	 */
44
45        /*
46         * Wait until a key is pressed on the console and then return it
47         */
48	int		(*getc)(void *arg);
49
50        /*
51         * Write the character ch to the console
52         */
53	void		(*putc)(void *arg, int ch);
54
55        /*
56         * Return non-zero if a key can be read from the console
57         */
58	int		(*poll)(void *arg);
59
60	/*
61	 * Host filesystem i/o
62	 */
63
64        /*
65         * Open a file in the host filesystem
66         */
67	int		(*open)(void *arg, const char *filename, void **h_return);
68
69        /*
70         * Close a file
71         */
72	int		(*close)(void *arg, void *h);
73
74        /*
75         * Return non-zero if the file is a directory
76         */
77	int		(*isdir)(void *arg, void *h);
78
79        /*
80         * Read size bytes from a file. The number of bytes remaining
81         * in dst after reading is returned in *resid_return
82         */
83	int		(*read)(void *arg, void *h, void *dst, size_t size,
84            size_t *resid_return);
85
86        /*
87         * Read an entry from a directory. The entry's inode number is
88         * returned in *fileno_return, its type in *type_return and
89         * the name length in *namelen_return. The name itself is
90         * copied to the buffer name which must be at least PATH_MAX
91         * in size.
92         */
93	int		(*readdir)(void *arg, void *h, uint32_t *fileno_return,
94            uint8_t *type_return, size_t *namelen_return, char *name);
95
96        /*
97         * Seek to a location within an open file
98         */
99	int		(*seek)(void *arg, void *h, uint64_t offset,
100            int whence);
101
102        /*
103         * Return some stat(2) related information about the file
104         */
105	int		(*stat)(void *arg, void *h, int *mode_return,
106            int *uid_return, int *gid_return, uint64_t *size_return);
107
108	/*
109	 * Disk image i/o
110	 */
111
112        /*
113         * Read from a disk image at the given offset
114         */
115	int		(*diskread)(void *arg, int unit, uint64_t offset,
116            void *dst, size_t size, size_t *resid_return);
117
118	/*
119	 * Guest virtual machine i/o
120	 */
121
122        /*
123         * Copy to the guest address space
124         */
125	int		(*copyin)(void *arg, const void *from,
126            uint64_t to, size_t size);
127
128        /*
129         * Copy from the guest address space
130         */
131	int		(*copyout)(void *arg, uint64_t from,
132            void *to, size_t size);
133
134        /*
135         * Set a guest register value
136         */
137	void		(*setreg)(void *arg, int, uint64_t);
138
139        /*
140         * Set a guest MSR value
141         */
142	void		(*setmsr)(void *arg, int, uint64_t);
143
144        /*
145         * Set a guest CR value
146         */
147	void		(*setcr)(void *arg, int, uint64_t);
148
149        /*
150         * Set the guest GDT address
151         */
152        void            (*setgdt)(void *arg, uint64_t, size_t);
153
154        /*
155         * Transfer control to the guest at the given address
156         */
157	void		(*exec)(void *arg, uint64_t pc);
158
159	/*
160	 * Misc
161	 */
162
163        /*
164         * Sleep for usec microseconds
165         */
166	void		(*delay)(void *arg, int usec);
167
168        /*
169         * Exit with the given exit code
170         */
171	void		(*exit)(void *arg, int v);
172
173        /*
174         * Return guest physical memory map details
175         */
176	void		(*getmem)(void *arg, uint64_t *lowmem,
177            uint64_t *highmem);
178};
179