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