summaryrefslogtreecommitdiffstats
path: root/GNU_efi_HelloWorld
diff options
context:
space:
mode:
authorRegina König2022-09-07 23:24:55 +0200
committerRegina König2022-09-07 23:24:55 +0200
commit09e1b4fb40878ef29b8ca36b93172fcd89c70883 (patch)
treef731cd63f8a6511d1b1bbad6ed4eb01111e77995 /GNU_efi_HelloWorld
parenthiuhi (diff)
parentRename dir and experiment with cmdline options (diff)
downloadmemtest86-master.tar.gz
memtest86-master.tar.xz
memtest86-master.zip
Merge branch 'master' of git.openslx.org:openslx-ng/memtest86HEADmaster
Diffstat (limited to 'GNU_efi_HelloWorld')
-rw-r--r--GNU_efi_HelloWorld/.gitignore3
-rw-r--r--GNU_efi_HelloWorld/Makefile49
-rw-r--r--GNU_efi_HelloWorld/Makefile_save36
-rw-r--r--GNU_efi_HelloWorld/example_Makefile96
-rw-r--r--GNU_efi_HelloWorld/gdb_procedure24
-rw-r--r--GNU_efi_HelloWorld/hello.c37
-rwxr-xr-xGNU_efi_HelloWorld/hello.debugbin0 -> 123240 bytes
-rwxr-xr-xGNU_efi_HelloWorld/hello.efibin0 -> 46888 bytes
-rwxr-xr-xGNU_efi_HelloWorld/peinfobin0 -> 27600 bytes
9 files changed, 245 insertions, 0 deletions
diff --git a/GNU_efi_HelloWorld/.gitignore b/GNU_efi_HelloWorld/.gitignore
new file mode 100644
index 0000000..0bf07f1
--- /dev/null
+++ b/GNU_efi_HelloWorld/.gitignore
@@ -0,0 +1,3 @@
+gnu-efi
+*.o
+*.so
diff --git a/GNU_efi_HelloWorld/Makefile b/GNU_efi_HelloWorld/Makefile
new file mode 100644
index 0000000..63deda2
--- /dev/null
+++ b/GNU_efi_HelloWorld/Makefile
@@ -0,0 +1,49 @@
+ARCH = $(shell uname -m | sed s,i[3456789]86,ia32,)
+
+OBJS = hello.o
+TARGET = hello.efi
+TARGET_DEBUG = hello.debug
+
+EFIINC = /usr/include/efi
+EFFINCS = -I$(EFIINC) -I$(EFIINC)/$(ARCH) -I$(EFIINC)/protocol
+EFILIB = /usr/lib
+EFI_CRT_OBJS = $(EFILIB)/crt0-efi-$(ARCH).o
+EFI_LDS = $(EFILIB)/elf_$(ARCH)_efi.lds
+
+CFLAGS = $(EFFINCS) -fno-stack-protector -fpic \
+ -fshort-wchar -mno-red-zone -Wall
+CFLAGS += -ggdb3 -O0 -DEFI_DEBUG=1
+# -DDEBUG
+
+
+ifeq ($(ARCH),x86_64)
+ CFLAGS += -DEFI_FUNCTION_WRAPPER
+endif
+
+LDFLAGS = -nostdlib -znocombreloc -T $(EFI_LDS) -shared \
+ -Bsymbolic -L $(EFILIB) $(EFI_CRT_OBJS)
+
+SECTIONS = .text .sdata .data .dynamic .dynsym .rel .rela .reloc
+
+DEBUG_SECTIONS = .debug_info .debug_abbrev .debug_aranges \
+ .debug_line .debug_str
+
+all: clear $(TARGET) $(TARGET_DEBUG)
+ cp hello.efi ../test_code/hda-contents/
+
+hello.so: $(OBJS)
+ ld $(LDFLAGS) $(OBJS) -o $@ -lefi -lgnuefi
+
+%.efi: %.so
+ objcopy $(foreach sec,$(SECTIONS),-j $(sec)) \
+ --target=efi-app-$(ARCH) $^ $@
+
+%.debug: %.so
+ objcopy $(foreach sec,$(SECTIONS) $(DEBUG_SECTIONS),-j $(sec)) \
+ --target=efi-app-$(ARCH) $^ $@
+
+clear:
+ rm -f *.efi
+ rm -f *.debug
+ rm -f *.o
+ rm -f *.so
diff --git a/GNU_efi_HelloWorld/Makefile_save b/GNU_efi_HelloWorld/Makefile_save
new file mode 100644
index 0000000..6ae963d
--- /dev/null
+++ b/GNU_efi_HelloWorld/Makefile_save
@@ -0,0 +1,36 @@
+ARCH = $(shell uname -m | sed s,i[3456789]86,ia32,)
+
+OBJS = hello.o
+TARGET = hello.efi
+
+EFIINC = /usr/include/efi
+EFFINCS = -I$(EFIINC) -I$(EFIINC)/$(ARCH) -I$(EFIINC)/protocol
+EFILIB = /usr/lib
+EFI_CRT_OBJS = $(EFILIB)/crt0-efi-$(ARCH).o
+EFI_LDS = $(EFILIB)/elf_$(ARCH)_efi.lds
+
+CFLAGS = $(EFFINCS) -fno-stack-protector -fpic \
+ -fshort-wchar -mno-red-zone -Wall
+
+ifeq ($(ARCH),x86_64)
+ CFLAGS += -DEFI_FUNCTION_WRAPPER
+endif
+
+LDFLAGS = -nostdlib -znocombreloc -T $(EFI_LDS) -shared \
+ -Bsymbolic -L $(EFILIB) $(EFI_CRT_OBJS)
+
+all: $(TARGET)
+ cp hello.efi ../test_code/hda-contents/
+
+hello.so: $(OBJS)
+ ld $(LDFLAGS) $(OBJS) -o $@ -lefi -lgnuefi
+
+%.efi: %.so
+ objcopy -j .text -j .sdata -j .data -j .dynamic \
+ -j .dynsym -j .rel -j .rela -j .reloc \
+ --target=efi-app-$(ARCH) $^ $@
+
+clear:
+ rm *.efi
+ rm *.o
+ rm *.so
diff --git a/GNU_efi_HelloWorld/example_Makefile b/GNU_efi_HelloWorld/example_Makefile
new file mode 100644
index 0000000..f62df60
--- /dev/null
+++ b/GNU_efi_HelloWorld/example_Makefile
@@ -0,0 +1,96 @@
+# /phoenix/kernel/boot/Makefile
+#
+# This file is a part of Phoenix operating system.
+# Copyright (c) 2011-2012, Artyom Lebedev <artyom.lebedev@gmail.com>
+# All rights reserved.
+# See COPYING file for copyright details.
+
+include $(PHOENIX_ROOT)/make/makevar.mak
+
+LOADER_BINARY = phoenix.efi
+
+COMPILE_DIR = build
+OBJ_DIR = $(COMPILE_DIR)/$(PHOENIX_TARGET)
+
+SUBDIRS = gnuefi lib lib/runtime lib/x86_64 loader \
+ $(PHOENIX_ROOT)/lib/common $(PHOENIX_ROOT)/lib/elf
+
+EFI_IMAGE = $(OBJ_DIR)/$(LOADER_BINARY)
+EFI_DEBUG_IMAGE = $(OBJ_DIR)/debug.$(LOADER_BINARY)
+ELF_IMAGE = $(OBJ_DIR)/elf_image.so
+
+SRCS = $(foreach dir,$(SUBDIRS),$(wildcard $(dir)/*.S $(dir)/*.c $(dir)/*.cpp))
+
+$(foreach dir,$(SUBDIRS),$(eval vpath %.S $(dir)) $(eval vpath %.c $(dir)) $(eval vpath %.cpp $(dir)))
+
+OBJS = $(foreach src,$(SRCS), \
+ $(OBJ_DIR)/$(patsubst %.cpp,%.o,$(patsubst %.c,%.o,$(patsubst %.S,%.o,$(notdir $(src))))))
+DEPS = $(OBJS:.o=.d)
+
+CFLAGS = $(GLOBAL_C_FLAGS) $(C_STANDARD) -Wno-pointer-sign
+
+CPP_FLAGS = $(GLOBAL_CXX_FLAGS) $(CXX_STANDARD) $(CXX_RESTRICTIONS) \
+ -fno-exceptions -fno-rtti
+
+COMMON_FLAGS = $(GLOBAL_FLAGS) -fpic -Wall -Werror -fshort-wchar \
+ -fno-strict-aliasing -fno-merge-constants -DEFI_FUNCTION_WRAPPER \
+ -mno-red-zone -DCONFIG_x86_64 -DBOOT_LOADER -DEFI_APP \
+ -DKERNEL_ADDRESS=$(KERNEL_ADDRESS)
+
+SECTIONS = .text .sdata .data .dynamic .dynsym .rel .rela .reloc
+DEBUG_SECTIONS = .debug_info .debug_abbrev .debug_loc .debug_aranges \
+ .debug_line .debug_macinfo .debug_str
+
+ifeq ($(PHOENIX_TARGET),RELEASE)
+COMMON_FLAGS += -O2
+else ifeq ($(PHOENIX_TARGET),DEBUG)
+COMMON_FLAGS += -ggdb3 -O0 -DDEBUG -DEFI_DEBUG=1
+else
+$(error Target not supported: $(PHOENIX_TARGET))
+endif
+
+INCLUDE_DIRS = inc inc/protocol inc/x86_64 lib \
+ $(PHOENIX_ROOT)/kernel/sys $(PHOENIX_ROOT)/kernel/sys/arch/$(PHOENIX_ARCH) \
+ $(PHOENIX_ROOT)/include $(PHOENIX_ROOT)/lib/elf
+
+IFLAGS = $(foreach incdir,$(INCLUDE_DIRS),-I$(incdir))
+
+LD_SCRIPT = gnuefi/elf_x86_64_efi.lds
+
+LDFLAGS = -nostdlib -T $(LD_SCRIPT) -shared -Bsymbolic --unresolved-symbols=report-all
+
+.PHONY: all clean
+
+all: $(EFI_IMAGE) $(EFI_DEBUG_IMAGE)
+
+# include dependencies if exist
+-include $(DEPS)
+
+$(EFI_IMAGE): $(ELF_IMAGE)
+ $(OBJCOPY) $(foreach sec,$(SECTIONS),-j $(sec)) --target=efi-app-x86_64 $< $@
+
+$(EFI_DEBUG_IMAGE): $(ELF_IMAGE)
+ $(OBJCOPY) $(foreach sec,$(SECTIONS) $(DEBUG_SECTIONS),-j $(sec)) --target=efi-app-x86_64 $< $@
+
+$(ELF_IMAGE): $(OBJ_DIR) $(OBJS)
+ $(LD) $(LDFLAGS) $(OBJS) -o $@
+
+$(OBJ_DIR)/%.o: %.S
+ $(CC) -DCONFIG_x86_64 -c -o $@ $<
+
+$(OBJ_DIR)/%.o: %.c
+ $(CC) $(IFLAGS) $(COMMON_FLAGS) $(CFLAGS) -c -o $@ $<
+ $(CC) -MM -MT '$@' $(IFLAGS) $(COMMON_FLAGS) $(CFLAGS) -c -o $(@:.o=.d) $<
+
+$(OBJ_DIR)/%.o: %.cpp
+ $(CC) $(IFLAGS) $(COMMON_FLAGS) $(CPP_FLAGS) -c -o $@ $<
+ $(CC) -MM -MT '$@' $(IFLAGS) $(COMMON_FLAGS) $(CPP_FLAGS) -c -o $(@:.o=.d) $<
+
+$(COMPILE_DIR):
+ if [ ! -d $@ ]; then mkdir $@; fi
+
+$(OBJ_DIR): $(COMPILE_DIR)
+ if [ ! -d $@ ]; then mkdir $@; fi
+
+clean:
+ $(RM) -rf $(COMPILE_DIR)
diff --git a/GNU_efi_HelloWorld/gdb_procedure b/GNU_efi_HelloWorld/gdb_procedure
new file mode 100644
index 0000000..2ee853f
--- /dev/null
+++ b/GNU_efi_HelloWorld/gdb_procedure
@@ -0,0 +1,24 @@
+../test_code: ./test.sh --- and run hello.efi
+../test_code: cat debug.log | grep hello -A 5
+ Loading driver at 0x0000657B000 EntryPoint=0x0000657E000
+
+(gdb) file hda_contents/hello.efi
+(gbb) info files
+ ...
+ Entry point: 0x3000
+ 0x0000000000003000 - 0x0000000000008980 is .text
+ ...
+ 0x000000000000a000 - 0x000000000000bd00 is .data
+ ....
+(gdb) file // unload file
+(gdb) add-symbol-file ../GNU_efi_HelloWorld/hello.debug 0x657E000 -s .data 0x6585000
+
+(gdb) b efi_main
+(gdb) b *0x657e260
+(gdb) info b
+
+(gdb) target remote localhost:1234
+(gdb) c
+
+(gdb) layout asm
+(gdb) layout src
diff --git a/GNU_efi_HelloWorld/hello.c b/GNU_efi_HelloWorld/hello.c
new file mode 100644
index 0000000..f135c21
--- /dev/null
+++ b/GNU_efi_HelloWorld/hello.c
@@ -0,0 +1,37 @@
+#include <efi.h>
+#include <efilib.h>
+
+EFI_STATUS
+EFIAPI
+efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) {
+
+ EFI_LOADED_IMAGE *loaded_image = NULL;
+ EFI_STATUS status;
+
+ InitializeLib(ImageHandle, SystemTable);
+ Print(L"Hello, world!\n");
+
+ status = uefi_call_wrapper(SystemTable->BootServices->HandleProtocol,
+ 3,
+ ImageHandle,
+ &LoadedImageProtocol,
+ (void **)&loaded_image);
+
+ if (EFI_ERROR(status)) {
+ Print(L"handleprotocol: %r\n", status);
+ }
+
+ Print(L"Image base: 0x%lx\n", loaded_image->ImageBase);
+ Print(L"UefiMain: 0x%1x\n", (unsigned long)efi_main);
+
+ DEBUG((D_ERROR, (CHAR8*)"DEBUG_TEST DEBUG_TEST\r\n"));
+
+ DEBUG((D_ERROR, (CHAR8*)"My Entry Point: 0x%08x\r\n",(CHAR16*)efi_main));
+
+/* volatile int wait = 1;
+ while(wait) {
+ __asm__ __volatile__("pause");
+ }
+*/
+ return EFI_SUCCESS;
+}
diff --git a/GNU_efi_HelloWorld/hello.debug b/GNU_efi_HelloWorld/hello.debug
new file mode 100755
index 0000000..eb4117a
--- /dev/null
+++ b/GNU_efi_HelloWorld/hello.debug
Binary files differ
diff --git a/GNU_efi_HelloWorld/hello.efi b/GNU_efi_HelloWorld/hello.efi
new file mode 100755
index 0000000..90ef0e9
--- /dev/null
+++ b/GNU_efi_HelloWorld/hello.efi
Binary files differ
diff --git a/GNU_efi_HelloWorld/peinfo b/GNU_efi_HelloWorld/peinfo
new file mode 100755
index 0000000..4645ea4
--- /dev/null
+++ b/GNU_efi_HelloWorld/peinfo
Binary files differ