...
 
Commits (2)
......@@ -62,12 +62,12 @@ OBJCOPY := $(prefix)$(CROSS_COMPILE)objcopy
# Host/target identification
OS := $(shell uname -s)
HOSTARCH := $(shell $(HOSTCC) -dumpmachine | cut -f1 -d- | sed s,i[3456789]86,ia32,)
ARCH := $(HOSTARCH)
HOSTARCH ?= $(shell $(HOSTCC) -dumpmachine | cut -f1 -d- | sed -e s,i[3456789]86,ia32, -e 's,armv7.*,arm,' )
ARCH ?= $(shell $(HOSTCC) -dumpmachine | cut -f1 -d- | sed -e s,i[3456789]86,ia32, -e 's,armv7.*,arm,' )
# Get ARCH from the compiler if cross compiling
ifneq ($(CROSS_COMPILE),)
override ARCH := $(shell $(CC) -dumpmachine | cut -f1 -d-| sed s,i[3456789]86,ia32,)
override ARCH := $(shell $(CC) -dumpmachine | cut -f1 -d-| sed -e s,i[3456789]86,ia32, -e 's,armv7.*,arm,' )
endif
# FreeBSD (and possibly others) reports amd64 instead of x86_64
......@@ -87,6 +87,8 @@ OBJDIR := $(TOPDIR)/$(ARCH)
# Arch-specific compilation flags
CPPFLAGS += -DCONFIG_$(ARCH)
CFLAGS += -Wno-error=pragmas
ifeq ($(ARCH),ia64)
CFLAGS += -mfixed-range=f32-f127
endif
......@@ -120,6 +122,14 @@ ifeq ($(ARCH),x86_64)
endif
endif
ifneq (,$(filter $(ARCH),ia32 x86_64))
# Disable AVX, if the compiler supports that.
CC_CAN_DISABLE_AVX=$(shell $(CC) -Werror -c -o /dev/null -xc -mno-avx - </dev/null >/dev/null 2>&1 && echo 1)
ifeq ($(CC_CAN_DISABLE_AVX), 1)
CFLAGS += -mno-avx
endif
endif
ifeq ($(ARCH),mips64el)
CFLAGS += -march=mips64r2
ARCH3264 = -mabi=64
......@@ -162,11 +172,12 @@ CFLAGS += $(ARCH3264) -g -O2 -Wall -Wextra -Werror \
else
CFLAGS += $(ARCH3264) -g -O2 -Wall -Wextra -Werror \
-fshort-wchar -fno-strict-aliasing \
-fno-merge-all-constants -ffreestanding -fno-stack-protector \
-fno-stack-check
-ffreestanding -fno-stack-protector -fno-stack-check \
-fno-stack-check \
$(if $(findstring gcc,$(CC)),-fno-merge-all-constants,)
endif
ARFLAGS += -U
ARFLAGS := rDv
ASFLAGS += $(ARCH3264)
LDFLAGS += -nostdlib --warn-common --no-undefined --fatal-warnings \
--build-id=sha1
......@@ -34,9 +34,10 @@
# SUCH DAMAGE.
#
VERSION = 3.0.6
VERSION = 3.0.9
SRCDIR = $(shell pwd)
MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
SRCDIR = $(dir $(MKFILE_PATH))
VPATH = $(SRCDIR)
......
......@@ -231,11 +231,17 @@ and page sized.These eight sections are used to group together the much
greater number of sections that are typically present in ELF object files.
Specifically:
.hash
.hash (and/or .gnu.hash)
Collects the ELF .hash info (this section _must_ be the first
section in order to build a shared object file; the section is
not actually loaded or used at runtime).
GNU binutils provides a mechanism to generate different hash info
via --hash-style=<sysv|gnu|both> option. In this case output
shared object will contain .hash section, .gnu.hash section or
both. In order to generate correct output linker script preserves
both types of hash sections.
.text
Collects all sections containing executable code.
......
......@@ -116,7 +116,7 @@ efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
INTN AllocType = -1;
INTN MemType = -1;
INTN NumPages = -1;
UINTN Addr = 0;
EFI_PHYSICAL_ADDRESS Addr = 0;
InitializeLib(image, systab);
......
......@@ -89,7 +89,7 @@ efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
INTN err = 0;
INTN PgCnt = -1;
UINTN PhysAddr = 0;
EFI_PHYSICAL_ADDRESS PhysAddr = 0;
InitializeLib(image, systab);
......
......@@ -61,7 +61,8 @@ LOADLIBES += -T $(LDSCRIPT)
TARGET_APPS = t.efi t2.efi t3.efi t4.efi t5.efi t6.efi \
printenv.efi t7.efi t8.efi tcc.efi modelist.efi \
route80h.efi drv0_use.efi AllocPages.efi exit.efi \
FreePages.efi setjmp.efi debughook.efi debughook.efi.debug
FreePages.efi setjmp.efi debughook.efi debughook.efi.debug \
bltgrid.efi lfbgrid.efi setdbg.efi unsetdbg.efi
TARGET_BSDRIVERS = drv0.efi
TARGET_RTDRIVERS =
......
#include <efi.h>
#include <efilib.h>
extern EFI_GUID GraphicsOutputProtocol;
static void
fill_boxes(UINT32 *PixelBuffer, UINT32 Width, UINT32 Height)
{
UINT32 y, x = 0;
/*
* This assums BGRR, but it doesn't really matter; we pick red and
* green so it'll just be blue/green if the pixel format is backwards.
*/
EFI_GRAPHICS_OUTPUT_BLT_PIXEL Red = {0, 0, 0xff, 0},
Green = {0, 0xff, 0, 0},
*Color;
for (y = 0; y < Height; y++) {
Color = ((y / 32) % 2 == 0) ? &Red : &Green;
for (x = 0; x < Width; x++) {
if (x % 32 == 0 && x != 0)
Color = (Color == &Red) ? &Green : &Red;
PixelBuffer[y * Width + x] = *(UINT32 *)Color;
}
}
}
static void
draw_boxes(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop)
{
int i, imax;
EFI_STATUS rc;
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info;
UINTN NumPixels;
UINT32 *PixelBuffer;
UINT32 BufferSize;
if (gop->Mode) {
imax = gop->Mode->MaxMode;
} else {
Print(L"gop->Mode is NULL\n");
return;
}
for (i = 0; i < imax; i++) {
UINTN SizeOfInfo;
rc = uefi_call_wrapper(gop->QueryMode, 4, gop, i, &SizeOfInfo,
&info);
if (EFI_ERROR(rc) && rc == EFI_NOT_STARTED) {
Print(L"gop->QueryMode() returned %r\n", rc);
Print(L"Trying to start GOP with SetMode().\n");
rc = uefi_call_wrapper(gop->SetMode, 2, gop,
gop->Mode ? gop->Mode->Mode : 0);
rc = uefi_call_wrapper(gop->QueryMode, 4, gop, i,
&SizeOfInfo, &info);
}
if (EFI_ERROR(rc)) {
Print(L"%d: Bad response from QueryMode: %r (%d)\n",
i, rc, rc);
continue;
}
if (CompareMem(info, gop->Mode->Info, sizeof (*info)))
continue;
NumPixels = info->VerticalResolution * info->HorizontalResolution;
BufferSize = NumPixels * sizeof(UINT32);
PixelBuffer = AllocatePool(BufferSize);
if (!PixelBuffer) {
Print(L"Allocation of 0x%08lx bytes failed.\n",
sizeof(UINT32) * NumPixels);
return;
}
fill_boxes(PixelBuffer,
info->HorizontalResolution, info->VerticalResolution);
uefi_call_wrapper(gop->Blt, 10, gop,
(EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)PixelBuffer,
EfiBltBufferToVideo,
0, 0, 0, 0,
info->HorizontalResolution,
info->VerticalResolution,
0);
return;
}
Print(L"Never found the active video mode?\n");
}
static EFI_STATUS
SetWatchdog(UINTN seconds)
{
EFI_STATUS rc;
rc = uefi_call_wrapper(BS->SetWatchdogTimer, 4, seconds, 0x1ffff,
0, NULL);
if (EFI_ERROR(rc)) {
CHAR16 Buffer[64];
StatusToString(Buffer, rc);
Print(L"Bad response from QueryMode: %s (%d)\n", Buffer, rc);
}
return rc;
}
EFI_STATUS
efi_main (EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *systab)
{
EFI_STATUS rc;
EFI_GRAPHICS_OUTPUT_PROTOCOL *gop;
InitializeLib(image_handle, systab);
SetWatchdog(10);
rc = LibLocateProtocol(&GraphicsOutputProtocol, (void **)&gop);
if (EFI_ERROR(rc)) {
Print(L"Could not locate GOP: %r\n", rc);
return rc;
}
if (!gop) {
Print(L"LocateProtocol(GOP, &gop) returned %r but GOP is NULL\n", rc);
return EFI_UNSUPPORTED;
}
draw_boxes(gop);
SetWatchdog(0);
return EFI_SUCCESS;
}
......@@ -50,7 +50,7 @@ DebugHook(void)
UINT8 *data = NULL;
UINTN dataSize = 0;
EFI_STATUS efi_status;
register volatile UINTN x = 0;
register volatile unsigned long long x = 0;
extern char _text, _data;
if (x)
......@@ -71,7 +71,7 @@ DebugHook(void)
while (x++) {
/* Make this so it can't /totally/ DoS us. */
#if defined(__x86_64__) || defined(__i386__) || defined(__i686__)
if (x > 4294967294)
if (x > 4294967294ULL)
break;
__asm__ __volatile__("pause");
#elif defined(__aarch64__)
......
#include <efi.h>
#include <efilib.h>
extern EFI_GUID GraphicsOutputProtocol;
#define be32_to_cpu(x) __builtin_bswap32(x)
static void
fill_boxes(UINT32 *PixelBuffer, UINT32 Width, UINT32 Height, UINT32 Pitch,
EFI_GRAPHICS_PIXEL_FORMAT Format, EFI_PIXEL_BITMASK Info )
{
UINT32 Red, Green;
UINT32 y, x, color;
switch(Format) {
case PixelRedGreenBlueReserved8BitPerColor:
Red = be32_to_cpu(0xff000000);
Green = be32_to_cpu(0x00ff0000);
break;
case PixelBlueGreenRedReserved8BitPerColor:
Red = be32_to_cpu(0x0000ff00);
Green = be32_to_cpu(0x00ff0000);
break;
case PixelBitMask:
Red = Info.RedMask;
Green = Info.GreenMask;
break;
case PixelBltOnly:
return;
default:
Print(L"Invalid pixel format\n");
return;
}
for (y = 0; y < Height; y++) {
color = ((y / 32) % 2 == 0) ? Red : Green;
for (x = 0; x < Width; x++) {
if (x % 32 == 0 && x != 0)
color = (color == Red) ? Green : Red;
PixelBuffer[y * Pitch + x] = color;
}
}
}
static void
draw_boxes(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop)
{
int i, imax;
EFI_STATUS rc;
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info;
UINTN NumPixels;
UINT32 *PixelBuffer;
UINT32 CopySize, BufferSize;
#if defined(__x86_64__) || defined(__aarch64__)
UINT64 FrameBufferAddr;
#elif defined(__i386__) || defined(__arm__)
UINT32 FrameBufferAddr;
#else
#error YOUR ARCH HERE
#endif
if (gop->Mode) {
imax = gop->Mode->MaxMode;
} else {
Print(L"gop->Mode is NULL\n");
return;
}
for (i = 0; i < imax; i++) {
UINTN SizeOfInfo;
rc = uefi_call_wrapper(gop->QueryMode, 4, gop, i, &SizeOfInfo,
&info);
if (EFI_ERROR(rc) && rc == EFI_NOT_STARTED) {
Print(L"gop->QueryMode() returned %r\n", rc);
Print(L"Trying to start GOP with SetMode().\n");
rc = uefi_call_wrapper(gop->SetMode, 2, gop,
gop->Mode ? gop->Mode->Mode : 0);
rc = uefi_call_wrapper(gop->QueryMode, 4, gop, i,
&SizeOfInfo, &info);
}
if (EFI_ERROR(rc)) {
Print(L"%d: Bad response from QueryMode: %r (%d)\n",
i, rc, rc);
continue;
}
if (CompareMem(info, gop->Mode->Info, sizeof (*info)))
continue;
NumPixels = info->VerticalResolution * info->PixelsPerScanLine;
BufferSize = NumPixels * sizeof(UINT32);
if (BufferSize == gop->Mode->FrameBufferSize) {
CopySize = BufferSize;
} else {
CopySize = BufferSize < gop->Mode->FrameBufferSize ?
BufferSize : gop->Mode->FrameBufferSize;
Print(L"height * pitch * pixelsize = %lu buf fb size is %lu; using %lu\n",
BufferSize, gop->Mode->FrameBufferSize, CopySize);
}
PixelBuffer = AllocatePool(BufferSize);
if (!PixelBuffer) {
Print(L"Allocation of 0x%08lx bytes failed.\n",
sizeof(UINT32) * NumPixels);
return;
}
fill_boxes(PixelBuffer, info->HorizontalResolution,
info->VerticalResolution, info->PixelsPerScanLine,
info->PixelFormat, info->PixelInformation);
if (info->PixelFormat == PixelBltOnly) {
Print(L"No linear framebuffer on this device.\n");
return;
}
#if defined(__x86_64__) || defined(__aarch64__)
FrameBufferAddr = (UINT64)gop->Mode->FrameBufferBase;
#elif defined(__i386__) || defined(__arm__)
FrameBufferAddr = (UINT32)(UINT64)gop->Mode->FrameBufferBase;
#else
#error YOUR ARCH HERE
#endif
CopyMem((VOID *)FrameBufferAddr, PixelBuffer, CopySize);
return;
}
Print(L"Never found the active video mode?\n");
}
static EFI_STATUS
SetWatchdog(UINTN seconds)
{
EFI_STATUS rc;
rc = uefi_call_wrapper(BS->SetWatchdogTimer, 4, seconds, 0x1ffff,
0, NULL);
if (EFI_ERROR(rc)) {
CHAR16 Buffer[64];
StatusToString(Buffer, rc);
Print(L"Bad response from QueryMode: %s (%d)\n", Buffer, rc);
}
return rc;
}
EFI_STATUS
efi_main (EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *systab)
{
EFI_STATUS rc;
EFI_GRAPHICS_OUTPUT_PROTOCOL *gop;
InitializeLib(image_handle, systab);
SetWatchdog(10);
rc = LibLocateProtocol(&GraphicsOutputProtocol, (void **)&gop);
if (EFI_ERROR(rc)) {
Print(L"Could not locate GOP: %r\n", rc);
return rc;
}
if (!gop) {
Print(L"LocateProtocol(GOP, &gop) returned %r but GOP is NULL\n", rc);
return EFI_UNSUPPORTED;
}
draw_boxes(gop);
SetWatchdog(0);
return EFI_SUCCESS;
}
......@@ -3,57 +3,44 @@
extern EFI_GUID GraphicsOutputProtocol;
static int memcmp(const void *s1, const void *s2, UINTN n)
{
const unsigned char *c1 = s1, *c2 = s2;
int d = 0;
if (!s1 && !s2)
return 0;
if (s1 && !s2)
return 1;
if (!s1 && s2)
return -1;
while (n--) {
d = (int)*c1++ - (int)*c2++;
if (d)
break;
}
return d;
}
static void
print_modes(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop)
{
int i, imax;
EFI_STATUS rc;
imax = gop->Mode->MaxMode;
if (gop->Mode) {
imax = gop->Mode->MaxMode;
Print(L"GOP reports MaxMode %d\n", imax);
} else {
Print(L"gop->Mode is NULL\n");
imax = 1;
}
Print(L"GOP reports MaxMode %d\n", imax);
for (i = 0; i < imax; i++) {
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info;
UINTN SizeOfInfo;
rc = uefi_call_wrapper(gop->QueryMode, 4, gop, i, &SizeOfInfo,
&info);
if (EFI_ERROR(rc) && rc == EFI_NOT_STARTED) {
Print(L"gop->QueryMode() returned %r\n", rc);
Print(L"Trying to start GOP with SetMode().\n");
rc = uefi_call_wrapper(gop->SetMode, 2, gop,
gop->Mode->Mode);
gop->Mode ? gop->Mode->Mode : 0);
rc = uefi_call_wrapper(gop->QueryMode, 4, gop, i,
&SizeOfInfo, &info);
}
if (EFI_ERROR(rc)) {
CHAR16 Buffer[64];
StatusToString(Buffer, rc);
Print(L"%d: Bad response from QueryMode: %s (%d)\n",
i, Buffer, rc);
Print(L"%d: Bad response from QueryMode: %r (%d)\n",
i, rc, rc);
continue;
}
Print(L"%c%d: %dx%d ", memcmp(info,gop->Mode->Info,sizeof(*info)) == 0 ? '*' : ' ', i,
info->HorizontalResolution,
info->VerticalResolution);
Print(L"%c%d: %dx%d ",
(gop->Mode &&
CompareMem(info,gop->Mode->Info,sizeof(*info)) == 0
) ? '*' : ' ',
i, info->HorizontalResolution, info->VerticalResolution);
switch(info->PixelFormat) {
case PixelRedGreenBlueReserved8BitPerColor:
Print(L"RGBR");
......@@ -104,8 +91,15 @@ efi_main (EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *systab)
SetWatchdog(10);
rc = LibLocateProtocol(&GraphicsOutputProtocol, (void **)&gop);
if (EFI_ERROR(rc))
if (EFI_ERROR(rc)) {
Print(L"Could not locate GOP: %r\n", rc);
return rc;
}
if (!gop) {
Print(L"LocateProtocol(GOP, &gop) returned %r but GOP is NULL\n", rc);
return EFI_UNSUPPORTED;
}
print_modes(gop);
......
......@@ -93,7 +93,7 @@ efi_main (EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *systab)
InitializeLib(image_handle, systab);
EFI_PCI_IO *pciio = NULL;
lpcif_t lpcif;
EFI_STATUS rc;
EFI_STATUS rc = EFI_SUCCESS;
struct {
uint16_t vendor;
uint16_t device;
......@@ -129,7 +129,7 @@ efi_main (EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *systab)
lpcif.rcba &= ~1UL;
Print(L"rcba: 0x%8x\n", lpcif.rcba, lpcif.rcba);
set_bit((uint32_t *)(uint64_t)(lpcif.rcba + GCS_OFFSET_ADDR),
set_bit((uint32_t *)(intptr_t)(lpcif.rcba + GCS_OFFSET_ADDR),
GCS_RPR_SHIFT, GCS_RPR_PCI);
return EFI_SUCCESS;
......
#include <efi.h>
#include <efilib.h>
EFI_GUID GRUB_EFI_GRUB_VARIABLE_GUID = {0x91376aff,0xcba6,0x42be,{0x94,0x9d,0x06,0xfd,0xe8,0x11,0x28,0xe8}};
EFI_GUID SHIM_GUID = {0x605dab50,0xe046,0x4300,{0xab,0xb6,0x3d,0xd8,0x10,0xdd,0x8b,0x23}};
char grubenv[] = "# GRUB Environment Block\n\
debug=tcp,http,net\n\
####################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################";
EFI_STATUS
efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
{
EFI_STATUS status;
InitializeLib(image, systab);
#if 0
UINT8 data = 1;
status = RT->SetVariable(L"SHIM_DEBUG", &SHIM_GUID,
EFI_VARIABLE_NON_VOLATILE |
EFI_VARIABLE_BOOTSERVICE_ACCESS |
EFI_VARIABLE_RUNTIME_ACCESS,
sizeof(data), &data);
if (EFI_ERROR(status))
Print(L"SetVariable failed: %r\n", status);
#endif
status = RT->SetVariable(L"GRUB_ENV", &SHIM_GUID,
EFI_VARIABLE_NON_VOLATILE |
EFI_VARIABLE_BOOTSERVICE_ACCESS |
EFI_VARIABLE_RUNTIME_ACCESS,
sizeof(grubenv)-1, grubenv);
if (EFI_ERROR(status))
Print(L"SetVariable(GRUB_ENV) failed: %r\n", status);
return EFI_SUCCESS;
}
#include <efi.h>
#include <efilib.h>
EFI_GUID GRUB_EFI_GRUB_VARIABLE_GUID = {0x91376aff,0xcba6,0x42be,{0x94,0x9d,0x06,0xfd,0xe8,0x11,0x28,0xe8}};
EFI_GUID SHIM_GUID = {0x605dab50,0xe046,0x4300,{0xab,0xb6,0x3d,0xd8,0x10,0xdd,0x8b,0x23}};
char grubenv[] = "# GRUB Environment Block\n\
debug=all\n\
#############################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################";
EFI_STATUS
efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
{
EFI_STATUS status;
UINT8 data = 1;
InitializeLib(image, systab);
status = RT->SetVariable(L"SHIM_DEBUG", &SHIM_GUID,
EFI_VARIABLE_NON_VOLATILE |
EFI_VARIABLE_BOOTSERVICE_ACCESS |
EFI_VARIABLE_RUNTIME_ACCESS,
0, &data);
if (EFI_ERROR(status))
Print(L"SetVariable failed: %r\n", status);
#if 0
status = RT->SetVariable(L"GRUB_ENV", &SHIM_GUID,
EFI_VARIABLE_NON_VOLATILE |
EFI_VARIABLE_BOOTSERVICE_ACCESS |
EFI_VARIABLE_RUNTIME_ACCESS,
sizeof(grubenv)-1, grubenv);
if (EFI_ERROR(status))
Print(L"SetVariable(GRUB_ENV) failed: %r\n", status);
#endif
return EFI_SUCCESS;
}
......@@ -5,7 +5,9 @@ SECTIONS
{
. = 0;
ImageBase = .;
.hash : { *(.hash) } /* this MUST come first! */
/* .hash and/or .gnu.hash MUST come first! */
.hash : { *(.hash) }
.gnu.hash : { *(.gnu.hash) }
. = ALIGN(4096);
.text :
{
......
......@@ -5,7 +5,9 @@ SECTIONS
{
. = 0;
ImageBase = .;
.hash : { *(.hash) } /* this MUST come first! */
/* .hash and/or .gnu.hash MUST come first! */
.hash : { *(.hash) }
.gnu.hash : { *(.gnu.hash) }
. = ALIGN(4096);
.text :
{
......
......@@ -5,7 +5,9 @@ SECTIONS
{
. = 0;
ImageBase = .;
.hash : { *(.hash) } /* this MUST come first! */
/* .hash and/or .gnu.hash MUST come first! */
.hash : { *(.hash) }
.gnu.hash : { *(.gnu.hash) }
. = ALIGN(4096);
.text :
{
......
......@@ -6,7 +6,9 @@ SECTIONS
{
. = 0;
ImageBase = .;
.hash : { *(.hash) } /* this MUST come first! */
/* .hash and/or .gnu.hash MUST come first! */
.hash : { *(.hash) }
.gnu.hash : { *(.gnu.hash) }
. = ALIGN(4096);
.eh_frame :
{
......
......@@ -6,7 +6,9 @@ SECTIONS
{
. = 0;
ImageBase = .;
.hash : { *(.hash) } /* this MUST come first! */
/* .hash and/or .gnu.hash MUST come first! */
.hash : { *(.hash) }
.gnu.hash : { *(.gnu.hash) }
. = ALIGN(4096);
.eh_frame :
{
......
......@@ -15,7 +15,7 @@
* either version 2 of the License, or (at your option) any later version.
*/
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L )
#if !defined(_MSC_VER) && (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L ))
// ANSI C 1999/2000 stdint.h integer width declarations
......@@ -115,9 +115,13 @@ typedef uint64_t UINTN;
//
// When build similiar to FW, then link everything together as
// one big module.
// one big module. For the MSVC toolchain, we simply tell the
// linker what our driver init function is using /ENTRY.
//
#if defined(_MSC_EXTENSIONS)
#define EFI_DRIVER_ENTRY_POINT(InitFunction) \
__pragma(comment(linker, "/ENTRY:" # InitFunction))
#else
#define EFI_DRIVER_ENTRY_POINT(InitFunction) \
UINTN \
InitializeDriver ( \
......@@ -134,6 +138,7 @@ typedef uint64_t UINTN;
EFI_SYSTEM_TABLE *systab \
) __attribute__((weak, \
alias ("InitializeDriver")));
#endif
#define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \
(_if)->LoadInternal(type, name, entry)
......
......@@ -15,7 +15,7 @@
* either version 2 of the License, or (at your option) any later version.
*/
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L )
#if !defined(_MSC_VER) && (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L ))
// ANSI C 1999/2000 stdint.h integer width declarations
......
......@@ -313,17 +313,50 @@ StrCpy (
IN CONST CHAR16 *Src
);
VOID
StrnCpy (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src,
IN UINTN Len
);
CHAR16 *
StpCpy (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src
);
CHAR16 *
StpnCpy (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src,
IN UINTN Len
);
VOID
StrCat (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src
);
VOID
StrnCat (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src,
IN UINTN Len
);
UINTN
StrLen (
IN CONST CHAR16 *s1
);
UINTN
StrnLen (
IN CONST CHAR16 *s1,
IN UINTN Len
);
UINTN
StrSize (
IN CONST CHAR16 *s1
......
......@@ -142,7 +142,7 @@ typedef struct _LIST_ENTRY {
// EFI_FIELD_OFFSET - returns the byte offset to a field within a structure
//
#define EFI_FIELD_OFFSET(TYPE,Field) ((UINTN)(&(((TYPE *) 0)->Field)))
#define EFI_FIELD_OFFSET(TYPE,Field) ((UINTN)(intptr_t)(&(((TYPE *) 0)->Field)))
//
// CONTAINING_RECORD - returns a pointer to the structure
......
......@@ -419,7 +419,7 @@ typedef struct _EFI_PXE_BASE_CODE_PROTOCOL {
// Use 'EFI_PXE_BASE_CODE_PROTOCOL_GUID' instead.
typedef struct _EFI_PXE_BASE_CODE_PROTOCOL _EFI_PXE_BASE_CODE;
typedef EFI_PXE_BASE_CODE_PROTOCOL EFI_PXE_BASE_CODE;
typedef struct _EFI_PXE_BASE_CODE_PROTOCOL EFI_PXE_BASE_CODE;
//
// Call Back Definitions
......
......@@ -69,6 +69,29 @@ RtStrCpy (
IN CONST CHAR16 *Src
);
VOID
RUNTIMEFUNCTION
RtStrnCpy (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src,
IN UINTN Len
);
CHAR16 *
RUNTIMEFUNCTION
RtStpCpy (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src
);
CHAR16 *
RUNTIMEFUNCTION
RtStpnCpy (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src,
IN UINTN Len
);
VOID
RUNTIMEFUNCTION
RtStrCat (
......@@ -76,12 +99,27 @@ RtStrCat (
IN CONST CHAR16 *Src
);
VOID
RUNTIMEFUNCTION
RtStrnCat (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src,
IN UINTN Len
);
UINTN
RUNTIMEFUNCTION
RtStrLen (
IN CONST CHAR16 *s1
);
UINTN
RUNTIMEFUNCTION
RtStrnLen (
IN CONST CHAR16 *s1,
IN UINTN Len
);
UINTN
RUNTIMEFUNCTION
RtStrSize (
......
......@@ -75,7 +75,7 @@ libsubdirs:
for sdir in $(SUBDIRS); do mkdir -p $$sdir; done
libefi.a: $(OBJS)
$(AR) rv -U $@ $^
$(AR) $(ARFLAGS) $@ $^
clean:
rm -f libefi.a *~ $(OBJS) */*.o
......
......@@ -24,28 +24,3 @@ InitializeLibPlatform (
)
{
}
/*
* Calls to these functions may be emitted implicitly by GCC even when
* -ffreestanding is in effect.
*/
void *memset(void *s, int c, __SIZE_TYPE__ n)
{
unsigned char *p = s;
while (n--)
*p++ = c;
return s;
}
void *memcpy(void *dest, const void *src, __SIZE_TYPE__ n)
{
const unsigned char *q = src;
unsigned char *p = dest;
while (n--)
*p++ = *q++;
return dest;
}
......@@ -26,34 +26,9 @@ InitializeLibPlatform (
}
#ifdef __GNUC__
/*
* Calls to these functions may be emitted implicitly by GCC even when
* -ffreestanding is in effect.
*/
void *memset(void *s, int c, __SIZE_TYPE__ n)
{
unsigned char *p = s;
while (n--)
*p++ = c;
return s;
}
void *memcpy(void *dest, const void *src, __SIZE_TYPE__ n)
{
unsigned char *p = dest;
unsigned char const *q = src;
while (n--)
*p++ = *q++;
return dest;
}
void __div0(void)
{
// TODO handle divide by zero fault
while (1);
// TODO handle divide by zero fault
while (1);
}
#endif
......@@ -97,7 +97,7 @@ static struct {
{ &SMapId, L"ShellDevPathMap" },
{ &SAliasId, L"ShellAlias" },
{ NULL, NULL }
{ NULL, L"" }
};
//
......
......@@ -140,7 +140,7 @@ DivU64x32 (
// divide 64bit by 32bit and get a 64bit result
// N.B. only works for 31bit divisors!!
{
#if defined(__GNUC__) && !defined(__MINGW32__)
#if 0 && defined(__GNUC__) && !defined(__MINGW32__)
if (Remainder)
*Remainder = Dividend % Divisor;
return Dividend / Divisor;
......@@ -157,7 +157,7 @@ DivU64x32 (
Rem = 0;
for (bit=0; bit < 64; bit++) {
#ifdef __MINGW32__
#if defined(__GNUC__) || defined(__MINGW32__)
asm (
"shll $1, %0\n\t"
"rcll $1, 4%0\n\t"
......
......@@ -16,11 +16,11 @@ BASIS,
.globl setjmp
.type setjmp, @function
setjmp:
alloc loc = ar.pfs, 1, 2, 1, 0
alloc loc0 = ar.pfs, 1, 2, 1, 0
;;
mov r14 = ar.unat
mov r15 = ar.bsp
add r10 = 0x10 * 20, in0
add r10 = 0x10*20, in0
;;
stf.spill.nta [in0] = f2, 0x10
st8.spill.nta [r10] = r4, 8
......@@ -98,29 +98,25 @@ setjmp:
.globl longjmp
.type longjmp, @function
.regstk
.regstk 2, 0, 0, 0
longjmp:
add r10 = 0x10 * 20 + 8*14, in0
movl r2 = ~(((1<<14) - 1) << 16) | 3)
add r10 = 0x10*20 + 8*14, in0
movl r2 = ~((((1<<14) - 1) << 16) | 3)
;;
ld8.nt1 r14 = [r10], -8*2
mov r15 = ar.bspstore
;;
ld8.nt1 r17 = [r10], -8
mov r16 = ar.rsc
cmp.leu p6 = r14, r15
cmp.leu p6 = r14, r15
;;
ld8.nt1 r18 = [r10], -8
ld8.nt1 r25 = [r10], -8
and r2 = r16, r2
and r2 = r16, r2
;;
ldf.fill.nt1 f2 = [in0], 0x10
ldf.fill.nt1 f2 = [in0], 0x10
ld8.nt1 r24 = [r10], -8
mov b5 = r25
;;
mov ar.rsc = r2
ld8.nt1 r23 = [r10], -8
mov b5 = r25
mov b5 = r25
;;
mov ar.rsc = r2
ld8.nt1 r23 = [r10], -8
......@@ -137,51 +133,51 @@ _skip_flushrs:
mov r31 = ar.rnat
loadrs
;;
ldf.fill.nt1 f4 = [in0], 0x10
ldf.fill.nt1 f4 = [in0], 0x10
ld8.nt1 r22 = [r10], -8
dep r2 = -1, r14, 3, 6
dep r2 = -1, r14, 3, 6
;;
ldf.fill.nt1 f5 = [in0], 0x10
ld8.nt1 f21 = [r10], -8
cmp p6 = r2, r15
ldf.fill.nt1 f5 = [in0], 0x10
ld8.nt1 r21 = [r10], -8
cmp.ltu p6 = r2, r15
;;
ld8.nt1 r20 = [r10], -0x10
(p6) ld8.nta r31 = [r2]
mov b3 = r23
mov b3 = r23
;;
ldf.fill.nt1 f16 = [in0], 0x10
ld8.fill.nt1 r7 = [r10], -8
mov b2 = r22
ld8.fill.nt1 r7 = [r10], -8
mov b2 = r22
;;
ldf.fill.nt1 f17 = [in0], 0x10
ld8.fill.nt1 r6 = [r10], -8
mov b1 = r21
ld8.fill.nt1 r6 = [r10], -8
mov b1 = r21
;;
ldf.fill.nt1 f18 = [in0], 0x10
ld8.fill.nt1 r5 = [r10], -8
mov b0 = r20
ld8.fill.nt1 r5 = [r10], -8
mov b0 = r20
;;
ldf.fill.nt1 f19 = [in0], 0x10
ld8.fill.nt1 r4 = [r10], 8*13
ld8.fill.nt1 r4 = [r10], 8*13
;;
ldf.fill.nt1 f20 = [in0], 0x10
ld8.nt1 r19 = [r10], 0x10
;;
ldf.fill.nt1 f21 = [in0], 0x10
ldf.nt1 f26 = [r10], 8
ld8.nt1 r26 = [r10], 8
mov ar.pfs = r19
;;
ldf.fill.nt1 f22 = [in0], 0x10
ld8.nt1 r27 = [r10], 8
mov pr = r26, -1
mov pr = r26, -1
;;
ldf.fill.nt1 r23 = [in0], 0x10
ldf.fill.nt1 f23 = [in0], 0x10
ld8.nt1 r28 = [r10], -17*8 - 0x10
mov ar.lc = r27
;;
ldf.fill.nt1 f24 = [in0], 0x10
ldf.fill.nt1 f25 = [in0], 0x10
mov r8 = in1
mov r8 = in1
;;
ldf.fill.nt1 f26 = [in0], 0x10
ldf.fill.nt1 f31 = [r10], -0x10
......@@ -192,9 +188,12 @@ _skip_flushrs:
ldf.fill.nt1 f28 = [in0]
ldf.fill.nt1 f29 = [r10], 0x10*3 + 8*4
;;
ld8.fill.nt1 sp = [r10]
ld8.fill.nt1 sp = [r10]
mov ar.unat = r18
;;
mov ar.bspstore = r14
mov ar.rnat = r31
;;
invala
mov ar.rsc = r16
br.ret.sptk b0
......@@ -49,7 +49,7 @@ Returns:
if (!LibInitialized) {
LibInitialized = TRUE;
LibFwInstance = FALSE;
LibImageHandle = ImageHandle;
LibImageHandle = ImageHandle;
//
......@@ -71,17 +71,16 @@ Returns:
if (ImageHandle) {
Status = uefi_call_wrapper(
BS->HandleProtocol,
3,
ImageHandle,
&LoadedImageProtocol,
(VOID*)&LoadedImage
);
BS->HandleProtocol,
3,
ImageHandle,
&LoadedImageProtocol,
(VOID*)&LoadedImage
);
if (!EFI_ERROR(Status)) {
PoolAllocationType = LoadedImage->ImageDataType;
}
EFIDebugVariable ();
}
......@@ -181,5 +180,35 @@ EFIDebugVariable (
Status = uefi_call_wrapper(RT->GetVariable, 5, L"EFIDebug", &EfiGlobalVariable, &Attributes, &DataSize, &NewEFIDebug);
if (!EFI_ERROR(Status)) {
EFIDebug = NewEFIDebug;
}
}
}
/*
* Calls to memset/memcpy may be emitted implicitly by GCC or MSVC
* even when -ffreestanding or /NODEFAULTLIB are in effect.
*/
#ifndef __SIZE_TYPE__
#define __SIZE_TYPE__ UINTN
#endif
void *memset(void *s, int c, __SIZE_TYPE__ n)
{
unsigned char *p = s;
while (n--)
*p++ = c;
return s;
}
void *memcpy(void *dest, const void *src, __SIZE_TYPE__ n)
{
const unsigned char *q = src;
unsigned char *p = dest;
while (n--)
*p++ = *q++;
return dest;
}
......@@ -24,28 +24,3 @@ InitializeLibPlatform (
)
{
}
/*
* Calls to these functions may be emitted implicitly by GCC even when
* -ffreestanding is in effect.
*/
void *memset(void *s, int c, __SIZE_TYPE__ n)
{
unsigned char *p = s;
while (n--)
*p++ = c;
return s;
}
void *memcpy(void *dest, const void *src, __SIZE_TYPE__ n)
{
const unsigned char *q = src;
unsigned char *p = dest;
while (n--)
*p++ = *q++;
return dest;
}
......@@ -1005,6 +1005,7 @@ Routine Description:
t - EFI time structure
g - Pointer to GUID
r - EFI status code (result code)
D - pointer to Device Path with normal ending.
N - Set output attribute to normal
H - Set output attribute to highlight
......@@ -1167,6 +1168,18 @@ Returns:
Item.Item.pw = Item.Scratch;
break;
case 'D':
{
EFI_DEVICE_PATH *dp = va_arg(ps->args, EFI_DEVICE_PATH *);
CHAR16 *dpstr = DevicePathToStr(dp);
StrnCpy(Item.Scratch, dpstr, PRINT_ITEM_BUFFER_LEN);
Item.Scratch[PRINT_ITEM_BUFFER_LEN-1] = L'\0';
FreePool(dpstr);
Item.Item.pw = Item.Scratch;
break;
}
case 'f':
FloatToString (
Item.Scratch,
......
......@@ -57,6 +57,61 @@ RtStrCpy (
*Dest = 0;
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStrnCpy)
#endif
VOID
RUNTIMEFUNCTION
RtStrnCpy (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src,
IN UINTN Len
)
// copy strings
{
UINTN Size = RtStrnLen(Src, Len);
if (Size != Len)
RtSetMem(Dest + Len, '\0', (UINT8)((Len - Size) * sizeof(CHAR16)));
RtCopyMem(Dest, Src, Size * sizeof(CHAR16));
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStrCpy)
#endif
CHAR16 *
RUNTIMEFUNCTION
RtStpCpy (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src
)
// copy strings
{
while (*Src) {
*(Dest++) = *(Src++);
}
*Dest = 0;
return Dest;
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStpnCpy)
#endif
CHAR16 *
RUNTIMEFUNCTION
RtStpnCpy (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src,
IN UINTN Len
)
// copy strings
{
UINTN Size = RtStrnLen(Src, Len);
if (Size != Len)
RtSetMem(Dest + Size, (Len - Size) * sizeof(CHAR16), '\0');
RtCopyMem(Dest, Src, Size * sizeof(CHAR16));
return Dest + Size;
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStrCat)
#endif
......@@ -66,10 +121,29 @@ RtStrCat (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src
)
{
{
RtStrCpy(Dest+StrLen(Dest), Src);
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStrnCat)
#endif
VOID
RUNTIMEFUNCTION
RtStrnCat (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src,
IN UINTN Len
)
{
UINTN DestSize, Size;
DestSize = StrLen(Dest);
Size = RtStrnLen(Src, Len);
RtCopyMem(Dest + DestSize, Src, Size * sizeof(CHAR16));
Dest[DestSize + Size] = '\0';
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStrLen)
#endif
......@@ -81,11 +155,28 @@ RtStrLen (
// string length
{
UINTN len;
for (len=0; *s1; s1+=1, len+=1) ;
return len;
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStrnLen)
#endif
UINTN
RUNTIMEFUNCTION
RtStrnLen (
IN CONST CHAR16 *s1,
IN UINTN Len
)
// copy strings
{
UINTN i;
for (i = 0; *s1 && i < Len; i++)
s1++;
return i;
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStrSize)
#endif
......@@ -97,7 +188,7 @@ RtStrSize (
// string size
{
UINTN len;
for (len=0; *s1; s1+=1, len+=1) ;
return (len + 1) * sizeof(CHAR16);
}
......
......@@ -113,6 +113,38 @@ StrCpy (
RtStrCpy (Dest, Src);
}
VOID
StrnCpy (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src,
IN UINTN Len
)
// copy strings
{
RtStrnCpy (Dest, Src, Len);
}
CHAR16 *
StpCpy (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src
)
// copy strings
{
return RtStpCpy (Dest, Src);
}
CHAR16 *
StpnCpy (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src,
IN UINTN Len
)
// copy strings
{
return RtStpnCpy (Dest, Src, Len);
}
VOID
StrCat (
IN CHAR16 *Dest,
......@@ -122,6 +154,27 @@ StrCat (
RtStrCat(Dest, Src);
}
VOID
StrnCat (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src,
IN UINTN Len
)
{
RtStrnCat(Dest, Src, Len);
}
UINTN
StrnLen (
IN CONST CHAR16 *s1,
IN UINTN Len
)
// string length
{
return RtStrnLen(s1, Len);
}
UINTN
StrLen (
IN CONST CHAR16 *s1
......