xref: /netbsd-src/sys/arch/mipsco/stand/common/bootinfo.c (revision ce099b40997c43048fb78bd578195f81d2456523)
1*ce099b40Smartin /*	$NetBSD: bootinfo.c,v 1.4 2008/04/28 20:23:28 martin Exp $	*/
2a3ec1726Swdk 
3a3ec1726Swdk /*-
4a3ec1726Swdk  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
5a3ec1726Swdk  * All rights reserved.
6a3ec1726Swdk  *
7a3ec1726Swdk  * This code is derived from software contributed to The NetBSD Foundation
8a3ec1726Swdk  * by Jonathan Stone, Michael Hitch and Simon Burge.
9a3ec1726Swdk  *
10a3ec1726Swdk  * Redistribution and use in source and binary forms, with or without
11a3ec1726Swdk  * modification, are permitted provided that the following conditions
12a3ec1726Swdk  * are met:
13a3ec1726Swdk  * 1. Redistributions of source code must retain the above copyright
14a3ec1726Swdk  *    notice, this list of conditions and the following disclaimer.
15a3ec1726Swdk  * 2. Redistributions in binary form must reproduce the above copyright
16a3ec1726Swdk  *    notice, this list of conditions and the following disclaimer in the
17a3ec1726Swdk  *    documentation and/or other materials provided with the distribution.
18a3ec1726Swdk  *
19a3ec1726Swdk  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20a3ec1726Swdk  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21a3ec1726Swdk  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22a3ec1726Swdk  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23a3ec1726Swdk  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24a3ec1726Swdk  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25a3ec1726Swdk  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26a3ec1726Swdk  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27a3ec1726Swdk  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28a3ec1726Swdk  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29a3ec1726Swdk  * POSSIBILITY OF SUCH DAMAGE.
30a3ec1726Swdk  */
31a3ec1726Swdk 
32a3ec1726Swdk #include <machine/types.h>
33a3ec1726Swdk #include <lib/libsa/stand.h>
34a3ec1726Swdk #include <lib/libkern/libkern.h>
35a3ec1726Swdk 
36a3ec1726Swdk #include "bootinfo.h"
37a3ec1726Swdk 
38a3ec1726Swdk static char *bootinfo = NULL;
39a3ec1726Swdk static char *bi_next;
40a3ec1726Swdk static int bi_size;
41a3ec1726Swdk 
bi_init(addr)42a3ec1726Swdk void bi_init(addr)
43a3ec1726Swdk 	paddr_t addr;
44a3ec1726Swdk {
45a3ec1726Swdk 	struct btinfo_common *bi;
46a3ec1726Swdk 	struct btinfo_magic bi_magic;
47a3ec1726Swdk 
48a3ec1726Swdk 	bootinfo = (char *)addr;
49a3ec1726Swdk 	bi = (struct btinfo_common *)bootinfo;
50a3ec1726Swdk 	bi->next = bi->type = 0;
51a3ec1726Swdk 	bi_next = bootinfo;
52a3ec1726Swdk 	bi_size = 0;
53a3ec1726Swdk 
54a3ec1726Swdk 	bi_magic.magic = BOOTINFO_MAGIC;
55a3ec1726Swdk 	bi_add(&bi_magic, BTINFO_MAGIC, sizeof(bi_magic));
56a3ec1726Swdk }
57a3ec1726Swdk 
bi_add(new,type,size)58a3ec1726Swdk void bi_add(new, type, size)
59a3ec1726Swdk 	void *new;
60a3ec1726Swdk 	int type, size;
61a3ec1726Swdk {
62a3ec1726Swdk 	struct btinfo_common *bi;
63a3ec1726Swdk 
64a3ec1726Swdk 	if (bi_size + size > BOOTINFO_SIZE)
65a3ec1726Swdk 		return;				/* XXX error? */
66a3ec1726Swdk 
67a3ec1726Swdk 	bi = new;
68a3ec1726Swdk 	bi->next = size;
69a3ec1726Swdk 	bi->type = type;
7020ab98b3Swiz 	memcpy(bi_next, new, size);
71a3ec1726Swdk 	bi_next += size;
72a3ec1726Swdk 
73a3ec1726Swdk 	bi = (struct btinfo_common *)bi_next;
74a3ec1726Swdk 	bi->next = bi->type = 0;
75636d4f1aStsutsui 
76636d4f1aStsutsui 	bi_size += size;
77a3ec1726Swdk }
78