Commit 10831ae8 authored by Julian Andres Klode's avatar Julian Andres Klode

Imported Upstream version 3.0v

parents
This diff is collapsed.
# -*- makefile -*-
# Copyright (c) 1999-2007 Hewlett-Packard Development Company, L.P.
# Contributed by David Mosberger <davidm@hpl.hp.com>
# Contributed by Stephane Eranian <eranian@hpl.hp.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.
#
TOPDIR := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)
#
# Variables below overridable from command-line:
# make VARNAME=value ...
#
#
# Where to install the package. GNU-EFI will create and access
# lib and include under the root
#
INSTALLROOT := /
PREFIX := /usr/local
LIBDIR := $(PREFIX)/lib
INSTALL := install
# Compilation tools
prefix := /usr/bin/
CC := $(prefix)gcc
AS := $(prefix)as
LD := $(prefix)ld
AR := $(prefix)ar
RANLIB := $(prefix)ranlib
OBJCOPY := $(prefix)objcopy
# Host/target identification
OS := $(shell uname -s)
HOSTARCH := $(shell $(CC) -dumpmachine | cut -f1 -d- | sed s,i[3456789]86,ia32,)
ARCH := $(shell uname -m | sed s,i[3456789]86,ia32,)
# FreeBSD (and possibly others) reports amd64 instead of x86_64
ifeq ($(ARCH),amd64)
override ARCH := x86_64
endif
#
# Variables below derived from variables above
#
GCCVERSION := $(shell $(CC) -dumpversion | cut -f1 -d.)
GCCMINOR := $(shell $(CC) -dumpversion | cut -f2 -d.)
# Rely on GCC MS ABI support?
GCCNEWENOUGH := $(shell ( [ $(GCCVERSION) -gt "4" ] \
|| ( [ $(GCCVERSION) -eq "4" ] \
&& [ $(GCCMINOR) -ge "7" ] ) ) \
&& echo 1)
ifeq ($(GCCNEWENOUGH),1)
CPPFLAGS += -DGNU_EFI_USE_MS_ABI -maccumulate-outgoing-args --std=c11
endif
# Arch-specific compilation flags
CPPFLAGS += -DCONFIG_$(ARCH)
ifeq ($(ARCH),ia64)
CFLAGS += -mfixed-range=f32-f127
endif
ifeq ($(ARCH),ia32)
CFLAGS += -mno-mmx -mno-sse
ifeq ($(HOSTARCH),x86_64)
ARCH3264 = -m32
endif
endif
ifeq ($(ARCH),x86_64)
CFLAGS += -mno-red-zone -mno-mmx -mno-sse
ifeq ($(HOSTARCH),ia32)
ARCH3264 = -m64
endif
endif
# Generic compilation flags
INCDIR += -I$(SRCDIR) -I$(TOPDIR)/inc -I$(TOPDIR)/inc/$(ARCH) \
-I$(TOPDIR)/inc/protocol
CFLAGS += $(ARCH3264) -O2 -fpic -Wall -fshort-wchar -fno-strict-aliasing \
-fno-merge-constants -ffreestanding -fno-stack-protector \
-fno-stack-check
ASFLAGS += $(ARCH3264)
LDFLAGS += -nostdlib --warn-common --no-undefined --fatal-warnings
#
# Copyright (C) 1999-2007 Hewlett-Packard Co.
# Contributed by David Mosberger <davidm@hpl.hp.com>
# Contributed by Stephane Eranian <eranian@hpl.hp.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.
#
%.efi: %.so
$(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel \
-j .rela -j .reloc --target=$(FORMAT) $*.so $@
%.so: %.o
$(LD) $(LDFLAGS) $^ -o $@ $(LOADLIBES)
%.o: %.c
$(CC) $(INCDIR) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
%.S: %.c
$(CC) $(INCDIR) $(CFLAGS) $(CPPFLAGS) -S $< -o $@
%.E: %.c
$(CC) $(INCDIR) $(CFLAGS) $(CPPFLAGS) -E $< -o $@
#
# Copyright (C) 1999-2007 Hewlett-Packard Co.
# Contributed by David Mosberger <davidm@hpl.hp.com>
# Contributed by Stephane Eranian <eranian@hpl.hp.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.
#
SRCDIR = $(shell pwd)
VPATH = $(SRCDIR)
include $(SRCDIR)/Make.defaults
SUBDIRS = lib gnuefi inc apps
gnuefi: lib
all: check_gcc $(SUBDIRS)
mkvars:
@echo AR=$(AR)
@echo ARCH=$(ARCH)
@echo ARCH3264=$(ARCH3264)
@echo AS=$(AS)
@echo ASFLAGS=$(ASFLAGS)
@echo CC=$(CC)
@echo CFLAGS=$(CFLAGS)
@echo CPPFLAGS=$(CPPFLAGS)
@echo GCCMINOR=$(GCCMINOR)
@echo GCCNEWENOUGH=$(GCCNEWENOUGH)
@echo GCCVERSION=$(GCCVERSION)
@echo HOSTARCH=$(HOSTARCH)
@echo INCDIR=$(INCDIR)
@echo INSTALL=$(INSTALL)
@echo INSTALLROOT=$(INSTALLROOT)
@echo LD=$(LD)
@echo LDFLAGS=$(LDFLAGS)
@echo LIBDIR=$(LIBDIR)
@echo OBJCOPY=$(OBJCOPY)
@echo OS=$(OS)
@echo prefix=$(prefix)
@echo PREFIX=$(PREFIX)
@echo RANLIB=$(RANLIB)
@echo SRCDIR=$(SRCDIR)
@echo TOPDIR=$(TOPDIR)
$(SUBDIRS):
mkdir -p $@
$(MAKE) -C $@ -f $(SRCDIR)/$@/Makefile SRCDIR=$(SRCDIR)/$@ ARCH=$(ARCH)
clean:
rm -f *~
@for d in $(SUBDIRS); do \
if [ -d $$d ]; then \
$(MAKE) -C $$d -f $(SRCDIR)/$$d/Makefile SRCDIR=$(SRCDIR)/$$d clean; \
fi; \
done
install:
@for d in $(SUBDIRS); do \
mkdir -p $$d; \
$(MAKE) -C $$d -f $(SRCDIR)/$$d/Makefile SRCDIR=$(SRCDIR)/$$d install; done
.PHONY: $(SUBDIRS) clean depend
#
# on both platforms you must use gcc 3.0 or higher
#
check_gcc:
ifeq ($(GCC_VERSION),2)
@echo "you need to use a version of gcc >= 3.0, you are using `$(CC) --version`"
@exit 1
endif
include $(SRCDIR)/Make.rules
The files in the "lib" and "inc" subdirectories are using the EFI Application
Toolkit distributed by Intel at http://developer.intel.com/technology/efi
This code is covered by the following agreement:
Copyright (c) 1998-2000 Intel Corporation
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.
THIS SOFTWARE IS PROVIDED ``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 INTEL 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. THE EFI SPECIFICATION AND ALL OTHER INFORMATION
ON THIS WEB SITE ARE PROVIDED "AS IS" WITH NO WARRANTIES, AND ARE SUBJECT
TO CHANGE WITHOUT NOTICE.
IMPORTANT information related to the gnu-efi package
----------------------------------------------------
June 2001
As of version 3.0, the gnu-efi package is now split in two different packages:
-> gnu-efi-X.y: contains the EFI library, include files and crt0.
-> elilo-X.y : contains the ELILO bootloader.
Note that X.y don't need to match for both packages. However elilo-3.x
requires at least gnu-efi-3.0. EFI support for x86_64 is provided in
gnu-efi-3.0d.
Both packages can be downloaded from:
http://www.sf.net/projects/gnu-efi
http://www.sf.net/projects/elilo
This diff is collapsed.
/*
* Copyright (C) 2013 Jerry Hoemann <jerry.hoemann@hp.com>
*
*
* Application to allocate memory at EFI. Syntax of command
* mimics the EFI Boot Service "AllocatePages."
*
* See UEFI spec 2.3, Section 6.2.
*
*
FS1:\> memmap
Type Start End #pages Attributes
BS_Code 0000000000000000-0000000000000FFF 0000000000000001 000000000000000F
Available 0000000000001000-000000000008DFFF 000000000000008D 000000000000000F
Reserved 000000000008E000-000000000008FFFF 0000000000000002 000000000000000F
Available 0000000000090000-000000000009FFFF 0000000000000010 000000000000000F
Available 0000000000100000-000000000FFFFFFF 000000000000FF00 000000000000000F
BS_Code 0000000010000000-0000000010061FFF 0000000000000062 000000000000000F
Available 0000000010062000-000000005CDFFFFF 000000000004CD9E 000000000000000F
ACPI_NVS 000000005CE00000-000000005DDFFFFF 0000000000001000 000000000000000F
BS_Data 000000005DE00000-000000005DFFFFFF 0000000000000200 000000000000000F
Available 000000005E000000-000000005EF1CFFF 0000000000000F1D 000000000000000F
BS_Data 000000005EF1D000-00000000709FBFFF 0000000000011ADF 000000000000000F
Available 00000000709FC000-00000000710E3FFF 00000000000006E8 000000000000000F
LoaderCode 00000000710E4000-00000000711FEFFF 000000000000011B 000000000000000F
Available 00000000711FF000-0000000071901FFF 0000000000000703 000000000000000F
BS_Code 0000000071902000-00000000721FEFFF 00000000000008FD 000000000000000F
Example to allocat 5 pages type BootCode at address 20000000 (hex)
FS1:\> AllocPages.efi 2 3 5 20000000
AllocatePage: __AllocType__ __MemType__ __NumPages__ [__Addr__]
__AllocType__ {0,1,2} -- Any, MaxAddr, Addr
__MemType__ {0..13}, Reserved ==0, LCode==1, LData==2, BSCode==3, BSData==4, ...
__NumPages__ {0..F000000}
[__Addr__] 0... 3FFFFFFFFFFF
All numbers in hex no leading 0x
AllocatPage(2,3,5,20000000)
Example to allocat 5 pages type BootCode at address 30000000 (hex)
FS1:\> AllocPages.efi 2 3 5 30000000
AllocatePage: __AllocType__ __MemType__ __NumPages__ [__Addr__]
__AllocType__ {0,1,2} -- Any, MaxAddr, Addr
__MemType__ {0..13}, Reserved ==0, LCode==1, LData==2, BSCode==3, BSData==4, ...
__NumPages__ {0..F000000}
[__Addr__] 0... 3FFFFFFFFFFF
All numbers in hex no leading 0x
FS1:\> memmap
Type Start End #pages Attributes
BS_Code 0000000000000000-0000000000000FFF 0000000000000001 000000000000000F
Available 0000000000001000-000000000008DFFF 000000000000008D 000000000000000F
Reserved 000000000008E000-000000000008FFFF 0000000000000002 000000000000000F
Available 0000000000090000-000000000009FFFF 0000000000000010 000000000000000F
Available 0000000000100000-000000000FFFFFFF 000000000000FF00 000000000000000F
BS_Code 0000000010000000-0000000010061FFF 0000000000000062 000000000000000F
Available 0000000010062000-000000001FFFFFFF 000000000000FF9E 000000000000000F
BS_Code 0000000020000000-0000000020004FFF 0000000000000005 000000000000000F
Available 0000000020005000-000000002FFFFFFF 000000000000FFFB 000000000000000F
BS_Code 0000000030000000-0000000030004FFF 0000000000000005 000000000000000F
Available 0000000030005000-000000005CDFFFFF 000000000002CDFB 000000000000000F
ACPI_NVS 000000005CE00000-000000005DDFFFFF 0000000000001000 000000000000000F
BS_Data 000000005DE00000-000000005DFFFFFF 0000000000000200 000000000000000F
Available 000000005E000000-000000005EF1CFFF 0000000000000F1D 000000000000000F
BS_Data 000000005EF1D000-00000000709FBFFF 0000000000011ADF 000000000000000F
Available 00000000709FC000-00000000710E3FFF 00000000000006E8 000000000000000F
LoaderCode 00000000710E4000-00000000711FEFFF 000000000000011B 000000000000000F
Available 00000000711FF000-0000000071901FFF 0000000000000703 000000000000000F
BS_Code 0000000071902000-00000000721FEFFF 00000000000008FD 000000000000000F
*/
#include <efi.h>
#include <efilib.h>
#include <ParseCmdLine.h>
#define MAX_NUM_PAGES 0x000000000F000000
#define MAX_ADDR ((1ULL << 46) - 1)
#ifdef DEBUG
#undef DEBUG
#endif
#define DEBUG 0
EFI_STATUS
efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
{
EFI_STATUS efi_status;
EFI_GUID LoadedImageProtocol = LOADED_IMAGE_PROTOCOL;
EFI_LOADED_IMAGE *info;
CHAR16 arglist[MAX_ARGS+1] = {0};
CHAR16 *argv[MAX_ARGS];
INTN argc = 0;
INTN err = 0;
INTN c = 0;
INTN AllocType = -1;
INTN MemType = -1;
INTN NumPages = -1;
UINTN Addr = 0;
InitializeLib(image, systab);
efi_status = uefi_call_wrapper( BS->HandleProtocol, 3, image,
&LoadedImageProtocol, &info);
Print(L"AllocatePage: __AllocType__ __MemType__ __NumPages__ [__Addr__]\n");
Print(L"__AllocType__ {0,1,2} -- Any, MaxAddr, Addr\n");
Print(L"__MemType__ {0..13}, Reserved ==0, LCode==1, LData==2, BSCode==3, BSData==4, ...\n");
Print(L"__NumPages__ {0..%x}\n", MAX_NUM_PAGES);
Print(L"[__Addr__] 0... %llx\n", MAX_ADDR);
Print(L"All numbers in hex no leading 0x\n");
Print(L"\n");
#if DEBUG
Print(L"%s\n", info->LoadOptions);
#endif
#if DEBUG
Print(L"Set up arglist\n");
#endif
CopyMem(arglist, info->LoadOptions, info->LoadOptionsSize);
#if DEBUG
Print(L"arglist = <%s>\n", arglist);
#endif
#if DEBUG
Print(L"Now try ParseCmdLine\n");
#endif
argc = ParseCmdLine(argv, arglist, info->LoadOptionsSize);
#if DEBUG
Print(L"argc = %d\n", argc);
#endif
#if DEBUG
for (c = 0; c < argc; c++ ) {
Print(L"argv[%d] = <%s>\n", c, argv[c]);
}
#endif
if ( (argc < 3) || (argc > 5) ) {
Print(L"Wrong argument count\n");
return EFI_SUCCESS;
}
AllocType = xtoi(argv[1]);
MemType = xtoi(argv[2]);
NumPages = xtoi(argv[3]);
if ( argc == 5 ) Addr = xtoi(argv[4]);
if ( (AllocType < 0) || (AllocType > 2)) {
Print(L"Invalid AllocType\n");
err++;
}
if ( (MemType < 0) || (MemType > 13) ) {
Print(L"Invalid MemType\n");
err++;
}
if ( (NumPages < 0) || (NumPages > MAX_NUM_PAGES) ) {
Print(L"Inavlid NumPages\n");
err++;
}
if ( Addr > MAX_ADDR ) {
Print(L"Inavlid Address\n");
err++;
}
if ( err ) {
return EFI_INVALID_PARAMETER;
}
Print(L"AllocatPage(%d,%d,%d,%lx)\n", AllocType, MemType, NumPages, Addr);
efi_status = uefi_call_wrapper(BS->AllocatePages, 4, AllocType, MemType, NumPages, &Addr);
if ( EFI_ERROR(efi_status) ) {
Print(L"Allocate Pages Failed: %d\n", efi_status);
return efi_status;
}
return EFI_SUCCESS;
}
/*
* Copyright (C) 2013 Jerry Hoemann <jerry.hoemann@hp.com>
*
* Application to allocate memory at EFI. Syntax of command
* mimics the EFI Boot Service "FreePages."
*
* See UEFI spec 2.3, Section 6.2.
*
Example freeing a 5 page BS_Code setment at address: 0000000020000000 (hex)
FS1:\> memmap
Type Start End #pages Attributes
BS_Code 0000000000000000-0000000000000FFF 0000000000000001 000000000000000F
Available 0000000000001000-000000000008DFFF 000000000000008D 000000000000000F
Reserved 000000000008E000-000000000008FFFF 0000000000000002 000000000000000F
Available 0000000000090000-000000000009FFFF 0000000000000010 000000000000000F
Available 0000000000100000-000000000FFFFFFF 000000000000FF00 000000000000000F
BS_Code 0000000010000000-0000000010061FFF 0000000000000062 000000000000000F
Available 0000000010062000-000000001FFFFFFF 000000000000FF9E 000000000000000F
BS_Code 0000000020000000-0000000020004FFF 0000000000000005 000000000000000F
Available 0000000020005000-000000005DDFFFFF 000000000003DDFB 000000000000000F
BS_Data 000000005DE00000-000000005DFFFFFF 0000000000000200 000000000000000F
Available 000000005E000000-000000006DE7CFFF 000000000000FE7D 000000000000000F
ACPI_NVS 000000006DE7D000-000000006EE7CFFF 0000000000001000 000000000000000F
BS_Data 000000006EE7D000-00000000709FBFFF 0000000000001B7F 000000000000000F
Available 00000000709FC000-00000000710E3FFF 00000000000006E8 000000000000000F
FS1:\> FreePages 0000000020000000 5
FreePages: __PhysAddr__ __PgCnt__
__PhysAddr__ 0... 3FFFFFFFFFFF
__PgCnt__ [0..F000000]
All numbers hex w/ no leading 0x
FreePages(20000000,5)
FS1:\> memmap
Type Start End #pages Attributes
BS_Code 0000000000000000-0000000000000FFF 0000000000000001 000000000000000F
Available 0000000000001000-000000000008DFFF 000000000000008D 000000000000000F
Reserved 000000000008E000-000000000008FFFF 0000000000000002 000000000000000F
Available 0000000000090000-000000000009FFFF 0000000000000010 000000000000000F
Available 0000000000100000-000000000FFFFFFF 000000000000FF00 000000000000000F
BS_Code 0000000010000000-0000000010061FFF 0000000000000062 000000000000000F
Available 0000000010062000-000000005DDFFFFF 000000000004DD9E 000000000000000F
BS_Data 000000005DE00000-000000005DFFFFFF 0000000000000200 000000000000000F
Available 000000005E000000-000000006DE7CFFF 000000000000FE7D 000000000000000F
ACPI_NVS 000000006DE7D000-000000006EE7CFFF 0000000000001000 000000000000000F
BS_Data 000000006EE7D000-00000000709FBFFF 0000000000001B7F 000000000000000F
Available 00000000709FC000-00000000710E3FFF 00000000000006E8 000000000000000F
*/
#include <efi.h>
#include <efilib.h>
#include <ParseCmdLine.h>
/*
* FreePages: __PhysAddr__ __PgCnt__
*
*/
#define MAX_NUM_PAGES 0x000000000F000000
#define MAX_ADDR ((1ULL << 46) - 1)
#ifdef DEBUG
#undef DEBUG
#endif
#define DEBUG 0
EFI_STATUS
efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
{
EFI_STATUS efi_status;
EFI_GUID LoadedImageProtocol = LOADED_IMAGE_PROTOCOL;
EFI_LOADED_IMAGE *info;
CHAR16 arglist[MAX_ARGS+1] = {0};
CHAR16 *argv[MAX_ARGS];
INTN argc = 0;
INTN c = 0;
INTN err = 0;
INTN PgCnt = -1;
UINTN PhysAddr = 0;
InitializeLib(image, systab);
efi_status = uefi_call_wrapper( BS->HandleProtocol, 3, image,
&LoadedImageProtocol, &info);
Print(L"FreePages: __PhysAddr__ __PgCnt__\n");
Print(L"__PhysAddr__ 0... %llx\n", MAX_ADDR);
Print(L"__PgCnt__ [0..%lx]\n", MAX_NUM_PAGES);
Print(L"All numbers hex w/ no leading 0x\n");
Print(L"\n");
#if DEBUG
Print(L"%s\n", info->LoadOptions);
#endif
#if DEBUG
Print(L"Set up arglist\n");
#endif
CopyMem(arglist, info->LoadOptions, info->LoadOptionsSize);
#if DEBUG
Print(L"arglist = <%s>\n", arglist);
#endif
#if DEBUG
Print(L"Now try ParseCmdLine\n");
#endif
argc = ParseCmdLine(argv, arglist, info->LoadOptionsSize);
#if DEBUG
Print(L"argc = %d\n", argc);
#endif
#if DEBUG
for (c = 0; c < argc; c++ ) {
Print(L"argv[%d] = <%s>\n", c, argv[c]);
}
#endif
if (argc != 3) {
Print(L"Invalid argument count\n");
return EFI_SUCCESS;
}
PhysAddr = xtoi(argv[1]);
PgCnt = xtoi(argv[2]);
if ( (PgCnt < 0) || (PgCnt > MAX_NUM_PAGES) ) {
Print(L"Inavlid PgCnt\n");
err++;
}
if ( PhysAddr > MAX_ADDR ) {
Print(L"Inavlid Address\n");
err++;
}
if ( err ) {
return EFI_SUCCESS;
}
Print(L"FreePages(%lx,%d)\n", PhysAddr, PgCnt);
efi_status = uefi_call_wrapper(BS->FreePages, 2, PhysAddr, PgCnt);
if ( EFI_ERROR(efi_status) ) {
Print(L"Free Pages Failed: %d\n", efi_status);
return efi_status;
}
return EFI_SUCCESS;
}
#
# Copyright (C) 1999-2001 Hewlett-Packard Co.
# Contributed by David Mosberger <davidm@hpl.hp.com>
# Contributed by Stephane Eranian <eranian@hpl.hp.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