userboot.h revision 241164
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: head/sys/boot/userboot/userboot.h 241164 2012-10-03 17:20:34Z ae $
27223695Sdfr */
28223695Sdfr
29223695Sdfr/*
30223695Sdfr * USERBOOT interface versions
31223695Sdfr */
32223695Sdfr#define	USERBOOT_VERSION_1      1
33239073Sae#define	USERBOOT_VERSION_2      2
34223695Sdfr
35223695Sdfr/*
36223695Sdfr * Exit codes from the loader
37223695Sdfr */
38223695Sdfr#define	USERBOOT_EXIT_QUIT      1
39223695Sdfr#define	USERBOOT_EXIT_REBOOT    2
40223695Sdfr
41241164Saestruct loader_callbacks {
42223695Sdfr	/*
43223695Sdfr	 * Console i/o
44223695Sdfr	 */
45223695Sdfr
46223695Sdfr        /*
47223695Sdfr         * Wait until a key is pressed on the console and then return it
48223695Sdfr         */
49223695Sdfr	int		(*getc)(void *arg);
50223695Sdfr
51223695Sdfr        /*
52223695Sdfr         * Write the character ch to the console
53223695Sdfr         */
54223695Sdfr	void		(*putc)(void *arg, int ch);
55223695Sdfr
56223695Sdfr        /*
57223695Sdfr         * Return non-zero if a key can be read from the console
58223695Sdfr         */
59223695Sdfr	int		(*poll)(void *arg);
60223695Sdfr
61223695Sdfr	/*
62223695Sdfr	 * Host filesystem i/o
63223695Sdfr	 */
64223695Sdfr
65223695Sdfr        /*
66223695Sdfr         * Open a file in the host filesystem
67223695Sdfr         */
68223695Sdfr	int		(*open)(void *arg, const char *filename, void **h_return);
69223695Sdfr
70223695Sdfr        /*
71223695Sdfr         * Close a file
72223695Sdfr         */
73223695Sdfr	int		(*close)(void *arg, void *h);
74223695Sdfr
75223695Sdfr        /*
76223695Sdfr         * Return non-zero if the file is a directory
77223695Sdfr         */
78223695Sdfr	int		(*isdir)(void *arg, void *h);
79223695Sdfr
80223695Sdfr        /*
81223695Sdfr         * Read size bytes from a file. The number of bytes remaining
82223695Sdfr         * in dst after reading is returned in *resid_return
83223695Sdfr         */
84223695Sdfr	int		(*read)(void *arg, void *h, void *dst, size_t size,
85223695Sdfr            size_t *resid_return);
86223695Sdfr
87223695Sdfr        /*
88223695Sdfr         * Read an entry from a directory. The entry's inode number is
89223695Sdfr         * returned in *fileno_return, its type in *type_return and
90223695Sdfr         * the name length in *namelen_return. The name itself is
91223695Sdfr         * copied to the buffer name which must be at least PATH_MAX
92223695Sdfr         * in size.
93223695Sdfr         */
94223695Sdfr	int		(*readdir)(void *arg, void *h, uint32_t *fileno_return,
95223695Sdfr            uint8_t *type_return, size_t *namelen_return, char *name);
96223695Sdfr
97223695Sdfr        /*
98223695Sdfr         * Seek to a location within an open file
99223695Sdfr         */
100223695Sdfr	int		(*seek)(void *arg, void *h, uint64_t offset,
101223695Sdfr            int whence);
102223695Sdfr
103223695Sdfr        /*
104223695Sdfr         * Return some stat(2) related information about the file
105223695Sdfr         */
106223695Sdfr	int		(*stat)(void *arg, void *h, int *mode_return,
107223695Sdfr            int *uid_return, int *gid_return, uint64_t *size_return);
108223695Sdfr
109223695Sdfr	/*
110223695Sdfr	 * Disk image i/o
111223695Sdfr	 */
112223695Sdfr
113223695Sdfr        /*
114223695Sdfr         * Read from a disk image at the given offset
115223695Sdfr         */
116223695Sdfr	int		(*diskread)(void *arg, int unit, uint64_t offset,
117223695Sdfr            void *dst, size_t size, size_t *resid_return);
118223695Sdfr
119223695Sdfr	/*
120223695Sdfr	 * Guest virtual machine i/o
121223695Sdfr	 */
122223695Sdfr
123223695Sdfr        /*
124223695Sdfr         * Copy to the guest address space
125223695Sdfr         */
126223695Sdfr	int		(*copyin)(void *arg, const void *from,
127223695Sdfr            uint64_t to, size_t size);
128223695Sdfr
129223695Sdfr        /*
130223695Sdfr         * Copy from the guest address space
131223695Sdfr         */
132223695Sdfr	int		(*copyout)(void *arg, uint64_t from,
133223695Sdfr            void *to, size_t size);
134223695Sdfr
135223695Sdfr        /*
136223695Sdfr         * Set a guest register value
137223695Sdfr         */
138223695Sdfr	void		(*setreg)(void *arg, int, uint64_t);
139223695Sdfr
140223695Sdfr        /*
141223695Sdfr         * Set a guest MSR value
142223695Sdfr         */
143223695Sdfr	void		(*setmsr)(void *arg, int, uint64_t);
144223695Sdfr
145223695Sdfr        /*
146223695Sdfr         * Set a guest CR value
147223695Sdfr         */
148223695Sdfr	void		(*setcr)(void *arg, int, uint64_t);
149223695Sdfr
150223695Sdfr        /*
151223695Sdfr         * Set the guest GDT address
152223695Sdfr         */
153223695Sdfr        void            (*setgdt)(void *arg, uint64_t, size_t);
154223695Sdfr
155223695Sdfr        /*
156223695Sdfr         * Transfer control to the guest at the given address
157223695Sdfr         */
158223695Sdfr	void		(*exec)(void *arg, uint64_t pc);
159223695Sdfr
160223695Sdfr	/*
161223695Sdfr	 * Misc
162223695Sdfr	 */
163223695Sdfr
164223695Sdfr        /*
165223695Sdfr         * Sleep for usec microseconds
166223695Sdfr         */
167223695Sdfr	void		(*delay)(void *arg, int usec);
168223695Sdfr
169223695Sdfr        /*
170223695Sdfr         * Exit with the given exit code
171223695Sdfr         */
172223695Sdfr	void		(*exit)(void *arg, int v);
173223695Sdfr
174223695Sdfr        /*
175223695Sdfr         * Return guest physical memory map details
176223695Sdfr         */
177223695Sdfr	void		(*getmem)(void *arg, uint64_t *lowmem,
178223695Sdfr            uint64_t *highmem);
179239058Sae	/*
180239058Sae	 * ioctl interface to the disk device
181239058Sae	 */
182239058Sae	int		(*diskioctl)(void *arg, int unit, u_long cmd,
183239058Sae	    void *data);
184223695Sdfr};
185