xref: /netbsd-src/sys/arch/pmax/stand/common/bootinfo.c (revision bb43e1b7cff7cfce8b7b610349766dd15e025f49)
1*bb43e1b7Stsutsui /*	$NetBSD: bootinfo.c,v 1.9 2011/01/11 16:19:38 tsutsui Exp $	*/
21e9b1f56Ssimonb 
31e9b1f56Ssimonb /*-
41e9b1f56Ssimonb  * Copyright (c) 1999 The NetBSD Foundation, Inc.
51e9b1f56Ssimonb  * All rights reserved.
61e9b1f56Ssimonb  *
71e9b1f56Ssimonb  * This code is derived from software contributed to The NetBSD Foundation
81e9b1f56Ssimonb  * by Jonathan Stone, Michael Hitch and Simon Burge.
91e9b1f56Ssimonb  *
101e9b1f56Ssimonb  * Redistribution and use in source and binary forms, with or without
111e9b1f56Ssimonb  * modification, are permitted provided that the following conditions
121e9b1f56Ssimonb  * are met:
131e9b1f56Ssimonb  * 1. Redistributions of source code must retain the above copyright
141e9b1f56Ssimonb  *    notice, this list of conditions and the following disclaimer.
151e9b1f56Ssimonb  * 2. Redistributions in binary form must reproduce the above copyright
161e9b1f56Ssimonb  *    notice, this list of conditions and the following disclaimer in the
171e9b1f56Ssimonb  *    documentation and/or other materials provided with the distribution.
181e9b1f56Ssimonb  *
191e9b1f56Ssimonb  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201e9b1f56Ssimonb  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211e9b1f56Ssimonb  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221e9b1f56Ssimonb  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231e9b1f56Ssimonb  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241e9b1f56Ssimonb  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251e9b1f56Ssimonb  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261e9b1f56Ssimonb  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271e9b1f56Ssimonb  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281e9b1f56Ssimonb  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291e9b1f56Ssimonb  * POSSIBILITY OF SUCH DAMAGE.
301e9b1f56Ssimonb  */
311e9b1f56Ssimonb 
321e9b1f56Ssimonb #include <machine/types.h>
331e9b1f56Ssimonb #include <lib/libsa/stand.h>
341e9b1f56Ssimonb #include <lib/libkern/libkern.h>
351e9b1f56Ssimonb 
361e9b1f56Ssimonb #include "bootinfo.h"
371e9b1f56Ssimonb 
381e9b1f56Ssimonb static char *bootinfo = NULL;
391e9b1f56Ssimonb static char *bi_next;
401e9b1f56Ssimonb static int bi_size;
411e9b1f56Ssimonb 
bi_init(paddr_t addr)42*bb43e1b7Stsutsui void bi_init(paddr_t addr)
431e9b1f56Ssimonb {
441e9b1f56Ssimonb 	struct btinfo_common *bi;
451e9b1f56Ssimonb 	struct btinfo_magic bi_magic;
461e9b1f56Ssimonb 
471e9b1f56Ssimonb 	bootinfo = (char *)addr;
481e9b1f56Ssimonb 	bi = (struct btinfo_common *)bootinfo;
491e9b1f56Ssimonb 	bi->next = bi->type = 0;
501e9b1f56Ssimonb 	bi_next = bootinfo;
511e9b1f56Ssimonb 	bi_size = 0;
521e9b1f56Ssimonb 
531e9b1f56Ssimonb 	bi_magic.magic = BOOTINFO_MAGIC;
541e9b1f56Ssimonb 	bi_add(&bi_magic, BTINFO_MAGIC, sizeof(bi_magic));
551e9b1f56Ssimonb }
561e9b1f56Ssimonb 
bi_add(void * new,int type,int size)57*bb43e1b7Stsutsui void bi_add(void *new, int type, int size)
581e9b1f56Ssimonb {
591e9b1f56Ssimonb 	struct btinfo_common *bi;
601e9b1f56Ssimonb 
611e9b1f56Ssimonb 	if (bi_size + size > BOOTINFO_SIZE)
621e9b1f56Ssimonb 		return;				/* XXX error? */
631e9b1f56Ssimonb 
641e9b1f56Ssimonb 	bi = new;
651e9b1f56Ssimonb 	bi->next = size;
661e9b1f56Ssimonb 	bi->type = type;
67c23e6dcbSsimonb 	memcpy(bi_next, new, size);
681e9b1f56Ssimonb 	bi_next += size;
691e9b1f56Ssimonb 
701e9b1f56Ssimonb 	bi = (struct btinfo_common *)bi_next;
711e9b1f56Ssimonb 	bi->next = bi->type = 0;
72636d4f1aStsutsui 
73636d4f1aStsutsui 	bi_size += size;
741e9b1f56Ssimonb }
75