1*454af1c0Sdsl /* $NetBSD: bootinfo.c,v 1.3 2009/03/14 15:36:14 dsl Exp $ */
281248a08Schristos
381248a08Schristos /*-
481248a08Schristos * Copyright (c) 1999 The NetBSD Foundation, Inc.
581248a08Schristos * All rights reserved.
681248a08Schristos *
781248a08Schristos * This code is derived from software contributed to The NetBSD Foundation
881248a08Schristos * by Jonathan Stone, Michael Hitch and Simon Burge.
981248a08Schristos *
1081248a08Schristos * Redistribution and use in source and binary forms, with or without
1181248a08Schristos * modification, are permitted provided that the following conditions
1281248a08Schristos * are met:
1381248a08Schristos * 1. Redistributions of source code must retain the above copyright
1481248a08Schristos * notice, this list of conditions and the following disclaimer.
1581248a08Schristos * 2. Redistributions in binary form must reproduce the above copyright
1681248a08Schristos * notice, this list of conditions and the following disclaimer in the
1781248a08Schristos * documentation and/or other materials provided with the distribution.
1881248a08Schristos *
1981248a08Schristos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2081248a08Schristos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2181248a08Schristos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2281248a08Schristos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2381248a08Schristos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2481248a08Schristos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2581248a08Schristos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2681248a08Schristos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2781248a08Schristos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2881248a08Schristos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2981248a08Schristos * POSSIBILITY OF SUCH DAMAGE.
3081248a08Schristos */
3181248a08Schristos
3281248a08Schristos #include <sys/param.h>
3381248a08Schristos #include <machine/types.h>
3481248a08Schristos #include <lib/libsa/stand.h>
3581248a08Schristos #include <lib/libkern/libkern.h>
3681248a08Schristos
3781248a08Schristos #include "bootinfo.h"
3881248a08Schristos
3981248a08Schristos static char *bootinfo = NULL;
4081248a08Schristos static char *bi_next;
4181248a08Schristos static int bi_size;
4281248a08Schristos
4381248a08Schristos u_long
bi_init(u_long addr)44*454af1c0Sdsl bi_init(u_long addr)
4581248a08Schristos {
4681248a08Schristos struct btinfo_common *bi;
4781248a08Schristos struct btinfo_magic bi_magic;
4881248a08Schristos u_long *endp;
4981248a08Schristos
5081248a08Schristos endp = (u_long *)ALIGN(addr);
5181248a08Schristos /*
5281248a08Schristos * For the first word we load our end address,
5381248a08Schristos * giving enough space for the bootinfo structure.
5481248a08Schristos */
5581248a08Schristos endp[0] = (u_long)((char *)endp + BOOTINFO_SIZE);
5681248a08Schristos bootinfo = (char *)ALIGN(&endp[2]);
5781248a08Schristos endp[1] = (u_long)bootinfo;
5881248a08Schristos bi = (struct btinfo_common *)bootinfo;
5981248a08Schristos bi->next = bi->type = 0;
6081248a08Schristos bi_next = bootinfo;
6181248a08Schristos bi_size = 0;
6281248a08Schristos
6381248a08Schristos bi_magic.magic = BOOTINFO_MAGIC;
6481248a08Schristos bi_add(&bi_magic, BTINFO_MAGIC, sizeof(bi_magic));
6581248a08Schristos return (u_long) endp;
6681248a08Schristos }
6781248a08Schristos
6881248a08Schristos void
bi_add(void * new,int type,size_t size)69*454af1c0Sdsl bi_add(void *new, int type, size_t size)
7081248a08Schristos {
7181248a08Schristos struct btinfo_common *bi;
7281248a08Schristos
7381248a08Schristos if (bi_size + size > BOOTINFO_SIZE)
7481248a08Schristos return; /* XXX error? */
7581248a08Schristos
7681248a08Schristos bi = new;
7781248a08Schristos bi->next = ALIGN(size);
7881248a08Schristos bi->type = type;
7981248a08Schristos memcpy(bi_next, new, size);
8081248a08Schristos bi_next += ALIGN(size);
8181248a08Schristos
8281248a08Schristos bi = (struct btinfo_common *)bi_next;
8381248a08Schristos bi->next = bi->type = 0;
8481248a08Schristos }
85