bootinfo64.c revision 199767f8919635c4928607450d9e0abb932109ce
/*-
* Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
* All rights reserved.
*
* 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
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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 <stand.h>
#include <machine/bootinfo.h>
#include <machine/metadata.h>
#include <machine/specialreg.h>
#include "bootstrap.h"
#include "libi386.h"
#include "btxv86.h"
/*
* Copy module-related data into the load area, where it can be
* used as a directory for loaded modules.
*
* Module data is presented in a self-describing format. Each datum
* is preceded by a 32-bit identifier and a 32-bit size field.
*
* Currently, the following data are saved:
*
* MOD_NAME (variable) module name (string)
* MOD_TYPE (variable) module type (string)
* MOD_ARGS (variable) module parameters (string)
* MOD_ADDR sizeof(vm_offset_t) module load address
* MOD_SIZE sizeof(size_t) module size
* MOD_METADATA (variable) type-specific metadata
*/
#define COPY32(v, a, c) { \
u_int32_t x = (v); \
if (c) \
i386_copyin(&x, a, sizeof(x)); \
a += sizeof(x); \
}
#define MOD_STR(t, a, s, c) { \
COPY32(t, a, c); \
if (c) \
}
#define MOD_VAR(t, a, s, c) { \
COPY32(t, a, c); \
COPY32(sizeof(s), a, c); \
if (c) \
i386_copyin(&s, a, sizeof(s)); \
}
#define MOD_METADATA(a, mm, c) { \
if (c) \
}
#define MOD_END(a, c) { \
COPY32(MODINFO_END, a, c); \
COPY32(0, a, c); \
}
static vm_offset_t
{
struct preloaded_file *fp;
struct file_metadata *md;
int c;
u_int64_t v;
c = addr != 0;
/* start with the first module on the list, should be the kernel */
}
return(addr);
}
/*
* Check to see if this CPU supports long mode.
*/
int
bi_checkcpu(void)
{
char *cpu_vendor;
int vendor[3];
int eflags;
unsigned int regs[4];
/* Check for presence of "cpuid". */
eflags = read_eflags();
return (0);
/* Fetch the vendor string. */
cpu_vendor = (char *)vendor;
/* Check for vendors that support AMD features. */
return (0);
/* Has to support AMD features. */
if (!(regs[0] >= 0x80000001))
return (0);
/* Check for long mode. */
}
/*
* Load the information expected by an amd64 kernel.
*
* - The 'boothowto' argument is constructed
* - The 'bootdev' argument is constructed
* - The 'bootinfo' struct is constructed, and copied into the kernel space.
* - The kernel environment is copied into kernel space.
* - Module metadata are formatted and placed in kernel space.
*/
int
{
struct i386_devdesc *rootdev;
struct file_metadata *md;
char *rootdevname;
int howto;
if (!bi_checkcpu()) {
printf("CPU doesn't support long mode\n");
return (EINVAL);
}
/*
* Allow the environment variable 'rootdev' to override the supplied device
* MI code before launching the kernel.
*/
printf("can't determine root device\n");
return(EINVAL);
}
if (addr == 0) {
/* find the last module in the chain */
}
}
/* pad to a page boundary */
/* place the metadata before anything */
panic("can't find kernel file");
kernend = 0; /* fill it in later */
if (add_smap != 0)
size = bi_copymodules64(0);
/* copy our environment */
/* set kernend */
/* patch MODINFOMD_KERNEND */
/* patch MODINFOMD_ENVP */
/* copy module list and metadata */
(void)bi_copymodules64(*modulep);
return(0);
}