summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorNigel Croxon <nigel.croxon@hp.com>2014-11-25 10:09:50 -0500
committerNigel Croxon <nigel.croxon@hp.com>2014-11-25 10:09:50 -0500
commit530d68ba191850edafc6da22cb2df55bec0c5fa5 (patch)
tree6752986507d3fc8ffc65085deedf11e7887a3d2a /apps
parent00bd66ef46b59a1623a293491a8b2c65a6d61975 (diff)
downloadgnu-efi-530d68ba191850edafc6da22cb2df55bec0c5fa5.tar.gz
The gnu-efi-3.0 toplevel subdirectory is really annoying. Kill it.
Signed-off-by: Peter Jones <pjones@redhat.com> Signed-off-by: Nigel Croxon <nigel.croxon@hp.com>
Diffstat (limited to 'apps')
-rw-r--r--apps/AllocPages.c184
-rw-r--r--apps/FreePages.c145
-rw-r--r--apps/Makefile94
-rw-r--r--apps/drv0.c193
-rw-r--r--apps/drv0.h37
-rw-r--r--apps/drv0_use.c79
-rw-r--r--apps/modelist.c114
-rw-r--r--apps/printenv.c32
-rw-r--r--apps/route80h.c146
-rw-r--r--apps/t.c27
-rw-r--r--apps/t2.c13
-rw-r--r--apps/t3.c95
-rw-r--r--apps/t4.c13
-rw-r--r--apps/t5.c13
-rw-r--r--apps/t6.c43
-rw-r--r--apps/t7.c25
-rw-r--r--apps/t8.c19
-rw-r--r--apps/tcc.c442
-rw-r--r--apps/tpause.c9
-rw-r--r--apps/trivial.S43
20 files changed, 1766 insertions, 0 deletions
diff --git a/apps/AllocPages.c b/apps/AllocPages.c
new file mode 100644
index 0000000..77a082e
--- /dev/null
+++ b/apps/AllocPages.c
@@ -0,0 +1,184 @@
+
+/*
+ * 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>
+
+
+#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;
+ CHAR16 **argv;
+ INTN argc;
+ INTN err = 0;
+#if DEBUG
+ INTN c = 0;
+#endif
+ INTN AllocType = -1;
+ INTN MemType = -1;
+ INTN NumPages = -1;
+ UINTN Addr = 0;
+
+ InitializeLib(image, systab);
+
+ 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"Now get argc/argv\n");
+#endif
+ argc = GetShellArgcArgv(image, &argv);
+#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 < 4) || (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;
+}
diff --git a/apps/FreePages.c b/apps/FreePages.c
new file mode 100644
index 0000000..bbf2f52
--- /dev/null
+++ b/apps/FreePages.c
@@ -0,0 +1,145 @@
+
+
+/*
+ * 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>
+
+/*
+ * 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;
+ CHAR16 **argv;
+ INTN argc = 0;
+#if DEBUG
+ INTN c = 0;
+#endif
+ INTN err = 0;
+
+ INTN PgCnt = -1;
+ UINTN PhysAddr = 0;
+
+ InitializeLib(image, systab);
+
+ 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"Now parse argc/argv\n");
+#endif
+ argc = GetShellArgcArgv(image, &argv);
+#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;
+}
diff --git a/apps/Makefile b/apps/Makefile
new file mode 100644
index 0000000..ec98425
--- /dev/null
+++ b/apps/Makefile
@@ -0,0 +1,94 @@
+#
+# 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 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 = .
+
+VPATH = $(SRCDIR)
+
+include $(SRCDIR)/../Make.defaults
+
+TOPDIR = $(SRCDIR)/..
+
+CDIR=$(TOPDIR)/..
+LINUX_HEADERS = /usr/src/sys/build
+CPPFLAGS += -D__KERNEL__ -I$(LINUX_HEADERS)/include
+CRTOBJS = ../gnuefi/crt0-efi-$(ARCH).o
+
+LDSCRIPT = $(TOPDIR)/gnuefi/elf_$(ARCH)_efi.lds
+ifneq (,$(findstring FreeBSD,$(OS)))
+LDSCRIPT = $(TOPDIR)/gnuefi/elf_$(ARCH)_fbsd_efi.lds
+endif
+
+LDFLAGS += -shared -Bsymbolic -L../lib -L../gnuefi $(CRTOBJS)
+
+LOADLIBES += -lefi -lgnuefi
+LOADLIBES += $(LIBGCC)
+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 \
+ FreePages.efi
+TARGET_BSDRIVERS = drv0.efi
+TARGET_RTDRIVERS =
+
+ifneq ($(HAVE_EFI_OBJCOPY),)
+
+FORMAT := --target efi-app-$(ARCH)
+$(TARGET_BSDRIVERS): FORMAT=--target efi-bsdrv-$(ARCH)
+$(TARGET_RTDRIVERS): FORMAT=--target efi-rtdrv-$(ARCH)
+
+else
+
+SUBSYSTEM := 0xa
+$(TARGET_BSDRIVERS): SUBSYSTEM = 0xb
+$(TARGET_RTDRIVERS): SUBSYSTEM = 0xc
+
+FORMAT := -O binary
+LDFLAGS += --defsym=EFI_SUBSYSTEM=$(SUBSYSTEM)
+
+endif
+
+TARGETS = $(TARGET_APPS) $(TARGET_BSDRIVERS) $(TARGET_RTDRIVERS)
+
+all: $(TARGETS)
+
+clean:
+ rm -f $(TARGETS) *~ *.o *.so
+
+.PHONY: install
+
+include $(SRCDIR)/../Make.rules
diff --git a/apps/drv0.c b/apps/drv0.c
new file mode 100644
index 0000000..126e8e7
--- /dev/null
+++ b/apps/drv0.c
@@ -0,0 +1,193 @@
+/*
+ * Copyright (C) 2013 David Decotigny <decot@googlers.com>
+ *
+ * Sample EFI shell session, together with drv0_use.efi:
+ *
+ * # Loading first instance:
+ *
+ * fs0:\> load drv0.efi
+ * Driver instance loaded successfully.
+ * load: Image fs0:\drv0.efi loaded at 2FD7C000 - Success
+ *
+ * # Testing 1st instance:
+ *
+ * fs0:\> drv0_use.efi
+ * Playing with driver instance 0...
+ * Hello Sample UEFI Driver!
+ * Hello was called 1 time(s).
+ *
+ * fs0:\> drv0_use.efi
+ * Playing with driver instance 0...
+ * Hello Sample UEFI Driver!
+ * Hello was called 2 time(s).
+ *
+ * # Loading another instance:
+ *
+ * fs0:\> load drv0.efi
+ * Driver instance loaded successfully.
+ * load: Image fs0:\drv0.efi loaded at 2FD6D000 - Success
+ *
+ * # Using both instances:
+ *
+ * fs0:\> drv0_use.efi
+ * Playing with driver instance 0...
+ * Hello Sample UEFI Driver!
+ * Hello was called 3 time(s).
+ * Playing with driver instance 1...
+ * Hello Sample UEFI Driver!
+ * Hello was called 1 time(s).
+ *
+ * fs0:\> drv0_use.efi
+ * Playing with driver instance 0...
+ * Hello Sample UEFI Driver!
+ * Hello was called 4 time(s).
+ * Playing with driver instance 1...
+ * Hello Sample UEFI Driver!
+ * Hello was called 2 time(s).
+ *
+ * # Removing 1st instance:
+ *
+ * fs0:\> dh
+ * Handle dump
+ * 1: Image(DxeCore)
+ * [...]
+ * 79: Image(\/drv0.efi) ImageDevPath (..A,0x800,0x17F7DF)/\/drv0.efi)
+ * 7A: Image(\/drv0.efi) ImageDevPath (..A,0x800,0x17F7DF)/\/drv0.efi)
+ *
+ * fs0:\> unload 79
+ * 79: Image(\/drv0.efi) ImageDevPath (..A,0x800,0x17F7DF)/\/drv0.efi)
+ * Unload driver image (y/n)? y
+ * Driver instance unloaded.
+ * unload: Success
+ *
+ * # Only 2nd instance remaining:
+ *
+ * fs0:\> drv0_use.efi
+ * Playing with driver instance 0...
+ * Hello Sample UEFI Driver!
+ * Hello was called 3 time(s).
+ *
+ * # Removing 2nd/last instance:
+ *
+ * fs0:\> dh
+ * Handle dump
+ * 1: Image(DxeCore)
+ * [...]
+ * 79: Image(\/drv0.efi) ImageDevPath (..A,0x800,0x17F7DF)/\/drv0.efi)
+ *
+ * fs0:\> unload 79
+ * 79: Image(\/drv0.efi) ImageDevPath (..A,0x800,0x17F7DF)/\/drv0.efi)
+ * Unload driver image (y/n)? y
+ * Driver instance unloaded.
+ * unload: Success
+ *
+ * # Expect error: no other drv0 instance left
+ *
+ * fs0:\> drv0_use.efi
+ * Error looking up handles for proto: 14
+ */
+
+#include <efi.h>
+#include <efilib.h>
+#include "drv0.h"
+
+
+static const EFI_GUID GnuEfiAppsDrv0ProtocolGuid
+ = GNU_EFI_APPS_DRV0_PROTOCOL_GUID;
+
+static struct {
+ GNU_EFI_APPS_DRV0_PROTOCOL Proto;
+ UINTN Counter;
+} InternalGnuEfiAppsDrv0ProtocolData;
+
+
+static
+EFI_STATUS
+EFI_FUNCTION
+Drv0SayHello(
+ IN struct _GNU_EFI_APPS_DRV0_PROTOCOL *This,
+ IN const CHAR16 *HelloWho
+ )
+{
+ if (! HelloWho)
+ return EFI_INVALID_PARAMETER;
+
+ Print(L"Hello %s!\n", HelloWho);
+ InternalGnuEfiAppsDrv0ProtocolData.Counter ++;
+ return EFI_SUCCESS;
+}
+
+
+static
+EFI_STATUS
+EFI_FUNCTION
+Drv0GetNumberOfHello(
+ IN struct _GNU_EFI_APPS_DRV0_PROTOCOL *This,
+ OUT UINTN *NumberOfHello
+ )
+{
+ if (! NumberOfHello)
+ return EFI_INVALID_PARAMETER;
+
+ *NumberOfHello = InternalGnuEfiAppsDrv0ProtocolData.Counter;
+ return EFI_SUCCESS;
+}
+
+
+static
+EFI_STATUS
+EFI_FUNCTION
+Drv0Unload(IN EFI_HANDLE ImageHandle)
+{
+ LibUninstallProtocolInterfaces(ImageHandle,
+ &GnuEfiAppsDrv0ProtocolGuid,
+ &InternalGnuEfiAppsDrv0ProtocolData.Proto,
+ NULL);
+ Print(L"Driver instance unloaded.\n", ImageHandle);
+ return EFI_SUCCESS;
+}
+
+
+EFI_STATUS
+efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SysTab)
+{
+ EFI_STATUS Status;
+ EFI_LOADED_IMAGE *LoadedImage = NULL;
+
+ InitializeLib(ImageHandle, SysTab);
+
+ /* Initialize global protocol definition + data */
+ InternalGnuEfiAppsDrv0ProtocolData.Proto.SayHello
+ = (GNU_EFI_APPS_DRV0_SAY_HELLO) Drv0SayHello;
+ InternalGnuEfiAppsDrv0ProtocolData.Proto.GetNumberOfHello
+ = (GNU_EFI_APPS_DRV0_GET_NUMBER_OF_HELLO) Drv0GetNumberOfHello;
+ InternalGnuEfiAppsDrv0ProtocolData.Counter = 0;
+
+ /* Grab handle to this image: we'll attach our proto instance to it */
+ Status = uefi_call_wrapper(BS->OpenProtocol, 6,
+ ImageHandle, &LoadedImageProtocol,
+ &LoadedImage, ImageHandle,
+ NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
+ if (EFI_ERROR(Status)) {
+ Print(L"Could not open loaded image protocol: %d\n", Status);
+ return Status;
+ }
+
+ /* Attach our proto to the current driver image */
+ Status = LibInstallProtocolInterfaces(
+ &ImageHandle, &GnuEfiAppsDrv0ProtocolGuid,
+ &InternalGnuEfiAppsDrv0ProtocolData.Proto, NULL);
+ if (EFI_ERROR(Status)) {
+ Print(L"Error registering driver instance: %d\n", Status);
+ return Status;
+ }
+
+ /* Register Unload callback, used to unregister current protocol
+ * instance from system */
+ LoadedImage->Unload = (EFI_IMAGE_UNLOAD)Drv0Unload;
+
+ Print(L"Driver instance loaded successfully.\n");
+ return EFI_SUCCESS; /* at this point, this instance stays resident
+ * until image is unloaded, eg. with shell's unload,
+ * ExitBootServices() */
+}
diff --git a/apps/drv0.h b/apps/drv0.h
new file mode 100644
index 0000000..26d2ffd
--- /dev/null
+++ b/apps/drv0.h
@@ -0,0 +1,37 @@
+#ifndef _GNU_EFI_APPS_DRV0_H_
+#define _GNU_EFI_APPS_DRV0_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* UEFI naming conventions */
+#define GNU_EFI_APPS_DRV0_PROTOCOL_GUID \
+{ 0xe4dcafd0, 0x586c, 0x4b3d, {0x86, 0xe7, 0x28, 0xde, 0x7f, 0xcc, 0x04, 0xb8} }
+
+INTERFACE_DECL(_GNU_EFI_APPS_DRV0_PROTOCOL);
+
+typedef
+EFI_STATUS
+(EFIAPI *GNU_EFI_APPS_DRV0_SAY_HELLO) (
+ IN struct _GNU_EFI_APPS_DRV0_PROTOCOL *This,
+ IN const CHAR16 *HelloWho
+ );
+
+typedef
+EFI_STATUS
+(EFIAPI *GNU_EFI_APPS_DRV0_GET_NUMBER_OF_HELLO) (
+ IN struct _GNU_EFI_APPS_DRV0_PROTOCOL *This,
+ OUT UINTN *NumberOfHello
+ );
+
+typedef struct _GNU_EFI_APPS_DRV0_PROTOCOL {
+ GNU_EFI_APPS_DRV0_SAY_HELLO SayHello;
+ GNU_EFI_APPS_DRV0_GET_NUMBER_OF_HELLO GetNumberOfHello;
+} GNU_EFI_APPS_DRV0_PROTOCOL;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/apps/drv0_use.c b/apps/drv0_use.c
new file mode 100644
index 0000000..f7c5869
--- /dev/null
+++ b/apps/drv0_use.c
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2013 David Decotigny <decot@googlers.com>
+ *
+ * See drv0.c for an example session.
+ */
+
+#include <efi.h>
+#include <efilib.h>
+#include "drv0.h"
+
+
+static EFI_GUID GnuEfiAppsDrv0ProtocolGuid
+ = GNU_EFI_APPS_DRV0_PROTOCOL_GUID;
+
+
+static
+EFI_STATUS
+PlayWithGnuEfiAppsDrv0Protocol(IN EFI_HANDLE DrvHandle) {
+ EFI_STATUS Status;
+ GNU_EFI_APPS_DRV0_PROTOCOL *drv = NULL;
+ UINTN NumberOfHello = 0;
+
+ Status = uefi_call_wrapper(BS->OpenProtocol, 6,
+ DrvHandle,
+ &GnuEfiAppsDrv0ProtocolGuid,
+ &drv,
+ DrvHandle,
+ NULL,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL);
+ if (EFI_ERROR(Status)) {
+ Print(L"Cannot open proto: %d\n", Status);
+ return Status;
+ }
+
+ Status = uefi_call_wrapper(drv->SayHello, 2, drv, L"Sample UEFI Driver");
+ if (EFI_ERROR(Status)) {
+ Print(L"Cannot call SayHello: %d\n", Status);
+ }
+
+ Status = uefi_call_wrapper(drv->GetNumberOfHello, 2, drv, &NumberOfHello);
+ if (EFI_ERROR(Status)) {
+ Print(L"Cannot call GetNumberOfHello: %d\n", Status);
+ } else {
+ Print(L"Hello was called %d time(s).\n", NumberOfHello);
+ }
+
+ return EFI_SUCCESS;
+}
+
+
+EFI_STATUS
+efi_main (EFI_HANDLE Image, EFI_SYSTEM_TABLE *SysTab)
+{
+ EFI_STATUS Status;
+ EFI_HANDLE *Handles = NULL;
+ UINTN i, NoHandles = 0;
+
+ InitializeLib(Image, SysTab);
+
+ Status = LibLocateHandle(ByProtocol, &GnuEfiAppsDrv0ProtocolGuid,
+ NULL, &NoHandles, &Handles);
+ if (EFI_ERROR(Status)) {
+ Print(L"Error looking up handles for proto: %d\n", Status);
+ return Status;
+ }
+
+ for (i = 0 ; i < NoHandles ; ++i)
+ {
+ Print(L"Playing with driver instance %d...\n", i);
+ Status = PlayWithGnuEfiAppsDrv0Protocol(Handles[i]);
+ if (EFI_ERROR(Status))
+ Print(L"Error playing with instance %d, skipping\n", i);
+ }
+
+ if (Handles)
+ FreePool(Handles);
+
+ return EFI_SUCCESS;
+}
diff --git a/apps/modelist.c b/apps/modelist.c
new file mode 100644
index 0000000..8d816d1
--- /dev/null
+++ b/apps/modelist.c
@@ -0,0 +1,114 @@
+#include <efi.h>
+#include <efilib.h>
+
+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;
+
+ 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) {
+ rc = uefi_call_wrapper(gop->SetMode, 2, gop,
+ gop->Mode->Mode);
+ 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);
+ continue;
+ }
+ Print(L"%c%d: %dx%d ", memcmp(info,gop->Mode->Info,sizeof(*info)) == 0 ? '*' : ' ', i,
+ info->HorizontalResolution,
+ info->VerticalResolution);
+ switch(info->PixelFormat) {
+ case PixelRedGreenBlueReserved8BitPerColor:
+ Print(L"RGBR");
+ break;
+ case PixelBlueGreenRedReserved8BitPerColor:
+ Print(L"BGRR");
+ break;
+ case PixelBitMask:
+ Print(L"R:%08x G:%08x B:%08x X:%08x",
+ info->PixelInformation.RedMask,
+ info->PixelInformation.GreenMask,
+ info->PixelInformation.BlueMask,
+ info->PixelInformation.ReservedMask);
+ break;
+ case PixelBltOnly:
+ Print(L"(blt only)");
+ break;
+ default:
+ Print(L"(Invalid pixel format)");
+ break;
+ }
+ Print(L" pitch %d\n", info->PixelsPerScanLine);
+ }
+}
+
+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))
+ return rc;
+
+ print_modes(gop);
+
+ SetWatchdog(0);
+ return EFI_SUCCESS;
+}
diff --git a/apps/printenv.c b/apps/printenv.c
new file mode 100644
index 0000000..6341e40
--- /dev/null
+++ b/apps/printenv.c
@@ -0,0 +1,32 @@
+#include <efi.h>
+#include <efilib.h>
+
+EFI_STATUS
+efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
+{
+ EFI_STATUS status;
+ CHAR16 name[256], *val, fmt[20];
+ EFI_GUID vendor;
+ UINTN size;
+
+ InitializeLib(image, systab);
+
+ name[0] = 0;
+ vendor = NullGuid;
+
+ Print(L"GUID Variable Name Value\n");
+ Print(L"=================================== ==================== ========\n");
+
+ StrCpy(fmt, L"%.-35g %.-20s %s\n");
+ while (1) {
+ size = sizeof(name);
+ status = uefi_call_wrapper(RT->GetNextVariableName, 3, &size, name, &vendor);
+ if (status != EFI_SUCCESS)
+ break;
+
+ val = LibGetVariable(name, &vendor);
+ Print(fmt, &vendor, name, val);
+ FreePool(val);
+ }
+ return EFI_SUCCESS;
+}
diff --git a/apps/route80h.c b/apps/route80h.c
new file mode 100644
index 0000000..21ea2d5
--- /dev/null
+++ b/apps/route80h.c
@@ -0,0 +1,146 @@
+#include <efi.h>
+#include <efilib.h>
+
+/* this example program changes the Reserved Page Route (RPR) bit on ICH10's General
+ * Control And Status Register (GCS) from LPC to PCI. In practical terms, it routes
+ * outb to port 80h to the PCI bus. */
+
+#define GCS_OFFSET_ADDR 0x3410
+#define GCS_RPR_SHIFT 2
+#define GCS_RPR_PCI 1
+#define GCS_RPR_LPC 0
+
+#define VENDOR_ID_INTEL 0x8086
+#define DEVICE_ID_LPCIF 0x3a16
+#define DEVICE_ID_COUGARPOINT_LPCIF 0x1c56
+
+static EFI_HANDLE ImageHandle;
+
+typedef struct {
+ uint16_t vendor_id; /* 00-01 */
+ uint16_t device_id; /* 02-03 */
+ char pad[0xEB]; /* 04-EF */
+ uint32_t rcba; /* F0-F3 */
+ uint32_t reserved[3]; /* F4-FF */
+} lpcif_t;
+
+static inline void set_bit(volatile uint32_t *flag, int bit, int value)
+{
+ uint32_t val = *flag;
+ Print(L"current value is 0x%2x\n", val);
+
+ if (value) {
+ val |= (1 << bit);
+ } else {
+ val &= ~(1 << bit);
+ }
+ Print(L"setting value to 0x%2x\n", val);
+ *flag = val;
+ val = *flag;
+ Print(L"new value is 0x%2x\n", val);
+}
+
+static inline int configspace_matches_ids(void *config, uint32_t vendor_id,
+ uint32_t device_id)
+{
+ uint32_t *cfg = config;
+ if (cfg[0] == vendor_id && cfg[1] == device_id)
+ return 1;
+ return 0;
+}
+
+static int is_device(EFI_PCI_IO *pciio, uint16_t vendor_id, uint16_t device_id)
+{
+ lpcif_t lpcif;
+ EFI_STATUS rc;
+
+ rc = uefi_call_wrapper(pciio->Pci.Read, 5, pciio, EfiPciIoWidthUint16, 0, 2, &lpcif);
+ if (EFI_ERROR(rc))
+ return 0;
+
+ if (vendor_id == lpcif.vendor_id && device_id == lpcif.device_id)
+ return 1;
+ return 0;
+}
+
+static EFI_STATUS find_pci_device(uint16_t vendor_id, uint16_t device_id,
+ EFI_PCI_IO **pciio)
+{
+ EFI_STATUS rc;
+ EFI_HANDLE *Handles;
+ UINTN NoHandles;
+ int i;
+
+ if (!pciio)
+ return EFI_INVALID_PARAMETER;
+
+ rc = LibLocateHandle(ByProtocol, &PciIoProtocol, NULL, &NoHandles,
+ &Handles);
+ if (EFI_ERROR(rc))
+ return rc;
+
+ for (i = 0; i < NoHandles; i++) {
+ void *pciio_tmp = NULL;
+ rc = uefi_call_wrapper(BS->OpenProtocol, 6, Handles[i],
+ &PciIoProtocol, &pciio_tmp, ImageHandle,
+ NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
+ if (EFI_ERROR(rc))
+ continue;
+ *pciio = pciio_tmp;
+ if (!is_device(*pciio, vendor_id, device_id)) {
+ *pciio = NULL;
+ continue;
+ }
+
+ return EFI_SUCCESS;
+ }
+ return EFI_NOT_FOUND;
+}
+
+EFI_STATUS
+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;
+ struct {
+ uint16_t vendor;
+ uint16_t device;
+ } devices[] = {
+ { VENDOR_ID_INTEL, DEVICE_ID_LPCIF },
+ { VENDOR_ID_INTEL, DEVICE_ID_COUGARPOINT_LPCIF },
+ { 0, 0 }
+ };
+ int i;
+
+ ImageHandle = image_handle;
+ for (i = 0; devices[i].vendor != 0; i++) {
+ rc = find_pci_device(devices[i].vendor, devices[i].device, &pciio);
+ if (EFI_ERROR(rc))
+ continue;
+ }
+
+ if (rc == EFI_NOT_FOUND) {
+ Print(L"Device not found.\n");
+ return rc;
+ } else if (EFI_ERROR(rc)) {
+ return rc;
+ }
+
+ rc = uefi_call_wrapper(pciio->Pci.Read, 5, pciio, EfiPciIoWidthUint32,
+ EFI_FIELD_OFFSET(lpcif_t, rcba), 1, &lpcif.rcba);
+ if (EFI_ERROR(rc))
+ return rc;
+ if (!(lpcif.rcba & 1)) {
+ Print(L"rcrb is not mapped, cannot route port 80h\n");
+ return EFI_UNSUPPORTED;
+ }
+ lpcif.rcba &= ~1UL;
+
+ Print(L"rcba: 0x%8x\n", lpcif.rcba, lpcif.rcba);
+ set_bit((uint32_t *)(uint64_t)(lpcif.rcba + GCS_OFFSET_ADDR),
+ GCS_RPR_SHIFT, GCS_RPR_PCI);
+
+ return EFI_SUCCESS;
+}
diff --git a/apps/t.c b/apps/t.c
new file mode 100644
index 0000000..c7e3d57
--- /dev/null
+++ b/apps/t.c
@@ -0,0 +1,27 @@
+#include <efi.h>
+#include <efilib.h>
+
+static CHAR16 *
+a2u (char *str)
+{
+ static CHAR16 mem[2048];
+ int i;
+
+ for (i = 0; str[i]; ++i)
+ mem[i] = (CHAR16) str[i];
+ mem[i] = 0;
+ return mem;
+}
+
+EFI_STATUS
+efi_main (EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *systab)
+{
+ SIMPLE_TEXT_OUTPUT_INTERFACE *conout;
+
+ InitializeLib(image_handle, systab);
+ conout = systab->ConOut;
+ uefi_call_wrapper(conout->OutputString, 2, conout, (CHAR16 *)L"Hello World!\n\r");
+ uefi_call_wrapper(conout->OutputString, 2, conout, a2u("Hello World!\n\r"));
+
+ return EFI_SUCCESS;
+}
diff --git a/apps/t2.c b/apps/t2.c
new file mode 100644
index 0000000..6a5d016
--- /dev/null
+++ b/apps/t2.c
@@ -0,0 +1,13 @@
+#include <efi.h>
+#include <efilib.h>
+
+EFI_STATUS
+efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
+{
+ SIMPLE_TEXT_OUTPUT_INTERFACE *conout;
+
+ conout = systab->ConOut;
+ uefi_call_wrapper(conout->OutputString, 2, conout, L"Hello World!\n\r");
+
+ return EFI_SUCCESS;
+}
diff --git a/apps/t3.c b/apps/t3.c
new file mode 100644
index 0000000..623830a
--- /dev/null
+++ b/apps/t3.c
@@ -0,0 +1,95 @@
+#include <efi.h>
+#include <efilib.h>
+
+EFI_STATUS
+efi_main(
+ EFI_HANDLE image_handle,
+ EFI_SYSTEM_TABLE *systab
+)
+{
+ EFI_GUID loaded_image_protocol = LOADED_IMAGE_PROTOCOL;
+ EFI_STATUS efi_status;
+ EFI_LOADED_IMAGE *li;
+ UINTN pat = PoolAllocationType;
+ VOID *void_li_p;
+
+ InitializeLib(image_handle, systab);
+ PoolAllocationType = 2; /* klooj */
+
+ Print(L"Hello World! (0xd=0x%x, 13=%d)\n", 13, 13);
+
+ Print(L"before InitializeLib(): PoolAllocationType=%d\n",
+ pat);
+
+ Print(L" after InitializeLib(): PoolAllocationType=%d\n",
+ PoolAllocationType);
+
+ /*
+ * Locate loaded_image_handle instance.
+ */
+
+ Print(L"BS->HandleProtocol() ");
+
+ efi_status = uefi_call_wrapper(
+ BS->HandleProtocol,
+ 3,
+ image_handle,
+ &loaded_image_protocol,
+ &void_li_p);
+ li = void_li_p;
+
+ Print(L"%xh (%r)\n", efi_status, efi_status);
+
+ if (efi_status != EFI_SUCCESS) {
+ return efi_status;
+ }
+
+ Print(L" li: %xh\n", li);
+
+ if (!li) {
+ return EFI_UNSUPPORTED;
+ }
+
+ Print(L" li->Revision: %xh\n", li->Revision);
+ Print(L" li->ParentHandle: %xh\n", li->ParentHandle);
+ Print(L" li->SystemTable: %xh\n", li->SystemTable);
+ Print(L" li->DeviceHandle: %xh\n", li->DeviceHandle);
+ Print(L" li->FilePath: %xh\n", li->FilePath);
+ Print(L" li->Reserved: %xh\n", li->Reserved);
+ Print(L" li->LoadOptionsSize: %xh\n", li->LoadOptionsSize);
+ Print(L" li->LoadOptions: %xh\n", li->LoadOptions);
+ Print(L" li->ImageBase: %xh\n", li->ImageBase);
+ Print(L" li->ImageSize: %xh\n", li->ImageSize);
+ Print(L" li->ImageCodeType: %xh\n", li->ImageCodeType);
+ Print(L" li->ImageDataType: %xh\n", li->ImageDataType);
+ Print(L" li->Unload: %xh\n", li->Unload);
+
+#if 0
+typedef struct {
+ UINT32 Revision;
+ EFI_HANDLE ParentHandle;
+ struct _EFI_SYSTEM_TABLE *SystemTable;
+
+ // Source location of image
+ EFI_HANDLE DeviceHandle;
+ EFI_DEVICE_PATH *FilePath;
+ VOID *Reserved;
+
+ // Images load options
+ UINT32 LoadOptionsSize;
+ VOID *LoadOptions;
+
+ // Location of where image was loaded
+ VOID *ImageBase;
+ UINT64 ImageSize;
+ EFI_MEMORY_TYPE ImageCodeType;
+ EFI_MEMORY_TYPE ImageDataType;
+
+ // If the driver image supports a dynamic unload request
+ EFI_IMAGE_UNLOAD Unload;
+
+} EFI_LOADED_IMAGE;
+#endif
+
+ return EFI_SUCCESS;
+}
diff --git a/apps/t4.c b/apps/t4.c
new file mode 100644
index 0000000..664048d
--- /dev/null
+++ b/apps/t4.c
@@ -0,0 +1,13 @@
+#include <efi.h>
+#include <efilib.h>
+
+EFI_STATUS
+efi_main (EFI_HANDLE *image, EFI_SYSTEM_TABLE *systab)
+{
+ UINTN index;
+
+ uefi_call_wrapper(systab->ConOut->OutputString, 2, systab->ConOut, L"Hello application started\r\n");
+ uefi_call_wrapper(systab->ConOut->OutputString, 2, systab->ConOut, L"\r\n\r\n\r\nHit any key to exit\r\n");
+ uefi_call_wrapper(systab->BootServices->WaitForEvent, 3, 1, &systab->ConIn->WaitForKey, &index);
+ return EFI_SUCCESS;
+}
diff --git a/apps/t5.c b/apps/t5.c
new file mode 100644
index 0000000..7c868d2
--- /dev/null
+++ b/apps/t5.c
@@ -0,0 +1,13 @@
+#include <efi.h>
+#include <efilib.h>
+
+EFI_STATUS
+efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
+{
+ InitializeLib(image, systab);
+ Print(L"HelloLib application started\n");
+ Print(L"\n\n\nHit any key to exit this image\n");
+ WaitForSingleEvent(ST->ConIn->WaitForKey, 0);
+ uefi_call_wrapper(ST->ConOut->OutputString, 2, ST->ConOut, L"\n\n");
+ return EFI_SUCCESS;
+}
diff --git a/apps/t6.c b/apps/t6.c
new file mode 100644
index 0000000..f95ea66
--- /dev/null
+++ b/apps/t6.c
@@ -0,0 +1,43 @@
+#include <efi.h>
+#include <efilib.h>
+
+typedef EFI_STATUS (*foo_t)(EFI_HANDLE, EFI_GUID *, VOID **);
+typedef struct {
+ unsigned long addr;
+ unsigned long gp;
+} fdesc_t;
+
+EFI_LOADED_IMAGE my_loaded;
+
+EFI_STATUS
+efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
+{
+ EFI_LOADED_IMAGE *loaded_image = NULL;
+#if 0
+ EFI_DEVICE_PATH *dev_path;
+#endif
+ EFI_STATUS status;
+
+ InitializeLib(image, systab);
+ status = uefi_call_wrapper(systab->BootServices->HandleProtocol,
+ 3,
+ image,
+ &LoadedImageProtocol,
+ (void **) &loaded_image);
+ if (EFI_ERROR(status)) {
+ Print(L"handleprotocol: %r\n", status);
+ }
+
+#if 0
+ BS->HandleProtocol(loaded_image->DeviceHandle, &DevicePathProtocol, (void **) &dev_path);
+
+ Print(L"Image device : %s\n", DevicePathToStr(dev_path));
+ Print(L"Image file : %s\n", DevicePathToStr(loaded_image->FilePath));
+#endif
+ Print(L"Image base : %lx\n", loaded_image->ImageBase);
+ Print(L"Image size : %lx\n", loaded_image->ImageSize);
+ Print(L"Load options size : %lx\n", loaded_image->LoadOptionsSize);
+ Print(L"Load options : %s\n", loaded_image->LoadOptions);
+
+ return EFI_SUCCESS;
+}
diff --git a/apps/t7.c b/apps/t7.c
new file mode 100644
index 0000000..a1df818
--- /dev/null
+++ b/apps/t7.c
@@ -0,0 +1,25 @@
+#include <efi.h>
+#include <efilib.h>
+
+EFI_STATUS
+efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
+{
+ EFI_INPUT_KEY efi_input_key;
+ EFI_STATUS efi_status;
+
+ InitializeLib(image, systab);
+
+ Print(L"HelloLib application started\n");
+
+ Print(L"\n\n\nHit any key to exit this image\n");
+ WaitForSingleEvent(ST->ConIn->WaitForKey, 0);
+
+ uefi_call_wrapper(ST->ConOut->OutputString, 2, ST->ConOut, L"\n\n");
+
+ efi_status = uefi_call_wrapper(ST->ConIn->ReadKeyStroke, 2, ST->ConIn, &efi_input_key);
+
+ Print(L"ScanCode: %xh UnicodeChar: %xh\n",
+ efi_input_key.ScanCode, efi_input_key.UnicodeChar);
+
+ return EFI_SUCCESS;
+}
diff --git a/apps/t8.c b/apps/t8.c
new file mode 100644
index 0000000..10f8811
--- /dev/null
+++ b/apps/t8.c
@@ -0,0 +1,19 @@
+#include <efi.h>
+#include <efilib.h>
+
+EFI_STATUS
+efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
+{
+ INTN Argc, i;
+ CHAR16 **Argv;
+
+ InitializeLib(ImageHandle, SystemTable);
+ Argc = GetShellArgcArgv(ImageHandle, &Argv);
+
+ Print(L"Hello World, started with Argc=%d\n", Argc);
+ for (i = 0 ; i < Argc ; ++i)
+ Print(L" Argv[%d] = '%s'\n", i, Argv[i]);
+
+ Print(L"Bye.\n");
+ return EFI_SUCCESS;
+}
diff --git a/apps/tcc.c b/apps/tcc.c
new file mode 100644
index 0000000..2d84a99
--- /dev/null
+++ b/apps/tcc.c
@@ -0,0 +1,442 @@
+/*
+ * Test if our calling convention gymnastics actually work
+ */
+
+#include <efi.h>
+#include <efilib.h>
+
+#ifdef __x86_64__
+#include <x86_64/pe.h>
+#include <x86_64/efibind.h>
+#endif
+
+#if 0
+ asm volatile("out %0,%1" : : "a" ((uint8_t)a), "dN" (0x80));
+
+extern void dump_stack(void);
+asm( ".globl dump_stack\n"
+ "dump_stack:\n"
+ " movq %rsp, %rdi\n"
+ " jmp *dump_stack_helper@GOTPCREL(%rip)\n"
+ ".size dump_stack, .-dump_stack");
+
+void dump_stack_helper(uint64_t rsp_val)
+{
+ uint64_t *rsp = (uint64_t *)rsp_val;
+ int x;
+
+ Print(L"%%rsp: 0x%08x%08x stack:\r\n",
+ (rsp_val & 0xffffffff00000000) >>32,
+ rsp_val & 0xffffffff);
+ for (x = 0; x < 8; x++) {
+ Print(L"%08x: ", ((uint64_t)rsp) & 0xffffffff);
+ Print(L"%016x ", *rsp++);
+ Print(L"%016x ", *rsp++);
+ Print(L"%016x ", *rsp++);
+ Print(L"%016x\r\n", *rsp++);
+ }
+}
+#endif
+
+EFI_STATUS EFI_FUNCTION test_failure_callback(void)
+{
+ return EFI_UNSUPPORTED;
+}
+
+EFI_STATUS test_failure(void)
+{
+ return uefi_call_wrapper(test_failure_callback, 0);
+}
+
+EFI_STATUS EFI_FUNCTION test_call0_callback(void)
+{
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS test_call0(void)
+{
+ return uefi_call_wrapper(test_call0_callback, 0);
+}
+
+EFI_STATUS EFI_FUNCTION test_call1_callback(UINT32 a)
+{
+ if (a != 0x12345678) {
+ return EFI_LOAD_ERROR;
+ }
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS test_call1(void)
+{
+ return uefi_call_wrapper(test_call1_callback, 1,0x12345678);
+}
+
+EFI_STATUS EFI_FUNCTION test_call2_callback(UINT32 a, UINT32 b)
+{
+ if (a != 0x12345678) {
+ return EFI_LOAD_ERROR;
+ }
+ if (b != 0x23456789) {
+ return EFI_INVALID_PARAMETER;
+ }
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS test_call2(void)
+{
+ return uefi_call_wrapper(test_call2_callback, 2,
+ 0x12345678, 0x23456789);
+}
+
+EFI_STATUS EFI_FUNCTION test_call3_callback(UINT32 a, UINT32 b,
+ UINT32 c)
+{
+ if (a != 0x12345678)
+ return EFI_LOAD_ERROR;
+ if (b != 0x23456789)
+ return EFI_INVALID_PARAMETER;
+ if (c != 0x3456789a)
+ return EFI_UNSUPPORTED;
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS test_call3(void)
+{
+ return uefi_call_wrapper(test_call3_callback, 3,
+ 0x12345678, 0x23456789, 0x3456789a);
+}
+
+EFI_STATUS EFI_FUNCTION test_call4_callback(UINT32 a, UINT32 b,
+ UINT32 c, UINT32 d)
+{
+ if (a != 0x12345678)
+ return EFI_LOAD_ERROR;
+ if (b != 0x23456789)
+ return EFI_INVALID_PARAMETER;
+ if (c != 0x3456789a)
+ return EFI_UNSUPPORTED;
+ if (d != 0x456789ab)
+ return EFI_BAD_BUFFER_SIZE;
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS test_call4(void)
+{
+ return uefi_call_wrapper(test_call4_callback, 4,
+ 0x12345678, 0x23456789, 0x3456789a, 0x456789ab);
+}
+
+EFI_STATUS EFI_FUNCTION test_call5_callback(UINT32 a, UINT32 b,
+ UINT32 c, UINT32 d, UINT32 e)
+{
+ if (a != 0x12345678)
+ return EFI_LOAD_ERROR;
+ if (b != 0x23456789)
+ return EFI_INVALID_PARAMETER;
+ if (c != 0x3456789a)
+ return EFI_UNSUPPORTED;
+ if (d != 0x456789ab)
+ return EFI_BAD_BUFFER_SIZE;
+ if (e != 0x56789abc)
+ return EFI_BUFFER_TOO_SMALL;
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS test_call5(void)
+{
+ return uefi_call_wrapper(test_call5_callback, 5,
+ 0x12345678, 0x23456789, 0x3456789a, 0x456789ab, 0x56789abc);
+}
+
+EFI_STATUS EFI_FUNCTION test_call6_callback(UINT32 a, UINT32 b,
+ UINT32 c, UINT32 d, UINT32 e, UINT32 f)
+{
+ if (a != 0x12345678)
+ return EFI_LOAD_ERROR;
+ if (b != 0x23456789)
+ return EFI_INVALID_PARAMETER;
+ if (c != 0x3456789a)
+ return EFI_UNSUPPORTED;
+ if (d != 0x456789ab)
+ return EFI_BAD_BUFFER_SIZE;
+ if (e != 0x56789abc)
+ return EFI_BUFFER_TOO_SMALL;
+ if (f != 0x6789abcd)
+ return EFI_NOT_READY;
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS test_call6(void)
+{
+ return uefi_call_wrapper(test_call6_callback, 6,
+ 0x12345678, 0x23456789, 0x3456789a, 0x456789ab, 0x56789abc,
+ 0x6789abcd);
+}
+
+EFI_STATUS EFI_FUNCTION test_call7_callback(UINT32 a, UINT32 b,
+ UINT32 c, UINT32 d, UINT32 e, UINT32 f, UINT32 g)
+{
+ if (a != 0x12345678)
+ return EFI_LOAD_ERROR;
+ if (b != 0x23456789)
+ return EFI_INVALID_PARAMETER;
+ if (c != 0x3456789a)
+ return EFI_UNSUPPORTED;
+ if (d != 0x456789ab)
+ return EFI_BAD_BUFFER_SIZE;
+ if (e != 0x56789abc)
+ return EFI_BUFFER_TOO_SMALL;
+ if (f != 0x6789abcd)
+ return EFI_NOT_READY;
+ if (g != 0x789abcde)
+ return EFI_DEVICE_ERROR;
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS test_call7(void)
+{
+ return uefi_call_wrapper(test_call7_callback, 7,
+ 0x12345678, 0x23456789, 0x3456789a, 0x456789ab,
+ 0x56789abc, 0x6789abcd, 0x789abcde);
+}
+
+EFI_STATUS EFI_FUNCTION test_call8_callback(UINT32 a, UINT32 b,
+ UINT32 c, UINT32 d, UINT32 e, UINT32 f, UINT32 g, UINT32 h)
+{
+ if (a != 0x12345678)
+ return EFI_LOAD_ERROR;
+ if (b != 0x23456789)
+ return EFI_INVALID_PARAMETER;
+ if (c != 0x3456789a)
+ return EFI_UNSUPPORTED;
+ if (d != 0x456789ab)
+ return EFI_BAD_BUFFER_SIZE;
+ if (e != 0x56789abc)
+ return EFI_BUFFER_TOO_SMALL;
+ if (f != 0x6789abcd)
+ return EFI_NOT_READY;
+ if (g != 0x789abcde)
+ return EFI_DEVICE_ERROR;
+ if (h != 0x89abcdef)
+ return EFI_WRITE_PROTECTED;
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS test_call8(void)
+{
+ return uefi_call_wrapper(test_call8_callback, 8,
+ 0x12345678,
+ 0x23456789,
+ 0x3456789a,
+ 0x456789ab,
+ 0x56789abc,
+ 0x6789abcd,
+ 0x789abcde,
+ 0x89abcdef);
+}
+
+EFI_STATUS EFI_FUNCTION test_call9_callback(UINT32 a, UINT32 b,
+ UINT32 c, UINT32 d, UINT32 e, UINT32 f, UINT32 g, UINT32 h, UINT32 i)
+{
+ if (a != 0x12345678)
+ return EFI_LOAD_ERROR;
+ if (b != 0x23456789)
+ return EFI_INVALID_PARAMETER;
+ if (c != 0x3456789a)
+ return EFI_UNSUPPORTED;
+ if (d != 0x456789ab)
+ return EFI_BAD_BUFFER_SIZE;
+ if (e != 0x56789abc)
+ return EFI_BUFFER_TOO_SMALL;
+ if (f != 0x6789abcd)
+ return EFI_NOT_READY;
+ if (g != 0x789abcde)
+ return EFI_DEVICE_ERROR;
+ if (h != 0x89abcdef)
+ return EFI_WRITE_PROTECTED;
+ if (i != 0x9abcdef0)
+ return EFI_OUT_OF_RESOURCES;
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS test_call9(void)
+{
+ return uefi_call_wrapper(test_call9_callback, 9,
+ 0x12345678,
+ 0x23456789,
+ 0x3456789a,
+ 0x456789ab,
+ 0x56789abc,
+ 0x6789abcd,
+ 0x789abcde,
+ 0x89abcdef,
+ 0x9abcdef0);
+}
+
+extern EFI_STATUS test_call10(void);
+EFI_STATUS EFI_FUNCTION test_call10_callback(UINT32 a, UINT32 b,
+ UINT32 c, UINT32 d, UINT32 e, UINT32 f, UINT32 g, UINT32 h, UINT32 i,
+ UINT32 j)
+{
+ if (a != 0x12345678)
+ return EFI_LOAD_ERROR;
+ if (b != 0x23456789)
+ return EFI_INVALID_PARAMETER;
+ if (c != 0x3456789a)
+ return EFI_UNSUPPORTED;
+ if (d != 0x456789ab)
+ return EFI_BAD_BUFFER_SIZE;
+ if (e != 0x56789abc)
+ return EFI_BUFFER_TOO_SMALL;
+ if (f != 0x6789abcd)
+ return EFI_NOT_READY;
+ if (g != 0x789abcde)
+ return EFI_DEVICE_ERROR;
+ if (h != 0x89abcdef)
+ return EFI_WRITE_PROTECTED;
+ if (i != 0x9abcdef0)
+ return EFI_OUT_OF_RESOURCES;
+ if (j != 0xabcdef01)
+ return EFI_VOLUME_CORRUPTED;
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS test_call10(void)
+{
+ return uefi_call_wrapper(test_call10_callback, 10,
+ 0x12345678,
+ 0x23456789,
+ 0x3456789a,
+ 0x456789ab,
+ 0x56789abc,
+ 0x6789abcd,
+ 0x789abcde,
+ 0x89abcdef,
+ 0x9abcdef0,
+ 0xabcdef01);
+}
+
+EFI_STATUS
+efi_main (EFI_HANDLE *image, EFI_SYSTEM_TABLE *systab)
+{
+ EFI_STATUS rc = EFI_SUCCESS;
+
+ InitializeLib(image, systab);
+ PoolAllocationType = 2; /* klooj */
+
+#ifndef __x86_64__
+ uefi_call_wrapper(systab->ConOut->OutputString, 2, systab->ConOut,
+ L"This test is only valid on x86_64\n");
+ return EFI_UNSUPPORTED;
+#endif
+
+ __asm__ volatile("out %0,%1" : : "a" ((uint8_t)0x14), "dN" (0x80));
+
+ Print(L"Hello\r\n");
+ rc = test_failure();
+ if (EFI_ERROR(rc)) {
+ Print(L"Returning Failure works\n");
+ } else {
+ Print(L"Returning failure doesn't work.\r\n");
+ Print(L"%%rax was 0x%016x, should have been 0x%016x\n",
+ rc, EFI_UNSUPPORTED);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ rc = test_call0();
+ if (!EFI_ERROR(rc)) {
+ Print(L"0 args works just fine here.\r\n");
+ } else {
+ Print(L"0 args failed: 0x%016x\n", rc);
+ return rc;
+ }
+
+ rc = test_call1();
+ if (!EFI_ERROR(rc)) {
+ Print(L"1 arg works just fine here.\r\n");
+ } else {
+ Print(L"1 arg failed: 0x%016x\n", rc);
+ return rc;
+ }
+
+ rc = test_call2();
+ if (!EFI_ERROR(rc)) {
+ Print(L"2 args works just fine here.\r\n");
+ } else {
+ Print(L"2 args failed: 0x%016x\n", rc);
+ return rc;
+ }
+
+ rc = test_call3();
+ if (!EFI_ERROR(rc)) {
+ Print(L"3 args works just fine here.\r\n");
+ } else {
+ Print(L"3 args failed: 0x%016x\n", rc);
+ return rc;
+ }
+
+ rc = test_call4();
+ if (!EFI_ERROR(rc)) {
+ Print(L"4 args works just fine here.\r\n");
+ } else {
+ Print(L"4 args failed: 0x%016x\n", rc);
+ return rc;
+ }
+
+ rc = test_call5();
+ if (!EFI_ERROR(rc)) {
+ Print(L"5 args works just fine here.\r\n");
+ } else {
+ Print(L"5 args failed: 0x%016x\n", rc);
+ return rc;
+ }
+
+ rc = test_call6();
+ if (!EFI_ERROR(rc)) {
+ Print(L"6 args works just fine here.\r\n");
+ } else {
+ Print(L"6 args failed: 0x%016x\n", rc);
+ return rc;
+ }
+
+ rc = test_call7();
+ if (!EFI_ERROR(rc)) {
+ Print(L"7 args works just fine here.\r\n");
+ } else {
+ Print(L"7 args failed: 0x%016x\n", rc);
+ return rc;
+ }
+
+ rc = test_call8();
+ if (!EFI_ERROR(rc)) {
+ Print(L"8 args works just fine here.\r\n");
+ } else {
+ Print(L"8 args failed: 0x%016x\n", rc);
+ return rc;
+ }
+
+ rc = test_call9();
+ if (!EFI_ERROR(rc)) {
+ Print(L"9 args works just fine here.\r\n");
+ } else {
+ Print(L"9 args failed: 0x%016x\n", rc);
+ return rc;
+ }
+
+ rc = test_call10();
+ if (!EFI_ERROR(rc)) {
+ Print(L"10 args works just fine here.\r\n");
+ } else {
+ Print(L"10 args failed: 0x%016x\n", rc);
+ return rc;
+ }
+
+ return rc;
+}
diff --git a/apps/tpause.c b/apps/tpause.c
new file mode 100644
index 0000000..51c86df
--- /dev/null
+++ b/apps/tpause.c
@@ -0,0 +1,9 @@
+#include <efi.h>
+#include <efilib.h>
+
+EFI_STATUS
+efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
+{
+ Print(L"Press `q' to quit, any other key to continue:\n");
+
+}
diff --git a/apps/trivial.S b/apps/trivial.S
new file mode 100644
index 0000000..40bc68f
--- /dev/null
+++ b/apps/trivial.S
@@ -0,0 +1,43 @@
+ .text
+ .align 4
+
+ .globl _start
+_start:
+#if 0
+ pushl %ebp
+ movl %esp,%ebp
+ pushl %ebx # save ebx
+ movl 12(%ebp),%eax # eax <- systab
+ movl 24(%eax),%ebx # ebx <- systab->FirmwareVendor
+ pushl %ebx
+ movl 44(%eax),%ebx # ebx <- systab->ConOut
+ pushl %ebx
+ movl 4(%ebx),%eax # eax <- conout->OutputString
+ call *%eax
+ movl -4(%ebp),%ebx # restore ebx
+ leave
+ ret
+
+#else
+
+ pushl %ebp
+ movl %esp,%ebp
+ pushl %ebx
+ call 0f
+0: popl %eax
+ addl $hello-0b,%eax
+ pushl %eax
+ movl 12(%ebp),%eax # eax <- systab
+ movl 44(%eax),%ebx # ebx <- systab->ConOut
+ pushl %ebx
+ movl 4(%ebx),%eax # eax <- conout->OutputString
+ call *%eax
+ movl -4(%ebp),%ebx
+ leave
+ ret
+
+ .section .rodata
+ .align 2
+hello: .byte 'h',0,'e',0,'l',0,'l',0,'o',0,'\n',0,'\r',0,0,0
+
+#endif