libpayload: rename i386 to x86
Change-Id: Ia9170bd3d04e76dbf9321ca7ea4be23b5e468d21 Signed-off-by: Stefan Reinauer <reinauer@google.com> Reviewed-on: http://review.coreboot.org/2033 Tested-by: build bot (Jenkins) Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
This commit is contained in:
committed by
Ronald G. Minnich
parent
9aaf7d17bb
commit
f6935a006a
29
payloads/libpayload/arch/x86/Config.in
Normal file
29
payloads/libpayload/arch/x86/Config.in
Normal file
@@ -0,0 +1,29 @@
|
||||
##
|
||||
## Copyright (c) 2012 The Chromium OS Authors.
|
||||
##
|
||||
## See file CREDITS for list of people who contributed to this
|
||||
## project.
|
||||
##
|
||||
## This program is free software; you can redistribute it and/or
|
||||
## modify it under the terms of the GNU General Public License as
|
||||
## published by the Free Software Foundation; either version 2 of
|
||||
## the License, or (at your option) any later version.
|
||||
##
|
||||
## This program is distributed in the hope that it will be useful,
|
||||
## but without any warranty; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
## GNU General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU General Public License
|
||||
## along with this program; if not, write to the Free Software
|
||||
## Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
## MA 02111-1307 USA
|
||||
##
|
||||
|
||||
if ARCH_X86
|
||||
|
||||
config ARCH_SPECIFIC_OPTIONS # dummy
|
||||
def_bool y
|
||||
select LITTLE_ENDIAN
|
||||
|
||||
endif
|
37
payloads/libpayload/arch/x86/Makefile.inc
Normal file
37
payloads/libpayload/arch/x86/Makefile.inc
Normal file
@@ -0,0 +1,37 @@
|
||||
##
|
||||
## This file is part of the libpayload project.
|
||||
##
|
||||
## Copyright (C) 2008 Advanced Micro Devices, Inc.
|
||||
##
|
||||
## 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. The name of the author may not be used to endorse or promote products
|
||||
## derived from this software without specific prior written permission.
|
||||
##
|
||||
## 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.
|
||||
##
|
||||
|
||||
head.o-y += head.S
|
||||
libc-y += main.c sysinfo.c
|
||||
libc-y += timer.c coreboot.c util.S
|
||||
libc-y += exec.S virtual.c
|
||||
libc-y += string.c
|
||||
|
||||
# Multiboot support is configurable
|
||||
libc-$(CONFIG_MULTIBOOT) += multiboot.c
|
290
payloads/libpayload/arch/x86/coreboot.c
Normal file
290
payloads/libpayload/arch/x86/coreboot.c
Normal file
@@ -0,0 +1,290 @@
|
||||
/*
|
||||
* This file is part of the libpayload project.
|
||||
*
|
||||
* Copyright (C) 2008 Advanced Micro Devices, Inc.
|
||||
* Copyright (C) 2009 coresystems GmbH
|
||||
*
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* 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 <libpayload-config.h>
|
||||
#include <libpayload.h>
|
||||
#include <coreboot_tables.h>
|
||||
|
||||
/*
|
||||
* Some of this is x86 specific, and the rest of it is generic. Right now,
|
||||
* since we only support x86, we'll avoid trying to make lots of infrastructure
|
||||
* we don't need. If in the future, we want to use coreboot on some other
|
||||
* architecture, then take out the generic parsing code and move it elsewhere.
|
||||
*/
|
||||
|
||||
/* === Parsing code === */
|
||||
/* This is the generic parsing code. */
|
||||
|
||||
static void cb_parse_memory(void *ptr, struct sysinfo_t *info)
|
||||
{
|
||||
struct cb_memory *mem = ptr;
|
||||
int count = MEM_RANGE_COUNT(mem);
|
||||
int i;
|
||||
|
||||
if (count > SYSINFO_MAX_MEM_RANGES)
|
||||
count = SYSINFO_MAX_MEM_RANGES;
|
||||
|
||||
info->n_memranges = 0;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
struct cb_memory_range *range = MEM_RANGE_PTR(mem, i);
|
||||
|
||||
#ifdef CONFIG_MEMMAP_RAM_ONLY
|
||||
if (range->type != CB_MEM_RAM)
|
||||
continue;
|
||||
#endif
|
||||
|
||||
info->memrange[info->n_memranges].base =
|
||||
cb_unpack64(range->start);
|
||||
|
||||
info->memrange[info->n_memranges].size =
|
||||
cb_unpack64(range->size);
|
||||
|
||||
info->memrange[info->n_memranges].type = range->type;
|
||||
|
||||
info->n_memranges++;
|
||||
}
|
||||
}
|
||||
|
||||
static void cb_parse_serial(void *ptr, struct sysinfo_t *info)
|
||||
{
|
||||
info->serial = ((struct cb_serial *)ptr);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_CHROMEOS
|
||||
static void cb_parse_vbnv(unsigned char *ptr, struct sysinfo_t *info)
|
||||
{
|
||||
struct cb_vbnv *vbnv = (struct cb_vbnv *)ptr;
|
||||
|
||||
info->vbnv_start = vbnv->vbnv_start;
|
||||
info->vbnv_size = vbnv->vbnv_size;
|
||||
}
|
||||
|
||||
static void cb_parse_gpios(unsigned char *ptr, struct sysinfo_t *info)
|
||||
{
|
||||
int i;
|
||||
struct cb_gpios *gpios = (struct cb_gpios *)ptr;
|
||||
|
||||
info->num_gpios = (gpios->count < SYSINFO_MAX_GPIOS) ?
|
||||
(gpios->count) : SYSINFO_MAX_GPIOS;
|
||||
|
||||
for (i = 0; i < info->num_gpios; i++)
|
||||
info->gpios[i] = gpios->gpios[i];
|
||||
}
|
||||
|
||||
static void cb_parse_vdat(unsigned char *ptr, struct sysinfo_t *info)
|
||||
{
|
||||
struct cb_vdat *vdat = (struct cb_vdat *) ptr;
|
||||
|
||||
info->vdat_addr = phys_to_virt(vdat->vdat_addr);
|
||||
info->vdat_size = vdat->vdat_size;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void cb_parse_tstamp(unsigned char *ptr, struct sysinfo_t *info)
|
||||
{
|
||||
struct cb_cbmem_tab *const cbmem = (struct cb_cbmem_tab *)ptr;
|
||||
info->tstamp_table = phys_to_virt(cbmem->cbmem_tab);
|
||||
}
|
||||
|
||||
static void cb_parse_cbmem_cons(unsigned char *ptr, struct sysinfo_t *info)
|
||||
{
|
||||
struct cb_cbmem_tab *const cbmem = (struct cb_cbmem_tab *)ptr;
|
||||
info->cbmem_cons = phys_to_virt(cbmem->cbmem_tab);
|
||||
}
|
||||
|
||||
static void cb_parse_mrc_cache(unsigned char *ptr, struct sysinfo_t *info)
|
||||
{
|
||||
struct cb_cbmem_tab *const cbmem = (struct cb_cbmem_tab *)ptr;
|
||||
info->mrc_cache = phys_to_virt(cbmem->cbmem_tab);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_NVRAM
|
||||
static void cb_parse_optiontable(void *ptr, struct sysinfo_t *info)
|
||||
{
|
||||
info->option_table = ptr;
|
||||
}
|
||||
|
||||
static void cb_parse_checksum(void *ptr, struct sysinfo_t *info)
|
||||
{
|
||||
struct cb_cmos_checksum *cmos_cksum = ptr;
|
||||
info->cmos_range_start = cmos_cksum->range_start;
|
||||
info->cmos_range_end = cmos_cksum->range_end;
|
||||
info->cmos_checksum_location = cmos_cksum->location;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_COREBOOT_VIDEO_CONSOLE
|
||||
static void cb_parse_framebuffer(void *ptr, struct sysinfo_t *info)
|
||||
{
|
||||
info->framebuffer = ptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void cb_parse_string(unsigned char *ptr, char **info)
|
||||
{
|
||||
*info = (char *)((struct cb_string *)ptr)->string;
|
||||
}
|
||||
|
||||
static int cb_parse_header(void *addr, int len, struct sysinfo_t *info)
|
||||
{
|
||||
struct cb_header *header;
|
||||
unsigned char *ptr = addr;
|
||||
void *forward;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < len; i += 16, ptr += 16) {
|
||||
header = (struct cb_header *)ptr;
|
||||
if (!strncmp((const char *)header->signature, "LBIO", 4))
|
||||
break;
|
||||
}
|
||||
|
||||
/* We walked the entire space and didn't find anything. */
|
||||
if (i >= len)
|
||||
return -1;
|
||||
|
||||
if (!header->table_bytes)
|
||||
return 0;
|
||||
|
||||
/* Make sure the checksums match. */
|
||||
if (ipchksum((u16 *) header, sizeof(*header)) != 0)
|
||||
return -1;
|
||||
|
||||
if (ipchksum((u16 *) (ptr + sizeof(*header)),
|
||||
header->table_bytes) != header->table_checksum)
|
||||
return -1;
|
||||
|
||||
info->header = header;
|
||||
|
||||
/* Now, walk the tables. */
|
||||
ptr += header->header_bytes;
|
||||
|
||||
for (i = 0; i < header->table_entries; i++) {
|
||||
struct cb_record *rec = (struct cb_record *)ptr;
|
||||
|
||||
/* We only care about a few tags here (maybe more later). */
|
||||
switch (rec->tag) {
|
||||
case CB_TAG_FORWARD:
|
||||
forward = phys_to_virt((void *)(unsigned long)((struct cb_forward *)rec)->forward);
|
||||
return cb_parse_header(forward, len, info);
|
||||
continue;
|
||||
case CB_TAG_MEMORY:
|
||||
cb_parse_memory(ptr, info);
|
||||
break;
|
||||
case CB_TAG_SERIAL:
|
||||
cb_parse_serial(ptr, info);
|
||||
break;
|
||||
case CB_TAG_VERSION:
|
||||
cb_parse_string(ptr, &info->cb_version);
|
||||
break;
|
||||
case CB_TAG_EXTRA_VERSION:
|
||||
cb_parse_string(ptr, &info->extra_version);
|
||||
break;
|
||||
case CB_TAG_BUILD:
|
||||
cb_parse_string(ptr, &info->build);
|
||||
break;
|
||||
case CB_TAG_COMPILE_TIME:
|
||||
cb_parse_string(ptr, &info->compile_time);
|
||||
break;
|
||||
case CB_TAG_COMPILE_BY:
|
||||
cb_parse_string(ptr, &info->compile_by);
|
||||
break;
|
||||
case CB_TAG_COMPILE_HOST:
|
||||
cb_parse_string(ptr, &info->compile_host);
|
||||
break;
|
||||
case CB_TAG_COMPILE_DOMAIN:
|
||||
cb_parse_string(ptr, &info->compile_domain);
|
||||
break;
|
||||
case CB_TAG_COMPILER:
|
||||
cb_parse_string(ptr, &info->compiler);
|
||||
break;
|
||||
case CB_TAG_LINKER:
|
||||
cb_parse_string(ptr, &info->linker);
|
||||
break;
|
||||
case CB_TAG_ASSEMBLER:
|
||||
cb_parse_string(ptr, &info->assembler);
|
||||
break;
|
||||
#ifdef CONFIG_NVRAM
|
||||
case CB_TAG_CMOS_OPTION_TABLE:
|
||||
cb_parse_optiontable(ptr, info);
|
||||
break;
|
||||
case CB_TAG_OPTION_CHECKSUM:
|
||||
cb_parse_checksum(ptr, info);
|
||||
break;
|
||||
#endif
|
||||
#ifdef CONFIG_COREBOOT_VIDEO_CONSOLE
|
||||
// FIXME we should warn on serial if coreboot set up a
|
||||
// framebuffer buf the payload does not know about it.
|
||||
case CB_TAG_FRAMEBUFFER:
|
||||
cb_parse_framebuffer(ptr, info);
|
||||
break;
|
||||
#endif
|
||||
case CB_TAG_MAINBOARD:
|
||||
info->mainboard = (struct cb_mainboard *)ptr;
|
||||
#ifdef CONFIG_CHROMEOS
|
||||
case CB_TAG_GPIO:
|
||||
cb_parse_gpios(ptr, info);
|
||||
break;
|
||||
case CB_TAG_VDAT:
|
||||
cb_parse_vdat(ptr, info);
|
||||
break;
|
||||
case CB_TAG_VBNV:
|
||||
cb_parse_vbnv(ptr, info);
|
||||
break;
|
||||
#endif
|
||||
case CB_TAG_TIMESTAMPS:
|
||||
cb_parse_tstamp(ptr, info);
|
||||
break;
|
||||
case CB_TAG_CBMEM_CONSOLE:
|
||||
cb_parse_cbmem_cons(ptr, info);
|
||||
break;
|
||||
case CB_TAG_MRC_CACHE:
|
||||
cb_parse_mrc_cache(ptr, info);
|
||||
break;
|
||||
}
|
||||
|
||||
ptr += rec->size;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* == Architecture specific == */
|
||||
/* This is the x86 specific stuff. */
|
||||
|
||||
int get_coreboot_info(struct sysinfo_t *info)
|
||||
{
|
||||
int ret = cb_parse_header(phys_to_virt(0x00000000), 0x1000, info);
|
||||
|
||||
if (ret != 1)
|
||||
ret = cb_parse_header(phys_to_virt(0x000f0000), 0x1000, info);
|
||||
|
||||
return (ret == 1) ? 0 : -1;
|
||||
}
|
99
payloads/libpayload/arch/x86/exec.S
Normal file
99
payloads/libpayload/arch/x86/exec.S
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* This file is part of the libpayload project.
|
||||
*
|
||||
* Copyright (C) 2008 Advanced Micro Devices, Inc.
|
||||
*
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* calling syntax: i386_do_exec(long addr, int argc, char **argv, int *ret) */
|
||||
|
||||
/* This implements the payload API detailed here:
|
||||
* http://www.coreboot.org/Payload_API
|
||||
*/
|
||||
|
||||
.align 4
|
||||
.text
|
||||
|
||||
.global i386_do_exec
|
||||
.type i386_do_exec,@function
|
||||
|
||||
i386_do_exec:
|
||||
pushl %ebp
|
||||
movl %esp, %ebp
|
||||
pushl %eax
|
||||
|
||||
/* Put the run address in %eax */
|
||||
movl 8(%ebp), %eax
|
||||
|
||||
/* Save off the rest of the registers */
|
||||
|
||||
pushl %esi
|
||||
pushl %ecx
|
||||
pushl %ebp
|
||||
|
||||
/* Push the argc and argv pointers on to the stack */
|
||||
|
||||
movl 12(%ebp), %esi
|
||||
movl 16(%ebp), %ecx
|
||||
|
||||
pushl %esi
|
||||
pushl %ecx
|
||||
|
||||
/* Move a "magic" number on the stack - the other
|
||||
* payload will use this as a clue that the argc
|
||||
* and argv are sane
|
||||
*/
|
||||
|
||||
movl $12345678, %ecx
|
||||
pushl %ecx
|
||||
|
||||
/* Jump to the code */
|
||||
call *%eax
|
||||
|
||||
/* %eax has the return value */
|
||||
|
||||
/* Skip over the argc/argv stuff still on the stack */
|
||||
addl $12, %esp
|
||||
|
||||
/* Get back %ebp */
|
||||
popl %ebp
|
||||
|
||||
/* Get the pointer to the return value
|
||||
* and save the return value in it
|
||||
*/
|
||||
|
||||
movl 20(%ebp), %ecx
|
||||
movl %eax, (%eax)
|
||||
|
||||
/* Get the rest of the saved registers */
|
||||
popl %ecx
|
||||
popl %esi
|
||||
popl %eax
|
||||
|
||||
/* Restore the stack pointer */
|
||||
movl %ebp,%esp
|
||||
popl %ebp
|
||||
ret
|
||||
|
104
payloads/libpayload/arch/x86/head.S
Normal file
104
payloads/libpayload/arch/x86/head.S
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* This file is part of the libpayload project.
|
||||
*
|
||||
* Copyright (C) 2008 Advanced Micro Devices, Inc.
|
||||
*
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.code32
|
||||
.global _entry, _leave
|
||||
.text
|
||||
.align 4
|
||||
|
||||
/*
|
||||
* Our entry point - assume that the CPU is in 32 bit protected mode and
|
||||
* all segments are in a flat model. That's our operating mode, so we won't
|
||||
* change anything.
|
||||
*/
|
||||
_entry:
|
||||
jmp _init
|
||||
|
||||
.align 4
|
||||
|
||||
#define MB_MAGIC 0x1BADB002
|
||||
#define MB_FLAGS 0x00010003
|
||||
|
||||
mb_header:
|
||||
.long MB_MAGIC
|
||||
.long MB_FLAGS
|
||||
.long -(MB_MAGIC + MB_FLAGS)
|
||||
.long mb_header
|
||||
.long _start
|
||||
.long _edata
|
||||
.long _end
|
||||
.long _init
|
||||
|
||||
/*
|
||||
* This function saves off the previous stack and switches us to our
|
||||
* own execution environment.
|
||||
*/
|
||||
_init:
|
||||
/* No interrupts, please. */
|
||||
cli
|
||||
|
||||
/* There is a bunch of stuff missing here to take arguments on the stack
|
||||
* See http://www.coreboot.org/Payload_API and exec.S.
|
||||
*/
|
||||
/* Store current stack pointer. */
|
||||
movl %esp, %esi
|
||||
|
||||
/* Store EAX and EBX */
|
||||
movl %eax,loader_eax
|
||||
movl %ebx,loader_ebx
|
||||
|
||||
/* Clear the bss */
|
||||
cld
|
||||
movl $.bss, %edi
|
||||
movl $_end, %ecx
|
||||
subl %edi, %ecx
|
||||
xor %ax, %ax
|
||||
rep stosb
|
||||
|
||||
/* Setup new stack. */
|
||||
movl $_stack, %ebx
|
||||
|
||||
movl %ebx, %esp
|
||||
|
||||
/* Save old stack pointer. */
|
||||
pushl %esi
|
||||
|
||||
/* Let's rock. */
|
||||
call start_main
|
||||
|
||||
/* %eax has the return value - pass it on unmolested */
|
||||
_leave:
|
||||
/* Get old stack pointer. */
|
||||
popl %ebx
|
||||
|
||||
/* Restore old stack. */
|
||||
movl %ebx, %esp
|
||||
|
||||
/* Return to the original context. */
|
||||
ret
|
73
payloads/libpayload/arch/x86/main.c
Normal file
73
payloads/libpayload/arch/x86/main.c
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* This file is part of the libpayload project.
|
||||
*
|
||||
* Copyright (C) 2008 Advanced Micro Devices, Inc.
|
||||
*
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* 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 <libpayload.h>
|
||||
|
||||
unsigned long loader_eax; /**< The value of EAX passed from the loader */
|
||||
unsigned long loader_ebx; /**< The value of EBX passed from the loader */
|
||||
|
||||
unsigned int main_argc; /**< The argc value to pass to main() */
|
||||
|
||||
/** The argv value to pass to main() */
|
||||
char *main_argv[MAX_ARGC_COUNT];
|
||||
|
||||
/**
|
||||
* This is our C entry function - set up the system
|
||||
* and jump into the payload entry point.
|
||||
*/
|
||||
void start_main(void);
|
||||
void start_main(void)
|
||||
{
|
||||
extern int main(int argc, char **argv);
|
||||
|
||||
/* Gather system information. */
|
||||
lib_get_sysinfo();
|
||||
|
||||
/* Optionally set up the consoles. */
|
||||
#ifndef CONFIG_SKIP_CONSOLE_INIT
|
||||
console_init();
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Any other system init that has to happen before the
|
||||
* user gets control goes here.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Go to the entry point.
|
||||
* In the future we may care about the return value.
|
||||
*/
|
||||
|
||||
(void) main(main_argc, (main_argc != 0) ? main_argv : NULL);
|
||||
|
||||
/*
|
||||
* Returning here will go to the _leave function to return
|
||||
* us to the original context.
|
||||
*/
|
||||
}
|
103
payloads/libpayload/arch/x86/multiboot.c
Normal file
103
payloads/libpayload/arch/x86/multiboot.c
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* This file is part of the libpayload project.
|
||||
*
|
||||
* Copyright (C) 2008 Advanced Micro Devices, Inc.
|
||||
*
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* 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 <libpayload-config.h>
|
||||
#include <libpayload.h>
|
||||
#include <multiboot_tables.h>
|
||||
|
||||
extern unsigned long loader_eax;
|
||||
extern unsigned long loader_ebx;
|
||||
|
||||
static void mb_parse_mmap(struct multiboot_header *table,
|
||||
struct sysinfo_t *info)
|
||||
{
|
||||
u8 *start = (u8 *) phys_to_virt(table->mmap_addr);
|
||||
u8 *ptr = start;
|
||||
|
||||
info->n_memranges = 0;
|
||||
|
||||
while(ptr < (start + table->mmap_length)) {
|
||||
struct multiboot_mmap *mmap = (struct multiboot_mmap *) ptr;
|
||||
|
||||
#ifdef CONFIG_MEMMAP_RAM_ONLY
|
||||
/* 1 == normal RAM. Ignore everything else for now */
|
||||
|
||||
if (mmap->type == 1) {
|
||||
#endif
|
||||
info->memrange[info->n_memranges].base = mmap->addr;
|
||||
info->memrange[info->n_memranges].size = mmap->length;
|
||||
info->memrange[info->n_memranges].type = mmap->type;
|
||||
|
||||
if (++info->n_memranges == SYSINFO_MAX_MEM_RANGES)
|
||||
return;
|
||||
#ifdef CONFIG_MEMMAP_RAM_ONLY
|
||||
}
|
||||
#endif
|
||||
|
||||
ptr += (mmap->size + sizeof(mmap->size));
|
||||
}
|
||||
}
|
||||
|
||||
static void mb_parse_cmdline(struct multiboot_header *table)
|
||||
{
|
||||
extern int main_argc;
|
||||
extern char *main_argv[];
|
||||
char *c = phys_to_virt(table->cmdline);
|
||||
|
||||
while(*c != '\0' && main_argc < MAX_ARGC_COUNT) {
|
||||
main_argv[main_argc++] = c;
|
||||
|
||||
for( ; *c != '\0' && !isspace(*c); c++);
|
||||
|
||||
if (*c) {
|
||||
*c = 0;
|
||||
c++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int get_multiboot_info(struct sysinfo_t *info)
|
||||
{
|
||||
struct multiboot_header *table;
|
||||
|
||||
if (loader_eax != MULTIBOOT_MAGIC)
|
||||
return -1;
|
||||
|
||||
table = (struct multiboot_header *) phys_to_virt(loader_ebx);
|
||||
|
||||
info->mbtable = phys_to_virt(loader_ebx);
|
||||
|
||||
if (table->flags & MULTIBOOT_FLAGS_MMAP)
|
||||
mb_parse_mmap(table, info);
|
||||
|
||||
if (table->flags & MULTIBOOT_FLAGS_CMDLINE)
|
||||
mb_parse_cmdline(table);
|
||||
|
||||
return 0;
|
||||
}
|
103
payloads/libpayload/arch/x86/string.c
Normal file
103
payloads/libpayload/arch/x86/string.c
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (C) 1991,1992,1993,1997,1998,2003, 2005 Free Software Foundation, Inc.
|
||||
* This file is part of the GNU C Library.
|
||||
* Copyright (c) 2011 The Chromium OS Authors.
|
||||
*
|
||||
* See file CREDITS for list of people who contributed to this
|
||||
* project.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/* From glibc-2.14, sysdeps/i386/memset.c */
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "string.h"
|
||||
|
||||
typedef uint32_t op_t;
|
||||
|
||||
void *memset(void *dstpp, int c, size_t len)
|
||||
{
|
||||
int d0;
|
||||
unsigned long int dstp = (unsigned long int) dstpp;
|
||||
|
||||
/* This explicit register allocation improves code very much indeed. */
|
||||
register op_t x asm("ax");
|
||||
|
||||
x = (unsigned char) c;
|
||||
|
||||
/* Clear the direction flag, so filling will move forward. */
|
||||
asm volatile("cld");
|
||||
|
||||
/* This threshold value is optimal. */
|
||||
if (len >= 12) {
|
||||
/* Fill X with four copies of the char we want to fill with. */
|
||||
x |= (x << 8);
|
||||
x |= (x << 16);
|
||||
|
||||
/* Adjust LEN for the bytes handled in the first loop. */
|
||||
len -= (-dstp) % sizeof(op_t);
|
||||
|
||||
/*
|
||||
* There are at least some bytes to set. No need to test for
|
||||
* LEN == 0 in this alignment loop.
|
||||
*/
|
||||
|
||||
/* Fill bytes until DSTP is aligned on a longword boundary. */
|
||||
asm volatile(
|
||||
"rep\n"
|
||||
"stosb" /* %0, %2, %3 */ :
|
||||
"=D" (dstp), "=c" (d0) :
|
||||
"0" (dstp), "1" ((-dstp) % sizeof(op_t)), "a" (x) :
|
||||
"memory");
|
||||
|
||||
/* Fill longwords. */
|
||||
asm volatile(
|
||||
"rep\n"
|
||||
"stosl" /* %0, %2, %3 */ :
|
||||
"=D" (dstp), "=c" (d0) :
|
||||
"0" (dstp), "1" (len / sizeof(op_t)), "a" (x) :
|
||||
"memory");
|
||||
len %= sizeof(op_t);
|
||||
}
|
||||
|
||||
/* Write the last few bytes. */
|
||||
asm volatile(
|
||||
"rep\n"
|
||||
"stosb" /* %0, %2, %3 */ :
|
||||
"=D" (dstp), "=c" (d0) :
|
||||
"0" (dstp), "1" (len), "a" (x) :
|
||||
"memory");
|
||||
|
||||
return dstpp;
|
||||
}
|
||||
|
||||
void *memcpy(void *dest, const void *src, size_t n)
|
||||
{
|
||||
unsigned long d0, d1, d2;
|
||||
|
||||
asm volatile(
|
||||
"rep ; movsl\n\t"
|
||||
"movl %4,%%ecx\n\t"
|
||||
"rep ; movsb\n\t"
|
||||
: "=&c" (d0), "=&D" (d1), "=&S" (d2)
|
||||
: "0" (n >> 2), "g" (n & 3), "1" (dest), "2" (src)
|
||||
: "memory"
|
||||
);
|
||||
|
||||
return dest;
|
||||
}
|
80
payloads/libpayload/arch/x86/sysinfo.c
Normal file
80
payloads/libpayload/arch/x86/sysinfo.c
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* This file is part of the libpayload project.
|
||||
*
|
||||
* Copyright (C) 2008 Advanced Micro Devices, Inc.
|
||||
*
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* 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 <libpayload-config.h>
|
||||
#include <libpayload.h>
|
||||
#include <coreboot_tables.h>
|
||||
#include <multiboot_tables.h>
|
||||
|
||||
/**
|
||||
* This is a global structure that is used through the library - we set it
|
||||
* up initially with some dummy values - hopefully they will be overridden.
|
||||
*/
|
||||
struct sysinfo_t lib_sysinfo = {
|
||||
.cpu_khz = 200,
|
||||
#ifdef CONFIG_SERIAL_CONSOLE
|
||||
.ser_ioport = CONFIG_SERIAL_IOBASE,
|
||||
#else
|
||||
.ser_ioport = 0x3f8,
|
||||
#endif
|
||||
};
|
||||
|
||||
int lib_get_sysinfo(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Get the CPU speed (for delays). */
|
||||
lib_sysinfo.cpu_khz = get_cpu_speed();
|
||||
|
||||
#ifdef CONFIG_MULTIBOOT
|
||||
/* Get the information from the multiboot tables,
|
||||
* if they exist */
|
||||
get_multiboot_info(&lib_sysinfo);
|
||||
#endif
|
||||
|
||||
/* Get information from the coreboot tables,
|
||||
* if they exist */
|
||||
|
||||
ret = get_coreboot_info(&lib_sysinfo);
|
||||
|
||||
if (!lib_sysinfo.n_memranges) {
|
||||
/* If we can't get a good memory range, use the default. */
|
||||
lib_sysinfo.n_memranges = 2;
|
||||
|
||||
lib_sysinfo.memrange[0].base = 0;
|
||||
lib_sysinfo.memrange[0].size = 640 * 1024;
|
||||
lib_sysinfo.memrange[0].type = CB_MEM_RAM;
|
||||
|
||||
lib_sysinfo.memrange[1].base = 1024 * 1024;
|
||||
lib_sysinfo.memrange[1].size = 31 * 1024 * 1024;
|
||||
lib_sysinfo.memrange[1].type = CB_MEM_RAM;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
124
payloads/libpayload/arch/x86/timer.c
Normal file
124
payloads/libpayload/arch/x86/timer.c
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* This file is part of the libpayload project.
|
||||
*
|
||||
* Copyright (C) 2008 Advanced Micro Devices, Inc.
|
||||
*
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file i386/timer.c
|
||||
* i386 specific timer routines
|
||||
*/
|
||||
|
||||
#include <libpayload.h>
|
||||
#include <arch/rdtsc.h>
|
||||
|
||||
/**
|
||||
* @ingroup arch
|
||||
* Global variable containing the speed of the processor in KHz.
|
||||
*/
|
||||
u32 cpu_khz;
|
||||
|
||||
/**
|
||||
* Calculate the speed of the processor for use in delays.
|
||||
*
|
||||
* @return The CPU speed in kHz.
|
||||
*/
|
||||
unsigned int get_cpu_speed(void)
|
||||
{
|
||||
unsigned long long start, end;
|
||||
|
||||
/* Set up the PPC port - disable the speaker, enable the T2 gate. */
|
||||
outb((inb(0x61) & ~0x02) | 0x01, 0x61);
|
||||
|
||||
/* Set the PIT to Mode 0, counter 2, word access. */
|
||||
outb(0xB0, 0x43);
|
||||
|
||||
/* Load the counter with 0xffff. */
|
||||
outb(0xff, 0x42);
|
||||
outb(0xff, 0x42);
|
||||
|
||||
/* Read the number of ticks during the period. */
|
||||
start = rdtsc();
|
||||
while (!(inb(0x61) & 0x20)) ;
|
||||
end = rdtsc();
|
||||
|
||||
/*
|
||||
* The clock rate is 1193180 Hz, the number of milliseconds for a
|
||||
* period of 0xffff is 1193180 / (0xFFFF * 1000) or .0182.
|
||||
* Multiply that by the number of measured clocks to get the kHz value.
|
||||
*/
|
||||
cpu_khz = (unsigned int)((end - start) * 1193180U / (1000 * 0xffff));
|
||||
|
||||
return cpu_khz;
|
||||
}
|
||||
|
||||
static inline void _delay(unsigned long long delta)
|
||||
{
|
||||
unsigned long long timeout = rdtsc() + delta;
|
||||
while (rdtsc() < timeout) ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delay for a specified number of nanoseconds.
|
||||
*
|
||||
* @param n Number of nanoseconds to delay for.
|
||||
*/
|
||||
void ndelay(unsigned int n)
|
||||
{
|
||||
_delay((unsigned long long)n * cpu_khz / 1000000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delay for a specified number of microseconds.
|
||||
*
|
||||
* @param n Number of microseconds to delay for.
|
||||
*/
|
||||
void udelay(unsigned int n)
|
||||
{
|
||||
_delay((unsigned long long)n * cpu_khz / 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delay for a specified number of milliseconds.
|
||||
*
|
||||
* @param m Number of milliseconds to delay for.
|
||||
*/
|
||||
void mdelay(unsigned int m)
|
||||
{
|
||||
_delay((unsigned long long)m * cpu_khz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delay for a specified number of seconds.
|
||||
*
|
||||
* @param s Number of seconds to delay for.
|
||||
*/
|
||||
void delay(unsigned int s)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<1000; i++)
|
||||
_delay((unsigned long long)s * cpu_khz);
|
||||
}
|
38
payloads/libpayload/arch/x86/util.S
Normal file
38
payloads/libpayload/arch/x86/util.S
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* This file is part of the libpayload project.
|
||||
*
|
||||
* Copyright (C) 2008 Advanced Micro Devices, Inc.
|
||||
*
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.global halt
|
||||
.text
|
||||
.align 4
|
||||
|
||||
/* This function puts the system into a halt. */
|
||||
halt:
|
||||
cli
|
||||
hlt
|
||||
jmp halt
|
38
payloads/libpayload/arch/x86/virtual.c
Normal file
38
payloads/libpayload/arch/x86/virtual.c
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* This file is part of the libpayload project.
|
||||
*
|
||||
* Copyright (C) 2008 coresystems GmbH
|
||||
*
|
||||
* 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. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* 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 <unistd.h>
|
||||
|
||||
unsigned long virtual_offset = 0;
|
||||
|
||||
|
||||
int getpagesize(void)
|
||||
{
|
||||
return 4096;
|
||||
}
|
Reference in New Issue
Block a user