Bring Intel/HP efi source into project, remove gnu-efi

This commit is contained in:
Justin C. Miller
2018-05-05 14:13:38 -07:00
parent b2f2a9c721
commit bc6a42735c
62 changed files with 13249 additions and 43 deletions

View File

@@ -1,5 +1,4 @@
#include <efi.h>
#include <efilib.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>

View File

@@ -1,6 +1,6 @@
#pragma once
#include <efi.h>
#include <stddef.h>
#include <efi/efi.h>
EFI_STATUS con_initialize(EFI_SYSTEM_TABLE *system_table, const CHAR16 *version);
void con_status_begin(const CHAR16 *message);

85
src/boot/crt0.s Normal file
View File

@@ -0,0 +1,85 @@
; crt0-efi-x86_64.S - x86_64 EFI startup code.
; Copyright (C) 1999 Hewlett-Packard Co.
; Contributed by David Mosberger <davidm@hpl.hp.com>.
; Copyright (C) 2005 Intel Co.
; Contributed by Fenghua Yu <fenghua.yu@intel.com>.
;
; All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions
; are met:
;
; * Redistributions of source code must retain the above copyright
; notice, this list of conditions and the following disclaimer.
; * 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.
; * Neither the name of Hewlett-Packard Co. 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER OR CONTRIBUTORS
; BE LIABLE FOR ANYDIRECT, 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.
;
; 2018-05-05 Converted to NASM syntax by Justin C. Miller
extern ImageBase
extern _DYNAMIC
extern _relocate
extern efi_main
section .text
align 4
global _start
_start:
sub rsp, 8
push rcx
push rdx
; These are already in RDI/RSI from EFI calling us, right? -justin
;lea rdi, [ImageBase]
;lea rsi, [_DYNAMIC]
pop rcx
pop rdx
push rcx
push rdx
call _relocate
pop rdi
pop rsi
call efi_main
add rsp, 8
.exit:
ret
; hand-craft a dummy .reloc section so EFI knows it's a relocatable executable:
section .data
dummy:
dd 0
%define IMAGE_REL_ABSOLUTE 0
section .reloc
label1:
dd 0 ; Page RVA
dd 10 ; Block Size (2*4+2)
dw (IMAGE_REL_ABSOLUTE<<12) + 0 ; reloc for dummy

View File

@@ -1,5 +1,5 @@
#pragma once
#include <efi.h>
#include <efi/efi.h>
int is_guid(EFI_GUID *a, EFI_GUID *b);

View File

@@ -1,5 +1,5 @@
#pragma once
#include <efi.h>
#include <efi/efi.h>
#include <stddef.h>
#define PAGE_SIZE 0x1000

View File

@@ -1,8 +1,8 @@
#include <efi.h>
#include <efilib.h>
#include <stdalign.h>
#include <stddef.h>
#include <efi/efi.h>
#include "console.h"
#include "guids.h"
#include "kernel_data.h"

View File

@@ -1,5 +1,3 @@
#include <efi.h>
#include <efilib.h>
#include <stddef.h>
#include "loader.h"

View File

@@ -1,5 +1,5 @@
#pragma once
#include <efi.h>
#include <efi/efi.h>
struct memory_map {
size_t length;

96
src/boot/reloc.c Normal file
View File

@@ -0,0 +1,96 @@
/* reloc_x86_64.c - position independent x86_64 ELF shared object relocator
Copyright (C) 1999 Hewlett-Packard Co.
Contributed by David Mosberger <davidm@hpl.hp.com>.
Copyright (C) 2005 Intel Co.
Contributed by Fenghua Yu <fenghua.yu@intel.com>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* 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.
* Neither the name of Hewlett-Packard Co. 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANYDIRECT, 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 <efi/efi.h>
#include <elf.h>
EFI_STATUS _relocate (long ldbase, Elf64_Dyn *dyn,
EFI_HANDLE image EFI_UNUSED,
EFI_SYSTEM_TABLE *systab EFI_UNUSED)
{
long relsz = 0, relent = 0;
Elf64_Rel *rel = 0;
unsigned long *addr;
int i;
for (i = 0; dyn[i].d_tag != DT_NULL; ++i) {
switch (dyn[i].d_tag) {
case DT_RELA:
rel = (Elf64_Rel*)
((unsigned long)dyn[i].d_un.d_ptr
+ ldbase);
break;
case DT_RELASZ:
relsz = dyn[i].d_un.d_val;
break;
case DT_RELAENT:
relent = dyn[i].d_un.d_val;
break;
default:
break;
}
}
if (!rel && relent == 0)
return EFI_SUCCESS;
if (!rel || relent == 0)
return EFI_LOAD_ERROR;
while (relsz > 0) {
/* apply the relocs */
switch (ELF64_R_TYPE (rel->r_info)) {
case R_X86_64_NONE:
break;
case R_X86_64_RELATIVE:
addr = (unsigned long *)
(ldbase + rel->r_offset);
*addr += ldbase;
break;
default:
break;
}
rel = (Elf64_Rel*) ((char *) rel + relent);
relsz -= relent;
}
return EFI_SUCCESS;
}

View File

@@ -1,7 +1,7 @@
#include "console.h"
#include <efi.h>
#include <efilib.h>
#include <stddef.h>
#include <efi/efi.h>
#include "console.h"
#define UNUSED __attribute__((unused))

View File

@@ -2,23 +2,8 @@
def configure(ctx):
from os.path import join
efi_dir = join(ctx.env.EXTERNAL, "gnu-efi")
ctx.env.EFI_DIR = efi_dir
lds_path = join(ctx.env.ARCH_D, "boot.ld")
efi_inc = join(efi_dir, "inc")
efi_arch = join(efi_dir, ctx.env.POPCORN_ARCH)
crt0_name = 'crt0-efi-{}.o'.format(ctx.env.POPCORN_ARCH)
crt0_path = join(efi_arch, "gnuefi", crt0_name)
lds_name = 'elf_{}_efi.lds'.format(ctx.env.POPCORN_ARCH)
lds_path = join(efi_dir, "gnuefi", lds_name)
ctx.env.append_value('INCLUDES_EFI', [
efi_inc,
join(efi_inc, "protocol"),
join(efi_inc, ctx.env.POPCORN_ARCH),
])
ctx.env.append_value('DEFINES_EFI', [
'KERNEL_FILENAME=L"{}"'.format(ctx.env.KERNEL_FILENAME),
'GNU_EFI_USE_MS_ABI',
@@ -27,12 +12,9 @@ def configure(ctx):
'EFI_DEBUG_CLEAR_MEMORY=0',
])
ctx.env.append_value('CFLAGS_EFI', ['-fPIC', '-fshort-wchar', '-Wa,--no-warn'])
ctx.env.append_value('STLIB_EFI', ['efi', 'gnuefi'])
ctx.env.append_value('STLIBPATH_EFI', [join(efi_arch, "lib"), join(efi_arch, "gnuefi")])
ctx.env.append_value('LINKFLAGS_EFI', [
'-shared',
'-T', lds_path,
crt0_path,
])
ctx.env.append_value('SECTIONS_EFI', [
"-j .text",
@@ -46,13 +28,8 @@ def configure(ctx):
])
def build(bld):
bld(rule = "make -C ${EFI_DIR} > /dev/null")
bld.add_group()
import os
sources = [f for f in os.listdir(str(bld.path))
if f.endswith('.c')
or f.endswith('.s')]
sources = bld.path.ant_glob("**/*.c")
sources += bld.path.ant_glob("**/*.s")
bld.program(
source = sources,