1*ce099b40Smartin /* $NetBSD: bootinfo.c,v 1.4 2008/04/28 20:23:34 martin Exp $ */
24e63f44fSthorpej
34e63f44fSthorpej /*-
44e63f44fSthorpej * Copyright (c) 1999 The NetBSD Foundation, Inc.
54e63f44fSthorpej * All rights reserved.
64e63f44fSthorpej *
74e63f44fSthorpej * This code is derived from software contributed to The NetBSD Foundation
84e63f44fSthorpej * by Jonathan Stone, Michael Hitch and Simon Burge.
94e63f44fSthorpej *
104e63f44fSthorpej * Redistribution and use in source and binary forms, with or without
114e63f44fSthorpej * modification, are permitted provided that the following conditions
124e63f44fSthorpej * are met:
134e63f44fSthorpej * 1. Redistributions of source code must retain the above copyright
144e63f44fSthorpej * notice, this list of conditions and the following disclaimer.
154e63f44fSthorpej * 2. Redistributions in binary form must reproduce the above copyright
164e63f44fSthorpej * notice, this list of conditions and the following disclaimer in the
174e63f44fSthorpej * documentation and/or other materials provided with the distribution.
184e63f44fSthorpej *
194e63f44fSthorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
204e63f44fSthorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
214e63f44fSthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
224e63f44fSthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
234e63f44fSthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
244e63f44fSthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
254e63f44fSthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
264e63f44fSthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
274e63f44fSthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
284e63f44fSthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
294e63f44fSthorpej * POSSIBILITY OF SUCH DAMAGE.
304e63f44fSthorpej */
314e63f44fSthorpej
324e63f44fSthorpej #include <machine/types.h>
334e63f44fSthorpej #include <lib/libsa/stand.h>
344e63f44fSthorpej #include <lib/libkern/libkern.h>
354e63f44fSthorpej
364e63f44fSthorpej #include "bootinfo.h"
374e63f44fSthorpej
38de92c0b2Stsutsui struct btinfo_common *bootinfo; /* bootinfo address */
394e63f44fSthorpej
40de92c0b2Stsutsui static char *bi_next; /* pointer to next bootinfo data */
41de92c0b2Stsutsui static int bi_size; /* current bootinfo size */
423975ceceSthorpej
433975ceceSthorpej void
bi_init(void * bi_addr)44de92c0b2Stsutsui bi_init(void *bi_addr)
454e63f44fSthorpej {
46de92c0b2Stsutsui struct btinfo_magic bi_magic;
474e63f44fSthorpej
48de92c0b2Stsutsui bootinfo = bi_addr;
49de92c0b2Stsutsui bootinfo->next = 0;
50de92c0b2Stsutsui bootinfo->type = BTINFO_NONE;
51de92c0b2Stsutsui
52de92c0b2Stsutsui bi_next = (void *)bootinfo;
53de92c0b2Stsutsui bi_size = 0;
544e63f44fSthorpej
554e63f44fSthorpej bi_magic.magic = BOOTINFO_MAGIC;
56de92c0b2Stsutsui bi_add(&bi_magic, BTINFO_MAGIC, sizeof(bi_magic));
574e63f44fSthorpej }
584e63f44fSthorpej
593975ceceSthorpej void
bi_add(void * new,int type,size_t size)60de92c0b2Stsutsui bi_add(void *new, int type, size_t size)
614e63f44fSthorpej {
62de92c0b2Stsutsui struct btinfo_common *bi;
634e63f44fSthorpej
64de92c0b2Stsutsui if (bi_size + size > BOOTINFO_SIZE)
65de92c0b2Stsutsui return; /* XXX should report error? */
66de92c0b2Stsutsui
67de92c0b2Stsutsui bi_size += size;
68de92c0b2Stsutsui
69de92c0b2Stsutsui /* register new bootinfo data */
70de92c0b2Stsutsui memcpy(bi_next, new, size);
71de92c0b2Stsutsui bi = (void *)bi_next;
72de92c0b2Stsutsui bi->next = size;
734e63f44fSthorpej bi->type = type;
74de92c0b2Stsutsui
75de92c0b2Stsutsui /* update pointer to next bootinfo data */
76de92c0b2Stsutsui bi_next += size;
77de92c0b2Stsutsui bi = (void *)bi_next;
78de92c0b2Stsutsui bi->next = 0;
79de92c0b2Stsutsui bi->type = BTINFO_NONE;
804e63f44fSthorpej }
81