Add a 'struct bootinfo' to represent the bootinfo structure used in the

kernel by x86 platforms (instead of a simple char *).  This way, the code
in, e.g., lookup_bootinfo, is a bit easier to understand.

While here, move the lookup_bootinfo function used in x86 platforms (amd64,
i386 and xen) to a common file (x86/x86_machdep.c), as it was exactly the
same in all of them.
This commit is contained in:
jmmv 2005-12-30 13:37:57 +00:00
parent 4e8460804d
commit eb23406894
7 changed files with 113 additions and 62 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.c,v 1.36 2005/12/24 20:06:47 perry Exp $ */
/* $NetBSD: machdep.c,v 1.37 2005/12/30 13:37:57 jmmv Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998, 2000 The NetBSD Foundation, Inc.
@ -72,7 +72,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.36 2005/12/24 20:06:47 perry Exp $");
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.37 2005/12/30 13:37:57 jmmv Exp $");
#include "opt_user_ldt.h"
#include "opt_ddb.h"
@ -161,8 +161,6 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.36 2005/12/24 20:06:47 perry Exp $");
char machine[] = "amd64"; /* CPU "architecture" */
char machine_arch[] = "x86_64"; /* machine == machine_arch */
char bootinfo[BOOTINFO_MAXSIZE];
/* Our exported CPU info; we have only one right now. */
struct cpu_info cpu_info_primary;
struct cpu_info *cpu_info_list;
@ -1554,21 +1552,6 @@ init_x86_64(first_avail)
maxproc = cpu_maxproc();
}
void *
lookup_bootinfo(type)
int type;
{
struct btinfo_common *help;
int n = *(int*)bootinfo;
help = (struct btinfo_common *)(bootinfo + sizeof(int));
while(n--) {
if(help->type == type)
return(help);
help = (struct btinfo_common *)((char*)help + help->len);
}
return(0);
}
void
cpu_reset()
{

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.c,v 1.568 2005/12/26 19:23:59 perry Exp $ */
/* $NetBSD: machdep.c,v 1.569 2005/12/30 13:37:57 jmmv Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998, 2000, 2004 The NetBSD Foundation, Inc.
@ -72,7 +72,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.568 2005/12/26 19:23:59 perry Exp $");
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.569 2005/12/30 13:37:57 jmmv Exp $");
#include "opt_beep.h"
#include "opt_compat_ibcs2.h"
@ -203,8 +203,6 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.568 2005/12/26 19:23:59 perry Exp $");
char machine[] = "i386"; /* CPU "architecture" */
char machine_arch[] = "i386"; /* machine == machine_arch */
char bootinfo[BOOTINFO_MAXSIZE];
extern struct bi_devmatch *x86_alldisks;
extern int x86_ndisks;
@ -2020,20 +2018,6 @@ cpu_exec_aout_makecmds(struct lwp *l, struct exec_package *epp)
return error;
}
void *
lookup_bootinfo(int type)
{
struct btinfo_common *help;
int n = *(int*)bootinfo;
help = (struct btinfo_common *)(bootinfo + sizeof(int));
while(n--) {
if(help->type == type)
return(help);
help = (struct btinfo_common *)((char*)help + help->len);
}
return(0);
}
#include <dev/ic/mc146818reg.h> /* for NVRAM POST */
#include <i386/isa/nvram.h> /* for NVRAM POST */

View File

@ -1,4 +1,4 @@
# $NetBSD: files.x86,v 1.14 2005/12/11 12:19:47 christos Exp $
# $NetBSD: files.x86,v 1.15 2005/12/30 13:37:57 jmmv Exp $
# options for MP configuration through the MP spec
defflag opt_mpbios.h MPBIOS MPVERBOSE MPDEBUG MPBIOS_SCANPCI
@ -25,6 +25,7 @@ file arch/x86/x86/lock_machdep.c lockdebug
file arch/x86/x86/mtrr_i686.c mtrr
file arch/x86/x86/softintr.c
file arch/x86/x86/x86_autoconf.c
file arch/x86/x86/x86_machdep.c
define lapic
file arch/x86/x86/lapic.c lapic needs-flag

View File

@ -1,4 +1,4 @@
/* $NetBSD: bootinfo.h,v 1.9 2005/07/06 08:27:31 junyoung Exp $ */
/* $NetBSD: bootinfo.h,v 1.10 2005/12/30 13:37:57 jmmv Exp $ */
/*
* Copyright (c) 1997
@ -157,11 +157,28 @@ struct btinfo_biosgeom {
struct bi_biosgeom_entry disk[1]; /* var len */
};
#ifdef _KERNEL
void *lookup_bootinfo(int);
#endif
#endif /* _LOCORE */
#ifdef _KERNEL
#define BOOTINFO_MAXSIZE 4096
#endif
#ifndef _LOCORE
/*
* Structure that holds the information passed by the boot loader.
*/
struct bootinfo {
/* Number of bootinfo_* entries in bi_data. */
uint32_t bi_nentries;
/* Raw data of bootinfo entries. The first one (if any) is
* found at bi_data[0] and can be casted to (bootinfo_common *).
* Once this is done, the following entry is found at 'len'
* offset as specified by the previous entry. */
uint8_t bi_data[BOOTINFO_MAXSIZE - sizeof(uint32_t)];
};
void *lookup_bootinfo(int);
#endif /* _LOCORE */
#endif /* _KERNEL */

View File

@ -0,0 +1,81 @@
/* $NetBSD: x86_machdep.c,v 1.1 2005/12/30 13:37:57 jmmv Exp $ */
/*-
* Copyright (c) 2005 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Julio M. Merino Vidal.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.1 2005/12/30 13:37:57 jmmv Exp $");
#include <sys/types.h>
#include <sys/systm.h>
#include <machine/bootinfo.h>
/* --------------------------------------------------------------------- */
/*
* Main bootinfo structure. This is filled in by the bootstrap process
* done in locore.S based on the information passed by the boot loader.
*/
struct bootinfo bootinfo;
/* --------------------------------------------------------------------- */
/*
* Given the type of a bootinfo entry, looks for a matching item inside
* the bootinfo structure. If found, returns a pointer to it (which must
* then be casted to the appropriate bootinfo_* type); otherwise, returns
* NULL.
*/
void *
lookup_bootinfo(int type)
{
boolean_t found;
int i;
struct btinfo_common *bic;
bic = (struct btinfo_common *)(bootinfo.bi_data);
found = FALSE;
for (i = 0; i < bootinfo.bi_nentries && !found; i++) {
if (bic->type == type)
found = TRUE;
else
bic = (struct btinfo_common *)
((uint8_t *)bic + bic->len);
}
return found ? bic : NULL;
}

View File

@ -1,4 +1,4 @@
# $NetBSD: files.xen,v 1.31 2005/11/21 22:15:13 bouyer Exp $
# $NetBSD: files.xen,v 1.32 2005/12/30 13:37:57 jmmv Exp $
# NetBSD: files.x86,v 1.10 2003/10/08 17:30:00 bouyer Exp
# NetBSD: files.i386,v 1.254 2004/03/25 23:32:10 jmc Exp
@ -93,6 +93,7 @@ file arch/xen/x86/intr.c
file arch/x86/x86/ipi.c multiprocessor
file arch/x86/x86/lock_machdep.c lockdebug
file arch/x86/x86/softintr.c
file arch/x86/x86/x86_machdep.c
include "arch/xen/conf/files.compat"

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.c,v 1.22 2005/12/24 20:07:48 perry Exp $ */
/* $NetBSD: machdep.c,v 1.23 2005/12/30 13:37:57 jmmv Exp $ */
/* NetBSD: machdep.c,v 1.559 2004/07/22 15:12:46 mycroft Exp */
/*-
@ -73,7 +73,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.22 2005/12/24 20:07:48 perry Exp $");
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.23 2005/12/30 13:37:57 jmmv Exp $");
#include "opt_beep.h"
#include "opt_compat_ibcs2.h"
@ -235,8 +235,6 @@ void xen_dbglow_init(void);
char machine[] = "i386"; /* CPU "architecture" */
char machine_arch[] = "i386"; /* machine == machine_arch */
char bootinfo[BOOTINFO_MAXSIZE];
extern struct bi_devmatch *x86_alldisks;
extern int x86_ndisks;
@ -2226,20 +2224,6 @@ cpu_exec_aout_makecmds(struct lwp *l, struct exec_package *epp)
return error;
}
void *
lookup_bootinfo(int type)
{
struct btinfo_common *help;
int n = *(int*)bootinfo;
help = (struct btinfo_common *)(bootinfo + sizeof(int));
while(n--) {
if(help->type == type)
return(help);
help = (struct btinfo_common *)((char*)help + help->len);
}
return(0);
}
#include <dev/ic/mc146818reg.h> /* for NVRAM POST */
#include <i386/isa/nvram.h> /* for NVRAM POST */