1*fad88a18Stsutsui /* $NetBSD: bootinfo.c,v 1.2 2019/12/14 02:58:20 tsutsui Exp $ */
25f7e80a8Spooka
35f7e80a8Spooka /*-
45f7e80a8Spooka * Copyright (c) 1999 The NetBSD Foundation, Inc.
55f7e80a8Spooka * All rights reserved.
65f7e80a8Spooka *
75f7e80a8Spooka * This code is derived from software contributed to The NetBSD Foundation
85f7e80a8Spooka * by Jonathan Stone, Michael Hitch and Simon Burge.
95f7e80a8Spooka *
105f7e80a8Spooka * Redistribution and use in source and binary forms, with or without
115f7e80a8Spooka * modification, are permitted provided that the following conditions
125f7e80a8Spooka * are met:
135f7e80a8Spooka * 1. Redistributions of source code must retain the above copyright
145f7e80a8Spooka * notice, this list of conditions and the following disclaimer.
155f7e80a8Spooka * 2. Redistributions in binary form must reproduce the above copyright
165f7e80a8Spooka * notice, this list of conditions and the following disclaimer in the
175f7e80a8Spooka * documentation and/or other materials provided with the distribution.
185f7e80a8Spooka *
195f7e80a8Spooka * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
205f7e80a8Spooka * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
215f7e80a8Spooka * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
225f7e80a8Spooka * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
235f7e80a8Spooka * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
245f7e80a8Spooka * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
255f7e80a8Spooka * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
265f7e80a8Spooka * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
275f7e80a8Spooka * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
285f7e80a8Spooka * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
295f7e80a8Spooka * POSSIBILITY OF SUCH DAMAGE.
305f7e80a8Spooka */
315f7e80a8Spooka
325f7e80a8Spooka #include <machine/types.h>
335f7e80a8Spooka #include <lib/libsa/stand.h>
345f7e80a8Spooka #include <lib/libkern/libkern.h>
355f7e80a8Spooka
365f7e80a8Spooka #include "bootinfo.h"
375f7e80a8Spooka
385f7e80a8Spooka char *bootinfo = NULL;
395f7e80a8Spooka static char *bi_next;
405f7e80a8Spooka static int bi_size;
415f7e80a8Spooka
bi_init(paddr_t addr)425f7e80a8Spooka void bi_init(paddr_t addr)
435f7e80a8Spooka {
445f7e80a8Spooka struct btinfo_common *bi;
455f7e80a8Spooka struct btinfo_magic bi_magic;
465f7e80a8Spooka
475f7e80a8Spooka bootinfo = (char *)addr;
485f7e80a8Spooka bi = (struct btinfo_common *)bootinfo;
495f7e80a8Spooka bi->next = bi->type = 0;
505f7e80a8Spooka bi_next = bootinfo;
515f7e80a8Spooka bi_size = 0;
525f7e80a8Spooka
535f7e80a8Spooka bi_magic.magic = BOOTINFO_MAGIC;
545f7e80a8Spooka bi_add(&bi_magic, BTINFO_MAGIC, sizeof(bi_magic));
555f7e80a8Spooka }
565f7e80a8Spooka
bi_add(void * new,int type,int size)575f7e80a8Spooka void bi_add(void *new, int type, int size)
585f7e80a8Spooka {
595f7e80a8Spooka struct btinfo_common *bi;
605f7e80a8Spooka
615f7e80a8Spooka if (bi_size + size > BOOTINFO_SIZE)
625f7e80a8Spooka return; /* XXX error? */
635f7e80a8Spooka
645f7e80a8Spooka bi = new;
655f7e80a8Spooka bi->next = size;
665f7e80a8Spooka bi->type = type;
675f7e80a8Spooka memcpy(bi_next, new, size);
685f7e80a8Spooka bi_next += size;
695f7e80a8Spooka
705f7e80a8Spooka bi = (struct btinfo_common *)bi_next;
715f7e80a8Spooka bi->next = bi->type = 0;
725f7e80a8Spooka }
73