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