diff --git a/.clang-format b/.clang-format deleted file mode 100644 index 61ce89f..0000000 --- a/.clang-format +++ /dev/null @@ -1,10 +0,0 @@ ---- -DerivePointerAlignment: 'true' -SpaceBeforeParens: ControlStatements -UseTab: ForIndentation -IndentWidth: 2 -TabWidth: 2 -ColumnLimit: 120 -BreakBeforeBraces: Attach - -... diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..46fc397 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +*.sh eol=lf +Makefile eol=lf diff --git a/.gitignore b/.gitignore index 5cdcfc8..5fd5a25 100644 --- a/.gitignore +++ b/.gitignore @@ -1,59 +1,14 @@ - -# Created by https://www.gitignore.io/api/c -# Edit at https://www.gitignore.io/?templates=c - -### C ### -# Prerequisites -*.d - -# Object files *.o -*.ko -*.obj -*.elf - -# Linker output -*.ilk -*.map -*.exp - -# Precompiled Headers -*.gch -*.pch - -# Libraries -*.lib -*.a -*.la -*.lo - -# Shared objects (inc. Windows DLLs) -*.dll -*.so -*.so.* -*.dylib - -# Executables -*.exe -*.out -*.app -*.i*86 -*.x86_64 -*.hex - -# Debug files -*.dSYM/ -*.su -*.idb -*.pdb - -# Kernel Module Compile Results -*.mod* -*.cmd -.tmp_versions/ -modules.order -Module.symvers -Mkfile.old -dkms.conf - -# End of https://www.gitignore.io/api/c +*.efi +*.vhd +*.sdf +*.suo +*.opensdf +*.opendb +*.fd +*.db* +arm +aa64 +x86_64 +x86_32 +image diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..5c68af2 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "gnu-efi"] + path = gnu-efi + url = git://git.code.sf.net/p/gnu-efi/code + ignore = dirty diff --git a/.vs/ProjectSettings.json b/.vs/ProjectSettings.json new file mode 100644 index 0000000..0cf5ea5 --- /dev/null +++ b/.vs/ProjectSettings.json @@ -0,0 +1,3 @@ +{ + "CurrentProjectSetting": "No Configurations" +} \ No newline at end of file diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json new file mode 100644 index 0000000..159b892 --- /dev/null +++ b/.vs/VSWorkspaceState.json @@ -0,0 +1,9 @@ +{ + "ExpandedNodes": [ + "", + "\\arch", + "\\arch\\uefi" + ], + "SelectedNode": "\\.gitignore", + "PreviewInSolutionExplorer": false +} \ No newline at end of file diff --git a/.vs/red/v15/ipch/AutoPCH/1f7ce03d182abcf7/SYS_CLOCK.ipch b/.vs/red/v15/ipch/AutoPCH/1f7ce03d182abcf7/SYS_CLOCK.ipch new file mode 100644 index 0000000..e523eac Binary files /dev/null and b/.vs/red/v15/ipch/AutoPCH/1f7ce03d182abcf7/SYS_CLOCK.ipch differ diff --git a/.vs/red/v15/ipch/AutoPCH/349d759258598ef9/ENTRY.ipch b/.vs/red/v15/ipch/AutoPCH/349d759258598ef9/ENTRY.ipch new file mode 100644 index 0000000..c3f0e22 Binary files /dev/null and b/.vs/red/v15/ipch/AutoPCH/349d759258598ef9/ENTRY.ipch differ diff --git a/.vs/red/v15/ipch/AutoPCH/434b3cd0330f060/TTY.ipch b/.vs/red/v15/ipch/AutoPCH/434b3cd0330f060/TTY.ipch new file mode 100644 index 0000000..d10ef71 Binary files /dev/null and b/.vs/red/v15/ipch/AutoPCH/434b3cd0330f060/TTY.ipch differ diff --git a/.vs/red/v15/ipch/AutoPCH/89012f5cd6e4fc25/ENTRY.ipch b/.vs/red/v15/ipch/AutoPCH/89012f5cd6e4fc25/ENTRY.ipch new file mode 100644 index 0000000..c96b365 Binary files /dev/null and b/.vs/red/v15/ipch/AutoPCH/89012f5cd6e4fc25/ENTRY.ipch differ diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite new file mode 100644 index 0000000..f36724b Binary files /dev/null and b/.vs/slnx.sqlite differ diff --git a/README.md b/README.md index effb712..c4ebead 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,6 @@ -# Sync +##Sync UEFI Bootloader -Sync, an experimental synchronising OS. +This branch represents the UEFI bootloader used by Sync. +It tries to set a nice video mode, then gets the date and time, then finds, packs and loads the kernel, giving the information gathered to it. -Currently features: -* Text mode printing with CSI support -* literally nothing else - -Keep posted. Development is relatively active. \ No newline at end of file +A .sln project is provided for convenience. The Windows SDK is required to compile using it, but it also works with gcc and llvm. \ No newline at end of file diff --git a/arch/uefi/boot.s b/arch/uefi/boot.s deleted file mode 100644 index 095bac0..0000000 --- a/arch/uefi/boot.s +++ /dev/null @@ -1,28 +0,0 @@ -[BITS 32] ;... somehow. - - -[GLOBAL load_gdt] -[EXTERN gp] -load_gdt: - lgdt [gp] - - mov ax, 0x10 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov ss, ax - jmp 0x08:flush ; Far jump and load the new CSD into the processor -flush: - ret - -[GLOBAL load_idt] -[EXTERN idtp] -load_idt: - lidt [idtp] - ret - - -SECTION .bss - resb 8192 -_sys_stack: diff --git a/arch/uefi/entry.c b/arch/uefi/entry.c deleted file mode 100644 index 439cbb0..0000000 --- a/arch/uefi/entry.c +++ /dev/null @@ -1,52 +0,0 @@ -/************************ - *** Team Kitty, 2019 *** - *** Sync *** - ***********************/ - -/* The entry point of the UEFI app. - * When the firmware loads the app, - * it calls the efi_main function. - * - * When it is called, the processor - * is running in 32-bit Protected mode. - * It is given a map of memory, and there - * are a bunch of Boot Services provided - * by the UEFI firmware. - * - * See uefi/docs for more information. - */ - - //Example stolen from osdev.org/uefi_bare_bones - -#include -#include - -EFI_STATUS efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) -{ - EFI_STATUS Status; - EFI_INPUT_KEY Key; - - /* Store the system table for future use in other functions */ - ST = SystemTable; - - /* Say hi */ - Status = ST->ConOut->OutputString(ST->ConOut, L"Hello World\n\r"); - if (EFI_ERROR(Status)) - return Status; - - /* Now wait for a keystroke before continuing, otherwise your - message will flash off the screen before you see it. - - First, we need to empty the console input buffer to flush - out any keystrokes entered before this point */ - Status = ST->ConIn->Reset(ST->ConIn, FALSE); - if (EFI_ERROR(Status)) - return Status; - - /* Now wait until a key becomes available. This is a simple - polling implementation. You could try and use the WaitForKey - event instead if you like */ - while ((Status = ST->ConIn->ReadKeyStroke(ST->ConIn, &Key)) == EFI_NOT_READY) ; - - return Status; -} \ No newline at end of file diff --git a/arch/uefi/linker.ld b/arch/uefi/linker.ld deleted file mode 100644 index c705f4a..0000000 --- a/arch/uefi/linker.ld +++ /dev/null @@ -1,25 +0,0 @@ -OUTPUT_FORMAT("elf32-i386") -ENTRY(start) -phys = 0x00100000; -SECTIONS -{ - .text phys : AT(phys) { - code = .; - *(.text) - *(.rodata) - . = ALIGN(4096); - } - .data : AT(phys + (data - code)) - { - data = .; - *(.data) - . = ALIGN(4096); - } - .bss : AT(phys + (bss - code)) - { - bss = .; - *(.bss) - . = ALIGN(4096); - } - end = .; -} diff --git a/arch/uefi/make.config b/arch/uefi/make.config deleted file mode 100644 index 70359ae..0000000 --- a/arch/uefi/make.config +++ /dev/null @@ -1,9 +0,0 @@ -KERNEL_ARCH_CFLAGS= -KERNEL_ARCH_CPPFLAGS= -KERNEL_ARCH_LDFLAGS= -KERNEL_ARCH_LIBS= - -KERNEL_ARCH_OBJS= \ -$(ARCHDIR)/boot.o \ -$(ARCHDIR)/sys_clock.o \ -$(ARCHDIR)/tty.o diff --git a/arch/uefi/sys_clock.c b/arch/uefi/sys_clock.c deleted file mode 100644 index cb26901..0000000 --- a/arch/uefi/sys_clock.c +++ /dev/null @@ -1,35 +0,0 @@ -/************************ - *** Team Kitty, 2019 *** - *** Sync *** - ***********************/ - -/* This file provides an interface to - * the hardware timer / RTC. Not much - * more to be said about it. */ - -#include -#include -#include -#include - -size_t timer_ticks = 0; -size_t flag = 0; -void timer_handler(struct int_frame* r) { - gdb_end(); - timer_ticks++; - - if(timer_ticks % 18 == 0) { - if(++flag % 2 == 0) { - serial_print(0x3F8, "Tick."); - } else { - serial_print(0x3F8, "Tock."); - } - } - - if(timer_ticks > 18) - timer_ticks = 0; -} - -void timer_install() { - irq_install_handler(0, &timer_handler); -} \ No newline at end of file diff --git a/arch/uefi/tty.c b/arch/uefi/tty.c deleted file mode 100644 index 417cfc3..0000000 --- a/arch/uefi/tty.c +++ /dev/null @@ -1,348 +0,0 @@ -/************************ - *** Team Kitty, 2019 *** - *** Sync *** - ***********************/ - - /* This file provides all of the functionality - * needed to interact with the Text-Mode VGA - * buffer, which will soon be defunct due to - * EFI and graphics. - * - * This file will be left for the forseeable - * future, because it allows for easy debugging. - * 17/07/19 Curle - */ - -#include -#include -#include -//#include - -#include "kernel/tty.h" -#include "kernel/utils.h" - -static const size_t TERM_WIDTH = 80; -static const size_t TERM_HEIGHT = 25; - -static size_t terminal_row; -static size_t terminal_column; - -static uint8_t current_color; -static uint16_t* term_buffer; -volatile uint16_t* vga_buffer = (uint16_t*)0xB8000; - -void screen_initialize(void) { - - terminal_row = 0; - terminal_column = 0; - current_color = vga_color_set(LIGHT_GREY, BLACK); - term_buffer = vga_buffer; - - for (size_t y = 0; y < TERM_HEIGHT; y++) { - for (size_t x = 0; x < TERM_WIDTH; x++) { - const size_t offset = y * TERM_WIDTH + x; - term_buffer[offset] = vga_entry(' ', current_color); - } - } -} - -void term_setcolor(enum vga_colors color) { current_color = color; } - -void term_putentryat(char c, uint8_t color, size_t x, size_t y) { - const size_t offset = y * TERM_WIDTH + x; - term_buffer[offset] = vga_entry(c, color); -} - -void term_putchar(char c) { - unsigned char uc = c; - - // Handle escaped characters, such as newline, and crtn. - switch (uc) { - case '\n': - terminal_column = 0; - terminal_row += 1; - break; - default: - term_putentryat(uc, current_color, terminal_column, terminal_row); - if (++terminal_column == TERM_WIDTH) { - terminal_column = 0; - if (++terminal_row == TERM_HEIGHT) { - term_scroll(false); - terminal_row = 0; - } - } - break; - } -} - -struct csi_sequence parse_csi(const char* data, size_t size) { - enum State { PARAMETER, INTERMEDIATE, FINAL, INVALID }; - enum State state = PARAMETER; - - struct csi_sequence sequence = {.parameter = NULL, - .parameter_len = 0, - .intermediate = NULL, - .intermediate_len = 0, - .final = NULL, - .valid = false}; - - for (size_t j = 0; j < size; j++) { - uint8_t c = data[j]; - if (state == PARAMETER && (c >= 0x30 && c <= 0x3F)) { - if (!sequence.parameter) - sequence.parameter = data + j; - sequence.parameter_len++; - } else if (c >= 0x20 && c <= 0x2F) { - if (!sequence.intermediate) - sequence.intermediate = data + j; - sequence.intermediate_len++; - state = INTERMEDIATE; - } else if (c >= 0x40 && c <= 0x7F) { - sequence.final = data + j; - sequence.valid = true; - state = FINAL; - break; - } else { - // Parameter found in intermediate byte location, or byte out of - // range - state = INVALID; - break; - } - } - return sequence; -} - -void term_write(const char* data, size_t size) { - for (size_t i = 0; i < size; i++) { - // Begin handling ANSI escape codes. - if (data[i] == 0x1b) { // The current character is ESC - the start of ANSI codes. - // term_writes("ANSI Code encountered: "); - - bool string_terminated = false; // Flag used in some of the escape codes - - // TODO: Should only progress if we have at least 2 more bytes - - switch ((uint8_t)data[i + 1]) { - case '[': // CSI - Control Sequence Introducer (The most common one, hence it comes first) - { - struct csi_sequence sequence = parse_csi(data + i + 2, size - (i + 2)); - if (sequence.valid) { - // Send it off to our handler function to keep this part clean - handleControlSequence(sequence); - i += sequence.parameter_len + sequence.intermediate_len + 2; // Move past sequence - } - } break; - // Single shifts are not handled, so just print them and exit - case 'N': // SS2 - Single Shift Two - term_writes("Single Shift Two\n"); - break; - case 'O': // SS3 - Single Shift Three - term_writes("Single Shift Three\n"); - break; - - // Control Strings - case 'P': // DCS - Device Control String - term_writes("Device Control String"); - string_terminated = false; - break; - case '\\': // ST - String Terminator - term_writes("String Terminator\n"); - string_terminated = true; - break; - case ']': // OSC - Operating System Command - term_writes("Operating System Command\n"); - string_terminated = false; - break; - case 'X': // SOS - Start Of String - term_writes("Start of String"); - string_terminated = false; - break; - case '^': // PM - Privacy Message - term_writes("Privacy Message\n"); - break; - case '_': // APC - Application Program Command - term_writes("Application Program Command\n"); - break; - } - } else { - term_putchar(data[i]); - } - } -} - -void term_writes(const char* data) { term_write(data, strlen(data)); } - -void puts(const char* string) { - term_write(string, strlen(string)); - term_putchar('\n'); -} - -void handleControlSequence(struct csi_sequence sequence) { - // Check for our failsafes - - if (sequence.valid) { - int n = 0; // Default of the flag used for a few items - - // Parse parameters, we only care about a max 2 of number only parameters - // for now - int params[2] = {0}; - int param_count = 0; - if (sequence.parameter_len) { - for (size_t i = 0; i < sequence.parameter_len && param_count < 1; i++) { - char c = sequence.parameter[i]; - if (isDigit(c)) { - n = (n * 10) + (sequence.parameter[i] - '0'); - } else if (c == ';') { - params[param_count++] = n; - } - } - params[param_count++] = n; - } - - switch (*(sequence.final)) { - case 'H': - case 'f': // CUP - Cursor Position - // TODO: Check to see if we have 2 paramaters - if (params[0]) - params[0]--; - if (params[1]) - params[1]--; - set_cursor(params[0], params[1]); - break; - case 'A': // CUU - Cursor Up - if (!params[0]) - params[0] = 1; - set_cursor(terminal_column, terminal_row - params[0]); - break; - case 'B': // CUD - Cursor Down - if (!params[0]) - params[0] = 1; - set_cursor(terminal_column, terminal_row + params[0]); - break; - case 'C': // CUF - Cursor Forward - if (!params[0]) - params[0] = 1; - set_cursor(terminal_column + params[0], terminal_row); - break; - case 'D': // CUB - Cursor Back - if (!params[0]) - params[0] = 1; - set_cursor(terminal_column - params[0], terminal_row); - break; - case 'E': // CNL - Cursor Next Line - if (!params[0]) - params[0] = 1; - set_cursor(0, terminal_row + params[0]); - break; - case 'F': // CPL - Cursor Previous Line - if (!params[0]) - params[0] = 1; - set_cursor(0, terminal_row - params[0]); - break; - case 'G': // CHA - Cursor Horizontal Absolute - if (params[0]) - params[0]--; - set_cursor(params[0], terminal_row); - break; - case 'J': // ED - Erase in Display - { - // current cursor pos = y * width + x - int pos = terminal_row * 80 + terminal_column; - if (params[0] == 0) { // Clear from cursor to end of screen - for (; pos < (25 * 80); pos++) { - vga_buffer[pos] = '\0'; - } - } else if (params[0] == 1) { // Clear from cursor to beginning - for (; pos > 0; pos--) { - vga_buffer[pos] = '\0'; - } - } else if (params[0] == 2 || params[0] == 3) { // Clear entire screen - // TODO: Support scrollback buffer? (n = 3) - for (int i = 0; i < (25 * 80); i++) { - vga_buffer[0] = '\0'; - } - } - break; - } - case 'K': // EL - Erase in Line - { - int pos = terminal_row * 80 + terminal_column; - if (params[0] == 0) { // From cursor to end of line - int endPos = (terminal_row + 1) * 80 - 1; // End of line = current row + 25 columns = current row + 1 - for (; pos < endPos; pos++) { - vga_buffer[pos] = '\0'; - } - } else if (params[0] == 1) { // From cursor to start of line - int endPos = terminal_row * 80; // Start of line = end of previous line + 1 == current line - for (; pos > endPos; pos--) { - vga_buffer[pos] = '\0'; - } - } else if (params[0] == 2) { // Entire current line - pos = terminal_row * 80; - int endPos = (terminal_row + 1) * 80 - 1; - for (; pos < endPos; pos++) { - vga_buffer[pos] = '\0'; - } - } - break; - } - case 'S': // SU - Scroll Up - term_scroll(true); - break; - case 'T': // SD - Scroll Down - term_scroll(false); - break; - } - } -} - -bool isDigit(char c) { return c >= '0' && c <= '9'; } - -void set_cursor(int n, int m) { - terminal_column = n; - terminal_row = m; -} - -void term_scroll(bool down) { - - int current_pos; - if (down) { - current_pos = 25 * 80; // Start of the last line. - } else { - current_pos = 160; // Start of the second line. - } - - unsigned char* term_buffer = (unsigned char*)vga_buffer; - - if (down) { // To scroll down, move every character into the one below it, or "pull" every character down - while (current_pos > 80) { - term_buffer[current_pos + 160] = vga_buffer[current_pos]; - term_buffer[current_pos + 159] = vga_buffer[current_pos - 1]; - current_pos -= 2; - } - } else { - while (current_pos <= 4000) { - term_buffer[current_pos - 160 /*The character immediately below it*/] = - vga_buffer[current_pos]; // Move each character up a line - term_buffer[current_pos - 159 /*The color of the character below*/] = - vga_buffer[current_pos + 1]; // As well as its color - current_pos += 2; // Move to next char - } - } - - if (down) { - current_pos = 0; // Start of first line - for (; current_pos < 80; current_pos++) { - term_buffer[current_pos] = '\0'; - current_pos += 2; - } - } else { - ; // Start of the last line - // Wipe out the bottom line - for (current_pos = 3840; current_pos <= 3920; current_pos += 2) { - term_buffer[current_pos] = 0; - } - } - terminal_row = 24; // Start writing on the last line - terminal_column = 0; -} diff --git a/bochsrc.txt b/bochsrc.txt deleted file mode 100644 index 38aa570..0000000 --- a/bochsrc.txt +++ /dev/null @@ -1,53 +0,0 @@ -# configuration file generated by Bochs -plugin_ctrl: unmapped=1, biosdev=1, speaker=1, extfpuirq=1, parallel=1, serial=1, iodebug=1 -config_interface: textconfig -display_library: x -memory: host=32, guest=32 -romimage: file="/usr/share/bochs/BIOS-bochs-latest", address=0x0, options=none -vgaromimage: file="/usr/share/bochs/VGABIOS-lgpl-latest" -boot: a -floppy_bootsig_check: disabled=1 -floppya: 1_44=/dev/loop0, status=inserted -# no floppyb -ata0: enabled=0 -ata1: enabled=0 -ata2: enabled=0 -ata3: enabled=0 -optromimage1: file=none -optromimage2: file=none -optromimage3: file=none -optromimage4: file=none -optramimage1: file=none -optramimage2: file=none -optramimage3: file=none -optramimage4: file=none -pci: enabled=1, chipset=i440fx -vga: extension=vbe, update_freq=5, realtime=1 -cpu: count=1:1:1, ips=1000000, quantum=16, model=bx_generic, reset_on_triple_fault=0, cpuid_limit_winnt=0, ignore_bad_msrs=1, mwait_is_nop=0 -cpuid: level=6, stepping=3, model=3, family=6, vendor_string="AuthenticAMD", brand_string="AMD Athlon(tm) processor" -cpuid: mmx=1, apic=xapic, simd=sse2, sse4a=0, misaligned_sse=0, sep=1, movbe=0, adx=0 -cpuid: aes=0, sha=0, xsave=0, xsaveopt=0, avx_f16c=0, avx_fma=0, bmi=0, xop=0, fma4=0 -cpuid: tbm=0, x86_64=1, 1g_pages=0, pcid=0, fsgsbase=0, smep=0, smap=0, mwait=1 -print_timestamps: enabled=0 -debugger_log: ../red.debug -magic_break: enabled=1 -port_e9_hack: enabled=0 -private_colormap: enabled=0 -clock: sync=none, time0=local, rtc_sync=0 -# no cmosimage -# no loader -log: ../red.log -logprefix: %t%e%d -debug: action=ignore -info: action=report -error: action=report -panic: action=ask -keyboard: type=mf, serial_delay=250, paste_delay=100000, user_shortcut=none -mouse: type=ps2, enabled=0, toggle=ctrl+mbutton -speaker: enabled=1, mode=system -parport1: enabled=1, file=none -parport2: enabled=0 -com1: enabled=1, mode=null -com2: enabled=0 -com3: enabled=0 -com4: enabled=0 diff --git a/debug.vbs b/debug.vbs new file mode 100644 index 0000000..08c72ee --- /dev/null +++ b/debug.vbs @@ -0,0 +1,141 @@ +' Visual Studio QEMU debugging script. +' +' I like invoking vbs as much as anyone else, but we need to download and unzip our +' firmware file, as well as launch QEMU, and neither Powershell or a standard batch +' can do that without having an extra console appearing. +' +' Note: You may get a prompt from the firewall when trying to download the BIOS file + +' Modify these variables as needed +QEMU_PATH = "C:\Program Files\qemu\" +' You can add something like "-S -gdb tcp:127.0.0.1:1234" if you plan to use gdb to debug +QEMU_OPTS = "-net none -monitor none -parallel none" +' Set to True if you need to download a file that might be cached locally +NO_CACHE = False + +' You shouldn't have to modify anything below this +TARGET = WScript.Arguments(1) + +If (TARGET = "x86") Then + UEFI_EXT = "ia32" + QEMU_ARCH = "i386" + FW_BASE = "OVMF" +ElseIf (TARGET = "x64") Then + UEFI_EXT = "x64" + QEMU_ARCH = "x86_64" + FW_BASE = "OVMF" +ElseIf (TARGET = "ARM") Then + UEFI_EXT = "arm" + QEMU_ARCH = "arm" + FW_BASE = "QEMU_EFI" + ' You can also add '-device VGA' to the options below, to get graphics output. + ' But if you do, be mindful that the keyboard input may not work... :( + QEMU_OPTS = "-M virt -cpu cortex-a15 " & QEMU_OPTS +ElseIf (TARGET = "ARM64") Then + UEFI_EXT = "aa64" + QEMU_ARCH = "aarch64" + FW_BASE = "QEMU_EFI" + QEMU_OPTS = "-M virt -cpu cortex-a57 " & QEMU_OPTS +Else + MsgBox("Unsupported debug target: " & TARGET) + Call WScript.Quit(1) +End If +BOOT_NAME = "boot" & UEFI_EXT & ".efi" +QEMU_EXE = "qemu-system-" & QEMU_ARCH & "w.exe" + +FW_ARCH = UCase(UEFI_EXT) +FW_DIR = "https://efi.akeo.ie/" & FW_BASE & "/" +FW_ZIP = FW_BASE & "-" & FW_ARCH & ".zip" +FW_FILE = FW_BASE & "_" & FW_ARCH & ".fd" +FW_URL = FW_DIR & FW_ZIP + +' Globals +Set fso = CreateObject("Scripting.FileSystemObject") +Set shell = CreateObject("WScript.Shell") + +' Download a file from FTP +Sub DownloadFtp(Server, Path) + Set file = fso.CreateTextFile("ftp.txt", True) + Call file.Write("open " & Server & vbCrLf &_ + "anonymous" & vbCrLf & "user" & vbCrLf & "bin" & vbCrLf &_ + "get " & Path & vbCrLf & "bye" & vbCrLf) + Call file.Close() + Call shell.Run("%comspec% /c ftp -s:ftp.txt > NUL", 0, True) + Call fso.DeleteFile("ftp.txt") +End Sub + +' Download a file from HTTP +Sub DownloadHttp(Url, File) + Const BINARY = 1 + Const OVERWRITE = 2 + Set xHttp = createobject("Microsoft.XMLHTTP") + Set bStrm = createobject("Adodb.Stream") + Call xHttp.Open("GET", Url, False) + If NO_CACHE = True Then + Call xHttp.SetRequestHeader("If-None-Match", "some-random-string") + Call xHttp.SetRequestHeader("Cache-Control", "no-cache,max-age=0") + Call xHttp.SetRequestHeader("Pragma", "no-cache") + End If + Call xHttp.Send() + If Not xHttp.Status = 200 Then + Call WScript.Echo("Unable to access file - Error " & xHttp.Status) + Call WScript.Quit(1) + End If + With bStrm + .type = BINARY + .open + .write xHttp.responseBody + .savetofile File, OVERWRITE + End With +End Sub + +' Unzip a specific file from an archive +Sub Unzip(Archive, File) + Const NOCONFIRMATION = &H10& + Const NOERRORUI = &H400& + Const SIMPLEPROGRESS = &H100& + unzipFlags = NOCONFIRMATION + NOERRORUI + SIMPLEPROGRESS + Set objShell = CreateObject("Shell.Application") + Set objSource = objShell.NameSpace(fso.GetAbsolutePathName(Archive)).Items() + Set objTarget = objShell.NameSpace(fso.GetAbsolutePathName(".")) + ' Only extract the file we are interested in + For i = 0 To objSource.Count - 1 + If objSource.Item(i).Name = File Then + Call objTarget.CopyHere(objSource.Item(i), unzipFlags) + End If + Next +End Sub + + +' Check that QEMU is available +If Not fso.FileExists(QEMU_PATH & QEMU_EXE) Then + Call WScript.Echo("'" & QEMU_PATH & QEMU_EXE & "' was not found." & vbCrLf &_ + "Please make sure QEMU is installed or edit the path in '.msvc\debug.vbs'.") + Call WScript.Quit(1) +End If + +' Fetch the UEFI firmware and unzip it +If Not fso.FileExists(FW_FILE) Then + Call WScript.Echo("The UEFI firmware file, needed for QEMU, " &_ + "will be downloaded from: " & FW_URL & vbCrLf & vbCrLf &_ + "Note: Unless you delete the file, this should only happen once.") + Call DownloadHttp(FW_URL, FW_ZIP) +End If +If Not fso.FileExists(FW_ZIP) And Not fso.FileExists(FW_FILE) Then + Call WScript.Echo("There was a problem downloading the QEMU UEFI firmware.") + Call WScript.Quit(1) +End If +If fso.FileExists(FW_ZIP) Then + Call Unzip(FW_ZIP, FW_BASE & ".fd") + Call fso.MoveFile(FW_BASE & ".fd", FW_FILE) + Call fso.DeleteFile(FW_ZIP) +End If +If Not fso.FileExists(FW_FILE) Then + Call WScript.Echo("There was a problem unzipping the QEMU UEFI firmware.") + Call WScript.Quit(1) +End If + +' Copy the app file as boot application and run it in QEMU +Call shell.Run("%COMSPEC% /c mkdir ""image\efi\boot""", 0, True) +Call fso.CopyFile(WScript.Arguments(0), "image\efi\boot\" & BOOT_NAME, True) +Call shell.Run("""" & QEMU_PATH & QEMU_EXE & """ " & QEMU_OPTS & " -L . -bios " & FW_FILE & " -hda fat:rw:image", 1, True) diff --git a/gnu-efi/.gitignore b/gnu-efi/.gitignore new file mode 100644 index 0000000..970b638 --- /dev/null +++ b/gnu-efi/.gitignore @@ -0,0 +1,6 @@ +*.efi +*.efi.debug +*.o +*.a +*.tar.* +*.tar diff --git a/gnu-efi/ChangeLog b/gnu-efi/ChangeLog new file mode 100644 index 0000000..b30ba25 --- /dev/null +++ b/gnu-efi/ChangeLog @@ -0,0 +1,1324 @@ + Updated Changelog + + Signed-off-by: Nigel Croxon + +commit 37d7bee82a627999563069b090866076e055a871 +Author: Nigel Croxon +Date: Thu May 14 12:38:39 2015 -0400 + + Added some missing error code descriptions + + Signed-off-by: Peter Jones + Signed-off-by: Nigel Croxon + +commit dae0b4b0b0d522caecf09123db2cf0250c37a169 +Author: Nigel Croxon +Date: Thu May 14 12:20:51 2015 -0400 + + Turns out we actually need setjmp in one of gnu-efi's prominent + users, and it seems to make more sense to put it here than in + the application. + + All of these are derived from the Tiano code, but I re-wrote the + x86_64 one because we use the ELF psABI calling conventions instead + of the MS ABI calling conventions. Which is to say you probably + shouldn't setjmp()/longjmp() between functions with EFIAPI (aka + __attribute__((ms_abi))) and those without. + + Signed-off-by: Peter Jones + Signed-off-by: Nigel Croxon + +commit b5a8e93cec396381a6d2beee022abbf50100f2fd +Author: Nigel Croxon +Date: Fri Apr 10 08:49:50 2015 -0400 + + Bump version to 3.0.2 + + Signed-off-by: Nigel Croxon + +commit 01c9f11ed5ad55661e8fc8a3eee35c578564754b +Author: Nigel Croxon +Date: Fri Apr 10 08:46:40 2015 -0400 + + Fix ARM32 and AARCH64 builds + Without these added into SUBDIRS the initplat.c compilation will fail. + + Signed-off-by: Koen Kooi + Acked-by: Ard Biesheuvel + Signed-off-by: Nigel Croxon + +commit dada63fd3de148c6f8551d253355c113547cd5a0 +Author: Nigel Croxon +Date: Mon Mar 23 10:41:43 2015 -0400 + + [PATCH] _SPrint: fix NULL termination + + maxlen is the maximum string length not the buffer size. + + Signed-off-by: Jeremy Compostella + Signed-off-by: Nigel Croxon + +commit ce7098fb52e5fd4d16038964d029eb759f28eaaf +Author: Nigel Croxon +Date: Thu Feb 19 11:22:45 2015 -0500 + + Enable out-of-tree building + + This patch enables building gnu-efi outside of the source tree. + That in turn enables building for multiple architectures in parallel. + + The build directory is controlled by the OBJDIR make variable. It + defaults to the value of ARCH, and can be overridden from the command + line. + + This patch also cleans up some doubled slashes between INSTALLROOT + and PREFIX. + + Signed-off-by: Jonathan Boeing + Signed-off-by: Nigel Croxon + +commit f64cef26270bfbe04f038da33f95ae3f14c071bc +Author: Nigel Croxon +Date: Tue Jan 6 15:49:50 2015 -0500 + + Since we're keeping this in git, it'd be nice not to see a bunch + of make targets in 'status' + + Signed-off-by: Peter Jones + Signed-off-by: Nigel Croxon + +commit 322efb6b21ed0a5e42e8f124fd22bf0f8dbf01ae +Author: Nigel Croxon +Date: Mon Jan 5 13:20:43 2015 -0500 + + version number changed from VERSION = 3.0u to VERSION = 3.0.1 + + Signed-off-by: Nigel Croxon + +commit 09027207f7c18af6caa45a744fc15c90b2a829db +Author: Nigel Croxon +Date: Mon Jan 5 13:13:22 2015 -0500 + + From: Pete Batard + Date: Wed, 10 Dec 2014 21:08:34 +0000 + Subject: [PATCH] fixes for MSVC compilation + + These fixes are needed to address the following error and warnings when compiling the library part + using Visual Studio 2013 Community Edition (as in https://github.com/pbatard/uefi-simple): + * "lib\x86_64\math.c(49): error C4235: nonstandard extension used : '_asm' keyword not supported + on this architecture" + * "lib\print.c(98): error C2059: syntax error : '('" due to placement of EFIAPI macro + * "lib\cmdline.c(94): warning C4090: 'function' : different 'const' qualifiers" + * "lib\smbios.c(25): warning C4068: unknown pragma" + * Also update macro definitions in "inc\\efibind.h" for MSVC + + Signed-off-by: Pete Batard + Signed-off-by: Nigel Croxon + +commit 15805ff38b83a72c2c7c96a24bd642ee1176d819 +Author: Nigel Croxon +Date: Tue Nov 25 14:23:21 2014 -0500 + + Add README.git file. Instructions on how to archive. + + Signed-off-by: Nigel Croxon + +commit b868aa75669723b7e32f46524822e17e388fe2ba +Author: Nigel Croxon +Date: Tue Nov 25 13:26:45 2014 -0500 + + This patch makes generating releases from git a very simple process; you + simply edit the makefile's "VERSION" line to the new version, commit + that as its own commit, and do: "make test-archive". That'll make a + file in the current directory gnu-efi-$VERSION.tar.bz2 , with its top + level directory gnu-efi-$VERSION/ and the source tree under that. + + Once you've tested that and you're sure it's what you want to release, + you do "make archive", which will tag a release in git and generate a + final tarball from it. You then push to the archive, being sure to + include the tag: + + git push origin master:master --tags + + And upload the archive wherever it's supposed to go. + + Signed-off-by: Peter Jones + Signed-off-by: Nigel Croxon + +commit 530d68ba191850edafc6da22cb2df55bec0c5fa5 +Author: Nigel Croxon +Date: Tue Nov 25 10:09:50 2014 -0500 + + The gnu-efi-3.0 toplevel subdirectory is really annoying. Kill it. + + Signed-off-by: Peter Jones + Signed-off-by: Nigel Croxon + +commit 00bd66ef46b59a1623a293491a8b2c65a6d61975 +Author: Nigel Croxon +Date: Mon Nov 24 14:33:09 2014 -0500 + + FreeBSD's binutils doesn't have "-j " support, so we need to + include non-globbed versions of .rel/.rela individually. + + Signed-off-by: Peter Jones + Signed-off-by: Bill Paul + Signed-off-by: Nigel Croxon + +commit 56eb64d3c06854b9b68d61e3c2d3bdf6ff2a9853 +Author: Nigel Croxon +Date: Mon Nov 24 14:27:14 2014 -0500 + + Right now we wind up trying to build gnuefi/.o from a source file that's + an empty string. This is caused by the macros trying to generate + install rules, but there's no real reason to have all that anyway. So + just have some static install rules that are simpler and don't generate + stuff on the fly. + + Signed-off-by: Peter Jones + Signed-off-by: Nigel Croxon + +commit 65e28a90a7be9e990b360286cea31e63319217fb +Author: Nigel Croxon +Date: Mon Nov 24 12:17:45 2014 -0500 + + Add current OsIndications values. + + Signed-off-by: Peter Jones + Signed-off-by: Nigel Croxon +Date: Mon Nov 24 12:15:34 2014 -0500 + + Add the QueryVariableInfo() API. + + Signed-off-by: Peter Jones + Signed-off-by: Nigel Croxon + +commit 60efb7a2939b65a01e95aa8b535f1b756d984fba +Author: Nigel Croxon +Date: Mon Nov 24 12:13:23 2014 -0500 + + Add the capsule API. + + Signed-off-by: Peter Jones + Signed-off-by: Nigel Croxon + +commit ef08b655d1f8dfbd9a0f3a86d5685b24695ef12f +Author: Nigel Croxon +Date: Mon Nov 17 16:05:42 2014 -0500 + + Fix Table Header misspelling. Change from EFI_TABLE_HEARDER to + EFI_TABLE_HEADER. + + Signed-Off-By: Nigel Croxon + +commit 370cce41da3fff41ba38feb1262002aff2d85ffd +Author: Nigel Croxon +Date: Thu Nov 6 14:41:40 2014 -0500 + + If CROSS_COMPILE is set, ignore the ARCH value supplied on the + command line and use the target machine of the cross compiler. + + Signed-off-by: Ard Biesheuvel + Signed-off-by: Nigel Croxon + +commit d32fb845433ff6fb38e81ae0d9273454e7d18197 +Author: Nigel Croxon +Date: Thu Nov 6 14:30:03 2014 -0500 + + Allow reuse of this file beyond GPL compatible software, + update the license of crt0-efi-aarch64.S to dual 2-clause BSD/GPLv2+. + + Signed-off-by: Ard Biesheuvel + Signed-off-by: Nigel Croxon + +commit aa1df67f48f3c035fa8891e1bb311ec21500d6d9 +Author: Nigel Croxon +Date: Tue Oct 21 11:08:47 2014 -0400 + + Add the missing Variable attributes + + From: Jeremy Compostella + Date: Mon, 13 Oct 2014 17:50:50 +0200 + Subject: [PATCH] Add the missing Variable attributes + + Signed-off-by: Jeremy Compostella + Signed-off-by: Nigel Croxon + +commit 5706dff09364cbbec37f47e2fe1350747f631d74 +Author: Nigel Croxon +Date: Tue Aug 26 10:54:22 2014 -0400 + + From: David Decotigny + Date: Mon, 25 Aug 2014 13:28:49 -0700 + Subject: [PATCH] document that binutils >= 2.24 needed. + + commit ac983081 "Add support for non-PE/COFF capable objcopy" depends + on objcopy accepting wildcards for the section names. This feature is + available only with binutils >= 2.24 (binutils 2e62b7218 "PR + binutils/15033"). + + Signed-off-by: David Decotigny + Signed-off-by: Nigel Croxon + +commit 6c10e225bc759d69af520a551b9d7b37f3ae0a82 +Author: Nigel Croxon +Date: Mon Aug 25 08:51:23 2014 -0400 + + From: David Decotigny + Date: Thu, 31 Jul 2014 18:19:16 -0700 + Subject: [PATCH 5/5] allow to use external stdarg.h + + in cases we use gnu-efi together with other libs that define stdarg.h, + break the tie by telling gnu-efi to use that stdarg.h . + + Signed-off-by: David Decotigny + Signed-off-by: Nigel Croxon + +commit 16d65c0669258c8044e3549b2d9eb0cf0eb08f5a +Author: Nigel Croxon +Date: Tue Aug 19 12:07:00 2014 -0400 + + From: Ard Biesheuvel + Date: Mon, 11 Aug 2014 15:39:16 +0200 + Subject: [PATCH] Add support for 32-bit ARM + + This adds support for 32-bit ARM using an approach similar to the one used for + 64-bit ARM (AArch64), i.e., it does not rely on an objcopy that is aware of EFI + or PE/COFF, but lays out the entire PE/COFF header using the assembler. + + In the 32-bit ARM case (which does not have a division instruction), some code + has been imported from the Linux kernel to perform the division operations in + software. + + Signed-off-by: Ard Biesheuvel + Signed-off-by: Nigel Croxon + +commit b28143d4fb4f6969dc0c87c853d3527d889951d7 +Author: Nigel Croxon +Date: Fri Aug 8 15:54:19 2014 -0400 + + Updated Changelog + + Signed-off-by: Nigel Croxon + +commit 1525190354f5faac33015e17c9ba7ea2bb2be35b +Author: Nigel Croxon +Date: Fri Aug 8 15:35:09 2014 -0400 + + From: Ard Biesheuvel + Date: Fri, 8 Aug 2014 18:16:59 +0200 + Subject: [PATCH 4/4] Add support for 64-bit ARM (AArch64) + + This adds support for 64-bit ARM (AArch64) environments. Since there is no + EFI-capable objcopy for this platform, this contains a manually laid out + PE/COFF header using the assembler. + + In addition, it includes the relocation bits, some string functions that GCC + assumes are available and other glue to hold it all together. + + This can be cross built using + + make CROSS_COMPILE=aarch64-linux-gnu- + + Signed-off-by: Ard Biesheuvel + Signed-off-by: Nigel Croxon + +commit ac983081525f9483941517dfb53cf8d0163d49c0 +Author: Nigel Croxon +Date: Fri Aug 8 15:32:26 2014 -0400 + + From: Ard Biesheuvel + Date: Fri, 8 Aug 2014 17:53:42 +0200 + Subject: [PATCH 3/4] Add support for non-PE/COFF capable objcopy + + Introduce HAVE_EFI_OBJCOPY and set it if objcopy for $ARCH support PE/COOF and + EFI, i.e., it supports --target efi-[app|bsdrv|rtdrv] options. Use it to decide + whether to invoke objcopy with those options or use the linker to populate the + PE/COFF header. + + Signed-off-by: Ard Biesheuvel + Signed-off-by: Nigel Croxon + +commit fb063f0f65543b3e2bf55a39d5aa70b17a98c65e +Author: Nigel Croxon +Date: Fri Aug 8 15:26:38 2014 -0400 + + From: Ard Biesheuvel + Date: Fri, 8 Aug 2014 17:37:36 +0200 + Subject: [PATCH 2/4] Add support for cross compilation + + This changes the logic that defines ARCH (and HOSTARCH) to take CROSS_COMPILE + into account. Also, $prefix is not assigned, so that the default will be what + is on the path rather than hardcoded in /usr/bin. + + This results in the build doing the right thing if CROSS_COMPILE is set in the + environment and no ARCH or prefix options are passed to make, aligning it with + most other CROSS_COMPILE compatible projects. + + Signed-off-by: Ard Biesheuvel + Signed-off-by: Nigel Croxon + +commit 7a98d83fc32de6cf0b1ce5e12dfe80690f29fb3f +Author: Nigel Croxon +Date: Fri Aug 8 15:25:03 2014 -0400 + + From: Ard Biesheuvel + Date: Fri, 8 Aug 2014 16:50:45 +0200 + Subject: [PATCH 1/4] Restrict GNU_EFI_USE_MS_ABI GCC version test to x86_64 + + The version test only applies to x86_64 builds, so no need to do it + for other archs. + + Signed-off-by: Ard Biesheuvel + Signed-off-by: Nigel Croxon + +commit f42974dd9a7d0ea690d293f88396abd289f0014c +Author: Nigel Croxon +Date: Fri Aug 8 15:21:16 2014 -0400 + + From: David Decotigny + Date: Thu, 31 Jul 2014 13:42:23 -0700 + Subject: [PATCH 4/4] Use Shell protocols to retrieve argc/argv, when + available. + + New header files efishellintf.h efishellparm.h are coming from EDK + II, initial location and license at top of files. Only modifications: + - efishellintf.h: s/EFI_FILE_PROTOCOL/EFI_FILE/ + expand BITx macros (1< + Signed-off-by: Nigel Croxon + +commit a61fa058e9a87f966de3342b8c95fdbdcb007827 +Author: Nigel Croxon +Date: Fri Aug 8 15:17:32 2014 -0400 + + From: David Decotigny + Date: Thu, 31 Jul 2014 13:41:52 -0700 + Subject: [PATCH 3/4] document format of LoadedImage::LoadOptions data + + Signed-off-by: David Decotigny + Signed-off-by: Nigel Croxon + +commit 2f440200c855154f929d28971b2fd702ea7a207a +Author: Nigel Croxon +Date: Fri Aug 8 15:15:59 2014 -0400 + + From: David Decotigny + Date: Thu, 31 Jul 2014 13:39:37 -0700 + Subject: [PATCH 2/4] Use OpenProtocol instead of HandleProtocol + + UEFI 2.x recommends OpenProtocol instead of HandleProtocol. + + Signed-off-by: David Decotigny + Signed-off-by: Nigel Croxon + +commit 7f173da1e54f8cfe4c7c7c091ab6585af07b25ce +Author: Nigel Croxon +Date: Fri Aug 8 15:14:26 2014 -0400 + + From: David Decotigny + Date: Thu, 31 Jul 2014 13:30:07 -0700 + Subject: [PATCH 1/4] move cmdline parser to its own file + + Signed-off-by: David Decotigny + Signed-off-by: Nigel Croxon + +commit 0ad8fb87cbc59f58675b18253ad802ba51f1d132 +Author: Nigel Croxon +Date: Wed Jul 30 15:06:36 2014 -0400 + + From: David Decotigny + Date: Mon, 28 Jul 2014 21:28:50 -0700 + Subject: [PATCH 3/3] make cmdline parsing a 1st class citizen + + Refactor ParseCmdline and apps/Alloc+FreePages to factorize + boilerplate and move the new parser to the main API. + + Signed-off-by: David Decotigny + Signed-off-by: Nigel Croxon + +commit ff7ec964f2c0de0cfc4b52cfdd356003450f28bf +Author: Nigel Croxon +Date: Wed Jul 30 15:05:28 2014 -0400 + + From: David Decotigny + Date: Mon, 28 Jul 2014 21:00:52 -0700 + Subject: [PATCH 2/3] Avoid buffer overflow while parsing the cmdline args + + Signed-off-by: David Decotigny + Signed-off-by: Nigel Croxon + +commit 8d86ee202a9bb553375f56ae1d2944818112b68b +Author: Nigel Croxon +Date: Wed Jul 30 15:04:44 2014 -0400 + + From: David Decotigny + Date: Mon, 28 Jul 2014 21:01:35 -0700 + Subject: [PATCH 1/3] Fix cmdline parser + + The cmdline parser would not return the correct number of args, would + allocate one too many. Also make it clear from the declaration that we + expect a suitably lare argv. + + Signed-off-by: David Decotigny + Signed-off-by: Nigel Croxon + +commit 1ec094bfaf46a610a740dadc0150bf457dd72345 +Author: Nigel Croxon +Date: Wed Jul 23 09:54:25 2014 -0400 + + From: Julian Klode + Date: Mon, 21 Jul 2014 14:26:23 -0400 + Subject: [PATCH] inc/efistdarg.h: Use gcc builtins instead of stdarg.h or broken stubs + + We cannot use stdarg.h, as this breaks applications compiling + with -nostdinc because those will not find the header. + We also cannot use the stubs, as they just produce broken code, + as seen in the gummiboot 45-1 Debian release. + + Signed-off-by: Julian Klode + Signed-off-by: Nigel Croxon + +commit 6caab22f23434f41f42cfe7591d9a7ae66de9f0a +Author: Nigel Croxon +Date: Thu Jun 19 10:39:23 2014 -0400 + + From: Laszlo Ersek + Date: Mon, 2 Jun 2014 23:26:48 +0200 + Subject: [PATCH] always observe EFIAPI calling convention when calling + STO.SetAttribute + + We have to consider the following cases wrt. the PRINT_STATE.Output and + PRINT_STATE.SetAttr EFIAPI function pointers, especially when building for + x86_64 with gcc: + + (1) The compiler is new enough, and EFIAPI actually ensures the Microsoft + calling convention. In this case everything happens to work fine even + if we forget uefi_call_wrapper(), because the wrapper would expand to + a normal C function call anyway. + + (2) Otherwise (ie. gcc is old), EFIAPI expands to nothing, and we must + take into account the called function's origin: + + (2a) If the callee that is declared EFIAPI is *defined* inside gnu-efi, + then EFIAPI means nothing for the callee too, so caller and callee + only understand each other if the caller intentionally omits + uefi_call_wrapper(). + + (2b) If the callee that is declared EFIAPI is defined by the platform + UEFI implementation, then the caller *must* use + uefi_call_wrapper(). + + The PRINT_STATE.Output EFIAPI function pointer is dereferenced correctly: + the PFLUSH() distinguishes cases (2a) from (2b) by using IsLocalPrint(). + + However use of the PRINT_STATE.SetAttr EFIAPI function pointer is not + always correct: + + - The PSETATTR() helper function always relies on the wrapper (case (2b)). + This is correct, because PRINT_STATE.SetAttr always points to a + platform-provided function. + + - The DbgPrint() function contains two incorrect calls: they mistakenly + assume case (2a) (or case (1)), even though the pointer always points to + a platform function, implying (2b). (The error is masked in case (1).) + Fix them. + + Signed-off-by: Laszlo Ersek + Signed-off-by: Nigel Croxon + +commit ecfd1ded9a799c3a572d4eb7fbb52582fe4d3390 +Author: Nigel Croxon +Date: Tue Jun 10 12:59:09 2014 -0400 + + Add VPoolPrint Function + + Equivalent to PoolPrint but using a va_list parameter + + Signed-off-by: Sylvain Chouleur + Signed-off-by: Nigel Croxon + +commit f16d93f3b9e314336a387a3885c7fd2f176c41d3 +Author: Nigel Croxon +Date: Fri May 16 11:33:51 2014 -0400 + + Revert "The prototype of DbgPrint() is incorrect, at the end of "inc/efidebug.h"." + A problem was found compiling on GCC 4.8. + + This reverts commit 644898eabc06c8efaa3aa54f84cdd468960a2f6c. + +commit 644898eabc06c8efaa3aa54f84cdd468960a2f6c +Author: Nigel Croxon +Date: Wed May 14 09:09:47 2014 -0400 + + The prototype of DbgPrint() is incorrect, at the end of "inc/efidebug.h". + Consequently, when your program calls DbgPrint() via the DEBUG() macro, + it fails to set up the stack correctly (it does not pass the arguments + through the ellipsis (...) according to the EFIAPI calling convention). + However, va_start() inside DbgPrint() *assumes* that stack. + + Signed-off-by: Laszlo Ersek + Signed-off-by: Nigel Croxon + +commit 8921ba2fc5f6163bdad3b5902c5d9d638415dde0 +Author: Nigel Croxon +Date: Mon Apr 14 18:49:23 2014 -0400 + + Cleaned up compile warnings. + + Signed-off-by: Nigel Croxon + +commit 42cca551dbf1c0be9e02e8d3d3c417ce35749638 +Author: Nigel Croxon +Date: Mon Apr 14 14:04:11 2014 -0400 + + Module lib/ParseCmdLine.c has errors, it incorrectly mixes "char" and "CHAR16" + and uses a pointer to argv[] like it's argv[]. The compiler only issues + warnings though. Here is a patch to remove compiler warnings and make the + code behave. + + Signed-off-by: Bernard Burette + Signed-off-by: Nigel Croxon + +commit 4e8460f1aedd2724de876be5b154eb5752bfada5 +Author: Nigel Croxon +Date: Mon Apr 14 13:53:03 2014 -0400 + + Here is a very small patch to remove a compiler warning when processing lib/smbios.c. + + Signed-off-by: Bernard Burette + Signed-off-by: Nigel Croxon + +commit 6a0875ca2fcb67e7d1a1e2d15f3bcc645329dc75 +Author: Nigel Croxon +Date: Mon Apr 14 13:45:16 2014 -0400 + + Here is a very small patch to remove compiler warning in function + "LibLocateHandleByDiskSignature()" because the "Start" variable is + give a value which is not used. + + Signed-off-by: Bernard Burette + Signed-off-by: Nigel Croxon + +commit d5f35dfb8008ba65bcc641559accd9bc13386ef9 +Author: Nigel Croxon +Date: Mon Apr 14 13:40:29 2014 -0400 + + Here is a very small patch to remove *~ files in include diretory. + + Signed-off-by: Bernard Burette + Signed-off-by: Nigel Croxon + +commit 1a04669a7bb022984c9b54a0f73d7d67a2540fb7 +Author: Nigel Croxon +Date: Mon Apr 14 12:45:57 2014 -0400 + + Here is a patch for "DevicePathToStr()" to display device path according to UEFI 2 specification. + The path is in the two files inc/efidevp.h and lib/dpath.c. + + It also add the Sata device path and removes the "/?" path for unknown device paths. + + Signed-off-by: Bernard Burette + Signed-off-by: Nigel Croxon + +commit 3c62e78556aea01e9798380cd46794c6ca09d4bd +Author: Nigel Croxon +Date: Tue Apr 1 10:26:44 2014 -0400 + + Removed GPL code setjmp_ia32.S, setjmp_ia64.S, setjmp_x86_64.S + Not used anymore. + + Signed-off-by: Nigel Croxon + +commit f9baa4f622cf34576d73e00d4a774a31f0f81fd7 +Author: Nigel Croxon +Date: Mon Mar 31 08:37:56 2014 -0400 + + Remove incumbent GPL 'debian' subdiretory. + Update ChangeLog + + Signed-off-by: Nigel Croxon + + +Changelog format change from here and above to 'git log' style. + +2014-04-01 Nigel Croxon + + Removed GPL code setjmp_ia32.S, setjmp_ia64.S, setjmp_x86_64.S + Not used anymore. + + Signed-off-by: Nigel Croxon + +2014-03-17 Nigel Croxon + + Add support for the simple pointer and absolute pointer protocols + + Signed-off-by: John Cronin + Signed-off-by: Nigel Croxon + +2014-03-14 Nigel Croxon + + Trying to recurse into subdirectories of object files may lead + to an error if the directory doesn't exist. Even when cleaning. + + Signed-off-by: Sylvain Gault + Signed-off-by: Nigel Croxon + +2014-03-14 Nigel Croxon + + Make install used to copy files unconditionnally to their + destination. However, if the destination is used by another + Makefile, it will always see modified files. "install" target + now only updates the files when they need to. + + Signed-off-by: Sylvain Gault + Signed-off-by: Nigel Croxon + +2014-02-13 Nigel Croxon + + Patch GNU-EFI to remove the ELILO code + + Signed-off-by: Jerry Hoemann + Signed-off-by: Nigel Croxon + +2014-02-13 Nigel Croxon + + Initialize Status before calling GrowBuffer() + Status must be initialized before calling GrowBuffer() as it may + otherwise be uninitialized or set to EFI_BUFFER_TOO_SMALL by + other functions. + + Signed-off-by: Gene Cumm + Signed-off-by: Nigel Croxon + +2014-01-23 Nigel Croxon + + These changes allow manually overridden SRCDIR (current source + directory) and TOPDIR (top of source tree) to separate the + build directory from the source tree. + + Signed-off-by: Gene Cumm + Signed-off-by: Nigel Croxon + +2014-01-16 Nigel Croxon + compilation: fix uninitialized variables warning + + Signed-off-by: Jeremy Compostella + Signed-off-by: Nigel Croxon + +2014-01-13 Nigel Croxon + Implement VSPrint function, prints a formatted unicode string to a buffer. + + Signed-off-by: Jeremy Compostella + Signed-off-by: Nigel Croxon + +2014-01-10 Nigel Croxon + Created lib/argify.c and inc/argify.h containing the function argify. + It contains verbatim copy of the comment at beginning of file from + elilo. + There was no COPYING file in the elilo source that the comment refers to. + + Signed-off-by: Jerry Hoemann + Signed-off-by: Nigel Croxon + +2014-01-08 Nigel Croxon + The information needed is not really the host architecture as given by + the kernel arch. The information actually needed is the default target + of gcc. + + Signed-off-by: Sylvain Gault + Signed-off-by: Nigel Croxon + +2013-10-11 Nigel Croxon + Added support for SetVariable to store volatile variable, + and SetNVVariable to store non volatile variable. + + Signed-off-by: Sylvain Chouleur + Signed-off-by: Nigel Croxon + +2013-10-07 Nigel Croxon + + Atoi needs to have consistent declaration/definition. + + Signed-off-by: Nigel Croxon + +2013-10-07 Nigel Croxon + if you have a function that takes const arguments and then + e.g. tries to copy StrCmp, gcc will give you warnings about those + calls, and the warnings are right. These clutter up other things + you might miss that you should be more concered about. + + You could work around it through vigorous typecasting + to non-const types, but why should you have to? All of these + functions are regorously defined as not changing their input + - it is const, and should be marked as such. + + Signed-off-by: Peter Jones + +2013-10-02 Nigel Croxon + + Added two simple applications to allocate/free memory at EFI. + Used to test/find memory fragmentation issues linux. + + Signed-off-by: Jerry Hoemann + Signed-off-by: Nigel Croxon + +2013-06-25 Nigel Croxon + Sample boot service driver. + + Signed-off-by: David Decotigny + +2013-06-25 Nigel Croxon +Date: Tue Jun 25 08:47:03 2013 -0400 + + Be more pedantic when linking, don't allow duplicate symbols, + abort upon first error. Also make sure linker script comes + last for apps. + + Signed-off-by: David Decotigny + +2013-06-25 Nigel Croxon + Fix compilation on x86_64 without HAVE_USE_MS_ABI + make -C apps would fail on tcc.c because uefi_call_wrapper() + doesn't deal correctly with efi_callO-type invocation. + + Signed-off-by: David Decotigny + +2013-06-12 Nigel Croxon + Fix typo when disabling mno-mmx + + Signed-Off-By: Nigel Croxon + +2013-06-12 Nigel Croxon + Disable MMX and SSE + + GCC 4.8.0 adds some optimizations that will use movups/movaps (and use + %xmm* registers) when they're faster, and of course that won't work at + all since UEFI firmwares aren't guaranteed to initialize the mmx/sse + instructions. + + This will be even more annoying, since most UEFI firmwares don't + initialize the #DE or #UD trap handlers, and your backtrace will be a + random path through uninitialized memory, occasionally including + whatever address the IDT has for #UD, but also addresses like "0x4" and + "0x507" that you don't normally expect to see in your call path. + + Signed-off-by: Peter Jones + + Author: Nigel Croxon + Date: Wed Jun 12 10:29:40 2013 -0400 + + bug in make 3.82 expand to odd values + + Some Makefiles tickle a bug in make 3.82 that cause libefi.a + and libgnuefi.a dependencies to expand to the odd values: + + libefi.a: boxdraw.o) smbios.o) ... + libgnuefi.a(reloc_x86_64.o: + + The patch replaces libgnuefi.a($(OBJS)) & libefi.a($(OBJS)) + with an equivalent expansion that should work with any make + that supports $(patsubst). + + Author: Nigel Croxon + Date: Wed Jun 12 09:53:01 2013 -0400 + + support .text.* sections on x86_64 + + Group them in .text. Also add vague linkage sections in .text. + + Signed-off-by: David Decotigny + + Author: Nigel Croxon + Date: Wed Jun 12 09:51:36 2013 -0400 + + cleanup and fix Make.defaults + + Reorder variables in Make.defaults so that they are grouped by + functions. Also fixed ifeq (x,y) to have required syntax and make it + work for ARCH amd64->x86_64 renaming on BSD. Also provides top-level + Makefile with a "mkvars" target that displays effective variables. + + Signed-off-by: David Decotigny + + Author: Nigel Croxon + Date: Wed Jun 12 09:47:16 2013 -0400 + + automatically determine number of uefi_call_wrapper() args on x86_64 + + Instead of asking developers to explicitly pass the number of + parameters to the functions that get called, we determine them + automatically at preprocessing time. This should result in more + robust code. + + Argument va_num is now ignored in x86_64 code, both with and + without HAVE_USE_MS_ABI. + + Credits to the macro magic given in the comments. + + Signed-off-by: David Decotigny + + Author: Nigel Croxon + Date: Wed Jun 12 09:38:10 2013 -0400 + + fix parameter-passing corruption on x86_64 for >= 5 args + + On x86_64 without HAVE_USE_MS_ABI support, uefi_call_wrapper() is a + variadic function. Parameters >=5 are copied to the stack and, when + passed small immediate values (and possibly other parameters), gcc + would emit a movl instruction before calling uefi_call_wrapper(). As a + result, only the lower 32b of these stack values are significant, the + upper 32b potentially contain garbage. Considering that + uefi_call_wrapper() assumes these arguments are clean 64b values + before calling the efi_callX() trampolines, the latter may be passed + garbage. This makes calling functions like + EFI_PCI_IO_PROTOCOL.Mem.Read()/Write() or BS->OpenProtocol() quite + unreliable. + + This patch fixes this by turning uefi_call_wrapper() into a macro that + allows to expose the efi_callX() trampoline signatures to the callers, + so that gcc can know upfront that it has to pass all arguments to + efi_callX() as clean 64b values (eg. movq for immediates). The + _cast64_efi_callX macros are just here to avoid a gcc warning, they do + nothing otherwise. + + Signed-off-by: David Decotigny + + Author: noxorc + Date: Wed May 15 15:26:16 2013 -0400 + + - Removes the ElfW() macro usage from reloc_ia32.c and reloc_x86_64.c. These + macros only exist in link.h on Linux. On FreeBSD, the equivalent macro is + __ElfN(). But the macro usage is redundant. You're only going to compile the + ia32 file for IA32 binaries and the x86_64 file for X64 binaries. If you had + just one file built for both cases, then using the macro might make more + sense. + + - Removes the "#define foo_t efi_foo_t" macros from reloc_ia32.c and + reloc_x86_64.c. + + - Modifies inc/x86_64/efibind.h and inc/ia32/efibind.h to use the new + definitions for uint64_t, int64_t and int8_t. The 64-bit types are now defined + as: + + typedef int __attribute__((__mode__(__DI__))) int64_t; + typedef unsigned int __attribute__((__mode__(__DI__))) uint64_t; + + This removes the conflict between the host types dragged in by elf.h and the + type definitions in efibind.h that made the #define foo_t efi_foo_t" hack + necessary. Also, int8_t is now defined as signed char instead of just char + (assuming char == signed char is apparently not good enough). + + - Also modifies these files to use stdint.h instead of stdint-gcc.h. It's + unclear if this is completely correct, but stdint-gcc.h is not present with + all GCC installs, and if you use -std=c99 or later you will force this case to + be hit. This also can break clang, which doesn't have a stdint-gcc.h at all. + + - Removes the #include of from reloc_ia32.c and reloc_x86_64.c (since + with the previous changes it's not needed anymore). + + - Places the #include of after #include /#include so + that we know the types will always be defined properly, in case you build on a + system where doesn't automatically pull in the right header files to + define all the needed types. (This actually happens on VxWorks. It's harmless + elsewhere. If you don't care about VxWorks, you can leave this out.) + + - Modifies setjmp_ia32.S and setjmp_x86_64.S so to change "function" to + @function. The clang compiler doesn't like the former. Clang and GCC both like + the latter. + + - Modifles Make.defaults so that if ARCH is detected as "amd64," it's changed + to "x86_64." It happens that uname -m on 64-bit FreeBSD reports the former + rather than the latter, which breaks the build. This may also be the case on + some other OSes. There's a way to force uname(1) to return x86_64 as the + machine type, but this way is a little friendlier. + + - Creates gnuefi/elf_ia32_fbsd_efi.lds which specifies the object file type as + elf-ia32-freebsd. This is required for building on FreeBSD/i386, not just + FreeBSD/amd64. + + - Modifies apps/Makefile to always use + $(TOPDIR)/gnuefi/elf_$(ARCH)_fbsd_efi.lds when building on either 32-bit or + 64-bit FreeBSD instead of just for the x86_64 case. + + - Changed LDFLAGS in Make.defaults to include --no-undefined. This will cause + linking to fail if there are any unsatisfied symbols when creating foo.so + during any of the app builds, as opposed to just silently succeeding and + producing an unusable binary. + + - Changed CFLAGS to include -ffreestanding -fno-stack-protector -fno-stack- + check. This prevents clang from inserting a call to memset() when compiling + the RtZeroMem() and RtSetMem() routines in lib/runtime/efirtlib.c and guards + against the native compiler in some Linux distros from adding in stack + checking code which relies on libc help that isn't present in the EFI runtime + environment. + + This does the following: + + - Cleans up the ia32 and x86-64 relocation code a bit (tries to break the + dependency between the host ELF headers and the EFI runtime environment) + - Avoids the dependency on stdint-gcc.h which may not always be available + - Allows GNU EFI to build out of the box on both FreeBSD/i386 and + FreeBSD/amd64 + - Allows GNU EFI to build out of the box with either GCC or clang on + FreeBSD/i386 and FreeBSD/amd64 9.0 and later. + - Makes things a little easier to port to VxWorks + - Avoids creating un-runable binaries with unresolved symbol definitions + (which can be very confusing to debug) + + Author: noxorc + Date: Wed May 8 16:29:45 2013 -0400 + + Add the definitions for TCP, UDP and IP, for both IPv4 and IPv6. + + +2013-05-02 Nigel Croxon + * Chnage from Matt Fleming + - Preparation for adding the networking protocol definitions. + Add the service binding protocol. + +2013-02-21 Nigel Croxon + * Change from Peter Jones + - Previously we were incorrectly passing 3 functions with + the System V ABI to UEFI functions as EFI ABI functions. + Mark them as EFIAPI so the compiler will (in our new + GNU_EFI_USE_MS_ABI world) use the correct ABI. + - These need to be EFIAPI functions because in some cases + they call ST->ConOut->OutputString(), which is an EFIAPI + function. (Which means that previously in cases that + needed "cdecl", these didn't work right.) + - If the compiler version is new enough, and GNU_EFI_USE_MS_ABI + is defined, use the function attribute ms_abi on everything + defined with "EFIAPI". Such calls will no longer go through + efi_call*, and as such will be properly type-checked. + - Honor PREFIX and LIBDIR correctly when passed in during the build. + - Add machine type defines for i386, arm/thumb, ia64, ebc, x86_64. + - __STDC_VERSION__ never actually gets defined unless there's a + --std=... line. So we were accidentally defining lots of c99 + types ourself. Since it's 2012, use --std=c11 where appropriate, + and if it's defined and we're using gcc, actually include gcc's + stdint definitions. + - New test application added: route80h. This is a test program + for PciIo. It routes ioport 80h on ICH10 to PCI. This is also + useful on a very limited set of hardware to enable use of + a port 80h debug card. + - New test applcation added: modelist. This lists video modes + the GOP driver is showing us. + * Change from Finnbarr Murphy + - https://sourceforge.net/p/gnu-efi/feature-requests/2/ + Please add the following status codes to + EFI_INCOMPATIBLE_VERSION 25 + EFI_SECURITY_VIOLATION 26 + EFI_CRC_ERROR 27 + EFI_END_OF_MEDIA 28 + EFI_END_OF_FILE 31 + EFI_INVALID_LANGUAGE 32 + EFI_COMPROMISED_DATA 33 + * Change from SourceForge.net Bug report + - https://sourceforge.net/p/gnu-efi/bugs/5/ + BufferSize is a UINT64 *. The file shipped with GNU EFI is from + 1998 whereas the latest one is from 2004. I suspect Intel changed + the API in order handle 64-bit systems. + * Change from Felipe Contreras + - The current code seems to screw the stack at certain points. + Multiple people have complained that gummiboot hangs right away, + which is in part the fault of gummiboot, but happens only + because the stack gets screwed. x86_64 EFI already aligns the + stack, so there's no need for so much code to find a proper + alignment, we always need to shift by 8 anyway. + * Change from A. Steinmetz + - https://sourceforge.net/p/gnu-efi/patches/1/ + The patch prepares for elilo to support uefi pxe over ipv6 + See uefi spec 2.3.1 errata c page 963 as reference. + Verfied on an ASUS Sabertooth X79 BIOS Rev. 2104 system which + is able to do an IPv6 UEFI PXE boot. + * Release 3.0t + +2012-09-21 Nigel Croxon + * Change from Peter Jones + - EFI Block I/O protocol versions 2 and 3 provide more information + regarding physical disk layout, including alingment offset at the + beginning of the disk ("LowestAlignedLba"), logical block size + ("LogicalBlocksPerPhysicalBlock"), and optimal block transfer size + ("OptimalTransferLengthGranularity"). + * Release 3.0r + +2012-04-30 Nigel Croxon + * Change from Matt Fleming + - The .reloc section is now 4096-byte boundary for x86_64. + Without this patch the .reloc section will not adhere to + the alignment value in the FileAlignment field (512 bytes by + default) of the PE/COFF header. This results in a signed + executable failing to boot in a secure boot environment. + * Release 3.0q + +2011-12-12 Nigel Croxon + * Changes from Fenghua Yu + - This fixes redefined types compilation failure for tcc.c on x86_64 machines. + * Release 3.0p + +2011-11-15 Nigel Croxon + * Changes from Darren Hart + - Conditionally assign toolchain binaries to allow overriding them. + - Force a dependency on lib for gnuefi. + * Release 3.0n + +2011-08-23 Nigel Croxon + * Changes from Peter Jones + - Add guarantee 16-byte stack alignment on x86_64. + - Add routine to make callbacks work. + - Add apps/tcc.efi to test calling convention. + * Release 3.0m + +2011-07-22 Nigel Croxon + * Changed Makefiles from GPL to BSD. + * Changes from Peter Jones + - Add ifdefs for ia64 to mirror ia32 and x86-64 so that + one can build with GCC. + - Add headers for PciIo. + - Add the UEFI 2.x bits for EFI_BOOT_SERVICES + - Add an ignore for .note.GNU-stack section in X86-64 linker maps. + * Release 3.0l + +2011-04-07 Nigel Croxon + * Change license from GPL to BSD. + * Release 3.0j + +2009-09-12 Julien BLACHE + * Add support for FreeBSD. + * Release 3.0i + +2009-09-11 Julien BLACHE + * Fix elf_ia32_efi.lds linker script to be compatible with the new + linker behaviour. Patch from the RedHat bugzilla 492183. + +2009-06-18 Nigel Croxon + * Release 3.0h + +2008-11-06 Nigel Croxon + * Fix to not having any relocations at all. + +2008-09-18 Nigel Croxon + * Use LIBDIR in makefiles + * Add setjmp/longjmp + * Fixes incorrect section attribute in crt0-efi-ia32.S + * Adds value EfiResetShutdown to enum EFI_RESET_TYPE + * Fixes a RAW warning in reloc_ia64.S + * Adds the USB HCI device path structure in the headers + patches were supplied by Peter Jones @ RedHat + +2008-02-22 Nigel Croxon + * Added '-mno-red-zone' to x68_64 compiles. + Patch provided by Mats Andersson. + +2008-01-23 Nigel Croxon + * release 3.0e to support x86_64 + EFI calling convention, the stack should be aligned in 16 bytes + to make it possible to use SSE2 in EFI boot services. + This patch fixes this issue. Patch provided by Huang Ying from Intel. + +2007-05-11 Nigel Croxon + * release 3.0d to support x86_64 from Chandramouli Narayanan + from Intel and based on 3.0c-1 + +2006-03-21 Stephane Eranian + * merged patch to support gcc-4.1 submitted by + Raymund Will from Novell/SuSE + +2006-03-20 Stephane Eranian + * updated ia-64 and ia-32 linker scripts to + match latest gcc. The new gcc may put functions in + .text* sections. patch submitted by H.J. Lu from Intel. + +2004-11-19 Stephane Eranian + * added patch to ignore .eh_frame section for IA-32. Patch + submitted by Jim Wilson + +2004-09-23 Stephane Eranian + * added patch to discard unwind sections, newer toolchains + complained about them. Patch submitted by Jesse Barnes from SGI. + +2003-09-29 Stephane Eranian + * updated elf_ia64_efi.lds to reflect new data sections + created by gcc-3.3. Patch provided by Andreas Schwab from Suse. + +2003-06-20 Stephane Eranian + * updated elf_ia64_efi.lds and elf_ia32_efi.lds to include + new types data sections produced by recent version of gcc-3.x + +2002-02-22 Stephane Eranian + * release 3.0a + * modified both IA-64 and IA-32 loader scripts to add support for the + new .rodata sections names (such as rodata.str2.8). Required + for new versions of gcc3.x. + +2001-06-20 Stephane Eranian + * release 3.0 + * split gnu-efi package in two different packages: the libary+include+crt and the bootloader. + * removed W2U() hack and related files to get from wide-char to unicode. + * Use -fshort-wchar option for unicode. + * restructured Makefiles now install under INSTALLROOT. + +2001-04-06 Stephane Eranian + + * incorporated patches from David and Michael Johnston at Intel + to get the package to compile for IA-32 linux target. + + * Fixed ELILO to compile for Ia-32 (does not execute yet, though): + Makefile and start_kernel() function. + +2001-04-06 Andreas Schwab + + * Fixed config.c to + get the timeout directive to do something. implemented the global + root= directive. + + * Fix the efi_main() to deal with the -C option properly + +2001-04-05 Stephane Eranian + + * update efi library to latest EFI toolkit 1.02 as distributed + by Intel. Fixed header + library files to compile with GCC + + * merged ELI and LILO (as of gnu-efi-1.1) together, mostly + taking the config file feature of ELI. + + * renamed LILO to ELILO to make the distinction + + * restructured code to make it easier to understand and maintain + + * fixed FPSWA driver checking and loading: we try all possible + files and let the driver itself figure out if it is the most + recent. + * added support for compression (gzip) but keep support for plain + ELF image. ELILO autodetects the format + + * change the way the kernel is invoked. Now we call it in + physical memory mode. This breaks the dependency between the + kernel code and the loader. No more lilo_start.c madness. + + * changed the way the boot_params are passed. We don't use the + ZERO_PAGE_ADDR trick anymore. Instead we use EFI runtime memory. + The address of the structure is passed to the kernel in r28 + by our convention. + + * released as gnu-efi-2.0 + +2001-04-03 David Mosberger + + * gnuefi/reloc_ia32.c (_relocate): Change return type from "void" + to "int". Return error status if relocation fails for some + reason. + + * gnuefi/elf_ia32_efi.lds: Drop unneeded ".rel.reloc" section. + + * gnuefi/crt0-efi-ia32.S (_start): Exit if _relocate() returns with + non-zero exit status. + + * inc/ia32/efibind.h [__GNUC__]: Force 8-byte alignment for 64-bit + types as that is what EFI appears to be expecting, despite the + "#pragma pack()" at the beginning of the file! + +2001-03-29 David Mosberger + + * gnuefi/reloc_ia32.c: Add a couple of defines to work around + libc/efilib collision on uint64_t et al. + (_relocate): Use ELF32_R_TYPE() instead of ELFW(R_TYPE)(). + + * gnuefi/crt0-efi-ia32.S (dummy): Add a dummy relocation entry. + +2001-03-29 David Mosberger + + * gnuefi/reloc_ia32.c: Add a couple of defines to work around + libc/efilib collision on uint64_t et al. + (_relocate): Use ELF32_R_TYPE() instead of ELFW(R_TYPE)(). + + * gnuefi/crt0-efi-ia32.S (dummy): Add a dummy relocation entry. + +2000-10-26 David Mosberger + + * gnuefi/elf_ia64_efi.lds: Mention .rela.sdata. + + * Make.defaults (CFLAGS): Remove -nostdinc flags so we can pick + up the C compiler's stdarg.h. + + * inc/stdarg.h: Remove this file. It's not correct for gcc (nor + most other optimizing compilers). + +2000-10-10 Stephane Eranian + + * cleaned up the error message and printing of those. + * added support to load the FPSWA from a file in case support is not + present in the firmware already + * fixed split_args() to do the right thing when you have leading spaces + before kernel name + * changed the argify() function to rely on \0 instead of LoadOptionSize + as the field seems to be broken with current firmware + * bumped version to 1.0 + +2000-10-04 David Mosberger + + * gnuefi/reloc_ia64.S: Reserve space for up to 750 function descriptors. + + * gnuefi/elf_ia64_efi.lds: Add .sdata section for small data and + put __gp in the "middle" of it. + + * gnuefi/crt0-efi-ia64.S (_start): Use movl/add to load + gp-relative addresses that could be out of the range of the addl + offset. + * gnuefi/reloc_ia64.S (_relocate): Ditto. + + * apps/Makefile: Remove standard rules and include Make.rules instead. + * lilo/Makefile: Ditto. + + * Make.rules: New file. + +2000-08-04 Stephane Eranian + * released version 0.9 + * incorporated ACPI changes for Asuza by NEC < kouchi@hpc.bs1.fc.nec.co.jp> + * added support for initrd (-i option) original ELI code from Bill Nottingham ) + * lots of cleanups + * got rid of #ifdef LILO_DEBUG and uses macro instead + * fix a few extra memory leaks in create_boot_params() + * added exit capability just before starting the kernel + +2000-06-22 David Mosberger + + * gnuefi/elf_ia64_efi.lds: Add .srodata, .ctors, .IA64.unwind, + .IA64.unwind_info to .data section and .rela.ctors to .rela + section. + +2000-04-03 David Mosberger + + * lilo/lilo.c (LILO_VERSION): Up version number to 0.9. + + * gnuefi/elf_ia64_efi.lds: Include .IA_64.unwind and + .IA_64.unwind_info in .data segment to avoid EFI load error + "ImageAddress: pointer outside of image" error due to the .dynsym + relocations against these sections. + + * ChangeLog: Moved from lilo/ChangeLogs. + + * gnuefi/reloc_ia64.S: fixed typo: .space directive had constant + 100 hardcoded instead of using MAX_FUNCTION_DESCRIPTORS + macro. Duh. + +2000-03-17 Stephane Eranian + + * Released 0.8 + * replace the getopt.c with new version free with better license + * created a documentation file + * fix a couple of memory leaks + * code cleanups + * created a separate directory for lilo in the gnu-efi package. + * added support for the BOOT_IMAGE argument to kernel + * default is to build natively now + diff --git a/gnu-efi/Make.defaults b/gnu-efi/Make.defaults new file mode 100644 index 0000000..ba743f1 --- /dev/null +++ b/gnu-efi/Make.defaults @@ -0,0 +1,183 @@ +# -*- makefile -*- +# Copyright (c) 1999-2007 Hewlett-Packard Development Company, L.P. +# Contributed by David Mosberger +# Contributed by Stephane Eranian +# +# 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 +HOSTCC := $(prefix)gcc +CC := $(prefix)$(CROSS_COMPILE)gcc +AS := $(prefix)$(CROSS_COMPILE)as +LD := $(prefix)$(CROSS_COMPILE)ld +AR := $(prefix)$(CROSS_COMPILE)ar +RANLIB := $(prefix)$(CROSS_COMPILE)ranlib +OBJCOPY := $(prefix)$(CROSS_COMPILE)objcopy + + +# Host/target identification +OS := $(shell uname -s) +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 -e s,i[3456789]86,ia32, -e 's,armv7.*,arm,' ) +endif + +# FreeBSD (and possibly others) reports amd64 instead of x86_64 +ifeq ($(ARCH),amd64) + override ARCH := x86_64 +endif + +# +# Where to build the package +# +OBJDIR := $(TOPDIR)/$(ARCH) + +# +# Variables below derived from variables above +# + +# Arch-specific compilation flags +CPPFLAGS += -DCONFIG_$(ARCH) + +CFLAGS += -Wno-error=pragmas + +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) + GCCVERSION := $(shell $(CC) -dumpversion | cut -f1 -d.) + GCCMINOR := $(shell $(CC) -dumpversion | cut -f2 -d.) + USING_CLANG := $(shell $(CC) -v 2>&1 | grep -q 'clang version' && echo clang) + + # 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 + else ifeq ($(USING_CLANG),clang) + CPPFLAGS += -DGNU_EFI_USE_MS_ABI --std=c11 + endif + + CFLAGS += -mno-red-zone + ifeq ($(HOSTARCH),ia32) + ARCH3264 = -m64 + 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 2>&1 && echo 1) + ifeq ($(CC_CAN_DISABLE_AVX), 1) + CFLAGS += -mno-avx + endif +endif + +ifeq ($(ARCH),mips64el) + CFLAGS += -march=mips64r2 + ARCH3264 = -mabi=64 +endif + +# +# Set HAVE_EFI_OBJCOPY if objcopy understands --target efi-[app|bsdrv|rtdrv], +# otherwise we need to compose the PE/COFF header using the assembler +# +ifneq ($(ARCH),aarch64) +ifneq ($(ARCH),arm) +ifneq ($(ARCH),mips64el) +export HAVE_EFI_OBJCOPY=y +endif +endif +endif + +ifneq ($(ARCH),arm) +export LIBGCC=$(shell $(CC) $(ARCH3264) -print-libgcc-file-name) +endif + +ifeq ($(ARCH),arm) +CFLAGS += -marm +endif + +# Generic compilation flags +INCDIR += -I$(SRCDIR) -I$(TOPDIR)/inc -I$(TOPDIR)/inc/$(ARCH) \ + -I$(TOPDIR)/inc/protocol + +# Only enable -fpic for non MinGW compilers (unneeded on MinGW) +GCCMACHINE := $(shell $(CC) -dumpmachine) +ifneq (mingw32,$(findstring mingw32, $(GCCMACHINE))) + CFLAGS += -fpic +endif + +ifeq (FreeBSD, $(findstring FreeBSD, $(OS))) +CFLAGS += $(ARCH3264) -g -O2 -Wall -Wextra -Werror \ + -fshort-wchar -fno-strict-aliasing \ + -ffreestanding -fno-stack-protector +else +CFLAGS += $(ARCH3264) -g -O2 -Wall -Wextra -Werror \ + -fshort-wchar -fno-strict-aliasing \ + -ffreestanding -fno-stack-protector -fno-stack-check \ + -fno-stack-check \ + $(if $(findstring gcc,$(CC)),-fno-merge-all-constants,) +endif + +ARFLAGS := rDv +ASFLAGS += $(ARCH3264) +LDFLAGS += -nostdlib --warn-common --no-undefined --fatal-warnings \ + --build-id=sha1 diff --git a/gnu-efi/Make.rules b/gnu-efi/Make.rules new file mode 100644 index 0000000..5b1c286 --- /dev/null +++ b/gnu-efi/Make.rules @@ -0,0 +1,58 @@ +# +# Copyright (C) 1999-2007 Hewlett-Packard Co. +# Contributed by David Mosberger +# Contributed by Stephane Eranian +# +# 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 .rel.* -j .rela.* -j .rel* -j .rela* \ + -j .reloc $(FORMAT) $*.so $@ + +%.efi.debug: %.so + $(OBJCOPY) -j .debug_info -j .debug_abbrev -j .debug_aranges \ + -j .debug_line -j .debug_str -j .debug_ranges \ + -j .note.gnu.build-id \ + $(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 $@ diff --git a/gnu-efi/Makefile b/gnu-efi/Makefile new file mode 100644 index 0000000..01d1a01 --- /dev/null +++ b/gnu-efi/Makefile @@ -0,0 +1,129 @@ +# +# Copyright (C) 1999-2007 Hewlett-Packard Co. +# Contributed by David Mosberger +# Contributed by Stephane Eranian +# +# 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. +# + +VERSION = 3.0.9 + +MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) +SRCDIR = $(dir $(MKFILE_PATH)) + +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 $(OBJDIR)/$@ + $(MAKE) -C $(OBJDIR)/$@ -f $(SRCDIR)/$@/Makefile SRCDIR=$(SRCDIR)/$@ ARCH=$(ARCH) + +clean: + rm -f *~ + @for d in $(SUBDIRS); do \ + if [ -d $(OBJDIR)/$$d ]; then \ + $(MAKE) -C $(OBJDIR)/$$d -f $(SRCDIR)/$$d/Makefile SRCDIR=$(SRCDIR)/$$d clean; \ + fi; \ + done + +install: + @for d in $(SUBDIRS); do \ + mkdir -p $(OBJDIR)/$$d; \ + $(MAKE) -C $(OBJDIR)/$$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 + +test-archive: + @rm -rf /tmp/gnu-efi-$(VERSION) /tmp/gnu-efi-$(VERSION)-tmp + @mkdir -p /tmp/gnu-efi-$(VERSION)-tmp + @git archive --format=tar $(shell git branch | awk '/^*/ { print $$2 }') | ( cd /tmp/gnu-efi-$(VERSION)-tmp/ ; tar x ) + @git diff | ( cd /tmp/gnu-efi-$(VERSION)-tmp/ ; patch -s -p1 -b -z .gitdiff ) + @mv /tmp/gnu-efi-$(VERSION)-tmp/ /tmp/gnu-efi-$(VERSION)/ + @dir=$$PWD; cd /tmp; tar -c --bzip2 -f $$dir/gnu-efi-$(VERSION).tar.bz2 gnu-efi-$(VERSION) + @rm -rf /tmp/gnu-efi-$(VERSION) + @echo "The archive is in gnu-efi-$(VERSION).tar.bz2" + +tag: + git tag $(VERSION) refs/heads/master + +archive: tag + @rm -rf /tmp/gnu-efi-$(VERSION) /tmp/gnu-efi-$(VERSION)-tmp + @mkdir -p /tmp/gnu-efi-$(VERSION)-tmp + @git archive --format=tar $(VERSION) | ( cd /tmp/gnu-efi-$(VERSION)-tmp/ ; tar x ) + @mv /tmp/gnu-efi-$(VERSION)-tmp/ /tmp/gnu-efi-$(VERSION)/ + @dir=$$PWD; cd /tmp; tar -c --bzip2 -f $$dir/gnu-efi-$(VERSION).tar.bz2 gnu-efi-$(VERSION) + @rm -rf /tmp/gnu-efi-$(VERSION) + @echo "The archive is in gnu-efi-$(VERSION).tar.bz2" + diff --git a/gnu-efi/README.efilib b/gnu-efi/README.efilib new file mode 100644 index 0000000..bb857ec --- /dev/null +++ b/gnu-efi/README.efilib @@ -0,0 +1,30 @@ + +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. diff --git a/gnu-efi/README.elilo b/gnu-efi/README.elilo new file mode 100644 index 0000000..96a8172 --- /dev/null +++ b/gnu-efi/README.elilo @@ -0,0 +1,19 @@ + + 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 diff --git a/gnu-efi/README.git b/gnu-efi/README.git new file mode 100644 index 0000000..c719b20 --- /dev/null +++ b/gnu-efi/README.git @@ -0,0 +1,21 @@ +README.git + +Generating releases from git a very simple process; + +1) Edit the file "Makefile". Changing the "VERSION" line to the new version. +2) Do a "git commit" just for the version number change. +3) Then do a "make test-archive". +That will make a file in the current directory gnu-efi-$VERSION.tar.bz2 , +with its top level directory gnu-efi-$VERSION/ and the source tree under that. + +Once you've tested that and you're sure it's what you want to release, +4) Do "make archive", which will tag a release in git and generate a +final tarball from it. + +You then push to the archive, being sure to include the tag: +5) "git push origin master:master --tags" + +And upload the archive wherever it's supposed to go. + + + diff --git a/gnu-efi/README.gnuefi b/gnu-efi/README.gnuefi new file mode 100644 index 0000000..512698c --- /dev/null +++ b/gnu-efi/README.gnuefi @@ -0,0 +1,405 @@ + ------------------------------------------------- + Building EFI Applications Using the GNU Toolchain + ------------------------------------------------- + + David Mosberger + + 23 September 1999 + + + Copyright (c) 1999-2007 Hewlett-Packard Co. + Copyright (c) 2006-2010 Intel Co. + +Last update: 04/09/2007 + +* Introduction + +This document has two parts: the first part describes how to develop +EFI applications for IA-64,x86 and x86_64 using the GNU toolchain and the EFI +development environment contained in this directory. The second part +describes some of the more subtle aspects of how this development +environment works. + + + +* Part 1: Developing EFI Applications + + +** Prerequisites: + + To develop x86 and x86_64 EFI applications, the following tools are needed: + + - gcc-3.0 or newer (gcc 2.7.2 is NOT sufficient!) + As of gnu-efi-3.0b, the Redhat 8.0 toolchain is known to work, + but the Redhat 9.0 toolchain is not currently supported. + + - A version of "objcopy" that supports EFI applications. To + check if your version includes EFI support, issue the + command: + + objcopy --help + + Verify that the line "supported targets" contains the string + "efi-app-ia32" and "efi-app-x86_64" and that the "-j" option + accepts wildcards. The binutils release binutils-2.24 + supports Intel64 EFI and accepts wildcard section names. + + - For debugging purposes, it's useful to have a version of + "objdump" that supports EFI applications as well. This + allows inspect and disassemble EFI binaries. + + To develop IA-64 EFI applications, the following tools are needed: + + - A version of gcc newer than July 30th 1999 (older versions + had problems with generating position independent code). + As of gnu-efi-3.0b, gcc-3.1 is known to work well. + + - A version of "objcopy" that supports EFI applications. To + check if your version includes EFI support, issue the + command: + + objcopy --help + + Verify that the line "supported targets" contains the string + "efi-app-ia64" and that the "-j" option accepts wildcards. + + - For debugging purposes, it's useful to have a version of + "objdump" that supports EFI applications as well. This + allows inspect and disassemble EFI binaries. + + +** Directory Structure + +This EFI development environment contains the following +subdirectories: + + inc: This directory contains the EFI-related include files. The + files are taken from Intel's EFI source distribution, except + that various fixes were applied to make it compile with the + GNU toolchain. + + lib: This directory contains the source code for Intel's EFI library. + Again, the files are taken from Intel's EFI source + distribution, with changes to make them compile with the GNU + toolchain. + + gnuefi: This directory contains the glue necessary to convert ELF64 + binaries to EFI binaries. Various runtime code bits, such as + a self-relocator are included as well. This code has been + contributed by the Hewlett-Packard Company and is distributed + under the GNU GPL. + + apps: This directory contains a few simple EFI test apps. + +** Setup + +It is necessary to edit the Makefile in the directory containing this +README file before EFI applications can be built. Specifically, you +should verify that macros CC, AS, LD, AR, RANLIB, and OBJCOPY point to +the appropriate compiler, assembler, linker, ar, and ranlib binaries, +respectively. + +If you're working in a cross-development environment, be sure to set +macro ARCH to the desired target architecture ("ia32" for x86, "x86_64" for +x86_64 and "ia64" for IA-64). For convenience, this can also be done from +the make command line (e.g., "make ARCH=ia64"). + + +** Building + +To build the sample EFI applications provided in subdirectory "apps", +simply invoke "make" in the toplevel directory (the directory +containing this README file). This should build lib/libefi.a and +gnuefi/libgnuefi.a first and then all the EFI applications such as a +apps/t6.efi. + + +** Running + +Just copy the EFI application (e.g., apps/t6.efi) to the EFI +filesystem, boot EFI, and then select "Invoke EFI application" to run +the application you want to test. Alternatively, you can invoke the +Intel-provided "nshell" application and then invoke your test binary +via the command line interface that "nshell" provides. + + +** Writing Your Own EFI Application + +Suppose you have your own EFI application in a file called +"apps/myefiapp.c". To get this application built by the GNU EFI build +environment, simply add "myefiapp.efi" to macro TARGETS in +apps/Makefile. Once this is done, invoke "make" in the top level +directory. This should result in EFI application apps/myefiapp.efi, +ready for execution. + +The GNU EFI build environment allows to write EFI applications as +described in Intel's EFI documentation, except for two differences: + + - The EFI application's entry point is always called "efi_main". The + declaration of this routine is: + + EFI_STATUS efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab); + + - UNICODE string literals must be written as W2U(L"Sample String") + instead of just L"Sample String". The W2U() macro is defined in + . This header file also declares the function W2UCpy() + which allows to convert a wide string into a UNICODE string and + store the result in a programmer-supplied buffer. + + - Calls to EFI services should be made via uefi_call_wrapper(). This + ensures appropriate parameter passing for the architecture. + + +* Part 2: Inner Workings + +WARNING: This part contains all the gory detail of how the GNU EFI +toolchain works. Normal users do not have to worry about such +details. Reading this part incurs a definite risk of inducing severe +headaches or other maladies. + +The basic idea behind the GNU EFI build environment is to use the GNU +toolchain to build a normal ELF binary that, at the end, is converted +to an EFI binary. EFI binaries are really just PE32+ binaries. PE +stands for "Portable Executable" and is the object file format +Microsoft is using on its Windows platforms. PE is basically the COFF +object file format with an MS-DOS2.0 compatible header slapped on in +front of it. The "32" in PE32+ stands for 32 bits, meaning that PE32 +is a 32-bit object file format. The plus in "PE32+" indicates that +this format has been hacked to allow loading a 4GB binary anywhere in +a 64-bit address space (unlike ELF64, however, this is not a full +64-bit object file format because the entire binary cannot span more +than 4GB of address space). EFI binaries are plain PE32+ binaries +except that the "subsystem id" differs from normal Windows binaries. +There are two flavors of EFI binaries: "applications" and "drivers" +and each has there own subsystem id and are identical otherwise. At +present, the GNU EFI build environment supports the building of EFI +applications only, though it would be trivial to generate drivers, as +the only difference is the subsystem id. For more details on PE32+, +see the spec at + + http://msdn.microsoft.com/library/specs/msdn_pecoff.htm. + +In theory, converting a suitable ELF64 binary to PE32+ is easy and +could be accomplished with the "objcopy" utility by specifying option +--target=efi-app-ia32 (x86) or --target=efi-app-ia64 (IA-64). But +life never is that easy, so here some complicating factors: + + (1) COFF sections are very different from ELF sections. + + ELF binaries distinguish between program headers and sections. + The program headers describe the memory segments that need to + be loaded/initialized, whereas the sections describe what + constitutes those segments. In COFF (and therefore PE32+) no + such distinction is made. Thus, COFF sections need to be page + aligned and have a size that is a multiple of the page size + (4KB for EFI), whereas ELF allows sections at arbitrary + addresses and with arbitrary sizes. + + (2) EFI binaries should be relocatable. + + Since EFI binaries are executed in physical mode, EFI cannot + guarantee that a given binary can be loaded at its preferred + address. EFI does _try_ to load a binary at it's preferred + address, but if it can't do so, it will load it at another + address and then relocate the binary using the contents of the + .reloc section. + + (3) On IA-64, the EFI entry point needs to point to a function + descriptor, not to the code address of the entry point. + + (4) The EFI specification assumes that wide characters use UNICODE + encoding. + + ANSI C does not specify the size or encoding that a wide + character uses. These choices are "implementation defined". + On most UNIX systems, the GNU toolchain uses a wchar_t that is + 4 bytes in size. The encoding used for such characters is + (mostly) UCS4. + +In the following sections, we address how the GNU EFI build +environment addresses each of these issues. + + +** (1) Accommodating COFF Sections + +In order to satisfy the COFF constraint of page-sized and page-aligned +sections, the GNU EFI build environment uses the special linker script +in gnuefi/elf_$(ARCH)_efi.lds where $(ARCH) is the target architecture +("ia32" for x86, "x86_64" for x86_64 and "ia64" for IA-64). +This script is set up to create only eight COFF section, each page aligned +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 (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= 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. + + .data + Collects read-only and read-write data, literal string data, + global offset tables, the uninitialized data segment (bss) and + various other sections containing data. + + The reason read-only data is placed here instead of the in + .text is to make it possible to disassemble the .text section + without getting garbage due to read-only data. Besides, since + EFI binaries execute in physical mode, differences in page + protection do not matter. + + The reason the uninitialized data is placed in this section is + that the EFI loader appears to be unable to handle sections + that are allocated but not loaded from the binary. + + .dynamic, .dynsym, .rela, .rel, .reloc + These sections contains the dynamic information necessary to + self-relocate the binary (see below). + +A couple of more points worth noting about the linker script: + + o On IA-64, the global pointer symbol (__gp) needs to be placed such + that the _entire_ EFI binary can be addressed using the signed + 22-bit offset that the "addl" instruction affords. Specifically, + this means that __gp should be placed at ImageBase + 0x200000. + Strictly speaking, only a couple of symbols need to be addressable + in this fashion, so with some care it should be possible to build + binaries much larger than 4MB. To get a list of symbols that need + to be addressable in this fashion, grep the assembly files in + directory gnuefi for the string "@gprel". + + o The link address (ImageBase) of the binary is (arbitrarily) set to + zero. This could be set to something larger to increase the chance + of EFI being able to load the binary without requiring relocation. + However, a start address of 0 makes debugging a wee bit easier + (great for those of us who can add, but not subtract... ;-). + + o The relocation related sections (.dynamic, .rel, .rela, .reloc) + cannot be placed inside .data because some tools in the GNU + toolchain rely on the existence of these sections. + + o Some sections in the ELF binary intentionally get dropped when + building the EFI binary. Particularly noteworthy are the dynamic + relocation sections for the .plabel and .reloc sections. It would + be _wrong_ to include these sections in the EFI binary because it + would result in .reloc and .plabel being relocated twice (once by + the EFI loader and once by the self-relocator; see below for a + description of the latter). Specifically, only the sections + mentioned with the -j option in the final "objcopy" command are + retained in the EFI binary (see Make.rules). + + +** (2) Building Relocatable Binaries + +ELF binaries are normally linked for a fixed load address and are thus +not relocatable. The only kind of ELF object that is relocatable are +shared objects ("shared libraries"). However, even those objects are +usually not completely position independent and therefore require +runtime relocation by the dynamic loader. For example, IA-64 binaries +normally require relocation of the global offset table. + +The approach to building relocatable binaries in the GNU EFI build +environment is to: + + (a) build an ELF shared object + + (b) link it together with a self-relocator that takes care of + applying the dynamic relocations that may be present in the + ELF shared object + + (c) convert the resulting image to an EFI binary + +The self-relocator is of course architecture dependent. The x86 +version can be found in gnuefi/reloc_ia32.c, the x86_64 version +can be found in gnuefi/reloc_x86_64.c and the IA-64 version can be +found in gnuefi/reloc_ia64.S. + +The self-relocator operates as follows: the startup code invokes it +right after EFI has handed off control to the EFI binary at symbol +"_start". Upon activation, the self-relocator searches the .dynamic +section (whose starting address is given by symbol _DYNAMIC) for the +dynamic relocation information, which can be found in the DT_REL, +DT_RELSZ, and DT_RELENT entries of the dynamic table (DT_RELA, +DT_RELASZ, and DT_RELAENT in the case of rela relocations, as is the +case for IA-64). The dynamic relocation information points to the ELF +relocation table. Once this table is found, the self-relocator walks +through it, applying each relocation one by one. Since the EFI +binaries are fully resolved shared objects, only a subset of all +possible relocations need to be supported. Specifically, on x86 only +the R_386_RELATIVE relocation is needed. On IA-64, the relocations +R_IA64_DIR64LSB, R_IA64_REL64LSB, and R_IA64_FPTR64LSB are needed. +Note that the R_IA64_FPTR64LSB relocation requires access to the +dynamic symbol table. This is why the .dynsym section is included in +the EFI binary. Another complication is that this relocation requires +memory to hold the function descriptors (aka "procedure labels" or +"plabels"). Each function descriptor uses 16 bytes of memory. The +IA-64 self-relocator currently reserves a static memory area that can +hold 100 of these descriptors. If the self-relocator runs out of +space, it causes the EFI binary to fail with error code 5 +(EFI_BUFFER_TOO_SMALL). When this happens, the manifest constant +MAX_FUNCTION_DESCRIPTORS in gnuefi/reloc_ia64.S should be increased +and the application recompiled. An easy way to count the number of +function descriptors required by an EFI application is to run the +command: + + objdump --dynamic-reloc example.so | fgrep FPTR64 | wc -l + +assuming "example" is the name of the desired EFI application. + + +** (3) Creating the Function Descriptor for the IA-64 EFI Binaries + +As mentioned above, the IA-64 PE32+ format assumes that the entry +point of the binary is a function descriptor. A function descriptors +consists of two double words: the first one is the code entry point +and the second is the global pointer that should be loaded before +calling the entry point. Since the ELF toolchain doesn't know how to +generate a function descriptor for the entry point, the startup code +in gnuefi/crt0-efi-ia64.S crafts one manually by with the code: + + .section .plabel, "a" + _start_plabel: + data8 _start + data8 __gp + +this places the procedure label for entry point _start in a section +called ".plabel". Now, the only problem is that _start and __gp need +to be relocated _before_ EFI hands control over to the EFI binary. +Fortunately, PE32+ defines a section called ".reloc" that can achieve +this. Thus, in addition to manually crafting the function descriptor, +the startup code also crafts a ".reloc" section that has will cause +the EFI loader to relocate the function descriptor before handing over +control to the EFI binary (again, see the PECOFF spec mentioned above +for details). + +A final question may be why .plabel and .reloc need to go in their own +COFF sections. The answer is simply: we need to be able to discard +the relocation entries that are generated for these sections. By +placing them in these sections, the relocations end up in sections +".rela.plabel" and ".rela.reloc" which makes it easy to filter them +out in the filter script. Also, the ".reloc" section needs to be in +its own section so that the objcopy program can recognize it and can +create the correct directory entries in the PE32+ binary. + + +** (4) Convenient and Portable Generation of UNICODE String Literals + +As of gnu-efi-3.0, we make use (and somewhat abuse) the gcc option +that forces wide characters (WCHAR_T) to use short integers (2 bytes) +instead of integers (4 bytes). This way we match the Unicode character +size. By abuse, we mean that we rely on the fact that the regular ASCII +characters are encoded the same way between (short) wide characters +and Unicode and basically only use the first byte. This allows us +to just use them interchangeably. + +The gcc option to force short wide characters is : -fshort-wchar + + * * * The End * * * diff --git a/gnu-efi/apps/AllocPages.c b/gnu-efi/apps/AllocPages.c new file mode 100644 index 0000000..bb81849 --- /dev/null +++ b/gnu-efi/apps/AllocPages.c @@ -0,0 +1,184 @@ + +/* + * Copyright (C) 2013 Jerry Hoemann + * + * + * 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 +#include + + +#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; + EFI_PHYSICAL_ADDRESS 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/gnu-efi/apps/FreePages.c b/gnu-efi/apps/FreePages.c new file mode 100644 index 0000000..247c75d --- /dev/null +++ b/gnu-efi/apps/FreePages.c @@ -0,0 +1,145 @@ + + +/* + * Copyright (C) 2013 Jerry Hoemann + * + * 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 +#include + +/* + * 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; + EFI_PHYSICAL_ADDRESS 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/gnu-efi/apps/Makefile b/gnu-efi/apps/Makefile new file mode 100644 index 0000000..4e1b69a --- /dev/null +++ b/gnu-efi/apps/Makefile @@ -0,0 +1,95 @@ +# +# Copyright (C) 1999-2001 Hewlett-Packard Co. +# Contributed by David Mosberger +# Contributed by Stephane Eranian +# +# 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 exit.efi \ + FreePages.efi setjmp.efi debughook.efi debughook.efi.debug \ + bltgrid.efi lfbgrid.efi setdbg.efi unsetdbg.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/gnu-efi/apps/bltgrid.c b/gnu-efi/apps/bltgrid.c new file mode 100644 index 0000000..2adde6a --- /dev/null +++ b/gnu-efi/apps/bltgrid.c @@ -0,0 +1,131 @@ +#include +#include + +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; +} diff --git a/gnu-efi/apps/debughook.c b/gnu-efi/apps/debughook.c new file mode 100644 index 0000000..78e4a76 --- /dev/null +++ b/gnu-efi/apps/debughook.c @@ -0,0 +1,97 @@ +#include +#include + +EFI_STATUS +GetVariableAttr(CHAR16 *var, UINT8 **data, UINTN *len, EFI_GUID owner, + UINT32 *attributes) +{ + EFI_STATUS efi_status; + + *len = 0; + + efi_status = uefi_call_wrapper(RT->GetVariable, 5, var, &owner, + NULL, len, NULL); + if (efi_status != EFI_BUFFER_TOO_SMALL) + return efi_status; + + *data = AllocateZeroPool(*len); + if (!*data) + return EFI_OUT_OF_RESOURCES; + + efi_status = uefi_call_wrapper(RT->GetVariable, 5, var, &owner, + attributes, len, *data); + + if (efi_status != EFI_SUCCESS) { + FreePool(*data); + *data = NULL; + } + return efi_status; +} + +EFI_STATUS +GetVariable(CHAR16 *var, UINT8 **data, UINTN *len, EFI_GUID owner) +{ + return GetVariableAttr(var, data, len, owner, NULL); +} + +EFI_GUID DUMMY_GUID = +{0x55aad538, 0x8f82, 0x4e2a, {0xa4,0xf0,0xbe, 0x59, 0x13, 0xb6, 0x5f, 0x1e}}; + +#if defined(__clang__) +# define _OPTNONE __attribute__((optnone)) +#else +# define _OPTNONE __attribute__((__optimize__("0"))) +#endif + +static _OPTNONE void +DebugHook(void) +{ + EFI_GUID guid = DUMMY_GUID; + UINT8 *data = NULL; + UINTN dataSize = 0; + EFI_STATUS efi_status; + register volatile unsigned long long x = 0; + extern char _text, _data; + + if (x) + return; + + efi_status = GetVariable(L"DUMMY_DEBUG", &data, &dataSize, guid); + if (EFI_ERROR(efi_status)) { + return; + } + + Print(L"add-symbol-file /usr/lib/debug/boot/efi/debughook.debug " + L"0x%08x -s .data 0x%08x\n", &_text, &_data); + + Print(L"Pausing for debugger attachment.\n"); + Print(L"To disable this, remove the EFI variable DUMMY_DEBUG-%g .\n", + &guid); + x = 1; + while (x++) { + /* Make this so it can't /totally/ DoS us. */ +#if defined(__x86_64__) || defined(__i386__) || defined(__i686__) + if (x > 4294967294ULL) + break; + __asm__ __volatile__("pause"); +#elif defined(__aarch64__) + if (x > 1000) + break; + __asm__ __volatile__("wfi"); +#else + if (x > 12000) + break; + uefi_call_wrapper(BS->Stall, 1, 5000); +#endif + } + x = 1; +} + + +EFI_STATUS +efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab) +{ + InitializeLib(image, systab); + DebugHook(); + return EFI_SUCCESS; +} diff --git a/gnu-efi/apps/drv0.c b/gnu-efi/apps/drv0.c new file mode 100644 index 0000000..1d0c06f --- /dev/null +++ b/gnu-efi/apps/drv0.c @@ -0,0 +1,191 @@ +/* + * Copyright (C) 2013 David Decotigny + * + * 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 +#include +#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 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( + 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, + (void**)&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/gnu-efi/apps/drv0.h b/gnu-efi/apps/drv0.h new file mode 100644 index 0000000..cf0e054 --- /dev/null +++ b/gnu-efi/apps/drv0.h @@ -0,0 +1,35 @@ +#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, 0xb9} } + +INTERFACE_DECL(_GNU_EFI_APPS_DRV0_PROTOCOL); + +typedef +EFI_STATUS +(EFIAPI *GNU_EFI_APPS_DRV0_SAY_HELLO) ( + IN const CHAR16 *HelloWho + ); + +typedef +EFI_STATUS +(EFIAPI *GNU_EFI_APPS_DRV0_GET_NUMBER_OF_HELLO) ( + 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/gnu-efi/apps/drv0_use.c b/gnu-efi/apps/drv0_use.c new file mode 100644 index 0000000..d8688cf --- /dev/null +++ b/gnu-efi/apps/drv0_use.c @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2013 David Decotigny + * + * See drv0.c for an example session. + */ + +#include +#include +#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, + (void**)&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, L"Sample UEFI Driver"); + if (EFI_ERROR(Status)) { + Print(L"Cannot call SayHello: %d\n", Status); + } + + Status = uefi_call_wrapper(drv->GetNumberOfHello, 2, &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/gnu-efi/apps/exit.c b/gnu-efi/apps/exit.c new file mode 100644 index 0000000..78b94a5 --- /dev/null +++ b/gnu-efi/apps/exit.c @@ -0,0 +1,12 @@ +#include +#include + +EFI_STATUS +efi_main (EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *systab) +{ + InitializeLib(image_handle, systab); + + Exit(EFI_SUCCESS, 0, NULL); + + return EFI_UNSUPPORTED; +} diff --git a/gnu-efi/apps/lfbgrid.c b/gnu-efi/apps/lfbgrid.c new file mode 100644 index 0000000..53a255a --- /dev/null +++ b/gnu-efi/apps/lfbgrid.c @@ -0,0 +1,170 @@ +#include +#include + +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; +} diff --git a/gnu-efi/apps/modelist.c b/gnu-efi/apps/modelist.c new file mode 100644 index 0000000..26892e1 --- /dev/null +++ b/gnu-efi/apps/modelist.c @@ -0,0 +1,108 @@ +#include +#include + +extern EFI_GUID GraphicsOutputProtocol; + +static void +print_modes(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop) +{ + int i, imax; + EFI_STATUS rc; + + 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; + } + + 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 ? 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; + } + 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"); + 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)) { + 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); + + SetWatchdog(0); + return EFI_SUCCESS; +} diff --git a/gnu-efi/apps/printenv.c b/gnu-efi/apps/printenv.c new file mode 100644 index 0000000..6341e40 --- /dev/null +++ b/gnu-efi/apps/printenv.c @@ -0,0 +1,32 @@ +#include +#include + +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/gnu-efi/apps/route80h.c b/gnu-efi/apps/route80h.c new file mode 100644 index 0000000..5272dd3 --- /dev/null +++ b/gnu-efi/apps/route80h.c @@ -0,0 +1,136 @@ +#include +#include + +/* 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 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, 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 = EFI_SUCCESS; + 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 *)(intptr_t)(lpcif.rcba + GCS_OFFSET_ADDR), + GCS_RPR_SHIFT, GCS_RPR_PCI); + + return EFI_SUCCESS; +} diff --git a/gnu-efi/apps/setdbg.c b/gnu-efi/apps/setdbg.c new file mode 100644 index 0000000..897140e --- /dev/null +++ b/gnu-efi/apps/setdbg.c @@ -0,0 +1,37 @@ +#include +#include + +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; +} diff --git a/gnu-efi/apps/setjmp.c b/gnu-efi/apps/setjmp.c new file mode 100644 index 0000000..bd70c11 --- /dev/null +++ b/gnu-efi/apps/setjmp.c @@ -0,0 +1,31 @@ + +#include +#include + +EFI_STATUS +efi_main( + EFI_HANDLE image_handle, + EFI_SYSTEM_TABLE *systab +) +{ + jmp_buf env; + int rc; + + InitializeLib(image_handle, systab); + rc = setjmp(&env); + Print(L"setjmp() = %d\n", rc); + + if (rc == 3) { + Print(L"3 worked\n"); + longjmp(&env, 0); + return 0; + } + + if (rc == 1) { + Print(L"0 got to be one yay\n"); + return 0; + } + + longjmp(&env, 3); + return 0; +} diff --git a/gnu-efi/apps/t.c b/gnu-efi/apps/t.c new file mode 100644 index 0000000..c7e3d57 --- /dev/null +++ b/gnu-efi/apps/t.c @@ -0,0 +1,27 @@ +#include +#include + +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/gnu-efi/apps/t2.c b/gnu-efi/apps/t2.c new file mode 100644 index 0000000..6a09c42 --- /dev/null +++ b/gnu-efi/apps/t2.c @@ -0,0 +1,14 @@ +#include +#include + +EFI_STATUS +efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab) +{ + SIMPLE_TEXT_OUTPUT_INTERFACE *conout; + + InitializeLib(image, systab); + conout = systab->ConOut; + uefi_call_wrapper(conout->OutputString, 2, conout, L"Hello World!\n\r"); + + return EFI_SUCCESS; +} diff --git a/gnu-efi/apps/t3.c b/gnu-efi/apps/t3.c new file mode 100644 index 0000000..623830a --- /dev/null +++ b/gnu-efi/apps/t3.c @@ -0,0 +1,95 @@ +#include +#include + +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/gnu-efi/apps/t4.c b/gnu-efi/apps/t4.c new file mode 100644 index 0000000..b8487ec --- /dev/null +++ b/gnu-efi/apps/t4.c @@ -0,0 +1,14 @@ +#include +#include + +EFI_STATUS +efi_main (EFI_HANDLE *image, EFI_SYSTEM_TABLE *systab) +{ + UINTN index; + + InitializeLib(image, systab); + 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/gnu-efi/apps/t5.c b/gnu-efi/apps/t5.c new file mode 100644 index 0000000..7c868d2 --- /dev/null +++ b/gnu-efi/apps/t5.c @@ -0,0 +1,13 @@ +#include +#include + +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/gnu-efi/apps/t6.c b/gnu-efi/apps/t6.c new file mode 100644 index 0000000..f95ea66 --- /dev/null +++ b/gnu-efi/apps/t6.c @@ -0,0 +1,43 @@ +#include +#include + +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/gnu-efi/apps/t7.c b/gnu-efi/apps/t7.c new file mode 100644 index 0000000..f02aaee --- /dev/null +++ b/gnu-efi/apps/t7.c @@ -0,0 +1,25 @@ +#include +#include + +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 CallRtStatus: %x\n", + efi_input_key.ScanCode, efi_input_key.UnicodeChar, efi_status); + + return EFI_SUCCESS; +} diff --git a/gnu-efi/apps/t8.c b/gnu-efi/apps/t8.c new file mode 100644 index 0000000..10f8811 --- /dev/null +++ b/gnu-efi/apps/t8.c @@ -0,0 +1,19 @@ +#include +#include + +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/gnu-efi/apps/tcc.c b/gnu-efi/apps/tcc.c new file mode 100644 index 0000000..09ad98b --- /dev/null +++ b/gnu-efi/apps/tcc.c @@ -0,0 +1,431 @@ +/* + * Test if our calling convention gymnastics actually work + */ + +#include +#include + +#if 0 +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 */ + +#ifdef __x86_64__ + __asm__ volatile("out %0,%1" : : "a" ((uint8_t)0x14), "dN" (0x80)); +#endif + + 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/gnu-efi/apps/tpause.c b/gnu-efi/apps/tpause.c new file mode 100644 index 0000000..51c86df --- /dev/null +++ b/gnu-efi/apps/tpause.c @@ -0,0 +1,9 @@ +#include +#include + +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/gnu-efi/apps/trivial.S b/gnu-efi/apps/trivial.S new file mode 100644 index 0000000..40bc68f --- /dev/null +++ b/gnu-efi/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 diff --git a/gnu-efi/apps/unsetdbg.c b/gnu-efi/apps/unsetdbg.c new file mode 100644 index 0000000..731e09b --- /dev/null +++ b/gnu-efi/apps/unsetdbg.c @@ -0,0 +1,37 @@ +#include +#include + +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; +} diff --git a/gnu-efi/gnuefi/Makefile b/gnu-efi/gnuefi/Makefile new file mode 100644 index 0000000..2a61699 --- /dev/null +++ b/gnu-efi/gnuefi/Makefile @@ -0,0 +1,75 @@ +# +# Copyright (C) 1999-2001 Hewlett-Packard Co. +# Contributed by David Mosberger +# Contributed by Stephane Eranian +# +# 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)/.. +FILES = reloc_$(ARCH) + +OBJS = $(FILES:%=%.o) + +# on aarch64, avoid jump tables before all relocations have been processed +reloc_aarch64.o: CFLAGS += -fno-jump-tables + +TARGETS = crt0-efi-$(ARCH).o libgnuefi.a + +all: $(TARGETS) + +libgnuefi.a: $(patsubst %,libgnuefi.a(%),$(OBJS)) + +clean: + rm -f $(TARGETS) *~ *.o $(OBJS) + +install: + mkdir -p $(INSTALLROOT)$(LIBDIR) + $(INSTALL) -m 644 $(TARGETS) $(INSTALLROOT)$(LIBDIR) +ifneq (,$(findstring FreeBSD,$(OS))) + ifeq ($(ARCH),x86_64) + $(INSTALL) -m 644 $(SRCDIR)/elf_$(ARCH)_fbsd_efi.lds $(INSTALLROOT)$(LIBDIR) + else + $(INSTALL) -m 644 $(SRCDIR)/elf_$(ARCH)_efi.lds $(INSTALLROOT)$(LIBDIR) + endif +else + $(INSTALL) -m 644 $(SRCDIR)/elf_$(ARCH)_efi.lds $(INSTALLROOT)$(LIBDIR) +endif + +include $(SRCDIR)/../Make.rules diff --git a/gnu-efi/gnuefi/crt0-efi-aarch64.S b/gnu-efi/gnuefi/crt0-efi-aarch64.S new file mode 100644 index 0000000..c300d89 --- /dev/null +++ b/gnu-efi/gnuefi/crt0-efi-aarch64.S @@ -0,0 +1,130 @@ +/* + * crt0-efi-aarch64.S - PE/COFF header for AArch64 EFI applications + * + * Copright (C) 2014 Linaro Ltd. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice and this list of conditions, without modification. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License as published by the Free Software Foundation; + * either version 2 of the License, or (at your option) any later version. + */ + + .section .text.head + + /* + * Magic "MZ" signature for PE/COFF + */ + .globl ImageBase +ImageBase: + .ascii "MZ" + .skip 58 // 'MZ' + pad + offset == 64 + .long pe_header - ImageBase // Offset to the PE header. +pe_header: + .ascii "PE" + .short 0 +coff_header: + .short 0xaa64 // AArch64 + .short 2 // nr_sections + .long 0 // TimeDateStamp + .long 0 // PointerToSymbolTable + .long 1 // NumberOfSymbols + .short section_table - optional_header // SizeOfOptionalHeader + .short 0x206 // Characteristics. + // IMAGE_FILE_DEBUG_STRIPPED | + // IMAGE_FILE_EXECUTABLE_IMAGE | + // IMAGE_FILE_LINE_NUMS_STRIPPED +optional_header: + .short 0x20b // PE32+ format + .byte 0x02 // MajorLinkerVersion + .byte 0x14 // MinorLinkerVersion + .long _data - _start // SizeOfCode + .long _data_size // SizeOfInitializedData + .long 0 // SizeOfUninitializedData + .long _start - ImageBase // AddressOfEntryPoint + .long _start - ImageBase // BaseOfCode + +extra_header_fields: + .quad 0 // ImageBase + .long 0x1000 // SectionAlignment + .long 0x200 // FileAlignment + .short 0 // MajorOperatingSystemVersion + .short 0 // MinorOperatingSystemVersion + .short 0 // MajorImageVersion + .short 0 // MinorImageVersion + .short 0 // MajorSubsystemVersion + .short 0 // MinorSubsystemVersion + .long 0 // Win32VersionValue + + .long _edata - ImageBase // SizeOfImage + + // Everything before the kernel image is considered part of the header + .long _start - ImageBase // SizeOfHeaders + .long 0 // CheckSum + .short EFI_SUBSYSTEM // Subsystem + .short 0 // DllCharacteristics + .quad 0 // SizeOfStackReserve + .quad 0 // SizeOfStackCommit + .quad 0 // SizeOfHeapReserve + .quad 0 // SizeOfHeapCommit + .long 0 // LoaderFlags + .long 0x6 // NumberOfRvaAndSizes + + .quad 0 // ExportTable + .quad 0 // ImportTable + .quad 0 // ResourceTable + .quad 0 // ExceptionTable + .quad 0 // CertificationTable + .quad 0 // BaseRelocationTable + + // Section table +section_table: + .ascii ".text\0\0\0" + .long _data - _start // VirtualSize + .long _start - ImageBase // VirtualAddress + .long _data - _start // SizeOfRawData + .long _start - ImageBase // PointerToRawData + + .long 0 // PointerToRelocations (0 for executables) + .long 0 // PointerToLineNumbers (0 for executables) + .short 0 // NumberOfRelocations (0 for executables) + .short 0 // NumberOfLineNumbers (0 for executables) + .long 0x60000020 // Characteristics (section flags) + + .ascii ".data\0\0\0" + .long _data_size // VirtualSize + .long _data - ImageBase // VirtualAddress + .long _data_size // SizeOfRawData + .long _data - ImageBase // PointerToRawData + + .long 0 // PointerToRelocations (0 for executables) + .long 0 // PointerToLineNumbers (0 for executables) + .short 0 // NumberOfRelocations (0 for executables) + .short 0 // NumberOfLineNumbers (0 for executables) + .long 0xc0000040 // Characteristics (section flags) + + .align 12 +_start: + stp x29, x30, [sp, #-32]! + mov x29, sp + + stp x0, x1, [sp, #16] + mov x2, x0 + mov x3, x1 + adr x0, ImageBase + adrp x1, _DYNAMIC + add x1, x1, #:lo12:_DYNAMIC + bl _relocate + cbnz x0, 0f + + ldp x0, x1, [sp, #16] + bl efi_main + +0: ldp x29, x30, [sp], #32 + ret diff --git a/gnu-efi/gnuefi/crt0-efi-arm.S b/gnu-efi/gnuefi/crt0-efi-arm.S new file mode 100644 index 0000000..c5bb6d4 --- /dev/null +++ b/gnu-efi/gnuefi/crt0-efi-arm.S @@ -0,0 +1,145 @@ +/* + * crt0-efi-arm.S - PE/COFF header for ARM EFI applications + * + * Copright (C) 2014 Linaro Ltd. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice and this list of conditions, without modification. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License as published by the Free Software Foundation; + * either version 2 of the License, or (at your option) any later version. + */ + + .section .text.head + + /* + * Magic "MZ" signature for PE/COFF + */ + .globl ImageBase +ImageBase: + .ascii "MZ" + .skip 58 // 'MZ' + pad + offset == 64 + .long pe_header - ImageBase // Offset to the PE header. +pe_header: + .ascii "PE" + .short 0 +coff_header: + .short 0x1c2 // Mixed ARM/Thumb + .short 2 // nr_sections + .long 0 // TimeDateStamp + .long 0 // PointerToSymbolTable + .long 1 // NumberOfSymbols + .short section_table - optional_header // SizeOfOptionalHeader + .short 0x306 // Characteristics. + // IMAGE_FILE_32BIT_MACHINE | + // IMAGE_FILE_DEBUG_STRIPPED | + // IMAGE_FILE_EXECUTABLE_IMAGE | + // IMAGE_FILE_LINE_NUMS_STRIPPED +optional_header: + .short 0x10b // PE32+ format + .byte 0x02 // MajorLinkerVersion + .byte 0x14 // MinorLinkerVersion + .long _edata - _start // SizeOfCode + .long 0 // SizeOfInitializedData + .long 0 // SizeOfUninitializedData + .long _start - ImageBase // AddressOfEntryPoint + .long _start - ImageBase // BaseOfCode + .long 0 // BaseOfData + +extra_header_fields: + .long 0 // ImageBase + .long 0x20 // SectionAlignment + .long 0x8 // FileAlignment + .short 0 // MajorOperatingSystemVersion + .short 0 // MinorOperatingSystemVersion + .short 0 // MajorImageVersion + .short 0 // MinorImageVersion + .short 0 // MajorSubsystemVersion + .short 0 // MinorSubsystemVersion + .long 0 // Win32VersionValue + + .long _edata - ImageBase // SizeOfImage + + // Everything before the kernel image is considered part of the header + .long _start - ImageBase // SizeOfHeaders + .long 0 // CheckSum + .short EFI_SUBSYSTEM // Subsystem + .short 0 // DllCharacteristics + .long 0 // SizeOfStackReserve + .long 0 // SizeOfStackCommit + .long 0 // SizeOfHeapReserve + .long 0 // SizeOfHeapCommit + .long 0 // LoaderFlags + .long 0x6 // NumberOfRvaAndSizes + + .quad 0 // ExportTable + .quad 0 // ImportTable + .quad 0 // ResourceTable + .quad 0 // ExceptionTable + .quad 0 // CertificationTable + .quad 0 // BaseRelocationTable + + // Section table +section_table: + + /* + * The EFI application loader requires a relocation section + * because EFI applications must be relocatable. This is a + * dummy section as far as we are concerned. + */ + .ascii ".reloc" + .byte 0 + .byte 0 // end of 0 padding of section name + .long 0 + .long 0 + .long 0 // SizeOfRawData + .long 0 // PointerToRawData + .long 0 // PointerToRelocations + .long 0 // PointerToLineNumbers + .short 0 // NumberOfRelocations + .short 0 // NumberOfLineNumbers + .long 0x42100040 // Characteristics (section flags) + + + .ascii ".text" + .byte 0 + .byte 0 + .byte 0 // end of 0 padding of section name + .long _edata - _start // VirtualSize + .long _start - ImageBase // VirtualAddress + .long _edata - _start // SizeOfRawData + .long _start - ImageBase // PointerToRawData + + .long 0 // PointerToRelocations (0 for executables) + .long 0 // PointerToLineNumbers (0 for executables) + .short 0 // NumberOfRelocations (0 for executables) + .short 0 // NumberOfLineNumbers (0 for executables) + .long 0xe0500020 // Characteristics (section flags) + +_start: + stmfd sp!, {r0-r2, lr} + + mov r2, r0 + mov r3, r1 + adr r1, .L_DYNAMIC + ldr r0, [r1] + add r1, r0, r1 + adr r0, ImageBase + bl _relocate + teq r0, #0 + bne 0f + + ldmfd sp, {r0-r1} + bl efi_main + +0: add sp, sp, #12 + ldr pc, [sp], #4 + +.L_DYNAMIC: + .word _DYNAMIC - . diff --git a/gnu-efi/gnuefi/crt0-efi-ia32.S b/gnu-efi/gnuefi/crt0-efi-ia32.S new file mode 100644 index 0000000..f9d5191 --- /dev/null +++ b/gnu-efi/gnuefi/crt0-efi-ia32.S @@ -0,0 +1,76 @@ +/* crt0-efi-ia32.S - x86 EFI startup code. + Copyright (C) 1999 Hewlett-Packard Co. + Contributed by David Mosberger . + + 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. +*/ + + .text + .align 4 + + .globl _start +_start: + pushl %ebp + movl %esp,%ebp + + pushl 12(%ebp) # copy "image" argument + pushl 8(%ebp) # copy "systab" argument + + call 0f +0: popl %eax + movl %eax,%ebx + + addl $ImageBase-0b,%eax # %eax = ldbase + addl $_DYNAMIC-0b,%ebx # %ebx = _DYNAMIC + + pushl %ebx # pass _DYNAMIC as second argument + pushl %eax # pass ldbase as first argument + call _relocate + popl %ebx + popl %ebx + testl %eax,%eax + jne .exit + + call efi_main # call app with "image" and "systab" argument + +.exit: leave + ret + + // hand-craft a dummy .reloc section so EFI knows it's a relocatable executable: + + .data +dummy: .long 0 + +#define IMAGE_REL_ABSOLUTE 0 + .section .reloc + .long dummy // Page RVA + .long 10 // Block Size (2*4+2) + .word (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy diff --git a/gnu-efi/gnuefi/crt0-efi-ia64.S b/gnu-efi/gnuefi/crt0-efi-ia64.S new file mode 100644 index 0000000..40c3c83 --- /dev/null +++ b/gnu-efi/gnuefi/crt0-efi-ia64.S @@ -0,0 +1,87 @@ +/* crt0-efi-ia64.S - IA-64 EFI startup code. + Copyright (C) 1999 Hewlett-Packard Co. + Contributed by David Mosberger . + + 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. +*/ + .text + .psr abi64 + .psr lsb + .lsb + + .proc _start +_start: + alloc loc0=ar.pfs,2,2,2,0 + mov loc1=rp + movl out0=@gprel(ImageBase) // out0 <- ImageBase (ldbase) + ;; + add out0=out0,gp + movl out1=@gprel(_DYNAMIC) // out1 <- _DYNAMIC + ;; // avoid WAW on CFM + add out1=out1,gp + br.call.sptk.few rp=_relocate +.Lret0: + cmp.ne p6,p0=r0,r8 // r8 == EFI_SUCCESS? +(p6) br.cond.sptk.few .exit // no -> + +.Lret1: + + mov out0=in0 // image handle + mov out1=in1 // systab + br.call.sptk.few rp=efi_main +.Lret2: +.exit: + mov ar.pfs=loc0 + mov rp=loc1 + ;; + br.ret.sptk.few rp + + .endp _start + + + // PE32+ wants a PLABEL, not the code address of the entry point: + + .align 16 + .global _start_plabel + .section .plabel, "a" +_start_plabel: + data8 _start + data8 __gp + + // hand-craft a .reloc section for the plabel: + +#define IMAGE_REL_BASED_DIR64 10 + + .section .reloc, "a" + data4 _start_plabel // Page RVA + data4 12 // Block Size (2*4+2*2) + data2 (IMAGE_REL_BASED_DIR64<<12) + 0 // reloc for plabel's entry point + data2 (IMAGE_REL_BASED_DIR64<<12) + 8 // reloc for plabel's global pointer diff --git a/gnu-efi/gnuefi/crt0-efi-mips64el.S b/gnu-efi/gnuefi/crt0-efi-mips64el.S new file mode 100644 index 0000000..6a62aca --- /dev/null +++ b/gnu-efi/gnuefi/crt0-efi-mips64el.S @@ -0,0 +1,188 @@ +/* + * crt0-efi-mips64el.S - PE/COFF header for MIPS64 EFI applications + * + * Copright (C) 2014 Linaro Ltd. + * Copright (C) 2017 Heiher + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice and this list of conditions, without modification. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License as published by the Free Software Foundation; + * either version 2 of the License, or (at your option) any later version. + */ + + .section .text.head + + /* + * Magic "MZ" signature for PE/COFF + */ + .globl ImageBase +ImageBase: + .ascii "MZ" + .skip 58 // 'MZ' + pad + offset == 64 + .long pe_header - ImageBase // Offset to the PE header. +pe_header: + .ascii "PE" + .short 0 +coff_header: + .short 0x166 // MIPS little endian + .short 2 // nr_sections + .long 0 // TimeDateStamp + .long 0 // PointerToSymbolTable + .long 1 // NumberOfSymbols + .short section_table - optional_header // SizeOfOptionalHeader + .short 0x206 // Characteristics. + // IMAGE_FILE_DEBUG_STRIPPED | + // IMAGE_FILE_EXECUTABLE_IMAGE | + // IMAGE_FILE_LINE_NUMS_STRIPPED +optional_header: + .short 0x20b // PE32+ format + .byte 0x02 // MajorLinkerVersion + .byte 0x14 // MinorLinkerVersion + .long _edata - _start // SizeOfCode + .long 0 // SizeOfInitializedData + .long 0 // SizeOfUninitializedData + .long _start - ImageBase // AddressOfEntryPoint + .long _start - ImageBase // BaseOfCode + +extra_header_fields: + .quad 0 // ImageBase + .long 0x20 // SectionAlignment + .long 0x8 // FileAlignment + .short 0 // MajorOperatingSystemVersion + .short 0 // MinorOperatingSystemVersion + .short 0 // MajorImageVersion + .short 0 // MinorImageVersion + .short 0 // MajorSubsystemVersion + .short 0 // MinorSubsystemVersion + .long 0 // Win32VersionValue + + .long _edata - ImageBase // SizeOfImage + + // Everything before the kernel image is considered part of the header + .long _start - ImageBase // SizeOfHeaders + .long 0 // CheckSum + .short EFI_SUBSYSTEM // Subsystem + .short 0 // DllCharacteristics + .quad 0 // SizeOfStackReserve + .quad 0 // SizeOfStackCommit + .quad 0 // SizeOfHeapReserve + .quad 0 // SizeOfHeapCommit + .long 0 // LoaderFlags + .long 0x6 // NumberOfRvaAndSizes + + .quad 0 // ExportTable + .quad 0 // ImportTable + .quad 0 // ResourceTable + .quad 0 // ExceptionTable + .quad 0 // CertificationTable + .quad 0 // BaseRelocationTable + + // Section table +section_table: + + /* + * The EFI application loader requires a relocation section + * because EFI applications must be relocatable. This is a + * dummy section as far as we are concerned. + */ + .ascii ".reloc" + .byte 0 + .byte 0 // end of 0 padding of section name + .long 0 + .long 0 + .long 0 // SizeOfRawData + .long 0 // PointerToRawData + .long 0 // PointerToRelocations + .long 0 // PointerToLineNumbers + .short 0 // NumberOfRelocations + .short 0 // NumberOfLineNumbers + .long 0x42100040 // Characteristics (section flags) + + + .ascii ".text" + .byte 0 + .byte 0 + .byte 0 // end of 0 padding of section name + .long _edata - _start // VirtualSize + .long _start - ImageBase // VirtualAddress + .long _edata - _start // SizeOfRawData + .long _start - ImageBase // PointerToRawData + + .long 0 // PointerToRelocations (0 for executables) + .long 0 // PointerToLineNumbers (0 for executables) + .short 0 // NumberOfRelocations (0 for executables) + .short 0 // NumberOfLineNumbers (0 for executables) + .long 0xe0500020 // Characteristics (section flags) + + .set push + .set noreorder + .align 4 + + .globl _start + .ent _start + .type _start, @function +_start: + daddiu $sp, -32 + sd $ra, ($sp) + + // Get pc & gp + .align 3 + bal 1f + sd $gp, 8($sp) +_pc: + .dword _gp + .dword _DYNAMIC + .dword _relocate +1: + // pc in ra + ld $gp, ($ra) + dli $t0, _pc + dsubu $gp, $t0 + daddu $gp, $ra + + sd $a0, 16($sp) + sd $a1, 24($sp) + + // a2: ImageHandle + move $a2, $a0 + // a3: SystemTable + move $a3, $a1 + // a0: ImageBase + dli $t1, ImageBase - _pc + daddu $a0, $ra, $t1 + // a1: DynamicSection + ld $t1, 8($ra) + dsubu $t1, $t0 + daddu $a1, $ra, $t1 + // call _relocate + ld $t1, 16($ra) + dsubu $t1, $t0 + daddu $t9, $ra, $t1 + jalr $t9 + nop + bnez $v0, 1b + nop + + // a0: ImageHandle + ld $a0, 16($sp) + // call efi_main + dla $t9, efi_main + jalr $t9 + // a1: SystemTable + ld $a1, 24($sp) + +1: + ld $gp, 8($sp) + ld $ra, ($sp) + jr $ra + daddiu $sp, 32 + .end _start + + .set pop diff --git a/gnu-efi/gnuefi/crt0-efi-x86_64.S b/gnu-efi/gnuefi/crt0-efi-x86_64.S new file mode 100644 index 0000000..6839150 --- /dev/null +++ b/gnu-efi/gnuefi/crt0-efi-x86_64.S @@ -0,0 +1,76 @@ +/* crt0-efi-x86_64.S - x86_64 EFI startup code. + Copyright (C) 1999 Hewlett-Packard Co. + Contributed by David Mosberger . + Copyright (C) 2005 Intel Co. + Contributed by Fenghua Yu . + + 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. +*/ + .text + .align 4 + + .globl _start +_start: + subq $8, %rsp + pushq %rcx + pushq %rdx + +0: + lea ImageBase(%rip), %rdi + lea _DYNAMIC(%rip), %rsi + + popq %rcx + popq %rdx + pushq %rcx + pushq %rdx + call _relocate + + popq %rdi + popq %rsi + + call efi_main + addq $8, %rsp + +.exit: + ret + + // hand-craft a dummy .reloc section so EFI knows it's a relocatable executable: + + .data +dummy: .long 0 + +#define IMAGE_REL_ABSOLUTE 0 + .section .reloc, "a" +label1: + .long dummy-label1 // Page RVA + .long 10 // Block Size (2*4+2) + .word (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy + diff --git a/gnu-efi/gnuefi/elf_aarch64_efi.lds b/gnu-efi/gnuefi/elf_aarch64_efi.lds new file mode 100644 index 0000000..836d982 --- /dev/null +++ b/gnu-efi/gnuefi/elf_aarch64_efi.lds @@ -0,0 +1,63 @@ +OUTPUT_FORMAT("elf64-littleaarch64", "elf64-littleaarch64", "elf64-littleaarch64") +OUTPUT_ARCH(aarch64) +ENTRY(_start) +SECTIONS +{ + .text 0x0 : { + _text = .; + *(.text.head) + *(.text) + *(.text.*) + *(.gnu.linkonce.t.*) + *(.srodata) + *(.rodata*) + . = ALIGN(16); + } + _etext = .; + _text_size = . - _text; + .dynamic : { *(.dynamic) } + .data : ALIGN(4096) + { + _data = .; + *(.sdata) + *(.data) + *(.data1) + *(.data.*) + *(.got.plt) + *(.got) + + /* the EFI loader doesn't seem to like a .bss section, so we stick + it all into .data: */ + . = ALIGN(16); + _bss = .; + *(.sbss) + *(.scommon) + *(.dynbss) + *(.bss) + *(COMMON) + . = ALIGN(16); + _bss_end = .; + } + + .rela.dyn : { *(.rela.dyn) } + .rela.plt : { *(.rela.plt) } + .rela.got : { *(.rela.got) } + .rela.data : { *(.rela.data) *(.rela.data*) } + . = ALIGN(512); + _edata = .; + _data_size = . - _data; + + . = ALIGN(4096); + .dynsym : { *(.dynsym) } + . = ALIGN(4096); + .dynstr : { *(.dynstr) } + . = ALIGN(4096); + .note.gnu.build-id : { *(.note.gnu.build-id) } + /DISCARD/ : + { + *(.rel.reloc) + *(.eh_frame) + *(.note.GNU-stack) + } + .comment 0 : { *(.comment) } +} diff --git a/gnu-efi/gnuefi/elf_arm_efi.lds b/gnu-efi/gnuefi/elf_arm_efi.lds new file mode 100644 index 0000000..665bbdb --- /dev/null +++ b/gnu-efi/gnuefi/elf_arm_efi.lds @@ -0,0 +1,63 @@ +OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") +OUTPUT_ARCH(arm) +ENTRY(_start) +SECTIONS +{ + .text 0x0 : { + _text = .; + *(.text.head) + *(.text) + *(.text.*) + *(.gnu.linkonce.t.*) + *(.srodata) + *(.rodata*) + . = ALIGN(16); + } + _etext = .; + _text_size = . - _text; + .dynamic : { *(.dynamic) } + .data : + { + _data = .; + *(.sdata) + *(.data) + *(.data1) + *(.data.*) + *(.got.plt) + *(.got) + + /* the EFI loader doesn't seem to like a .bss section, so we stick + it all into .data: */ + . = ALIGN(16); + _bss = .; + *(.sbss) + *(.scommon) + *(.dynbss) + *(.bss) + *(.bss.*) + *(COMMON) + . = ALIGN(16); + _bss_end = .; + } + + .rel.dyn : { *(.rel.dyn) } + .rel.plt : { *(.rel.plt) } + .rel.got : { *(.rel.got) } + .rel.data : { *(.rel.data) *(.rel.data*) } + _edata = .; + _data_size = . - _etext; + + . = ALIGN(4096); + .dynsym : { *(.dynsym) } + . = ALIGN(4096); + .dynstr : { *(.dynstr) } + . = ALIGN(4096); + .note.gnu.build-id : { *(.note.gnu.build-id) } + /DISCARD/ : + { + *(.rel.reloc) + *(.eh_frame) + *(.note.GNU-stack) + } + .comment 0 : { *(.comment) } +} diff --git a/gnu-efi/gnuefi/elf_ia32_efi.lds b/gnu-efi/gnuefi/elf_ia32_efi.lds new file mode 100644 index 0000000..f27fe5f --- /dev/null +++ b/gnu-efi/gnuefi/elf_ia32_efi.lds @@ -0,0 +1,86 @@ +OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") +OUTPUT_ARCH(i386) +ENTRY(_start) +SECTIONS +{ + . = 0; + ImageBase = .; + /* .hash and/or .gnu.hash MUST come first! */ + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + . = ALIGN(4096); + .text : + { + _text = .; + *(.text) + *(.text.*) + *(.gnu.linkonce.t.*) + . = ALIGN(16); + } + _etext = .; + _text_size = . - _text; + . = ALIGN(4096); + .sdata : + { + _data = .; + *(.got.plt) + *(.got) + *(.srodata) + *(.sdata) + *(.sbss) + *(.scommon) + } + . = ALIGN(4096); + .data : + { + *(.rodata*) + *(.data) + *(.data1) + *(.data.*) + *(.sdata) + *(.got.plt) + *(.got) + /* the EFI loader doesn't seem to like a .bss section, so we stick + it all into .data: */ + *(.sbss) + *(.scommon) + *(.dynbss) + *(.bss) + *(COMMON) + } + .note.gnu.build-id : { *(.note.gnu.build-id) } + + . = ALIGN(4096); + .dynamic : { *(.dynamic) } + . = ALIGN(4096); + .rel : + { + *(.rel.data) + *(.rel.data.*) + *(.rel.got) + *(.rel.stab) + *(.data.rel.ro.local) + *(.data.rel.local) + *(.data.rel.ro) + *(.data.rel*) + } + _edata = .; + _data_size = . - _etext; + . = ALIGN(4096); + .reloc : /* This is the PECOFF .reloc section! */ + { + *(.reloc) + } + . = ALIGN(4096); + .dynsym : { *(.dynsym) } + . = ALIGN(4096); + .dynstr : { *(.dynstr) } + . = ALIGN(4096); + /DISCARD/ : + { + *(.rel.reloc) + *(.eh_frame) + *(.note.GNU-stack) + } + .comment 0 : { *(.comment) } +} diff --git a/gnu-efi/gnuefi/elf_ia32_fbsd_efi.lds b/gnu-efi/gnuefi/elf_ia32_fbsd_efi.lds new file mode 100644 index 0000000..cd309e2 --- /dev/null +++ b/gnu-efi/gnuefi/elf_ia32_fbsd_efi.lds @@ -0,0 +1,86 @@ +OUTPUT_FORMAT("elf32-i386-freebsd", "elf32-i386-freebsd", "elf32-i386-freebsd") +OUTPUT_ARCH(i386) +ENTRY(_start) +SECTIONS +{ + . = 0; + ImageBase = .; + /* .hash and/or .gnu.hash MUST come first! */ + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + . = ALIGN(4096); + .text : + { + _text = .; + *(.text) + *(.text.*) + *(.gnu.linkonce.t.*) + . = ALIGN(16); + } + _etext = .; + _text_size = . - _text; + . = ALIGN(4096); + .sdata : + { + _data = .; + *(.got.plt) + *(.got) + *(.srodata) + *(.sdata) + *(.sbss) + *(.scommon) + } + . = ALIGN(4096); + .data : + { + *(.rodata*) + *(.data) + *(.data1) + *(.data.*) + *(.sdata) + *(.got.plt) + *(.got) + /* the EFI loader doesn't seem to like a .bss section, so we stick + it all into .data: */ + *(.sbss) + *(.scommon) + *(.dynbss) + *(.bss) + *(COMMON) + } + .note.gnu.build-id : { *(.note.gnu.build-id) } + + . = ALIGN(4096); + .dynamic : { *(.dynamic) } + . = ALIGN(4096); + .rel : + { + *(.rel.data) + *(.rel.data.*) + *(.rel.got) + *(.rel.stab) + *(.data.rel.ro.local) + *(.data.rel.local) + *(.data.rel.ro) + *(.data.rel*) + } + _edata = .; + _data_size = . - _etext; + . = ALIGN(4096); + .reloc : /* This is the PECOFF .reloc section! */ + { + *(.reloc) + } + . = ALIGN(4096); + .dynsym : { *(.dynsym) } + . = ALIGN(4096); + .dynstr : { *(.dynstr) } + . = ALIGN(4096); + /DISCARD/ : + { + *(.rel.reloc) + *(.eh_frame) + *(.note.GNU-stack) + } + .comment 0 : { *(.comment) } +} diff --git a/gnu-efi/gnuefi/elf_ia64_efi.lds b/gnu-efi/gnuefi/elf_ia64_efi.lds new file mode 100644 index 0000000..190792a --- /dev/null +++ b/gnu-efi/gnuefi/elf_ia64_efi.lds @@ -0,0 +1,81 @@ +OUTPUT_FORMAT("elf64-ia64-little") +OUTPUT_ARCH(ia64) +ENTRY(_start_plabel) +SECTIONS +{ + . = 0; + ImageBase = .; + /* .hash and/or .gnu.hash MUST come first! */ + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + . = ALIGN(4096); + .text : + { + _text = .; + *(.text) + *(.text.*) + *(.gnu.linkonce.t.*) + . = ALIGN(16); + } + _etext = .; + _text_size = . - _text; + . = ALIGN(4096); + __gp = ALIGN (8) + 0x200000; + .sdata : + { + _data = .; + *(.got.plt) + *(.got) + *(.srodata) + *(.sdata) + *(.sbss) + *(.scommon) + } + . = ALIGN(4096); + .data : + { + *(.rodata*) + *(.ctors) + *(.data*) + *(.gnu.linkonce.d*) + *(.plabel) /* data whose relocs we want to ignore */ + /* the EFI loader doesn't seem to like a .bss section, so we stick + it all into .data: */ + *(.dynbss) + *(.bss) + *(COMMON) + } + .note.gnu.build-id : { *(.note.gnu.build-id) } + + . = ALIGN(4096); + .dynamic : { *(.dynamic) } + . = ALIGN(4096); + .rela : + { + *(.rela.text) + *(.rela.data*) + *(.rela.sdata) + *(.rela.got) + *(.rela.gnu.linkonce.d*) + *(.rela.stab) + *(.rela.ctors) + } + _edata = .; + _data_size = . - _etext; + . = ALIGN(4096); + .reloc : /* This is the PECOFF .reloc section! */ + { + *(.reloc) + } + . = ALIGN(4096); + .dynsym : { *(.dynsym) } + . = ALIGN(4096); + .dynstr : { *(.dynstr) } + /DISCARD/ : + { + *(.rela.plabel) + *(.rela.reloc) + *(.IA_64.unwind*) + *(.IA64.unwind*) + } +} diff --git a/gnu-efi/gnuefi/elf_mips64el_efi.lds b/gnu-efi/gnuefi/elf_mips64el_efi.lds new file mode 100644 index 0000000..4d1a077 --- /dev/null +++ b/gnu-efi/gnuefi/elf_mips64el_efi.lds @@ -0,0 +1,64 @@ +OUTPUT_FORMAT("elf64-tradlittlemips", "elf64-tradbigmips", "elf64-tradlittlemips") +OUTPUT_ARCH(mips) +ENTRY(_start) +SECTIONS +{ + .text 0x0 : { + _text = .; + *(.text.head) + *(.text) + *(.text.*) + *(.gnu.linkonce.t.*) + *(.srodata) + *(.rodata*) + . = ALIGN(16); + } + _etext = .; + _text_size = . - _text; + .dynamic : { *(.dynamic) } + .data : + { + _data = .; + *(.sdata) + *(.data) + *(.data1) + *(.data.*) + *(.got.plt) + HIDDEN (_gp = ALIGN (16) + 0x7ff0); + *(.got) + + /* the EFI loader doesn't seem to like a .bss section, so we stick + it all into .data: */ + . = ALIGN(16); + _bss = .; + *(.sbss) + *(.scommon) + *(.dynbss) + *(.bss) + *(COMMON) + . = ALIGN(16); + _bss_end = .; + } + + .rel.dyn : { *(.rel.dyn) } + .rel.plt : { *(.rel.plt) } + .rel.got : { *(.rel.got) } + .rel.data : { *(.rel.data) *(.rel.data*) } + _edata = .; + _data_size = . - _etext; + + . = ALIGN(4096); + .dynsym : { *(.dynsym) } + . = ALIGN(4096); + .dynstr : { *(.dynstr) } + . = ALIGN(4096); + .note.gnu.build-id : { *(.note.gnu.build-id) } + /DISCARD/ : + { + *(.rel.reloc) + *(.eh_frame) + *(.MIPS.abiflags) + *(.note.GNU-stack) + } + .comment 0 : { *(.comment) } +} diff --git a/gnu-efi/gnuefi/elf_x86_64_efi.lds b/gnu-efi/gnuefi/elf_x86_64_efi.lds new file mode 100644 index 0000000..7be5902 --- /dev/null +++ b/gnu-efi/gnuefi/elf_x86_64_efi.lds @@ -0,0 +1,76 @@ +/* Same as elf_x86_64_fbsd_efi.lds, except for OUTPUT_FORMAT below - KEEP IN SYNC */ +OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64") +OUTPUT_ARCH(i386:x86-64) +ENTRY(_start) +SECTIONS +{ + . = 0; + ImageBase = .; + /* .hash and/or .gnu.hash MUST come first! */ + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + . = ALIGN(4096); + .eh_frame : + { + *(.eh_frame) + } + . = ALIGN(4096); + .text : + { + _text = .; + *(.text) + *(.text.*) + *(.gnu.linkonce.t.*) + . = ALIGN(16); + } + _etext = .; + _text_size = . - _text; + . = ALIGN(4096); + .reloc : + { + *(.reloc) + } + . = ALIGN(4096); + .data : + { + _data = .; + *(.rodata*) + *(.got.plt) + *(.got) + *(.data*) + *(.sdata) + /* the EFI loader doesn't seem to like a .bss section, so we stick + it all into .data: */ + *(.sbss) + *(.scommon) + *(.dynbss) + *(.bss) + *(COMMON) + *(.rel.local) + } + .note.gnu.build-id : { *(.note.gnu.build-id) } + + _edata = .; + _data_size = . - _etext; + . = ALIGN(4096); + .dynamic : { *(.dynamic) } + . = ALIGN(4096); + .rela : + { + *(.rela.data*) + *(.rela.got) + *(.rela.stab) + } + . = ALIGN(4096); + .dynsym : { *(.dynsym) } + . = ALIGN(4096); + .dynstr : { *(.dynstr) } + . = ALIGN(4096); + .ignored.reloc : + { + *(.rela.reloc) + *(.eh_frame) + *(.note.GNU-stack) + } + .comment 0 : { *(.comment) } +} diff --git a/gnu-efi/gnuefi/elf_x86_64_fbsd_efi.lds b/gnu-efi/gnuefi/elf_x86_64_fbsd_efi.lds new file mode 100644 index 0000000..fe1f334 --- /dev/null +++ b/gnu-efi/gnuefi/elf_x86_64_fbsd_efi.lds @@ -0,0 +1,70 @@ +/* Same as elf_x86_64_efi.lds, except for OUTPUT_FORMAT below - KEEP IN SYNC */ +OUTPUT_FORMAT("elf64-x86-64-freebsd", "elf64-x86-64-freebsd", "elf64-x86-64-freebsd") +OUTPUT_ARCH(i386:x86-64) +ENTRY(_start) +SECTIONS +{ + . = 0; + ImageBase = .; + /* .hash and/or .gnu.hash MUST come first! */ + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + . = ALIGN(4096); + .eh_frame : + { + *(.eh_frame) + } + . = ALIGN(4096); + .text : + { + _text = .; + *(.text) + . = ALIGN(16); + } + _etext = .; + _text_size = . - _text; + .reloc : + { + *(.reloc) + } + . = ALIGN(4096); + .data : + { + _data = .; + *(.rodata*) + *(.got.plt) + *(.got) + *(.data*) + *(.sdata) + /* the EFI loader doesn't seem to like a .bss section, so we stick + it all into .data: */ + *(.sbss) + *(.scommon) + *(.dynbss) + *(.bss) + *(COMMON) + *(.rel.local) + } + .note.gnu.build-id : { *(.note.gnu.build-id) } + + . = ALIGN(4096); + .dynamic : { *(.dynamic) } + . = ALIGN(4096); + .rela : + { + *(.rela.data*) + *(.rela.got) + *(.rela.stab) + } + _edata = .; + _data_size = . - _etext; + . = ALIGN(4096); + .dynsym : { *(.dynsym) } + . = ALIGN(4096); + .dynstr : { *(.dynstr) } + . = ALIGN(4096); + .ignored.reloc : + { + *(.rela.reloc) + } +} diff --git a/gnu-efi/gnuefi/reloc_aarch64.c b/gnu-efi/gnuefi/reloc_aarch64.c new file mode 100644 index 0000000..0867279 --- /dev/null +++ b/gnu-efi/gnuefi/reloc_aarch64.c @@ -0,0 +1,97 @@ +/* reloc_aarch64.c - position independent x86 ELF shared object relocator + Copyright (C) 2014 Linaro Ltd. + Copyright (C) 1999 Hewlett-Packard Co. + Contributed by David Mosberger . + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials + provided with the distribution. + * Neither the name of Hewlett-Packard Co. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. +*/ + +#include +#include + +#include + +EFI_STATUS _relocate (long ldbase, Elf64_Dyn *dyn, + EFI_HANDLE image EFI_UNUSED, + EFI_SYSTEM_TABLE *systab EFI_UNUSED) +{ + long relsz = 0, relent = 0; + Elf64_Rela *rel = 0; + unsigned long *addr; + int i; + + for (i = 0; dyn[i].d_tag != DT_NULL; ++i) { + switch (dyn[i].d_tag) { + case DT_RELA: + rel = (Elf64_Rela*) + ((unsigned long)dyn[i].d_un.d_ptr + + ldbase); + break; + + case DT_RELASZ: + relsz = dyn[i].d_un.d_val; + break; + + case DT_RELAENT: + relent = dyn[i].d_un.d_val; + break; + + default: + break; + } + } + + if (!rel && relent == 0) + return EFI_SUCCESS; + + if (!rel || relent == 0) + return EFI_LOAD_ERROR; + + while (relsz > 0) { + /* apply the relocs */ + switch (ELF64_R_TYPE (rel->r_info)) { + case R_AARCH64_NONE: + break; + + case R_AARCH64_RELATIVE: + addr = (unsigned long *) + (ldbase + rel->r_offset); + *addr = ldbase + rel->r_addend; + break; + + default: + break; + } + rel = (Elf64_Rela*) ((char *) rel + relent); + relsz -= relent; + } + return EFI_SUCCESS; +} diff --git a/gnu-efi/gnuefi/reloc_arm.c b/gnu-efi/gnuefi/reloc_arm.c new file mode 100644 index 0000000..7585066 --- /dev/null +++ b/gnu-efi/gnuefi/reloc_arm.c @@ -0,0 +1,97 @@ +/* reloc_arm.c - position independent x86 ELF shared object relocator + Copyright (C) 2014 Linaro Ltd. + Copyright (C) 1999 Hewlett-Packard Co. + Contributed by David Mosberger . + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials + provided with the distribution. + * Neither the name of Hewlett-Packard Co. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. +*/ + +#include +#include + +#include + +EFI_STATUS _relocate (long ldbase, Elf32_Dyn *dyn, + EFI_HANDLE image EFI_UNUSED, + EFI_SYSTEM_TABLE *systab EFI_UNUSED) +{ + long relsz = 0, relent = 0; + Elf32_Rel *rel = 0; + unsigned long *addr; + int i; + + for (i = 0; dyn[i].d_tag != DT_NULL; ++i) { + switch (dyn[i].d_tag) { + case DT_REL: + rel = (Elf32_Rel*) + ((unsigned long)dyn[i].d_un.d_ptr + + ldbase); + break; + + case DT_RELSZ: + relsz = dyn[i].d_un.d_val; + break; + + case DT_RELENT: + relent = dyn[i].d_un.d_val; + break; + + default: + break; + } + } + + if (!rel && relent == 0) + return EFI_SUCCESS; + + if (!rel || relent == 0) + return EFI_LOAD_ERROR; + + while (relsz > 0) { + /* apply the relocs */ + switch (ELF32_R_TYPE (rel->r_info)) { + case R_ARM_NONE: + break; + + case R_ARM_RELATIVE: + addr = (unsigned long *) + (ldbase + rel->r_offset); + *addr += ldbase; + break; + + default: + break; + } + rel = (Elf32_Rel*) ((char *) rel + relent); + relsz -= relent; + } + return EFI_SUCCESS; +} diff --git a/gnu-efi/gnuefi/reloc_ia32.c b/gnu-efi/gnuefi/reloc_ia32.c new file mode 100644 index 0000000..da9d8a7 --- /dev/null +++ b/gnu-efi/gnuefi/reloc_ia32.c @@ -0,0 +1,99 @@ +/* reloc_ia32.c - position independent x86 ELF shared object relocator + Copyright (C) 1999 Hewlett-Packard Co. + Contributed by David Mosberger . + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials + provided with the distribution. + * Neither the name of Hewlett-Packard Co. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. +*/ + +#include +#include + +#include + +EFI_STATUS _relocate (long ldbase, Elf32_Dyn *dyn, + EFI_HANDLE image EFI_UNUSED, + EFI_SYSTEM_TABLE *systab EFI_UNUSED) +{ + long relsz = 0, relent = 0; + Elf32_Rel *rel = 0; + unsigned long *addr; + int i; + + for (i = 0; dyn[i].d_tag != DT_NULL; ++i) { + switch (dyn[i].d_tag) { + case DT_REL: + rel = (Elf32_Rel*) + ((unsigned long)dyn[i].d_un.d_ptr + + ldbase); + break; + + case DT_RELSZ: + relsz = dyn[i].d_un.d_val; + break; + + case DT_RELENT: + relent = dyn[i].d_un.d_val; + break; + + case DT_RELA: + break; + + default: + break; + } + } + + if (!rel && relent == 0) + return EFI_SUCCESS; + + if (!rel || relent == 0) + return EFI_LOAD_ERROR; + + while (relsz > 0) { + /* apply the relocs */ + switch (ELF32_R_TYPE (rel->r_info)) { + case R_386_NONE: + break; + + case R_386_RELATIVE: + addr = (unsigned long *) + (ldbase + rel->r_offset); + *addr += ldbase; + break; + + default: + break; + } + rel = (Elf32_Rel*) ((char *) rel + relent); + relsz -= relent; + } + return EFI_SUCCESS; +} diff --git a/gnu-efi/gnuefi/reloc_ia64.S b/gnu-efi/gnuefi/reloc_ia64.S new file mode 100644 index 0000000..40203bf --- /dev/null +++ b/gnu-efi/gnuefi/reloc_ia64.S @@ -0,0 +1,227 @@ +/* reloc_ia64.S - position independent IA-64 ELF shared object relocator + Copyright (C) 1999 Hewlett-Packard Co. + Contributed by David Mosberger . + + 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. +*/ + +/* + * This is written in assembly because the entire code needs to be position + * independent. Note that the compiler does not generate code that's position + * independent by itself because it relies on the global offset table being + * relocated. + */ + .text + .psr abi64 + .psr lsb + .lsb + +/* + * This constant determines how many R_IA64_FPTR64LSB relocations we + * can deal with. If you get EFI_BUFFER_TOO_SMALL errors, you may + * need to increase this number. + */ +#define MAX_FUNCTION_DESCRIPTORS 750 + +#define ST_VALUE_OFF 8 /* offset of st_value in elf sym */ + +#define EFI_SUCCESS 0 +#define EFI_LOAD_ERROR 1 +#define EFI_BUFFER_TOO_SMALL 5 + +#define DT_NULL 0 /* Marks end of dynamic section */ +#define DT_RELA 7 /* Address of Rela relocs */ +#define DT_RELASZ 8 /* Total size of Rela relocs */ +#define DT_RELAENT 9 /* Size of one Rela reloc */ +#define DT_SYMTAB 6 /* Address of symbol table */ +#define DT_SYMENT 11 /* Size of one symbol table entry */ + +#define R_IA64_NONE 0 +#define R_IA64_REL64MSB 0x6e +#define R_IA64_REL64LSB 0x6f +#define R_IA64_DIR64MSB 0x26 +#define R_IA64_DIR64LSB 0x27 +#define R_IA64_FPTR64MSB 0x46 +#define R_IA64_FPTR64LSB 0x47 + +#define ldbase in0 /* load address (address of .text) */ +#define dyn in1 /* address of _DYNAMIC */ + +#define d_tag r16 +#define d_val r17 +#define rela r18 +#define relasz r19 +#define relaent r20 +#define addr r21 +#define r_info r22 +#define r_offset r23 +#define r_addend r24 +#define r_type r25 +#define r_sym r25 /* alias of r_type ! */ +#define fptr r26 +#define fptr_limit r27 +#define symtab f8 +#define syment f9 +#define ftmp f10 + +#define target r16 +#define val r17 + +#define NLOC 0 + +#define Pnull p6 +#define Prela p7 +#define Prelasz p8 +#define Prelaent p9 +#define Psymtab p10 +#define Psyment p11 + +#define Pnone p6 +#define Prel p7 +#define Pfptr p8 + +#define Pmore p6 + +#define Poom p6 /* out-of-memory */ + + .global _relocate + .proc _relocate +_relocate: + alloc r2=ar.pfs,2,0,0,0 + movl fptr = @gprel(fptr_mem_base) + ;; + add fptr = fptr, gp + movl fptr_limit = @gprel(fptr_mem_limit) + ;; + add fptr_limit = fptr_limit, gp + +search_dynamic: + ld8 d_tag = [dyn],8 + ;; + ld8 d_val = [dyn],8 + cmp.eq Pnull,p0 = DT_NULL,d_tag +(Pnull) br.cond.sptk.few apply_relocs + cmp.eq Prela,p0 = DT_RELA,d_tag + cmp.eq Prelasz,p0 = DT_RELASZ,d_tag + cmp.eq Psymtab,p0 = DT_SYMTAB,d_tag + cmp.eq Psyment,p0 = DT_SYMENT,d_tag + cmp.eq Prelaent,p0 = DT_RELAENT,d_tag + ;; +(Prela) add rela = d_val, ldbase +(Prelasz) mov relasz = d_val +(Prelaent) mov relaent = d_val +(Psymtab) add val = d_val, ldbase + ;; +(Psyment) setf.sig syment = d_val + ;; +(Psymtab) setf.sig symtab = val + br.sptk.few search_dynamic + +apply_loop: + ld8 r_offset = [rela] + add addr = 8,rela + sub relasz = relasz,relaent + ;; + + ld8 r_info = [addr],8 + ;; + ld8 r_addend = [addr] + add target = ldbase, r_offset + + add rela = rela,relaent + extr.u r_type = r_info, 0, 32 + ;; + cmp.eq Pnone,p0 = R_IA64_NONE,r_type + cmp.eq Prel,p0 = R_IA64_REL64LSB,r_type + cmp.eq Pfptr,p0 = R_IA64_FPTR64LSB,r_type +(Prel) br.cond.sptk.few apply_REL64 + ;; + cmp.eq Prel,p0 = R_IA64_DIR64LSB,r_type // treat DIR64 just like REL64 + +(Pnone) br.cond.sptk.few apply_relocs +(Prel) br.cond.sptk.few apply_REL64 +(Pfptr) br.cond.sptk.few apply_FPTR64 + + mov r8 = EFI_LOAD_ERROR + br.ret.sptk.few rp + +apply_relocs: + cmp.ltu Pmore,p0=0,relasz +(Pmore) br.cond.sptk.few apply_loop + + mov r8 = EFI_SUCCESS + br.ret.sptk.few rp + +apply_REL64: + ld8 val = [target] + ;; + add val = val,ldbase + ;; + st8 [target] = val + br.cond.sptk.few apply_relocs + + // FPTR relocs are a bit more interesting: we need to lookup + // the symbol's value in symtab, allocate 16 bytes of memory, + // store the value in [target] in the first and the gp in the + // second dword. +apply_FPTR64: + st8 [target] = fptr + extr.u r_sym = r_info,32,32 + add target = 8,fptr + ;; + + setf.sig ftmp = r_sym + mov r8=EFI_BUFFER_TOO_SMALL + ;; + cmp.geu Poom,p0 = fptr,fptr_limit + + xma.lu ftmp = ftmp,syment,symtab +(Poom) br.ret.sptk.few rp + ;; + getf.sig addr = ftmp + st8 [target] = gp + ;; + add addr = ST_VALUE_OFF, addr + ;; + ld8 val = [addr] + ;; + add val = val,ldbase + ;; + st8 [fptr] = val,16 + br.cond.sptk.few apply_relocs + + .endp _relocate + + .data + .align 16 +fptr_mem_base: + .space MAX_FUNCTION_DESCRIPTORS*16 +fptr_mem_limit: diff --git a/gnu-efi/gnuefi/reloc_mips64el.c b/gnu-efi/gnuefi/reloc_mips64el.c new file mode 100644 index 0000000..4db21ad --- /dev/null +++ b/gnu-efi/gnuefi/reloc_mips64el.c @@ -0,0 +1,115 @@ +/* reloc_mips64el.c - position independent MIPS64 ELF shared object relocator + Copyright (C) 2014 Linaro Ltd. + Copyright (C) 1999 Hewlett-Packard Co. + Contributed by David Mosberger . + Copyright (C) 2017 Lemote Co. + Contributed by Heiher + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials + provided with the distribution. + * Neither the name of Hewlett-Packard Co. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. +*/ + +#include +#include + +#include + +EFI_STATUS _relocate (long ldbase, Elf64_Dyn *dyn, + EFI_HANDLE image EFI_UNUSED, + EFI_SYSTEM_TABLE *systab EFI_UNUSED) +{ + long relsz = 0, relent = 0, gotsz = 0; + Elf64_Rel *rel = 0; + unsigned long *addr = 0; + int i; + + for (i = 0; dyn[i].d_tag != DT_NULL; ++i) { + switch (dyn[i].d_tag) { + case DT_REL: + rel = (Elf64_Rel*) + ((unsigned long)dyn[i].d_un.d_ptr + + ldbase); + break; + + case DT_RELSZ: + relsz = dyn[i].d_un.d_val; + break; + + case DT_RELENT: + relent = dyn[i].d_un.d_val; + break; + + case DT_PLTGOT: + addr = (unsigned long *) + ((unsigned long)dyn[i].d_un.d_ptr + + ldbase); + break; + + case DT_MIPS_LOCAL_GOTNO: + gotsz = dyn[i].d_un.d_val; + break; + + default: + break; + } + } + + if ((!rel && relent == 0) && (!addr && gotsz == 0)) + return EFI_SUCCESS; + + if ((!rel && relent != 0) || (!addr && gotsz != 0)) + return EFI_LOAD_ERROR; + + while (gotsz > 0) { + *addr += ldbase; + addr += 1; + gotsz --; + } + + while (relsz > 0) { + /* apply the relocs */ + switch (ELF64_R_TYPE (swap_uint64 (rel->r_info))) { + case R_MIPS_NONE: + break; + + case (R_MIPS_64 << 8) | R_MIPS_REL32: + addr = (unsigned long *) + (ldbase + rel->r_offset); + *addr += ldbase; + break; + + default: + break; + } + rel = (Elf64_Rel*) ((char *) rel + relent); + relsz -= relent; + } + return EFI_SUCCESS; +} diff --git a/gnu-efi/gnuefi/reloc_x86_64.c b/gnu-efi/gnuefi/reloc_x86_64.c new file mode 100644 index 0000000..04b75b2 --- /dev/null +++ b/gnu-efi/gnuefi/reloc_x86_64.c @@ -0,0 +1,98 @@ +/* reloc_x86_64.c - position independent x86_64 ELF shared object relocator + Copyright (C) 1999 Hewlett-Packard Co. + Contributed by David Mosberger . + Copyright (C) 2005 Intel Co. + Contributed by Fenghua Yu . + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials + provided with the distribution. + * Neither the name of Hewlett-Packard Co. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. +*/ + +#include +#include + +#include + +EFI_STATUS _relocate (long ldbase, Elf64_Dyn *dyn, + EFI_HANDLE image EFI_UNUSED, + EFI_SYSTEM_TABLE *systab EFI_UNUSED) +{ + long relsz = 0, relent = 0; + Elf64_Rel *rel = 0; + unsigned long *addr; + int i; + + for (i = 0; dyn[i].d_tag != DT_NULL; ++i) { + switch (dyn[i].d_tag) { + case DT_RELA: + rel = (Elf64_Rel*) + ((unsigned long)dyn[i].d_un.d_ptr + + ldbase); + break; + + case DT_RELASZ: + relsz = dyn[i].d_un.d_val; + break; + + case DT_RELAENT: + relent = dyn[i].d_un.d_val; + break; + + default: + break; + } + } + + if (!rel && relent == 0) + return EFI_SUCCESS; + + if (!rel || relent == 0) + return EFI_LOAD_ERROR; + + while (relsz > 0) { + /* apply the relocs */ + switch (ELF64_R_TYPE (rel->r_info)) { + case R_X86_64_NONE: + break; + + case R_X86_64_RELATIVE: + addr = (unsigned long *) + (ldbase + rel->r_offset); + *addr += ldbase; + break; + + default: + break; + } + rel = (Elf64_Rel*) ((char *) rel + relent); + relsz -= relent; + } + return EFI_SUCCESS; +} diff --git a/gnu-efi/inc/Makefile b/gnu-efi/inc/Makefile new file mode 100644 index 0000000..273d303 --- /dev/null +++ b/gnu-efi/inc/Makefile @@ -0,0 +1,27 @@ +SRCDIR = . + +VPATH = $(SRCDIR) + +include $(SRCDIR)/../Make.defaults + +TOPDIR = $(SRCDIR)/.. + +CDIR=$(TOPDIR)/.. + +all: + +clean: + +install: + mkdir -p $(INSTALLROOT)$(PREFIX)/include/efi + mkdir -p $(INSTALLROOT)$(PREFIX)/include/efi/protocol + mkdir -p $(INSTALLROOT)$(PREFIX)/include/efi/$(ARCH) + $(INSTALL) -m 644 $(SRCDIR)/*.h $(INSTALLROOT)$(PREFIX)/include/efi + $(INSTALL) -m 644 $(SRCDIR)/protocol/*.h $(INSTALLROOT)$(PREFIX)/include/efi/protocol + $(INSTALL) -m 644 $(SRCDIR)/$(ARCH)/*.h $(INSTALLROOT)$(PREFIX)/include/efi/$(ARCH) +ifeq ($(ARCH),ia64) + mkdir -p $(INSTALLROOT)$(PREFIX)/include/efi/protocol/ia64 + $(INSTALL) -m 644 $(SRCDIR)/protocol/ia64/*.h $(INSTALLROOT)$(PREFIX)/include/efi/protocol/ia64 +endif + +include $(SRCDIR)/../Make.rules diff --git a/include/efi/aarch64/efibind.h b/gnu-efi/inc/aarch64/efibind.h similarity index 100% rename from include/efi/aarch64/efibind.h rename to gnu-efi/inc/aarch64/efibind.h diff --git a/include/efi/aarch64/efilibplat.h b/gnu-efi/inc/aarch64/efilibplat.h similarity index 100% rename from include/efi/aarch64/efilibplat.h rename to gnu-efi/inc/aarch64/efilibplat.h diff --git a/include/efi/aarch64/efisetjmp_arch.h b/gnu-efi/inc/aarch64/efisetjmp_arch.h similarity index 100% rename from include/efi/aarch64/efisetjmp_arch.h rename to gnu-efi/inc/aarch64/efisetjmp_arch.h diff --git a/include/efi/efi.h b/gnu-efi/inc/efi.h similarity index 100% rename from include/efi/efi.h rename to gnu-efi/inc/efi.h diff --git a/include/efi/efi_nii.h b/gnu-efi/inc/efi_nii.h similarity index 100% rename from include/efi/efi_nii.h rename to gnu-efi/inc/efi_nii.h diff --git a/include/efi/efi_pxe.h b/gnu-efi/inc/efi_pxe.h similarity index 100% rename from include/efi/efi_pxe.h rename to gnu-efi/inc/efi_pxe.h diff --git a/include/efi/efiapi.h b/gnu-efi/inc/efiapi.h similarity index 100% rename from include/efi/efiapi.h rename to gnu-efi/inc/efiapi.h diff --git a/include/efi/eficompiler.h b/gnu-efi/inc/eficompiler.h similarity index 100% rename from include/efi/eficompiler.h rename to gnu-efi/inc/eficompiler.h diff --git a/include/efi/eficon.h b/gnu-efi/inc/eficon.h similarity index 100% rename from include/efi/eficon.h rename to gnu-efi/inc/eficon.h diff --git a/include/efi/efidebug.h b/gnu-efi/inc/efidebug.h similarity index 100% rename from include/efi/efidebug.h rename to gnu-efi/inc/efidebug.h diff --git a/include/efi/efidef.h b/gnu-efi/inc/efidef.h similarity index 100% rename from include/efi/efidef.h rename to gnu-efi/inc/efidef.h diff --git a/include/efi/efidevp.h b/gnu-efi/inc/efidevp.h similarity index 100% rename from include/efi/efidevp.h rename to gnu-efi/inc/efidevp.h diff --git a/include/efi/efierr.h b/gnu-efi/inc/efierr.h similarity index 100% rename from include/efi/efierr.h rename to gnu-efi/inc/efierr.h diff --git a/include/efi/efifs.h b/gnu-efi/inc/efifs.h similarity index 100% rename from include/efi/efifs.h rename to gnu-efi/inc/efifs.h diff --git a/include/efi/efigpt.h b/gnu-efi/inc/efigpt.h similarity index 100% rename from include/efi/efigpt.h rename to gnu-efi/inc/efigpt.h diff --git a/include/efi/efiip.h b/gnu-efi/inc/efiip.h similarity index 100% rename from include/efi/efiip.h rename to gnu-efi/inc/efiip.h diff --git a/include/efi/efilib.h b/gnu-efi/inc/efilib.h similarity index 100% rename from include/efi/efilib.h rename to gnu-efi/inc/efilib.h diff --git a/include/efi/efilink.h b/gnu-efi/inc/efilink.h similarity index 100% rename from include/efi/efilink.h rename to gnu-efi/inc/efilink.h diff --git a/include/efi/efinet.h b/gnu-efi/inc/efinet.h similarity index 100% rename from include/efi/efinet.h rename to gnu-efi/inc/efinet.h diff --git a/include/efi/efipart.h b/gnu-efi/inc/efipart.h similarity index 100% rename from include/efi/efipart.h rename to gnu-efi/inc/efipart.h diff --git a/include/efi/efipciio.h b/gnu-efi/inc/efipciio.h similarity index 100% rename from include/efi/efipciio.h rename to gnu-efi/inc/efipciio.h diff --git a/include/efi/efipoint.h b/gnu-efi/inc/efipoint.h similarity index 100% rename from include/efi/efipoint.h rename to gnu-efi/inc/efipoint.h diff --git a/include/efi/efiprot.h b/gnu-efi/inc/efiprot.h similarity index 100% rename from include/efi/efiprot.h rename to gnu-efi/inc/efiprot.h diff --git a/include/efi/efipxebc.h b/gnu-efi/inc/efipxebc.h similarity index 100% rename from include/efi/efipxebc.h rename to gnu-efi/inc/efipxebc.h diff --git a/include/efi/efirtlib.h b/gnu-efi/inc/efirtlib.h similarity index 100% rename from include/efi/efirtlib.h rename to gnu-efi/inc/efirtlib.h diff --git a/include/efi/efiser.h b/gnu-efi/inc/efiser.h similarity index 100% rename from include/efi/efiser.h rename to gnu-efi/inc/efiser.h diff --git a/include/efi/efisetjmp.h b/gnu-efi/inc/efisetjmp.h similarity index 100% rename from include/efi/efisetjmp.h rename to gnu-efi/inc/efisetjmp.h diff --git a/include/efi/efishellintf.h b/gnu-efi/inc/efishellintf.h similarity index 100% rename from include/efi/efishellintf.h rename to gnu-efi/inc/efishellintf.h diff --git a/include/efi/efishellparm.h b/gnu-efi/inc/efishellparm.h similarity index 100% rename from include/efi/efishellparm.h rename to gnu-efi/inc/efishellparm.h diff --git a/include/efi/efistdarg.h b/gnu-efi/inc/efistdarg.h similarity index 100% rename from include/efi/efistdarg.h rename to gnu-efi/inc/efistdarg.h diff --git a/include/efi/efitcp.h b/gnu-efi/inc/efitcp.h similarity index 100% rename from include/efi/efitcp.h rename to gnu-efi/inc/efitcp.h diff --git a/include/efi/efiudp.h b/gnu-efi/inc/efiudp.h similarity index 100% rename from include/efi/efiudp.h rename to gnu-efi/inc/efiudp.h diff --git a/include/efi/efiui.h b/gnu-efi/inc/efiui.h similarity index 100% rename from include/efi/efiui.h rename to gnu-efi/inc/efiui.h diff --git a/include/efi/ia32/efibind.h b/gnu-efi/inc/ia32/efibind.h similarity index 100% rename from include/efi/ia32/efibind.h rename to gnu-efi/inc/ia32/efibind.h diff --git a/include/efi/ia32/efilibplat.h b/gnu-efi/inc/ia32/efilibplat.h similarity index 100% rename from include/efi/ia32/efilibplat.h rename to gnu-efi/inc/ia32/efilibplat.h diff --git a/include/efi/ia32/efisetjmp_arch.h b/gnu-efi/inc/ia32/efisetjmp_arch.h similarity index 100% rename from include/efi/ia32/efisetjmp_arch.h rename to gnu-efi/inc/ia32/efisetjmp_arch.h diff --git a/include/efi/ia32/pe.h b/gnu-efi/inc/ia32/pe.h similarity index 100% rename from include/efi/ia32/pe.h rename to gnu-efi/inc/ia32/pe.h diff --git a/include/efi/ia64/efibind.h b/gnu-efi/inc/ia64/efibind.h similarity index 100% rename from include/efi/ia64/efibind.h rename to gnu-efi/inc/ia64/efibind.h diff --git a/include/efi/ia64/efilibplat.h b/gnu-efi/inc/ia64/efilibplat.h similarity index 100% rename from include/efi/ia64/efilibplat.h rename to gnu-efi/inc/ia64/efilibplat.h diff --git a/include/efi/ia64/efisetjmp_arch.h b/gnu-efi/inc/ia64/efisetjmp_arch.h similarity index 100% rename from include/efi/ia64/efisetjmp_arch.h rename to gnu-efi/inc/ia64/efisetjmp_arch.h diff --git a/include/efi/ia64/pe.h b/gnu-efi/inc/ia64/pe.h similarity index 100% rename from include/efi/ia64/pe.h rename to gnu-efi/inc/ia64/pe.h diff --git a/include/efi/ia64/salproc.h b/gnu-efi/inc/ia64/salproc.h similarity index 100% rename from include/efi/ia64/salproc.h rename to gnu-efi/inc/ia64/salproc.h diff --git a/gnu-efi/inc/inc.mak b/gnu-efi/inc/inc.mak new file mode 100644 index 0000000..3848d02 --- /dev/null +++ b/gnu-efi/inc/inc.mak @@ -0,0 +1,23 @@ + + +INC_DEPS = $(INC_DEPS) \ + efi.h \ + efiapi.h \ + efibind.h \ + eficon.h \ + efidebug.h \ + efidef.h \ + efidevp.h \ + efierr.h \ + efifs.h \ + efilib.h \ + efipart.h \ + efipciio.h \ + efiprot.h \ + efipxe.h \ + efivar.h \ + pe.h \ + efiip.h \ + efiudp.h \ + efitcp.h \ + stdarg.h diff --git a/include/efi/libsmbios.h b/gnu-efi/inc/libsmbios.h similarity index 100% rename from include/efi/libsmbios.h rename to gnu-efi/inc/libsmbios.h diff --git a/gnu-efi/inc/make.inf b/gnu-efi/inc/make.inf new file mode 100644 index 0000000..4d54565 --- /dev/null +++ b/gnu-efi/inc/make.inf @@ -0,0 +1,33 @@ +# +# +# + +[sources] + efi.h + efiapi.h + eficon.h + efidebug.h + efidef.h + efidevp.h + efierr.h + efifs.h + efilib.h + efipart.h + efipciio.h + efiprot.h + efipxebc.h + efistdarg.h + efinet.h + efiip.h + efiudp.h + efitcp.h + +[ia32sources] + efibind.h + pe.h + efilibplat.h + +[ia64sources] + efibind.h + pe.h + efilibplat.h diff --git a/gnu-efi/inc/makefile.hdr b/gnu-efi/inc/makefile.hdr new file mode 100644 index 0000000..61a1698 --- /dev/null +++ b/gnu-efi/inc/makefile.hdr @@ -0,0 +1,48 @@ + +# +# This is a machine generated file - DO NOT EDIT +# Generated by genmake.exe +# Generated from make.inf +# Copyright (c) 1998 Intel Corporation +# + +INC_DEPS = $(INC_DEPS) \ + $(SDK_INSTALL_DIR)\include\efi\efi.h \ + $(SDK_INSTALL_DIR)\include\efi\efiapi.h \ + $(SDK_INSTALL_DIR)\include\efi\eficon.h \ + $(SDK_INSTALL_DIR)\include\efi\efidebug.h \ + $(SDK_INSTALL_DIR)\include\efi\efidef.h \ + $(SDK_INSTALL_DIR)\include\efi\efidevp.h \ + $(SDK_INSTALL_DIR)\include\efi\efierr.h \ + $(SDK_INSTALL_DIR)\include\efi\efifs.h \ + $(SDK_INSTALL_DIR)\include\efi\efilib.h \ + $(SDK_INSTALL_DIR)\include\efi\efipart.h \ + $(SDK_INSTALL_DIR)\include\efi\efipciio.h \ + $(SDK_INSTALL_DIR)\include\efi\efiprot.h \ + $(SDK_INSTALL_DIR)\include\efi\efipxebc.h \ + $(SDK_INSTALL_DIR)\include\efi\efistdarg.h \ + $(SDK_INSTALL_DIR)\include\efi\efinet.h \ + $(SDK_INSTALL_DIR)\include\efi\efiip.h \ + $(SDK_INSTALL_DIR)\include\efi\efiudp.h \ + $(SDK_INSTALL_DIR)\include\efi\efitcp.h \ + + +!IF "$(PROCESSOR)" == "Ia32" +INC_DEPS = $(INC_DEPS) \ + $(SDK_INSTALL_DIR)\include\efi\Ia32\efibind.h \ + $(SDK_INSTALL_DIR)\include\efi\Ia32\pe.h \ + $(SDK_INSTALL_DIR)\include\efi\Ia32\efilibplat.h \ + + +!ENDIF + + +!IF "$(PROCESSOR)" == "Ia64" +INC_DEPS = $(INC_DEPS) \ + $(SDK_INSTALL_DIR)\include\efi\Ia64\efibind.h \ + $(SDK_INSTALL_DIR)\include\efi\Ia64\pe.h \ + $(SDK_INSTALL_DIR)\include\efi\Ia64\efilibplat.h \ + + +!ENDIF + diff --git a/include/efi/mips64el/efibind.h b/gnu-efi/inc/mips64el/efibind.h similarity index 100% rename from include/efi/mips64el/efibind.h rename to gnu-efi/inc/mips64el/efibind.h diff --git a/include/efi/arm/efilibplat.h b/gnu-efi/inc/mips64el/efilibplat.h similarity index 100% rename from include/efi/arm/efilibplat.h rename to gnu-efi/inc/mips64el/efilibplat.h diff --git a/include/efi/mips64el/efisetjmp_arch.h b/gnu-efi/inc/mips64el/efisetjmp_arch.h similarity index 100% rename from include/efi/mips64el/efisetjmp_arch.h rename to gnu-efi/inc/mips64el/efisetjmp_arch.h diff --git a/include/efi/pci22.h b/gnu-efi/inc/pci22.h similarity index 100% rename from include/efi/pci22.h rename to gnu-efi/inc/pci22.h diff --git a/include/efi/protocol/adapterdebug.h b/gnu-efi/inc/protocol/adapterdebug.h similarity index 100% rename from include/efi/protocol/adapterdebug.h rename to gnu-efi/inc/protocol/adapterdebug.h diff --git a/include/efi/protocol/eficonsplit.h b/gnu-efi/inc/protocol/eficonsplit.h similarity index 100% rename from include/efi/protocol/eficonsplit.h rename to gnu-efi/inc/protocol/eficonsplit.h diff --git a/include/efi/protocol/efidbg.h b/gnu-efi/inc/protocol/efidbg.h similarity index 100% rename from include/efi/protocol/efidbg.h rename to gnu-efi/inc/protocol/efidbg.h diff --git a/include/efi/protocol/efivar.h b/gnu-efi/inc/protocol/efivar.h similarity index 100% rename from include/efi/protocol/efivar.h rename to gnu-efi/inc/protocol/efivar.h diff --git a/include/efi/protocol/ia64/eficontext.h b/gnu-efi/inc/protocol/ia64/eficontext.h similarity index 100% rename from include/efi/protocol/ia64/eficontext.h rename to gnu-efi/inc/protocol/ia64/eficontext.h diff --git a/include/efi/protocol/intload.h b/gnu-efi/inc/protocol/intload.h similarity index 100% rename from include/efi/protocol/intload.h rename to gnu-efi/inc/protocol/intload.h diff --git a/include/efi/protocol/legacyboot.h b/gnu-efi/inc/protocol/legacyboot.h similarity index 100% rename from include/efi/protocol/legacyboot.h rename to gnu-efi/inc/protocol/legacyboot.h diff --git a/include/efi/protocol/make.inf b/gnu-efi/inc/protocol/make.inf similarity index 100% rename from include/efi/protocol/make.inf rename to gnu-efi/inc/protocol/make.inf diff --git a/include/efi/protocol/makefile.hdr b/gnu-efi/inc/protocol/makefile.hdr similarity index 100% rename from include/efi/protocol/makefile.hdr rename to gnu-efi/inc/protocol/makefile.hdr diff --git a/include/efi/protocol/piflash64.h b/gnu-efi/inc/protocol/piflash64.h similarity index 100% rename from include/efi/protocol/piflash64.h rename to gnu-efi/inc/protocol/piflash64.h diff --git a/include/efi/protocol/readme.txt b/gnu-efi/inc/protocol/readme.txt similarity index 100% rename from include/efi/protocol/readme.txt rename to gnu-efi/inc/protocol/readme.txt diff --git a/include/efi/protocol/vgaclass.h b/gnu-efi/inc/protocol/vgaclass.h similarity index 100% rename from include/efi/protocol/vgaclass.h rename to gnu-efi/inc/protocol/vgaclass.h diff --git a/include/efi/romload.h b/gnu-efi/inc/romload.h similarity index 100% rename from include/efi/romload.h rename to gnu-efi/inc/romload.h diff --git a/gnu-efi/lib/Makefile b/gnu-efi/lib/Makefile new file mode 100644 index 0000000..0e6410d --- /dev/null +++ b/gnu-efi/lib/Makefile @@ -0,0 +1,93 @@ +# +# Copyright (C) 1999-2001 Hewlett-Packard Co. +# Contributed by David Mosberger +# Contributed by Stephane Eranian +# +# 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)/.. +FILES = boxdraw smbios console crc data debug dpath \ + error event exit guid hand hw init lock \ + misc print sread str cmdline \ + runtime/rtlock runtime/efirtlib runtime/rtstr runtime/vm runtime/rtdata \ + $(ARCH)/initplat $(ARCH)/math $(ARCH)/setjmp + +ifeq ($(ARCH),ia64) +FILES += $(ARCH)/salpal $(ARCH)/palproc +endif + +ifeq ($(ARCH),x86_64) +FILES += $(ARCH)/callwrap $(ARCH)/efi_stub +endif + +ifeq ($(ARCH),arm) +FILES += $(ARCH)/uldiv $(ARCH)/ldivmod $(ARCH)/div $(ARCH)/llsl $(ARCH)/llsr \ + $(ARCH)/mullu +endif + +OBJS = $(FILES:%=%.o) + +SUBDIRS = ia32 x86_64 ia64 aarch64 arm mips64el runtime + +LIBDIRINSTALL = $(INSTALLROOT)$(LIBDIR) + +all: libsubdirs libefi.a + +.PHONY: libsubdirs +libsubdirs: + for sdir in $(SUBDIRS); do mkdir -p $$sdir; done + +libefi.a: $(OBJS) + $(AR) $(ARFLAGS) $@ $^ + +clean: + rm -f libefi.a *~ $(OBJS) */*.o + +$(LIBDIRINSTALL): + mkdir -p $@ + +$(LIBDIRINSTALL)/libefi.a: libefi.a | $(LIBDIRINSTALL) + $(INSTALL) -m 644 $< $(dir $@) + +install: $(LIBDIRINSTALL)/libefi.a + +include $(SRCDIR)/../Make.rules + +.PHONY: libsubdirs diff --git a/gnu-efi/lib/Makefile.orig b/gnu-efi/lib/Makefile.orig new file mode 100644 index 0000000..65aa8ca --- /dev/null +++ b/gnu-efi/lib/Makefile.orig @@ -0,0 +1,91 @@ +# +# Copyright (C) 1999-2001 Hewlett-Packard Co. +# Contributed by David Mosberger +# Contributed by Stephane Eranian +# +# 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)/.. +FILES = boxdraw smbios console crc data debug dpath \ + error event guid hand hw init lock \ + misc print sread str cmdline \ + runtime/rtlock runtime/efirtlib runtime/rtstr runtime/vm runtime/rtdata \ + $(ARCH)/initplat $(ARCH)/math + +ifeq ($(ARCH),ia64) +FILES += $(ARCH)/salpal $(ARCH)/palproc +endif + +ifeq ($(ARCH),x86_64) +FILES += $(ARCH)/callwrap $(ARCH)/efi_stub +endif + +ifeq ($(ARCH),arm) +FILES += $(ARCH)/lib1funcs $(ARCH)/div64 +endif + +OBJS = $(FILES:%=%.o) + +SUBDIRS = ia32 x86_64 ia64 aarch64 arm runtime + +LIBDIRINSTALL = $(INSTALLROOT)$(LIBDIR) + +all: libsubdirs libefi.a + +.PHONY: libsubdirs +libsubdirs: + for sdir in $(SUBDIRS); do mkdir -p $$sdir; done + +libefi.a: $(patsubst %,libefi.a(%),$(OBJS)) + +clean: + rm -f libefi.a *~ $(OBJS) */*.o + +$(LIBDIRINSTALL): + mkdir -p $@ + +$(LIBDIRINSTALL)/libefi.a: libefi.a | $(LIBDIRINSTALL) + $(INSTALL) -m 644 $< $(dir $@) + +install: $(LIBDIRINSTALL)/libefi.a + +include $(SRCDIR)/../Make.rules + +.PHONY: libsubdirs diff --git a/gnu-efi/lib/aarch64/efi_stub.S b/gnu-efi/lib/aarch64/efi_stub.S new file mode 100644 index 0000000..464eae5 --- /dev/null +++ b/gnu-efi/lib/aarch64/efi_stub.S @@ -0,0 +1 @@ +/* This stub is a stub to make the build happy */ diff --git a/gnu-efi/lib/aarch64/initplat.c b/gnu-efi/lib/aarch64/initplat.c new file mode 100644 index 0000000..6c5e1fa --- /dev/null +++ b/gnu-efi/lib/aarch64/initplat.c @@ -0,0 +1,26 @@ +/* + * Copright (C) 2014 Linaro Ltd. + * Author: Ard Biesheuvel + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice and this list of conditions, without modification. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License as published by the Free Software Foundation; + * either version 2 of the License, or (at your option) any later version. + */ + +#include "lib.h" + +VOID +InitializeLibPlatform ( + IN EFI_HANDLE ImageHandle EFI_UNUSED, + IN EFI_SYSTEM_TABLE *SystemTable EFI_UNUSED + ) +{ +} diff --git a/gnu-efi/lib/aarch64/math.c b/gnu-efi/lib/aarch64/math.c new file mode 100644 index 0000000..8c16444 --- /dev/null +++ b/gnu-efi/lib/aarch64/math.c @@ -0,0 +1,63 @@ +/* + * Copright (C) 2014 Linaro Ltd. + * Author: Ard Biesheuvel + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice and this list of conditions, without modification. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License as published by the Free Software Foundation; + * either version 2 of the License, or (at your option) any later version. + */ + +#include "lib.h" + +UINT64 +LShiftU64 ( + IN UINT64 Operand, + IN UINTN Count + ) +// Left shift 64bit by 32bit and get a 64bit result +{ + return Operand << Count; +} + +UINT64 +RShiftU64 ( + IN UINT64 Operand, + IN UINTN Count + ) +// Right shift 64bit by 32bit and get a 64bit result +{ + return Operand >> Count; +} + + +UINT64 +MultU64x32 ( + IN UINT64 Multiplicand, + IN UINTN Multiplier + ) +// Multiple 64bit by 32bit and get a 64bit result +{ + return Multiplicand * Multiplier; +} + +UINT64 +DivU64x32 ( + IN UINT64 Dividend, + IN UINTN Divisor, + OUT UINTN *Remainder OPTIONAL + ) +// divide 64bit by 32bit and get a 64bit result +// N.B. only works for 31bit divisors!! +{ + if (Remainder) + *Remainder = Dividend % Divisor; + return Dividend / Divisor; +} diff --git a/gnu-efi/lib/aarch64/setjmp.S b/gnu-efi/lib/aarch64/setjmp.S new file mode 100644 index 0000000..46c29b1 --- /dev/null +++ b/gnu-efi/lib/aarch64/setjmp.S @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved. + * This program and the accompanying materials are licensed and made +available + * under the terms and conditions of the BSD License which accompanies +this + * distribution. The full text of the license may be found at + * http://opensource.org/licenses/bsd-license.php. + * + * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, + * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR + * IMPLIED. + */ + .text + .p2align 3 + +#define GPR_LAYOUT \ + REG_PAIR (x19, x20, 0); \ + REG_PAIR (x21, x22, 16); \ + REG_PAIR (x23, x24, 32); \ + REG_PAIR (x25, x26, 48); \ + REG_PAIR (x27, x28, 64); \ + REG_PAIR (x29, x30, 80); \ + REG_ONE (x16, 96) + +#define FPR_LAYOUT \ + REG_PAIR(d8, d9, 112); \ + REG_PAIR(d10, d11, 128); \ + REG_PAIR(d12, d13, 144); \ + REG_PAIR(d14, d15, 160); + +#define REG_PAIR(REG1, REG2, OFFS) stp REG1, REG2, [x0, OFFS] +#define REG_ONE(REG1, OFFS) str REG1, [x0, OFFS] + + .globl setjmp + .type setjmp, @function +setjmp: + mov x16, sp + GPR_LAYOUT + FPR_LAYOUT + mov w0, #0 + ret + +#undef REG_PAIR +#undef REG_ONE + +#define REG_PAIR(REG1, REG2, OFFS) ldp REG1, REG2, [x0, OFFS] +#define REG_ONE(REG1, OFFS) ldr REG1, [x0, OFFS] + + .globl longjmp + .type longjmp, @function +longjmp: + GPR_LAYOUT + FPR_LAYOUT + mov sp, x16 + cmp w1, #0 + mov w0, #1 + csel w0, w1, w0, ne + br x30 diff --git a/gnu-efi/lib/boxdraw.c b/gnu-efi/lib/boxdraw.c new file mode 100644 index 0000000..5865fb9 --- /dev/null +++ b/gnu-efi/lib/boxdraw.c @@ -0,0 +1,173 @@ +/*++ + +Copyright (c) 1998 Intel Corporation + +Module Name: + + BoxDraw.c + +Abstract: + Lib functions to support Box Draw Unicode code pages. + + + +Revision History + +--*/ + +#include "lib.h" + +typedef struct { + CHAR16 Unicode; + CHAR8 PcAnsi; + CHAR8 Ascii; +} UNICODE_TO_CHAR; + + +// +// This list is used to define the valid extend chars. +// It also provides a mapping from Unicode to PCANSI or +// ASCII. The ASCII mapping we just made up. +// +// + +STATIC UNICODE_TO_CHAR UnicodeToPcAnsiOrAscii[] = { + { BOXDRAW_HORIZONTAL, 0xc4, L'-'}, + { BOXDRAW_VERTICAL, 0xb3, L'|'}, + { BOXDRAW_DOWN_RIGHT, 0xda, L'/'}, + { BOXDRAW_DOWN_LEFT, 0xbf, L'\\'}, + { BOXDRAW_UP_RIGHT, 0xc0, L'\\'}, + { BOXDRAW_UP_LEFT, 0xd9, L'/'}, + { BOXDRAW_VERTICAL_RIGHT, 0xc3, L'|'}, + { BOXDRAW_VERTICAL_LEFT, 0xb4, L'|'}, + { BOXDRAW_DOWN_HORIZONTAL, 0xc2, L'+'}, + { BOXDRAW_UP_HORIZONTAL, 0xc1, L'+'}, + { BOXDRAW_VERTICAL_HORIZONTAL, 0xc5, L'+'}, + { BOXDRAW_DOUBLE_HORIZONTAL, 0xcd, L'-'}, + { BOXDRAW_DOUBLE_VERTICAL, 0xba, L'|'}, + { BOXDRAW_DOWN_RIGHT_DOUBLE, 0xd5, L'/'}, + { BOXDRAW_DOWN_DOUBLE_RIGHT, 0xd6, L'/'}, + { BOXDRAW_DOUBLE_DOWN_RIGHT, 0xc9, L'/'}, + { BOXDRAW_DOWN_LEFT_DOUBLE, 0xb8, L'\\'}, + { BOXDRAW_DOWN_DOUBLE_LEFT, 0xb7, L'\\'}, + { BOXDRAW_DOUBLE_DOWN_LEFT, 0xbb, L'\\'}, + { BOXDRAW_UP_RIGHT_DOUBLE, 0xd4, L'\\'}, + { BOXDRAW_UP_DOUBLE_RIGHT, 0xd3, L'\\'}, + { BOXDRAW_DOUBLE_UP_RIGHT, 0xc8, L'\\'}, + { BOXDRAW_UP_LEFT_DOUBLE, 0xbe, L'/'}, + { BOXDRAW_UP_DOUBLE_LEFT, 0xbd, L'/'}, + { BOXDRAW_DOUBLE_UP_LEFT, 0xbc, L'/'}, + { BOXDRAW_VERTICAL_RIGHT_DOUBLE, 0xc6, L'|'}, + { BOXDRAW_VERTICAL_DOUBLE_RIGHT, 0xc7, L'|'}, + { BOXDRAW_DOUBLE_VERTICAL_RIGHT, 0xcc, L'|'}, + { BOXDRAW_VERTICAL_LEFT_DOUBLE, 0xb5, L'|'}, + { BOXDRAW_VERTICAL_DOUBLE_LEFT, 0xb6, L'|'}, + { BOXDRAW_DOUBLE_VERTICAL_LEFT, 0xb9, L'|'}, + { BOXDRAW_DOWN_HORIZONTAL_DOUBLE, 0xd1, L'+'}, + { BOXDRAW_DOWN_DOUBLE_HORIZONTAL, 0xd2, L'+'}, + { BOXDRAW_DOUBLE_DOWN_HORIZONTAL, 0xcb, L'+'}, + { BOXDRAW_UP_HORIZONTAL_DOUBLE, 0xcf, L'+'}, + { BOXDRAW_UP_DOUBLE_HORIZONTAL, 0xd0, L'+'}, + { BOXDRAW_DOUBLE_UP_HORIZONTAL, 0xca, L'+'}, + { BOXDRAW_VERTICAL_HORIZONTAL_DOUBLE, 0xd8, L'+'}, + { BOXDRAW_VERTICAL_DOUBLE_HORIZONTAL, 0xd7, L'+'}, + { BOXDRAW_DOUBLE_VERTICAL_HORIZONTAL, 0xce, L'+'}, + + { BLOCKELEMENT_FULL_BLOCK, 0xdb, L'*'}, + { BLOCKELEMENT_LIGHT_SHADE, 0xb0, L'+'}, + + { GEOMETRICSHAPE_UP_TRIANGLE, 0x1e, L'^'}, + { GEOMETRICSHAPE_RIGHT_TRIANGLE, 0x10, L'>'}, + { GEOMETRICSHAPE_DOWN_TRIANGLE, 0x1f, L'v'}, + { GEOMETRICSHAPE_LEFT_TRIANGLE, 0x11, L'<'}, + + /* BugBug: Left Arrow is an ESC. We can not make it print + on a PCANSI terminal. If we can make left arrow + come out on PC ANSI we can add it back. + + { ARROW_LEFT, 0x1b, L'<'}, + */ + + { ARROW_UP, 0x18, L'^'}, + + /* BugBut: Took out left arrow so right has to go too. + { ARROW_RIGHT, 0x1a, L'>'}, + */ + { ARROW_DOWN, 0x19, L'v'}, + + { 0x0000, 0x00, L'\0' } +}; + + +BOOLEAN +LibIsValidTextGraphics ( + IN CHAR16 Graphic, + OUT CHAR8 *PcAnsi, OPTIONAL + OUT CHAR8 *Ascii OPTIONAL + ) +/*++ + +Routine Description: + + Detects if a Unicode char is for Box Drawing text graphics. + +Arguments: + + Grphic - Unicode char to test. + + PcAnsi - Optional pointer to return PCANSI equivalent of Graphic. + + Asci - Optional pointer to return Ascii equivalent of Graphic. + +Returns: + + TRUE if Gpaphic is a supported Unicode Box Drawing character. + +--*/{ + UNICODE_TO_CHAR *Table; + + if ((((Graphic & 0xff00) != 0x2500) && ((Graphic & 0xff00) != 0x2100))) { + + // + // Unicode drawing code charts are all in the 0x25xx range, + // arrows are 0x21xx + // + return FALSE; + } + + for (Table = UnicodeToPcAnsiOrAscii; Table->Unicode != 0x0000; Table++) { + if (Graphic == Table->Unicode) { + if (PcAnsi) { + *PcAnsi = Table->PcAnsi; + } + if (Ascii) { + *Ascii = Table->Ascii; + } + return TRUE; + } + } + return FALSE; +} + +BOOLEAN +IsValidAscii ( + IN CHAR16 Ascii + ) +{ + if ((Ascii >= 0x20) && (Ascii <= 0x7f)) { + return TRUE; + } + return FALSE; +} + +BOOLEAN +IsValidEfiCntlChar ( + IN CHAR16 c + ) +{ + if (c == CHAR_NULL || c == CHAR_BACKSPACE || c == CHAR_LINEFEED || c == CHAR_CARRIAGE_RETURN) { + return TRUE; + } + return FALSE; +} + diff --git a/gnu-efi/lib/cmdline.c b/gnu-efi/lib/cmdline.c new file mode 100644 index 0000000..f21c44c --- /dev/null +++ b/gnu-efi/lib/cmdline.c @@ -0,0 +1,121 @@ +#include "lib.h" + +#include "efiprot.h" +#include "efishellintf.h" +#include "efishellparm.h" + +#ifndef MAX_ARGV_CONTENTS_SIZE +# define MAX_CMDLINE_SIZE 1024 +#endif +#ifndef MAX_ARGC +# define MAX_CMDLINE_ARGC 32 +#endif + +/* + Parse LoadedImage options area, called only in case the regular + shell protos are not available. + + Format of LoadedImage->LoadOptions appears to be a + single-space-separated list of args (looks like the shell already + pre-parses the input, it apparently folds several consecutive spaces + into one): + argv[0] space argv[1] (etc.) argv[N] space \0 cwd \0 other data + For safety, we support the trailing \0 without a space before, as + well as several consecutive spaces (-> several args). +*/ +static +INTN +GetShellArgcArgvFromLoadedImage( + EFI_HANDLE ImageHandle, + CHAR16 **ResultArgv[] + ) +{ + EFI_STATUS Status; + void *LoadedImage = NULL; + static CHAR16 ArgvContents[MAX_CMDLINE_SIZE]; + static CHAR16 *Argv[MAX_CMDLINE_ARGC], *ArgStart, *c; + UINTN Argc = 0, BufLen; + + Status = uefi_call_wrapper(BS->OpenProtocol, 6, + ImageHandle, + &LoadedImageProtocol, + &LoadedImage, + ImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR(Status)) + return -1; + + BufLen = ((EFI_LOADED_IMAGE *)LoadedImage)->LoadOptionsSize; + if (BufLen < 2) /* We are expecting at least a \0 */ + return -1; + else if (BufLen > sizeof(ArgvContents)) + BufLen = sizeof(ArgvContents); + + CopyMem(ArgvContents, ((EFI_LOADED_IMAGE *)LoadedImage)->LoadOptions, BufLen); + ArgvContents[MAX_CMDLINE_SIZE - 1] = L'\0'; + + for (c = ArgStart = ArgvContents ; *c != L'\0' ; ++c) { + if (*c == L' ') { + *c = L'\0'; + if (Argc < MAX_CMDLINE_ARGC) Argv[Argc++] = ArgStart; + ArgStart = c + 1; + } + } + + if ((*ArgStart != L'\0') && (Argc < MAX_CMDLINE_ARGC)) + Argv[Argc++] = ArgStart; + + // Print(L"Got argc/argv from loaded image proto\n"); + *ResultArgv = Argv; + return Argc; +} + +INTN GetShellArgcArgv(EFI_HANDLE ImageHandle, CHAR16 **Argv[]) +{ + // Code inspired from EDK2's + // ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.c (BSD) + EFI_STATUS Status; + static const EFI_GUID EfiShellParametersProtocolGuid + = EFI_SHELL_PARAMETERS_PROTOCOL_GUID; + static const EFI_GUID ShellInterfaceProtocolGuid + = SHELL_INTERFACE_PROTOCOL_GUID; + EFI_SHELL_PARAMETERS_PROTOCOL *EfiShellParametersProtocol = NULL; + EFI_SHELL_INTERFACE *EfiShellInterfaceProtocol = NULL; + + Status = uefi_call_wrapper(BS->OpenProtocol, 6, + ImageHandle, + (EFI_GUID*)&EfiShellParametersProtocolGuid, + (VOID **)&EfiShellParametersProtocol, + ImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (!EFI_ERROR(Status)) + { + // use shell 2.0 interface + // Print(L"Got argc/argv from shell intf proto\n"); + *Argv = EfiShellParametersProtocol->Argv; + return EfiShellParametersProtocol->Argc; + } + + // try to get shell 1.0 interface instead. + Status = uefi_call_wrapper(BS->OpenProtocol, 6, + ImageHandle, + (EFI_GUID*)&ShellInterfaceProtocolGuid, + (VOID **)&EfiShellInterfaceProtocol, + ImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (!EFI_ERROR(Status)) + { + // Print(L"Got argc/argv from shell params proto\n"); + *Argv = EfiShellInterfaceProtocol->Argv; + return EfiShellInterfaceProtocol->Argc; + } + + // shell 1.0 and 2.0 interfaces failed + return GetShellArgcArgvFromLoadedImage(ImageHandle, Argv); +} diff --git a/gnu-efi/lib/console.c b/gnu-efi/lib/console.c new file mode 100644 index 0000000..5ca47ef --- /dev/null +++ b/gnu-efi/lib/console.c @@ -0,0 +1,104 @@ +/*++ + +Copyright (c) 1998 Intel Corporation + +Module Name: + + console.c + +Abstract: + + + + +Revision History + +--*/ + +#include "lib.h" + + + +VOID +Output ( + IN CHAR16 *Str + ) +// Write a string to the console at the current cursor location +{ + uefi_call_wrapper(ST->ConOut->OutputString, 2, ST->ConOut, Str); +} + + +VOID +Input ( + IN CHAR16 *Prompt OPTIONAL, + OUT CHAR16 *InStr, + IN UINTN StrLen + ) +// Input a string at the current cursor location, for StrLen +{ + IInput ( + ST->ConOut, + ST->ConIn, + Prompt, + InStr, + StrLen + ); +} + +VOID +IInput ( + IN SIMPLE_TEXT_OUTPUT_INTERFACE *ConOut, + IN SIMPLE_INPUT_INTERFACE *ConIn, + IN CHAR16 *Prompt OPTIONAL, + OUT CHAR16 *InStr, + IN UINTN StrLen + ) +// Input a string at the current cursor location, for StrLen +{ + EFI_INPUT_KEY Key; + EFI_STATUS Status; + UINTN Len; + + if (Prompt) { + ConOut->OutputString (ConOut, Prompt); + } + + Len = 0; + for (; ;) { + WaitForSingleEvent (ConIn->WaitForKey, 0); + + Status = uefi_call_wrapper(ConIn->ReadKeyStroke, 2, ConIn, &Key); + if (EFI_ERROR(Status)) { + DEBUG((D_ERROR, "Input: error return from ReadKey %x\n", Status)); + break; + } + + if (Key.UnicodeChar == '\n' || + Key.UnicodeChar == '\r') { + break; + } + + if (Key.UnicodeChar == '\b') { + if (Len) { + uefi_call_wrapper(ConOut->OutputString, 2, ConOut, L"\b \b"); + Len -= 1; + } + continue; + } + + if (Key.UnicodeChar >= ' ') { + if (Len < StrLen-1) { + InStr[Len] = Key.UnicodeChar; + + InStr[Len+1] = 0; + uefi_call_wrapper(ConOut->OutputString, 2, ConOut, &InStr[Len]); + + Len += 1; + } + continue; + } + } + + InStr[Len] = 0; +} diff --git a/gnu-efi/lib/crc.c b/gnu-efi/lib/crc.c new file mode 100644 index 0000000..4367ed1 --- /dev/null +++ b/gnu-efi/lib/crc.c @@ -0,0 +1,218 @@ +/*++ + +Copyright (c) 1998 Intel Corporation + +Module Name: + + crc.c + +Abstract: + + CRC32 functions + + + +Revision History + +--*/ + +#include "lib.h" + + +UINT32 CRCTable[256] = { + 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, + 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, + 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2, + 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, + 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, + 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, + 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C, + 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, + 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, + 0xCFBA9599, 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, + 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, 0x76DC4190, 0x01DB7106, + 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, + 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, + 0x91646C97, 0xE6635C01, 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, + 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950, + 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, + 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, + 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, + 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA, + 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, + 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, + 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, + 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, 0xE3630B12, 0x94643B84, + 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, + 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, + 0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, + 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8, 0xA1D1937E, + 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, + 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, + 0x316E8EEF, 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, + 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, + 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, + 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, + 0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, + 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242, + 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, + 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, + 0x616BFFD3, 0x166CCF45, 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, + 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, + 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, + 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, + 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, + 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D + }; + + + +VOID +SetCrc ( + IN OUT EFI_TABLE_HEADER *Hdr + ) +/*++ + +Routine Description: + + Updates the CRC32 value in the table header + +Arguments: + + Hdr - The table to update + +Returns: + + None + +--*/ +{ + SetCrcAltSize (Hdr->HeaderSize, Hdr); +} + +VOID +SetCrcAltSize ( + IN UINTN Size, + IN OUT EFI_TABLE_HEADER *Hdr + ) +/*++ + +Routine Description: + + Updates the CRC32 value in the table header + +Arguments: + + Hdr - The table to update + +Returns: + + None + +--*/ +{ + Hdr->CRC32 = 0; + Hdr->CRC32 = CalculateCrc((UINT8 *)Hdr, Size); +} + + +BOOLEAN +CheckCrc ( + IN UINTN MaxSize, + IN OUT EFI_TABLE_HEADER *Hdr + ) +/*++ + +Routine Description: + + Checks the CRC32 value in the table header + +Arguments: + + Hdr - The table to check + +Returns: + + TRUE if the CRC is OK in the table + +--*/ +{ + return CheckCrcAltSize (MaxSize, Hdr->HeaderSize, Hdr); +} + + + + +BOOLEAN +CheckCrcAltSize ( + IN UINTN MaxSize, + IN UINTN Size, + IN OUT EFI_TABLE_HEADER *Hdr + ) +/*++ + +Routine Description: + + Checks the CRC32 value in the table header + +Arguments: + + Hdr - The table to check + +Returns: + + TRUE if the CRC is OK in the table + +--*/ +{ + UINT32 Crc; + UINT32 OrgCrc; + BOOLEAN f; + + if (Size == 0) { + // + // If header size is 0 CRC will pass so return FALSE here + // + return FALSE; + } + if (MaxSize && Size > MaxSize) { + DEBUG((D_ERROR, "CheckCrc32: Size > MaxSize\n")); + return FALSE; + } + + // clear old crc from header + OrgCrc = Hdr->CRC32; + Hdr->CRC32 = 0; + Crc = CalculateCrc((UINT8 *)Hdr, Size); + + // set restults + Hdr->CRC32 = OrgCrc; + + // return status + f = OrgCrc == (UINT32) Crc; + if (!f) { + DEBUG((D_ERROR, "CheckCrc32: Crc check failed\n")); + } + + return f; +} + + +UINT32 +CalculateCrc ( + UINT8 *pt, + UINTN Size + ) +{ + UINTN Crc; + + // compute crc + Crc = 0xffffffff; + while (Size) { + Crc = (Crc >> 8) ^ CRCTable[(UINT8) Crc ^ *pt]; + pt += 1; + Size -= 1; + } + Crc = Crc ^ 0xffffffff; + return (UINT32)Crc; +} diff --git a/gnu-efi/lib/data.c b/gnu-efi/lib/data.c new file mode 100644 index 0000000..5b4f3b5 --- /dev/null +++ b/gnu-efi/lib/data.c @@ -0,0 +1,203 @@ +/*++ + +Copyright (c) 1998 Intel Corporation + +Module Name: + + data.c + +Abstract: + + EFI library global data + + + +Revision History + +--*/ + +#include "lib.h" + +// +// LibInitialized - TRUE once InitializeLib() is called for the first time +// + +BOOLEAN LibInitialized = FALSE; + +// +// ImageHandle - Current ImageHandle, as passed to InitializeLib +// +EFI_HANDLE LibImageHandle; + +// +// ST - pointer to the EFI system table +// + +EFI_SYSTEM_TABLE *ST; + +// +// BS - pointer to the boot services table +// + +EFI_BOOT_SERVICES *BS; + + +// +// Default pool allocation type +// + +EFI_MEMORY_TYPE PoolAllocationType = EfiBootServicesData; + +// +// Unicode collation functions that are in use +// + +EFI_UNICODE_COLLATION_INTERFACE LibStubUnicodeInterface = { + LibStubStriCmp, + LibStubMetaiMatch, + LibStubStrLwrUpr, + LibStubStrLwrUpr, + NULL, // FatToStr + NULL, // StrToFat + NULL // SupportedLanguages +}; + +EFI_UNICODE_COLLATION_INTERFACE *UnicodeInterface = &LibStubUnicodeInterface; + +// +// Root device path +// + +EFI_DEVICE_PATH RootDevicePath[] = { + {END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, {END_DEVICE_PATH_LENGTH,0}} +}; + +EFI_DEVICE_PATH EndDevicePath[] = { + {END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, {END_DEVICE_PATH_LENGTH, 0}} +}; + +EFI_DEVICE_PATH EndInstanceDevicePath[] = { + {END_DEVICE_PATH_TYPE, END_INSTANCE_DEVICE_PATH_SUBTYPE, {END_DEVICE_PATH_LENGTH, 0}} +}; + + +// +// EFI IDs +// + +EFI_GUID gEfiGlobalVariableGuid = EFI_GLOBAL_VARIABLE; +EFI_GUID NullGuid = { 0,0,0,{0,0,0,0,0,0,0,0} }; + +// +// Protocol IDs +// + +EFI_GUID gEfiDevicePathProtocolGuid = EFI_DEVICE_PATH_PROTOCOL_GUID; +EFI_GUID gEfiDevicePathToTextProtocolGuid = EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID; +EFI_GUID gEfiDevicePathFromTextProtocolGuid = EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL_GUID; +EFI_GUID gEfiLoadedImageProtocolGuid = EFI_LOADED_IMAGE_PROTOCOL_GUID; +EFI_GUID gEfiSimpleTextInProtocolGuid = EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID; +EFI_GUID gEfiSimpleTextOutProtocolGuid = EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID; +EFI_GUID gEfiBlockIoProtocolGuid = EFI_BLOCK_IO_PROTOCOL_GUID; +EFI_GUID gEfiBlockIo2ProtocolGuid = EFI_BLOCK_IO2_PROTOCOL_GUID; +EFI_GUID gEfiDiskIoProtocolGuid = EFI_DISK_IO_PROTOCOL_GUID; +EFI_GUID gEfiDiskIo2ProtocolGuid = EFI_DISK_IO2_PROTOCOL_GUID; +EFI_GUID gEfiSimpleFileSystemProtocolGuid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID; +EFI_GUID gEfiLoadFileProtocolGuid = EFI_LOAD_FILE_PROTOCOL_GUID; +EFI_GUID gEfiDeviceIoProtocolGuid = EFI_DEVICE_IO_PROTOCOL_GUID; +EFI_GUID gEfiUnicodeCollationProtocolGuid = EFI_UNICODE_COLLATION_PROTOCOL_GUID; +EFI_GUID gEfiSerialIoProtocolGuid = EFI_SERIAL_IO_PROTOCOL_GUID; +EFI_GUID gEfiSimpleNetworkProtocolGuid = EFI_SIMPLE_NETWORK_PROTOCOL_GUID; +EFI_GUID gEfiPxeBaseCodeProtocolGuid = EFI_PXE_BASE_CODE_PROTOCOL_GUID; +EFI_GUID gEfiPxeBaseCodeCallbackProtocolGuid = EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL_GUID; +EFI_GUID gEfiNetworkInterfaceIdentifierProtocolGuid = EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_GUID; +EFI_GUID gEFiUiInterfaceProtocolGuid = EFI_UI_INTERFACE_PROTOCOL_GUID; +EFI_GUID gEfiPciIoProtocolGuid = EFI_PCI_IO_PROTOCOL_GUID; +EFI_GUID gEfiPciRootBridgeIoProtocolGuid = EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GUID; +EFI_GUID gEfiDriverBindingProtocolGuid = EFI_DRIVER_BINDING_PROTOCOL_GUID; +EFI_GUID gEfiComponentNameProtocolGuid = EFI_COMPONENT_NAME_PROTOCOL_GUID; +EFI_GUID gEfiComponentName2ProtocolGuid = EFI_COMPONENT_NAME2_PROTOCOL_GUID; +EFI_GUID gEfiHashProtocolGuid = EFI_HASH_PROTOCOL_GUID; +EFI_GUID gEfiPlatformDriverOverrideProtocolGuid = EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL_GUID; +EFI_GUID gEfiBusSpecificDriverOverrideProtocolGuid = EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL_GUID; +EFI_GUID gEfiDriverFamilyOverrideProtocolGuid = EFI_DRIVER_FAMILY_OVERRIDE_PROTOCOL_GUID; +EFI_GUID gEfiEbcProtocolGuid = EFI_EBC_PROTOCOL_GUID; + +// +// File system information IDs +// + +EFI_GUID gEfiFileInfoGuid = EFI_FILE_INFO_ID; +EFI_GUID gEfiFileSystemInfoGuid = EFI_FILE_SYSTEM_INFO_ID; +EFI_GUID gEfiFileSystemVolumeLabelInfoIdGuid = EFI_FILE_SYSTEM_VOLUME_LABEL_INFO_ID; + +// +// Reference implementation public protocol IDs +// + +EFI_GUID InternalShellProtocol = INTERNAL_SHELL_GUID; +EFI_GUID VariableStoreProtocol = VARIABLE_STORE_PROTOCOL; +EFI_GUID LegacyBootProtocol = LEGACY_BOOT_PROTOCOL; +EFI_GUID VgaClassProtocol = VGA_CLASS_DRIVER_PROTOCOL; + +EFI_GUID TextOutSpliterProtocol = TEXT_OUT_SPLITER_PROTOCOL; +EFI_GUID ErrorOutSpliterProtocol = ERROR_OUT_SPLITER_PROTOCOL; +EFI_GUID TextInSpliterProtocol = TEXT_IN_SPLITER_PROTOCOL; +/* Added for GOP support */ +EFI_GUID gEfiGraphicsOutputProtocolGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; +EFI_GUID gEfiEdidDiscoveredProtocolGuid = EFI_EDID_DISCOVERED_PROTOCOL_GUID; +EFI_GUID gEfiEdidActiveProtocolGuid = EFI_EDID_ACTIVE_PROTOCOL_GUID; +EFI_GUID gEfiEdidOverrideProtocolGuid = EFI_EDID_OVERRIDE_PROTOCOL_GUID; + +EFI_GUID AdapterDebugProtocol = ADAPTER_DEBUG_PROTOCOL; + +// +// Device path media protocol IDs +// +EFI_GUID gEfiPcAnsiGuid = EFI_PC_ANSI_GUID; +EFI_GUID gEfiVT100Guid = EFI_VT_100_GUID; +EFI_GUID gEfiVT100PlusGuid = EFI_VT_100_PLUS_GUID; +EFI_GUID gEfiVTUTF8Guid = EFI_VT_UTF8_GUID; + +// +// EFI GPT Partition Type GUIDs +// +EFI_GUID EfiPartTypeSystemPartitionGuid = EFI_PART_TYPE_EFI_SYSTEM_PART_GUID; +EFI_GUID EfiPartTypeLegacyMbrGuid = EFI_PART_TYPE_LEGACY_MBR_GUID; + + +// +// Reference implementation Vendor Device Path Guids +// +EFI_GUID UnknownDevice = UNKNOWN_DEVICE_GUID; + +// +// Configuration Table GUIDs +// + +EFI_GUID MpsTableGuid = MPS_TABLE_GUID; +EFI_GUID AcpiTableGuid = ACPI_TABLE_GUID; +EFI_GUID SMBIOSTableGuid = SMBIOS_TABLE_GUID; +EFI_GUID SalSystemTableGuid = SAL_SYSTEM_TABLE_GUID; + +// +// Network protocol GUIDs +// +EFI_GUID Ip4ServiceBindingProtocol = EFI_IP4_SERVICE_BINDING_PROTOCOL; +EFI_GUID Ip4Protocol = EFI_IP4_PROTOCOL; +EFI_GUID Udp4ServiceBindingProtocol = EFI_UDP4_SERVICE_BINDING_PROTOCOL; +EFI_GUID Udp4Protocol = EFI_UDP4_PROTOCOL; +EFI_GUID Tcp4ServiceBindingProtocol = EFI_TCP4_SERVICE_BINDING_PROTOCOL; +EFI_GUID Tcp4Protocol = EFI_TCP4_PROTOCOL; + +// +// Pointer protocol GUIDs +// +EFI_GUID SimplePointerProtocol = EFI_SIMPLE_POINTER_PROTOCOL_GUID; +EFI_GUID AbsolutePointerProtocol = EFI_ABSOLUTE_POINTER_PROTOCOL_GUID; + +// +// Debugger protocol GUIDs +// +EFI_GUID gEfiDebugImageInfoTableGuid = EFI_DEBUG_IMAGE_INFO_TABLE_GUID; +EFI_GUID gEfiDebugSupportProtocolGuid = EFI_DEBUG_SUPPORT_PROTOCOL_GUID; diff --git a/gnu-efi/lib/debug.c b/gnu-efi/lib/debug.c new file mode 100644 index 0000000..b635123 --- /dev/null +++ b/gnu-efi/lib/debug.c @@ -0,0 +1,43 @@ +/*++ + +Copyright (c) 1998 Intel Corporation + +Module Name: + + debug.c + +Abstract: + + Debug library functions + + + +Revision History + +--*/ + +#include "lib.h" + + + +// +// Declare runtime functions +// + +// +// +// + +INTN +DbgAssert ( + IN CONST CHAR8 *FileName, + IN INTN LineNo, + IN CONST CHAR8 *Description + ) +{ + DbgPrint (D_ERROR, (CHAR8 *)"%EASSERT FAILED: %a(%d): %a%N\n", FileName, LineNo, Description); + + BREAKPOINT(); + return 0; +} + diff --git a/gnu-efi/lib/dpath.c b/gnu-efi/lib/dpath.c new file mode 100644 index 0000000..7486252 --- /dev/null +++ b/gnu-efi/lib/dpath.c @@ -0,0 +1,1260 @@ +/*++ + +Copyright (c) 1998 Intel Corporation + +Module Name: + + dpath.c + +Abstract: + MBR & Device Path functions + + + +Revision History + +2014/04 B.Burette - updated device path text representation, conforming to + UEFI specification 2.4 (dec. 2013). More specifically: + - § 9.3.5: added some media types ie. Sata() + - § 9.6.1.2: Acpi(PNP0A03,0) makes more sense when displayed as PciRoot(0) + - § 9.6.1.5: use commas (instead of '|') between option specific parameters + - § 9.6.1.6: hex values in device paths must be preceded by "0x" or "0X" + +--*/ + +#include "lib.h" + +#define ALIGN_SIZE(a) ((a % MIN_ALIGNMENT_SIZE) ? MIN_ALIGNMENT_SIZE - (a % MIN_ALIGNMENT_SIZE) : 0) + + + +EFI_DEVICE_PATH * +DevicePathFromHandle ( + IN EFI_HANDLE Handle + ) +{ + EFI_STATUS Status; + EFI_DEVICE_PATH *DevicePath; + + Status = uefi_call_wrapper(BS->HandleProtocol, 3, Handle, &DevicePathProtocol, (VOID*)&DevicePath); + if (EFI_ERROR(Status)) { + DevicePath = NULL; + } + + return DevicePath; +} + + +EFI_DEVICE_PATH * +DevicePathInstance ( + IN OUT EFI_DEVICE_PATH **DevicePath, + OUT UINTN *Size + ) +{ + EFI_DEVICE_PATH *Start, *Next, *DevPath; + UINTN Count; + + DevPath = *DevicePath; + Start = DevPath; + + if (!DevPath) { + return NULL; + } + + // + // Check for end of device path type + // + + for (Count = 0; ; Count++) { + Next = NextDevicePathNode(DevPath); + + if (IsDevicePathEndType(DevPath)) { + break; + } + + if (Count > 01000) { + // + // BugBug: Debug code to catch bogus device paths + // + DEBUG((D_ERROR, "DevicePathInstance: DevicePath %x Size %d", *DevicePath, ((UINT8 *) DevPath) - ((UINT8 *) Start) )); + DumpHex (0, 0, ((UINT8 *) DevPath) - ((UINT8 *) Start), Start); + break; + } + + DevPath = Next; + } + + ASSERT (DevicePathSubType(DevPath) == END_ENTIRE_DEVICE_PATH_SUBTYPE || + DevicePathSubType(DevPath) == END_INSTANCE_DEVICE_PATH_SUBTYPE); + + // + // Set next position + // + + if (DevicePathSubType(DevPath) == END_ENTIRE_DEVICE_PATH_SUBTYPE) { + Next = NULL; + } + + *DevicePath = Next; + + // + // Return size and start of device path instance + // + + *Size = ((UINT8 *) DevPath) - ((UINT8 *) Start); + return Start; +} + +UINTN +DevicePathInstanceCount ( + IN EFI_DEVICE_PATH *DevicePath + ) +{ + UINTN Count, Size; + + Count = 0; + while (DevicePathInstance(&DevicePath, &Size)) { + Count += 1; + } + + return Count; +} + + +EFI_DEVICE_PATH * +AppendDevicePath ( + IN EFI_DEVICE_PATH *Src1, + IN EFI_DEVICE_PATH *Src2 + ) +// Src1 may have multiple "instances" and each instance is appended +// Src2 is appended to each instance is Src1. (E.g., it's possible +// to append a new instance to the complete device path by passing +// it in Src2) +{ + UINTN Src1Size, Src1Inst, Src2Size, Size; + EFI_DEVICE_PATH *Dst, *Inst; + UINT8 *DstPos; + + // + // If there's only 1 path, just duplicate it + // + + if (!Src1) { + ASSERT (!IsDevicePathUnpacked (Src2)); + return DuplicateDevicePath (Src2); + } + + if (!Src2) { + ASSERT (!IsDevicePathUnpacked (Src1)); + return DuplicateDevicePath (Src1); + } + + // + // Verify we're not working with unpacked paths + // + +// ASSERT (!IsDevicePathUnpacked (Src1)); +// ASSERT (!IsDevicePathUnpacked (Src2)); + + // + // Append Src2 to every instance in Src1 + // + + Src1Size = DevicePathSize(Src1); + Src1Inst = DevicePathInstanceCount(Src1); + Src2Size = DevicePathSize(Src2); + Size = Src1Size * Src1Inst + Src2Size; + + Dst = AllocatePool (Size); + if (Dst) { + DstPos = (UINT8 *) Dst; + + // + // Copy all device path instances + // + + while ((Inst = DevicePathInstance (&Src1, &Size))) { + + CopyMem(DstPos, Inst, Size); + DstPos += Size; + + CopyMem(DstPos, Src2, Src2Size); + DstPos += Src2Size; + + CopyMem(DstPos, EndInstanceDevicePath, sizeof(EFI_DEVICE_PATH)); + DstPos += sizeof(EFI_DEVICE_PATH); + } + + // Change last end marker + DstPos -= sizeof(EFI_DEVICE_PATH); + CopyMem(DstPos, EndDevicePath, sizeof(EFI_DEVICE_PATH)); + } + + return Dst; +} + + +EFI_DEVICE_PATH * +AppendDevicePathNode ( + IN EFI_DEVICE_PATH *Src1, + IN EFI_DEVICE_PATH *Src2 + ) +// Src1 may have multiple "instances" and each instance is appended +// Src2 is a signal device path node (without a terminator) that is +// appended to each instance is Src1. +{ + EFI_DEVICE_PATH *Temp, *Eop; + UINTN Length; + + // + // Build a Src2 that has a terminator on it + // + + Length = DevicePathNodeLength(Src2); + Temp = AllocatePool (Length + sizeof(EFI_DEVICE_PATH)); + if (!Temp) { + return NULL; + } + + CopyMem (Temp, Src2, Length); + Eop = NextDevicePathNode(Temp); + SetDevicePathEndNode(Eop); + + // + // Append device paths + // + + Src1 = AppendDevicePath (Src1, Temp); + FreePool (Temp); + return Src1; +} + + +EFI_DEVICE_PATH * +FileDevicePath ( + IN EFI_HANDLE Device OPTIONAL, + IN CHAR16 *FileName + ) +/*++ + + N.B. Results are allocated from pool. The caller must FreePool + the resulting device path structure + +--*/ +{ + UINTN Size; + FILEPATH_DEVICE_PATH *FilePath; + EFI_DEVICE_PATH *Eop, *DevicePath; + + Size = StrSize(FileName); + FilePath = AllocateZeroPool (Size + SIZE_OF_FILEPATH_DEVICE_PATH + sizeof(EFI_DEVICE_PATH)); + DevicePath = NULL; + + if (FilePath) { + + // + // Build a file path + // + + FilePath->Header.Type = MEDIA_DEVICE_PATH; + FilePath->Header.SubType = MEDIA_FILEPATH_DP; + SetDevicePathNodeLength (&FilePath->Header, Size + SIZE_OF_FILEPATH_DEVICE_PATH); + CopyMem (FilePath->PathName, FileName, Size); + Eop = NextDevicePathNode(&FilePath->Header); + SetDevicePathEndNode(Eop); + + // + // Append file path to device's device path + // + + DevicePath = (EFI_DEVICE_PATH *) FilePath; + if (Device) { + DevicePath = AppendDevicePath ( + DevicePathFromHandle(Device), + DevicePath + ); + + FreePool(FilePath); + } + } + + return DevicePath; +} + + + +UINTN +DevicePathSize ( + IN EFI_DEVICE_PATH *DevPath + ) +{ + EFI_DEVICE_PATH *Start; + + // + // Search for the end of the device path structure + // + + Start = DevPath; + while (!IsDevicePathEnd(DevPath)) { + DevPath = NextDevicePathNode(DevPath); + } + + // + // Compute the size + // + + return ((UINTN) DevPath - (UINTN) Start) + sizeof(EFI_DEVICE_PATH); +} + +EFI_DEVICE_PATH * +DuplicateDevicePath ( + IN EFI_DEVICE_PATH *DevPath + ) +{ + EFI_DEVICE_PATH *NewDevPath; + UINTN Size; + + + // + // Compute the size + // + + Size = DevicePathSize (DevPath); + + // + // Make a copy + // + + NewDevPath = AllocatePool (Size); + if (NewDevPath) { + CopyMem (NewDevPath, DevPath, Size); + } + + return NewDevPath; +} + +EFI_DEVICE_PATH * +UnpackDevicePath ( + IN EFI_DEVICE_PATH *DevPath + ) +{ + EFI_DEVICE_PATH *Src, *Dest, *NewPath; + UINTN Size; + + // + // Walk device path and round sizes to valid boundries + // + + Src = DevPath; + Size = 0; + for (; ;) { + Size += DevicePathNodeLength(Src); + Size += ALIGN_SIZE(Size); + + if (IsDevicePathEnd(Src)) { + break; + } + + Src = NextDevicePathNode(Src); + } + + + // + // Allocate space for the unpacked path + // + + NewPath = AllocateZeroPool (Size); + if (NewPath) { + + ASSERT (((UINTN)NewPath) % MIN_ALIGNMENT_SIZE == 0); + + // + // Copy each node + // + + Src = DevPath; + Dest = NewPath; + for (; ;) { + Size = DevicePathNodeLength(Src); + CopyMem (Dest, Src, Size); + Size += ALIGN_SIZE(Size); + SetDevicePathNodeLength (Dest, Size); + Dest->Type |= EFI_DP_TYPE_UNPACKED; + Dest = (EFI_DEVICE_PATH *) (((UINT8 *) Dest) + Size); + + if (IsDevicePathEnd(Src)) { + break; + } + + Src = NextDevicePathNode(Src); + } + } + + return NewPath; +} + + +EFI_DEVICE_PATH* +AppendDevicePathInstance ( + IN EFI_DEVICE_PATH *Src, + IN EFI_DEVICE_PATH *Instance + ) +{ + UINT8 *Ptr; + EFI_DEVICE_PATH *DevPath; + UINTN SrcSize; + UINTN InstanceSize; + + if (Src == NULL) { + return DuplicateDevicePath (Instance); + } + SrcSize = DevicePathSize(Src); + InstanceSize = DevicePathSize(Instance); + Ptr = AllocatePool (SrcSize + InstanceSize); + DevPath = (EFI_DEVICE_PATH *)Ptr; + ASSERT(DevPath); + + CopyMem (Ptr, Src, SrcSize); +// FreePool (Src); + + while (!IsDevicePathEnd(DevPath)) { + DevPath = NextDevicePathNode(DevPath); + } + // + // Convert the End to an End Instance, since we are + // appending another instacne after this one its a good + // idea. + // + DevPath->SubType = END_INSTANCE_DEVICE_PATH_SUBTYPE; + + DevPath = NextDevicePathNode(DevPath); + CopyMem (DevPath, Instance, InstanceSize); + return (EFI_DEVICE_PATH *)Ptr; +} + +EFI_STATUS +LibDevicePathToInterface ( + IN EFI_GUID *Protocol, + IN EFI_DEVICE_PATH *FilePath, + OUT VOID **Interface + ) +{ + EFI_STATUS Status; + EFI_HANDLE Device; + + Status = uefi_call_wrapper(BS->LocateDevicePath, 3, Protocol, &FilePath, &Device); + + if (!EFI_ERROR(Status)) { + + // If we didn't get a direct match return not found + Status = EFI_NOT_FOUND; + + if (IsDevicePathEnd(FilePath)) { + + // + // It was a direct match, lookup the protocol interface + // + + Status =uefi_call_wrapper(BS->HandleProtocol, 3, Device, Protocol, Interface); + } + } + + // + // If there was an error, do not return an interface + // + + if (EFI_ERROR(Status)) { + *Interface = NULL; + } + + return Status; +} + +static VOID +_DevPathPci ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath + ) +{ + PCI_DEVICE_PATH *Pci; + + Pci = DevPath; + CatPrint(Str, L"Pci(0x%x,0x%x)", Pci->Device, Pci->Function); +} + +static VOID +_DevPathPccard ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath + ) +{ + PCCARD_DEVICE_PATH *Pccard; + + Pccard = DevPath; + CatPrint(Str, L"Pccard(0x%x)", Pccard-> FunctionNumber ); +} + +static VOID +_DevPathMemMap ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath + ) +{ + MEMMAP_DEVICE_PATH *MemMap; + + MemMap = DevPath; + CatPrint(Str, L"MemMap(%d,0x%x,0x%x)", + MemMap->MemoryType, + MemMap->StartingAddress, + MemMap->EndingAddress + ); +} + +static VOID +_DevPathController ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath + ) +{ + CONTROLLER_DEVICE_PATH *Controller; + + Controller = DevPath; + CatPrint(Str, L"Ctrl(%d)", + Controller->Controller + ); +} + +static VOID +_DevPathVendor ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath + ) +{ + VENDOR_DEVICE_PATH *Vendor; + CHAR16 *Type; + UNKNOWN_DEVICE_VENDOR_DEVICE_PATH *UnknownDevPath; + + Vendor = DevPath; + switch (DevicePathType(&Vendor->Header)) { + case HARDWARE_DEVICE_PATH: Type = L"Hw"; break; + case MESSAGING_DEVICE_PATH: Type = L"Msg"; break; + case MEDIA_DEVICE_PATH: Type = L"Media"; break; + default: Type = L"?"; break; + } + + CatPrint(Str, L"Ven%s(%g", Type, &Vendor->Guid); + if (CompareGuid (&Vendor->Guid, &UnknownDevice) == 0) { + // + // GUID used by EFI to enumerate an EDD 1.1 device + // + UnknownDevPath = (UNKNOWN_DEVICE_VENDOR_DEVICE_PATH *)Vendor; + CatPrint(Str, L":%02x)", UnknownDevPath->LegacyDriveLetter); + } else { + CatPrint(Str, L")"); + } +} + + +/* + Type: 2 (ACPI Device Path) SubType: 1 (ACPI Device Path) + */ +static VOID +_DevPathAcpi ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath + ) +{ + ACPI_HID_DEVICE_PATH *Acpi; + + Acpi = DevPath; + if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) { + switch ( EISA_ID_TO_NUM( Acpi-> HID ) ) { + case 0x301 : { + CatPrint( Str , L"Keyboard(%d)" , Acpi-> UID ) ; + break ; + } + case 0x401 : { + CatPrint( Str , L"ParallelPort(%d)" , Acpi-> UID ) ; + break ; + } + case 0x501 : { + CatPrint( Str , L"Serial(%d)" , Acpi-> UID ) ; + break ; + } + case 0x604 : { + CatPrint( Str , L"Floppy(%d)" , Acpi-> UID ) ; + break ; + } + case 0xa03 : { + CatPrint( Str , L"PciRoot(%d)" , Acpi-> UID ) ; + break ; + } + case 0xa08 : { + CatPrint( Str , L"PcieRoot(%d)" , Acpi-> UID ) ; + break ; + } + default : { + CatPrint( Str , L"Acpi(PNP%04x" , EISA_ID_TO_NUM( Acpi-> HID ) ) ; + if ( Acpi-> UID ) CatPrint( Str , L",%d" , Acpi-> UID ) ; + CatPrint( Str , L")" ) ; + break ; + } + } + } else { + CatPrint( Str , L"Acpi(0x%X" , Acpi-> HID ) ; + if ( Acpi-> UID ) CatPrint( Str , L",%d" , Acpi-> UID ) ; + CatPrint( Str , L")" , Acpi-> HID , Acpi-> UID ) ; + } +} + + +static VOID +_DevPathAtapi ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath + ) +{ + ATAPI_DEVICE_PATH *Atapi; + + Atapi = DevPath; + CatPrint(Str, L"Ata(%s,%s)", + Atapi->PrimarySecondary ? L"Secondary" : L"Primary", + Atapi->SlaveMaster ? L"Slave" : L"Master" + ); +} + +static VOID +_DevPathScsi ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath + ) +{ + SCSI_DEVICE_PATH *Scsi; + + Scsi = DevPath; + CatPrint(Str, L"Scsi(%d,%d)", Scsi->Pun, Scsi->Lun); +} + + +static VOID +_DevPathFibre ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath + ) +{ + FIBRECHANNEL_DEVICE_PATH *Fibre; + + Fibre = DevPath; + CatPrint( Str , L"Fibre%s(0x%016lx,0x%016lx)" , + DevicePathType( & Fibre-> Header ) == MSG_FIBRECHANNEL_DP ? L"" : L"Ex" , + Fibre-> WWN , Fibre-> Lun ) ; +} + +static VOID +_DevPath1394 ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath + ) +{ + F1394_DEVICE_PATH *F1394; + + F1394 = DevPath; + CatPrint(Str, L"1394(%g)", &F1394->Guid); +} + + + +static VOID +_DevPathUsb ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath + ) +{ + USB_DEVICE_PATH *Usb; + + Usb = DevPath; + CatPrint( Str , L"Usb(0x%x,0x%x)" , Usb-> Port , Usb-> Endpoint ) ; +} + + +static VOID +_DevPathI2O ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath + ) +{ + I2O_DEVICE_PATH *I2O; + + I2O = DevPath; + CatPrint(Str, L"I2O(0x%X)", I2O->Tid); +} + +static VOID +_DevPathMacAddr ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath + ) +{ + MAC_ADDR_DEVICE_PATH *MAC; + UINTN HwAddressSize; + UINTN Index; + + MAC = DevPath; + + /* HwAddressSize = sizeof(EFI_MAC_ADDRESS); */ + HwAddressSize = DevicePathNodeLength( & MAC-> Header ) ; + HwAddressSize -= sizeof( MAC-> Header ) ; + HwAddressSize -= sizeof( MAC-> IfType ) ; + if (MAC->IfType == 0x01 || MAC->IfType == 0x00) { + HwAddressSize = 6; + } + + CatPrint(Str, L"Mac("); + + for(Index = 0; Index < HwAddressSize; Index++) { + CatPrint(Str, L"%02x",MAC->MacAddress.Addr[Index]); + } + if ( MAC-> IfType != 0 ) { + CatPrint(Str, L",%d" , MAC-> IfType ) ; + } + CatPrint(Str, L")"); +} + +static VOID +CatPrintIPv4( + IN OUT POOL_PRINT * Str , + IN EFI_IPv4_ADDRESS * Address + ) +{ + CatPrint( Str , L"%d.%d.%d.%d" , Address-> Addr[ 0 ] , Address-> Addr[ 1 ] , + Address-> Addr[ 2 ] , Address-> Addr[ 3 ] ) ; +} + +static BOOLEAN +IsNotNullIPv4( + IN EFI_IPv4_ADDRESS * Address + ) +{ + UINT8 val ; + val = Address-> Addr[ 0 ] | Address-> Addr[ 1 ] ; + val |= Address-> Addr[ 2 ] | Address-> Addr[ 3 ] ; + return val != 0 ; +} + +static VOID +CatPrintNetworkProtocol( + IN OUT POOL_PRINT * Str , + IN UINT16 Proto + ) +{ + if ( Proto == 6 ) { + CatPrint( Str , L"TCP" ) ; + } else if ( Proto == 17 ) { + CatPrint( Str , L"UDP" ) ; + } else { + CatPrint( Str , L"%d" , Proto ) ; + } +} + +static VOID +_DevPathIPv4 ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath + ) +{ + IPv4_DEVICE_PATH *IP; + BOOLEAN show ; + + IP = DevPath; + CatPrint( Str , L"IPv4(") ; + CatPrintIPv4( Str , & IP-> RemoteIpAddress ) ; + CatPrint( Str , L",") ; + CatPrintNetworkProtocol( Str , IP-> Protocol ) ; + CatPrint( Str , L",%s" , IP-> StaticIpAddress ? L"Static" : L"DHCP" ) ; + show = IsNotNullIPv4( & IP-> LocalIpAddress ) ; + if ( ! show && DevicePathNodeLength( & IP-> Header ) == sizeof( IPv4_DEVICE_PATH ) ) { + /* only version 2 includes gateway and netmask */ + show |= IsNotNullIPv4( & IP-> GatewayIpAddress ) ; + show |= IsNotNullIPv4( & IP-> SubnetMask ) ; + } + if ( show ) { + CatPrint( Str , L"," ) ; + CatPrintIPv4( Str , & IP-> LocalIpAddress ) ; + if ( DevicePathNodeLength( & IP-> Header ) == sizeof( IPv4_DEVICE_PATH ) ) { + /* only version 2 includes gateway and netmask */ + show = IsNotNullIPv4( & IP-> GatewayIpAddress ) ; + show |= IsNotNullIPv4( & IP-> SubnetMask ) ; + if ( show ) { + CatPrint( Str , L",") ; + CatPrintIPv4( Str , & IP-> GatewayIpAddress ) ; + if ( IsNotNullIPv4( & IP-> SubnetMask ) ) { + CatPrint( Str , L",") ; + CatPrintIPv4( Str , & IP-> SubnetMask ) ; + } + } + } + } + CatPrint( Str , L")") ; +} + +#define CatPrintIPv6_ADD( x , y ) ( ( (UINT16) ( x ) ) << 8 | ( y ) ) +static VOID +CatPrintIPv6( + IN OUT POOL_PRINT * Str , + IN EFI_IPv6_ADDRESS * Address + ) +{ + CatPrint( Str , L"%x:%x:%x:%x:%x:%x:%x:%x" , + CatPrintIPv6_ADD( Address-> Addr[ 0 ] , Address-> Addr[ 1 ] ) , + CatPrintIPv6_ADD( Address-> Addr[ 2 ] , Address-> Addr[ 3 ] ) , + CatPrintIPv6_ADD( Address-> Addr[ 4 ] , Address-> Addr[ 5 ] ) , + CatPrintIPv6_ADD( Address-> Addr[ 6 ] , Address-> Addr[ 7 ] ) , + CatPrintIPv6_ADD( Address-> Addr[ 8 ] , Address-> Addr[ 9 ] ) , + CatPrintIPv6_ADD( Address-> Addr[ 10 ] , Address-> Addr[ 11 ] ) , + CatPrintIPv6_ADD( Address-> Addr[ 12 ] , Address-> Addr[ 13 ] ) , + CatPrintIPv6_ADD( Address-> Addr[ 14 ] , Address-> Addr[ 15 ] ) ) ; +} + +static VOID +_DevPathIPv6 ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath + ) +{ + IPv6_DEVICE_PATH *IP; + + IP = DevPath; + CatPrint( Str , L"IPv6(") ; + CatPrintIPv6( Str , & IP-> RemoteIpAddress ) ; + CatPrint( Str , L",") ; + CatPrintNetworkProtocol( Str, IP-> Protocol ) ; + CatPrint( Str , L",%s," , IP-> IPAddressOrigin ? + ( IP-> IPAddressOrigin == 1 ? L"StatelessAutoConfigure" : + L"StatefulAutoConfigure" ) : L"Static" ) ; + CatPrintIPv6( Str , & IP-> LocalIpAddress ) ; + if ( DevicePathNodeLength( & IP-> Header ) == sizeof( IPv6_DEVICE_PATH ) ) { + CatPrint( Str , L",") ; + CatPrintIPv6( Str , & IP-> GatewayIpAddress ) ; + CatPrint( Str , L",") ; + CatPrint( Str , L"%d" , & IP-> PrefixLength ) ; + } + CatPrint( Str , L")") ; +} + +static VOID +_DevPathUri ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath + ) +{ + URI_DEVICE_PATH *Uri; + + Uri = DevPath; + + CatPrint( Str, L"Uri(%a)", Uri->Uri ); +} + +static VOID +_DevPathInfiniBand ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath + ) +{ + INFINIBAND_DEVICE_PATH *InfiniBand; + + InfiniBand = DevPath; + CatPrint( Str , L"Infiniband(0x%x,%g,0x%lx,0x%lx,0x%lx)" , + InfiniBand-> ResourceFlags , InfiniBand-> PortGid , InfiniBand-> ServiceId , + InfiniBand-> TargetPortId , InfiniBand-> DeviceId ) ; +} + +static VOID +_DevPathUart ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath + ) +{ + UART_DEVICE_PATH *Uart; + CHAR8 Parity; + + Uart = DevPath; + switch (Uart->Parity) { + case 0 : Parity = 'D'; break; + case 1 : Parity = 'N'; break; + case 2 : Parity = 'E'; break; + case 3 : Parity = 'O'; break; + case 4 : Parity = 'M'; break; + case 5 : Parity = 'S'; break; + default : Parity = 'x'; break; + } + + if (Uart->BaudRate == 0) { + CatPrint(Str, L"Uart(DEFAULT %c",Uart->BaudRate,Parity); + } else { + CatPrint(Str, L"Uart(%d %c",Uart->BaudRate,Parity); + } + + if (Uart->DataBits == 0) { + CatPrint(Str, L"D"); + } else { + CatPrint(Str, L"%d",Uart->DataBits); + } + + switch (Uart->StopBits) { + case 0 : CatPrint(Str, L"D)"); break; + case 1 : CatPrint(Str, L"1)"); break; + case 2 : CatPrint(Str, L"1.5)"); break; + case 3 : CatPrint(Str, L"2)"); break; + default : CatPrint(Str, L"x)"); break; + } +} + +static VOID +_DevPathSata ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath + ) +{ + SATA_DEVICE_PATH * Sata ; + + Sata = DevPath; + CatPrint( Str , L"Sata(0x%x,0x%x,0x%x)" , Sata-> HBAPortNumber , + Sata-> PortMultiplierPortNumber , Sata-> Lun ) ; +} + +static VOID +_DevPathHardDrive ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath + ) +{ + HARDDRIVE_DEVICE_PATH *Hd; + + Hd = DevPath; + switch (Hd->SignatureType) { + case SIGNATURE_TYPE_MBR: + CatPrint(Str, L"HD(Part%d,Sig%08X)", + Hd->PartitionNumber, + *((UINT32 *)(&(Hd->Signature[0]))) + ); + break; + case SIGNATURE_TYPE_GUID: + CatPrint(Str, L"HD(Part%d,Sig%g)", + Hd->PartitionNumber, + (EFI_GUID *) &(Hd->Signature[0]) + ); + break; + default: + CatPrint(Str, L"HD(Part%d,MBRType=%02x,SigType=%02x)", + Hd->PartitionNumber, + Hd->MBRType, + Hd->SignatureType + ); + break; + } +} + +static VOID +_DevPathCDROM ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath + ) +{ + CDROM_DEVICE_PATH *Cd; + + Cd = DevPath; + CatPrint( Str , L"CDROM(0x%x)" , Cd-> BootEntry ) ; +} + +static VOID +_DevPathFilePath ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath + ) +{ + FILEPATH_DEVICE_PATH *Fp; + + Fp = DevPath; + CatPrint(Str, L"%s", Fp->PathName); +} + +static VOID +_DevPathMediaProtocol ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath + ) +{ + MEDIA_PROTOCOL_DEVICE_PATH *MediaProt; + + MediaProt = DevPath; + CatPrint(Str, L"%g", &MediaProt->Protocol); +} + +static VOID +_DevPathBssBss ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath + ) +{ + BBS_BBS_DEVICE_PATH *Bss; + CHAR16 *Type; + + Bss = DevPath; + switch (Bss->DeviceType) { + case BBS_TYPE_FLOPPY: Type = L"Floppy"; break; + case BBS_TYPE_HARDDRIVE: Type = L"Harddrive"; break; + case BBS_TYPE_CDROM: Type = L"CDROM"; break; + case BBS_TYPE_PCMCIA: Type = L"PCMCIA"; break; + case BBS_TYPE_USB: Type = L"Usb"; break; + case BBS_TYPE_EMBEDDED_NETWORK: Type = L"Net"; break; + default: Type = L"?"; break; + } + + CatPrint(Str, L"Bss-%s(%a)", Type, Bss->String); +} + + +static VOID +_DevPathEndInstance ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath EFI_UNUSED + ) +{ + CatPrint(Str, L","); +} + +/** + * Print unknown device node. + * UEFI 2.4 § 9.6.1.6 table 89. + */ + +static VOID +_DevPathNodeUnknown ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath + ) +{ + EFI_DEVICE_PATH * Path ; + UINT8 * value ; + int length , index ; + Path = DevPath ; + value = DevPath ; + value += 4 ; + switch ( Path-> Type ) { + case HARDWARE_DEVICE_PATH : { /* Unknown Hardware Device Path */ + CatPrint( Str , L"HardwarePath(%d" , Path-> SubType ) ; + break ; + } + case ACPI_DEVICE_PATH : { /* Unknown ACPI Device Path */ + CatPrint( Str , L"AcpiPath(%d" , Path-> SubType ) ; + break ; + } + case MESSAGING_DEVICE_PATH : { /* Unknown Messaging Device Path */ + CatPrint( Str , L"Msg(%d" , Path-> SubType ) ; + break ; + } + case MEDIA_DEVICE_PATH : { /* Unknown Media Device Path */ + CatPrint( Str , L"MediaPath(%d" , Path-> SubType ) ; + break ; + } + case BBS_DEVICE_PATH : { /* Unknown BIOS Boot Specification Device Path */ + CatPrint( Str , L"BbsPath(%d" , Path-> SubType ) ; + break ; + } + default : { /* Unknown Device Path */ + CatPrint( Str , L"Path(%d,%d" , Path-> Type , Path-> SubType ) ; + break ; + } + } + length = DevicePathNodeLength( Path ) ; + for ( index = 0 ; index < length ; index ++ ) { + if ( index == 0 ) CatPrint( Str , L",0x" ) ; + CatPrint( Str , L"%02x" , * value ) ; + value ++ ; + } + CatPrint( Str , L")" ) ; +} + + +/* + * Table to convert "Type" and "SubType" to a "convert to text" function/ + * Entries hold "Type" and "SubType" for know values. + * Special "SubType" 0 is used as default for known type with unknown subtype. + */ +struct { + UINT8 Type; + UINT8 SubType; + VOID (*Function)(POOL_PRINT *, VOID *); +} DevPathTable[] = { + { HARDWARE_DEVICE_PATH, HW_PCI_DP, _DevPathPci}, + { HARDWARE_DEVICE_PATH, HW_PCCARD_DP, _DevPathPccard}, + { HARDWARE_DEVICE_PATH, HW_MEMMAP_DP, _DevPathMemMap}, + { HARDWARE_DEVICE_PATH, HW_VENDOR_DP, _DevPathVendor}, + { HARDWARE_DEVICE_PATH, HW_CONTROLLER_DP, _DevPathController}, + { ACPI_DEVICE_PATH, ACPI_DP, _DevPathAcpi}, + { MESSAGING_DEVICE_PATH, MSG_ATAPI_DP, _DevPathAtapi}, + { MESSAGING_DEVICE_PATH, MSG_SCSI_DP, _DevPathScsi}, + { MESSAGING_DEVICE_PATH, MSG_FIBRECHANNEL_DP, _DevPathFibre}, + { MESSAGING_DEVICE_PATH, MSG_1394_DP, _DevPath1394}, + { MESSAGING_DEVICE_PATH, MSG_USB_DP, _DevPathUsb}, + { MESSAGING_DEVICE_PATH, MSG_I2O_DP, _DevPathI2O}, + { MESSAGING_DEVICE_PATH, MSG_MAC_ADDR_DP, _DevPathMacAddr}, + { MESSAGING_DEVICE_PATH, MSG_IPv4_DP, _DevPathIPv4}, + { MESSAGING_DEVICE_PATH, MSG_IPv6_DP, _DevPathIPv6}, + { MESSAGING_DEVICE_PATH, MSG_URI_DP, _DevPathUri}, + { MESSAGING_DEVICE_PATH, MSG_INFINIBAND_DP, _DevPathInfiniBand}, + { MESSAGING_DEVICE_PATH, MSG_UART_DP, _DevPathUart}, + { MESSAGING_DEVICE_PATH , MSG_SATA_DP , _DevPathSata } , + { MESSAGING_DEVICE_PATH, MSG_VENDOR_DP, _DevPathVendor}, + { MEDIA_DEVICE_PATH, MEDIA_HARDDRIVE_DP, _DevPathHardDrive}, + { MEDIA_DEVICE_PATH, MEDIA_CDROM_DP, _DevPathCDROM}, + { MEDIA_DEVICE_PATH, MEDIA_VENDOR_DP, _DevPathVendor}, + { MEDIA_DEVICE_PATH, MEDIA_FILEPATH_DP, _DevPathFilePath}, + { MEDIA_DEVICE_PATH, MEDIA_PROTOCOL_DP, _DevPathMediaProtocol}, + { BBS_DEVICE_PATH, BBS_BBS_DP, _DevPathBssBss}, + { END_DEVICE_PATH_TYPE, END_INSTANCE_DEVICE_PATH_SUBTYPE, _DevPathEndInstance}, + { 0, 0, NULL} +}; + + +CHAR16 * +DevicePathToStr ( + EFI_DEVICE_PATH *DevPath + ) +/*++ + + Turns the Device Path into a printable string. Allcoates + the string from pool. The caller must FreePool the returned + string. + +--*/ +{ + POOL_PRINT Str; + EFI_DEVICE_PATH *DevPathNode; + VOID (*DumpNode)(POOL_PRINT *, VOID *); + UINTN Index, NewSize; + + ZeroMem(&Str, sizeof(Str)); + + // + // Unpacked the device path + // + + DevPath = UnpackDevicePath(DevPath); + ASSERT (DevPath); + + + // + // Process each device path node + // + + DevPathNode = DevPath; + while (!IsDevicePathEnd(DevPathNode)) { + // + // Find the handler to dump this device path node + // + + DumpNode = NULL; + for (Index = 0; DevPathTable[Index].Function; Index += 1) { + + if (DevicePathType(DevPathNode) == DevPathTable[Index].Type && + DevicePathSubType(DevPathNode) == DevPathTable[Index].SubType) { + DumpNode = DevPathTable[Index].Function; + break; + } + } + + // + // If not found, use a generic function + // + + if (!DumpNode) { + DumpNode = _DevPathNodeUnknown; + } + + // + // Put a path seperator in if needed + // + + if (Str.len && DumpNode != _DevPathEndInstance) { + CatPrint (&Str, L"/"); + } + + // + // Print this node of the device path + // + + DumpNode (&Str, DevPathNode); + + // + // Next device path node + // + + DevPathNode = NextDevicePathNode(DevPathNode); + } + + // + // Shrink pool used for string allocation + // + + FreePool (DevPath); + NewSize = (Str.len + 1) * sizeof(CHAR16); + Str.str = ReallocatePool (Str.str, NewSize, NewSize); + Str.str[Str.len] = 0; + return Str.str; +} + +BOOLEAN +LibMatchDevicePaths ( + IN EFI_DEVICE_PATH *Multi, + IN EFI_DEVICE_PATH *Single + ) +{ + EFI_DEVICE_PATH *DevicePath, *DevicePathInst; + UINTN Size; + + if (!Multi || !Single) { + return FALSE; + } + + DevicePath = Multi; + while ((DevicePathInst = DevicePathInstance (&DevicePath, &Size))) { + if (CompareMem (Single, DevicePathInst, Size) == 0) { + return TRUE; + } + } + return FALSE; +} + +EFI_DEVICE_PATH * +LibDuplicateDevicePathInstance ( + IN EFI_DEVICE_PATH *DevPath + ) +{ + EFI_DEVICE_PATH *NewDevPath,*DevicePathInst,*Temp; + UINTN Size = 0; + + // + // get the size of an instance from the input + // + + Temp = DevPath; + DevicePathInst = DevicePathInstance (&Temp, &Size); + + // + // Make a copy and set proper end type + // + NewDevPath = NULL; + if (Size) { + NewDevPath = AllocatePool (Size + sizeof(EFI_DEVICE_PATH)); + } + + if (NewDevPath) { + CopyMem (NewDevPath, DevicePathInst, Size); + Temp = NextDevicePathNode(NewDevPath); + SetDevicePathEndNode(Temp); + } + + return NewDevPath; +} + diff --git a/gnu-efi/lib/error.c b/gnu-efi/lib/error.c new file mode 100644 index 0000000..3a856a6 --- /dev/null +++ b/gnu-efi/lib/error.c @@ -0,0 +1,83 @@ +/*++ + +Copyright (c) 1998 Intel Corporation + +Module Name: + + error.c + +Abstract: + + + + +Revision History + +--*/ + +#include "lib.h" + + +struct { + EFI_STATUS Code; + WCHAR *Desc; +} ErrorCodeTable[] = { + { EFI_SUCCESS, L"Success"}, + { EFI_LOAD_ERROR, L"Load Error"}, + { EFI_INVALID_PARAMETER, L"Invalid Parameter"}, + { EFI_UNSUPPORTED, L"Unsupported"}, + { EFI_BAD_BUFFER_SIZE, L"Bad Buffer Size"}, + { EFI_BUFFER_TOO_SMALL, L"Buffer Too Small"}, + { EFI_NOT_READY, L"Not Ready"}, + { EFI_DEVICE_ERROR, L"Device Error"}, + { EFI_WRITE_PROTECTED, L"Write Protected"}, + { EFI_OUT_OF_RESOURCES, L"Out of Resources"}, + { EFI_VOLUME_CORRUPTED, L"Volume Corrupt"}, + { EFI_VOLUME_FULL, L"Volume Full"}, + { EFI_NO_MEDIA, L"No Media"}, + { EFI_MEDIA_CHANGED, L"Media changed"}, + { EFI_NOT_FOUND, L"Not Found"}, + { EFI_ACCESS_DENIED, L"Access Denied"}, + { EFI_NO_RESPONSE, L"No Response"}, + { EFI_NO_MAPPING, L"No mapping"}, + { EFI_TIMEOUT, L"Time out"}, + { EFI_NOT_STARTED, L"Not started"}, + { EFI_ALREADY_STARTED, L"Already started"}, + { EFI_ABORTED, L"Aborted"}, + { EFI_ICMP_ERROR, L"ICMP Error"}, + { EFI_TFTP_ERROR, L"TFTP Error"}, + { EFI_PROTOCOL_ERROR, L"Protocol Error"}, + { EFI_INCOMPATIBLE_VERSION, L"Incompatible Version"}, + { EFI_SECURITY_VIOLATION, L"Security Policy Violation"}, + { EFI_CRC_ERROR, L"CRC Error"}, + { EFI_END_OF_MEDIA, L"End of Media"}, + { EFI_END_OF_FILE, L"End of File"}, + { EFI_INVALID_LANGUAGE, L"Invalid Languages"}, + { EFI_COMPROMISED_DATA, L"Compromised Data"}, + + // warnings + { EFI_WARN_UNKOWN_GLYPH, L"Warning Unknown Glyph"}, + { EFI_WARN_DELETE_FAILURE, L"Warning Delete Failure"}, + { EFI_WARN_WRITE_FAILURE, L"Warning Write Failure"}, + { EFI_WARN_BUFFER_TOO_SMALL, L"Warning Buffer Too Small"}, + { 0, NULL} +} ; + + +VOID +StatusToString ( + OUT CHAR16 *Buffer, + IN EFI_STATUS Status + ) +{ + UINTN Index; + + for (Index = 0; ErrorCodeTable[Index].Desc; Index +=1) { + if (ErrorCodeTable[Index].Code == Status) { + StrCpy (Buffer, ErrorCodeTable[Index].Desc); + return; + } + } + + SPrint (Buffer, 0, L"%X", Status); +} diff --git a/gnu-efi/lib/event.c b/gnu-efi/lib/event.c new file mode 100644 index 0000000..0babc92 --- /dev/null +++ b/gnu-efi/lib/event.c @@ -0,0 +1,154 @@ +/*++ + +Copyright (c) 1998 Intel Corporation + +Module Name: + + event.c + +Abstract: + + + + +Revision History + +--*/ + +#include "lib.h" + + +EFI_EVENT +LibCreateProtocolNotifyEvent ( + IN EFI_GUID *ProtocolGuid, + IN EFI_TPL NotifyTpl, + IN EFI_EVENT_NOTIFY NotifyFunction, + IN VOID *NotifyContext, + OUT VOID *Registration + ) +{ + EFI_STATUS Status; + EFI_EVENT Event; + + // + // Create the event + // + + Status = uefi_call_wrapper( + BS->CreateEvent, + 5, + EVT_NOTIFY_SIGNAL, + NotifyTpl, + NotifyFunction, + NotifyContext, + &Event + ); + if ( EFI_ERROR( Status ) ) return NULL ; + ASSERT (!EFI_ERROR(Status)); + + // + // Register for protocol notifactions on this event + // + + Status = uefi_call_wrapper( + BS->RegisterProtocolNotify, + 3, + ProtocolGuid, + Event, + Registration + ); + if ( EFI_ERROR( Status ) ) return NULL ; + ASSERT (!EFI_ERROR(Status)); + + // + // Kick the event so we will perform an initial pass of + // current installed drivers + // + + uefi_call_wrapper(BS->SignalEvent, 1, Event); + return Event; +} + + +EFI_STATUS +WaitForSingleEvent ( + IN EFI_EVENT Event, + IN UINT64 Timeout OPTIONAL + ) +{ + EFI_STATUS Status; + UINTN Index; + EFI_EVENT TimerEvent; + EFI_EVENT WaitList[2]; + + if (Timeout) { + // + // Create a timer event + // + + Status = uefi_call_wrapper(BS->CreateEvent, 5, EVT_TIMER, 0, NULL, NULL, &TimerEvent); + if (!EFI_ERROR(Status)) { + + // + // Set the timer event + // + + uefi_call_wrapper(BS->SetTimer, 3, TimerEvent, TimerRelative, Timeout); + + // + // Wait for the original event or the timer + // + + WaitList[0] = Event; + WaitList[1] = TimerEvent; + Status = uefi_call_wrapper(BS->WaitForEvent, 3, 2, WaitList, &Index); + uefi_call_wrapper(BS->CloseEvent, 1, TimerEvent); + + // + // If the timer expired, change the return to timed out + // + + if (!EFI_ERROR(Status) && Index == 1) { + Status = EFI_TIMEOUT; + } + } + + } else { + + // + // No timeout... just wait on the event + // + + Status = uefi_call_wrapper(BS->WaitForEvent, 3, 1, &Event, &Index); + ASSERT (!EFI_ERROR(Status)); + ASSERT (Index == 0); + } + + return Status; +} + +VOID +WaitForEventWithTimeout ( + IN EFI_EVENT Event, + IN UINTN Timeout, + IN UINTN Row, + IN UINTN Column, + IN CHAR16 *String, + IN EFI_INPUT_KEY TimeoutKey, + OUT EFI_INPUT_KEY *Key + ) +{ + EFI_STATUS Status; + + do { + PrintAt (Column, Row, String, Timeout); + Status = WaitForSingleEvent (Event, 10000000); + if (Status == EFI_SUCCESS) { + if (!EFI_ERROR(uefi_call_wrapper(ST->ConIn->ReadKeyStroke, 2, ST->ConIn, Key))) { + return; + } + } + } while (Timeout > 0); + CopyMem(Key, &TimeoutKey, sizeof(EFI_INPUT_KEY)); +} + diff --git a/gnu-efi/lib/exit.c b/gnu-efi/lib/exit.c new file mode 100644 index 0000000..ada27c9 --- /dev/null +++ b/gnu-efi/lib/exit.c @@ -0,0 +1,19 @@ +#include "lib.h" + +VOID +Exit( + IN EFI_STATUS ExitStatus, + IN UINTN ExitDataSize, + IN CHAR16 *ExitData OPTIONAL + ) +{ + uefi_call_wrapper(BS->Exit, + 4, + LibImageHandle, + ExitStatus, + ExitDataSize, + ExitData); + + // Uh oh, Exit() returned?! + for (;;) { } +} diff --git a/gnu-efi/lib/guid.c b/gnu-efi/lib/guid.c new file mode 100644 index 0000000..6498e90 --- /dev/null +++ b/gnu-efi/lib/guid.c @@ -0,0 +1,179 @@ +/*++ + +Copyright (c) 1998 Intel Corporation + +Module Name: + + misc.c + +Abstract: + + Misc EFI support functions + + + +Revision History + +--*/ + +#include "lib.h" + + +// +// Additional Known guids +// + +#define SHELL_INTERFACE_PROTOCOL \ + { 0x47c7b223, 0xc42a, 0x11d2, {0x8e, 0x57, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b} } + +#define ENVIRONMENT_VARIABLE_ID \ + { 0x47c7b224, 0xc42a, 0x11d2, {0x8e, 0x57, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b} } + +#define DEVICE_PATH_MAPPING_ID \ + { 0x47c7b225, 0xc42a, 0x11d2, {0x8e, 0x57, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b} } + +#define PROTOCOL_ID_ID \ + { 0x47c7b226, 0xc42a, 0x11d2, {0x8e, 0x57, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b} } + +#define ALIAS_ID \ + { 0x47c7b227, 0xc42a, 0x11d2, {0x8e, 0x57, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b} } + +static EFI_GUID ShellInterfaceProtocol = SHELL_INTERFACE_PROTOCOL; +static EFI_GUID SEnvId = ENVIRONMENT_VARIABLE_ID; +static EFI_GUID SMapId = DEVICE_PATH_MAPPING_ID; +static EFI_GUID SProtId = PROTOCOL_ID_ID; +static EFI_GUID SAliasId = ALIAS_ID; + +static struct { + EFI_GUID *Guid; + WCHAR *GuidName; +} KnownGuids[] = { + { &NullGuid, L"G0" }, + { &gEfiGlobalVariableGuid, L"EfiVar" }, + + { &VariableStoreProtocol, L"VarStore" }, + { &gEfiDevicePathProtocolGuid, L"DevPath" }, + { &gEfiLoadedImageProtocolGuid, L"LdImg" }, + { &gEfiSimpleTextInProtocolGuid, L"TxtIn" }, + { &gEfiSimpleTextOutProtocolGuid, L"TxtOut" }, + { &gEfiBlockIoProtocolGuid, L"BlkIo" }, + { &gEfiBlockIo2ProtocolGuid, L"BlkIo2" }, + { &gEfiDiskIoProtocolGuid, L"DskIo" }, + { &gEfiDiskIo2ProtocolGuid, L"DskIo2" }, + { &gEfiSimpleFileSystemProtocolGuid, L"Fs" }, + { &gEfiLoadFileProtocolGuid, L"LdFile" }, + { &gEfiDeviceIoProtocolGuid, L"DevIo" }, + { &gEfiComponentNameProtocolGuid, L"CName" }, + { &gEfiComponentName2ProtocolGuid, L"CName2" }, + + { &gEfiFileInfoGuid, L"FileInfo" }, + { &gEfiFileSystemInfoGuid, L"FsInfo" }, + { &gEfiFileSystemVolumeLabelInfoIdGuid, L"FsVolInfo" }, + + { &gEfiUnicodeCollationProtocolGuid, L"Unicode" }, + { &LegacyBootProtocol, L"LegacyBoot" }, + { &gEfiSerialIoProtocolGuid, L"SerIo" }, + { &VgaClassProtocol, L"VgaClass"}, + { &gEfiSimpleNetworkProtocolGuid, L"Net" }, + { &gEfiNetworkInterfaceIdentifierProtocolGuid, L"Nii" }, + { &gEfiPxeBaseCodeProtocolGuid, L"Pxe" }, + { &gEfiPxeBaseCodeCallbackProtocolGuid, L"PxeCb" }, + + { &TextOutSpliterProtocol, L"TxtOutSplit" }, + { &ErrorOutSpliterProtocol, L"ErrOutSplit" }, + { &TextInSpliterProtocol, L"TxtInSplit" }, + { &gEfiPcAnsiGuid, L"PcAnsi" }, + { &gEfiVT100Guid, L"Vt100" }, + { &gEfiVT100PlusGuid, L"Vt100Plus" }, + { &gEfiVTUTF8Guid, L"VtUtf8" }, + { &UnknownDevice, L"UnknownDev" }, + + { &EfiPartTypeSystemPartitionGuid, L"ESP" }, + { &EfiPartTypeLegacyMbrGuid, L"GPT MBR" }, + + { &ShellInterfaceProtocol, L"ShellInt" }, + { &SEnvId, L"SEnv" }, + { &SProtId, L"ShellProtId" }, + { &SMapId, L"ShellDevPathMap" }, + { &SAliasId, L"ShellAlias" }, + + { NULL, L"" } +}; + +// +// +// + +LIST_ENTRY GuidList; + + +VOID +InitializeGuid ( + VOID + ) +{ +} + +INTN +CompareGuid( + IN EFI_GUID *Guid1, + IN EFI_GUID *Guid2 + ) +/*++ + +Routine Description: + + Compares to GUIDs + +Arguments: + + Guid1 - guid to compare + Guid2 - guid to compare + +Returns: + = 0 if Guid1 == Guid2 + +--*/ +{ + return RtCompareGuid (Guid1, Guid2); +} + + +VOID +GuidToString ( + OUT CHAR16 *Buffer, + IN EFI_GUID *Guid + ) +{ + + UINTN Index; + + // + // Else, (for now) use additional internal function for mapping guids + // + + for (Index=0; KnownGuids[Index].Guid; Index++) { + if (CompareGuid(Guid, KnownGuids[Index].Guid) == 0) { + SPrint (Buffer, 0, KnownGuids[Index].GuidName); + return ; + } + } + + // + // Else dump it + // + + SPrint (Buffer, 0, L"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", + Guid->Data1, + Guid->Data2, + Guid->Data3, + Guid->Data4[0], + Guid->Data4[1], + Guid->Data4[2], + Guid->Data4[3], + Guid->Data4[4], + Guid->Data4[5], + Guid->Data4[6], + Guid->Data4[7] + ); +} diff --git a/gnu-efi/lib/hand.c b/gnu-efi/lib/hand.c new file mode 100644 index 0000000..6864765 --- /dev/null +++ b/gnu-efi/lib/hand.c @@ -0,0 +1,636 @@ +/*++ + +Copyright (c) 1998 Intel Corporation + +Module Name: + + hand.c + +Abstract: + + + + +Revision History + +--*/ + +#include "lib.h" +#include "efistdarg.h" // !!! + + +EFI_STATUS +LibLocateProtocol ( + IN EFI_GUID *ProtocolGuid, + OUT VOID **Interface + ) +// +// Find the first instance of this Protocol in the system and return it's interface +// +{ + EFI_STATUS Status; + UINTN NumberHandles, Index; + EFI_HANDLE *Handles; + + + *Interface = NULL; + Status = LibLocateHandle (ByProtocol, ProtocolGuid, NULL, &NumberHandles, &Handles); + if (EFI_ERROR(Status)) { + DEBUG((D_INFO, "LibLocateProtocol: Handle not found\n")); + return Status; + } + + for (Index=0; Index < NumberHandles; Index++) { + Status = uefi_call_wrapper(BS->HandleProtocol, 3, Handles[Index], ProtocolGuid, Interface); + if (!EFI_ERROR(Status)) { + break; + } + } + + if (Handles) { + FreePool (Handles); + } + + return Status; +} + +EFI_STATUS +LibLocateHandle ( + IN EFI_LOCATE_SEARCH_TYPE SearchType, + IN EFI_GUID *Protocol OPTIONAL, + IN VOID *SearchKey OPTIONAL, + IN OUT UINTN *NoHandles, + OUT EFI_HANDLE **Buffer + ) + +{ + EFI_STATUS Status; + UINTN BufferSize; + + // + // Initialize for GrowBuffer loop + // + + Status = EFI_SUCCESS; + *Buffer = NULL; + BufferSize = 50 * sizeof(EFI_HANDLE); + + // + // Call the real function + // + + while (GrowBuffer (&Status, (VOID **) Buffer, BufferSize)) { + + Status = uefi_call_wrapper( + BS->LocateHandle, + 5, + SearchType, + Protocol, + SearchKey, + &BufferSize, + *Buffer + ); + + } + + *NoHandles = BufferSize / sizeof (EFI_HANDLE); + if (EFI_ERROR(Status)) { + *NoHandles = 0; + } + + return Status; +} + +EFI_STATUS +LibLocateHandleByDiskSignature ( + IN UINT8 MBRType, + IN UINT8 SignatureType, + IN VOID *Signature, + IN OUT UINTN *NoHandles, + OUT EFI_HANDLE **Buffer + ) + +{ + EFI_STATUS Status; + UINTN BufferSize; + UINTN NoBlockIoHandles; + EFI_HANDLE *BlockIoBuffer; + EFI_DEVICE_PATH *DevicePath; + UINTN Index; + EFI_DEVICE_PATH *Next, *DevPath; + HARDDRIVE_DEVICE_PATH *HardDriveDevicePath; + BOOLEAN Match; + BOOLEAN PreviousNodeIsHardDriveDevicePath; + + // + // Initialize for GrowBuffer loop + // + + Status = EFI_SUCCESS; + BlockIoBuffer = NULL; + BufferSize = 50 * sizeof(EFI_HANDLE); + + // + // Call the real function + // + + while (GrowBuffer (&Status, (VOID **)&BlockIoBuffer, BufferSize)) { + + // + // Get list of device handles that support the BLOCK_IO Protocol. + // + + Status = uefi_call_wrapper( + BS->LocateHandle, + 5, + ByProtocol, + &BlockIoProtocol, + NULL, + &BufferSize, + BlockIoBuffer + ); + + } + + NoBlockIoHandles = BufferSize / sizeof (EFI_HANDLE); + if (EFI_ERROR(Status)) { + NoBlockIoHandles = 0; + } + + // + // If there was an error or there are no device handles that support + // the BLOCK_IO Protocol, then return. + // + + if (NoBlockIoHandles == 0) { + FreePool(BlockIoBuffer); + *NoHandles = 0; + *Buffer = NULL; + return Status; + } + + // + // Loop through all the device handles that support the BLOCK_IO Protocol + // + + *NoHandles = 0; + + for(Index=0;IndexHandleProtocol, + 3, + BlockIoBuffer[Index], + &DevicePathProtocol, + (VOID*)&DevicePath + ); + + // + // Search DevicePath for a Hard Drive Media Device Path node. + // If one is found, then see if it matches the signature that was + // passed in. If it does match, and the next node is the End of the + // device path, and the previous node is not a Hard Drive Media Device + // Path, then we have found a match. + // + + Match = FALSE; + + if (DevicePath != NULL) { + + PreviousNodeIsHardDriveDevicePath = FALSE; + + DevPath = DevicePath; + + // + // Check for end of device path type + // + + for (; ;) { + + if ((DevicePathType(DevPath) == MEDIA_DEVICE_PATH) && + (DevicePathSubType(DevPath) == MEDIA_HARDDRIVE_DP)) { + + HardDriveDevicePath = (HARDDRIVE_DEVICE_PATH *)(DevPath); + + if (PreviousNodeIsHardDriveDevicePath == FALSE) { + + Next = NextDevicePathNode(DevPath); + if (IsDevicePathEndType(Next)) { + if ((HardDriveDevicePath->MBRType == MBRType) && + (HardDriveDevicePath->SignatureType == SignatureType)) { + switch(SignatureType) { + case SIGNATURE_TYPE_MBR: + if (*((UINT32 *)(Signature)) == *(UINT32 *)(&(HardDriveDevicePath->Signature[0]))) { + Match = TRUE; + } + break; + case SIGNATURE_TYPE_GUID: + if (CompareGuid((EFI_GUID *)Signature,(EFI_GUID *)(&(HardDriveDevicePath->Signature[0]))) == 0) { + Match = TRUE; + } + break; + } + } + } + } + PreviousNodeIsHardDriveDevicePath = TRUE; + } else { + PreviousNodeIsHardDriveDevicePath = FALSE; + } + + if (IsDevicePathEnd(DevPath)) { + break; + } + + DevPath = NextDevicePathNode(DevPath); + } + + } + + if (Match == FALSE) { + BlockIoBuffer[Index] = NULL; + } else { + *NoHandles = *NoHandles + 1; + } + } + + // + // If there are no matches, then return + // + + if (*NoHandles == 0) { + FreePool(BlockIoBuffer); + *NoHandles = 0; + *Buffer = NULL; + return EFI_SUCCESS; + } + + // + // Allocate space for the return buffer of device handles. + // + + *Buffer = AllocatePool(*NoHandles * sizeof(EFI_HANDLE)); + + if (*Buffer == NULL) { + FreePool(BlockIoBuffer); + *NoHandles = 0; + *Buffer = NULL; + return EFI_OUT_OF_RESOURCES; + } + + // + // Build list of matching device handles. + // + + *NoHandles = 0; + for(Index=0;IndexHandleProtocol, 3, DeviceHandle, &FileSystemProtocol, (VOID*)&Volume); + + // + // Open the root directory of the volume + // + + if (!EFI_ERROR(Status)) { + Status = uefi_call_wrapper(Volume->OpenVolume, 2, Volume, &File); + } + + // + // Done + // + + return EFI_ERROR(Status) ? NULL : File; +} + +EFI_FILE_INFO * +LibFileInfo ( + IN EFI_FILE_HANDLE FHand + ) +{ + EFI_STATUS Status; + EFI_FILE_INFO *Buffer; + UINTN BufferSize; + + // + // Initialize for GrowBuffer loop + // + + Status = EFI_SUCCESS; + Buffer = NULL; + BufferSize = SIZE_OF_EFI_FILE_INFO + 200; + + // + // Call the real function + // + + while (GrowBuffer (&Status, (VOID **) &Buffer, BufferSize)) { + Status = uefi_call_wrapper( + FHand->GetInfo, + 4, + FHand, + &GenericFileInfo, + &BufferSize, + Buffer + ); + } + + return Buffer; +} + + +EFI_FILE_SYSTEM_INFO * +LibFileSystemInfo ( + IN EFI_FILE_HANDLE FHand + ) +{ + EFI_STATUS Status; + EFI_FILE_SYSTEM_INFO *Buffer; + UINTN BufferSize; + + // + // Initialize for GrowBuffer loop + // + + Status = EFI_SUCCESS; + Buffer = NULL; + BufferSize = SIZE_OF_EFI_FILE_SYSTEM_INFO + 200; + + // + // Call the real function + // + + while (GrowBuffer (&Status, (VOID **) &Buffer, BufferSize)) { + Status = uefi_call_wrapper( + FHand->GetInfo, + 4, + FHand, + &FileSystemInfo, + &BufferSize, + Buffer + ); + } + + return Buffer; +} + +EFI_FILE_SYSTEM_VOLUME_LABEL_INFO * +LibFileSystemVolumeLabelInfo ( + IN EFI_FILE_HANDLE FHand + ) +{ + EFI_STATUS Status; + EFI_FILE_SYSTEM_VOLUME_LABEL_INFO *Buffer; + UINTN BufferSize; + + // + // Initialize for GrowBuffer loop + // + + Status = EFI_SUCCESS; + Buffer = NULL; + BufferSize = SIZE_OF_EFI_FILE_SYSTEM_VOLUME_LABEL_INFO + 200; + + // + // Call the real function + // + + while (GrowBuffer (&Status, (VOID **) &Buffer, BufferSize)) { + Status = uefi_call_wrapper( + FHand->GetInfo, + 4, + FHand, + &FileSystemVolumeLabelInfo, + &BufferSize, + Buffer + ); + } + + return Buffer; +} + + + +EFI_STATUS +LibInstallProtocolInterfaces ( + IN OUT EFI_HANDLE *Handle, + ... + ) +{ + va_list args; + EFI_STATUS Status; + EFI_GUID *Protocol; + VOID *Interface; + EFI_TPL OldTpl; + UINTN Index; + EFI_HANDLE OldHandle; + + // + // Syncronize with notifcations + // + + OldTpl = uefi_call_wrapper(BS->RaiseTPL, 1, TPL_NOTIFY); + OldHandle = *Handle; + + // + // Install the protocol interfaces + // + + Index = 0; + Status = EFI_SUCCESS; + va_start (args, Handle); + + while (!EFI_ERROR(Status)) { + + // + // If protocol is NULL, then it's the end of the list + // + + Protocol = va_arg(args, EFI_GUID *); + if (!Protocol) { + break; + } + + Interface = va_arg(args, VOID *); + + // + // Install it + // + + DEBUG((D_INFO, "LibInstallProtocolInterface: %d %x\n", Protocol, Interface)); + Status = uefi_call_wrapper(BS->InstallProtocolInterface, 4, Handle, Protocol, EFI_NATIVE_INTERFACE, Interface); + if (EFI_ERROR(Status)) { + break; + } + + Index += 1; + } + + // + // If there was an error, remove all the interfaces that were + // installed without any errors + // + + if (EFI_ERROR(Status)) { + va_start (args, Handle); + while (Index) { + + Protocol = va_arg(args, EFI_GUID *); + Interface = va_arg(args, VOID *); + uefi_call_wrapper(BS->UninstallProtocolInterface, 3, *Handle, Protocol, Interface); + + Index -= 1; + } + + *Handle = OldHandle; + } + + // + // Done + // + + uefi_call_wrapper(BS->RestoreTPL, 1, OldTpl); + return Status; +} + + +VOID +LibUninstallProtocolInterfaces ( + IN EFI_HANDLE Handle, + ... + ) +{ + va_list args; + EFI_STATUS Status; + EFI_GUID *Protocol; + VOID *Interface; + + + va_start (args, Handle); + for (; ;) { + + // + // If protocol is NULL, then it's the end of the list + // + + Protocol = va_arg(args, EFI_GUID *); + if (!Protocol) { + break; + } + + Interface = va_arg(args, VOID *); + + // + // Uninstall it + // + + Status = uefi_call_wrapper(BS->UninstallProtocolInterface, 3, Handle, Protocol, Interface); + if (EFI_ERROR(Status)) { + DEBUG((D_ERROR, "LibUninstallProtocolInterfaces: failed %g, %r\n", Protocol, Handle)); + } + } +} + + +EFI_STATUS +LibReinstallProtocolInterfaces ( + IN OUT EFI_HANDLE *Handle, + ... + ) +{ + va_list args; + EFI_STATUS Status; + EFI_GUID *Protocol; + VOID *OldInterface, *NewInterface; + EFI_TPL OldTpl; + UINTN Index; + + // + // Syncronize with notifcations + // + + OldTpl = uefi_call_wrapper(BS->RaiseTPL, 1, TPL_NOTIFY); + + // + // Install the protocol interfaces + // + + Index = 0; + Status = EFI_SUCCESS; + va_start (args, Handle); + + while (!EFI_ERROR(Status)) { + + // + // If protocol is NULL, then it's the end of the list + // + + Protocol = va_arg(args, EFI_GUID *); + if (!Protocol) { + break; + } + + OldInterface = va_arg(args, VOID *); + NewInterface = va_arg(args, VOID *); + + // + // Reinstall it + // + + Status = uefi_call_wrapper(BS->ReinstallProtocolInterface, 4, Handle, Protocol, OldInterface, NewInterface); + if (EFI_ERROR(Status)) { + break; + } + + Index += 1; + } + + // + // If there was an error, undo all the interfaces that were + // reinstalled without any errors + // + + if (EFI_ERROR(Status)) { + va_start (args, Handle); + while (Index) { + + Protocol = va_arg(args, EFI_GUID *); + OldInterface = va_arg(args, VOID *); + NewInterface = va_arg(args, VOID *); + + uefi_call_wrapper(BS->ReinstallProtocolInterface, 4, Handle, Protocol, NewInterface, OldInterface); + + Index -= 1; + } + } + + // + // Done + // + + uefi_call_wrapper(BS->RestoreTPL, 1, OldTpl); + return Status; +} diff --git a/gnu-efi/lib/hw.c b/gnu-efi/lib/hw.c new file mode 100644 index 0000000..09a77f9 --- /dev/null +++ b/gnu-efi/lib/hw.c @@ -0,0 +1,132 @@ +/*++ + +Copyright (c) 1998 Intel Corporation + +Module Name: + + hw.c + +Abstract: + + Debug library functions for Hardware IO access + + + +Revision History + +--*/ + +#include "lib.h" + + +EFI_STATUS +InitializeGlobalIoDevice ( + IN EFI_DEVICE_PATH *DevicePath, + IN EFI_GUID *Protocol, + IN CHAR8 *ErrorStr EFI_UNUSED, + OUT EFI_DEVICE_IO_INTERFACE **GlobalIoFncs + ) +/*++ + +Routine Description: + + Check to see if DevicePath exists for a given Protocol. Return Error if it + exists. Return GlobalIoFuncs set match the DevicePath + + Arguments: + + DevicePath - to operate on + Protocol - to check the DevicePath against + ErrorStr - ASCII string to display on error + GlobalIoFncs - Returned with DeviceIoProtocol for the DevicePath + +Returns: + + Pass or Fail based on wether GlobalIoFncs where found + +--*/ +{ + EFI_STATUS Status; + EFI_HANDLE Handle; + + // + // Check to see if this device path already has Protocol on it. + // if so we are loading recursivly and should exit with an error + // + Status = uefi_call_wrapper(BS->LocateDevicePath, 3, Protocol, &DevicePath, &Handle); + if (!EFI_ERROR(Status)) { + DEBUG ((D_INIT, "Device Already Loaded for %a device\n", ErrorStr)); + return EFI_LOAD_ERROR; + } + + Status = uefi_call_wrapper(BS->LocateDevicePath, 3, &DeviceIoProtocol, &DevicePath, &Handle); + if (!EFI_ERROR(Status)) { + Status = uefi_call_wrapper(BS->HandleProtocol, 3, Handle, &DeviceIoProtocol, (VOID*)GlobalIoFncs); + } + + ASSERT (!EFI_ERROR(Status)); + return Status; +} + +UINT32 +ReadPort ( + IN EFI_DEVICE_IO_INTERFACE *GlobalIoFncs, + IN EFI_IO_WIDTH Width, + IN UINTN Port + ) +{ + UINT32 Data; + EFI_STATUS Status EFI_UNUSED; + + Status = uefi_call_wrapper(GlobalIoFncs->Io.Read, 5, GlobalIoFncs, Width, (UINT64)Port, 1, &Data); + ASSERT(!EFI_ERROR(Status)); + return Data; +} + +UINT32 +WritePort ( + IN EFI_DEVICE_IO_INTERFACE *GlobalIoFncs, + IN EFI_IO_WIDTH Width, + IN UINTN Port, + IN UINTN Data + ) +{ + EFI_STATUS Status EFI_UNUSED; + + Status = uefi_call_wrapper(GlobalIoFncs->Io.Write, 5, GlobalIoFncs, Width, (UINT64)Port, 1, &Data); + ASSERT(!EFI_ERROR(Status)); + return (UINT32)Data; +} + +UINT32 +ReadPciConfig ( + IN EFI_DEVICE_IO_INTERFACE *GlobalIoFncs, + IN EFI_IO_WIDTH Width, + IN UINTN Address + ) +{ + UINT32 Data; + EFI_STATUS Status EFI_UNUSED; + + Status = uefi_call_wrapper(GlobalIoFncs->Pci.Read, 5, GlobalIoFncs, Width, (UINT64)Address, 1, &Data); + ASSERT(!EFI_ERROR(Status)); + return Data; +} + +UINT32 +WritePciConfig ( + IN EFI_DEVICE_IO_INTERFACE *GlobalIoFncs, + IN EFI_IO_WIDTH Width, + IN UINTN Address, + IN UINTN Data + ) +{ + EFI_STATUS Status EFI_UNUSED; + + Status = uefi_call_wrapper(GlobalIoFncs->Pci.Write, 5, GlobalIoFncs, Width, (UINT64)Address, 1, &Data); + ASSERT(!EFI_ERROR(Status)); + return (UINT32)Data; +} + + + diff --git a/gnu-efi/lib/ia32/efi_stub.S b/gnu-efi/lib/ia32/efi_stub.S new file mode 100644 index 0000000..464eae5 --- /dev/null +++ b/gnu-efi/lib/ia32/efi_stub.S @@ -0,0 +1 @@ +/* This stub is a stub to make the build happy */ diff --git a/gnu-efi/lib/ia32/initplat.c b/gnu-efi/lib/ia32/initplat.c new file mode 100644 index 0000000..7c887a6 --- /dev/null +++ b/gnu-efi/lib/ia32/initplat.c @@ -0,0 +1,27 @@ +/*++ + +Copyright (c) 1998 Intel Corporation + +Module Name: + + initplat.c + +Abstract: + + + + +Revision History + +--*/ + +#include "lib.h" + +VOID +InitializeLibPlatform ( + IN EFI_HANDLE ImageHandle EFI_UNUSED, + IN EFI_SYSTEM_TABLE *SystemTable EFI_UNUSED + ) +{ +} + diff --git a/gnu-efi/lib/ia32/math.c b/gnu-efi/lib/ia32/math.c new file mode 100644 index 0000000..fce7a8d --- /dev/null +++ b/gnu-efi/lib/ia32/math.c @@ -0,0 +1,199 @@ +/*++ + +Copyright (c) 1998 Intel Corporation + +Module Name: + + math.c + +Abstract: + + + + +Revision History + +--*/ + +#include "lib.h" + + +// +// Declare runtime functions +// + +#ifdef RUNTIME_CODE +#ifndef __GNUC__ +#pragma RUNTIME_CODE(LShiftU64) +#pragma RUNTIME_CODE(RShiftU64) +#pragma RUNTIME_CODE(MultU64x32) +#pragma RUNTIME_CODE(DivU64x32) +#endif +#endif + +// +// +// + +UINT64 +LShiftU64 ( + IN UINT64 Operand, + IN UINTN Count + ) +// Left shift 64bit by 32bit and get a 64bit result +{ +#ifdef __GNUC__ + return Operand << Count; +#else + UINT64 Result; + _asm { + mov eax, dword ptr Operand[0] + mov edx, dword ptr Operand[4] + mov ecx, Count + and ecx, 63 + + shld edx, eax, cl + shl eax, cl + + cmp ecx, 32 + jc short ls10 + + mov edx, eax + xor eax, eax + +ls10: + mov dword ptr Result[0], eax + mov dword ptr Result[4], edx + } + + return Result; +#endif +} + +UINT64 +RShiftU64 ( + IN UINT64 Operand, + IN UINTN Count + ) +// Right shift 64bit by 32bit and get a 64bit result +{ +#ifdef __GNUC__ + return Operand >> Count; +#else + UINT64 Result; + _asm { + mov eax, dword ptr Operand[0] + mov edx, dword ptr Operand[4] + mov ecx, Count + and ecx, 63 + + shrd eax, edx, cl + shr edx, cl + + cmp ecx, 32 + jc short rs10 + + mov eax, edx + xor edx, edx + +rs10: + mov dword ptr Result[0], eax + mov dword ptr Result[4], edx + } + + return Result; +#endif +} + + +UINT64 +MultU64x32 ( + IN UINT64 Multiplicand, + IN UINTN Multiplier + ) +// Multiple 64bit by 32bit and get a 64bit result +{ +#ifdef __GNUC__ + return Multiplicand * Multiplier; +#else + UINT64 Result; + _asm { + mov eax, dword ptr Multiplicand[0] + mul Multiplier + mov dword ptr Result[0], eax + mov dword ptr Result[4], edx + mov eax, dword ptr Multiplicand[4] + mul Multiplier + add dword ptr Result[4], eax + } + + return Result; +#endif +} + +UINT64 +DivU64x32 ( + IN UINT64 Dividend, + IN UINTN Divisor, + OUT UINTN *Remainder OPTIONAL + ) +// divide 64bit by 32bit and get a 64bit result +// N.B. only works for 31bit divisors!! +{ +#if 0 && defined(__GNUC__) && !defined(__MINGW32__) + if (Remainder) + *Remainder = Dividend % Divisor; + return Dividend / Divisor; +#else + UINT32 Rem; + UINT32 bit; + + ASSERT (Divisor != 0); + ASSERT ((Divisor >> 31) == 0); + + // + // For each bit in the dividend + // + + Rem = 0; + for (bit=0; bit < 64; bit++) { +#if defined(__GNUC__) || defined(__MINGW32__) + asm ( + "shll $1, %0\n\t" + "rcll $1, 4%0\n\t" + "rcll $1, %2\n\t" + "mov %2, %%eax\n\t" + "cmp %1, %%eax\n\t" + "cmc\n\t" + "sbb %%eax, %%eax\n\t" + "sub %%eax, %0\n\t" + "and %1, %%eax\n\t" + "sub %%eax, %2" + : /* no outputs */ + : "m"(Dividend), "m"(Divisor), "m"(Rem) + : "cc","memory","%eax" + ); +#else + _asm { + shl dword ptr Dividend[0], 1 ; shift rem:dividend left one + rcl dword ptr Dividend[4], 1 + rcl dword ptr Rem, 1 + + mov eax, Rem + cmp eax, Divisor ; Is Rem >= Divisor? + cmc ; No - do nothing + sbb eax, eax ; Else, + sub dword ptr Dividend[0], eax ; set low bit in dividen + and eax, Divisor ; and + sub Rem, eax ; subtract divisor + } +#endif + } + + if (Remainder) { + *Remainder = Rem; + } + + return Dividend; +#endif +} diff --git a/gnu-efi/lib/ia32/setjmp.S b/gnu-efi/lib/ia32/setjmp.S new file mode 100644 index 0000000..aa9c084 --- /dev/null +++ b/gnu-efi/lib/ia32/setjmp.S @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved. + * This program and the accompanying materials are licensed and made +available + * under the terms and conditions of the BSD License which accompanies +this + * distribution. The full text of the license may be found at + * http://opensource.org/licenses/bsd-license.php. + * + * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, + * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR + * IMPLIED. + */ + .text + .globl setjmp +#ifndef __MINGW32__ + .type setjmp, @function +#else + .def setjmp; .scl 2; .type 32; .endef +#endif +setjmp: + pop %ecx + movl (%esp), %edx + movl %ebx, (%edx) + movl %esi, 4(%edx) + movl %edi, 8(%edx) + movl %ebp, 12(%edx) + movl %esp, 16(%edx) + xorl %eax, %eax + jmp *%ecx + + .globl longjmp +#ifndef __MINGW32__ + .type longjmp, @function +#else + .def longjmp; .scl 2; .type 32; .endef +#endif +longjmp: + pop %eax + pop %edx + pop %eax + movl (%edx), %ebx + movl 4(%edx), %esi + movl 8(%edx), %edi diff --git a/gnu-efi/lib/ia64/initplat.c b/gnu-efi/lib/ia64/initplat.c new file mode 100644 index 0000000..810d4fe --- /dev/null +++ b/gnu-efi/lib/ia64/initplat.c @@ -0,0 +1,30 @@ +/*++ + +Copyright (c) 1999 Intel Corporation + +Module Name: + + initplat.c + +Abstract: + + Functions to make SAL and PAL proc calls + +Revision History + +--*/ +#include "lib.h" + +//#include "palproc.h" + +VOID +InitializeLibPlatform ( + IN EFI_HANDLE ImageHandle EFI_UNUSED, + IN EFI_SYSTEM_TABLE *SystemTable EFI_UNUSED + ) +{ + PLABEL SalPlabel; + UINT64 PalEntry; + + LibInitSalAndPalProc (&SalPlabel, &PalEntry); +} diff --git a/gnu-efi/lib/ia64/math.c b/gnu-efi/lib/ia64/math.c new file mode 100644 index 0000000..a8c4e12 --- /dev/null +++ b/gnu-efi/lib/ia64/math.c @@ -0,0 +1,88 @@ +/*++ + +Copyright (c) 1998 Intel Corporation + +Module Name: + + math.c + +Abstract: + + + + +Revision History + +--*/ + +#include "lib.h" + + +// +// Declare runtime functions +// + +#ifdef RUNTIME_CODE +#ifndef __GNUC__ +#pragma RUNTIME_CODE(LShiftU64) +#pragma RUNTIME_CODE(RShiftU64) +#pragma RUNTIME_CODE(MultU64x32) +#pragma RUNTIME_CODE(DivU64x32) +#endif +#endif + +// +// +// + + + + +UINT64 +LShiftU64 ( + IN UINT64 Operand, + IN UINTN Count + ) +// Left shift 64bit by 32bit and get a 64bit result +{ + return Operand << Count; +} + +UINT64 +RShiftU64 ( + IN UINT64 Operand, + IN UINTN Count + ) +// Right shift 64bit by 32bit and get a 64bit result +{ + return Operand >> Count; +} + + +UINT64 +MultU64x32 ( + IN UINT64 Multiplicand, + IN UINTN Multiplier + ) +// Multiple 64bit by 32bit and get a 64bit result +{ + return Multiplicand * Multiplier; +} + +UINT64 +DivU64x32 ( + IN UINT64 Dividend, + IN UINTN Divisor, + OUT UINTN *Remainder OPTIONAL + ) +// divide 64bit by 32bit and get a 64bit result +// N.B. only works for 31bit divisors!! +{ + ASSERT (Divisor != 0); + + if (Remainder) { + *Remainder = Dividend % Divisor; + } + + return Dividend / Divisor; +} diff --git a/gnu-efi/lib/ia64/palproc.S b/gnu-efi/lib/ia64/palproc.S new file mode 100644 index 0000000..c304a78 --- /dev/null +++ b/gnu-efi/lib/ia64/palproc.S @@ -0,0 +1,161 @@ +//++ +// Copyright (c) 1996-99 Intel Corp. +// +// +// Module Name: +// +// palproc.s +// +// Abstract: +// +// Contains an implementation for making PAL PROC calls on +// IA-64 architecture. +// +// +// +// Revision History: +// +//-- + + .file "palproc.s" + +#include "palproc.h" + + +//----------------------------------------------------------------------------- +//++ +// MakeStaticPALCall +// +// This routine is called whenever an architected static calling convention +// based PAL call is to be made. This call does use RSE actually, but our policy +// in making static PAL calls before memory is available is to make sure that +// we do not nest too deep and allocate beyond 96 banked registers. In other +// words we carefully code calls and control flow before memory is available. +// +// Arguments : All parameters set up to do static PAL call. +// +// On Entry : +// +// Return Value: +// +// As per static calling conventions. +// +//-- +//--------------------------------------------------------------------------- +PROCEDURE_ENTRY(MakeStaticPALCall) + + NESTED_SETUP (5,8,0,0) + mov loc3 = b5 + mov loc4 = r2 + mov loc7 = r1;; + + movl loc6 = PAL_MC_CLEAR_LOG + mov r2 = psr;; + mov loc5 = r2 + + cmp.eq p6,p7 = r28,loc6;; + (p7)movl loc6 = PAL_MC_DYNAMIC_STATE;; + (p7)cmp.eq p6,p7 = r28,loc6;; + + (p7)movl loc6 = PAL_MC_ERROR_INFO;; + (p7)cmp.eq p6,p7 = r28,loc6;; + + (p7)movl loc6 = PAL_MC_RESUME;; + (p7)cmp.eq p6,p7 = r28,loc6 + + mov loc6 = 0x1;; + (p7)dep r2 = loc6,r2,13,1;; // psr.ic = 1 + +// p6 will be true, if it is one of the MCHK calls. There has been lots of debate +// on psr.ic for these values. For now, do not do any thing to psr.ic + +// (p6)dep r2 = r0,r2,13,1;; // psr.ic = 0 + dep r2 = r0,r2,14,1;; // psr.i = 0 + + mov psr.l = r2 + srlz.d;; // Needs data serailization. + srlz.i;; // Needs instruction serailization. + +StaticGetPALLocalIP: + mov loc2 = ip;; + add loc2 = StaticComeBackFromPALCall - StaticGetPALLocalIP,loc2;; + mov b0 = loc2 // return address after Pal call + mov r28 = in1 // get the input parameters to PAL call + mov r29 = in2 + mov r30 = in3;; + mov r31 = in4 + mov b5 = in0;; // get the PalProcEntrypt from input + br.sptk b5 // Take the plunge. + +StaticComeBackFromPALCall: + + mov psr.l = loc5;; + srlz.d;; // Needs data serailization. + srlz.i;; // Needs instruction serailization. + + mov b5 = loc3 + mov r2 = loc4 + mov r1 = loc7 + + NESTED_RETURN + +PROCEDURE_EXIT(MakeStaticPALCall) + + +//----------------------------------------------------------------------------- +//++ +// MakeStackedPALCall +// +// This routine is called whenever an architected stacked calling convention +// based PAL call is to be made. This call is made after memory is available. +// Although stacked calls could be made directly from 'C', there is a PAL +// requirement which forces the index to be in GR28 and hence this stub is +// needed +// +// Arguments : All parameters set up to do stacted PAL call. +// +// On Entry : +// in0: PAL_PROC entrypoint +// in1-in4 : PAL_PROC arguments +// +// Return Value: +// +// As per stacked calling conventions. +// +//-- +//--------------------------------------------------------------------------- +PROCEDURE_ENTRY(MakeStackedPALCall) + + NESTED_SETUP (5,8,4,0) + mov loc3 = b5 + mov loc4 = r2 + mov loc7 = r1 + mov r2 = psr;; + mov loc5 = r2;; + dep r2 = r0,r2,14,1;; // psr.i = 0 + mov psr.l = r2 + srlz.d;; // Needs data serailization. + srlz.i;; // Needs instruction serailization. + +StackedGetPALLocalIP: + mov r28 = in1 // get the input parameters to PAL call + mov out0 = in1 + mov out1 = in2;; + mov out2 = in3 + mov out3 = in4 + mov b5 = in0;; // get the PalProcEntrypt from input + br.call.dpnt b0=b5;; // Take the plunge. + +StackedComeBackFromPALCall: + + mov psr.l = loc5;; + srlz.d;; // Needs data serailization. + srlz.i;; // Needs instruction serailization. + mov b5 = loc3 + mov r2 = loc4 + mov r1 = loc7 + + NESTED_RETURN + +PROCEDURE_EXIT(MakeStackedPALCall) + diff --git a/gnu-efi/lib/ia64/palproc.h b/gnu-efi/lib/ia64/palproc.h new file mode 100644 index 0000000..240946d --- /dev/null +++ b/gnu-efi/lib/ia64/palproc.h @@ -0,0 +1,51 @@ +// +// +// Copyright (c) 1996-99 Intel Corp. +// +// +//Module Name: +// +// palproc.h +// +//Abstract: +// +// This module contains generic macros for an IA64 assembly writer. +// +// +//Revision History +// + +#ifndef _PALPROC_H +#define _PALPROC_H + +#define PROCEDURE_ENTRY(name) .##text; \ + .##type name, @function; \ + .##global name; \ + .##proc name; \ +name: + +#define PROCEDURE_EXIT(name) .##endp name + +// Note: use of NESTED_SETUP requires number of locals (l) >= 3 + +#define NESTED_SETUP(i,l,o,r) \ + alloc loc1=ar##.##pfs,i,l,o,r ;\ + mov loc0=b0 + +#define NESTED_RETURN \ + mov b0=loc0 ;\ + mov ar##.##pfs=loc1 ;;\ + br##.##ret##.##dpnt b0;; + + +// defines needed in palproc.s + +#define PAL_MC_CLEAR_LOG 0x0015 +#define PAL_MC_DRAIN 0x0016 +#define PAL_MC_EXPECTED 0x0017 +#define PAL_MC_DYNAMIC_STATE 0x0018 +#define PAL_MC_ERROR_INFO 0x0019 +#define PAL_MC_RESUME 0x001a +#define PAL_MC_REGISTER_MEM 0x001b + +#endif // _PALPROC_H diff --git a/gnu-efi/lib/ia64/salpal.c b/gnu-efi/lib/ia64/salpal.c new file mode 100644 index 0000000..3d808f3 --- /dev/null +++ b/gnu-efi/lib/ia64/salpal.c @@ -0,0 +1,335 @@ +/*++ + +Copyright (c) 1999 Intel Corporation + +Module Name: + + salpal.c + +Abstract: + + Functions to make SAL and PAL proc calls + +Revision History + +--*/ +#include "lib.h" +#include "palproc.h" +#include "salproc.h" +/*++ + +Copyright (c) 1999 Intel Corporation + +Module Name: + + EfiRtLib.h + +Abstract: + + EFI Runtime library functions + + + +Revision History + +--*/ + +#include "efi.h" +#include "efilib.h" + +rArg +MakeStaticPALCall ( + IN UINT64 PALPROCPtr, + IN UINT64 Arg1, + IN UINT64 Arg2, + IN UINT64 Arg3, + IN UINT64 Arg4 + ); + +rArg +MakeStackedPALCall ( + IN UINT64 PALPROCPtr, + IN UINT64 Arg1, + IN UINT64 Arg2, + IN UINT64 Arg3, + IN UINT64 Arg4 + ); + + +PLABEL SalProcPlabel; +PLABEL PalProcPlabel; +CALL_SAL_PROC GlobalSalProc; +CALL_PAL_PROC GlobalPalProc; + +VOID +LibInitSalAndPalProc ( + OUT PLABEL *SalPlabel, + OUT UINT64 *PalEntry + ) +{ + SAL_SYSTEM_TABLE_ASCENDING_ORDER *SalSystemTable; + EFI_STATUS Status; + + GlobalSalProc = NULL; + GlobalPalProc = NULL; + + Status = LibGetSystemConfigurationTable(&SalSystemTableGuid, (VOID **)&SalSystemTable); + if (EFI_ERROR(Status)) { + return; + } + + // + // BugBug: Add code to test checksum on the Sal System Table + // + if (SalSystemTable->Entry0.Type != 0) { + return; + } + + SalProcPlabel.ProcEntryPoint = SalSystemTable->Entry0.SalProcEntry; + SalProcPlabel.GP = SalSystemTable->Entry0.GlobalDataPointer; + GlobalSalProc = (CALL_SAL_PROC)&SalProcPlabel.ProcEntryPoint; + + // + // Need to check the PAL spec to make sure I'm not responsible for + // storing more state. + // We are passing in a Plabel that should be ignorred by the PAL. Call + // this way will cause use to retore our gp after the PAL returns. + // + PalProcPlabel.ProcEntryPoint = SalSystemTable->Entry0.PalProcEntry; + PalProcPlabel.GP = SalSystemTable->Entry0.GlobalDataPointer; + GlobalPalProc = (CALL_PAL_PROC)PalProcPlabel.ProcEntryPoint; + + *PalEntry = PalProcPlabel.ProcEntryPoint; + *SalPlabel = SalProcPlabel; +} + +EFI_STATUS +LibGetSalIoPortMapping ( + OUT UINT64 *IoPortMapping + ) +/*++ + + Get the IO Port Map from the SAL System Table. + DO NOT USE THIS TO DO YOU OWN IO's!!!!!!!!!!!! + Only use this for getting info, or initing the built in EFI IO abstraction. + Always use the EFI Device IO protoocl to access IO space. + +--*/ +{ + SAL_SYSTEM_TABLE_ASCENDING_ORDER *SalSystemTable; + SAL_ST_MEMORY_DESCRIPTOR_ENTRY *SalMemDesc; + EFI_STATUS Status; + + Status = LibGetSystemConfigurationTable(&SalSystemTableGuid, (VOID **)&SalSystemTable); + if (EFI_ERROR(Status)) { + return EFI_UNSUPPORTED; + } + + // + // BugBug: Add code to test checksum on the Sal System Table + // + if (SalSystemTable->Entry0.Type != 0) { + return EFI_UNSUPPORTED; + } + + // + // The SalSystemTable pointer includes the Type 0 entry. + // The SalMemDesc is Type 1 so it comes next. + // + SalMemDesc = (SAL_ST_MEMORY_DESCRIPTOR_ENTRY *)(SalSystemTable + 1); + while (SalMemDesc->Type == SAL_ST_MEMORY_DESCRIPTOR) { + if (SalMemDesc->MemoryType == SAL_IO_PORT_MAPPING) { + *IoPortMapping = SalMemDesc->PhysicalMemoryAddress; + return EFI_SUCCESS; + } + SalMemDesc++; + } + return EFI_UNSUPPORTED; +} + +EFI_STATUS +LibGetSalIpiBlock ( + OUT UINT64 *IpiBlock + ) +/*++ + + Get the IPI block from the SAL system table + +--*/ +{ + SAL_SYSTEM_TABLE_ASCENDING_ORDER *SalSystemTable; + SAL_ST_MEMORY_DESCRIPTOR_ENTRY *SalMemDesc; + EFI_STATUS Status; + + Status = LibGetSystemConfigurationTable(&SalSystemTableGuid, (VOID*)&SalSystemTable); + if (EFI_ERROR(Status)) { + return EFI_UNSUPPORTED; + } + + // + // BugBug: Add code to test checksum on the Sal System Table + // + if (SalSystemTable->Entry0.Type != 0) { + return EFI_UNSUPPORTED; + } + + // + // The SalSystemTable pointer includes the Type 0 entry. + // The SalMemDesc is Type 1 so it comes next. + // + SalMemDesc = (SAL_ST_MEMORY_DESCRIPTOR_ENTRY *)(SalSystemTable + 1); + while (SalMemDesc->Type == SAL_ST_MEMORY_DESCRIPTOR) { + if (SalMemDesc->MemoryType == SAL_SAPIC_IPI_BLOCK ) { + *IpiBlock = SalMemDesc->PhysicalMemoryAddress; + return EFI_SUCCESS; + } + SalMemDesc++; + } + return EFI_UNSUPPORTED; +} + +EFI_STATUS +LibGetSalWakeupVector ( + OUT UINT64 *WakeVector + ) +/*++ + +Get the wakeup vector from the SAL system table + +--*/ +{ + SAL_ST_AP_WAKEUP_DECRIPTOR *ApWakeUp; + + ApWakeUp = LibSearchSalSystemTable (SAL_ST_AP_WAKEUP); + if (!ApWakeUp) { + *WakeVector = -1; + return EFI_UNSUPPORTED; + } + *WakeVector = ApWakeUp->ExternalInterruptVector; + return EFI_SUCCESS; +} + +VOID * +LibSearchSalSystemTable ( + IN UINT8 EntryType + ) +{ + EFI_STATUS Status; + UINT8 *SalTableHack; + SAL_SYSTEM_TABLE_ASCENDING_ORDER *SalSystemTable; + UINT16 EntryCount; + UINT16 Count; + + Status = LibGetSystemConfigurationTable(&SalSystemTableGuid, (VOID*)&SalSystemTable); + if (EFI_ERROR(Status)) { + return NULL; + } + + EntryCount = SalSystemTable->Header.EntryCount; + if (EntryCount == 0) { + return NULL; + } + // + // BugBug: Add code to test checksum on the Sal System Table + // + + SalTableHack = (UINT8 *)&SalSystemTable->Entry0; + for (Count = 0; Count < EntryCount ;Count++) { + if (*SalTableHack == EntryType) { + return (VOID *)SalTableHack; + } + switch (*SalTableHack) { + case SAL_ST_ENTRY_POINT: + SalTableHack += 48; + break; + case SAL_ST_MEMORY_DESCRIPTOR: + SalTableHack += 32; + break; + case SAL_ST_PLATFORM_FEATURES: + SalTableHack += 16; + break; + case SAL_ST_TR_USAGE: + SalTableHack += 32; + break; + case SAL_ST_PTC: + SalTableHack += 16; + break; + case SAL_ST_AP_WAKEUP: + SalTableHack += 16; + break; + default: + ASSERT(FALSE); + break; + } + } + return NULL; +} + +VOID +LibSalProc ( + IN UINT64 Arg1, + IN UINT64 Arg2, + IN UINT64 Arg3, + IN UINT64 Arg4, + IN UINT64 Arg5, + IN UINT64 Arg6, + IN UINT64 Arg7, + IN UINT64 Arg8, + OUT rArg *Results OPTIONAL + ) +{ + rArg ReturnValue; + + ReturnValue.p0 = -3; // SAL status return completed with error + if (GlobalSalProc) { + ReturnValue = GlobalSalProc(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8); + } + + if (Results) { + CopyMem (Results, &ReturnValue, sizeof(rArg)); + } +} + +VOID +LibPalProc ( + IN UINT64 Arg1, // Pal Proc index + IN UINT64 Arg2, + IN UINT64 Arg3, + IN UINT64 Arg4, + OUT rArg *Results OPTIONAL + ) +{ + + rArg ReturnValue; + + ReturnValue.p0 = -3; // PAL status return completed with error + + // + // check for valid PalProc entry point + // + + if (!GlobalPalProc) { + if (Results) + CopyMem (Results, &ReturnValue, sizeof(rArg)); + return; + } + + // + // check if index falls within stacked or static register calling conventions + // and call appropriate Pal stub call + // + + if (((Arg1 >=255) && (Arg1 <=511)) || + ((Arg1 >=768) && (Arg1 <=1023))) { + ReturnValue = MakeStackedPALCall((UINT64)GlobalPalProc,Arg1,Arg2,Arg3,Arg4); + } + else { + ReturnValue = MakeStaticPALCall((UINT64)GlobalPalProc,Arg1,Arg2,Arg3,Arg4); + } + + if (Results) + CopyMem (Results, &ReturnValue, sizeof(rArg)); + + return; +} + diff --git a/gnu-efi/lib/ia64/setjmp.S b/gnu-efi/lib/ia64/setjmp.S new file mode 100644 index 0000000..bbb29d8 --- /dev/null +++ b/gnu-efi/lib/ia64/setjmp.S @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved. + * This program and the accompanying materials are licensed and made +available + * under the terms and conditions of the BSD License which accompanies +this + * distribution. The full text of the license may be found at + * http://opensource.org/licenses/bsd-license.php. + * + * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, + * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR + * IMPLIED. + */ + .text + .globl setjmp + .type setjmp, @function +setjmp: + alloc loc0 = ar.pfs, 1, 2, 1, 0 + ;; + mov r14 = ar.unat + mov r15 = ar.bsp + add r10 = 0x10*20, in0 + ;; + stf.spill.nta [in0] = f2, 0x10 + st8.spill.nta [r10] = r4, 8 + mov r21 = b1 + ;; + stf.spill.nta [in0] = f3, 0x10 + st8.spill.nta [r10] = r5, 8 + mov r22 = b2 + ;; + stf.spill.nta [in0] = f4, 0x10 + st8.spill.nta [r10] = r6, 8 + mov r23 = b3 + ;; + stf.spill.nta [in0] = f5, 0x10 + st8.spill.nta [r10] = r7, 8 + mov r24 = b4 + ;; + stf.spill.nta [in0] = f16, 0x10 + st8.spill.nta [r10] = sp, 8 + mov r25 = b5 + ;; + stf.spill.nta [in0] = f17, 0x10 + st8.nta [r10] = loc1, 8 + mov r16 = pr + ;; + stf.spill.nta [in0] = f18, 0x10 + st8.nta [r10] = r21, 8 + mov r17 = ar.lc + ;; + stf.spill.nta [in0] = f19, 0x10 + st8.nta [r10] = r22, 8 + ;; + stf.spill.nta [in0] = f20, 0x10 + st8.nta [r10] = r23, 8 + ;; + stf.spill.nta [in0] = f21, 0x10 + st8.nta [r10] = r24, 8 + ;; + stf.spill.nta [in0] = f22, 0x10 + st8.nta [r10] = r25, 8 + ;; + stf.spill.nta [in0] = f23, 0x10 + mov r18 = ar.unat + ;; + stf.spill.nta [in0] = f24, 0x10 + st8.nta [r10] = r14, 8 + ;; + stf.spill.nta [in0] = f25, 0x10 + st8.nta [r10] = r18, 8 + ;; + stf.spill.nta [in0] = f26, 0x10 + st8.nta [r10] = loc0, 8 + ;; + stf.spill.nta [in0] = f27, 0x10 + st8.nta [r10] = r15, 8 + mov r8 = 0 + ;; + stf.spill.nta [in0] = f28, 0x10 + mov r19 = ar.fpsr + ;; + stf.spill.nta [in0] = f29, 0x10 + st8.nta [r10] = r16, 8 + mov ar.pfs = loc0 + ;; + stf.spill.nta [in0] = f30, 0x10 + st8.nta [r10] = r17, 8 + mov b0 = loc1 + ;; + stf.spill.nta [in0] = f31, 0x10 + st8.nta [r10] = r19 + ;; + mov ar.unat = r14 + br.ret.sptk b0 + ;; + + .globl longjmp + .type longjmp, @function + .regstk 2, 0, 0, 0 +longjmp: + 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 + ;; + ld8.nt1 r18 = [r10], -8 + ld8.nt1 r25 = [r10], -8 + and r2 = r16, r2 + ;; + ldf.fill.nt1 f2 = [in0], 0x10 + ld8.nt1 r24 = [r10], -8 + mov b5 = r25 + ;; + mov ar.rsc = r2 + ld8.nt1 r23 = [r10], -8 + mov b4 = r24 + ;; + ldf.fill.nt1 f3 = [in0], 0x10 + mov ar.unat = r17 +(p6) br.spnt.many _skip_flushrs + ;; + flushrs + mov r15 = ar.bsp + ;; +_skip_flushrs: + mov r31 = ar.rnat + loadrs + ;; + ldf.fill.nt1 f4 = [in0], 0x10 + ld8.nt1 r22 = [r10], -8 + dep r2 = -1, r14, 3, 6 + ;; + 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 + ;; + ldf.fill.nt1 f16 = [in0], 0x10 + ld8.fill.nt1 r7 = [r10], -8 + mov b2 = r22 + ;; + ldf.fill.nt1 f17 = [in0], 0x10 + ld8.fill.nt1 r6 = [r10], -8 + mov b1 = r21 + ;; + ldf.fill.nt1 f18 = [in0], 0x10 + ld8.fill.nt1 r5 = [r10], -8 + mov b0 = r20 + ;; + ldf.fill.nt1 f19 = [in0], 0x10 + ld8.fill.nt1 r4 = [r10], 8*13 + ;; + ldf.fill.nt1 f20 = [in0], 0x10 + ld8.nt1 r19 = [r10], 0x10 + ;; + ldf.fill.nt1 f21 = [in0], 0x10 + ld8.nt1 r26 = [r10], 8 + mov ar.pfs = r19 + ;; + ldf.fill.nt1 f22 = [in0], 0x10 + ld8.nt1 r27 = [r10], 8 + mov pr = r26, -1 + ;; + 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 + ;; + ldf.fill.nt1 f26 = [in0], 0x10 + ldf.fill.nt1 f31 = [r10], -0x10 + ;; + ldf.fill.nt1 f27 = [in0], 0x10 + ldf.fill.nt1 f30 = [r10], -0x10 + ;; + ldf.fill.nt1 f28 = [in0] + ldf.fill.nt1 f29 = [r10], 0x10*3 + 8*4 + ;; + 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 diff --git a/gnu-efi/lib/init.c b/gnu-efi/lib/init.c new file mode 100644 index 0000000..4f238c0 --- /dev/null +++ b/gnu-efi/lib/init.c @@ -0,0 +1,214 @@ +/*++ + +Copyright (c) 1998 Intel Corporation + +Module Name: + + +Abstract: + + + + +Revision History + +--*/ + +#include "lib.h" + +VOID +EFIDebugVariable ( + VOID + ); + +VOID +InitializeLib ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +/*++ + +Routine Description: + + Initializes EFI library for use + +Arguments: + + Firmware's EFI system table + +Returns: + + None + +--*/ +{ + EFI_LOADED_IMAGE *LoadedImage; + EFI_STATUS Status; + CHAR8 *LangCode; + + if (!LibInitialized) { + LibInitialized = TRUE; + LibFwInstance = FALSE; + LibImageHandle = ImageHandle; + + + // + // Set up global pointer to the system table, boot services table, + // and runtime services table + // + + ST = SystemTable; + BS = SystemTable->BootServices; + RT = SystemTable->RuntimeServices; +// ASSERT (CheckCrc(0, &ST->Hdr)); +// ASSERT (CheckCrc(0, &BS->Hdr)); +// ASSERT (CheckCrc(0, &RT->Hdr)); + + + // + // Initialize pool allocation type + // + + if (ImageHandle) { + Status = uefi_call_wrapper( + BS->HandleProtocol, + 3, + ImageHandle, + &LoadedImageProtocol, + (VOID*)&LoadedImage + ); + + if (!EFI_ERROR(Status)) { + PoolAllocationType = LoadedImage->ImageDataType; + } + EFIDebugVariable (); + } + + // + // Initialize Guid table + // + + InitializeGuid(); + + InitializeLibPlatform(ImageHandle,SystemTable); + } + + // + // + // + + if (ImageHandle && UnicodeInterface == &LibStubUnicodeInterface) { + LangCode = LibGetVariable (VarLanguage, &EfiGlobalVariable); + InitializeUnicodeSupport (LangCode); + if (LangCode) { + FreePool (LangCode); + } + } +} + +VOID +InitializeUnicodeSupport ( + CHAR8 *LangCode + ) +{ + EFI_UNICODE_COLLATION_INTERFACE *Ui; + EFI_STATUS Status; + CHAR8 *Languages; + UINTN Index, Position, Length; + UINTN NoHandles; + EFI_HANDLE *Handles; + + // + // If we don't know it, lookup the current language code + // + + LibLocateHandle (ByProtocol, &UnicodeCollationProtocol, NULL, &NoHandles, &Handles); + if (!LangCode || !NoHandles) { + goto Done; + } + + // + // Check all driver's for a matching language code + // + + for (Index=0; Index < NoHandles; Index++) { + Status = uefi_call_wrapper(BS->HandleProtocol, 3, Handles[Index], &UnicodeCollationProtocol, (VOID*)&Ui); + if (EFI_ERROR(Status)) { + continue; + } + + // + // Check for a matching language code + // + + Languages = Ui->SupportedLanguages; + Length = strlena(Languages); + for (Position=0; Position < Length; Position += ISO_639_2_ENTRY_SIZE) { + + // + // If this code matches, use this driver + // + + if (CompareMem (Languages+Position, LangCode, ISO_639_2_ENTRY_SIZE) == 0) { + UnicodeInterface = Ui; + goto Done; + } + } + } + +Done: + // + // Cleanup + // + + if (Handles) { + FreePool (Handles); + } +} + +VOID +EFIDebugVariable ( + VOID + ) +{ + EFI_STATUS Status; + UINT32 Attributes; + UINTN DataSize; + UINTN NewEFIDebug; + + DataSize = sizeof(EFIDebug); + 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; +} diff --git a/include/efi/lib.h b/gnu-efi/lib/lib.h similarity index 100% rename from include/efi/lib.h rename to gnu-efi/lib/lib.h diff --git a/gnu-efi/lib/lock.c b/gnu-efi/lib/lock.c new file mode 100644 index 0000000..a33bec3 --- /dev/null +++ b/gnu-efi/lib/lock.c @@ -0,0 +1,107 @@ +/*++ + +Copyright (c) 1998 Intel Corporation + +Module Name: + + lock.c + +Abstract: + + Implements FLOCK + + + +Revision History + +--*/ + + +#include "lib.h" + + +VOID +InitializeLock ( + IN OUT FLOCK *Lock, + IN EFI_TPL Priority + ) +/*++ + +Routine Description: + + Initialize a basic mutual exclusion lock. Each lock + provides mutual exclusion access at it's task priority + level. Since there is no-premption (at any TPL) or + multiprocessor support, acquiring the lock only consists + of raising to the locks TPL. + + Note on a debug build the lock is acquired and released + to help ensure proper usage. + +Arguments: + + Lock - The FLOCK structure to initialize + + Priority - The task priority level of the lock + + +Returns: + + An initialized F Lock structure. + +--*/ +{ + Lock->Tpl = Priority; + Lock->OwnerTpl = 0; + Lock->Lock = 0; +} + + +VOID +AcquireLock ( + IN FLOCK *Lock + ) +/*++ + +Routine Description: + + Raising to the task priority level of the mutual exclusion + lock, and then acquires ownership of the lock. + +Arguments: + + Lock - The lock to acquire + +Returns: + + Lock owned + +--*/ +{ + RtAcquireLock (Lock); +} + + +VOID +ReleaseLock ( + IN FLOCK *Lock + ) +/*++ + +Routine Description: + + Releases ownership of the mutual exclusion lock, and + restores the previous task priority level. + +Arguments: + + Lock - The lock to release + +Returns: + + Lock unowned + +--*/ +{ + RtReleaseLock (Lock); +} diff --git a/gnu-efi/lib/mips64el/efi_stub.S b/gnu-efi/lib/mips64el/efi_stub.S new file mode 100644 index 0000000..464eae5 --- /dev/null +++ b/gnu-efi/lib/mips64el/efi_stub.S @@ -0,0 +1 @@ +/* This stub is a stub to make the build happy */ diff --git a/gnu-efi/lib/mips64el/initplat.c b/gnu-efi/lib/mips64el/initplat.c new file mode 100644 index 0000000..6c5e1fa --- /dev/null +++ b/gnu-efi/lib/mips64el/initplat.c @@ -0,0 +1,26 @@ +/* + * Copright (C) 2014 Linaro Ltd. + * Author: Ard Biesheuvel + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice and this list of conditions, without modification. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License as published by the Free Software Foundation; + * either version 2 of the License, or (at your option) any later version. + */ + +#include "lib.h" + +VOID +InitializeLibPlatform ( + IN EFI_HANDLE ImageHandle EFI_UNUSED, + IN EFI_SYSTEM_TABLE *SystemTable EFI_UNUSED + ) +{ +} diff --git a/gnu-efi/lib/mips64el/math.c b/gnu-efi/lib/mips64el/math.c new file mode 100644 index 0000000..8c16444 --- /dev/null +++ b/gnu-efi/lib/mips64el/math.c @@ -0,0 +1,63 @@ +/* + * Copright (C) 2014 Linaro Ltd. + * Author: Ard Biesheuvel + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice and this list of conditions, without modification. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License as published by the Free Software Foundation; + * either version 2 of the License, or (at your option) any later version. + */ + +#include "lib.h" + +UINT64 +LShiftU64 ( + IN UINT64 Operand, + IN UINTN Count + ) +// Left shift 64bit by 32bit and get a 64bit result +{ + return Operand << Count; +} + +UINT64 +RShiftU64 ( + IN UINT64 Operand, + IN UINTN Count + ) +// Right shift 64bit by 32bit and get a 64bit result +{ + return Operand >> Count; +} + + +UINT64 +MultU64x32 ( + IN UINT64 Multiplicand, + IN UINTN Multiplier + ) +// Multiple 64bit by 32bit and get a 64bit result +{ + return Multiplicand * Multiplier; +} + +UINT64 +DivU64x32 ( + IN UINT64 Dividend, + IN UINTN Divisor, + OUT UINTN *Remainder OPTIONAL + ) +// divide 64bit by 32bit and get a 64bit result +// N.B. only works for 31bit divisors!! +{ + if (Remainder) + *Remainder = Dividend % Divisor; + return Dividend / Divisor; +} diff --git a/gnu-efi/lib/mips64el/setjmp.S b/gnu-efi/lib/mips64el/setjmp.S new file mode 100644 index 0000000..930aca4 --- /dev/null +++ b/gnu-efi/lib/mips64el/setjmp.S @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved. + * Copright (c) 2017 Lemote Co. + * Author: Heiher + * + * This program and the accompanying materials are licensed and made +available + * under the terms and conditions of the BSD License which accompanies +this + * distribution. The full text of the license may be found at + * http://opensource.org/licenses/bsd-license.php. + * + * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, + * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR + * IMPLIED. + */ + .text + .p2align 3 + + .globl setjmp + .type setjmp, @function +setjmp: + sd $ra, 0x00($a0) + sd $sp, 0x08($a0) + sd $fp, 0x10($a0) + sd $gp, 0x18($a0) + + sd $s0, 0x20($a0) + sd $s1, 0x28($a0) + sd $s2, 0x30($a0) + sd $s3, 0x38($a0) + sd $s4, 0x40($a0) + sd $s5, 0x48($a0) + sd $s6, 0x50($a0) + sd $s7, 0x58($a0) + +#ifdef __mips_hard_float + mfc0 $v0, $12 + ext $v0, $v0, 29, 1 + beqz $v0, 1f + + s.d $f24, 0x60($a0) + s.d $f25, 0x68($a0) + s.d $f26, 0x70($a0) + s.d $f27, 0x78($a0) + s.d $f28, 0x80($a0) + s.d $f29, 0x88($a0) + s.d $f30, 0x90($a0) + s.d $f31, 0x98($a0) + +1: +#endif + move $v0, $zero + jr $ra + + .globl longjmp + .type longjmp, @function +longjmp: + ld $ra, 0x00($a0) + ld $sp, 0x08($a0) + ld $fp, 0x10($a0) + ld $gp, 0x18($a0) + + ld $s0, 0x20($a0) + ld $s1, 0x28($a0) + ld $s2, 0x30($a0) + ld $s3, 0x38($a0) + ld $s4, 0x40($a0) + ld $s5, 0x48($a0) + ld $s6, 0x50($a0) + ld $s7, 0x58($a0) + +#ifdef __mips_hard_float + mfc0 $v0, $12 + ext $v0, $v0, 29, 1 + beqz $v0, 1f + + l.d $f24, 0x60($a0) + l.d $f25, 0x68($a0) + l.d $f26, 0x70($a0) + l.d $f27, 0x78($a0) + l.d $f28, 0x80($a0) + l.d $f29, 0x88($a0) + l.d $f30, 0x90($a0) + l.d $f31, 0x98($a0) + +1: +#endif + li $v0, 1 + movn $v0, $a1, $a1 + jr $ra diff --git a/gnu-efi/lib/misc.c b/gnu-efi/lib/misc.c new file mode 100644 index 0000000..fdcc934 --- /dev/null +++ b/gnu-efi/lib/misc.c @@ -0,0 +1,563 @@ +/*++ + +Copyright (c) 1998 Intel Corporation + +Module Name: + + misc.c + +Abstract: + + + + +Revision History + +--*/ + +#include "lib.h" + + +// +// +// + +VOID * +AllocatePool ( + IN UINTN Size + ) +{ + EFI_STATUS Status; + VOID *p; + + Status = uefi_call_wrapper(BS->AllocatePool, 3, PoolAllocationType, Size, &p); + if (EFI_ERROR(Status)) { + DEBUG((D_ERROR, "AllocatePool: out of pool %x\n", Status)); + p = NULL; + } + return p; +} + +VOID * +AllocateZeroPool ( + IN UINTN Size + ) +{ + VOID *p; + + p = AllocatePool (Size); + if (p) { + ZeroMem (p, Size); + } + + return p; +} + +VOID * +ReallocatePool ( + IN VOID *OldPool, + IN UINTN OldSize, + IN UINTN NewSize + ) +{ + VOID *NewPool; + + NewPool = NULL; + if (NewSize) { + NewPool = AllocatePool (NewSize); + } + + if (OldPool) { + if (NewPool) { + CopyMem (NewPool, OldPool, OldSize < NewSize ? OldSize : NewSize); + } + + FreePool (OldPool); + } + + return NewPool; +} + + +VOID +FreePool ( + IN VOID *Buffer + ) +{ + uefi_call_wrapper(BS->FreePool, 1, Buffer); +} + + + +VOID +ZeroMem ( + IN VOID *Buffer, + IN UINTN Size + ) +{ + RtZeroMem (Buffer, Size); +} + +VOID +SetMem ( + IN VOID *Buffer, + IN UINTN Size, + IN UINT8 Value + ) +{ + RtSetMem (Buffer, Size, Value); +} + +VOID +CopyMem ( + IN VOID *Dest, + IN CONST VOID *Src, + IN UINTN len + ) +{ + RtCopyMem (Dest, Src, len); +} + +INTN +CompareMem ( + IN CONST VOID *Dest, + IN CONST VOID *Src, + IN UINTN len + ) +{ + return RtCompareMem (Dest, Src, len); +} + +BOOLEAN +GrowBuffer( + IN OUT EFI_STATUS *Status, + IN OUT VOID **Buffer, + IN UINTN BufferSize + ) +/*++ + +Routine Description: + + Helper function called as part of the code needed + to allocate the proper sized buffer for various + EFI interfaces. + +Arguments: + + Status - Current status + + Buffer - Current allocated buffer, or NULL + + BufferSize - Current buffer size needed + +Returns: + + TRUE - if the buffer was reallocated and the caller + should try the API again. + +--*/ +{ + BOOLEAN TryAgain; + + // + // If this is an initial request, buffer will be null with a new buffer size + // + + if (!*Buffer && BufferSize) { + *Status = EFI_BUFFER_TOO_SMALL; + } + + // + // If the status code is "buffer too small", resize the buffer + // + + TryAgain = FALSE; + if (*Status == EFI_BUFFER_TOO_SMALL) { + + if (*Buffer) { + FreePool (*Buffer); + } + + *Buffer = AllocatePool (BufferSize); + + if (*Buffer) { + TryAgain = TRUE; + } else { + *Status = EFI_OUT_OF_RESOURCES; + } + } + + // + // If there's an error, free the buffer + // + + if (!TryAgain && EFI_ERROR(*Status) && *Buffer) { + FreePool (*Buffer); + *Buffer = NULL; + } + + return TryAgain; +} + + +EFI_MEMORY_DESCRIPTOR * +LibMemoryMap ( + OUT UINTN *NoEntries, + OUT UINTN *MapKey, + OUT UINTN *DescriptorSize, + OUT UINT32 *DescriptorVersion + ) +{ + EFI_STATUS Status; + EFI_MEMORY_DESCRIPTOR *Buffer; + UINTN BufferSize; + + // + // Initialize for GrowBuffer loop + // + + Status = EFI_SUCCESS; + Buffer = NULL; + BufferSize = sizeof(EFI_MEMORY_DESCRIPTOR); + + // + // Call the real function + // + + while (GrowBuffer (&Status, (VOID **) &Buffer, BufferSize)) { + Status = uefi_call_wrapper(BS->GetMemoryMap, 5, &BufferSize, Buffer, MapKey, DescriptorSize, DescriptorVersion); + } + + // + // Convert buffer size to NoEntries + // + + if (!EFI_ERROR(Status)) { + *NoEntries = BufferSize / *DescriptorSize; + } + + return Buffer; +} + +VOID * +LibGetVariableAndSize ( + IN CHAR16 *Name, + IN EFI_GUID *VendorGuid, + OUT UINTN *VarSize + ) +{ + EFI_STATUS Status; + VOID *Buffer; + UINTN BufferSize; + + // + // Initialize for GrowBuffer loop + // + + Buffer = NULL; + BufferSize = 100; + + // + // Call the real function + // + + while (GrowBuffer (&Status, &Buffer, BufferSize)) { + Status = uefi_call_wrapper( + RT->GetVariable, + 5, + Name, + VendorGuid, + NULL, + &BufferSize, + Buffer + ); + } + if (Buffer) { + *VarSize = BufferSize; + } else { + *VarSize = 0; + } + return Buffer; +} + +VOID * +LibGetVariable ( + IN CHAR16 *Name, + IN EFI_GUID *VendorGuid + ) +{ + UINTN VarSize; + + return LibGetVariableAndSize (Name, VendorGuid, &VarSize); +} + +EFI_STATUS +LibDeleteVariable ( + IN CHAR16 *VarName, + IN EFI_GUID *VarGuid + ) +{ + VOID *VarBuf; + EFI_STATUS Status; + + VarBuf = LibGetVariable(VarName,VarGuid); + + Status = EFI_NOT_FOUND; + + if (VarBuf) { + // + // Delete variable from Storage + // + Status = uefi_call_wrapper( + RT->SetVariable, + 5, + VarName, VarGuid, + EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, + 0, NULL + ); + ASSERT (!EFI_ERROR(Status)); + FreePool(VarBuf); + } + + return (Status); +} + +EFI_STATUS +LibSetNVVariable ( + IN CHAR16 *VarName, + IN EFI_GUID *VarGuid, + IN UINTN DataSize, + IN VOID *Data + ) +{ + EFI_STATUS Status; + + Status = uefi_call_wrapper( + RT->SetVariable, + 5, + VarName, VarGuid, + EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, + DataSize, Data + ); + ASSERT (!EFI_ERROR(Status)); + return (Status); +} + +EFI_STATUS +LibSetVariable ( + IN CHAR16 *VarName, + IN EFI_GUID *VarGuid, + IN UINTN DataSize, + IN VOID *Data + ) +{ + EFI_STATUS Status; + + Status = uefi_call_wrapper( + RT->SetVariable, + 5, + VarName, VarGuid, + EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, + DataSize, Data + ); + ASSERT (!EFI_ERROR(Status)); + return (Status); +} + +EFI_STATUS +LibInsertToTailOfBootOrder ( + IN UINT16 BootOption, + IN BOOLEAN OnlyInsertIfEmpty + ) +{ + UINT16 *BootOptionArray; + UINT16 *NewBootOptionArray; + UINTN VarSize; + UINTN Index; + EFI_STATUS Status; + + BootOptionArray = LibGetVariableAndSize (VarBootOrder, &EfiGlobalVariable, &VarSize); + if (VarSize != 0 && OnlyInsertIfEmpty) { + if (BootOptionArray) { + FreePool (BootOptionArray); + } + return EFI_UNSUPPORTED; + } + + VarSize += sizeof(UINT16); + NewBootOptionArray = AllocatePool (VarSize); + + for (Index = 0; Index < ((VarSize/sizeof(UINT16)) - 1); Index++) { + NewBootOptionArray[Index] = BootOptionArray[Index]; + } + // + // Insert in the tail of the array + // + NewBootOptionArray[Index] = BootOption; + + Status = uefi_call_wrapper( + RT->SetVariable, + 5, + VarBootOrder, &EfiGlobalVariable, + EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, + VarSize, (VOID*) NewBootOptionArray + ); + + if (NewBootOptionArray) { + FreePool (NewBootOptionArray); + } + if (BootOptionArray) { + FreePool (BootOptionArray); + } + return Status; +} + + +BOOLEAN +ValidMBR( + IN MASTER_BOOT_RECORD *Mbr, + IN EFI_BLOCK_IO *BlkIo + ) +{ + UINT32 StartingLBA, EndingLBA; + UINT32 NewEndingLBA; + INTN i, j; + BOOLEAN ValidMbr; + + if (Mbr->Signature != MBR_SIGNATURE) { + // + // The BPB also has this signature, so it can not be used alone. + // + return FALSE; + } + + ValidMbr = FALSE; + for (i=0; iPartition[i].OSIndicator == 0x00 || EXTRACT_UINT32(Mbr->Partition[i].SizeInLBA) == 0 ) { + continue; + } + ValidMbr = TRUE; + StartingLBA = EXTRACT_UINT32(Mbr->Partition[i].StartingLBA); + EndingLBA = StartingLBA + EXTRACT_UINT32(Mbr->Partition[i].SizeInLBA) - 1; + if (EndingLBA > BlkIo->Media->LastBlock) { + // + // Compatability Errata: + // Some systems try to hide drive space with thier INT 13h driver + // This does not hide space from the OS driver. This means the MBR + // that gets created from DOS is smaller than the MBR created from + // a real OS (NT & Win98). This leads to BlkIo->LastBlock being + // wrong on some systems FDISKed by the OS. + // + // + if (BlkIo->Media->LastBlock < MIN_MBR_DEVICE_SIZE) { + // + // If this is a very small device then trust the BlkIo->LastBlock + // + return FALSE; + } + + if (EndingLBA > (BlkIo->Media->LastBlock + MBR_ERRATA_PAD)) { + return FALSE; + } + + } + for (j=i+1; jPartition[j].OSIndicator == 0x00 || EXTRACT_UINT32(Mbr->Partition[j].SizeInLBA) == 0) { + continue; + } + if ( EXTRACT_UINT32(Mbr->Partition[j].StartingLBA) >= StartingLBA && + EXTRACT_UINT32(Mbr->Partition[j].StartingLBA) <= EndingLBA ) { + // + // The Start of this region overlaps with the i'th region + // + return FALSE; + } + NewEndingLBA = EXTRACT_UINT32(Mbr->Partition[j].StartingLBA) + EXTRACT_UINT32(Mbr->Partition[j].SizeInLBA) - 1; + if ( NewEndingLBA >= StartingLBA && NewEndingLBA <= EndingLBA ) { + // + // The End of this region overlaps with the i'th region + // + return FALSE; + } + } + } + // + // Non of the regions overlapped so MBR is O.K. + // + return ValidMbr; +} + + +UINT8 +DecimaltoBCD( + IN UINT8 DecValue + ) +{ + return RtDecimaltoBCD (DecValue); +} + + +UINT8 +BCDtoDecimal( + IN UINT8 BcdValue + ) +{ + return RtBCDtoDecimal (BcdValue); +} + +EFI_STATUS +LibGetSystemConfigurationTable( + IN EFI_GUID *TableGuid, + IN OUT VOID **Table + ) + +{ + UINTN Index; + + for(Index=0;IndexNumberOfTableEntries;Index++) { + if (CompareGuid(TableGuid,&(ST->ConfigurationTable[Index].VendorGuid))==0) { + *Table = ST->ConfigurationTable[Index].VendorTable; + return EFI_SUCCESS; + } + } + return EFI_NOT_FOUND; +} + + +CHAR16 * +LibGetUiString ( + IN EFI_HANDLE Handle, + IN UI_STRING_TYPE StringType, + IN ISO_639_2 *LangCode, + IN BOOLEAN ReturnDevicePathStrOnMismatch + ) +{ + UI_INTERFACE *Ui; + UI_STRING_TYPE Index; + UI_STRING_ENTRY *Array; + EFI_STATUS Status; + + Status = uefi_call_wrapper(BS->HandleProtocol, 3, Handle, &UiProtocol, (VOID *)&Ui); + if (EFI_ERROR(Status)) { + return (ReturnDevicePathStrOnMismatch) ? DevicePathToStr(DevicePathFromHandle(Handle)) : NULL; + } + + // + // Skip the first strings + // + for (Index = UiDeviceString, Array = Ui->Entry; Index < StringType; Index++, Array++) { + while (Array->LangCode) { + Array++; + } + } + + // + // Search for the match + // + while (Array->LangCode) { + if (strcmpa (Array->LangCode, LangCode) == 0) { + return Array->UiString; + } + } + return (ReturnDevicePathStrOnMismatch) ? DevicePathToStr(DevicePathFromHandle(Handle)) : NULL; +} diff --git a/gnu-efi/lib/print.c b/gnu-efi/lib/print.c new file mode 100644 index 0000000..35e43c0 --- /dev/null +++ b/gnu-efi/lib/print.c @@ -0,0 +1,1482 @@ +/*++ + +Copyright (c) 1998 Intel Corporation + +Module Name: + + print.c + +Abstract: + + + + +Revision History + +--*/ + +#include "lib.h" +#include "efistdarg.h" // !!! + +// +// Declare runtime functions +// + +#ifdef RUNTIME_CODE +#ifndef __GNUC__ +#pragma RUNTIME_CODE(DbgPrint) + +// For debugging.. + +/* +#pragma RUNTIME_CODE(_Print) +#pragma RUNTIME_CODE(PFLUSH) +#pragma RUNTIME_CODE(PSETATTR) +#pragma RUNTIME_CODE(PPUTC) +#pragma RUNTIME_CODE(PGETC) +#pragma RUNTIME_CODE(PITEM) +#pragma RUNTIME_CODE(ValueToHex) +#pragma RUNTIME_CODE(ValueToString) +#pragma RUNTIME_CODE(TimeToString) +*/ + +#endif /* !defined(__GNUC__) */ +#endif + +// +// +// + + +#define PRINT_STRING_LEN 200 +#define PRINT_ITEM_BUFFER_LEN 100 + +typedef struct { + BOOLEAN Ascii; + UINTN Index; + union { + CONST CHAR16 *pw; + CONST CHAR8 *pc; + } un; +} POINTER; + +#define pw un.pw +#define pc un.pc + +typedef struct _pitem { + + POINTER Item; + CHAR16 Scratch[PRINT_ITEM_BUFFER_LEN]; + UINTN Width; + UINTN FieldWidth; + UINTN *WidthParse; + CHAR16 Pad; + BOOLEAN PadBefore; + BOOLEAN Comma; + BOOLEAN Long; +} PRINT_ITEM; + + +typedef struct _pstate { + // Input + POINTER fmt; + va_list args; + + // Output + CHAR16 *Buffer; + CHAR16 *End; + CHAR16 *Pos; + UINTN Len; + + UINTN Attr; + UINTN RestoreAttr; + + UINTN AttrNorm; + UINTN AttrHighlight; + UINTN AttrError; + + INTN (EFIAPI *Output)(VOID *context, CHAR16 *str); + INTN (EFIAPI *SetAttr)(VOID *context, UINTN attr); + VOID *Context; + + // Current item being formatted + struct _pitem *Item; +} PRINT_STATE; + +// +// Internal fucntions +// + +STATIC +UINTN +_Print ( + IN PRINT_STATE *ps + ); + +STATIC +UINTN +_IPrint ( + IN UINTN Column, + IN UINTN Row, + IN SIMPLE_TEXT_OUTPUT_INTERFACE *Out, + IN CONST CHAR16 *fmt, + IN CONST CHAR8 *fmta, + IN va_list args + ); + +STATIC +INTN EFIAPI +_DbgOut ( + IN VOID *Context, + IN CHAR16 *Buffer + ); + +STATIC +VOID +PFLUSH ( + IN OUT PRINT_STATE *ps + ); + +STATIC +VOID +PPUTC ( + IN OUT PRINT_STATE *ps, + IN CHAR16 c + ); + +STATIC +VOID +PITEM ( + IN OUT PRINT_STATE *ps + ); + +STATIC +CHAR16 +PGETC ( + IN POINTER *p + ); + +STATIC +VOID +PSETATTR ( + IN OUT PRINT_STATE *ps, + IN UINTN Attr + ); + +// +// +// + +INTN EFIAPI +_SPrint ( + IN VOID *Context, + IN CHAR16 *Buffer + ); + +INTN EFIAPI +_PoolPrint ( + IN VOID *Context, + IN CHAR16 *Buffer + ); + +INTN +DbgPrint ( + IN INTN mask, + IN CONST CHAR8 *fmt, + ... + ) +/*++ + +Routine Description: + + Prints a formatted unicode string to the default StandardError console + +Arguments: + + mask - Bit mask of debug string. If a bit is set in the + mask that is also set in EFIDebug the string is + printed; otherwise, the string is not printed + + fmt - Format string + +Returns: + + Length of string printed to the StandardError console + +--*/ +{ + SIMPLE_TEXT_OUTPUT_INTERFACE *DbgOut; + PRINT_STATE ps; + va_list args; + UINTN back; + UINTN attr; + UINTN SavedAttribute; + + + if (!(EFIDebug & mask)) { + return 0; + } + + va_start (args, fmt); + ZeroMem (&ps, sizeof(ps)); + + ps.Output = _DbgOut; + ps.fmt.Ascii = TRUE; + ps.fmt.pc = fmt; + va_copy(ps.args, args); + ps.Attr = EFI_TEXT_ATTR(EFI_LIGHTGRAY, EFI_RED); + + DbgOut = LibRuntimeDebugOut; + + if (!DbgOut) { + DbgOut = ST->StdErr; + } + + if (DbgOut) { + ps.Attr = DbgOut->Mode->Attribute; + ps.Context = DbgOut; + ps.SetAttr = (INTN (EFIAPI *)(VOID *, UINTN)) DbgOut->SetAttribute; + } + + SavedAttribute = ps.Attr; + + back = (ps.Attr >> 4) & 0xf; + ps.AttrNorm = EFI_TEXT_ATTR(EFI_LIGHTGRAY, back); + ps.AttrHighlight = EFI_TEXT_ATTR(EFI_WHITE, back); + ps.AttrError = EFI_TEXT_ATTR(EFI_YELLOW, back); + + attr = ps.AttrNorm; + + if (mask & D_WARN) { + attr = ps.AttrHighlight; + } + + if (mask & D_ERROR) { + attr = ps.AttrError; + } + + if (ps.SetAttr) { + ps.Attr = attr; + uefi_call_wrapper(ps.SetAttr, 2, ps.Context, attr); + } + + _Print (&ps); + + va_end (ps.args); + va_end (args); + + // + // Restore original attributes + // + + if (ps.SetAttr) { + uefi_call_wrapper(ps.SetAttr, 2, ps.Context, SavedAttribute); + } + + return 0; +} + +STATIC +INTN +IsLocalPrint(void *func) +{ + if (func == _DbgOut || func == _SPrint || func == _PoolPrint) + return 1; + return 0; +} + +STATIC +INTN EFIAPI +_DbgOut ( + IN VOID *Context, + IN CHAR16 *Buffer + ) +// Append string worker for DbgPrint +{ + SIMPLE_TEXT_OUTPUT_INTERFACE *DbgOut; + + DbgOut = Context; +// if (!DbgOut && ST && ST->ConOut) { +// DbgOut = ST->ConOut; +// } + + if (DbgOut) { + if (IsLocalPrint(DbgOut->OutputString)) + DbgOut->OutputString(DbgOut, Buffer); + else + uefi_call_wrapper(DbgOut->OutputString, 2, DbgOut, Buffer); + } + + return 0; +} + +INTN EFIAPI +_SPrint ( + IN VOID *Context, + IN CHAR16 *Buffer + ) +// Append string worker for SPrint, PoolPrint and CatPrint +{ + UINTN len; + POOL_PRINT *spc; + + spc = Context; + len = StrLen(Buffer); + + // + // Is the string is over the max truncate it + // + + if (spc->len + len > spc->maxlen) { + len = spc->maxlen - spc->len; + } + + // + // Append the new text + // + + CopyMem (spc->str + spc->len, Buffer, len * sizeof(CHAR16)); + spc->len += len; + + // + // Null terminate it + // + + if (spc->len < spc->maxlen) { + spc->str[spc->len] = 0; + } else if (spc->maxlen) { + spc->str[spc->maxlen] = 0; + } + + return 0; +} + + +INTN EFIAPI +_PoolPrint ( + IN VOID *Context, + IN CHAR16 *Buffer + ) +// Append string worker for PoolPrint and CatPrint +{ + UINTN newlen; + POOL_PRINT *spc; + + spc = Context; + newlen = spc->len + StrLen(Buffer) + 1; + + // + // Is the string is over the max, grow the buffer + // + + if (newlen > spc->maxlen) { + + // + // Grow the pool buffer + // + + newlen += PRINT_STRING_LEN; + spc->maxlen = newlen; + spc->str = ReallocatePool ( + spc->str, + spc->len * sizeof(CHAR16), + spc->maxlen * sizeof(CHAR16) + ); + + if (!spc->str) { + spc->len = 0; + spc->maxlen = 0; + } + } + + // + // Append the new text + // + + return _SPrint (Context, Buffer); +} + + + +VOID +_PoolCatPrint ( + IN CONST CHAR16 *fmt, + IN va_list args, + IN OUT POOL_PRINT *spc, + IN INTN (EFIAPI *Output)(VOID *context, CHAR16 *str) + ) +// Dispath function for SPrint, PoolPrint, and CatPrint +{ + PRINT_STATE ps; + + ZeroMem (&ps, sizeof(ps)); + ps.Output = Output; + ps.Context = spc; + ps.fmt.pw = fmt; + va_copy(ps.args, args); + _Print (&ps); + va_end(ps.args); +} + + + +UINTN +VSPrint ( + OUT CHAR16 *Str, + IN UINTN StrSize, + IN CONST CHAR16 *fmt, + va_list args + ) +/*++ + +Routine Description: + + Prints a formatted unicode string to a buffer using a va_list + +Arguments: + + Str - Output buffer to print the formatted string into + + StrSize - Size of Str. String is truncated to this size. + A size of 0 means there is no limit + + fmt - The format string + + args - va_list + + +Returns: + + String length returned in buffer + +--*/ +{ + POOL_PRINT spc; + + spc.str = Str; + spc.maxlen = StrSize / sizeof(CHAR16) - 1; + spc.len = 0; + + _PoolCatPrint (fmt, args, &spc, _SPrint); + + return spc.len; +} + +UINTN +SPrint ( + OUT CHAR16 *Str, + IN UINTN StrSize, + IN CONST CHAR16 *fmt, + ... + ) +/*++ + +Routine Description: + + Prints a formatted unicode string to a buffer + +Arguments: + + Str - Output buffer to print the formatted string into + + StrSize - Size of Str. String is truncated to this size. + A size of 0 means there is no limit + + fmt - The format string + +Returns: + + String length returned in buffer + +--*/ +{ + va_list args; + UINTN len; + + va_start (args, fmt); + len = VSPrint(Str, StrSize, fmt, args); + va_end (args); + + return len; +} + +CHAR16 * +VPoolPrint ( + IN CONST CHAR16 *fmt, + va_list args + ) +/*++ + +Routine Description: + + Prints a formatted unicode string to allocated pool using va_list argument. + The caller must free the resulting buffer. + +Arguments: + + fmt - The format string + args - The arguments in va_list form + +Returns: + + Allocated buffer with the formatted string printed in it. + The caller must free the allocated buffer. The buffer + allocation is not packed. + +--*/ +{ + POOL_PRINT spc; + ZeroMem (&spc, sizeof(spc)); + _PoolCatPrint (fmt, args, &spc, _PoolPrint); + return spc.str; +} + +CHAR16 * +PoolPrint ( + IN CONST CHAR16 *fmt, + ... + ) +/*++ + +Routine Description: + + Prints a formatted unicode string to allocated pool. The caller + must free the resulting buffer. + +Arguments: + + fmt - The format string + +Returns: + + Allocated buffer with the formatted string printed in it. + The caller must free the allocated buffer. The buffer + allocation is not packed. + +--*/ +{ + va_list args; + CHAR16 *pool; + va_start (args, fmt); + pool = VPoolPrint(fmt, args); + va_end (args); + return pool; +} + +CHAR16 * +CatPrint ( + IN OUT POOL_PRINT *Str, + IN CONST CHAR16 *fmt, + ... + ) +/*++ + +Routine Description: + + Concatenates a formatted unicode string to allocated pool. + The caller must free the resulting buffer. + +Arguments: + + Str - Tracks the allocated pool, size in use, and + amount of pool allocated. + + fmt - The format string + +Returns: + + Allocated buffer with the formatted string printed in it. + The caller must free the allocated buffer. The buffer + allocation is not packed. + +--*/ +{ + va_list args; + + va_start (args, fmt); + _PoolCatPrint (fmt, args, Str, _PoolPrint); + va_end (args); + return Str->str; +} + + + +UINTN +Print ( + IN CONST CHAR16 *fmt, + ... + ) +/*++ + +Routine Description: + + Prints a formatted unicode string to the default console + +Arguments: + + fmt - Format string + +Returns: + + Length of string printed to the console + +--*/ +{ + va_list args; + UINTN back; + + va_start (args, fmt); + back = _IPrint ((UINTN) -1, (UINTN) -1, ST->ConOut, fmt, NULL, args); + va_end (args); + return back; +} + +UINTN +VPrint ( + IN CONST CHAR16 *fmt, + va_list args + ) +/*++ + +Routine Description: + + Prints a formatted unicode string to the default console using a va_list + +Arguments: + + fmt - Format string + args - va_list +Returns: + + Length of string printed to the console + +--*/ +{ + return _IPrint ((UINTN) -1, (UINTN) -1, ST->ConOut, fmt, NULL, args); +} + + +UINTN +PrintAt ( + IN UINTN Column, + IN UINTN Row, + IN CONST CHAR16 *fmt, + ... + ) +/*++ + +Routine Description: + + Prints a formatted unicode string to the default console, at + the supplied cursor position + +Arguments: + + Column, Row - The cursor position to print the string at + + fmt - Format string + +Returns: + + Length of string printed to the console + +--*/ +{ + va_list args; + UINTN back; + + va_start (args, fmt); + back = _IPrint (Column, Row, ST->ConOut, fmt, NULL, args); + va_end (args); + return back; +} + + +UINTN +IPrint ( + IN SIMPLE_TEXT_OUTPUT_INTERFACE *Out, + IN CONST CHAR16 *fmt, + ... + ) +/*++ + +Routine Description: + + Prints a formatted unicode string to the specified console + +Arguments: + + Out - The console to print the string too + + fmt - Format string + +Returns: + + Length of string printed to the console + +--*/ +{ + va_list args; + UINTN back; + + va_start (args, fmt); + back = _IPrint ((UINTN) -1, (UINTN) -1, Out, fmt, NULL, args); + va_end (args); + return back; +} + + +UINTN +IPrintAt ( + IN SIMPLE_TEXT_OUTPUT_INTERFACE *Out, + IN UINTN Column, + IN UINTN Row, + IN CONST CHAR16 *fmt, + ... + ) +/*++ + +Routine Description: + + Prints a formatted unicode string to the specified console, at + the supplied cursor position + +Arguments: + + Out - The console to print the string to + + Column, Row - The cursor position to print the string at + + fmt - Format string + +Returns: + + Length of string printed to the console + +--*/ +{ + va_list args; + UINTN back; + + va_start (args, fmt); + back = _IPrint (Column, Row, Out, fmt, NULL, args); + va_end (args); + return back; +} + + +UINTN +_IPrint ( + IN UINTN Column, + IN UINTN Row, + IN SIMPLE_TEXT_OUTPUT_INTERFACE *Out, + IN CONST CHAR16 *fmt, + IN CONST CHAR8 *fmta, + IN va_list args + ) +// Display string worker for: Print, PrintAt, IPrint, IPrintAt +{ + PRINT_STATE ps; + UINTN back; + + ZeroMem (&ps, sizeof(ps)); + ps.Context = Out; + ps.Output = (INTN (EFIAPI *)(VOID *, CHAR16 *)) Out->OutputString; + ps.SetAttr = (INTN (EFIAPI *)(VOID *, UINTN)) Out->SetAttribute; + ps.Attr = Out->Mode->Attribute; + + back = (ps.Attr >> 4) & 0xF; + ps.AttrNorm = EFI_TEXT_ATTR(EFI_LIGHTGRAY, back); + ps.AttrHighlight = EFI_TEXT_ATTR(EFI_WHITE, back); + ps.AttrError = EFI_TEXT_ATTR(EFI_YELLOW, back); + + if (fmt) { + ps.fmt.pw = fmt; + } else { + ps.fmt.Ascii = TRUE; + ps.fmt.pc = fmta; + } + + va_copy(ps.args, args); + + if (Column != (UINTN) -1) { + uefi_call_wrapper(Out->SetCursorPosition, 3, Out, Column, Row); + } + + back = _Print (&ps); + va_end(ps.args); + return back; +} + + +UINTN +APrint ( + IN CONST CHAR8 *fmt, + ... + ) +/*++ + +Routine Description: + + For those whom really can't deal with unicode, a print + function that takes an ascii format string + +Arguments: + + fmt - ascii format string + +Returns: + + Length of string printed to the console + +--*/ + +{ + va_list args; + UINTN back; + + va_start (args, fmt); + back = _IPrint ((UINTN) -1, (UINTN) -1, ST->ConOut, NULL, fmt, args); + va_end (args); + return back; +} + + +STATIC +VOID +PFLUSH ( + IN OUT PRINT_STATE *ps + ) +{ + *ps->Pos = 0; + if (IsLocalPrint(ps->Output)) + ps->Output(ps->Context, ps->Buffer); + else + uefi_call_wrapper(ps->Output, 2, ps->Context, ps->Buffer); + ps->Pos = ps->Buffer; +} + +STATIC +VOID +PSETATTR ( + IN OUT PRINT_STATE *ps, + IN UINTN Attr + ) +{ + PFLUSH (ps); + + ps->RestoreAttr = ps->Attr; + if (ps->SetAttr) { + uefi_call_wrapper(ps->SetAttr, 2, ps->Context, Attr); + } + + ps->Attr = Attr; +} + +STATIC +VOID +PPUTC ( + IN OUT PRINT_STATE *ps, + IN CHAR16 c + ) +{ + // if this is a newline, add a carraige return + if (c == '\n') { + PPUTC (ps, '\r'); + } + + *ps->Pos = c; + ps->Pos += 1; + ps->Len += 1; + + // if at the end of the buffer, flush it + if (ps->Pos >= ps->End) { + PFLUSH(ps); + } +} + + +STATIC +CHAR16 +PGETC ( + IN POINTER *p + ) +{ + CHAR16 c; + + c = p->Ascii ? p->pc[p->Index] : p->pw[p->Index]; + p->Index += 1; + + return c; +} + + +STATIC +VOID +PITEM ( + IN OUT PRINT_STATE *ps + ) +{ + UINTN Len, i; + PRINT_ITEM *Item; + CHAR16 c; + + // Get the length of the item + Item = ps->Item; + Item->Item.Index = 0; + while (Item->Item.Index < Item->FieldWidth) { + c = PGETC(&Item->Item); + if (!c) { + Item->Item.Index -= 1; + break; + } + } + Len = Item->Item.Index; + + // if there is no item field width, use the items width + if (Item->FieldWidth == (UINTN) -1) { + Item->FieldWidth = Len; + } + + // if item is larger then width, update width + if (Len > Item->Width) { + Item->Width = Len; + } + + + // if pad field before, add pad char + if (Item->PadBefore) { + for (i=Item->Width; i < Item->FieldWidth; i+=1) { + PPUTC (ps, ' '); + } + } + + // pad item + for (i=Len; i < Item->Width; i++) { + PPUTC (ps, Item->Pad); + } + + // add the item + Item->Item.Index=0; + while (Item->Item.Index < Len) { + PPUTC (ps, PGETC(&Item->Item)); + } + + // If pad at the end, add pad char + if (!Item->PadBefore) { + for (i=Item->Width; i < Item->FieldWidth; i+=1) { + PPUTC (ps, ' '); + } + } +} + + +STATIC +UINTN +_Print ( + IN PRINT_STATE *ps + ) +/*++ + +Routine Description: + + %w.lF - w = width + l = field width + F = format of arg + + Args F: + 0 - pad with zeros + - - justify on left (default is on right) + , - add comma's to field + * - width provided on stack + n - Set output attribute to normal (for this field only) + h - Set output attribute to highlight (for this field only) + e - Set output attribute to error (for this field only) + l - Value is 64 bits + + a - ascii string + s - unicode string + X - fixed 8 byte value in hex + x - hex value + d - value as signed decimal + u - value as unsigned decimal + f - value as floating point + c - Unicode char + 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 + E - Set output attribute to error + % - Print a % + +Arguments: + + SystemTable - The system table + +Returns: + + Number of charactors written + +--*/ +{ + CHAR16 c; + UINTN Attr; + PRINT_ITEM Item; + CHAR16 Buffer[PRINT_STRING_LEN]; + + ps->Len = 0; + ps->Buffer = Buffer; + ps->Pos = Buffer; + ps->End = Buffer + PRINT_STRING_LEN - 1; + ps->Item = &Item; + + ps->fmt.Index = 0; + while ((c = PGETC(&ps->fmt))) { + + if (c != '%') { + PPUTC ( ps, c ); + continue; + } + + // setup for new item + Item.FieldWidth = (UINTN) -1; + Item.Width = 0; + Item.WidthParse = &Item.Width; + Item.Pad = ' '; + Item.PadBefore = TRUE; + Item.Comma = FALSE; + Item.Long = FALSE; + Item.Item.Ascii = FALSE; + Item.Item.pw = NULL; + ps->RestoreAttr = 0; + Attr = 0; + + while ((c = PGETC(&ps->fmt))) { + + switch (c) { + + case '%': + // + // %% -> % + // + Item.Scratch[0] = '%'; + Item.Scratch[1] = 0; + Item.Item.pw = Item.Scratch; + break; + + case '0': + Item.Pad = '0'; + break; + + case '-': + Item.PadBefore = FALSE; + break; + + case ',': + Item.Comma = TRUE; + break; + + case '.': + Item.WidthParse = &Item.FieldWidth; + break; + + case '*': + *Item.WidthParse = va_arg(ps->args, UINTN); + break; + + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + *Item.WidthParse = 0; + do { + *Item.WidthParse = *Item.WidthParse * 10 + c - '0'; + c = PGETC(&ps->fmt); + } while (c >= '0' && c <= '9') ; + ps->fmt.Index -= 1; + break; + + case 'a': + Item.Item.pc = va_arg(ps->args, CHAR8 *); + Item.Item.Ascii = TRUE; + if (!Item.Item.pc) { + Item.Item.pc = (CHAR8 *)"(null)"; + } + break; + + case 's': + Item.Item.pw = va_arg(ps->args, CHAR16 *); + if (!Item.Item.pw) { + Item.Item.pw = L"(null)"; + } + break; + + case 'c': + Item.Scratch[0] = (CHAR16) va_arg(ps->args, UINTN); + Item.Scratch[1] = 0; + Item.Item.pw = Item.Scratch; + break; + + case 'l': + Item.Long = TRUE; + break; + + case 'X': + Item.Width = Item.Long ? 16 : 8; + Item.Pad = '0'; +#if __GNUC__ >= 7 + __attribute__ ((fallthrough)); +#endif + case 'x': + ValueToHex ( + Item.Scratch, + Item.Long ? va_arg(ps->args, UINT64) : va_arg(ps->args, UINT32) + ); + Item.Item.pw = Item.Scratch; + + break; + + + case 'g': + GuidToString (Item.Scratch, va_arg(ps->args, EFI_GUID *)); + Item.Item.pw = Item.Scratch; + break; + + case 'u': + ValueToString ( + Item.Scratch, + Item.Comma, + Item.Long ? va_arg(ps->args, UINT64) : va_arg(ps->args, UINT32) + ); + Item.Item.pw = Item.Scratch; + break; + + case 'd': + ValueToString ( + Item.Scratch, + Item.Comma, + Item.Long ? va_arg(ps->args, INT64) : va_arg(ps->args, INT32) + ); + 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, + Item.Comma, + va_arg(ps->args, double) + ); + Item.Item.pw = Item.Scratch; + break; + + case 't': + TimeToString (Item.Scratch, va_arg(ps->args, EFI_TIME *)); + Item.Item.pw = Item.Scratch; + break; + + case 'r': + StatusToString (Item.Scratch, va_arg(ps->args, EFI_STATUS)); + Item.Item.pw = Item.Scratch; + break; + + case 'n': + PSETATTR(ps, ps->AttrNorm); + break; + + case 'h': + PSETATTR(ps, ps->AttrHighlight); + break; + + case 'e': + PSETATTR(ps, ps->AttrError); + break; + + case 'N': + Attr = ps->AttrNorm; + break; + + case 'H': + Attr = ps->AttrHighlight; + break; + + case 'E': + Attr = ps->AttrError; + break; + + default: + Item.Scratch[0] = '?'; + Item.Scratch[1] = 0; + Item.Item.pw = Item.Scratch; + break; + } + + // if we have an Item + if (Item.Item.pw) { + PITEM (ps); + break; + } + + // if we have an Attr set + if (Attr) { + PSETATTR(ps, Attr); + ps->RestoreAttr = 0; + break; + } + } + + if (ps->RestoreAttr) { + PSETATTR(ps, ps->RestoreAttr); + } + } + + // Flush buffer + PFLUSH (ps); + return ps->Len; +} + +STATIC CHAR8 Hex[] = {'0','1','2','3','4','5','6','7', + '8','9','A','B','C','D','E','F'}; + +VOID +ValueToHex ( + IN CHAR16 *Buffer, + IN UINT64 v + ) +{ + CHAR8 str[30], *p1; + CHAR16 *p2; + + if (!v) { + Buffer[0] = '0'; + Buffer[1] = 0; + return ; + } + + p1 = str; + p2 = Buffer; + + while (v) { + // Without the cast, the MSVC compiler may insert a reference to __allmull + *(p1++) = Hex[(UINTN)(v & 0xf)]; + v = RShiftU64 (v, 4); + } + + while (p1 != str) { + *(p2++) = *(--p1); + } + *p2 = 0; +} + + +VOID +ValueToString ( + IN CHAR16 *Buffer, + IN BOOLEAN Comma, + IN INT64 v + ) +{ + STATIC CHAR8 ca[] = { 3, 1, 2 }; + CHAR8 str[40], *p1; + CHAR16 *p2; + UINTN c, r; + + if (!v) { + Buffer[0] = '0'; + Buffer[1] = 0; + return ; + } + + p1 = str; + p2 = Buffer; + + if (v < 0) { + *(p2++) = '-'; + v = -v; + } + + while (v) { + v = (INT64)DivU64x32 ((UINT64)v, 10, &r); + *(p1++) = (CHAR8)r + '0'; + } + + c = (Comma ? ca[(p1 - str) % 3] : 999) + 1; + while (p1 != str) { + + c -= 1; + if (!c) { + *(p2++) = ','; + c = 3; + } + + *(p2++) = *(--p1); + } + *p2 = 0; +} + +VOID +FloatToString ( + IN CHAR16 *Buffer, + IN BOOLEAN Comma, + IN double v + ) +{ + /* + * Integer part. + */ + INTN i = (INTN)v; + ValueToString(Buffer, Comma, i); + + + /* + * Decimal point. + */ + UINTN x = StrLen(Buffer); + Buffer[x] = L'.'; + x++; + + + /* + * Keep fractional part. + */ + float f = (float)(v - i); + if (f < 0) f = -f; + + + /* + * Leading fractional zeroes. + */ + f *= 10.0; + while ( (f != 0) + && ((INTN)f == 0)) + { + Buffer[x] = L'0'; + x++; + f *= 10.0; + } + + + /* + * Fractional digits. + */ + while ((float)(INTN)f != f) + { + f *= 10; + } + ValueToString(Buffer + x, FALSE, (INTN)f); + return; +} + +VOID +TimeToString ( + OUT CHAR16 *Buffer, + IN EFI_TIME *Time + ) +{ + UINTN Hour, Year; + CHAR16 AmPm; + + AmPm = 'a'; + Hour = Time->Hour; + if (Time->Hour == 0) { + Hour = 12; + } else if (Time->Hour >= 12) { + AmPm = 'p'; + if (Time->Hour >= 13) { + Hour -= 12; + } + } + + Year = Time->Year % 100; + + // bugbug: for now just print it any old way + SPrint (Buffer, 0, L"%02d/%02d/%02d %02d:%02d%c", + Time->Month, + Time->Day, + Year, + Hour, + Time->Minute, + AmPm + ); +} + + + + +VOID +DumpHex ( + IN UINTN Indent, + IN UINTN Offset, + IN UINTN DataSize, + IN VOID *UserData + ) +{ + CHAR8 *Data, Val[50], Str[20], c; + UINTN Size, Index; + + UINTN ScreenCount; + UINTN TempColumn; + UINTN ScreenSize; + CHAR16 ReturnStr[1]; + + + uefi_call_wrapper(ST->ConOut->QueryMode, 4, ST->ConOut, ST->ConOut->Mode->Mode, &TempColumn, &ScreenSize); + ScreenCount = 0; + ScreenSize -= 2; + + Data = UserData; + while (DataSize) { + Size = 16; + if (Size > DataSize) { + Size = DataSize; + } + + for (Index=0; Index < Size; Index += 1) { + c = Data[Index]; + Val[Index*3+0] = Hex[c>>4]; + Val[Index*3+1] = Hex[c&0xF]; + Val[Index*3+2] = (Index == 7)?'-':' '; + Str[Index] = (c < ' ' || c > 'z') ? '.' : c; + } + + Val[Index*3] = 0; + Str[Index] = 0; + Print (L"%*a%X: %-.48a *%a*\n", Indent, "", Offset, Val, Str); + + Data += Size; + Offset += Size; + DataSize -= Size; + + ScreenCount++; + if (ScreenCount >= ScreenSize && ScreenSize != 0) { + // + // If ScreenSize == 0 we have the console redirected so don't + // block updates + // + ScreenCount = 0; + Print (L"Press Enter to continue :"); + Input (L"", ReturnStr, sizeof(ReturnStr)/sizeof(CHAR16)); + Print (L"\n"); + } + + } +} diff --git a/gnu-efi/lib/runtime/efirtlib.c b/gnu-efi/lib/runtime/efirtlib.c new file mode 100644 index 0000000..f782e4c --- /dev/null +++ b/gnu-efi/lib/runtime/efirtlib.c @@ -0,0 +1,145 @@ +/*++ + +Copyright (c) 1999 Intel Corporation + +Module Name: + + EfiRtLib.h + +Abstract: + + EFI Runtime library functions + + + +Revision History + +--*/ + +#include "efi.h" +#include "efilib.h" +#include "efirtlib.h" + +#ifndef __GNUC__ +#pragma RUNTIME_CODE(RtZeroMem) +#endif +VOID +RUNTIMEFUNCTION +RtZeroMem ( + IN VOID *Buffer, + IN UINTN Size + ) +{ + INT8 *pt; + + pt = Buffer; + while (Size--) { + *(pt++) = 0; + } +} + +#ifndef __GNUC__ +#pragma RUNTIME_CODE(RtSetMem) +#endif +VOID +RUNTIMEFUNCTION +RtSetMem ( + IN VOID *Buffer, + IN UINTN Size, + IN UINT8 Value + ) +{ + INT8 *pt; + + pt = Buffer; + while (Size--) { + *(pt++) = Value; + } +} + +#ifndef __GNUC__ +#pragma RUNTIME_CODE(RtCopyMem) +#endif +VOID +RUNTIMEFUNCTION +RtCopyMem ( + IN VOID *Dest, + IN CONST VOID *Src, + IN UINTN len + ) +{ + CHAR8 *d; + CONST CHAR8 *s = Src; + d = Dest; + while (len--) { + *(d++) = *(s++); + } +} + +#ifndef __GNUC__ +#pragma RUNTIME_CODE(RtCompareMem) +#endif +INTN +RUNTIMEFUNCTION +RtCompareMem ( + IN CONST VOID *Dest, + IN CONST VOID *Src, + IN UINTN len + ) +{ + CONST CHAR8 *d = Dest, *s = Src; + while (len--) { + if (*d != *s) { + return *d - *s; + } + + d += 1; + s += 1; + } + + return 0; +} + +#ifndef __GNUC__ +#pragma RUNTIME_CODE(RtCompareGuid) +#endif +INTN +RUNTIMEFUNCTION +RtCompareGuid ( + IN EFI_GUID *Guid1, + IN EFI_GUID *Guid2 + ) +/*++ + +Routine Description: + + Compares to GUIDs + +Arguments: + + Guid1 - guid to compare + Guid2 - guid to compare + +Returns: + = 0 if Guid1 == Guid2 + +--*/ +{ + INT32 *g1, *g2, r; + + // + // Compare 32 bits at a time + // + + g1 = (INT32 *) Guid1; + g2 = (INT32 *) Guid2; + + r = g1[0] - g2[0]; + r |= g1[1] - g2[1]; + r |= g1[2] - g2[2]; + r |= g1[3] - g2[3]; + + return r; +} + + diff --git a/gnu-efi/lib/runtime/rtdata.c b/gnu-efi/lib/runtime/rtdata.c new file mode 100644 index 0000000..3efcbf3 --- /dev/null +++ b/gnu-efi/lib/runtime/rtdata.c @@ -0,0 +1,65 @@ +/*++ + +Copyright (c) 1998 Intel Corporation + +Module Name: + + data.c + +Abstract: + + EFI library global data + + + +Revision History + +--*/ + +#include "lib.h" + + +// +// These globals are runtime globals +// +// N.B. The Microsoft C compiler will only put the data in the +// right data section if it is explicitly initialized.. +// + +#ifndef __GNUC__ +#pragma BEGIN_RUNTIME_DATA() +#endif + +// +// RT - pointer to the runtime table +// + +EFI_RUNTIME_SERVICES *RT; + +// +// LibStandalone - TRUE if lib is linked in as part of the firmware. +// N.B. The EFI fw sets this value directly +// + +BOOLEAN LibFwInstance; + +// +// EFIDebug - Debug mask +// + +UINTN EFIDebug = EFI_DBUG_MASK; + +// +// LibRuntimeDebugOut - Runtime Debug Output device +// + +SIMPLE_TEXT_OUTPUT_INTERFACE *LibRuntimeDebugOut; + +// +// LibRuntimeRaiseTPL, LibRuntimeRestoreTPL - pointers to Runtime functions from the +// Boot Services Table +// + +EFI_RAISE_TPL LibRuntimeRaiseTPL = NULL; +EFI_RESTORE_TPL LibRuntimeRestoreTPL = NULL; + diff --git a/gnu-efi/lib/runtime/rtlock.c b/gnu-efi/lib/runtime/rtlock.c new file mode 100644 index 0000000..2eafdca --- /dev/null +++ b/gnu-efi/lib/runtime/rtlock.c @@ -0,0 +1,102 @@ +/*++ + +Copyright (c) 1998 Intel Corporation + +Module Name: + + lock.c + +Abstract: + + Implements FLOCK + + + +Revision History + +--*/ + + +#include "lib.h" + + + +#ifndef __GNUC__ +#pragma RUNTIME_CODE(RtAcquireLock) +#endif +VOID +RtAcquireLock ( + IN FLOCK *Lock + ) +/*++ + +Routine Description: + + Raising to the task priority level of the mutual exclusion + lock, and then acquires ownership of the lock. + +Arguments: + + Lock - The lock to acquire + +Returns: + + Lock owned + +--*/ +{ + if (BS) { + if (BS->RaiseTPL != NULL) { + Lock->OwnerTpl = uefi_call_wrapper(BS->RaiseTPL, 1, Lock->Tpl); + } + } + else { + if (LibRuntimeRaiseTPL != NULL) { + Lock->OwnerTpl = LibRuntimeRaiseTPL(Lock->Tpl); + } + } + Lock->Lock += 1; + ASSERT (Lock->Lock == 1); +} + + +#ifndef __GNUC__ +#pragma RUNTIME_CODE(RtAcquireLock) +#endif +VOID +RtReleaseLock ( + IN FLOCK *Lock + ) +/*++ + +Routine Description: + + Releases ownership of the mutual exclusion lock, and + restores the previous task priority level. + +Arguments: + + Lock - The lock to release + +Returns: + + Lock unowned + +--*/ +{ + EFI_TPL Tpl; + + Tpl = Lock->OwnerTpl; + ASSERT(Lock->Lock == 1); + Lock->Lock -= 1; + if (BS) { + if (BS->RestoreTPL != NULL) { + uefi_call_wrapper(BS->RestoreTPL, 1, Tpl); + } + } + else { + if (LibRuntimeRestoreTPL != NULL) { + LibRuntimeRestoreTPL(Tpl); + } + } +} diff --git a/gnu-efi/lib/runtime/rtstr.c b/gnu-efi/lib/runtime/rtstr.c new file mode 100644 index 0000000..73965ca --- /dev/null +++ b/gnu-efi/lib/runtime/rtstr.c @@ -0,0 +1,231 @@ +/*++ + +Copyright (c) 1998 Intel Corporation + +Module Name: + + str.c + +Abstract: + + String runtime functions + + +Revision History + +--*/ + +#include "lib.h" + +#ifndef __GNUC__ +#pragma RUNTIME_CODE(RtAcquireLock) +#endif +INTN +RUNTIMEFUNCTION +RtStrCmp ( + IN CONST CHAR16 *s1, + IN CONST CHAR16 *s2 + ) +// compare strings +{ + while (*s1) { + if (*s1 != *s2) { + break; + } + + s1 += 1; + s2 += 1; + } + + return *s1 - *s2; +} + +#ifndef __GNUC__ +#pragma RUNTIME_CODE(RtStrCpy) +#endif +VOID +RUNTIMEFUNCTION +RtStrCpy ( + IN CHAR16 *Dest, + IN CONST CHAR16 *Src + ) +// copy strings +{ + while (*Src) { + *(Dest++) = *(Src++); + } + *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 + Size, (Len - Size) * sizeof(CHAR16), '\0'); + 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 +VOID +RUNTIMEFUNCTION +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 +UINTN +RUNTIMEFUNCTION +RtStrLen ( + IN CONST CHAR16 *s1 + ) +// 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 +UINTN +RUNTIMEFUNCTION +RtStrSize ( + IN CONST CHAR16 *s1 + ) +// string size +{ + UINTN len; + + for (len=0; *s1; s1+=1, len+=1) ; + return (len + 1) * sizeof(CHAR16); +} + +#ifndef __GNUC__ +#pragma RUNTIME_CODE(RtBCDtoDecimal) +#endif +UINT8 +RUNTIMEFUNCTION +RtBCDtoDecimal( + IN UINT8 BcdValue + ) +{ + UINTN High, Low; + + High = BcdValue >> 4; + Low = BcdValue - (High << 4); + + return ((UINT8)(Low + (High * 10))); +} + + +#ifndef __GNUC__ +#pragma RUNTIME_CODE(RtDecimaltoBCD) +#endif +UINT8 +RUNTIMEFUNCTION +RtDecimaltoBCD ( + IN UINT8 DecValue + ) +{ + UINTN High, Low; + + High = DecValue / 10; + Low = DecValue - (High * 10); + + return ((UINT8)(Low + (High << 4))); +} + + diff --git a/gnu-efi/lib/runtime/vm.c b/gnu-efi/lib/runtime/vm.c new file mode 100644 index 0000000..26e0c8e --- /dev/null +++ b/gnu-efi/lib/runtime/vm.c @@ -0,0 +1,105 @@ +/*++ + +Copyright (c) 1998 Intel Corporation + +Module Name: + + vm.c + +Abstract: + + EFI Hell to remap runtime address into the new virual address space + that was registered by the OS for RT calls. + + So the code image needs to be relocated. All pointers need to be + manually fixed up since the address map changes. + + GOOD LUCK NOT HAVING BUGS IN YOUR CODE! PLEASE TEST A LOT. MAKE SURE + EXIT BOOTSERVICES OVER WRITES ALL BOOTSERVICE MEMORY & DATA SPACES WHEN + YOU TEST. + +Revision History + +--*/ + +#include "lib.h" + +#ifndef __GNUC__ +#pragma RUNTIME_CODE(RtLibEnableVirtualMappings) +#endif +VOID +RUNTIMEFUNCTION +RtLibEnableVirtualMappings ( + VOID + ) +{ + EFI_CONVERT_POINTER ConvertPointer; + + // + // If this copy of the lib is linked into the firmware, then + // do not update the pointers yet. + // + + if (!LibFwInstance) { + + // + // Different components are updating to the new virtual + // mappings at differnt times. The only function that + // is safe to call at this notification is ConvertAddress + // + + ConvertPointer = RT->ConvertPointer; + + // + // Fix any pointers that the lib created, that may be needed + // during runtime. + // + + ConvertPointer (EFI_INTERNAL_PTR, (VOID **)&RT); + ConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&LibRuntimeDebugOut); + + ConvertPointer (EFI_INTERNAL_PTR, (VOID **)&LibRuntimeRaiseTPL); + ConvertPointer (EFI_INTERNAL_PTR, (VOID **)&LibRuntimeRestoreTPL); + + // that was it :^) + } +} + + +#ifndef __GNUC__ +#pragma RUNTIME_CODE(RtConvertList) +#endif +VOID +RUNTIMEFUNCTION +RtConvertList ( + IN UINTN DebugDisposition, + IN OUT LIST_ENTRY *ListHead + ) +{ + LIST_ENTRY *Link; + LIST_ENTRY *NextLink; + EFI_CONVERT_POINTER ConvertPointer; + + ConvertPointer = RT->ConvertPointer; + + // + // Convert all the Flink & Blink pointers in the list + // + + Link = ListHead; + do { + NextLink = Link->Flink; + + ConvertPointer ( + Link->Flink == ListHead ? DebugDisposition : 0, + (VOID **)&Link->Flink + ); + + ConvertPointer ( + Link->Blink == ListHead ? DebugDisposition : 0, + (VOID **)&Link->Blink + ); + + Link = NextLink; + } while (Link != ListHead); +} diff --git a/gnu-efi/lib/smbios.c b/gnu-efi/lib/smbios.c new file mode 100644 index 0000000..d349fb6 --- /dev/null +++ b/gnu-efi/lib/smbios.c @@ -0,0 +1,135 @@ +/*++ + +Copyright (c) 2000 Intel Corporation + +Module Name: + + Smbios.c + +Abstract: + + Lib fucntions for SMBIOS. Used to get system serial number and GUID + +Revision History + +--*/ + +#include "lib.h" + +/* + * We convert 32 bit values to pointers. In 64 bit mode the compiler will issue a + * warning stating that the value is too small for the pointer: + * "warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]" + * we can safely ignore them here. + */ +#ifdef __GNUC__ +#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" +#endif + +EFI_STATUS +LibGetSmbiosSystemGuidAndSerialNumber ( + IN EFI_GUID *SystemGuid, + OUT CHAR8 **SystemSerialNumber + ) +{ + EFI_STATUS Status; + SMBIOS_STRUCTURE_TABLE *SmbiosTable; + SMBIOS_STRUCTURE_POINTER Smbios; + SMBIOS_STRUCTURE_POINTER SmbiosEnd; + UINT16 Index; + + Status = LibGetSystemConfigurationTable(&SMBIOSTableGuid, (VOID**)&SmbiosTable); + if (EFI_ERROR(Status)) { + return EFI_NOT_FOUND; + } + + Smbios.Hdr = (SMBIOS_HEADER *)SmbiosTable->TableAddress; + SmbiosEnd.Raw = (UINT8 *)(SmbiosTable->TableAddress + SmbiosTable->TableLength); + for (Index = 0; Index < SmbiosTable->TableLength ; Index++) { + if (Smbios.Hdr->Type == 1) { + if (Smbios.Hdr->Length < 0x19) { + // + // Older version did not support Guid and Serial number + // + continue; + } + + // + // SMBIOS tables are byte packed so we need to do a byte copy to + // prevend alignment faults on IA-64. + + CopyMem (SystemGuid, &Smbios.Type1->Uuid, sizeof(EFI_GUID)); + *SystemSerialNumber = LibGetSmbiosString(&Smbios, Smbios.Type1->SerialNumber); + return EFI_SUCCESS; + } + + // + // Make Smbios point to the next record + // + LibGetSmbiosString (&Smbios, -1); + + if (Smbios.Raw >= SmbiosEnd.Raw) { + // + // SMBIOS 2.1 incorrectly stated the length of SmbiosTable as 0x1e. + // given this we must double check against the lenght of + /// the structure. My home PC has this bug.ruthard + // + return EFI_SUCCESS; + } + } + + return EFI_SUCCESS; +} + +CHAR8* +LibGetSmbiosString ( + IN SMBIOS_STRUCTURE_POINTER *Smbios, + IN UINT16 StringNumber + ) +/*++ + + Return SMBIOS string given the string number. + + Arguments: + Smbios - Pointer to SMBIOS structure + StringNumber - String number to return. -1 is used to skip all strings and + point to the next SMBIOS structure. + + Returns: + Pointer to string, or pointer to next SMBIOS strcuture if StringNumber == -1 +--*/ +{ + UINT16 Index; + CHAR8 *String; + + // + // Skip over formatted section + // + String = (CHAR8 *)(Smbios->Raw + Smbios->Hdr->Length); + + // + // Look through unformated section + // + for (Index = 1; Index <= StringNumber; Index++) { + if (StringNumber == Index) { + return String; + } + + // + // Skip string + // + for (; *String != 0; String++); + String++; + + if (*String == 0) { + // + // If double NULL then we are done. + // Retrun pointer to next structure in Smbios. + // if you pass in a -1 you will always get here + // + Smbios->Raw = (UINT8 *)++String; + return NULL; + } + } + return NULL; +} diff --git a/gnu-efi/lib/sread.c b/gnu-efi/lib/sread.c new file mode 100644 index 0000000..888f954 --- /dev/null +++ b/gnu-efi/lib/sread.c @@ -0,0 +1,358 @@ +/*++ + +Copyright (c) 1998 Intel Corporation + +Module Name: + + sread.c + +Abstract: + + Simple read file access + + + +Revision History + +--*/ + +#include "lib.h" + +#define SIMPLE_READ_SIGNATURE EFI_SIGNATURE_32('s','r','d','r') +typedef struct _SIMPLE_READ_FILE { + UINTN Signature; + BOOLEAN FreeBuffer; + VOID *Source; + UINTN SourceSize; + EFI_FILE_HANDLE FileHandle; +} SIMPLE_READ_HANDLE; + + + +EFI_STATUS +OpenSimpleReadFile ( + IN BOOLEAN BootPolicy, + IN VOID *SourceBuffer OPTIONAL, + IN UINTN SourceSize, + IN OUT EFI_DEVICE_PATH **FilePath, + OUT EFI_HANDLE *DeviceHandle, + OUT SIMPLE_READ_FILE *SimpleReadHandle + ) +/*++ + +Routine Description: + + Opens a file for (simple) reading. The simple read abstraction + will access the file either from a memory copy, from a file + system interface, or from the load file interface. + +Arguments: + +Returns: + + A handle to access the file + +--*/ +{ + SIMPLE_READ_HANDLE *FHand; + EFI_DEVICE_PATH *UserFilePath; + EFI_DEVICE_PATH *TempFilePath; + EFI_DEVICE_PATH *TempFilePathPtr; + FILEPATH_DEVICE_PATH *FilePathNode; + EFI_FILE_HANDLE FileHandle, LastHandle; + EFI_STATUS Status; + EFI_LOAD_FILE_INTERFACE *LoadFile; + + FHand = NULL; + UserFilePath = *FilePath; + + // + // Allocate a new simple read handle structure + // + + FHand = AllocateZeroPool (sizeof(SIMPLE_READ_HANDLE)); + if (!FHand) { + Status = EFI_OUT_OF_RESOURCES; + goto Done; + } + + *SimpleReadHandle = (SIMPLE_READ_FILE) FHand; + FHand->Signature = SIMPLE_READ_SIGNATURE; + + // + // If the caller passed a copy of the file, then just use it + // + + if (SourceBuffer) { + FHand->Source = SourceBuffer; + FHand->SourceSize = SourceSize; + *DeviceHandle = NULL; + Status = EFI_SUCCESS; + goto Done; + } + + // + // Attempt to access the file via a file system interface + // + + FileHandle = NULL; + Status = uefi_call_wrapper(BS->LocateDevicePath, 3, &FileSystemProtocol, FilePath, DeviceHandle); + if (!EFI_ERROR(Status)) { + FileHandle = LibOpenRoot (*DeviceHandle); + } + + Status = FileHandle ? EFI_SUCCESS : EFI_UNSUPPORTED; + + // + // To access as a filesystem, the filepath should only + // contain filepath components. Follow the filepath nodes + // and find the target file + // + + FilePathNode = (FILEPATH_DEVICE_PATH *) *FilePath; + while (!IsDevicePathEnd(&FilePathNode->Header)) { + + // + // For filesystem access each node should be a filepath component + // + + if (DevicePathType(&FilePathNode->Header) != MEDIA_DEVICE_PATH || + DevicePathSubType(&FilePathNode->Header) != MEDIA_FILEPATH_DP) { + Status = EFI_UNSUPPORTED; + } + + // + // If there's been an error, stop + // + + if (EFI_ERROR(Status)) { + break; + } + + // + // Open this file path node + // + + LastHandle = FileHandle; + FileHandle = NULL; + + Status = uefi_call_wrapper( + LastHandle->Open, + 5, + LastHandle, + &FileHandle, + FilePathNode->PathName, + EFI_FILE_MODE_READ, + 0 + ); + + // + // Close the last node + // + + uefi_call_wrapper(LastHandle->Close, 1, LastHandle); + + // + // Get the next node + // + + FilePathNode = (FILEPATH_DEVICE_PATH *) NextDevicePathNode(&FilePathNode->Header); + } + + // + // If success, return the FHand + // + + if (!EFI_ERROR(Status)) { + ASSERT(FileHandle); + FHand->FileHandle = FileHandle; + goto Done; + } + + // + // Cleanup from filesystem access + // + + if (FileHandle) { + uefi_call_wrapper(FileHandle->Close, 1, FileHandle); + FileHandle = NULL; + *FilePath = UserFilePath; + } + + // + // If the error is something other then unsupported, return it + // + + if (Status != EFI_UNSUPPORTED) { + goto Done; + } + + // + // Attempt to access the file via the load file protocol + // + + Status = LibDevicePathToInterface (&LoadFileProtocol, *FilePath, (VOID*)&LoadFile); + if (!EFI_ERROR(Status)) { + + TempFilePath = DuplicateDevicePath (*FilePath); + + TempFilePathPtr = TempFilePath; + + Status = uefi_call_wrapper(BS->LocateDevicePath, 3, &LoadFileProtocol, &TempFilePath, DeviceHandle); + + FreePool (TempFilePathPtr); + + // + // Determine the size of buffer needed to hold the file + // + + SourceSize = 0; + Status = uefi_call_wrapper( + LoadFile->LoadFile, + 5, + LoadFile, + *FilePath, + BootPolicy, + &SourceSize, + NULL + ); + + // + // We expect a buffer too small error to inform us + // of the buffer size needed + // + + if (Status == EFI_BUFFER_TOO_SMALL) { + SourceBuffer = AllocatePool (SourceSize); + + if (SourceBuffer) { + FHand->FreeBuffer = TRUE; + FHand->Source = SourceBuffer; + FHand->SourceSize = SourceSize; + + Status = uefi_call_wrapper( + LoadFile->LoadFile, + 5, + LoadFile, + *FilePath, + BootPolicy, + &SourceSize, + SourceBuffer + ); + } + } + + // + // If success, return FHand + // + + if (!EFI_ERROR(Status) || Status == EFI_ALREADY_STARTED) { + goto Done; + } + } + + // + // Nothing else to try + // + + DEBUG ((D_LOAD|D_WARN, "OpenSimpleReadFile: Device did not support a known load protocol\n")); + Status = EFI_UNSUPPORTED; + +Done: + + // + // If the file was not accessed, clean up + // + if (EFI_ERROR(Status) && (Status != EFI_ALREADY_STARTED)) { + if (FHand) { + if (FHand->FreeBuffer) { + FreePool (FHand->Source); + } + + FreePool (FHand); + } + } + + return Status; +} + +EFI_STATUS +ReadSimpleReadFile ( + IN SIMPLE_READ_FILE UserHandle, + IN UINTN Offset, + IN OUT UINTN *ReadSize, + OUT VOID *Buffer + ) +{ + UINTN EndPos; + SIMPLE_READ_HANDLE *FHand; + EFI_STATUS Status; + + FHand = UserHandle; + ASSERT (FHand->Signature == SIMPLE_READ_SIGNATURE); + if (FHand->Source) { + + // + // Move data from our local copy of the file + // + + EndPos = Offset + *ReadSize; + if (EndPos > FHand->SourceSize) { + *ReadSize = FHand->SourceSize - Offset; + if (Offset >= FHand->SourceSize) { + *ReadSize = 0; + } + } + + CopyMem (Buffer, (CHAR8 *) FHand->Source + Offset, *ReadSize); + Status = EFI_SUCCESS; + + } else { + + // + // Read data from the file + // + + Status = uefi_call_wrapper(FHand->FileHandle->SetPosition, 2, FHand->FileHandle, Offset); + + if (!EFI_ERROR(Status)) { + Status = uefi_call_wrapper(FHand->FileHandle->Read, 3, FHand->FileHandle, ReadSize, Buffer); + } + } + + return Status; +} + + +VOID +CloseSimpleReadFile ( + IN SIMPLE_READ_FILE UserHandle + ) +{ + SIMPLE_READ_HANDLE *FHand; + + FHand = UserHandle; + ASSERT (FHand->Signature == SIMPLE_READ_SIGNATURE); + + // + // Free any file handle we opened + // + + if (FHand->FileHandle) { + uefi_call_wrapper(FHand->FileHandle->Close, 1, FHand->FileHandle); + } + + // + // If we allocated the Source buffer, free it + // + + if (FHand->FreeBuffer) { + FreePool (FHand->Source); + } + + // + // Done with this simple read file handle + // + + FreePool (FHand); +} diff --git a/gnu-efi/lib/str.c b/gnu-efi/lib/str.c new file mode 100644 index 0000000..9a89f30 --- /dev/null +++ b/gnu-efi/lib/str.c @@ -0,0 +1,432 @@ +/*++ + +Copyright (c) 1998 Intel Corporation + +Module Name: + + str.c + +Abstract: + + + + +Revision History + +--*/ + +#include "lib.h" + + +INTN +StrCmp ( + IN CONST CHAR16 *s1, + IN CONST CHAR16 *s2 + ) +// compare strings +{ + return RtStrCmp(s1, s2); +} + +INTN +StrnCmp ( + IN CONST CHAR16 *s1, + IN CONST CHAR16 *s2, + IN UINTN len + ) +// compare strings +{ + while (*s1 && len) { + if (*s1 != *s2) { + break; + } + + s1 += 1; + s2 += 1; + len -= 1; + } + + return len ? *s1 - *s2 : 0; +} + + +INTN EFIAPI +LibStubStriCmp ( + IN EFI_UNICODE_COLLATION_INTERFACE *This EFI_UNUSED, + IN CHAR16 *s1, + IN CHAR16 *s2 + ) +{ + return StrCmp (s1, s2); +} + +VOID EFIAPI +LibStubStrLwrUpr ( + IN EFI_UNICODE_COLLATION_INTERFACE *This EFI_UNUSED, + IN CHAR16 *Str EFI_UNUSED + ) +{ +} + +INTN +StriCmp ( + IN CONST CHAR16 *s1, + IN CONST CHAR16 *s2 + ) +// compare strings +{ + if (UnicodeInterface == &LibStubUnicodeInterface) + return UnicodeInterface->StriColl(UnicodeInterface, (CHAR16 *)s1, (CHAR16 *)s2); + else + return uefi_call_wrapper(UnicodeInterface->StriColl, 3, UnicodeInterface, (CHAR16 *)s1, (CHAR16 *)s2); +} + +VOID +StrLwr ( + IN CHAR16 *Str + ) +// lwoer case string +{ + if (UnicodeInterface == &LibStubUnicodeInterface) + UnicodeInterface->StrLwr(UnicodeInterface, Str); + else uefi_call_wrapper(UnicodeInterface->StrLwr, 2, UnicodeInterface, Str); +} + +VOID +StrUpr ( + IN CHAR16 *Str + ) +// upper case string +{ + if (UnicodeInterface == &LibStubUnicodeInterface) + UnicodeInterface->StrUpr(UnicodeInterface, Str); + else uefi_call_wrapper(UnicodeInterface->StrUpr, 2, UnicodeInterface, Str); +} + +VOID +StrCpy ( + IN CHAR16 *Dest, + IN CONST CHAR16 *Src + ) +// copy strings +{ + 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, + IN CONST CHAR16 *Src + ) +{ + 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 + ) +// string length +{ + return RtStrLen(s1); +} + +UINTN +StrSize ( + IN CONST CHAR16 *s1 + ) +// string size +{ + return RtStrSize(s1); +} + +CHAR16 * +StrDuplicate ( + IN CONST CHAR16 *Src + ) +// duplicate a string +{ + CHAR16 *Dest; + UINTN Size; + + Size = StrSize(Src); + Dest = AllocatePool (Size); + if (Dest) { + CopyMem (Dest, Src, Size); + } + return Dest; +} + +UINTN +strlena ( + IN CONST CHAR8 *s1 + ) +// string length +{ + UINTN len; + + for (len=0; *s1; s1+=1, len+=1) ; + return len; +} + +UINTN +strcmpa ( + IN CONST CHAR8 *s1, + IN CONST CHAR8 *s2 + ) +// compare strings +{ + while (*s1) { + if (*s1 != *s2) { + break; + } + + s1 += 1; + s2 += 1; + } + + return *s1 - *s2; +} + +UINTN +strncmpa ( + IN CONST CHAR8 *s1, + IN CONST CHAR8 *s2, + IN UINTN len + ) +// compare strings +{ + while (*s1 && len) { + if (*s1 != *s2) { + break; + } + + s1 += 1; + s2 += 1; + len -= 1; + } + + return len ? *s1 - *s2 : 0; +} + + + +UINTN +xtoi ( + CONST CHAR16 *str + ) +// convert hex string to uint +{ + UINTN u; + CHAR16 c; + + // skip preceeding white space + while (*str && *str == ' ') { + str += 1; + } + + // convert hex digits + u = 0; + while ((c = *(str++))) { + if (c >= 'a' && c <= 'f') { + c -= 'a' - 'A'; + } + + if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F')) { + u = (u << 4) | (c - (c >= 'A' ? 'A'-10 : '0')); + } else { + break; + } + } + + return u; +} + +UINTN +Atoi ( + CONST CHAR16 *str + ) +// convert hex string to uint +{ + UINTN u; + CHAR16 c; + + // skip preceeding white space + while (*str && *str == ' ') { + str += 1; + } + + // convert digits + u = 0; + while ((c = *(str++))) { + if (c >= '0' && c <= '9') { + u = (u * 10) + c - '0'; + } else { + break; + } + } + + return u; +} + +BOOLEAN +MetaMatch ( + IN CHAR16 *String, + IN CHAR16 *Pattern + ) +{ + CHAR16 c, p, l; + + for (; ;) { + p = *Pattern; + Pattern += 1; + + switch (p) { + case 0: + // End of pattern. If end of string, TRUE match + return *String ? FALSE : TRUE; + + case '*': + // Match zero or more chars + while (*String) { + if (MetaMatch (String, Pattern)) { + return TRUE; + } + String += 1; + } + return MetaMatch (String, Pattern); + + case '?': + // Match any one char + if (!*String) { + return FALSE; + } + String += 1; + break; + + case '[': + // Match char set + c = *String; + if (!c) { + return FALSE; // syntax problem + } + + l = 0; + while ((p = *Pattern++)) { + if (p == ']') { + return FALSE; + } + + if (p == '-') { // if range of chars, + p = *Pattern; // get high range + if (p == 0 || p == ']') { + return FALSE; // syntax problem + } + + if (c >= l && c <= p) { // if in range, + break; // it's a match + } + } + + l = p; + if (c == p) { // if char matches + break; // move on + } + } + + // skip to end of match char set + while (p && p != ']') { + p = *Pattern; + Pattern += 1; + } + + String += 1; + break; + + default: + c = *String; + if (c != p) { + return FALSE; + } + + String += 1; + break; + } + } +} + + +BOOLEAN EFIAPI +LibStubMetaiMatch ( + IN EFI_UNICODE_COLLATION_INTERFACE *This EFI_UNUSED, + IN CHAR16 *String, + IN CHAR16 *Pattern + ) +{ + return MetaMatch (String, Pattern); +} + + +BOOLEAN +MetaiMatch ( + IN CHAR16 *String, + IN CHAR16 *Pattern + ) +{ + if (UnicodeInterface == &LibStubUnicodeInterface) + return UnicodeInterface->MetaiMatch(UnicodeInterface, String, Pattern); + else return uefi_call_wrapper(UnicodeInterface->MetaiMatch, 3, UnicodeInterface, String, Pattern); +} diff --git a/include/arch/uefi/vga.h b/include/arch/uefi/vga.h deleted file mode 100644 index 52c20c7..0000000 --- a/include/arch/uefi/vga.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef ARCH_I386_VGA_H -#define ARCH_I386_VGA_H - -#include - -enum vga_colors { - BLACK = 0, - BLUE = 1, - GREEN = 2, - CYAN = 3, - RED = 4, - MAGENTA = 5, - BROWN = 6, - LIGHT_GREY = 7, - DARK_GREY = 8, - LIGHT_BLUE = 9, - LIGHT_GREEN = 10, - LIGHT_CYAN = 11, - LIGHT_RED = 12, - LIGHT_MAGENTA = 13, - LIGHT_BROWN = 14, - WHITE = 15 -}; - -static inline uint8_t vga_color_set(enum vga_colors fg, enum vga_colors bg) { return bg << 4 | fg; } - -static inline uint16_t vga_entry(uint8_t uc, uint8_t color) { return color << 8 | uc; } - -#endif diff --git a/include/efi/arm/efibind.h b/include/efi/arm/efibind.h deleted file mode 100644 index 40a5a9c..0000000 --- a/include/efi/arm/efibind.h +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copright (C) 2014 - 2015 Linaro Ltd. - * Author: Ard Biesheuvel - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice and this list of conditions, without modification. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * Alternatively, this software may be distributed under the terms of the - * GNU General Public License as published by the Free Software Foundation; - * either version 2 of the License, or (at your option) any later version. - */ - -#if !defined(_MSC_VER) && (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L )) - -// ANSI C 1999/2000 stdint.h integer width declarations - -typedef unsigned long long uint64_t; -typedef long long int64_t; -typedef unsigned int uint32_t; -typedef int int32_t; -typedef unsigned short uint16_t; -typedef short int16_t; -typedef unsigned char uint8_t; -typedef signed char int8_t; // unqualified 'char' is unsigned on ARM - -#else -#include -#endif - -/* - * This prevents GCC from emitting GOT based relocations, and use R_ARM_REL32 - * relative relocations instead, which are more suitable for static binaries. - */ -#ifdef __GNUC__ -#pragma GCC visibility push (hidden) -#endif - -// -// Basic EFI types of various widths -// - -#ifndef __WCHAR_TYPE__ -# define __WCHAR_TYPE__ short -#endif - -typedef uint64_t UINT64; -typedef int64_t INT64; - -typedef uint32_t UINT32; -typedef int32_t INT32; - -typedef uint16_t UINT16; -typedef int16_t INT16; -typedef uint8_t UINT8; -typedef int8_t INT8; -typedef __WCHAR_TYPE__ WCHAR; - -#undef VOID -#define VOID void - -typedef int32_t INTN; -typedef uint32_t UINTN; - -#define EFIERR(a) (0x80000000 | a) -#define EFI_ERROR_MASK 0x80000000 -#define EFIERR_OEM(a) (0xc0000000 | a) - -#define BAD_POINTER 0xFBFBFBFB -#define MAX_ADDRESS 0xFFFFFFFF - -#define BREAKPOINT() while (TRUE); - -// -// Pointers must be aligned to these address to function -// - -#define MIN_ALIGNMENT_SIZE 4 - -#define ALIGN_VARIABLE(Value ,Adjustment) \ - (UINTN)Adjustment = 0; \ - if((UINTN)Value % MIN_ALIGNMENT_SIZE) \ - (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \ - Value = (UINTN)Value + (UINTN)Adjustment - - -// -// Define macros to build data structure signatures from characters. -// - -#define EFI_SIGNATURE_16(A,B) ((A) | (B<<8)) -#define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16)) -#define EFI_SIGNATURE_64(A,B,C,D,E,F,G,H) (EFI_SIGNATURE_32(A,B,C,D) | ((UINT64)(EFI_SIGNATURE_32(E,F,G,H)) << 32)) - -// -// EFIAPI - prototype calling convention for EFI function pointers -// BOOTSERVICE - prototype for implementation of a boot service interface -// RUNTIMESERVICE - prototype for implementation of a runtime service interface -// RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service -// RUNTIME_CODE - pragma macro for declaring runtime code -// - -#ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options -#define EFIAPI // Substitute expresion to force C calling convention -#endif - -#define BOOTSERVICE -#define RUNTIMESERVICE -#define RUNTIMEFUNCTION - - -#define RUNTIME_CODE(a) alloc_text("rtcode", a) -#define BEGIN_RUNTIME_DATA() data_seg("rtdata") -#define END_RUNTIME_DATA() data_seg("") - -#define VOLATILE volatile - -#define MEMORY_FENCE __sync_synchronize - -// -// When build similiar to FW, then link everything together as -// 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 ( \ - VOID *ImageHandle, \ - VOID *SystemTable \ - ) \ - { \ - return InitFunction(ImageHandle, \ - SystemTable); \ - } \ - \ - EFI_STATUS efi_main( \ - EFI_HANDLE image, \ - EFI_SYSTEM_TABLE *systab \ - ) __attribute__((weak, \ - alias ("InitializeDriver"))); -#endif - -#define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \ - (_if)->LoadInternal(type, name, entry) - - -// -// Some compilers don't support the forward reference construct: -// typedef struct XXXXX -// -// The following macro provide a workaround for such cases. - -#define INTERFACE_DECL(x) struct x - -#define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__) -#define EFI_FUNCTION diff --git a/include/efi/arm/efisetjmp_arch.h b/include/efi/arm/efisetjmp_arch.h deleted file mode 100644 index 3a09ea5..0000000 --- a/include/efi/arm/efisetjmp_arch.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef GNU_EFI_ARM_SETJMP_H -#define GNU_EFI_ARM_SETJMP_H - -#define JMPBUF_ALIGN 4 - -typedef struct { - UINT32 R3; // A copy of R13 - UINT32 R4; - UINT32 R5; - UINT32 R6; - UINT32 R7; - UINT32 R8; - UINT32 R9; - UINT32 R10; - UINT32 R11; - UINT32 R12; - UINT32 R13; - UINT32 R14; -} ALIGN(JMPBUF_ALIGN) jmp_buf; - -#endif /* GNU_EFI_ARM_SETJMP_H */ diff --git a/include/efi/mips64el/efilibplat.h b/include/efi/mips64el/efilibplat.h deleted file mode 100644 index 70a0786..0000000 --- a/include/efi/mips64el/efilibplat.h +++ /dev/null @@ -1,25 +0,0 @@ -/*++ - -Copyright (c) 1998 Intel Corporation - -Module Name: - - efilibplat.h - -Abstract: - - EFI to compile bindings - - - - -Revision History - ---*/ - -VOID -InitializeLibPlatform ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ); - diff --git a/include/efi/x86_64/efibind.h b/include/efi/x86_64/efibind.h deleted file mode 100644 index 4309f9f..0000000 --- a/include/efi/x86_64/efibind.h +++ /dev/null @@ -1,390 +0,0 @@ -/*++ - -Copyright (c) 1998 Intel Corporation - -Module Name: - - efefind.h - -Abstract: - - EFI to compile bindings - - - - -Revision History - ---*/ -#ifndef X86_64_EFI_BIND -#define X86_64_EFI_BIND -#ifndef __GNUC__ -#pragma pack() -#endif - -#if defined(GNU_EFI_USE_MS_ABI) - #if (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)))||(defined(__clang__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 2))) - #define HAVE_USE_MS_ABI 1 - #else - #error Compiler is too old for GNU_EFI_USE_MS_ABI - #endif -#endif - -// -// Basic int types of various widths -// - -#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L ) - - // No ANSI C 1999/2000 stdint.h integer width declarations - - #if defined(_MSC_EXTENSIONS) - - // Use Microsoft C compiler integer width declarations - - typedef unsigned __int64 uint64_t; - typedef __int64 int64_t; - typedef unsigned __int32 uint32_t; - typedef __int32 int32_t; - typedef unsigned short uint16_t; - typedef short int16_t; - typedef unsigned char uint8_t; - typedef char int8_t; - #elif defined(__GNUC__) - typedef int __attribute__((__mode__(__DI__))) int64_t; - typedef unsigned int __attribute__((__mode__(__DI__))) uint64_t; - typedef unsigned int uint32_t; - typedef int int32_t; - typedef unsigned short uint16_t; - typedef short int16_t; - typedef unsigned char uint8_t; - typedef signed char int8_t; - #elif defined(UNIX_LP64) - - /* Use LP64 programming model from C_FLAGS for integer width declarations */ - - typedef unsigned long uint64_t; - typedef long int64_t; - typedef unsigned int uint32_t; - typedef int int32_t; - typedef unsigned short uint16_t; - typedef short int16_t; - typedef unsigned char uint8_t; - typedef char int8_t; - #else - - /* Assume P64 programming model from C_FLAGS for integer width declarations */ - - typedef unsigned long long uint64_t __attribute__((aligned (8))); - typedef long long int64_t __attribute__((aligned (8))); - typedef unsigned int uint32_t; - typedef int int32_t; - typedef unsigned short uint16_t; - typedef short int16_t; - typedef unsigned char uint8_t; - typedef char int8_t; - #endif -#elif defined(__GNUC__) - #include -#endif - -// -// Basic EFI types of various widths -// - -#ifndef __WCHAR_TYPE__ -# define __WCHAR_TYPE__ short -#endif - -typedef uint64_t UINT64; -typedef int64_t INT64; - -#ifndef _BASETSD_H_ - typedef uint32_t UINT32; - typedef int32_t INT32; -#endif - -typedef uint16_t UINT16; -typedef int16_t INT16; -typedef uint8_t UINT8; -typedef int8_t INT8; -typedef __WCHAR_TYPE__ WCHAR; - -#undef VOID -#define VOID void - - -typedef int64_t INTN; -typedef uint64_t UINTN; - -#ifdef EFI_NT_EMULATOR - #define POST_CODE(_Data) -#else - #ifdef EFI_DEBUG -#define POST_CODE(_Data) __asm mov eax,(_Data) __asm out 0x80,al - #else - #define POST_CODE(_Data) - #endif -#endif - -#define EFIERR(a) (0x8000000000000000 | a) -#define EFI_ERROR_MASK 0x8000000000000000 -#define EFIERR_OEM(a) (0xc000000000000000 | a) - - -#define BAD_POINTER 0xFBFBFBFBFBFBFBFB -#define MAX_ADDRESS 0xFFFFFFFFFFFFFFFF - -#ifdef EFI_NT_EMULATOR - #define BREAKPOINT() __asm { int 3 } -#else - #define BREAKPOINT() while (TRUE); // Make it hang on Bios[Dbg]32 -#endif - -// -// Pointers must be aligned to these address to function -// - -#define MIN_ALIGNMENT_SIZE 4 - -#define ALIGN_VARIABLE(Value ,Adjustment) \ - (UINTN)Adjustment = 0; \ - if((UINTN)Value % MIN_ALIGNMENT_SIZE) \ - (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \ - Value = (UINTN)Value + (UINTN)Adjustment - - -// -// Define macros to build data structure signatures from characters. -// - -#define EFI_SIGNATURE_16(A,B) ((A) | (B<<8)) -#define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16)) -#define EFI_SIGNATURE_64(A,B,C,D,E,F,G,H) (EFI_SIGNATURE_32(A,B,C,D) | ((UINT64)(EFI_SIGNATURE_32(E,F,G,H)) << 32)) -// -// To export & import functions in the EFI emulator environment -// - -#ifdef EFI_NT_EMULATOR - #define EXPORTAPI __declspec( dllexport ) -#else - #define EXPORTAPI -#endif - - -// -// EFIAPI - prototype calling convention for EFI function pointers -// BOOTSERVICE - prototype for implementation of a boot service interface -// RUNTIMESERVICE - prototype for implementation of a runtime service interface -// RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service -// RUNTIME_CODE - pragma macro for declaring runtime code -// - -#ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options - #ifdef _MSC_EXTENSIONS - #define EFIAPI __cdecl // Force C calling convention for Microsoft C compiler - #elif defined(HAVE_USE_MS_ABI) - // Force amd64/ms calling conventions. - #define EFIAPI __attribute__((ms_abi)) - #else - #define EFIAPI // Substitute expresion to force C calling convention - #endif -#endif - -#define BOOTSERVICE -//#define RUNTIMESERVICE(proto,a) alloc_text("rtcode",a); proto a -//#define RUNTIMEFUNCTION(proto,a) alloc_text("rtcode",a); proto a -#define RUNTIMESERVICE -#define RUNTIMEFUNCTION - - -#define RUNTIME_CODE(a) alloc_text("rtcode", a) -#define BEGIN_RUNTIME_DATA() data_seg("rtdata") -#define END_RUNTIME_DATA() data_seg("") - -#define VOLATILE volatile - -#define MEMORY_FENCE() - -#ifdef EFI_NT_EMULATOR - -// -// To help ensure proper coding of integrated drivers, they are -// compiled as DLLs. In NT they require a dll init entry pointer. -// The macro puts a stub entry point into the DLL so it will load. -// - -#define EFI_DRIVER_ENTRY_POINT(InitFunction) \ - UINTN \ - __stdcall \ - _DllMainCRTStartup ( \ - UINTN Inst, \ - UINTN reason_for_call, \ - VOID *rserved \ - ) \ - { \ - return 1; \ - } \ - \ - int \ - EXPORTAPI \ - __cdecl \ - InitializeDriver ( \ - void *ImageHandle, \ - void *SystemTable \ - ) \ - { \ - return InitFunction(ImageHandle, SystemTable); \ - } - - - #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \ - (_if)->LoadInternal(type, name, NULL) - -#else // EFI_NT_EMULATOR - -// -// When build similiar to FW, then link everything together as -// 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 ( \ - VOID *ImageHandle, \ - VOID *SystemTable \ - ) \ - { \ - return InitFunction(ImageHandle, \ - SystemTable); \ - } \ - \ - EFI_STATUS efi_main( \ - EFI_HANDLE image, \ - EFI_SYSTEM_TABLE *systab \ - ) __attribute__((weak, \ - alias ("InitializeDriver"))); -#endif - - #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \ - (_if)->LoadInternal(type, name, entry) - -#endif // EFI_NT_EMULATOR - -// -// Some compilers don't support the forward reference construct: -// typedef struct XXXXX -// -// The following macro provide a workaround for such cases. -// -#ifdef NO_INTERFACE_DECL -#define INTERFACE_DECL(x) -#else -#if defined(__GNUC__) || defined(_MSC_EXTENSIONS) -#define INTERFACE_DECL(x) struct x -#else -#define INTERFACE_DECL(x) typedef struct x -#endif -#endif - -/* for x86_64, EFI_FUNCTION_WRAPPER must be defined */ -#if defined(HAVE_USE_MS_ABI) -#define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__) -#else -/* - Credits for macro-magic: - https://groups.google.com/forum/?fromgroups#!topic/comp.std.c/d-6Mj5Lko_s - http://efesx.com/2010/08/31/overloading-macros/ -*/ -#define __VA_NARG__(...) \ - __VA_NARG_(_0, ## __VA_ARGS__, __RSEQ_N()) -#define __VA_NARG_(...) \ - __VA_ARG_N(__VA_ARGS__) -#define __VA_ARG_N( \ - _0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,N,...) N -#define __RSEQ_N() \ - 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 - -#define __VA_ARG_NSUFFIX__(prefix,...) \ - __VA_ARG_NSUFFIX_N(prefix, __VA_NARG__(__VA_ARGS__)) -#define __VA_ARG_NSUFFIX_N(prefix,nargs) \ - __VA_ARG_NSUFFIX_N_(prefix, nargs) -#define __VA_ARG_NSUFFIX_N_(prefix,nargs) \ - prefix ## nargs - -/* Prototypes of EFI cdecl -> stdcall trampolines */ -UINT64 efi_call0(void *func); -UINT64 efi_call1(void *func, UINT64 arg1); -UINT64 efi_call2(void *func, UINT64 arg1, UINT64 arg2); -UINT64 efi_call3(void *func, UINT64 arg1, UINT64 arg2, UINT64 arg3); -UINT64 efi_call4(void *func, UINT64 arg1, UINT64 arg2, UINT64 arg3, - UINT64 arg4); -UINT64 efi_call5(void *func, UINT64 arg1, UINT64 arg2, UINT64 arg3, - UINT64 arg4, UINT64 arg5); -UINT64 efi_call6(void *func, UINT64 arg1, UINT64 arg2, UINT64 arg3, - UINT64 arg4, UINT64 arg5, UINT64 arg6); -UINT64 efi_call7(void *func, UINT64 arg1, UINT64 arg2, UINT64 arg3, - UINT64 arg4, UINT64 arg5, UINT64 arg6, UINT64 arg7); -UINT64 efi_call8(void *func, UINT64 arg1, UINT64 arg2, UINT64 arg3, - UINT64 arg4, UINT64 arg5, UINT64 arg6, UINT64 arg7, - UINT64 arg8); -UINT64 efi_call9(void *func, UINT64 arg1, UINT64 arg2, UINT64 arg3, - UINT64 arg4, UINT64 arg5, UINT64 arg6, UINT64 arg7, - UINT64 arg8, UINT64 arg9); -UINT64 efi_call10(void *func, UINT64 arg1, UINT64 arg2, UINT64 arg3, - UINT64 arg4, UINT64 arg5, UINT64 arg6, UINT64 arg7, - UINT64 arg8, UINT64 arg9, UINT64 arg10); - -/* Front-ends to efi_callX to avoid compiler warnings */ -#define _cast64_efi_call0(f) \ - efi_call0(f) -#define _cast64_efi_call1(f,a1) \ - efi_call1(f, (UINT64)(a1)) -#define _cast64_efi_call2(f,a1,a2) \ - efi_call2(f, (UINT64)(a1), (UINT64)(a2)) -#define _cast64_efi_call3(f,a1,a2,a3) \ - efi_call3(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3)) -#define _cast64_efi_call4(f,a1,a2,a3,a4) \ - efi_call4(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3), (UINT64)(a4)) -#define _cast64_efi_call5(f,a1,a2,a3,a4,a5) \ - efi_call5(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3), (UINT64)(a4), \ - (UINT64)(a5)) -#define _cast64_efi_call6(f,a1,a2,a3,a4,a5,a6) \ - efi_call6(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3), (UINT64)(a4), \ - (UINT64)(a5), (UINT64)(a6)) -#define _cast64_efi_call7(f,a1,a2,a3,a4,a5,a6,a7) \ - efi_call7(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3), (UINT64)(a4), \ - (UINT64)(a5), (UINT64)(a6), (UINT64)(a7)) -#define _cast64_efi_call8(f,a1,a2,a3,a4,a5,a6,a7,a8) \ - efi_call8(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3), (UINT64)(a4), \ - (UINT64)(a5), (UINT64)(a6), (UINT64)(a7), (UINT64)(a8)) -#define _cast64_efi_call9(f,a1,a2,a3,a4,a5,a6,a7,a8,a9) \ - efi_call9(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3), (UINT64)(a4), \ - (UINT64)(a5), (UINT64)(a6), (UINT64)(a7), (UINT64)(a8), \ - (UINT64)(a9)) -#define _cast64_efi_call10(f,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) \ - efi_call10(f, (UINT64)(a1), (UINT64)(a2), (UINT64)(a3), (UINT64)(a4), \ - (UINT64)(a5), (UINT64)(a6), (UINT64)(a7), (UINT64)(a8), \ - (UINT64)(a9), (UINT64)(a10)) - -/* main wrapper (va_num ignored) */ -#define uefi_call_wrapper(func,va_num,...) \ - __VA_ARG_NSUFFIX__(_cast64_efi_call, __VA_ARGS__) (func , ##__VA_ARGS__) - -#endif - -#if defined(HAVE_USE_MS_ABI) && !defined(_MSC_EXTENSIONS) - #define EFI_FUNCTION __attribute__((ms_abi)) -#else - #define EFI_FUNCTION -#endif - -#ifdef _MSC_EXTENSIONS -#pragma warning ( disable : 4731 ) // Suppress warnings about modification of EBP -#endif - -#endif diff --git a/include/efi/x86_64/efilibplat.h b/include/efi/x86_64/efilibplat.h deleted file mode 100644 index 3844578..0000000 --- a/include/efi/x86_64/efilibplat.h +++ /dev/null @@ -1,26 +0,0 @@ -/*++ - -Copyright (c) 1998 Intel Corporation - -Module Name: - - efilibplat.h - -Abstract: - - EFI to compile bindings - - - - -Revision History - ---*/ - -VOID -InitializeLibPlatform ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ); - - diff --git a/include/efi/x86_64/efisetjmp_arch.h b/include/efi/x86_64/efisetjmp_arch.h deleted file mode 100644 index a489993..0000000 --- a/include/efi/x86_64/efisetjmp_arch.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef GNU_EFI_X86_64_SETJMP_H -#define GNU_EFI_X86_64_SETJMP_H - -#define JMPBUF_ALIGN 8 - -typedef struct { - UINT64 Rbx; - UINT64 Rsp; - UINT64 Rbp; - - UINT64 Rdi; - UINT64 Rsi; - UINT64 R12; - UINT64 R13; - UINT64 R14; - UINT64 R15; - UINT64 Rip; - UINT64 MxCsr; - UINT8 XmmBuffer[160]; // XMM6 - XMM15 -} ALIGN(JMPBUF_ALIGN) jmp_buf; - -#endif /* GNU_EFI_X86_64_SETJMP_H */ diff --git a/include/efi/x86_64/pe.h b/include/efi/x86_64/pe.h deleted file mode 100644 index 979b936..0000000 --- a/include/efi/x86_64/pe.h +++ /dev/null @@ -1,595 +0,0 @@ -/* - PE32+ header file - */ -#ifndef _PE_H -#define _PE_H - -#define IMAGE_DOS_SIGNATURE 0x5A4D // MZ -#define IMAGE_OS2_SIGNATURE 0x454E // NE -#define IMAGE_OS2_SIGNATURE_LE 0x454C // LE -#define IMAGE_NT_SIGNATURE 0x00004550 // PE00 -#define IMAGE_EDOS_SIGNATURE 0x44454550 // PEED - - -typedef struct _IMAGE_DOS_HEADER { // DOS .EXE header - UINT16 e_magic; // Magic number - UINT16 e_cblp; // Bytes on last page of file - UINT16 e_cp; // Pages in file - UINT16 e_crlc; // Relocations - UINT16 e_cparhdr; // Size of header in paragraphs - UINT16 e_minalloc; // Minimum extra paragraphs needed - UINT16 e_maxalloc; // Maximum extra paragraphs needed - UINT16 e_ss; // Initial (relative) SS value - UINT16 e_sp; // Initial SP value - UINT16 e_csum; // Checksum - UINT16 e_ip; // Initial IP value - UINT16 e_cs; // Initial (relative) CS value - UINT16 e_lfarlc; // File address of relocation table - UINT16 e_ovno; // Overlay number - UINT16 e_res[4]; // Reserved words - UINT16 e_oemid; // OEM identifier (for e_oeminfo) - UINT16 e_oeminfo; // OEM information; e_oemid specific - UINT16 e_res2[10]; // Reserved words - UINT32 e_lfanew; // File address of new exe header - } IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER; - -typedef struct _IMAGE_OS2_HEADER { // OS/2 .EXE header - UINT16 ne_magic; // Magic number - UINT8 ne_ver; // Version number - UINT8 ne_rev; // Revision number - UINT16 ne_enttab; // Offset of Entry Table - UINT16 ne_cbenttab; // Number of bytes in Entry Table - UINT32 ne_crc; // Checksum of whole file - UINT16 ne_flags; // Flag UINT16 - UINT16 ne_autodata; // Automatic data segment number - UINT16 ne_heap; // Initial heap allocation - UINT16 ne_stack; // Initial stack allocation - UINT32 ne_csip; // Initial CS:IP setting - UINT32 ne_sssp; // Initial SS:SP setting - UINT16 ne_cseg; // Count of file segments - UINT16 ne_cmod; // Entries in Module Reference Table - UINT16 ne_cbnrestab; // Size of non-resident name table - UINT16 ne_segtab; // Offset of Segment Table - UINT16 ne_rsrctab; // Offset of Resource Table - UINT16 ne_restab; // Offset of resident name table - UINT16 ne_modtab; // Offset of Module Reference Table - UINT16 ne_imptab; // Offset of Imported Names Table - UINT32 ne_nrestab; // Offset of Non-resident Names Table - UINT16 ne_cmovent; // Count of movable entries - UINT16 ne_align; // Segment alignment shift count - UINT16 ne_cres; // Count of resource segments - UINT8 ne_exetyp; // Target Operating system - UINT8 ne_flagsothers; // Other .EXE flags - UINT16 ne_pretthunks; // offset to return thunks - UINT16 ne_psegrefbytes; // offset to segment ref. bytes - UINT16 ne_swaparea; // Minimum code swap area size - UINT16 ne_expver; // Expected Windows version number - } IMAGE_OS2_HEADER, *PIMAGE_OS2_HEADER; - -// -// File header format. -// - -typedef struct _IMAGE_FILE_HEADER { - UINT16 Machine; - UINT16 NumberOfSections; - UINT32 TimeDateStamp; - UINT32 PointerToSymbolTable; - UINT32 NumberOfSymbols; - UINT16 SizeOfOptionalHeader; - UINT16 Characteristics; -} IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER; - -#define IMAGE_SIZEOF_FILE_HEADER 20 - -#define IMAGE_FILE_RELOCS_STRIPPED 0x0001 // Relocation info stripped from file. -#define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002 // File is executable (i.e. no unresolved externel references). -#define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004 // Line nunbers stripped from file. -#define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008 // Local symbols stripped from file. -#define IMAGE_FILE_BYTES_REVERSED_LO 0x0080 // Bytes of machine word are reversed. -#define IMAGE_FILE_32BIT_MACHINE 0x0100 // 32 bit word machine. -#define IMAGE_FILE_DEBUG_STRIPPED 0x0200 // Debugging info stripped from file in .DBG file -#define IMAGE_FILE_SYSTEM 0x1000 // System File. -#define IMAGE_FILE_DLL 0x2000 // File is a DLL. -#define IMAGE_FILE_BYTES_REVERSED_HI 0x8000 // Bytes of machine word are reversed. - -#define IMAGE_FILE_MACHINE_UNKNOWN 0 -#define IMAGE_FILE_MACHINE_I386 0x14c // Intel 386. -#define IMAGE_FILE_MACHINE_R3000 0x162 // MIPS little-endian, 0540 big-endian -#define IMAGE_FILE_MACHINE_R4000 0x166 // MIPS little-endian -#define IMAGE_FILE_MACHINE_ALPHA 0x184 // Alpha_AXP -#define IMAGE_FILE_MACHINE_ARMTHUMB_MIXED 0x1c2 // Arm/Thumb -#define IMAGE_FILE_MACHINE_POWERPC 0x1F0 // IBM PowerPC Little-Endian -#define IMAGE_FILE_MACHINE_IA64 0x200 // IA-64 -#define IMAGE_FILE_MACHINE_TAHOE 0x7cc // Intel EM machine -#define IMAGE_FILE_MACHINE_EBC 0xebc // EFI Byte Code -#define IMAGE_FILE_MACHINE_X64 0x8664 // x86_64 -// -// Directory format. -// - -typedef struct _IMAGE_DATA_DIRECTORY { - UINT32 VirtualAddress; - UINT32 Size; -} IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY; - -#define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16 - -// -// Optional header format. -// - -typedef struct _IMAGE_OPTIONAL_HEADER { - // - // Standard fields. - // - - UINT16 Magic; - UINT8 MajorLinkerVersion; - UINT8 MinorLinkerVersion; - UINT32 SizeOfCode; - UINT32 SizeOfInitializedData; - UINT32 SizeOfUninitializedData; - UINT32 AddressOfEntryPoint; - UINT32 BaseOfCode; - UINT32 BaseOfData; - - // - // NT additional fields. - // - - UINT32 ImageBase; - UINT32 SectionAlignment; - UINT32 FileAlignment; - UINT16 MajorOperatingSystemVersion; - UINT16 MinorOperatingSystemVersion; - UINT16 MajorImageVersion; - UINT16 MinorImageVersion; - UINT16 MajorSubsystemVersion; - UINT16 MinorSubsystemVersion; - UINT32 Reserved1; - UINT32 SizeOfImage; - UINT32 SizeOfHeaders; - UINT32 CheckSum; - UINT16 Subsystem; - UINT16 DllCharacteristics; - UINT32 SizeOfStackReserve; - UINT32 SizeOfStackCommit; - UINT32 SizeOfHeapReserve; - UINT32 SizeOfHeapCommit; - UINT32 LoaderFlags; - UINT32 NumberOfRvaAndSizes; - IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; -} IMAGE_OPTIONAL_HEADER, *PIMAGE_OPTIONAL_HEADER; - -typedef struct _IMAGE_ROM_OPTIONAL_HEADER { - UINT16 Magic; - UINT8 MajorLinkerVersion; - UINT8 MinorLinkerVersion; - UINT32 SizeOfCode; - UINT32 SizeOfInitializedData; - UINT32 SizeOfUninitializedData; - UINT32 AddressOfEntryPoint; - UINT32 BaseOfCode; - UINT32 BaseOfData; - UINT32 BaseOfBss; - UINT32 GprMask; - UINT32 CprMask[4]; - UINT32 GpValue; -} IMAGE_ROM_OPTIONAL_HEADER, *PIMAGE_ROM_OPTIONAL_HEADER; - -#define IMAGE_SIZEOF_ROM_OPTIONAL_HEADER 56 -#define IMAGE_SIZEOF_STD_OPTIONAL_HEADER 28 -#define IMAGE_SIZEOF_NT_OPTIONAL_HEADER 224 - -#define IMAGE_NT_OPTIONAL_HDR_MAGIC 0x10b -#define IMAGE_ROM_OPTIONAL_HDR_MAGIC 0x107 - -typedef struct _IMAGE_NT_HEADERS { - UINT32 Signature; - IMAGE_FILE_HEADER FileHeader; - IMAGE_OPTIONAL_HEADER OptionalHeader; -} IMAGE_NT_HEADERS, *PIMAGE_NT_HEADERS; - -typedef struct _IMAGE_ROM_HEADERS { - IMAGE_FILE_HEADER FileHeader; - IMAGE_ROM_OPTIONAL_HEADER OptionalHeader; -} IMAGE_ROM_HEADERS, *PIMAGE_ROM_HEADERS; - -#define IMAGE_FIRST_SECTION( ntheader ) ((PIMAGE_SECTION_HEADER) \ - ((UINT32)ntheader + \ - FIELD_OFFSET( IMAGE_NT_HEADERS, OptionalHeader ) + \ - ((PIMAGE_NT_HEADERS)(ntheader))->FileHeader.SizeOfOptionalHeader \ - )) - - -// Subsystem Values - -#define IMAGE_SUBSYSTEM_UNKNOWN 0 // Unknown subsystem. -#define IMAGE_SUBSYSTEM_NATIVE 1 // Image doesn't require a subsystem. -#define IMAGE_SUBSYSTEM_WINDOWS_GUI 2 // Image runs in the Windows GUI subsystem. -#define IMAGE_SUBSYSTEM_WINDOWS_CUI 3 // Image runs in the Windows character subsystem. -#define IMAGE_SUBSYSTEM_OS2_CUI 5 // image runs in the OS/2 character subsystem. -#define IMAGE_SUBSYSTEM_POSIX_CUI 7 // image run in the Posix character subsystem. - - -// Directory Entries - -#define IMAGE_DIRECTORY_ENTRY_EXPORT 0 // Export Directory -#define IMAGE_DIRECTORY_ENTRY_IMPORT 1 // Import Directory -#define IMAGE_DIRECTORY_ENTRY_RESOURCE 2 // Resource Directory -#define IMAGE_DIRECTORY_ENTRY_EXCEPTION 3 // Exception Directory -#define IMAGE_DIRECTORY_ENTRY_SECURITY 4 // Security Directory -#define IMAGE_DIRECTORY_ENTRY_BASERELOC 5 // Base Relocation Table -#define IMAGE_DIRECTORY_ENTRY_DEBUG 6 // Debug Directory -#define IMAGE_DIRECTORY_ENTRY_COPYRIGHT 7 // Description String -#define IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8 // Machine Value (MIPS GP) -#define IMAGE_DIRECTORY_ENTRY_TLS 9 // TLS Directory -#define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10 // Load Configuration Directory - -// -// Section header format. -// - -#define IMAGE_SIZEOF_SHORT_NAME 8 - -typedef struct _IMAGE_SECTION_HEADER { - UINT8 Name[IMAGE_SIZEOF_SHORT_NAME]; - union { - UINT32 PhysicalAddress; - UINT32 VirtualSize; - } Misc; - UINT32 VirtualAddress; - UINT32 SizeOfRawData; - UINT32 PointerToRawData; - UINT32 PointerToRelocations; - UINT32 PointerToLinenumbers; - UINT16 NumberOfRelocations; - UINT16 NumberOfLinenumbers; - UINT32 Characteristics; -} IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER; - -#define IMAGE_SIZEOF_SECTION_HEADER 40 - -#define IMAGE_SCN_TYPE_NO_PAD 0x00000008 // Reserved. - -#define IMAGE_SCN_CNT_CODE 0x00000020 // Section contains code. -#define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 // Section contains initialized data. -#define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 // Section contains uninitialized data. - -#define IMAGE_SCN_LNK_OTHER 0x00000100 // Reserved. -#define IMAGE_SCN_LNK_INFO 0x00000200 // Section contains comments or some other type of information. -#define IMAGE_SCN_LNK_REMOVE 0x00000800 // Section contents will not become part of image. -#define IMAGE_SCN_LNK_COMDAT 0x00001000 // Section contents comdat. - -#define IMAGE_SCN_ALIGN_1BYTES 0x00100000 // -#define IMAGE_SCN_ALIGN_2BYTES 0x00200000 // -#define IMAGE_SCN_ALIGN_4BYTES 0x00300000 // -#define IMAGE_SCN_ALIGN_8BYTES 0x00400000 // -#define IMAGE_SCN_ALIGN_16BYTES 0x00500000 // Default alignment if no others are specified. -#define IMAGE_SCN_ALIGN_32BYTES 0x00600000 // -#define IMAGE_SCN_ALIGN_64BYTES 0x00700000 // - -#define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 // Section can be discarded. -#define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 // Section is not cachable. -#define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 // Section is not pageable. -#define IMAGE_SCN_MEM_SHARED 0x10000000 // Section is shareable. -#define IMAGE_SCN_MEM_EXECUTE 0x20000000 // Section is executable. -#define IMAGE_SCN_MEM_READ 0x40000000 // Section is readable. -#define IMAGE_SCN_MEM_WRITE 0x80000000 // Section is writeable. - -// -// Symbol format. -// - - -#define IMAGE_SIZEOF_SYMBOL 18 - -// -// Section values. -// -// Symbols have a section number of the section in which they are -// defined. Otherwise, section numbers have the following meanings: -// - -#define IMAGE_SYM_UNDEFINED (UINT16)0 // Symbol is undefined or is common. -#define IMAGE_SYM_ABSOLUTE (UINT16)-1 // Symbol is an absolute value. -#define IMAGE_SYM_DEBUG (UINT16)-2 // Symbol is a special debug item. - -// -// Type (fundamental) values. -// - -#define IMAGE_SYM_TYPE_NULL 0 // no type. -#define IMAGE_SYM_TYPE_VOID 1 // -#define IMAGE_SYM_TYPE_CHAR 2 // type character. -#define IMAGE_SYM_TYPE_SHORT 3 // type short integer. -#define IMAGE_SYM_TYPE_INT 4 // -#define IMAGE_SYM_TYPE_LONG 5 // -#define IMAGE_SYM_TYPE_FLOAT 6 // -#define IMAGE_SYM_TYPE_DOUBLE 7 // -#define IMAGE_SYM_TYPE_STRUCT 8 // -#define IMAGE_SYM_TYPE_UNION 9 // -#define IMAGE_SYM_TYPE_ENUM 10 // enumeration. -#define IMAGE_SYM_TYPE_MOE 11 // member of enumeration. -#define IMAGE_SYM_TYPE_BYTE 12 // -#define IMAGE_SYM_TYPE_WORD 13 // -#define IMAGE_SYM_TYPE_UINT 14 // -#define IMAGE_SYM_TYPE_DWORD 15 // - -// -// Type (derived) values. -// - -#define IMAGE_SYM_DTYPE_NULL 0 // no derived type. -#define IMAGE_SYM_DTYPE_POINTER 1 // pointer. -#define IMAGE_SYM_DTYPE_FUNCTION 2 // function. -#define IMAGE_SYM_DTYPE_ARRAY 3 // array. - -// -// Storage classes. -// - -#define IMAGE_SYM_CLASS_END_OF_FUNCTION (BYTE )-1 -#define IMAGE_SYM_CLASS_NULL 0 -#define IMAGE_SYM_CLASS_AUTOMATIC 1 -#define IMAGE_SYM_CLASS_EXTERNAL 2 -#define IMAGE_SYM_CLASS_STATIC 3 -#define IMAGE_SYM_CLASS_REGISTER 4 -#define IMAGE_SYM_CLASS_EXTERNAL_DEF 5 -#define IMAGE_SYM_CLASS_LABEL 6 -#define IMAGE_SYM_CLASS_UNDEFINED_LABEL 7 -#define IMAGE_SYM_CLASS_MEMBER_OF_STRUCT 8 -#define IMAGE_SYM_CLASS_ARGUMENT 9 -#define IMAGE_SYM_CLASS_STRUCT_TAG 10 -#define IMAGE_SYM_CLASS_MEMBER_OF_UNION 11 -#define IMAGE_SYM_CLASS_UNION_TAG 12 -#define IMAGE_SYM_CLASS_TYPE_DEFINITION 13 -#define IMAGE_SYM_CLASS_UNDEFINED_STATIC 14 -#define IMAGE_SYM_CLASS_ENUM_TAG 15 -#define IMAGE_SYM_CLASS_MEMBER_OF_ENUM 16 -#define IMAGE_SYM_CLASS_REGISTER_PARAM 17 -#define IMAGE_SYM_CLASS_BIT_FIELD 18 -#define IMAGE_SYM_CLASS_BLOCK 100 -#define IMAGE_SYM_CLASS_FUNCTION 101 -#define IMAGE_SYM_CLASS_END_OF_STRUCT 102 -#define IMAGE_SYM_CLASS_FILE 103 -// new -#define IMAGE_SYM_CLASS_SECTION 104 -#define IMAGE_SYM_CLASS_WEAK_EXTERNAL 105 - -// type packing constants - -#define N_BTMASK 017 -#define N_TMASK 060 -#define N_TMASK1 0300 -#define N_TMASK2 0360 -#define N_BTSHFT 4 -#define N_TSHIFT 2 - -// MACROS - -// -// Communal selection types. -// - -#define IMAGE_COMDAT_SELECT_NODUPLICATES 1 -#define IMAGE_COMDAT_SELECT_ANY 2 -#define IMAGE_COMDAT_SELECT_SAME_SIZE 3 -#define IMAGE_COMDAT_SELECT_EXACT_MATCH 4 -#define IMAGE_COMDAT_SELECT_ASSOCIATIVE 5 - -#define IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY 1 -#define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY 2 -#define IMAGE_WEAK_EXTERN_SEARCH_ALIAS 3 - - -// -// Relocation format. -// - -typedef struct _IMAGE_RELOCATION { - UINT32 VirtualAddress; - UINT32 SymbolTableIndex; - UINT16 Type; -} IMAGE_RELOCATION; - -#define IMAGE_SIZEOF_RELOCATION 10 - -// -// I386 relocation types. -// - -#define IMAGE_REL_I386_ABSOLUTE 0 // Reference is absolute, no relocation is necessary -#define IMAGE_REL_I386_DIR16 01 // Direct 16-bit reference to the symbols virtual address -#define IMAGE_REL_I386_REL16 02 // PC-relative 16-bit reference to the symbols virtual address -#define IMAGE_REL_I386_DIR32 06 // Direct 32-bit reference to the symbols virtual address -#define IMAGE_REL_I386_DIR32NB 07 // Direct 32-bit reference to the symbols virtual address, base not included -#define IMAGE_REL_I386_SEG12 011 // Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address -#define IMAGE_REL_I386_SECTION 012 -#define IMAGE_REL_I386_SECREL 013 -#define IMAGE_REL_I386_REL32 024 // PC-relative 32-bit reference to the symbols virtual address - -// -// MIPS relocation types. -// - -#define IMAGE_REL_MIPS_ABSOLUTE 0 // Reference is absolute, no relocation is necessary -#define IMAGE_REL_MIPS_REFHALF 01 -#define IMAGE_REL_MIPS_REFWORD 02 -#define IMAGE_REL_MIPS_JMPADDR 03 -#define IMAGE_REL_MIPS_REFHI 04 -#define IMAGE_REL_MIPS_REFLO 05 -#define IMAGE_REL_MIPS_GPREL 06 -#define IMAGE_REL_MIPS_LITERAL 07 -#define IMAGE_REL_MIPS_SECTION 012 -#define IMAGE_REL_MIPS_SECREL 013 -#define IMAGE_REL_MIPS_REFWORDNB 042 -#define IMAGE_REL_MIPS_PAIR 045 - -// -// Alpha Relocation types. -// - -#define IMAGE_REL_ALPHA_ABSOLUTE 0x0 -#define IMAGE_REL_ALPHA_REFLONG 0x1 -#define IMAGE_REL_ALPHA_REFQUAD 0x2 -#define IMAGE_REL_ALPHA_GPREL32 0x3 -#define IMAGE_REL_ALPHA_LITERAL 0x4 -#define IMAGE_REL_ALPHA_LITUSE 0x5 -#define IMAGE_REL_ALPHA_GPDISP 0x6 -#define IMAGE_REL_ALPHA_BRADDR 0x7 -#define IMAGE_REL_ALPHA_HINT 0x8 -#define IMAGE_REL_ALPHA_INLINE_REFLONG 0x9 -#define IMAGE_REL_ALPHA_REFHI 0xA -#define IMAGE_REL_ALPHA_REFLO 0xB -#define IMAGE_REL_ALPHA_PAIR 0xC -#define IMAGE_REL_ALPHA_MATCH 0xD -#define IMAGE_REL_ALPHA_SECTION 0xE -#define IMAGE_REL_ALPHA_SECREL 0xF -#define IMAGE_REL_ALPHA_REFLONGNB 0x10 - -// -// IBM PowerPC relocation types. -// - -#define IMAGE_REL_PPC_ABSOLUTE 0x0000 // NOP -#define IMAGE_REL_PPC_ADDR64 0x0001 // 64-bit address -#define IMAGE_REL_PPC_ADDR32 0x0002 // 32-bit address -#define IMAGE_REL_PPC_ADDR24 0x0003 // 26-bit address, shifted left 2 (branch absolute) -#define IMAGE_REL_PPC_ADDR16 0x0004 // 16-bit address -#define IMAGE_REL_PPC_ADDR14 0x0005 // 16-bit address, shifted left 2 (load doubleword) -#define IMAGE_REL_PPC_REL24 0x0006 // 26-bit PC-relative offset, shifted left 2 (branch relative) -#define IMAGE_REL_PPC_REL14 0x0007 // 16-bit PC-relative offset, shifted left 2 (br cond relative) -#define IMAGE_REL_PPC_TOCREL16 0x0008 // 16-bit offset from TOC base -#define IMAGE_REL_PPC_TOCREL14 0x0009 // 16-bit offset from TOC base, shifted left 2 (load doubleword) - -#define IMAGE_REL_PPC_ADDR32NB 0x000A // 32-bit addr w/o image base -#define IMAGE_REL_PPC_SECREL 0x000B // va of containing section (as in an image sectionhdr) -#define IMAGE_REL_PPC_SECTION 0x000C // sectionheader number -#define IMAGE_REL_PPC_IFGLUE 0x000D // substitute TOC restore instruction iff symbol is glue code -#define IMAGE_REL_PPC_IMGLUE 0x000E // symbol is glue code; virtual address is TOC restore instruction - -#define IMAGE_REL_PPC_TYPEMASK 0x00FF // mask to isolate above values in IMAGE_RELOCATION.Type - -// Flag bits in IMAGE_RELOCATION.TYPE - -#define IMAGE_REL_PPC_NEG 0x0100 // subtract reloc value rather than adding it -#define IMAGE_REL_PPC_BRTAKEN 0x0200 // fix branch prediction bit to predict branch taken -#define IMAGE_REL_PPC_BRNTAKEN 0x0400 // fix branch prediction bit to predict branch not taken -#define IMAGE_REL_PPC_TOCDEFN 0x0800 // toc slot defined in file (or, data in toc) - -// -// Based relocation format. -// - -typedef struct _IMAGE_BASE_RELOCATION { - UINT32 VirtualAddress; - UINT32 SizeOfBlock; -// UINT16 TypeOffset[1]; -} IMAGE_BASE_RELOCATION, *PIMAGE_BASE_RELOCATION; - -#define IMAGE_SIZEOF_BASE_RELOCATION 8 - -// -// Based relocation types. -// - -#define IMAGE_REL_BASED_ABSOLUTE 0 -#define IMAGE_REL_BASED_HIGH 1 -#define IMAGE_REL_BASED_LOW 2 -#define IMAGE_REL_BASED_HIGHLOW 3 -#define IMAGE_REL_BASED_HIGHADJ 4 -#define IMAGE_REL_BASED_MIPS_JMPADDR 5 -#define IMAGE_REL_BASED_IA64_IMM64 9 -#define IMAGE_REL_BASED_DIR64 10 - -// -// Line number format. -// - -typedef struct _IMAGE_LINENUMBER { - union { - UINT32 SymbolTableIndex; // Symbol table index of function name if Linenumber is 0. - UINT32 VirtualAddress; // Virtual address of line number. - } Type; - UINT16 Linenumber; // Line number. -} IMAGE_LINENUMBER; - -#define IMAGE_SIZEOF_LINENUMBER 6 - -// -// Archive format. -// - -#define IMAGE_ARCHIVE_START_SIZE 8 -#define IMAGE_ARCHIVE_START "!\n" -#define IMAGE_ARCHIVE_END "`\n" -#define IMAGE_ARCHIVE_PAD "\n" -#define IMAGE_ARCHIVE_LINKER_MEMBER "/ " -#define IMAGE_ARCHIVE_LONGNAMES_MEMBER "// " - -typedef struct _IMAGE_ARCHIVE_MEMBER_HEADER { - UINT8 Name[16]; // File member name - `/' terminated. - UINT8 Date[12]; // File member date - decimal. - UINT8 UserID[6]; // File member user id - decimal. - UINT8 GroupID[6]; // File member group id - decimal. - UINT8 Mode[8]; // File member mode - octal. - UINT8 Size[10]; // File member size - decimal. - UINT8 EndHeader[2]; // String to end header. -} IMAGE_ARCHIVE_MEMBER_HEADER, *PIMAGE_ARCHIVE_MEMBER_HEADER; - -#define IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR 60 - -// -// DLL support. -// - -// -// Export Format -// - -typedef struct _IMAGE_EXPORT_DIRECTORY { - UINT32 Characteristics; - UINT32 TimeDateStamp; - UINT16 MajorVersion; - UINT16 MinorVersion; - UINT32 Name; - UINT32 Base; - UINT32 NumberOfFunctions; - UINT32 NumberOfNames; - UINT32 *AddressOfFunctions; - UINT32 *AddressOfNames; - UINT32 *AddressOfNameOrdinals; -} IMAGE_EXPORT_DIRECTORY, *PIMAGE_EXPORT_DIRECTORY; - -// -// Import Format -// - -typedef struct _IMAGE_IMPORT_BY_NAME { - UINT16 Hint; - UINT8 Name[1]; -} IMAGE_IMPORT_BY_NAME, *PIMAGE_IMPORT_BY_NAME; - -typedef struct _IMAGE_THUNK_DATA { - union { - UINT32 Function; - UINT32 Ordinal; - PIMAGE_IMPORT_BY_NAME AddressOfData; - } u1; -} IMAGE_THUNK_DATA, *PIMAGE_THUNK_DATA; - -#define IMAGE_ORDINAL_FLAG 0x80000000 -#define IMAGE_SNAP_BY_ORDINAL(Ordinal) ((Ordinal & IMAGE_ORDINAL_FLAG) != 0) -#define IMAGE_ORDINAL(Ordinal) (Ordinal & 0xffff) - -typedef struct _IMAGE_IMPORT_DESCRIPTOR { - UINT32 Characteristics; - UINT32 TimeDateStamp; - UINT32 ForwarderChain; - UINT32 Name; - PIMAGE_THUNK_DATA FirstThunk; -} IMAGE_IMPORT_DESCRIPTOR, *PIMAGE_IMPORT_DESCRIPTOR; - -#endif diff --git a/include/kernel.h b/include/kernel.h deleted file mode 100644 index a16f0f6..0000000 --- a/include/kernel.h +++ /dev/null @@ -1,12 +0,0 @@ -/************************ - *** Team Kitty, 2019 *** - *** Sync *** - ***********************/ - -#include -#include -#include - -void panic(char*); - -void gdb_end(); \ No newline at end of file diff --git a/include/kernel/descriptor_tables.h b/include/kernel/descriptor_tables.h deleted file mode 100755 index b6aa919..0000000 --- a/include/kernel/descriptor_tables.h +++ /dev/null @@ -1,166 +0,0 @@ -/************************ - *** Team Kitty, 2019 *** - *** Sync *** - ***********************/ - -#pragma once -#include -#include - -void gdt_set_gate(int, uint32_t, uint32_t, uint8_t, uint8_t); -void gdt_install(); - -struct gdt_item { - uint16_t low_limit; - uint16_t low_base; - uint8_t middle_base; - uint8_t access; - uint8_t granular; - uint8_t high_base; -} __attribute__((packed)); //Prevent compiler optimisation by packing - -struct gdt_ptr { - uint16_t limit; - unsigned int base; -} __attribute__((packed)); - -struct gdt_item gdt[3]; //3-entry gdt -struct gdt_ptr gp; - -extern void load_gdt(); - -void idt_set_gate(unsigned char, unsigned long, unsigned short, unsigned char); -void idt_install(); - -struct idt_entry { - unsigned short base_low; - unsigned short selector; - unsigned char always0; - unsigned char flags; - unsigned short base_high; -} __attribute__((packed)); - -struct idt_ptr { - unsigned short limit; - unsigned int base; -}__attribute__((packed)); - -struct idt_entry idt[256]; //interrupt table of 256 entries -struct idt_ptr idtp; //pointer to idt table - -struct int_frame { - void (*eip) (void); - uint16_t cs, :16; - uint32_t eflags; - void* esp; - uint16_t ss, :16; -} __attribute__((packed)); - -void isr_common(struct int_frame*, size_t); - -void isr_error_common(struct int_frame*, size_t, size_t); - -void irq_common(struct int_frame*, size_t); - -extern void load_idt(); - -//These are all reserved by Intel, and need to be here. -extern void isr0(); -extern void isr1(); -extern void isr2(); -extern void isr3(); -extern void isr4(); -extern void isr5(); -extern void isr6(); -extern void isr7(); -extern void isr8(); -extern void isr9(); -extern void isr10(); -extern void isr11(); -extern void isr12(); -extern void isr13(); -extern void isr14(); -extern void isr15(); -extern void isr16(); -extern void isr17(); -extern void isr18(); -extern void isr19(); -extern void isr20(); -extern void isr21(); -extern void isr22(); -extern void isr23(); -extern void isr24(); -extern void isr25(); -extern void isr26(); -extern void isr27(); -extern void isr28(); -extern void isr29(); -extern void isr30(); -extern void isr31(); - -extern void irq0(); -extern void irq1(); -extern void irq2(); -extern void irq3(); -extern void irq4(); -extern void irq5(); -extern void irq6(); -extern void irq7(); -extern void irq8(); -extern void irq9(); -extern void irq10(); -extern void irq11(); -extern void irq12(); -extern void irq13(); -extern void irq14(); -extern void irq15(); - -static void* irq_routines[16] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 -}; - -void irq_install_handler(int irq, void (*handler)(struct int_frame* r)); - -void irq_uninstall_handler(int); - -void irq_install(); - -void irq_remap(); - -void timer_install(); - -static const char* exception_messages[] = { - "Division by Zero", - "Debug", - "Non Maskable Interrupt", - "Breakpoint", - "Into Detected Overflow", - "Out of Bounds", - "Invalid Opcode", - "No Coprocessor", - "Double Fault", - "Coprocessor Segment Overrun", - "Bad TSS", - "Segment Not Present", - "Stack Fault", - "General Protection Fault", - "Page Fault", - "Unknown Interrupt", - "Coprocessor Fault", - "Alignment Check", - "Machine Check", - "Reserved", - "Reserved", - "Reserved", - "Reserved", - "Reserved", - "Reserved", - "Reserved", - "Reserved", - "Reserved", - "Reserved", - "Reserved", - "Reserved", - "Reserved" -}; diff --git a/include/kernel/serial.h b/include/kernel/serial.h deleted file mode 100755 index b17344a..0000000 --- a/include/kernel/serial.h +++ /dev/null @@ -1,26 +0,0 @@ -/************************ - *** Team Kitty, 2019 *** - *** Sync *** - ***********************/ - -#pragma once -#include -#include - -void init_serial(); - -void serial_set_baud_rate(uint16_t, uint16_t); - -void serial_configure_line(uint16_t); - -void serial_configure_buffers(uint16_t); - -void serial_write(uint16_t, const char); - -void serial_configure_modem(uint16_t); - -int serial_check_tqueue(uint16_t); - -void serial_print(uint16_t, const char*); - -void serial_printf(uint16_t, const char*, ...); diff --git a/include/kernel/tty.h b/include/kernel/tty.h deleted file mode 100644 index 7eba419..0000000 --- a/include/kernel/tty.h +++ /dev/null @@ -1,34 +0,0 @@ -/************************ - *** Team Kitty, 2019 *** - *** Sync *** - ***********************/ - -#pragma once - -#include -#include -#include - -#include "arch/i386/vga.h" - -struct csi_sequence { - const char* parameter; - size_t parameter_len; - const char* intermediate; - size_t intermediate_len; - const char* final; - bool valid; -}; - -void term_setcolor(enum vga_colors); -void screen_initialize(void); -void term_putentryat(char, uint8_t, size_t, size_t); -void term_putchar(char); -void term_write(const char*, size_t); -void term_writes(const char*); -void puts(const char*); -void handleControlSequence(struct csi_sequence); -void set_cursor(int, int); -void term_scroll(bool); - -bool isDigit(char c); diff --git a/include/kernel/utils.h b/include/kernel/utils.h deleted file mode 100755 index 7d06107..0000000 --- a/include/kernel/utils.h +++ /dev/null @@ -1,28 +0,0 @@ -/************************ - *** Team Kitty, 2019 *** - *** Sync *** - ***********************/ - - -#pragma once -#include - -/* A temporary file, to get the system compiling. */ - -size_t strlen(const char*); - -unsigned char inb(unsigned short); - -void outb(unsigned short, unsigned char); - -void memcpy(void*, void*, size_t); - -void memset(void*, int, size_t); - -void int_to_ascii(int, char*); - -void int_to_hex(int, char*); - -void empty_string(char*); - -char* itoc(size_t); diff --git a/kernel/descriptor_tables.c b/kernel/descriptor_tables.c deleted file mode 100755 index f0df107..0000000 --- a/kernel/descriptor_tables.c +++ /dev/null @@ -1,257 +0,0 @@ -/************************ - *** Team Kitty, 2019 *** - *** Sync *** - ***********************/ - -/* This file combines the implementation - of IDT and GDT, Interrupt Descriptor - Table and Global Descriptor Table - respectively. - - These are in the same file, because - otherwise the GDT file would be - roughly 10 lines long. - - This file contains the code to set up - and configure the PIC, to configure and - load the IDT and GDT through the processor, - and other functions that are uniquely - related to the above tasks. */ - -#include -#include -#include - - /* - * The GDT gate setting function. - * Defines where the important parts of memory are. - * - * @param num: GDT position ID. - * @param base: Start of the memory block this entry is for. - * @param limit: End of the above memory block. - * @param access: The ring number associated with this entry. - * @param gran: Granularity - how big the assigned chunks of memory are. - */ -void gdt_set_gate(int num, uint32_t base, - uint32_t limit, uint8_t access, - uint8_t gran) { - - /* The function is mostly shifts and masks, nothing too special. */ - /* The gdt[] array is defined in the descriptor_tables header. */ - gdt[num].low_base = (base & 0xFFFF); - gdt[num].middle_base = (base >> 16) & 0xFF; - gdt[num].high_base = (base >> 24) & 0xFF; - - gdt[num].low_limit = (limit & 0xFFFF); - gdt[num].granular = ((limit >> 16) & 0x0F); - - gdt[num].granular = (gran & 0xF0); - gdt[num].access = access; -} - -/* - The function that puts it all together. It sets up the pointer, - fills it in, and tells the CPU to load the new GDT immediately. - */ -void gdt_install() { - /* gp = GDT Pointer, defined in descriptor_tables header. */ - gp.limit = (sizeof(struct gdt_item) * 3) - 1; - gp.base = (uint32_t)&gdt; - - /* The CPU requires that the first gate always be null. */ - gdt_set_gate(0, 0, 0, 0, 0); - - /* This is the Code Segment, it starts at 0 and ends at 4GB, meaning - that it encompasses the entirety of available memory. - - This defines the code segment with exclusive execute permission, - allowing the kernel to execute itself. */ - gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF); - - /* The Data Segment, the same range as the Code Segment (0 - 4GB) - but with Read/Write permission, allowing the kernel to modify RAM. */ - gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF); - - /* Lastly, call the external ASM function that loads the GDT into the - processor. */ - load_gdt(); -} - -/* - Identically to the GDT set gate function, but for the IDT array. - * @param num: IDT access ID - * @param base: Start of memory block - * @param sel: Selector. I have no idea what that means. - * @param flags: Permission levels and all that stuff. - */ -void idt_set_gate(unsigned char num, - unsigned long base, - unsigned short sel, - unsigned char flags) { - /* Again, it's all shifts and masks. Nothing special. */ - idt[num].base_low = base & 0xFFFF; - idt[num].base_high = (base >> 16) & 0xFFFF; - - idt[num].selector = sel; - idt[num].always0 = 0; - - /* Set the permission level to 3. All interrupts are from ring 3. */ - idt[num].flags = flags | 0x60; -} - -/* - Same as GDT_install: sets up the pointers and fills in the contents, then passes - it on to the CPU to be loaded. - */ -void idt_install() { - /* idtp is the IDT Pointer, defined in the descriptor_tables header. */ - idtp.limit = (sizeof (struct idt_entry) * 256) - 1; - idtp.base = (uint32_t) &idt; - - memset(&idt, 0, sizeof(struct idt_entry) * 256); - - /* Manually fill in the array - these functions are defined in - interrupts.c */ - - idt_set_gate(0, (unsigned)isr0, 0x08, 0x8E); - idt_set_gate(1, (unsigned)isr1, 0x08, 0x8E); - idt_set_gate(2, (unsigned)isr2, 0x08, 0x8E); - idt_set_gate(3, (unsigned)isr3, 0x08, 0x8E); - idt_set_gate(4, (unsigned)isr4, 0x08, 0x8E); - idt_set_gate(5, (unsigned)isr5, 0x08, 0x8E); - idt_set_gate(6, (unsigned)isr6, 0x08, 0x8E); - idt_set_gate(7, (unsigned)isr7, 0x08, 0x8E); - - idt_set_gate(8, (unsigned)isr8, 0x08, 0x8E); - idt_set_gate(9, (unsigned)isr9, 0x08, 0x8E); - idt_set_gate(10, (unsigned)isr10, 0x08, 0x8E); - idt_set_gate(11, (unsigned)isr11, 0x08, 0x8E); - idt_set_gate(12, (unsigned)isr12, 0x08, 0x8E); - idt_set_gate(13, (unsigned)isr13, 0x08, 0x8E); - idt_set_gate(14, (unsigned)isr14, 0x08, 0x8E); - idt_set_gate(15, (unsigned)isr15, 0x08, 0x8E); - - idt_set_gate(16, (unsigned)isr16, 0x08, 0x8E); - idt_set_gate(17, (unsigned)isr17, 0x08, 0x8E); - idt_set_gate(18, (unsigned)isr18, 0x08, 0x8E); - idt_set_gate(19, (unsigned)isr19, 0x08, 0x8E); - idt_set_gate(20, (unsigned)isr20, 0x08, 0x8E); - idt_set_gate(21, (unsigned)isr21, 0x08, 0x8E); - idt_set_gate(22, (unsigned)isr22, 0x08, 0x8E); - idt_set_gate(23, (unsigned)isr23, 0x08, 0x8E); - - idt_set_gate(24, (unsigned)isr24, 0x08, 0x8E); - idt_set_gate(25, (unsigned)isr25, 0x08, 0x8E); - idt_set_gate(26, (unsigned)isr26, 0x08, 0x8E); - idt_set_gate(27, (unsigned)isr27, 0x08, 0x8E); - idt_set_gate(28, (unsigned)isr28, 0x08, 0x8E); - idt_set_gate(29, (unsigned)isr29, 0x08, 0x8E); - idt_set_gate(30, (unsigned)isr30, 0x08, 0x8E); - idt_set_gate(31, (unsigned)isr31, 0x08, 0x8E); - - load_idt(); - irq_install(); - -} - -/* A simple wrapper that adds a function pointer to the IRQ array. */ -void irq_install_handler(int irq, void (*handler)(struct int_frame* r)) { - irq_routines[irq] = handler; -} - -/* A simple wrapper that unlinks a function pointer, rendering the IRQ unused. */ -void irq_uninstall_handler(int irq) { - irq_routines[irq] = 0; -} - -/* - Since the PIC starts with irq values that overlap with the CPU default ISR - lines, it's necessary to remap the PIC. - - Doing this also means that we have to completely reinitialize the PIC, which - is why this is so long. - */ - -void irq_remap() { - /* 0x20 is the Master PIC, - 0xA0 is the Slave PIC. */ - outb(0x20, 0x11); - outb(0xA0, 0x11); - outb(0x21, 0x20); - outb(0xA1, 0x28); - outb(0x21, 0x04); - outb(0xA1, 0x02); - outb(0x21, 0x01); - outb(0xA1, 0x01); - outb(0x21, 0x0); - outb(0xA1, 0x0); -} - -/* A handler function to perform all of the required steps in one function call. - TODO: move all Descriptor Table things to a single callable function. -*/ -void irq_install() { - irq_remap(); - idt_set_gate(32, (unsigned)irq0, 0x08, 0x8E); - idt_set_gate(33, (unsigned)irq1, 0x08, 0x8E); - idt_set_gate(34, (unsigned)irq2, 0x08, 0x8E); - idt_set_gate(35, (unsigned)irq3, 0x08, 0x8E); - idt_set_gate(36, (unsigned)irq4, 0x08, 0x8E); - idt_set_gate(37, (unsigned)irq5, 0x08, 0x8E); - idt_set_gate(38, (unsigned)irq6, 0x08, 0x8E); - idt_set_gate(39, (unsigned)irq7, 0x08, 0x8E); - idt_set_gate(40, (unsigned)irq8, 0x08, 0x8E); - idt_set_gate(41, (unsigned)irq9, 0x08, 0x8E); - idt_set_gate(42, (unsigned)irq10, 0x08, 0x8E); - idt_set_gate(43, (unsigned)irq11, 0x08, 0x8E); - idt_set_gate(44, (unsigned)irq12, 0x08, 0x8E); - idt_set_gate(45, (unsigned)irq13, 0x08, 0x8E); - idt_set_gate(46, (unsigned)irq14, 0x08, 0x8E); - idt_set_gate(47, (unsigned)irq15, 0x08, 0x8E); -} - - -/* All of the ISR routines call this function for now. - ! This function is NOT leaf, and it might clobber the stack. - ! Be careful! -*/ -void isr_common(struct int_frame* r, size_t exception) { - /* We only have the capacity to handle 32 exceptions. This is a limitation of the CPU. */ - if(exception < 32) { - /* exception_messages is an array defined in descriptor_tables.h */ - serial_print(0x3F8, exception_messages[exception]); - serial_print(0x3F8, " Exception.\r\n"); - panic(exception_messages[exception]); - } -} - -/* The common handler for exceptions that throw error codes, which give us useful insight - into what went wrong. In pure Curle style, though, we just ignore the error code. */ -void isr_error_common(struct int_frame* r, size_t exception, size_t error) { - - if(exception < 32) { - serial_print(0x3F8, exception_messages[exception]); - serial_printf(0x3F8, " Exception. Context given: %d\r\n", error); - panic(exception_messages[exception]); - } - -} - -/* Likewise, this function is common to all IRQ handlers. It calls the assigned routine, - which was set up earlier by irq_install.*/ -void irq_common(struct int_frame* r, size_t interrupt) { - void (*handler)(struct int_frame* r); - serial_print(0x3F8, "[INFO] Received IRQ: " + interrupt); - /* We set all uninitialized routines to 0, so the if(handler) check here allows us to - safely tell whether we've actually got something for this IRQ. */ - handler = irq_routines[interrupt]; - if(handler) - handler(r); - - /* The Slave PIC must be told it's been read in order to receive another 8+ IRQ. */ - if(interrupt > 7) - outb(0xA0, 0x20); - - /* In either case, we tell the Master PIC it's been read to receive any IRQ. */ - outb(0x20, 0x20); -} diff --git a/kernel/interrupts.c b/kernel/interrupts.c deleted file mode 100644 index f738d87..0000000 --- a/kernel/interrupts.c +++ /dev/null @@ -1,212 +0,0 @@ -/************************ - *** Team Kitty, 2019 *** - *** Sync *** - ***********************/ - -/* This file contains all of the ISR and IRQ - * (Interrupt Service Request) functions. - * - * As they use the GCC interrupt attribute, - * this file must be compiled without red- - * zone protection, thus all of these - * functions are in their own file to - * accomodate this. - * - * Calling a function like so: - * - * __attribute__((interrupt)) isr1(registers_t* frame) {} - * - * allows the function to be used to serve - * interrupts - GCC compiles it under unique - * conditions, as it preserves the state of - * the processor and stack between execution, - * as well as using the IRET instruction to - * return to the middle of the previous function. - * - * There is also a version of the interrupt - * attribute which allows for error handlers, - * these having a size_t input as an error code. - */ - - -#include -#include -#include "kernel/descriptor_tables.h" - -#ifdef __x86_64__ -typedef unsigned long long int uword_t; -#else -typedef unsigned int uword_t; -#endif - -/* The interrupt numbers, their meanings, and - * special information is laid out below: - * - * 0 - Divide by Zero - * 1 - Debug - * 2 - Non-Maskable - * 3 - Breakpoint - * 4 - Into Detected Overflow - * 5 - Out of Bounds - * 6 - Invalid Opcode - * 7 - No Coprocessor - * 8 - Double Fault * (With Error) - * 9 - Coprocessor Segment Overrun - * 10 - Bad TSS * (With Error) - * 11 - Segment Not Present * (With Error) - * 12 - Stack Fault * (With Error) - * 13 - General Protection Fault * (With Error) - * 14 - Page Fault * (With Error) - * 15 - Unknown Interrupt - * 16 - Coprocessor Fault - * 17 - Alignment Check - * 18 - Machine Check - * 19 to 31 - Reserved - */ - -__attribute__((interrupt)) void isr0(struct int_frame* r) { - isr_common(r, 0); -} -__attribute__((interrupt)) void isr1(struct int_frame* r) { - isr_common(r, 1); -} -__attribute__((interrupt)) void isr2(struct int_frame* r) { - isr_common(r, 2); -} -__attribute__((interrupt)) void isr3(struct int_frame* r) { - isr_common(r, 3); -} -__attribute__((interrupt)) void isr4(struct int_frame* r) { - isr_common(r, 4); -} -__attribute__((interrupt)) void isr5(struct int_frame* r) { - isr_common(r, 5); -} -__attribute__((interrupt)) void isr6(struct int_frame* r) { - isr_common(r, 6); -} -__attribute__((interrupt)) void isr7(struct int_frame* r) { - isr_common(r, 7); -} -__attribute__((interrupt)) void isr8(struct int_frame* r, size_t error) { - isr_error_common(r, 8, error); -} -__attribute__((interrupt)) void isr9(struct int_frame* r) { - isr_common(r, 9); -} -__attribute__((interrupt)) void isr10(struct int_frame* r, size_t error) { - isr_error_common(r, 10, error); -} -__attribute__((interrupt)) void isr11(struct int_frame* r, size_t error) { - isr_error_common(r, 11, error); -} -__attribute__((interrupt)) void isr12(struct int_frame* r, size_t error) { - isr_error_common(r, 12, error); -} -__attribute__((interrupt)) void isr13(struct int_frame* r, size_t error) { - isr_error_common(r, 13, error); -} -__attribute__((interrupt)) void isr14(struct int_frame* r, size_t error) { - isr_error_common(r, 14, error); -} -__attribute__((interrupt)) void isr15(struct int_frame* r) { - isr_common(r, 15); -} -__attribute__((interrupt)) void isr16(struct int_frame* r) { - isr_common(r, 16); -} -__attribute__((interrupt)) void isr17(struct int_frame* r) { - isr_common(r, 17); -} -__attribute__((interrupt)) void isr18(struct int_frame* r) { - isr_common(r, 18); -} -__attribute__((interrupt)) void isr19(struct int_frame* r) { - isr_common(r, 19); -} -__attribute__((interrupt)) void isr20(struct int_frame* r) { - isr_common(r, 20); -} -__attribute__((interrupt)) void isr21(struct int_frame* r) { - isr_common(r, 21); -} -__attribute__((interrupt)) void isr22(struct int_frame* r) { - isr_common(r, 22); -} -__attribute__((interrupt)) void isr23(struct int_frame* r) { - isr_common(r, 23); -} -__attribute__((interrupt)) void isr24(struct int_frame* r) { - isr_common(r, 24); -} -__attribute__((interrupt)) void isr25(struct int_frame* r) { - isr_common(r, 25); -} -__attribute__((interrupt)) void isr26(struct int_frame* r) { - isr_common(r, 26); -} -__attribute__((interrupt)) void isr27(struct int_frame* r) { - isr_common(r, 27); -} -__attribute__((interrupt)) void isr28(struct int_frame* r) { - isr_common(r, 28); -} -__attribute__((interrupt)) void isr29(struct int_frame* r) { - isr_common(r, 29); -} -__attribute__((interrupt)) void isr30(struct int_frame* r) { - isr_common(r, 30); -} -__attribute__((interrupt)) void isr31(struct int_frame* r) { - isr_common(r, 31); -} - - -__attribute__((interrupt)) void irq0(struct int_frame* r) { - irq_common(r, 0); -} -__attribute__((interrupt)) void irq1(struct int_frame* r) { - irq_common(r, 1); -} -__attribute__((interrupt)) void irq2(struct int_frame* r) { - irq_common(r, 2); -} -__attribute__((interrupt)) void irq3(struct int_frame* r) { - irq_common(r, 3); -} -__attribute__((interrupt)) void irq4(struct int_frame* r) { - irq_common(r, 4); -} -__attribute__((interrupt)) void irq5(struct int_frame* r) { - irq_common(r, 5); -} -__attribute__((interrupt)) void irq6(struct int_frame* r) { - irq_common(r, 6); -} -__attribute__((interrupt)) void irq7(struct int_frame* r) { - irq_common(r, 7); -} -__attribute__((interrupt)) void irq8(struct int_frame* r) { - irq_common(r, 8); -} -__attribute__((interrupt)) void irq9(struct int_frame* r) { - irq_common(r, 9); -} -__attribute__((interrupt)) void irq10(struct int_frame* r) { - irq_common(r, 10); -} -__attribute__((interrupt)) void irq11(struct int_frame* r) { - irq_common(r, 11); -} -__attribute__((interrupt)) void irq12(struct int_frame* r) { - irq_common(r, 12); -} -__attribute__((interrupt)) void irq13(struct int_frame* r) { - irq_common(r, 13); -} -__attribute__((interrupt)) void irq14(struct int_frame* r) { - irq_common(r, 14); -} -__attribute__((interrupt)) void irq15(struct int_frame* r) { - irq_common(r, 15); -} \ No newline at end of file diff --git a/kernel/kernel.c b/kernel/kernel.c deleted file mode 100644 index a10c531..0000000 --- a/kernel/kernel.c +++ /dev/null @@ -1,119 +0,0 @@ -/************************ - *** Team Kitty, 2019 *** - *** Sync *** - ***********************/ - -/* This file contains the entry point - * to the kernel. This section consists - * mainly of bootloading functions. - * - * Graphics and memory will be setup - * at later stages. - */ - - -/* In the UEFI bootloading stages, - * most of this setup is no longer - * required. - * - * For example, a linear framebuffer - * is provided at loading, so there is - * no longer any need to initialise the - * screen, or print using our functions. - * - * Additionally, there are some other - * changes in how memory is mapped, but - * since there are no memory functions - * made yet, this is safe. 17/7/19 - */ - -//#include -#include -#include -#include -#include - -void gdb_end() {} /* GDB Debugging stump */ - - -/* Because we are loading from UEFI, this - * kernel entry point function is no longer - * called. - * - * It will be left until its functionality has - * been replicated into the UEFI entry point, - * and then it will be removed. - * - */ - -int kernel_main(void) { - /* The kernel is started in 32-bit protected mode by the ASM. */ - /* Here, we start by enabling the screen, then loading a GDT and IDT into the actual places they need to be. */ - - /* Black the screen out. */ - screen_initialize(); - - /* Prepare the serial line for our debug output. */ - init_serial(); - serial_print(0x3F8, "[INFO] Serial ready.\r\n"); - - - serial_print(0x3F8, "[INFO] Beginning GDT subroutine.\r\n"); - - /* term_writes: writes a string to the terminal. */ - term_writes("GDT..."); - - /* Prepares the Global Descriptor Table, called from gdt.c */ - gdt_install(); - - /* puts: writes a line to the terminal. */ - puts("GDT Ready."); - serial_print(0x3F8, "[INFO] GDT subroutine complete.\r\n"); - - /* Prepare the Interrupt Descriptor Table. */ - serial_print(0x3F8, "[INFO] Beginning IDT subroutine.\r\n"); - term_writes("IDT..."); - idt_install(); - puts("IDT Ready."); - serial_print(0x3F8, "[INFO] IDT subroutine complete.\r\n[INFO] Enabling interrupts.\r\n"); - - gdb_end(); /* The first important step. Waypoint it for gdb debugging. */ - - term_writes("Memory available:"); - /* TODO: implement check_a20, which double-triple checks the state of the A20 line. */ - - //if(check_a20()) - puts(" 4GB"); - serial_print(0x3F8, "[INFO] A20 enabled. 4GB memory available."); - - /* The first important thing: start the system clock immediately. */ - serial_print(0x3F8, "[INFO] Starting System Clock.\r\n"); - term_writes("Timer..."); - timer_install(); - puts("Timer Ready."); - - serial_print(0x3F8, "[INFO] All subsystems ready. Printing message.\r\n"); - - /* Everything is ready; print a pretty message. */ - term_setcolor(RED); - term_writes("\n(c)"); - term_setcolor(GREEN); - term_writes(" Sync"); - term_setcolor(WHITE); - term_writes(", 2019\n"); - - serial_print(0x3F8, "[INFO] All operations complete. Checking for other tasks...\r\n"); - - /* Here are a series of tests for the ANSI escape code and CSI implementations. */ - term_writes("\x1b[BA"); /* Down a line, then A. */ - - - /* A stub causing a Divide by Zero error. */ - serial_print(0x3F8, "[DEBUG] Attempting a Divide by Zero error.\r\n"); - char div = (5 / 0); - serial_print(0x3F8, "[DEBUG] Survived the error!\r\n"); - - gdb_end(); /* Everything is done. The last debug routine. */ - return 0; -} - diff --git a/kernel/serial.c b/kernel/serial.c deleted file mode 100755 index bc06ab3..0000000 --- a/kernel/serial.c +++ /dev/null @@ -1,194 +0,0 @@ -/************************ - *** Team Kitty, 2019 *** - *** Sync *** - ***********************/ - - /* This file provides an interface to the serial port. - * Most emulators allow the serial port to be saved into - * a text buffer, or a file, but this code should work on - * hardware with an actual serial port and monitor. */ - -#include -#include -#include -#include - -#define SERIAL_DATA_PORT(base) (base) -#define SERIAL_FIFO_COMMAND_PORT(base) (base + 2) -#define SERIAL_LINE_COMMAND_PORT(base) (base + 3) -#define SERIAL_MODEM_COMMAND_PORT(base) (base + 4) -#define SERIAL_LINE_STATUS_PORT(base) (base + 5) -#define SERIAL_COM1_BASE 0x3F8 - -#define SERIAL_LINE_ENABLE_DLAB 0x80 - -/** serial_set_baud_rate: - * Sets the speed that data is sent via the serial port. - * The default speed is 115200 bits/s. - * The argument given is the divisor of the number. - * Hence, the new speed becomes (115200/divisor) bits/s. - * - * @param com The COM port to configure. - * @param divisor The new divisor for the baud rate. - */ - -void serial_set_baud_rate(uint16_t com, uint16_t divisor) { - outb(SERIAL_LINE_COMMAND_PORT(com), - SERIAL_LINE_ENABLE_DLAB); - - outb(SERIAL_DATA_PORT(com), - (divisor >> 8) & 0x00FF); - - outb(SERIAL_DATA_PORT(com), - divisor & 0x00FF); - -} - -/** serial_configure_line: - * Sets a specific data byteset in the Serial hardware. - * Required for expected operation. - * - * @param com The COM port to configure. - */ - -void serial_configure_line(uint16_t com) { - /* Bit: | 7 | 6 | 5 4 3 | 2 | 1 0 | - * Content: | d | b | parity| s | dl | - * Value: | 0 | 0 | 0 0 0 | 0 | 1 1 | = 0x03 - */ - - outb(SERIAL_LINE_COMMAND_PORT(com), 0x0B); -} - -/** serial_configure_buffers: - * Enables FIFO (First In First Out) on the Serial line. - * It clears both the receive and transmit queues. - * It uses a 14 byte wide queue. - * - * @param com The COM port to configure. - */ - -void serial_configure_buffers(uint16_t com) { - /* Bit: | 7 6 | 5 | 4 | 3 | 2 | 1 | 0 | - * Content: | 1v1 | bs | r | dma | clt | clr | e | - * Value: | 1 1 | 0 | 0 | 0 | 1 | 1 | 1 | = 0xC7 - */ - - outb(SERIAL_FIFO_COMMAND_PORT(com), 0xC7); -} - -/** serial_configure_modem - * @param com The COM port to configure. - */ - -void serial_configure_modem(uint16_t com) { - /* Bit: | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | - * Content: | r | r | af | lb | ao2 | ao1 | rts | dtr | - * Value: | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | = 0x03 - */ - - outb(SERIAL_MODEM_COMMAND_PORT(com), 0x3); -} - -/** serial_check_tqueue: - * Checks whether the Transmit FIFO Queue is empty on the given port. - * - * @param com The COM port to check. - * @return 0 If the queue is not empty. - * 1 If the queue is empty. - */ - -int serial_check_tqueue(uint16_t com) { - return inb(SERIAL_LINE_STATUS_PORT(com)) & 0x20; -} - -/** serial_write: - * Prints a single character to the serial port. - * Does nothing fancy. - * @param com The COM port to write to. - * @param data The character to write. - */ - -void serial_write(uint16_t com, const char chr) { - //Hang until we have access to the COM port. - while(serial_check_tqueue(com) == 0); - outb(com, chr); -} - -/** serial_print: - * Prints a string to the serial port. - * Does not support ANSI codes, or color. - * - * @param com The COM port to write to. - * @param data The string to write. - */ - -void serial_print(uint16_t com, const char* data) { - for(size_t i = 0; i < strlen(data); i++) { - serial_write(com, data[i]); - } -} - -/** serial_printf: - * A printf-style function for the serial port. - * - * @param format The base string - used to substitute the succeding values. - * @param ... The substitutions. - */ - -void serial_printf(uint16_t com, const char* format, ...) { - uint32_t storage; //To hold temporary variables - char stringstore[10] = {0}; //To convert ints to strings. - va_list list; - va_start(list, format); - - for(size_t i = 0; i < strlen(format); i++) { - //Check for the format specifier - if(format[i] == '%') { - //Check for the other specs - if(format[i+1] == 'd') { - - storage = va_arg(list, int); - int_to_ascii(storage, stringstore); - serial_print(com, stringstore); - empty_string(stringstore); - i += 2; - - } else if(format[i+1] == 'x') { - - storage = va_arg(list, int); - int_to_hex(storage, stringstore); - serial_print(com, stringstore); - empty_string(stringstore); - i += 2; - - } else if(format[i+1] == 's') { - - serial_print(com, va_arg(list, char*)); - i += 2; - - } else { - serial_print(com, "ERROR: Attempting to parse unknown format string."); - return; - } - } else { - serial_write(com, format[i]); - i++; - } - } - va_end(list); //Free the list -} - -void init_serial() { - // Disable interrupts - outb(SERIAL_COM1_BASE + 1, 0x00); - - // Set baud rate divisor. - serial_set_baud_rate(SERIAL_COM1_BASE, 3); - // 8 bits, no parity, one stop bit. - serial_configure_line(SERIAL_COM1_BASE); - // Enable FIFO and clear buffers. - serial_configure_buffers(SERIAL_COM1_BASE); - // Enable IRQs, RTS/DSR set. - serial_configure_modem(SERIAL_COM1_BASE); -} diff --git a/kernel/syscalls.c b/kernel/syscalls.c deleted file mode 100644 index b7c6994..0000000 --- a/kernel/syscalls.c +++ /dev/null @@ -1,48 +0,0 @@ -/*#include -#include -#include -#include -#include -#include -#include - -//prototypes; these are the bare minimum for newlib to compile. - -void _exit(); - -int close(int file); - -char **environ; - -int execve(char *name, char **argv, char **env); - -int fork(); - -int fstat(int file, struct stat *st); - -int getpid(); - -int isatty(int file); - -int kill(int pid, int sig); - -int link(char *old, char *new); - -int lseek(int file, int ptr, int dir); - -int open(const char* name, int flags, ...); - -int read(int file, char* ptr, int len); - -caddr_t sbrk(int incr); - -int stat(const char* file, struct stat *st); - -clock_t times(struct tms* buf); - -int unlink(char* name); - -int wait(int file, char* ptr, int len); - -int gettimeofday(struct timeval* p, struct timezone* z); -*/ \ No newline at end of file diff --git a/kernel/utils.c b/kernel/utils.c deleted file mode 100644 index bc2de7a..0000000 --- a/kernel/utils.c +++ /dev/null @@ -1,200 +0,0 @@ -/************************ - *** Team Kitty, 2019 *** - *** Sync *** - ***********************/ - -/* This file contains utility functions - * for the kernel and OS to use. They - * will be naturally optimized through - * the run of development, and thus are - * to be used scarcely until a more - * permanent solution can be found. - */ - -#include -#include -#include -#include -#include -#include - -/* - Returns the length of a given string. - * @param string: String to count - */ -size_t strlen(const char* string) { - size_t size = 0; - while (string[size]) - size++; - return size; -} - -/* - Read data from a port. Effectively communicates with hardware. - * @param port: The port number to read, as a hex short. - */ -uint8_t inb(uint16_t port) { - uint8_t ptr; - asm volatile("inb %1, %0" : "=a" (ptr) : "dN" (port)); - return ptr; -} - -/* - Write data to a port. Effectively communicates with hardware. - * @param port: The port to read - * @param data: A pointer to which the data will be stored. - - */ -void outb(uint16_t port, uint8_t data) { - asm volatile("outb %1, %0" : : "dN" (port), "a" (data)); -} - - -/* - Memory Copy. Required by GCC. - * @param dest: The destination in memory, to which the data will be copied. - * @param src: The source of the data which will be copied. - * @param n: The length of the copy, in byets. - */ -void memcpy(void* dest, void* src, size_t n) { - char* src_c = (char*)src; - char* dest_c = (char*)dest; - - for(size_t i = 0; i < n; i++) { - dest_c[i] = src_c[i]; - } -} - -/* - Memory Set. Required by GCC> - * @param src: The data to be overwritten. - * @param chr: The byte to overwrite the source with. - * @param n: How many bytes to overwrite. -*/ -void memset(void* src, int chr, size_t n) { - uint8_t* ptr = src; - while(n--) { - *ptr++ = (uint8_t) chr; - } -} - - /* - Turns an integer into a C-str. - * @note Inefficient and unsafe. - * @param num: The number to convert - * @param string: The string to be written into. - */ - -void int_to_ascii(int num, char* string) { - size_t i = 0; //Counter. - // TODO: Convert this to a for-loop? - int32_t calc = 0; - bool negative = false; - - if(num == 0) { - string[0] = '0'; - string[1] = '\0'; - return; - } - - // TODO: Implement this as an abs() function? - if(num < 0) { - num = -num; - string[i] = '-'; - i++; - } - - while(num != 0) { - // Overall this looks pretty confusing. - // TODO: cleanup? - calc = num % 10; // Gets the lowest digit, - num = num / 10; // Shifts the other digits down to prepare for the next iteration. - calc += 48; // Convert the number to an ASCII value - - string[i] = calc;// Set the current position in the string - i++; // Increase for the next number. - } - - // ! This code does weird things. - // It serves an unknown purpose, and should not be used, but is left here just in case. - /* - for(size_t j = 0; j < i/2; j++) { - calc = string[j]; - string[j] = string[i-j-1]; - string[j-i-1] = calc; - } - */ -} - - /* - A strange version of the above function. Different way of doing the same thing? - * @param num: the number to convert. Must be positive - * @retval The new string. - */ -char* itoc(size_t num) { - char* result; - size_t tmp_value; - do { - tmp_value = num; - num /= 10; - *result++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - num * 10)]; - }while (num); - - return result; -} - - -/* - Same as itoa, but for hexadecimal. - * @param num: Number to convert - * @param string: String pointer to put the converted number. -*/ -void int_to_hex(int num, char* string) { - empty_string(string); - - uint8_t i = 8; - uint8_t temp = 0; - - while(i != 0) { - i--; - temp = num & 0xF; - num = num >> 4; - - if(temp >= 10) { - temp += 7; - } - - temp += 48; - string[i] = temp; - } -} - - /* - Converts a C-str to an empty C-str. :) - * @param string: The string to empty. - */ - -void empty_string(char* string) { - size_t len = strlen(string); - - for(size_t i = 0; i < len + 1; i++) { - string[i] = '\0'; - } -} - - - /* - The signal that everything has gone wrong. - Equivalent to a linux kernel panic and a Windows Blue Screen. - - TODO: Needs to be re-engineered to give as much useful information as possible. Ideally also have a visual interface, XP installer style. - - * @param cause: A string, telling the basic reason for the crash. - */ -void panic(char* cause) { - term_writes("\n\n>>>> PANIC <<<<\nCaused by: "); - term_writes(cause); - - for(;;); - -} diff --git a/main.c b/main.c new file mode 100644 index 0000000..5166bab --- /dev/null +++ b/main.c @@ -0,0 +1,35 @@ +#include +#include + +// Application entrypoint (must be set to 'efi_main' for gnu-efi crt0 compatibility) +EFI_STATUS efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) +{ + UINTN Event; + +#if defined(_GNU_EFI) + InitializeLib(ImageHandle, SystemTable); +#endif + + /* + * In addition to the standard %-based flags, Print() supports the following: + * %N Set output attribute to normal + * %H Set output attribute to highlight + * %E Set output attribute to error + * %B Set output attribute to blue color + * %V Set output attribute to green color + * %r Human readable version of a status code + */ + Print(L"\n%H*** Sync Bootloading ***%N\n\n"); + + + + Print(L"%BPress any key to exit.%N\n"); + SystemTable->ConIn->Reset(SystemTable->ConIn, FALSE); + SystemTable->BootServices->WaitForEvent(1, &SystemTable->ConIn->WaitForKey, &Event); +#if defined(_DEBUG) + // If running in debug mode, use the EFI shut down call to close QEMU + SystemTable->RuntimeServices->ResetSystem(EfiResetShutdown, EFI_SUCCESS, 0, NULL); +#endif + + return EFI_SUCCESS; +} diff --git a/makefile b/makefile index 79feb11..9e8239c 100755 --- a/makefile +++ b/makefile @@ -1,100 +1,171 @@ -DEFAULT_HOST:=i686-elf -HOST?=DEFAULT_HOST -HOSTARCH:=i386 -CC:=$(PREFIX)/bin/$(DEFAULT_HOST)-gcc - -CFLAGS?= -O0 -g -fno-pie -fno-stack-protector -Wl,--build-id=none -CPPFLAGS?= -LDFLAGS?= -LIBS?= - -DESTDIR?= -PREFIX?=/usr/local -EXEC_PREFIX?=$(PREFIX) -BOOTDIR?=$(EXEC_PREFIX)/boot -INCLUDEDIR?=$(PREFIX)/include - -CFLAGS:=$(CFLAGS) -ffreestanding -Wall -Wextra -I"../include" -I"../../include" -CPPFLAGS:=$(CPPFLAGS) -D__is_kernel -Iinclude -LDFLAGS:=$(LDFLAGS) -LIBS:=$(LIBS) -nostdlib -lgcc - -ARCHDIR=arch/$(HOSTARCH) - -include $(ARCHDIR)/make.config - -CFLAGS:=$(CFLAGS) $(KERNEL_ARCH_CFLAGS) -CPPFLAGS:=$(CPPFLAGS) $(KERNEL_ARCH_CPPFLAGS) -LDFLAGS:=$(LDFLAGS) $(KERNEL_ARCH_LDFLAGS) -LIBS:=$(LIBS) $(KERNEL_ARCH_LIBS) - -KERNEL_OBJS= \ -$(KERNEL_ARCH_OBJS) \ -kernel/utils.o \ -kernel/serial.o \ -kernel/interrupts.o \ -kernel/descriptor_tables.o \ -kernel/kernel.o - -OBJS=\ -$(KERNEL_OBJS) - -LINK_LIST=\ -$(LDFLAGS) \ -$(KERNEL_OBJS) \ -$(LIBS) \ - -.PHONY: all clean install install-headers install-kernel -.SUFFIXES: .o .c .s - -all: BOOTX64.EFI - -red.kernel: $(OBJS) $(ARCHDIR)/linker.ld - $(CC) -T $(ARCHDIR)/linker.ld -o $@ $(CFLAGS) $(LINK_LIST) - -kernel/interrupts.o: - $(CC) -MD -c kernel/interrupts.c -o $@ -std=gnu11 $(CFLAGS) -mno-red-zone -mgeneral-regs-only $(CPPFLAGS) - -.c.o: - $(CC) -MD -c $< -o $@ -std=gnu11 $(CFLAGS) $(CPPFLAGS) -.s.o: - nasm -f elf $< -o $@ - -clean: - rm -f red.kernel - rm -f $(OBJS) *.o */*.o */*/*.o - rm -f $(OBJS:.o=.d) *.d */*.d */*/*.d - -install: install-headers install-kernel gen-iso - -install-headers: - mkdir -p $(DESTDIR)$(INCLUDEDIR) - cp -R --preserve=timestamps include/. $(DESTDIR)$(INCLUDEDIR)/. - -install-kernel: red.kernel - mkdir -p $(DESTDIR)$(BOOTDIR) - cp red.kernel $(DESTDIR)$(BOOTDIR) - -gen-iso: - rm -f red.iso - cp red.kernel iso/boot/kernel.elf - genisoimage -R \ - -b boot/grub/stage2_eltorito \ - -no-emul-boot \ - -A ProjectRED \ - -input-charset utf8 \ - -quiet \ - -boot-info-table \ - -o red.iso \ - iso - -BOOTX64.EFI: arch/uefi/entry.o efi/lib/data.o - $(EFI-CC) -nostdlib -Wl,-dll -shared -Wl,--subsystem,10 -e efi_main -o BOOTX64.EFI arch/uefi/entry.o data.o -lgcc - -arch/uefi/entry.o: - $(EFI-CC) -ffreestanding -Iinclude/efi/ -Iinclude/efi/x86_64 -Iinclude/efi/protocol -c -o arch/uefi/entry.o arch/uefi/entry.c - -efi/lib/data.o: - $(EFI-CC) -ffreestanding -Iinclude/efi/ -Iinclude/efi/x86_64 -Iinclude/efi/protocol -c -o data.o efi/lib/data.c - --include $(OBJS:.o=.d) +ARCH = x64 +# You can alter the subsystem according to your EFI binary target: +# 10 = EFI application +# 11 = EFI boot service driver +# 12 = EFI runtime driver +SUBSYSTEM = 10 + +# Try to auto-detect the target ARCH +ifeq ($(shell uname -o),Msys) + IS_MINGW32 = $(findstring MINGW32,$(shell uname -s)) + IS_MINGW64 = $(findstring MINGW64,$(shell uname -s)) + ifeq ($(IS_MINGW32),MINGW32) + ARCH = ia32 + endif + ifeq ($(IS_MINGW64),MINGW64) + ARCH = x64 + endif +else + ifeq ($(shell uname -m),x86_64) + ARCH = x64 + else ifeq ($(shell uname -m),arm) + ARCH = arm + CROSS_COMPILE = + else ifeq ($(shell uname -m),aarch64) + ARCH = aa64 + CROSS_COMPILE = + else + ARCH = ia32 + endif +endif + +# Auto-detect the host arch for MinGW +ifeq ($(shell uname -m),x86_64) + MINGW_HOST = w64 +else + MINGW_HOST = w32 +endif + +ifeq ($(ARCH),x64) + GNUEFI_ARCH = x86_64 + GCC_ARCH = x86_64 + QEMU_ARCH = x86_64 + FW_BASE = OVMF + CROSS_COMPILE = $(GCC_ARCH)-$(MINGW_HOST)-mingw32- + EP_PREFIX = + CFLAGS = -m64 -mno-red-zone + LDFLAGS = -Wl,-dll -Wl,--subsystem,$(SUBSYSTEM) +else ifeq ($(ARCH),ia32) + GNUEFI_ARCH = ia32 + GCC_ARCH = i686 + QEMU_ARCH = i386 + FW_BASE = OVMF + CROSS_COMPILE = $(GCC_ARCH)-$(MINGW_HOST)-mingw32- + EP_PREFIX = _ + CFLAGS = -m32 -mno-red-zone + LDFLAGS = -Wl,-dll -Wl,--subsystem,$(SUBSYSTEM) +else ifeq ($(ARCH),arm) + GNUEFI_ARCH = arm + GCC_ARCH = arm + QEMU_ARCH = arm + FW_BASE = QEMU_EFI + CROSS_COMPILE = $(GCC_ARCH)-linux-gnueabihf- + EP_PREFIX = + CFLAGS = -marm -fpic -fshort-wchar + LDFLAGS = -Wl,--no-wchar-size-warning -Wl,--defsym=EFI_SUBSYSTEM=$(SUBSYSTEM) + CRT0_LIBS = -lgnuefi + QEMU_OPTS = -M virt -cpu cortex-a15 +else ifeq ($(ARCH),aa64) + GNUEFI_ARCH = aarch64 + GCC_ARCH = aarch64 + QEMU_ARCH = aarch64 + FW_BASE = QEMU_EFI + CROSS_COMPILE = $(GCC_ARCH)-linux-gnu- + EP_PREFIX = + CFLAGS = -fpic -fshort-wchar + LDFLAGS = -Wl,--no-wchar-size-warning -Wl,--defsym=EFI_SUBSYSTEM=$(SUBSYSTEM) + CRT0_LIBS = -lgnuefi + QEMU_OPTS = -M virt -cpu cortex-a57 +endif +FW_ARCH = $(shell echo $(ARCH) | tr a-z A-Z) +FW_ZIP = $(FW_BASE)-$(FW_ARCH).zip +GNUEFI_DIR = $(CURDIR)/gnu-efi +GNUEFI_LIBS = lib + +# If the compiler produces an elf binary, we need to fiddle with a PE crt0 +ifneq ($(CRT0_LIBS),) + CRT0_DIR = $(GNUEFI_DIR)/$(GNUEFI_ARCH)/gnuefi + LDFLAGS += -L$(CRT0_DIR) -T $(GNUEFI_DIR)/gnuefi/elf_$(GNUEFI_ARCH)_efi.lds $(CRT0_DIR)/crt0-efi-$(GNUEFI_ARCH).o + GNUEFI_LIBS += gnuefi +endif + +# SYSTEMROOT is only defined on Windows systems +ifneq ($(SYSTEMROOT),) + QEMU = "/c/Program Files/qemu/qemu-system-$(QEMU_ARCH)w.exe" + # MinGW on Windows doesn't use (tuple)-ar but (tuple)-gcc-ar + # so we remove the cross compiler tuple altogether + CROSS_COMPILE = +else + QEMU = qemu-system-$(QEMU_ARCH) -nographic +endif + +CC := $(CROSS_COMPILE)gcc +OBJCOPY := $(CROSS_COMPILE)objcopy +CFLAGS += -fno-stack-protector -Wshadow -Wall -Wunused -Werror-implicit-function-declaration +CFLAGS += -I$(GNUEFI_DIR)/inc -I$(GNUEFI_DIR)/inc/$(GNUEFI_ARCH) -I$(GNUEFI_DIR)/inc/protocol +CFLAGS += -DCONFIG_$(GNUEFI_ARCH) -D__MAKEWITH_GNUEFI -DGNU_EFI_USE_MS_ABI +LDFLAGS += -L$(GNUEFI_DIR)/$(GNUEFI_ARCH)/lib -e $(EP_PREFIX)efi_main +LDFLAGS += -s -Wl,-Bsymbolic -nostdlib -shared +LIBS = -lefi $(CRT0_LIBS) + +ifeq (, $(shell which $(CC))) + $(error The selected compiler ($(CC)) was not found) +endif + +GCCVERSION := $(shell $(CC) -dumpversion | cut -f1 -d.) +GCCMINOR := $(shell $(CC) -dumpversion | cut -f2 -d.) +GCCMACHINE := $(shell $(CC) -dumpmachine) +GCCNEWENOUGH := $(shell ( [ $(GCCVERSION) -gt "4" ] \ + || ( [ $(GCCVERSION) -eq "4" ] \ + && [ $(GCCMINOR) -ge "7" ] ) ) \ + && echo 1) +ifneq ($(GCCNEWENOUGH),1) + $(error You need GCC 4.7 or later) +endif + +ifneq ($(GCC_ARCH),$(findstring $(GCC_ARCH), $(GCCMACHINE))) + $(error The selected compiler ($(CC)) is not set for $(ARCH)) +endif + +.PHONY: all clean superclean +all: $(GNUEFI_DIR)/$(GNUEFI_ARCH)/lib/libefi.a main.efi + +$(GNUEFI_DIR)/$(GNUEFI_ARCH)/lib/libefi.a: + $(MAKE) -C$(GNUEFI_DIR) CROSS_COMPILE=$(CROSS_COMPILE) ARCH=$(GNUEFI_ARCH) $(GNUEFI_LIBS) + +%.efi: %.o + @echo [LD] $(notdir $@) +ifeq ($(CRT0_LIBS),) + @$(CC) $(LDFLAGS) $< -o $@ $(LIBS) +else + @$(CC) $(LDFLAGS) $< -o $*.elf $(LIBS) + @$(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel* \ + -j .rela* -j .reloc -j .eh_frame -O binary $*.elf $@ + @rm -f $*.elf +endif + +%.o: %.c + @echo [CC] $(notdir $@) + @$(CC) $(CFLAGS) -ffreestanding -c $< + +qemu: CFLAGS += -D_DEBUG +qemu: all $(FW_BASE)_$(FW_ARCH).fd image/efi/boot/boot$(ARCH).efi + $(QEMU) $(QEMU_OPTS) -bios ./$(FW_BASE)_$(FW_ARCH).fd -net none -hda fat:rw:image + +image/efi/boot/boot$(ARCH).efi: main.efi + mkdir -p image/efi/boot + cp -f $< $@ + +$(FW_BASE)_$(FW_ARCH).fd: + wget https://efi.akeo.ie/$(FW_BASE)/$(FW_ZIP) + unzip $(FW_ZIP) $(FW_BASE).fd + mv $(FW_BASE).fd $(FW_BASE)_$(FW_ARCH).fd + rm $(FW_ZIP) + +clean: + rm -f main.efi *.o + rm -rf image + +superclean: clean + $(MAKE) -C$(GNUEFI_DIR) ARCH=$(GNUEFI_ARCH) clean + rm -f *.fd diff --git a/uefi-simple.sln b/uefi-simple.sln new file mode 100644 index 0000000..f2012a9 --- /dev/null +++ b/uefi-simple.sln @@ -0,0 +1,64 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27004.2006 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "uefi-simple", ".vs\msvc\uefi-simple.vcxproj", "{DFA0BA98-D0BA-4176-9A34-B5BA6355B1DE}" + ProjectSection(ProjectDependencies) = postProject + {3135D563-9596-4584-9ED6-616ADEC52974} = {3135D563-9596-4584-9ED6-616ADEC52974} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gnu-efi", ".vs\msvc\gnu-efi.vcxproj", "{3135D563-9596-4584-9ED6-616ADEC52974}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|arm = Debug|arm + Debug|aa64 = Debug|aa64 + Debug|ia32 = Debug|ia32 + Debug|x64 = Debug|x64 + Release|arm = Release|arm + Release|aa64 = Release|aa64 + Release|ia32 = Release|ia32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DFA0BA98-D0BA-4176-9A34-B5BA6355B1DE}.Debug|arm.ActiveCfg = Debug|ARM + {DFA0BA98-D0BA-4176-9A34-B5BA6355B1DE}.Debug|arm.Build.0 = Debug|ARM + {DFA0BA98-D0BA-4176-9A34-B5BA6355B1DE}.Debug|aa64.ActiveCfg = Debug|ARM64 + {DFA0BA98-D0BA-4176-9A34-B5BA6355B1DE}.Debug|aa64.Build.0 = Debug|ARM64 + {DFA0BA98-D0BA-4176-9A34-B5BA6355B1DE}.Debug|ia32.ActiveCfg = Debug|Win32 + {DFA0BA98-D0BA-4176-9A34-B5BA6355B1DE}.Debug|ia32.Build.0 = Debug|Win32 + {DFA0BA98-D0BA-4176-9A34-B5BA6355B1DE}.Debug|x64.ActiveCfg = Debug|x64 + {DFA0BA98-D0BA-4176-9A34-B5BA6355B1DE}.Debug|x64.Build.0 = Debug|x64 + {DFA0BA98-D0BA-4176-9A34-B5BA6355B1DE}.Release|arm.ActiveCfg = Release|ARM + {DFA0BA98-D0BA-4176-9A34-B5BA6355B1DE}.Release|arm.Build.0 = Release|ARM + {DFA0BA98-D0BA-4176-9A34-B5BA6355B1DE}.Release|aa64.ActiveCfg = Release|ARM64 + {DFA0BA98-D0BA-4176-9A34-B5BA6355B1DE}.Release|aa64.Build.0 = Release|ARM64 + {DFA0BA98-D0BA-4176-9A34-B5BA6355B1DE}.Release|ia32.ActiveCfg = Release|Win32 + {DFA0BA98-D0BA-4176-9A34-B5BA6355B1DE}.Release|ia32.Build.0 = Release|Win32 + {DFA0BA98-D0BA-4176-9A34-B5BA6355B1DE}.Release|x64.ActiveCfg = Release|x64 + {DFA0BA98-D0BA-4176-9A34-B5BA6355B1DE}.Release|x64.Build.0 = Release|x64 + {3135D563-9596-4584-9ED6-616ADEC52974}.Debug|arm.ActiveCfg = Debug|ARM + {3135D563-9596-4584-9ED6-616ADEC52974}.Debug|arm.Build.0 = Debug|ARM + {3135D563-9596-4584-9ED6-616ADEC52974}.Debug|aa64.ActiveCfg = Debug|ARM64 + {3135D563-9596-4584-9ED6-616ADEC52974}.Debug|aa64.Build.0 = Debug|ARM64 + {3135D563-9596-4584-9ED6-616ADEC52974}.Debug|ia32.ActiveCfg = Debug|Win32 + {3135D563-9596-4584-9ED6-616ADEC52974}.Debug|ia32.Build.0 = Debug|Win32 + {3135D563-9596-4584-9ED6-616ADEC52974}.Debug|x64.ActiveCfg = Debug|x64 + {3135D563-9596-4584-9ED6-616ADEC52974}.Debug|x64.Build.0 = Debug|x64 + {3135D563-9596-4584-9ED6-616ADEC52974}.Release|arm.ActiveCfg = Release|ARM + {3135D563-9596-4584-9ED6-616ADEC52974}.Release|arm.Build.0 = Release|ARM + {3135D563-9596-4584-9ED6-616ADEC52974}.Release|aa64.ActiveCfg = Release|ARM64 + {3135D563-9596-4584-9ED6-616ADEC52974}.Release|aa64.Build.0 = Release|ARM64 + {3135D563-9596-4584-9ED6-616ADEC52974}.Release|ia32.ActiveCfg = Release|Win32 + {3135D563-9596-4584-9ED6-616ADEC52974}.Release|ia32.Build.0 = Release|Win32 + {3135D563-9596-4584-9ED6-616ADEC52974}.Release|x64.ActiveCfg = Release|x64 + {3135D563-9596-4584-9ED6-616ADEC52974}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {376E6530-5878-4CF4-AFB7-123F799056A2} + EndGlobalSection +EndGlobal diff --git a/x64/Debug/gnu-efi.lib b/x64/Debug/gnu-efi.lib new file mode 100644 index 0000000..a83d6c4 Binary files /dev/null and b/x64/Debug/gnu-efi.lib differ diff --git a/x64/Debug/gnu-efi.pdb b/x64/Debug/gnu-efi.pdb new file mode 100644 index 0000000..6704fbd Binary files /dev/null and b/x64/Debug/gnu-efi.pdb differ diff --git a/x64/Debug/gnu-efi/boxdraw.obj b/x64/Debug/gnu-efi/boxdraw.obj new file mode 100644 index 0000000..b69f1a0 Binary files /dev/null and b/x64/Debug/gnu-efi/boxdraw.obj differ diff --git a/x64/Debug/gnu-efi/cmdline.obj b/x64/Debug/gnu-efi/cmdline.obj new file mode 100644 index 0000000..3df2fc7 Binary files /dev/null and b/x64/Debug/gnu-efi/cmdline.obj differ diff --git a/x64/Debug/gnu-efi/console.obj b/x64/Debug/gnu-efi/console.obj new file mode 100644 index 0000000..f3c6b2f Binary files /dev/null and b/x64/Debug/gnu-efi/console.obj differ diff --git a/x64/Debug/gnu-efi/crc.obj b/x64/Debug/gnu-efi/crc.obj new file mode 100644 index 0000000..18c5fac Binary files /dev/null and b/x64/Debug/gnu-efi/crc.obj differ diff --git a/x64/Debug/gnu-efi/data.obj b/x64/Debug/gnu-efi/data.obj new file mode 100644 index 0000000..7258fa2 Binary files /dev/null and b/x64/Debug/gnu-efi/data.obj differ diff --git a/x64/Debug/gnu-efi/debug.obj b/x64/Debug/gnu-efi/debug.obj new file mode 100644 index 0000000..6e90f7b Binary files /dev/null and b/x64/Debug/gnu-efi/debug.obj differ diff --git a/x64/Debug/gnu-efi/dpath.obj b/x64/Debug/gnu-efi/dpath.obj new file mode 100644 index 0000000..1f681e3 Binary files /dev/null and b/x64/Debug/gnu-efi/dpath.obj differ diff --git a/x64/Debug/gnu-efi/efirtlib.obj b/x64/Debug/gnu-efi/efirtlib.obj new file mode 100644 index 0000000..8189c5a Binary files /dev/null and b/x64/Debug/gnu-efi/efirtlib.obj differ diff --git a/x64/Debug/gnu-efi/error.obj b/x64/Debug/gnu-efi/error.obj new file mode 100644 index 0000000..731f495 Binary files /dev/null and b/x64/Debug/gnu-efi/error.obj differ diff --git a/x64/Debug/gnu-efi/event.obj b/x64/Debug/gnu-efi/event.obj new file mode 100644 index 0000000..0a8c0b4 Binary files /dev/null and b/x64/Debug/gnu-efi/event.obj differ diff --git a/x64/Debug/gnu-efi/gnu-efi.log b/x64/Debug/gnu-efi/gnu-efi.log new file mode 100644 index 0000000..13cacad --- /dev/null +++ b/x64/Debug/gnu-efi/gnu-efi.log @@ -0,0 +1,31 @@ + boxdraw.c + cmdline.c + console.c + crc.c + data.c + debug.c + dpath.c + error.c + event.c + guid.c + hand.c + hw.c + init.c + lock.c + misc.c + print.c + efirtlib.c + rtdata.c + rtlock.c + rtstr.c + Generating Code... + Compiling... + vm.c + smbios.c + sread.c + str.c + Generating Code... + initplat.c + math.c + Generating Code... + gnu-efi.vcxproj -> C:\Users\Gem\Documents\uefi-simple\x64\Debug\gnu-efi.lib diff --git a/x64/Debug/gnu-efi/gnu-efi.pdb b/x64/Debug/gnu-efi/gnu-efi.pdb new file mode 100644 index 0000000..6704fbd Binary files /dev/null and b/x64/Debug/gnu-efi/gnu-efi.pdb differ diff --git a/x64/Debug/gnu-efi/gnu-efi.tlog/CL.command.1.tlog b/x64/Debug/gnu-efi/gnu-efi.tlog/CL.command.1.tlog new file mode 100644 index 0000000..d5b6a37 Binary files /dev/null and b/x64/Debug/gnu-efi/gnu-efi.tlog/CL.command.1.tlog differ diff --git a/x64/Debug/gnu-efi/gnu-efi.tlog/CL.read.1.tlog b/x64/Debug/gnu-efi/gnu-efi.tlog/CL.read.1.tlog new file mode 100644 index 0000000..e0cd1fc Binary files /dev/null and b/x64/Debug/gnu-efi/gnu-efi.tlog/CL.read.1.tlog differ diff --git a/x64/Debug/gnu-efi/gnu-efi.tlog/CL.write.1.tlog b/x64/Debug/gnu-efi/gnu-efi.tlog/CL.write.1.tlog new file mode 100644 index 0000000..8170448 Binary files /dev/null and b/x64/Debug/gnu-efi/gnu-efi.tlog/CL.write.1.tlog differ diff --git a/x64/Debug/gnu-efi/gnu-efi.tlog/Lib-link.read.1.tlog b/x64/Debug/gnu-efi/gnu-efi.tlog/Lib-link.read.1.tlog new file mode 100644 index 0000000..894fdf8 Binary files /dev/null and b/x64/Debug/gnu-efi/gnu-efi.tlog/Lib-link.read.1.tlog differ diff --git a/x64/Debug/gnu-efi/gnu-efi.tlog/Lib-link.write.1.tlog b/x64/Debug/gnu-efi/gnu-efi.tlog/Lib-link.write.1.tlog new file mode 100644 index 0000000..820f2e2 Binary files /dev/null and b/x64/Debug/gnu-efi/gnu-efi.tlog/Lib-link.write.1.tlog differ diff --git a/x64/Debug/gnu-efi/gnu-efi.tlog/Lib.command.1.tlog b/x64/Debug/gnu-efi/gnu-efi.tlog/Lib.command.1.tlog new file mode 100644 index 0000000..12ebf11 Binary files /dev/null and b/x64/Debug/gnu-efi/gnu-efi.tlog/Lib.command.1.tlog differ diff --git a/x64/Debug/gnu-efi/gnu-efi.tlog/gnu-efi.lastbuildstate b/x64/Debug/gnu-efi/gnu-efi.tlog/gnu-efi.lastbuildstate new file mode 100644 index 0000000..ed802cb --- /dev/null +++ b/x64/Debug/gnu-efi/gnu-efi.tlog/gnu-efi.lastbuildstate @@ -0,0 +1,2 @@ +#TargetFrameworkVersion=v4.0:PlatformToolSet=v141:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native64Bit:WindowsTargetPlatformVersion=10.0.17763.0 +Debug|x64|C:\Users\Gem\Documents\uefi-simple\| diff --git a/x64/Debug/gnu-efi/guid.obj b/x64/Debug/gnu-efi/guid.obj new file mode 100644 index 0000000..c8ee1c0 Binary files /dev/null and b/x64/Debug/gnu-efi/guid.obj differ diff --git a/x64/Debug/gnu-efi/hand.obj b/x64/Debug/gnu-efi/hand.obj new file mode 100644 index 0000000..89d7cd7 Binary files /dev/null and b/x64/Debug/gnu-efi/hand.obj differ diff --git a/x64/Debug/gnu-efi/hw.obj b/x64/Debug/gnu-efi/hw.obj new file mode 100644 index 0000000..fb97db3 Binary files /dev/null and b/x64/Debug/gnu-efi/hw.obj differ diff --git a/x64/Debug/gnu-efi/init.obj b/x64/Debug/gnu-efi/init.obj new file mode 100644 index 0000000..20efc17 Binary files /dev/null and b/x64/Debug/gnu-efi/init.obj differ diff --git a/x64/Debug/gnu-efi/initplat.obj b/x64/Debug/gnu-efi/initplat.obj new file mode 100644 index 0000000..73033db Binary files /dev/null and b/x64/Debug/gnu-efi/initplat.obj differ diff --git a/x64/Debug/gnu-efi/lock.obj b/x64/Debug/gnu-efi/lock.obj new file mode 100644 index 0000000..acd09fe Binary files /dev/null and b/x64/Debug/gnu-efi/lock.obj differ diff --git a/x64/Debug/gnu-efi/math.obj b/x64/Debug/gnu-efi/math.obj new file mode 100644 index 0000000..8269882 Binary files /dev/null and b/x64/Debug/gnu-efi/math.obj differ diff --git a/x64/Debug/gnu-efi/misc.obj b/x64/Debug/gnu-efi/misc.obj new file mode 100644 index 0000000..9ea6aaa Binary files /dev/null and b/x64/Debug/gnu-efi/misc.obj differ diff --git a/x64/Debug/gnu-efi/print.obj b/x64/Debug/gnu-efi/print.obj new file mode 100644 index 0000000..d2981cf Binary files /dev/null and b/x64/Debug/gnu-efi/print.obj differ diff --git a/x64/Debug/gnu-efi/rtdata.obj b/x64/Debug/gnu-efi/rtdata.obj new file mode 100644 index 0000000..c950f6a Binary files /dev/null and b/x64/Debug/gnu-efi/rtdata.obj differ diff --git a/x64/Debug/gnu-efi/rtlock.obj b/x64/Debug/gnu-efi/rtlock.obj new file mode 100644 index 0000000..cf6e24b Binary files /dev/null and b/x64/Debug/gnu-efi/rtlock.obj differ diff --git a/x64/Debug/gnu-efi/rtstr.obj b/x64/Debug/gnu-efi/rtstr.obj new file mode 100644 index 0000000..0e67829 Binary files /dev/null and b/x64/Debug/gnu-efi/rtstr.obj differ diff --git a/x64/Debug/gnu-efi/smbios.obj b/x64/Debug/gnu-efi/smbios.obj new file mode 100644 index 0000000..a323d0d Binary files /dev/null and b/x64/Debug/gnu-efi/smbios.obj differ diff --git a/x64/Debug/gnu-efi/sread.obj b/x64/Debug/gnu-efi/sread.obj new file mode 100644 index 0000000..0270bec Binary files /dev/null and b/x64/Debug/gnu-efi/sread.obj differ diff --git a/x64/Debug/gnu-efi/str.obj b/x64/Debug/gnu-efi/str.obj new file mode 100644 index 0000000..52948f8 Binary files /dev/null and b/x64/Debug/gnu-efi/str.obj differ diff --git a/x64/Debug/gnu-efi/vm.obj b/x64/Debug/gnu-efi/vm.obj new file mode 100644 index 0000000..4495520 Binary files /dev/null and b/x64/Debug/gnu-efi/vm.obj differ diff --git a/x64/Debug/uefi-simple.pdb b/x64/Debug/uefi-simple.pdb new file mode 100644 index 0000000..70117b6 Binary files /dev/null and b/x64/Debug/uefi-simple.pdb differ diff --git a/x64/Debug/uefi-simple/main.obj b/x64/Debug/uefi-simple/main.obj new file mode 100644 index 0000000..92d12ee Binary files /dev/null and b/x64/Debug/uefi-simple/main.obj differ diff --git a/x64/Debug/uefi-simple/uefi-simple.log b/x64/Debug/uefi-simple/uefi-simple.log new file mode 100644 index 0000000..513e3ee --- /dev/null +++ b/x64/Debug/uefi-simple/uefi-simple.log @@ -0,0 +1,2 @@ + main.c + uefi-simple.vcxproj -> C:\Users\Gem\Documents\uefi-simple\x64\Debug\uefi-simple.efi diff --git a/x64/Debug/uefi-simple/uefi-simple.tlog/CL.command.1.tlog b/x64/Debug/uefi-simple/uefi-simple.tlog/CL.command.1.tlog new file mode 100644 index 0000000..2cba74c Binary files /dev/null and b/x64/Debug/uefi-simple/uefi-simple.tlog/CL.command.1.tlog differ diff --git a/x64/Debug/uefi-simple/uefi-simple.tlog/CL.read.1.tlog b/x64/Debug/uefi-simple/uefi-simple.tlog/CL.read.1.tlog new file mode 100644 index 0000000..a5283e0 Binary files /dev/null and b/x64/Debug/uefi-simple/uefi-simple.tlog/CL.read.1.tlog differ diff --git a/x64/Debug/uefi-simple/uefi-simple.tlog/CL.write.1.tlog b/x64/Debug/uefi-simple/uefi-simple.tlog/CL.write.1.tlog new file mode 100644 index 0000000..cff84fb Binary files /dev/null and b/x64/Debug/uefi-simple/uefi-simple.tlog/CL.write.1.tlog differ diff --git a/x64/Debug/uefi-simple/uefi-simple.tlog/link.command.1.tlog b/x64/Debug/uefi-simple/uefi-simple.tlog/link.command.1.tlog new file mode 100644 index 0000000..25c86c6 Binary files /dev/null and b/x64/Debug/uefi-simple/uefi-simple.tlog/link.command.1.tlog differ diff --git a/x64/Debug/uefi-simple/uefi-simple.tlog/link.read.1.tlog b/x64/Debug/uefi-simple/uefi-simple.tlog/link.read.1.tlog new file mode 100644 index 0000000..f5fc68a Binary files /dev/null and b/x64/Debug/uefi-simple/uefi-simple.tlog/link.read.1.tlog differ diff --git a/x64/Debug/uefi-simple/uefi-simple.tlog/link.write.1.tlog b/x64/Debug/uefi-simple/uefi-simple.tlog/link.write.1.tlog new file mode 100644 index 0000000..004d884 Binary files /dev/null and b/x64/Debug/uefi-simple/uefi-simple.tlog/link.write.1.tlog differ diff --git a/x64/Debug/uefi-simple/uefi-simple.tlog/uefi-simple.lastbuildstate b/x64/Debug/uefi-simple/uefi-simple.tlog/uefi-simple.lastbuildstate new file mode 100644 index 0000000..ed802cb --- /dev/null +++ b/x64/Debug/uefi-simple/uefi-simple.tlog/uefi-simple.lastbuildstate @@ -0,0 +1,2 @@ +#TargetFrameworkVersion=v4.0:PlatformToolSet=v141:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native64Bit:WindowsTargetPlatformVersion=10.0.17763.0 +Debug|x64|C:\Users\Gem\Documents\uefi-simple\| diff --git a/x64/Debug/uefi-simple/vc141.pdb b/x64/Debug/uefi-simple/vc141.pdb new file mode 100644 index 0000000..6f16fd5 Binary files /dev/null and b/x64/Debug/uefi-simple/vc141.pdb differ