kloader.h revision 1.1.2.5 1 1.1.2.5 skrll /* $NetBSD: kloader.h,v 1.1.2.5 2005/03/04 16:40:53 skrll Exp $ */
2 1.1.2.2 skrll
3 1.1.2.2 skrll /*-
4 1.1.2.2 skrll * Copyright (c) 2001, 2002, 2004 The NetBSD Foundation, Inc.
5 1.1.2.2 skrll * All rights reserved.
6 1.1.2.2 skrll *
7 1.1.2.2 skrll * Redistribution and use in source and binary forms, with or without
8 1.1.2.2 skrll * modification, are permitted provided that the following conditions
9 1.1.2.2 skrll * are met:
10 1.1.2.2 skrll * 1. Redistributions of source code must retain the above copyright
11 1.1.2.2 skrll * notice, this list of conditions and the following disclaimer.
12 1.1.2.2 skrll * 2. Redistributions in binary form must reproduce the above copyright
13 1.1.2.2 skrll * notice, this list of conditions and the following disclaimer in the
14 1.1.2.2 skrll * documentation and/or other materials provided with the distribution.
15 1.1.2.2 skrll * 3. All advertising materials mentioning features or use of this software
16 1.1.2.2 skrll * must display the following acknowledgement:
17 1.1.2.2 skrll * This product includes software developed by the NetBSD
18 1.1.2.2 skrll * Foundation, Inc. and its contributors.
19 1.1.2.2 skrll * 4. Neither the name of The NetBSD Foundation nor the names of its
20 1.1.2.2 skrll * contributors may be used to endorse or promote products derived
21 1.1.2.2 skrll * from this software without specific prior written permission.
22 1.1.2.2 skrll *
23 1.1.2.2 skrll * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24 1.1.2.2 skrll * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 1.1.2.2 skrll * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 1.1.2.2 skrll * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27 1.1.2.2 skrll * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 1.1.2.2 skrll * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 1.1.2.2 skrll * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 1.1.2.2 skrll * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 1.1.2.2 skrll * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 1.1.2.2 skrll * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 1.1.2.2 skrll * POSSIBILITY OF SUCH DAMAGE.
34 1.1.2.2 skrll */
35 1.1.2.2 skrll
36 1.1.2.2 skrll #ifndef _DEV_KLOADER_H_
37 1.1.2.2 skrll #define _DEV_KLOADER_H_
38 1.1.2.2 skrll
39 1.1.2.2 skrll #ifdef KLOADER_NO_BOOTINFO
40 1.1.2.2 skrll struct bootinfo {
41 1.1.2.2 skrll int dummy;
42 1.1.2.2 skrll };
43 1.1.2.2 skrll #else
44 1.1.2.2 skrll #include <machine/bootinfo.h>
45 1.1.2.2 skrll #endif
46 1.1.2.2 skrll
47 1.1.2.2 skrll struct kloader_ops;
48 1.1.2.2 skrll struct kloader_page_tag;
49 1.1.2.2 skrll struct kloader_bootinfo;
50 1.1.2.2 skrll
51 1.1.2.2 skrll /*
52 1.1.2.2 skrll * kloader_bootfunc_t load new kernel into existing kernel area from
53 1.1.2.2 skrll * lined list of new kernel pieces. and then, jump to kernel
54 1.1.2.2 skrll * entry. This function must be PIC.
55 1.1.2.2 skrll */
56 1.1.2.2 skrll typedef void kloader_bootfunc_t(struct kloader_bootinfo *,
57 1.1.2.2 skrll struct kloader_page_tag *);
58 1.1.2.2 skrll /*
59 1.1.2.2 skrll * koader_jumpfunc_t jump to boot loader described abobe.
60 1.1.2.2 skrll */
61 1.1.2.2 skrll typedef void kloader_jumpfunc_t(kloader_bootfunc_t *, vaddr_t,
62 1.1.2.2 skrll struct kloader_bootinfo *, struct kloader_page_tag *);
63 1.1.2.2 skrll /*
64 1.1.2.2 skrll * reset func is optional. may be called when kloader reboot is failed.
65 1.1.2.2 skrll */
66 1.1.2.2 skrll struct kloader_ops {
67 1.1.2.2 skrll kloader_jumpfunc_t *jump;
68 1.1.2.2 skrll kloader_bootfunc_t *boot;
69 1.1.2.2 skrll void (*reset)(void);
70 1.1.2.2 skrll };
71 1.1.2.2 skrll
72 1.1.2.2 skrll /*
73 1.1.2.2 skrll * new kernel is primary loaded into discrete pages.
74 1.1.2.2 skrll */
75 1.1.2.2 skrll struct kloader_page_tag {
76 1.1.2.2 skrll u_int32_t next;
77 1.1.2.2 skrll u_int32_t src;
78 1.1.2.2 skrll u_int32_t dst;
79 1.1.2.2 skrll u_int32_t sz;
80 1.1.2.2 skrll } __attribute__((__packed__, __aligned__(4)));
81 1.1.2.2 skrll
82 1.1.2.2 skrll #define KLOADER_KERNELARGS_MAX 256
83 1.1.2.2 skrll
84 1.1.2.2 skrll struct kloader_bootinfo {
85 1.1.2.2 skrll /* kernel entry point */
86 1.1.2.2 skrll vaddr_t entry;
87 1.1.2.2 skrll
88 1.1.2.2 skrll /* argc, argv type boot argument */
89 1.1.2.2 skrll int argc;
90 1.1.2.2 skrll char **argv;
91 1.1.2.2 skrll
92 1.1.2.2 skrll /* struct type boot argument */
93 1.1.2.5 skrll struct bootinfo bootinfo;
94 1.1.2.2 skrll
95 1.1.2.2 skrll /* argv buffer */
96 1.1.2.2 skrll char _argbuf[KLOADER_KERNELARGS_MAX];
97 1.1.2.2 skrll } __attribute__((__packed__, __aligned__(4)));
98 1.1.2.2 skrll
99 1.1.2.2 skrll /*
100 1.1.2.2 skrll * kloader_reboot_setup sets machine dependent kloader_ops to
101 1.1.2.2 skrll * kloader. (call __kloader_reboot_setup here.) and load new kernel.
102 1.1.2.2 skrll */
103 1.1.2.2 skrll void kloader_reboot_setup(const char *);
104 1.1.2.2 skrll void __kloader_reboot_setup(struct kloader_ops *, const char *);
105 1.1.2.2 skrll
106 1.1.2.2 skrll /*
107 1.1.2.2 skrll * kloader_reboot jumps to 2nd boot loader.
108 1.1.2.2 skrll * call after all shutdown hooks done.
109 1.1.2.2 skrll */
110 1.1.2.2 skrll void kloader_reboot(void) __attribute__((__noreturn__));
111 1.1.2.2 skrll
112 1.1.2.2 skrll /*
113 1.1.2.2 skrll * kloader_bootinfo_set sets arguments of new kernel to boot. this is optional.
114 1.1.2.2 skrll * theses parameter is passed to kloader_bootfunc_t.
115 1.1.2.2 skrll */
116 1.1.2.2 skrll void kloader_bootinfo_set(struct kloader_bootinfo *, int, char *[],
117 1.1.2.2 skrll struct bootinfo *, int);
118 1.1.2.2 skrll
119 1.1.2.2 skrll #endif /* _DEV_KLOADER_H_ */
120