190075Sobrien/*	$NetBSD: bootinfo.c,v 1.8 2008/04/28 20:23:31 martin Exp $	*/
2169689Skan
3132718Skan/*-
452284Sobrien * Copyright (c) 1999 The NetBSD Foundation, Inc.
590075Sobrien * All rights reserved.
652284Sobrien *
790075Sobrien * This code is derived from software contributed to The NetBSD Foundation
890075Sobrien * by Jonathan Stone, Michael Hitch and Simon Burge.
990075Sobrien *
1090075Sobrien * Redistribution and use in source and binary forms, with or without
1152284Sobrien * modification, are permitted provided that the following conditions
1290075Sobrien * are met:
1390075Sobrien * 1. Redistributions of source code must retain the above copyright
1490075Sobrien *    notice, this list of conditions and the following disclaimer.
1590075Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1652284Sobrien *    notice, this list of conditions and the following disclaimer in the
1752284Sobrien *    documentation and/or other materials provided with the distribution.
1890075Sobrien *
19169689Skan * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20169689Skan * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2152284Sobrien * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2252284Sobrien * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2390075Sobrien * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2452284Sobrien * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2552284Sobrien * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2652284Sobrien * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2752284Sobrien * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2852284Sobrien * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2952284Sobrien * POSSIBILITY OF SUCH DAMAGE.
3052284Sobrien */
3152284Sobrien
3252284Sobrien#include <machine/types.h>
3352284Sobrien#include <lib/libsa/stand.h>
3452284Sobrien#include <lib/libkern/libkern.h>
3552284Sobrien
3652284Sobrien#include "bootinfo.h"
3752284Sobrien
3852284Sobrienstatic char *bootinfo = NULL;
3952284Sobrienstatic char *bi_next;
4052284Sobrienstatic int bi_size;
4152284Sobrien
4252284Sobrienvoid bi_init(paddr_t addr)
4352284Sobrien{
4452284Sobrien	struct btinfo_common *bi;
4552284Sobrien	struct btinfo_magic bi_magic;
4652284Sobrien
4752284Sobrien	bootinfo = (char *)addr;
4852284Sobrien	bi = (struct btinfo_common *)bootinfo;
4952284Sobrien	bi->next = bi->type = 0;
5052284Sobrien	bi_next = bootinfo;
5152284Sobrien	bi_size = 0;
5252284Sobrien
5352284Sobrien	bi_magic.magic = BOOTINFO_MAGIC;
5452284Sobrien	bi_add(&bi_magic, BTINFO_MAGIC, sizeof(bi_magic));
55132718Skan}
56132718Skan
5752284Sobrienvoid bi_add(void *new, int type, int size)
5852284Sobrien{
5952284Sobrien	struct btinfo_common *bi;
6052284Sobrien
6152284Sobrien	if (bi_size + size > BOOTINFO_SIZE)
6252284Sobrien		return;				/* XXX error? */
6352284Sobrien
6452284Sobrien	bi = new;
65117395Skan	bi->next = size;
6690075Sobrien	bi->type = type;
67132718Skan	memcpy(bi_next, new, size);
6852284Sobrien	bi_next += size;
6990075Sobrien
7090075Sobrien	bi = (struct btinfo_common *)bi_next;
7190075Sobrien	bi->next = bi->type = 0;
7252284Sobrien
7390075Sobrien	bi_size += size;
74132718Skan}
75132718Skan