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