├── .gdbinit ├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── ap_trampoline.asm ├── ap_trampoline.h ├── blueguard.c ├── gnu-efi ├── .gitignore ├── ChangeLog ├── Make.defaults ├── Make.rules ├── Makefile ├── README.efilib ├── README.elilo ├── README.git ├── README.gnuefi ├── apps │ ├── AllocPages.c │ ├── FreePages.c │ ├── Makefile │ ├── drv0.c │ ├── drv0.h │ ├── drv0_use.c │ ├── modelist.c │ ├── printenv.c │ ├── route80h.c │ ├── t.c │ ├── t2.c │ ├── t3.c │ ├── t4.c │ ├── t5.c │ ├── t6.c │ ├── t7.c │ ├── t8.c │ ├── tcc.c │ ├── tpause.c │ └── trivial.S ├── gnuefi │ ├── Makefile │ ├── crt0-efi-aarch64.S │ ├── crt0-efi-arm.S │ ├── crt0-efi-ia32.S │ ├── crt0-efi-ia64.S │ ├── crt0-efi-x86_64.S │ ├── elf_aarch64_efi.lds │ ├── elf_arm_efi.lds │ ├── elf_ia32_efi.lds │ ├── elf_ia32_fbsd_efi.lds │ ├── elf_ia64_efi.lds │ ├── elf_x86_64_efi.lds │ ├── elf_x86_64_fbsd_efi.lds │ ├── reloc_aarch64.c │ ├── reloc_arm.c │ ├── reloc_ia32.c │ ├── reloc_ia64.S │ └── reloc_x86_64.c ├── inc │ ├── Makefile │ ├── aarch64 │ │ ├── efibind.h │ │ └── efilibplat.h │ ├── arm │ │ ├── efibind.h │ │ └── efilibplat.h │ ├── efi.h │ ├── efi_nii.h │ ├── efi_pxe.h │ ├── efiapi.h │ ├── eficon.h │ ├── efidebug.h │ ├── efidef.h │ ├── efidevp.h │ ├── efierr.h │ ├── efifs.h │ ├── efigpt.h │ ├── efiip.h │ ├── efilib.h │ ├── efilink.h │ ├── efinet.h │ ├── efipart.h │ ├── efipciio.h │ ├── efipoint.h │ ├── efiprot.h │ ├── efipxebc.h │ ├── efirtlib.h │ ├── efiser.h │ ├── efishellintf.h │ ├── efishellparm.h │ ├── efistdarg.h │ ├── efitcp.h │ ├── efiudp.h │ ├── efiui.h │ ├── ia32 │ │ ├── efibind.h │ │ ├── efilibplat.h │ │ └── pe.h │ ├── ia64 │ │ ├── efibind.h │ │ ├── efilibplat.h │ │ ├── pe.h │ │ └── salproc.h │ ├── inc.mak │ ├── libsmbios.h │ ├── make.inf │ ├── makefile.hdr │ ├── pci22.h │ ├── protocol │ │ ├── adapterdebug.h │ │ ├── eficonsplit.h │ │ ├── efidbg.h │ │ ├── efivar.h │ │ ├── ia64 │ │ │ └── eficontext.h │ │ ├── intload.h │ │ ├── legacyboot.h │ │ ├── make.inf │ │ ├── makefile.hdr │ │ ├── piflash64.h │ │ ├── readme.txt │ │ └── vgaclass.h │ ├── romload.h │ └── x86_64 │ │ ├── efibind.h │ │ ├── efilibplat.h │ │ └── pe.h └── lib │ ├── Makefile │ ├── aarch64 │ ├── efi_stub.S │ ├── initplat.c │ └── math.c │ ├── arm │ ├── div64.S │ ├── efi_stub.S │ ├── initplat.c │ ├── lib1funcs.S │ └── math.c │ ├── boxdraw.c │ ├── cmdline.c │ ├── console.c │ ├── crc.c │ ├── data.c │ ├── debug.c │ ├── dpath.c │ ├── error.c │ ├── event.c │ ├── guid.c │ ├── hand.c │ ├── hw.c │ ├── ia32 │ ├── efi_stub.S │ ├── initplat.c │ └── math.c │ ├── ia64 │ ├── initplat.c │ ├── math.c │ ├── palproc.S │ ├── palproc.h │ └── salpal.c │ ├── init.c │ ├── lib.h │ ├── lock.c │ ├── misc.c │ ├── print.c │ ├── runtime │ ├── efirtlib.c │ ├── rtdata.c │ ├── rtlock.c │ ├── rtstr.c │ └── vm.c │ ├── smbios.c │ ├── sread.c │ ├── str.c │ └── x86_64 │ ├── callwrap.c │ ├── efi_stub.S │ ├── initplat.c │ └── math.c ├── hv_driver.c ├── hv_handlers.c ├── hv_handlers.h ├── lib_uefi.c ├── lib_uefi.h ├── pic.asm ├── pic.h ├── realmode_emu.c ├── realmode_emu.h ├── regs.asm ├── regs.h ├── reloc_pe.c ├── reloc_pe.h ├── smp.c ├── smp.h ├── spinlock.asm ├── spinlock.h ├── string.c ├── string.h ├── vm_setup.c ├── vm_setup.h ├── vmx_api.asm ├── vmx_api.c ├── vmx_api.h ├── vmx_emu.asm ├── vmx_emu.h └── win8_ap_tramp.asm /.gdbinit: -------------------------------------------------------------------------------- 1 | layout split 2 | #layout reg 3 | set disassembly-flavor intel 4 | set architecture i386:x86-64 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.obj 5 | *.elf 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Libraries 12 | *.lib 13 | *.a 14 | *.la 15 | *.lo 16 | 17 | # Shared objects (inc. Windows DLLs) 18 | *.dll 19 | *.so 20 | *.so.* 21 | *.dylib 22 | 23 | # Executables 24 | *.exe 25 | *.out 26 | *.app 27 | *.i*86 28 | *.x86_64 29 | *.hex 30 | *.efi 31 | 32 | # Debug files 33 | *.dSYM/ 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, nohajc 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CC=x86_64-w64-mingw32-gcc 2 | LD=x86_64-w64-mingw32-gcc 3 | CFLAGS=-ffreestanding -O0 -Wall -Wno-unused-label -mno-ms-bitfields -g 4 | CPPFLAGS=-Ignu-efi/inc{,/x86_64,/protocol} -Ignu-efi/lib 5 | LDFLAGS=-nostdlib -Wl,-dll -shared -e efi_main -lgcc 6 | SUBSYS_APP=-Wl,--subsystem,10 7 | SUBSYS_RTDRV=-Wl,--subsystem,12 8 | ASM=nasm 9 | 10 | VM_IMG="/media/data/Virtual Machines/vmware/Windows 8 x64/Windows 8 x64.vmdk" 11 | KVM_IMG="/media/data/Virtual Machines/kvm_win8.1.vmdk" 12 | MOUNT_POINT=vm_mount 13 | EFI_PATH=$(MOUNT_POINT)/EFI/BlueGuard 14 | 15 | all: bootx64.efi hv_driver.efi 16 | 17 | bootx64.efi: blueguard.o data.o rtdata.o lib_uefi.o 18 | $(CC) $(LDFLAGS) $(SUBSYS_APP) -o $@ $^ 19 | 20 | hv_driver.efi: hv_driver.o hv_handlers.o data.o rtdata.o lib_uefi.o vmx_api.o vmx_api_c.o vmx_emu.o vm_setup.o regs.o reloc_pe.o smp.o ap_trampoline.o spinlock.o pic.o string.o realmode_emu.o 21 | $(CC) $(LDFLAGS) $(SUBSYS_RTDRV) -o $@ $^ 22 | 23 | blueguard.o: blueguard.c 24 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< 25 | 26 | lib_uefi.o: lib_uefi.c lib_uefi.h 27 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< 28 | 29 | data.o: gnu-efi/lib/data.c 30 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< 31 | 32 | rtdata.o: gnu-efi/lib/runtime/rtdata.c 33 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< 34 | 35 | hv_driver.o: hv_driver.c 36 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< 37 | 38 | hv_handlers.o: hv_handlers.c hv_handlers.h 39 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< 40 | 41 | vm_setup.o: vm_setup.c vm_setup.h 42 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< 43 | 44 | realmode_emu.o: realmode_emu.c realmode_emu.h 45 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< 46 | 47 | vmx_api_c.o: vmx_api.c vmx_api.h 48 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< 49 | 50 | vmx_api.o: vmx_api.asm vmx_api.h 51 | $(ASM) -f win64 $< -o $@ 52 | 53 | vmx_emu.o: vmx_emu.asm vmx_emu.h 54 | $(ASM) -f win64 $< -o $@ 55 | 56 | regs.o: regs.asm regs.h 57 | $(ASM) -f win64 $< -o $@ 58 | 59 | ap_trampoline.o: ap_trampoline.asm ap_trampoline.h 60 | $(ASM) -f win64 $< -o $@ 61 | 62 | spinlock.o: spinlock.asm spinlock.h 63 | $(ASM) -f win64 $< -o $@ 64 | 65 | pic.o: pic.asm pic.h 66 | $(ASM) -f win64 $< -o $@ 67 | 68 | reloc_pe.o: reloc_pe.c reloc_pe.h 69 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< 70 | 71 | smp.o: smp.c smp.h 72 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< 73 | 74 | string.o: string.c string.h 75 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< 76 | 77 | install: 78 | mkdir -p $(MOUNT_POINT) 79 | /opt/vmware/bin/vmware-mount $(VM_IMG) $(MOUNT_POINT) 80 | mkdir -p $(EFI_PATH) 81 | cp *.efi $(EFI_PATH) 82 | /opt/vmware/bin/vmware-mount -k $(VM_IMG) 83 | 84 | hw_install: 85 | mkdir -p /mnt/efi 86 | mount /dev/sda1 /mnt/efi 87 | cp bootx64.efi /mnt/efi/EFI/BlueGuard/blueguard.efi 88 | cp hv_driver.efi /mnt/efi/EFI/BlueGuard/hv_driver.efi 89 | umount /mnt/efi 90 | 91 | kvm_install: 92 | mkdir -p $(MOUNT_POINT) 93 | /opt/vmware/bin/vmware-mount $(KVM_IMG) 2 $(MOUNT_POINT) 94 | mkdir -p $(EFI_PATH) 95 | cp *.efi $(EFI_PATH) 96 | /opt/vmware/bin/vmware-mount -k $(KVM_IMG) 97 | 98 | umount: 99 | /opt/vmware/bin/vmware-mount -k $(VM_IMG) 100 | 101 | kvm_umount: 102 | /opt/vmware/bin/vmware-mount -k $(KVM_IMG) 103 | 104 | 105 | clean: 106 | -rm *.o 107 | -rm bootx64.efi 108 | -rm hv_driver.efi 109 | 110 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BlueGuard 2 | UEFI Hypervisor 3 | -------------------------------------------------------------------------------- /ap_trampoline.asm: -------------------------------------------------------------------------------- 1 | extern ap_entry64 2 | extern LAPIC_addr 3 | extern ap_stacks 4 | global init_tramp 5 | global ap_tramp32 6 | global ap_tramp64 7 | global gdt32 8 | global GDTR32 9 | global GDT32_LABEL 10 | global tramp_size 11 | global JMP_START_PTR 12 | global AP_START_LABEL 13 | global AP_GDTR 14 | global AP_IDTR 15 | global AP_CR3 16 | global AP_CR4 17 | global JMP_32_PTR 18 | global AP_32_LABEL 19 | global JMP_64_PTR 20 | global AP_64_LABEL 21 | global ACTIVE_CPU_CNT 22 | 23 | 24 | section .text 25 | 26 | USE16 27 | 28 | init_tramp: 29 | push cs 30 | pop ds ; We have data in the code segment 31 | 32 | ; Enable the A20 gate 33 | set_A20_ap: 34 | in al, 0x64 35 | test al, 0x02 36 | jnz set_A20_ap 37 | mov al, 0xD1 38 | out 0x64, al 39 | check_A20_ap: 40 | in al, 0x64 41 | test al, 0x02 42 | jnz check_A20_ap 43 | mov al, 0xDF 44 | out 0x60, al 45 | 46 | call ip0 47 | ip0: 48 | pop bx ; Get IP 49 | mov bp,[bx+ACTIVE_CPU_CNT-ip0] ; save CPU number 50 | lock inc dword [bx+ACTIVE_CPU_CNT-ip0] ; Increase active CPU counter 51 | db 0xEA ; jmp 0:start 52 | JMP_START_PTR: 53 | dw 0 ; offset 54 | dw 0 ; segment 55 | start: 56 | call ip1 57 | ip1: 58 | pop bx 59 | push cs 60 | pop ds 61 | lgdt [bx+GDTR32-ip1] 62 | mov eax,cr0 63 | or al,1 64 | mov cr0,eax 65 | db 0x66 ; jmp dword 8:ap_tramp32 66 | db 0xEA 67 | JMP_32_PTR: 68 | dd 0 69 | dw 8 70 | 71 | ;align 16 72 | 73 | USE32 74 | 75 | ap_tramp32: 76 | mov eax,16 77 | mov ds,ax 78 | mov es,ax 79 | mov fs,ax 80 | mov gs,ax 81 | mov ss,ax 82 | ;mov eax,100000b ; Set the PAE bit 83 | ;mov cr4,eax 84 | mov esi,[bx+AP_CR4-ip1] ; Set PAE bit etc. according to the BSP's CR4 85 | mov cr4,esi 86 | mov esi,[bx+AP_CR3-ip1] ; Is PML4T really bellow 4 GB? 87 | mov cr3,esi 88 | mov ecx,0xC0000080 ; Read from the EFER MSR 89 | rdmsr 90 | or eax,0x00000100 ; Set the LME bit 91 | wrmsr 92 | mov eax,cr0 93 | or eax,0x80000000 ; Enable paging 94 | mov cr0,eax 95 | lgdt [bx+AP_GDTR-ip1] 96 | lidt [bx+AP_IDTR-ip1] 97 | db 0xEA ; Jump to 64bit segment (ap_tramp64) 98 | JMP_64_PTR: 99 | dd 0 ; WE ASSUME THAT THE EFI IMAGE IS LOADED SOMEWHERE BELOW 4 GB 100 | dw 0 ; TODO: MAKE SURE IT IS BELOW 4 GB BY RELOCATING THE CODE IF NECESSARY! 101 | 102 | ;align 16 103 | 104 | USE64 105 | 106 | ap_tramp64: 107 | xor rax,rax 108 | mov ds,ax 109 | mov es,ax 110 | mov ss,ax 111 | mov fs,ax 112 | mov gs,ax 113 | ; ENABLE LAPIC 114 | mov rdi,[LAPIC_addr] 115 | mov [rdi+0xF0],dword 0x1FF 116 | ; SETUP STACK 117 | mov ebx,ebp ; get CPU number (n-th activated) 118 | and ebx,0xFF 119 | mov rcx,rbx 120 | shl rbx,12 121 | add rbx,[ap_stacks] 122 | mov rsp,rbx ; set stack location 123 | sti ; Enable interrupts 124 | call ap_entry64 125 | sleep: 126 | hlt 127 | jmp sleep 128 | 129 | 130 | ; Taken from the Pure64 bootloader by ReturnInfinity 131 | 132 | GDTR32: ; Global Descriptors Table Register 133 | dw gdt32_end - gdt32 - 1 ; limit of GDT (size minus one) 134 | dq gdt32 ; linear address of GDT 135 | 136 | align 16 137 | gdt32: 138 | dw 0x0000, 0x0000, 0x0000, 0x0000 ; Null desciptor 139 | dw 0xFFFF, 0x0000 140 | db 0x00, 0x9A, 0xCF, 0x00 ; 32-bit code descriptor 141 | dw 0xFFFF, 0x0000 142 | db 0x00, 0x92, 0xCF, 0x00 ; 32-bit data descriptor 143 | gdt32_end: 144 | 145 | 146 | GDT32_LABEL: 147 | dq gdt32 148 | 149 | AP_32_LABEL: 150 | dq ap_tramp32 151 | 152 | AP_64_LABEL: 153 | dq ap_tramp64 154 | 155 | AP_START_LABEL: 156 | dq start 157 | 158 | align 16 159 | AP_GDTR: 160 | dw 0 161 | dq 0 162 | 163 | AP_IDTR: 164 | dw 0 165 | dq 0 166 | 167 | AP_CR3: 168 | dd 0 169 | 170 | AP_CR4: 171 | dd 0 172 | 173 | ACTIVE_CPU_CNT: 174 | dd 0 175 | 176 | tramp_size: 177 | dd $ - $$ 178 | -------------------------------------------------------------------------------- /ap_trampoline.h: -------------------------------------------------------------------------------- 1 | #ifndef _AP_TRAMPOLINE_ 2 | #define _AP_TRAMPOLINE_ 3 | 4 | #include 5 | #include "smp.h" 6 | 7 | void init_tramp(void); 8 | extern uint32_t tramp_size; 9 | 10 | extern struct{ 11 | uint16_t addr; 12 | uint16_t seg; 13 | } __attribute__((packed)) JMP_START_PTR; 14 | 15 | extern struct{ 16 | uint32_t addr; 17 | uint16_t seg; 18 | } __attribute__((packed)) JMP_32_PTR; 19 | 20 | extern struct{ 21 | uint32_t addr; 22 | uint16_t seg; 23 | } __attribute__((packed)) JMP_64_PTR; 24 | 25 | extern uint64_t AP_32_LABEL; 26 | 27 | extern uint64_t AP_64_LABEL; 28 | 29 | extern uint64_t AP_START_LABEL; 30 | 31 | extern struct{ 32 | uint16_t limit; 33 | uint64_t base; 34 | } __attribute__((packed)) GDTR32; 35 | 36 | extern uint64_t GDT32_LABEL; 37 | 38 | extern struct{ 39 | uint16_t limit; 40 | uint64_t base; 41 | } __attribute__((packed)) AP_GDTR; 42 | 43 | extern struct{ 44 | uint16_t limit; 45 | uint64_t base; 46 | } __attribute__((packed)) AP_IDTR; 47 | 48 | extern uint32_t AP_CR3; 49 | extern uint32_t AP_CR4; 50 | 51 | extern uint32_t ACTIVE_CPU_CNT; 52 | 53 | //extern uint64_t AP_STACK; 54 | 55 | void ap_tramp32(void); 56 | void ap_tramp64(void); 57 | 58 | #endif -------------------------------------------------------------------------------- /blueguard.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "lib_uefi.h" 7 | 8 | 9 | EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE * sys_table) 10 | { 11 | EFI_STATUS err; 12 | EFI_LOADED_IMAGE * loaded_image; 13 | EFI_FILE_HANDLE root_dir; 14 | /*EFI_FILE_HANDLE win_bootmgr; 15 | EFI_FILE_HANDLE hv_driver;*/ 16 | //CHAR16 *loaded_image_path; 17 | EFI_DEVICE_PATH * win_bootmgr_path; 18 | EFI_DEVICE_PATH * hv_driver_path; 19 | EFI_HANDLE win_bootmgr_image; 20 | EFI_HANDLE hv_driver_image; 21 | 22 | init(image, sys_table); 23 | 24 | /* Store the system table for future use in other functions */ 25 | 26 | /* Say hi */ 27 | err = ST->ConOut->OutputString(ST->ConOut, L"Starting BlueGuard.\r\n"); 28 | if (EFI_ERROR(err)) 29 | return err; 30 | 31 | 32 | err = BS->OpenProtocol(image, &LoadedImageProtocol, (VOID **)&loaded_image, 33 | image, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL); 34 | if (EFI_ERROR(err)) { 35 | print(L"Error getting a LoadedImageProtocol handle.\r\n"); 36 | BS->Stall(3 * 1000 * 1000); 37 | return err; 38 | } 39 | 40 | root_dir = LibOpenRoot(loaded_image->DeviceHandle); 41 | if (!root_dir) { 42 | print(L"Unable to open root directory.\r\n"); 43 | BS->Stall(3 * 1000 * 1000); 44 | return EFI_LOAD_ERROR; 45 | } 46 | 47 | /*err = root_dir->Open(root_dir, &win_bootmgr, L"\\EFI\\Microsoft\\Boot\\bootmgfw.efi", EFI_FILE_MODE_READ, 0ULL); 48 | if (EFI_ERROR(err)){ 49 | print(L"Unable to locate Windows boot manager.\r\n"); 50 | return EFI_LOAD_ERROR; 51 | } 52 | win_bootmgr->Close(win_bootmgr);*/ 53 | 54 | hv_driver_path = FileDevicePath(loaded_image->DeviceHandle, L"\\EFI\\BlueGuard\\hv_driver.efi"); 55 | if (!hv_driver_path) { 56 | print(L"Error getting hv_driver device path.\r\n"); 57 | BS->Stall(3 * 1000 * 1000); 58 | return EFI_INVALID_PARAMETER; 59 | } 60 | 61 | err = BS->LoadImage(FALSE, image, hv_driver_path, NULL, 0, &hv_driver_image); 62 | if (EFI_ERROR(err)) { 63 | print(L"Error loading hv_driver image.\r\n"); 64 | BS->Stall(3 * 1000 * 1000); 65 | return err; 66 | } 67 | 68 | err = BS->StartImage(hv_driver_image, NULL, NULL); 69 | if(err == EFI_SUCCESS){ 70 | print(L"hv_driver initialized successfully.\r\n"); 71 | } 72 | else{ 73 | print(L"Initialization of hv_driver failed.\r\n"); 74 | } 75 | 76 | win_bootmgr_path = FileDevicePath(loaded_image->DeviceHandle, L"\\EFI\\Microsoft\\Boot\\bootmgfw.efi"); 77 | if (!win_bootmgr_path) { 78 | print(L"Error getting bootmgfw device path.\r\n"); 79 | BS->Stall(3 * 1000 * 1000); 80 | return EFI_INVALID_PARAMETER; 81 | } 82 | 83 | err = BS->LoadImage(FALSE, image, win_bootmgr_path, NULL, 0, &win_bootmgr_image); 84 | if (EFI_ERROR(err)) { 85 | print(L"Error loading bootmgfw image.\r\n"); 86 | BS->Stall(3 * 1000 * 1000); 87 | return err; 88 | } 89 | 90 | print(L"Press any key to continue...\r\n"); 91 | wait_for_key(); 92 | 93 | print(L"Starting Windows now.\r\n"); 94 | //BS->Stall(5 * 1000 * 1000); 95 | 96 | err = BS->StartImage(win_bootmgr_image, NULL, NULL); 97 | 98 | FreePool(win_bootmgr_path); 99 | root_dir->Close(root_dir); 100 | 101 | return err; 102 | } 103 | -------------------------------------------------------------------------------- /gnu-efi/.gitignore: -------------------------------------------------------------------------------- 1 | *.efi 2 | *.o 3 | *.a 4 | *.tar.* 5 | *.tar 6 | -------------------------------------------------------------------------------- /gnu-efi/Make.rules: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 1999-2007 Hewlett-Packard Co. 3 | # Contributed by David Mosberger 4 | # Contributed by Stephane Eranian 5 | # 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # * Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # * Redistributions in binary form must reproduce the above 15 | # copyright notice, this list of conditions and the following 16 | # disclaimer in the documentation and/or other materials 17 | # provided with the distribution. 18 | # * Neither the name of Hewlett-Packard Co. nor the names of its 19 | # contributors may be used to endorse or promote products derived 20 | # from this software without specific prior written permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 24 | # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 27 | # BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 28 | # OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 32 | # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 33 | # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 | # SUCH DAMAGE. 35 | # 36 | 37 | %.efi: %.so 38 | $(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel \ 39 | -j .rela -j .rel.* -j .rela.* -j .rel* -j .rela* \ 40 | -j .reloc $(FORMAT) $*.so $@ 41 | 42 | %.so: %.o 43 | $(LD) $(LDFLAGS) $^ -o $@ $(LOADLIBES) 44 | 45 | %.o: %.c 46 | $(CC) $(INCDIR) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ 47 | 48 | %.S: %.c 49 | $(CC) $(INCDIR) $(CFLAGS) $(CPPFLAGS) -S $< -o $@ 50 | 51 | %.E: %.c 52 | $(CC) $(INCDIR) $(CFLAGS) $(CPPFLAGS) -E $< -o $@ 53 | -------------------------------------------------------------------------------- /gnu-efi/README.efilib: -------------------------------------------------------------------------------- 1 | 2 | The files in the "lib" and "inc" subdirectories are using the EFI Application 3 | Toolkit distributed by Intel at http://developer.intel.com/technology/efi 4 | 5 | This code is covered by the following agreement: 6 | 7 | Copyright (c) 1998-2000 Intel Corporation 8 | 9 | Redistribution and use in source and binary forms, with or without modification, are permitted 10 | provided that the following conditions are met: 11 | 12 | Redistributions of source code must retain the above copyright notice, this list of conditions and 13 | the following disclaimer. 14 | 15 | Redistributions in binary form must reproduce the above copyright notice, this list of conditions 16 | and the following disclaimer in the documentation and/or other materials provided with the 17 | distribution. 18 | 19 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 21 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL BE 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | POSSIBILITY OF SUCH DAMAGE. THE EFI SPECIFICATION AND ALL OTHER INFORMATION 29 | ON THIS WEB SITE ARE PROVIDED "AS IS" WITH NO WARRANTIES, AND ARE SUBJECT 30 | TO CHANGE WITHOUT NOTICE. 31 | -------------------------------------------------------------------------------- /gnu-efi/README.elilo: -------------------------------------------------------------------------------- 1 | 2 | IMPORTANT information related to the gnu-efi package 3 | ---------------------------------------------------- 4 | June 2001 5 | 6 | As of version 3.0, the gnu-efi package is now split in two different packages: 7 | 8 | -> gnu-efi-X.y: contains the EFI library, include files and crt0. 9 | 10 | -> elilo-X.y : contains the ELILO bootloader. 11 | 12 | Note that X.y don't need to match for both packages. However elilo-3.x 13 | requires at least gnu-efi-3.0. EFI support for x86_64 is provided in 14 | gnu-efi-3.0d. 15 | 16 | Both packages can be downloaded from: 17 | 18 | http://www.sf.net/projects/gnu-efi 19 | http://www.sf.net/projects/elilo 20 | -------------------------------------------------------------------------------- /gnu-efi/README.git: -------------------------------------------------------------------------------- 1 | README.git 2 | 3 | Generating releases from git a very simple process; 4 | 5 | 1) Edit the file "Makefile". Changing the "VERSION" line to the new version. 6 | 2) Do a "git commit" just for the version number change. 7 | 3) Then do a "make test-archive". 8 | That will make a file in the current directory gnu-efi-$VERSION.tar.bz2 , 9 | with its top level directory gnu-efi-$VERSION/ and the source tree under that. 10 | 11 | Once you've tested that and you're sure it's what you want to release, 12 | 4) Do "make archive", which will tag a release in git and generate a 13 | final tarball from it. 14 | 15 | You then push to the archive, being sure to include the tag: 16 | 5) "git push origin master:master --tags" 17 | 18 | And upload the archive wherever it's supposed to go. 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /gnu-efi/apps/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 1999-2001 Hewlett-Packard Co. 3 | # Contributed by David Mosberger 4 | # Contributed by Stephane Eranian 5 | # 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # * Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # * Redistributions in binary form must reproduce the above 15 | # copyright notice, this list of conditions and the following 16 | # disclaimer in the documentation and/or other materials 17 | # provided with the distribution. 18 | # * Neither the name of Hewlett-Packard Co. nor the names of its 19 | # contributors may be used to endorse or promote products derived 20 | # from this software without specific prior written permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 24 | # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 27 | # BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 28 | # OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 32 | # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 33 | # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 | # SUCH DAMAGE. 35 | # 36 | 37 | SRCDIR = . 38 | 39 | VPATH = $(SRCDIR) 40 | 41 | include $(SRCDIR)/../Make.defaults 42 | 43 | TOPDIR = $(SRCDIR)/.. 44 | 45 | CDIR=$(TOPDIR)/.. 46 | LINUX_HEADERS = /usr/src/sys/build 47 | CPPFLAGS += -D__KERNEL__ -I$(LINUX_HEADERS)/include 48 | CRTOBJS = ../gnuefi/crt0-efi-$(ARCH).o 49 | 50 | LDSCRIPT = $(TOPDIR)/gnuefi/elf_$(ARCH)_efi.lds 51 | ifneq (,$(findstring FreeBSD,$(OS))) 52 | LDSCRIPT = $(TOPDIR)/gnuefi/elf_$(ARCH)_fbsd_efi.lds 53 | endif 54 | 55 | LDFLAGS += -shared -Bsymbolic -L../lib -L../gnuefi $(CRTOBJS) 56 | 57 | LOADLIBES += -lefi -lgnuefi 58 | LOADLIBES += $(LIBGCC) 59 | LOADLIBES += -T $(LDSCRIPT) 60 | 61 | TARGET_APPS = t.efi t2.efi t3.efi t4.efi t5.efi t6.efi \ 62 | printenv.efi t7.efi t8.efi tcc.efi modelist.efi \ 63 | route80h.efi drv0_use.efi AllocPages.efi \ 64 | FreePages.efi 65 | TARGET_BSDRIVERS = drv0.efi 66 | TARGET_RTDRIVERS = 67 | 68 | ifneq ($(HAVE_EFI_OBJCOPY),) 69 | 70 | FORMAT := --target efi-app-$(ARCH) 71 | $(TARGET_BSDRIVERS): FORMAT=--target efi-bsdrv-$(ARCH) 72 | $(TARGET_RTDRIVERS): FORMAT=--target efi-rtdrv-$(ARCH) 73 | 74 | else 75 | 76 | SUBSYSTEM := 0xa 77 | $(TARGET_BSDRIVERS): SUBSYSTEM = 0xb 78 | $(TARGET_RTDRIVERS): SUBSYSTEM = 0xc 79 | 80 | FORMAT := -O binary 81 | LDFLAGS += --defsym=EFI_SUBSYSTEM=$(SUBSYSTEM) 82 | 83 | endif 84 | 85 | TARGETS = $(TARGET_APPS) $(TARGET_BSDRIVERS) $(TARGET_RTDRIVERS) 86 | 87 | all: $(TARGETS) 88 | 89 | clean: 90 | rm -f $(TARGETS) *~ *.o *.so 91 | 92 | .PHONY: install 93 | 94 | include $(SRCDIR)/../Make.rules 95 | -------------------------------------------------------------------------------- /gnu-efi/apps/drv0.h: -------------------------------------------------------------------------------- 1 | #ifndef _GNU_EFI_APPS_DRV0_H_ 2 | #define _GNU_EFI_APPS_DRV0_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | /* UEFI naming conventions */ 9 | #define GNU_EFI_APPS_DRV0_PROTOCOL_GUID \ 10 | { 0xe4dcafd0, 0x586c, 0x4b3d, {0x86, 0xe7, 0x28, 0xde, 0x7f, 0xcc, 0x04, 0xb8} } 11 | 12 | INTERFACE_DECL(_GNU_EFI_APPS_DRV0_PROTOCOL); 13 | 14 | typedef 15 | EFI_STATUS 16 | (EFIAPI *GNU_EFI_APPS_DRV0_SAY_HELLO) ( 17 | IN struct _GNU_EFI_APPS_DRV0_PROTOCOL *This, 18 | IN const CHAR16 *HelloWho 19 | ); 20 | 21 | typedef 22 | EFI_STATUS 23 | (EFIAPI *GNU_EFI_APPS_DRV0_GET_NUMBER_OF_HELLO) ( 24 | IN struct _GNU_EFI_APPS_DRV0_PROTOCOL *This, 25 | OUT UINTN *NumberOfHello 26 | ); 27 | 28 | typedef struct _GNU_EFI_APPS_DRV0_PROTOCOL { 29 | GNU_EFI_APPS_DRV0_SAY_HELLO SayHello; 30 | GNU_EFI_APPS_DRV0_GET_NUMBER_OF_HELLO GetNumberOfHello; 31 | } GNU_EFI_APPS_DRV0_PROTOCOL; 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /gnu-efi/apps/drv0_use.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 David Decotigny 3 | * 4 | * See drv0.c for an example session. 5 | */ 6 | 7 | #include 8 | #include 9 | #include "drv0.h" 10 | 11 | 12 | static EFI_GUID GnuEfiAppsDrv0ProtocolGuid 13 | = GNU_EFI_APPS_DRV0_PROTOCOL_GUID; 14 | 15 | 16 | static 17 | EFI_STATUS 18 | PlayWithGnuEfiAppsDrv0Protocol(IN EFI_HANDLE DrvHandle) { 19 | EFI_STATUS Status; 20 | GNU_EFI_APPS_DRV0_PROTOCOL *drv = NULL; 21 | UINTN NumberOfHello = 0; 22 | 23 | Status = uefi_call_wrapper(BS->OpenProtocol, 6, 24 | DrvHandle, 25 | &GnuEfiAppsDrv0ProtocolGuid, 26 | &drv, 27 | DrvHandle, 28 | NULL, 29 | EFI_OPEN_PROTOCOL_GET_PROTOCOL); 30 | if (EFI_ERROR(Status)) { 31 | Print(L"Cannot open proto: %d\n", Status); 32 | return Status; 33 | } 34 | 35 | Status = uefi_call_wrapper(drv->SayHello, 2, drv, L"Sample UEFI Driver"); 36 | if (EFI_ERROR(Status)) { 37 | Print(L"Cannot call SayHello: %d\n", Status); 38 | } 39 | 40 | Status = uefi_call_wrapper(drv->GetNumberOfHello, 2, drv, &NumberOfHello); 41 | if (EFI_ERROR(Status)) { 42 | Print(L"Cannot call GetNumberOfHello: %d\n", Status); 43 | } else { 44 | Print(L"Hello was called %d time(s).\n", NumberOfHello); 45 | } 46 | 47 | return EFI_SUCCESS; 48 | } 49 | 50 | 51 | EFI_STATUS 52 | efi_main (EFI_HANDLE Image, EFI_SYSTEM_TABLE *SysTab) 53 | { 54 | EFI_STATUS Status; 55 | EFI_HANDLE *Handles = NULL; 56 | UINTN i, NoHandles = 0; 57 | 58 | InitializeLib(Image, SysTab); 59 | 60 | Status = LibLocateHandle(ByProtocol, &GnuEfiAppsDrv0ProtocolGuid, 61 | NULL, &NoHandles, &Handles); 62 | if (EFI_ERROR(Status)) { 63 | Print(L"Error looking up handles for proto: %d\n", Status); 64 | return Status; 65 | } 66 | 67 | for (i = 0 ; i < NoHandles ; ++i) 68 | { 69 | Print(L"Playing with driver instance %d...\n", i); 70 | Status = PlayWithGnuEfiAppsDrv0Protocol(Handles[i]); 71 | if (EFI_ERROR(Status)) 72 | Print(L"Error playing with instance %d, skipping\n", i); 73 | } 74 | 75 | if (Handles) 76 | FreePool(Handles); 77 | 78 | return EFI_SUCCESS; 79 | } 80 | -------------------------------------------------------------------------------- /gnu-efi/apps/modelist.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | extern EFI_GUID GraphicsOutputProtocol; 5 | 6 | static int memcmp(const void *s1, const void *s2, UINTN n) 7 | { 8 | const unsigned char *c1 = s1, *c2 = s2; 9 | int d = 0; 10 | 11 | if (!s1 && !s2) 12 | return 0; 13 | if (s1 && !s2) 14 | return 1; 15 | if (!s1 && s2) 16 | return -1; 17 | 18 | while (n--) { 19 | d = (int)*c1++ - (int)*c2++; 20 | if (d) 21 | break; 22 | } 23 | return d; 24 | } 25 | 26 | static void 27 | print_modes(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop) 28 | { 29 | int i, imax; 30 | EFI_STATUS rc; 31 | 32 | imax = gop->Mode->MaxMode; 33 | 34 | Print(L"GOP reports MaxMode %d\n", imax); 35 | for (i = 0; i < imax; i++) { 36 | EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info; 37 | UINTN SizeOfInfo; 38 | rc = uefi_call_wrapper(gop->QueryMode, 4, gop, i, &SizeOfInfo, 39 | &info); 40 | if (EFI_ERROR(rc) && rc == EFI_NOT_STARTED) { 41 | rc = uefi_call_wrapper(gop->SetMode, 2, gop, 42 | gop->Mode->Mode); 43 | rc = uefi_call_wrapper(gop->QueryMode, 4, gop, i, 44 | &SizeOfInfo, &info); 45 | } 46 | 47 | if (EFI_ERROR(rc)) { 48 | CHAR16 Buffer[64]; 49 | StatusToString(Buffer, rc); 50 | Print(L"%d: Bad response from QueryMode: %s (%d)\n", 51 | i, Buffer, rc); 52 | continue; 53 | } 54 | Print(L"%c%d: %dx%d ", memcmp(info,gop->Mode->Info,sizeof(*info)) == 0 ? '*' : ' ', i, 55 | info->HorizontalResolution, 56 | info->VerticalResolution); 57 | switch(info->PixelFormat) { 58 | case PixelRedGreenBlueReserved8BitPerColor: 59 | Print(L"RGBR"); 60 | break; 61 | case PixelBlueGreenRedReserved8BitPerColor: 62 | Print(L"BGRR"); 63 | break; 64 | case PixelBitMask: 65 | Print(L"R:%08x G:%08x B:%08x X:%08x", 66 | info->PixelInformation.RedMask, 67 | info->PixelInformation.GreenMask, 68 | info->PixelInformation.BlueMask, 69 | info->PixelInformation.ReservedMask); 70 | break; 71 | case PixelBltOnly: 72 | Print(L"(blt only)"); 73 | break; 74 | default: 75 | Print(L"(Invalid pixel format)"); 76 | break; 77 | } 78 | Print(L" pitch %d\n", info->PixelsPerScanLine); 79 | } 80 | } 81 | 82 | static EFI_STATUS 83 | SetWatchdog(UINTN seconds) 84 | { 85 | EFI_STATUS rc; 86 | rc = uefi_call_wrapper(BS->SetWatchdogTimer, 4, seconds, 0x1ffff, 87 | 0, NULL); 88 | if (EFI_ERROR(rc)) { 89 | CHAR16 Buffer[64]; 90 | StatusToString(Buffer, rc); 91 | Print(L"Bad response from QueryMode: %s (%d)\n", Buffer, rc); 92 | } 93 | return rc; 94 | } 95 | 96 | EFI_STATUS 97 | efi_main (EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *systab) 98 | { 99 | EFI_STATUS rc; 100 | EFI_GRAPHICS_OUTPUT_PROTOCOL *gop; 101 | 102 | InitializeLib(image_handle, systab); 103 | 104 | SetWatchdog(10); 105 | 106 | rc = LibLocateProtocol(&GraphicsOutputProtocol, (void **)&gop); 107 | if (EFI_ERROR(rc)) 108 | return rc; 109 | 110 | print_modes(gop); 111 | 112 | SetWatchdog(0); 113 | return EFI_SUCCESS; 114 | } 115 | -------------------------------------------------------------------------------- /gnu-efi/apps/printenv.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | EFI_STATUS 5 | efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab) 6 | { 7 | EFI_STATUS status; 8 | CHAR16 name[256], *val, fmt[20]; 9 | EFI_GUID vendor; 10 | UINTN size; 11 | 12 | InitializeLib(image, systab); 13 | 14 | name[0] = 0; 15 | vendor = NullGuid; 16 | 17 | Print(L"GUID Variable Name Value\n"); 18 | Print(L"=================================== ==================== ========\n"); 19 | 20 | StrCpy(fmt, L"%.-35g %.-20s %s\n"); 21 | while (1) { 22 | size = sizeof(name); 23 | status = uefi_call_wrapper(RT->GetNextVariableName, 3, &size, name, &vendor); 24 | if (status != EFI_SUCCESS) 25 | break; 26 | 27 | val = LibGetVariable(name, &vendor); 28 | Print(fmt, &vendor, name, val); 29 | FreePool(val); 30 | } 31 | return EFI_SUCCESS; 32 | } 33 | -------------------------------------------------------------------------------- /gnu-efi/apps/route80h.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* this example program changes the Reserved Page Route (RPR) bit on ICH10's General 5 | * Control And Status Register (GCS) from LPC to PCI. In practical terms, it routes 6 | * outb to port 80h to the PCI bus. */ 7 | 8 | #define GCS_OFFSET_ADDR 0x3410 9 | #define GCS_RPR_SHIFT 2 10 | #define GCS_RPR_PCI 1 11 | #define GCS_RPR_LPC 0 12 | 13 | #define VENDOR_ID_INTEL 0x8086 14 | #define DEVICE_ID_LPCIF 0x3a16 15 | #define DEVICE_ID_COUGARPOINT_LPCIF 0x1c56 16 | 17 | static EFI_HANDLE ImageHandle; 18 | 19 | typedef struct { 20 | uint16_t vendor_id; /* 00-01 */ 21 | uint16_t device_id; /* 02-03 */ 22 | char pad[0xEB]; /* 04-EF */ 23 | uint32_t rcba; /* F0-F3 */ 24 | uint32_t reserved[3]; /* F4-FF */ 25 | } lpcif_t; 26 | 27 | static inline void set_bit(volatile uint32_t *flag, int bit, int value) 28 | { 29 | uint32_t val = *flag; 30 | Print(L"current value is 0x%2x\n", val); 31 | 32 | if (value) { 33 | val |= (1 << bit); 34 | } else { 35 | val &= ~(1 << bit); 36 | } 37 | Print(L"setting value to 0x%2x\n", val); 38 | *flag = val; 39 | val = *flag; 40 | Print(L"new value is 0x%2x\n", val); 41 | } 42 | 43 | static inline int configspace_matches_ids(void *config, uint32_t vendor_id, 44 | uint32_t device_id) 45 | { 46 | uint32_t *cfg = config; 47 | if (cfg[0] == vendor_id && cfg[1] == device_id) 48 | return 1; 49 | return 0; 50 | } 51 | 52 | static int is_device(EFI_PCI_IO *pciio, uint16_t vendor_id, uint16_t device_id) 53 | { 54 | lpcif_t lpcif; 55 | EFI_STATUS rc; 56 | 57 | rc = uefi_call_wrapper(pciio->Pci.Read, 5, pciio, EfiPciIoWidthUint16, 0, 2, &lpcif); 58 | if (EFI_ERROR(rc)) 59 | return 0; 60 | 61 | if (vendor_id == lpcif.vendor_id && device_id == lpcif.device_id) 62 | return 1; 63 | return 0; 64 | } 65 | 66 | static EFI_STATUS find_pci_device(uint16_t vendor_id, uint16_t device_id, 67 | EFI_PCI_IO **pciio) 68 | { 69 | EFI_STATUS rc; 70 | EFI_HANDLE *Handles; 71 | UINTN NoHandles; 72 | int i; 73 | 74 | if (!pciio) 75 | return EFI_INVALID_PARAMETER; 76 | 77 | rc = LibLocateHandle(ByProtocol, &PciIoProtocol, NULL, &NoHandles, 78 | &Handles); 79 | if (EFI_ERROR(rc)) 80 | return rc; 81 | 82 | for (i = 0; i < NoHandles; i++) { 83 | void *pciio_tmp = NULL; 84 | rc = uefi_call_wrapper(BS->OpenProtocol, 6, Handles[i], 85 | &PciIoProtocol, &pciio_tmp, ImageHandle, 86 | NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL); 87 | if (EFI_ERROR(rc)) 88 | continue; 89 | *pciio = pciio_tmp; 90 | if (!is_device(*pciio, vendor_id, device_id)) { 91 | *pciio = NULL; 92 | continue; 93 | } 94 | 95 | return EFI_SUCCESS; 96 | } 97 | return EFI_NOT_FOUND; 98 | } 99 | 100 | EFI_STATUS 101 | efi_main (EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *systab) 102 | { 103 | InitializeLib(image_handle, systab); 104 | EFI_PCI_IO *pciio = NULL; 105 | lpcif_t lpcif; 106 | EFI_STATUS rc; 107 | struct { 108 | uint16_t vendor; 109 | uint16_t device; 110 | } devices[] = { 111 | { VENDOR_ID_INTEL, DEVICE_ID_LPCIF }, 112 | { VENDOR_ID_INTEL, DEVICE_ID_COUGARPOINT_LPCIF }, 113 | { 0, 0 } 114 | }; 115 | int i; 116 | 117 | ImageHandle = image_handle; 118 | for (i = 0; devices[i].vendor != 0; i++) { 119 | rc = find_pci_device(devices[i].vendor, devices[i].device, &pciio); 120 | if (EFI_ERROR(rc)) 121 | continue; 122 | } 123 | 124 | if (rc == EFI_NOT_FOUND) { 125 | Print(L"Device not found.\n"); 126 | return rc; 127 | } else if (EFI_ERROR(rc)) { 128 | return rc; 129 | } 130 | 131 | rc = uefi_call_wrapper(pciio->Pci.Read, 5, pciio, EfiPciIoWidthUint32, 132 | EFI_FIELD_OFFSET(lpcif_t, rcba), 1, &lpcif.rcba); 133 | if (EFI_ERROR(rc)) 134 | return rc; 135 | if (!(lpcif.rcba & 1)) { 136 | Print(L"rcrb is not mapped, cannot route port 80h\n"); 137 | return EFI_UNSUPPORTED; 138 | } 139 | lpcif.rcba &= ~1UL; 140 | 141 | Print(L"rcba: 0x%8x\n", lpcif.rcba, lpcif.rcba); 142 | set_bit((uint32_t *)(uint64_t)(lpcif.rcba + GCS_OFFSET_ADDR), 143 | GCS_RPR_SHIFT, GCS_RPR_PCI); 144 | 145 | return EFI_SUCCESS; 146 | } 147 | -------------------------------------------------------------------------------- /gnu-efi/apps/t.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static CHAR16 * 5 | a2u (char *str) 6 | { 7 | static CHAR16 mem[2048]; 8 | int i; 9 | 10 | for (i = 0; str[i]; ++i) 11 | mem[i] = (CHAR16) str[i]; 12 | mem[i] = 0; 13 | return mem; 14 | } 15 | 16 | EFI_STATUS 17 | efi_main (EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *systab) 18 | { 19 | SIMPLE_TEXT_OUTPUT_INTERFACE *conout; 20 | 21 | InitializeLib(image_handle, systab); 22 | conout = systab->ConOut; 23 | uefi_call_wrapper(conout->OutputString, 2, conout, (CHAR16 *)L"Hello World!\n\r"); 24 | uefi_call_wrapper(conout->OutputString, 2, conout, a2u("Hello World!\n\r")); 25 | 26 | return EFI_SUCCESS; 27 | } 28 | -------------------------------------------------------------------------------- /gnu-efi/apps/t2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | EFI_STATUS 5 | efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab) 6 | { 7 | SIMPLE_TEXT_OUTPUT_INTERFACE *conout; 8 | 9 | conout = systab->ConOut; 10 | uefi_call_wrapper(conout->OutputString, 2, conout, L"Hello World!\n\r"); 11 | 12 | return EFI_SUCCESS; 13 | } 14 | -------------------------------------------------------------------------------- /gnu-efi/apps/t3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | EFI_STATUS 5 | efi_main( 6 | EFI_HANDLE image_handle, 7 | EFI_SYSTEM_TABLE *systab 8 | ) 9 | { 10 | EFI_GUID loaded_image_protocol = LOADED_IMAGE_PROTOCOL; 11 | EFI_STATUS efi_status; 12 | EFI_LOADED_IMAGE *li; 13 | UINTN pat = PoolAllocationType; 14 | VOID *void_li_p; 15 | 16 | InitializeLib(image_handle, systab); 17 | PoolAllocationType = 2; /* klooj */ 18 | 19 | Print(L"Hello World! (0xd=0x%x, 13=%d)\n", 13, 13); 20 | 21 | Print(L"before InitializeLib(): PoolAllocationType=%d\n", 22 | pat); 23 | 24 | Print(L" after InitializeLib(): PoolAllocationType=%d\n", 25 | PoolAllocationType); 26 | 27 | /* 28 | * Locate loaded_image_handle instance. 29 | */ 30 | 31 | Print(L"BS->HandleProtocol() "); 32 | 33 | efi_status = uefi_call_wrapper( 34 | BS->HandleProtocol, 35 | 3, 36 | image_handle, 37 | &loaded_image_protocol, 38 | &void_li_p); 39 | li = void_li_p; 40 | 41 | Print(L"%xh (%r)\n", efi_status, efi_status); 42 | 43 | if (efi_status != EFI_SUCCESS) { 44 | return efi_status; 45 | } 46 | 47 | Print(L" li: %xh\n", li); 48 | 49 | if (!li) { 50 | return EFI_UNSUPPORTED; 51 | } 52 | 53 | Print(L" li->Revision: %xh\n", li->Revision); 54 | Print(L" li->ParentHandle: %xh\n", li->ParentHandle); 55 | Print(L" li->SystemTable: %xh\n", li->SystemTable); 56 | Print(L" li->DeviceHandle: %xh\n", li->DeviceHandle); 57 | Print(L" li->FilePath: %xh\n", li->FilePath); 58 | Print(L" li->Reserved: %xh\n", li->Reserved); 59 | Print(L" li->LoadOptionsSize: %xh\n", li->LoadOptionsSize); 60 | Print(L" li->LoadOptions: %xh\n", li->LoadOptions); 61 | Print(L" li->ImageBase: %xh\n", li->ImageBase); 62 | Print(L" li->ImageSize: %xh\n", li->ImageSize); 63 | Print(L" li->ImageCodeType: %xh\n", li->ImageCodeType); 64 | Print(L" li->ImageDataType: %xh\n", li->ImageDataType); 65 | Print(L" li->Unload: %xh\n", li->Unload); 66 | 67 | #if 0 68 | typedef struct { 69 | UINT32 Revision; 70 | EFI_HANDLE ParentHandle; 71 | struct _EFI_SYSTEM_TABLE *SystemTable; 72 | 73 | // Source location of image 74 | EFI_HANDLE DeviceHandle; 75 | EFI_DEVICE_PATH *FilePath; 76 | VOID *Reserved; 77 | 78 | // Images load options 79 | UINT32 LoadOptionsSize; 80 | VOID *LoadOptions; 81 | 82 | // Location of where image was loaded 83 | VOID *ImageBase; 84 | UINT64 ImageSize; 85 | EFI_MEMORY_TYPE ImageCodeType; 86 | EFI_MEMORY_TYPE ImageDataType; 87 | 88 | // If the driver image supports a dynamic unload request 89 | EFI_IMAGE_UNLOAD Unload; 90 | 91 | } EFI_LOADED_IMAGE; 92 | #endif 93 | 94 | return EFI_SUCCESS; 95 | } 96 | -------------------------------------------------------------------------------- /gnu-efi/apps/t4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | EFI_STATUS 5 | efi_main (EFI_HANDLE *image, EFI_SYSTEM_TABLE *systab) 6 | { 7 | UINTN index; 8 | 9 | uefi_call_wrapper(systab->ConOut->OutputString, 2, systab->ConOut, L"Hello application started\r\n"); 10 | uefi_call_wrapper(systab->ConOut->OutputString, 2, systab->ConOut, L"\r\n\r\n\r\nHit any key to exit\r\n"); 11 | uefi_call_wrapper(systab->BootServices->WaitForEvent, 3, 1, &systab->ConIn->WaitForKey, &index); 12 | return EFI_SUCCESS; 13 | } 14 | -------------------------------------------------------------------------------- /gnu-efi/apps/t5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | EFI_STATUS 5 | efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab) 6 | { 7 | InitializeLib(image, systab); 8 | Print(L"HelloLib application started\n"); 9 | Print(L"\n\n\nHit any key to exit this image\n"); 10 | WaitForSingleEvent(ST->ConIn->WaitForKey, 0); 11 | uefi_call_wrapper(ST->ConOut->OutputString, 2, ST->ConOut, L"\n\n"); 12 | return EFI_SUCCESS; 13 | } 14 | -------------------------------------------------------------------------------- /gnu-efi/apps/t6.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | typedef EFI_STATUS (*foo_t)(EFI_HANDLE, EFI_GUID *, VOID **); 5 | typedef struct { 6 | unsigned long addr; 7 | unsigned long gp; 8 | } fdesc_t; 9 | 10 | EFI_LOADED_IMAGE my_loaded; 11 | 12 | EFI_STATUS 13 | efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab) 14 | { 15 | EFI_LOADED_IMAGE *loaded_image = NULL; 16 | #if 0 17 | EFI_DEVICE_PATH *dev_path; 18 | #endif 19 | EFI_STATUS status; 20 | 21 | InitializeLib(image, systab); 22 | status = uefi_call_wrapper(systab->BootServices->HandleProtocol, 23 | 3, 24 | image, 25 | &LoadedImageProtocol, 26 | (void **) &loaded_image); 27 | if (EFI_ERROR(status)) { 28 | Print(L"handleprotocol: %r\n", status); 29 | } 30 | 31 | #if 0 32 | BS->HandleProtocol(loaded_image->DeviceHandle, &DevicePathProtocol, (void **) &dev_path); 33 | 34 | Print(L"Image device : %s\n", DevicePathToStr(dev_path)); 35 | Print(L"Image file : %s\n", DevicePathToStr(loaded_image->FilePath)); 36 | #endif 37 | Print(L"Image base : %lx\n", loaded_image->ImageBase); 38 | Print(L"Image size : %lx\n", loaded_image->ImageSize); 39 | Print(L"Load options size : %lx\n", loaded_image->LoadOptionsSize); 40 | Print(L"Load options : %s\n", loaded_image->LoadOptions); 41 | 42 | return EFI_SUCCESS; 43 | } 44 | -------------------------------------------------------------------------------- /gnu-efi/apps/t7.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | EFI_STATUS 5 | efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab) 6 | { 7 | EFI_INPUT_KEY efi_input_key; 8 | EFI_STATUS efi_status; 9 | 10 | InitializeLib(image, systab); 11 | 12 | Print(L"HelloLib application started\n"); 13 | 14 | Print(L"\n\n\nHit any key to exit this image\n"); 15 | WaitForSingleEvent(ST->ConIn->WaitForKey, 0); 16 | 17 | uefi_call_wrapper(ST->ConOut->OutputString, 2, ST->ConOut, L"\n\n"); 18 | 19 | efi_status = uefi_call_wrapper(ST->ConIn->ReadKeyStroke, 2, ST->ConIn, &efi_input_key); 20 | 21 | Print(L"ScanCode: %xh UnicodeChar: %xh\n", 22 | efi_input_key.ScanCode, efi_input_key.UnicodeChar); 23 | 24 | return EFI_SUCCESS; 25 | } 26 | -------------------------------------------------------------------------------- /gnu-efi/apps/t8.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | EFI_STATUS 5 | efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) 6 | { 7 | INTN Argc, i; 8 | CHAR16 **Argv; 9 | 10 | InitializeLib(ImageHandle, SystemTable); 11 | Argc = GetShellArgcArgv(ImageHandle, &Argv); 12 | 13 | Print(L"Hello World, started with Argc=%d\n", Argc); 14 | for (i = 0 ; i < Argc ; ++i) 15 | Print(L" Argv[%d] = '%s'\n", i, Argv[i]); 16 | 17 | Print(L"Bye.\n"); 18 | return EFI_SUCCESS; 19 | } 20 | -------------------------------------------------------------------------------- /gnu-efi/apps/tpause.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | EFI_STATUS 5 | efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab) 6 | { 7 | Print(L"Press `q' to quit, any other key to continue:\n"); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /gnu-efi/apps/trivial.S: -------------------------------------------------------------------------------- 1 | .text 2 | .align 4 3 | 4 | .globl _start 5 | _start: 6 | #if 0 7 | pushl %ebp 8 | movl %esp,%ebp 9 | pushl %ebx # save ebx 10 | movl 12(%ebp),%eax # eax <- systab 11 | movl 24(%eax),%ebx # ebx <- systab->FirmwareVendor 12 | pushl %ebx 13 | movl 44(%eax),%ebx # ebx <- systab->ConOut 14 | pushl %ebx 15 | movl 4(%ebx),%eax # eax <- conout->OutputString 16 | call *%eax 17 | movl -4(%ebp),%ebx # restore ebx 18 | leave 19 | ret 20 | 21 | #else 22 | 23 | pushl %ebp 24 | movl %esp,%ebp 25 | pushl %ebx 26 | call 0f 27 | 0: popl %eax 28 | addl $hello-0b,%eax 29 | pushl %eax 30 | movl 12(%ebp),%eax # eax <- systab 31 | movl 44(%eax),%ebx # ebx <- systab->ConOut 32 | pushl %ebx 33 | movl 4(%ebx),%eax # eax <- conout->OutputString 34 | call *%eax 35 | movl -4(%ebp),%ebx 36 | leave 37 | ret 38 | 39 | .section .rodata 40 | .align 2 41 | hello: .byte 'h',0,'e',0,'l',0,'l',0,'o',0,'\n',0,'\r',0,0,0 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /gnu-efi/gnuefi/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 1999-2001 Hewlett-Packard Co. 3 | # Contributed by David Mosberger 4 | # Contributed by Stephane Eranian 5 | # 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # * Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # * Redistributions in binary form must reproduce the above 15 | # copyright notice, this list of conditions and the following 16 | # disclaimer in the documentation and/or other materials 17 | # provided with the distribution. 18 | # * Neither the name of Hewlett-Packard Co. nor the names of its 19 | # contributors may be used to endorse or promote products derived 20 | # from this software without specific prior written permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 24 | # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 27 | # BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 28 | # OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 32 | # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 33 | # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 | # SUCH DAMAGE. 35 | # 36 | 37 | SRCDIR = . 38 | 39 | VPATH = $(SRCDIR) 40 | 41 | include $(SRCDIR)/../Make.defaults 42 | 43 | TOPDIR = $(SRCDIR)/.. 44 | 45 | CDIR=$(TOPDIR)/.. 46 | FILES = reloc_$(ARCH) 47 | 48 | OBJS = $(FILES:%=%.o) 49 | 50 | # on aarch64, avoid jump tables before all relocations have been processed 51 | reloc_aarch64.o: CFLAGS += -fno-jump-tables 52 | 53 | TARGETS = crt0-efi-$(ARCH).o libgnuefi.a 54 | 55 | all: $(TARGETS) 56 | 57 | libgnuefi.a: $(patsubst %,libgnuefi.a(%),$(OBJS)) 58 | 59 | clean: 60 | rm -f $(TARGETS) *~ *.o $(OBJS) 61 | 62 | install: 63 | mkdir -p $(INSTALLROOT)$(LIBDIR) 64 | $(INSTALL) -m 644 $(TARGETS) $(INSTALLROOT)$(LIBDIR) 65 | ifneq (,$(findstring FreeBSD,$(OS))) 66 | ifeq ($(ARCH),x86_64) 67 | $(INSTALL) -m 644 $(SRCDIR)/elf_$(ARCH)_fbsd_efi.lds $(INSTALLROOT)$(LIBDIR) 68 | else 69 | $(INSTALL) -m 644 $(SRCDIR)/elf_$(ARCH)_efi.lds $(INSTALLROOT)$(LIBDIR) 70 | endif 71 | else 72 | $(INSTALL) -m 644 $(SRCDIR)/elf_$(ARCH)_efi.lds $(INSTALLROOT)$(LIBDIR) 73 | endif 74 | 75 | include $(SRCDIR)/../Make.rules 76 | -------------------------------------------------------------------------------- /gnu-efi/gnuefi/crt0-efi-ia32.S: -------------------------------------------------------------------------------- 1 | /* crt0-efi-ia32.S - x86 EFI startup code. 2 | Copyright (C) 1999 Hewlett-Packard Co. 3 | Contributed by David Mosberger . 4 | 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above 14 | copyright notice, this list of conditions and the following 15 | disclaimer in the documentation and/or other materials 16 | provided with the distribution. 17 | * Neither the name of Hewlett-Packard Co. nor the names of its 18 | contributors may be used to endorse or promote products derived 19 | from this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 22 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 23 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 26 | BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 27 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 31 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 32 | THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 | SUCH DAMAGE. 34 | */ 35 | 36 | .text 37 | .align 4 38 | 39 | .globl _start 40 | _start: 41 | pushl %ebp 42 | movl %esp,%ebp 43 | 44 | pushl 12(%ebp) # copy "image" argument 45 | pushl 8(%ebp) # copy "systab" argument 46 | 47 | call 0f 48 | 0: popl %eax 49 | movl %eax,%ebx 50 | 51 | addl $ImageBase-0b,%eax # %eax = ldbase 52 | addl $_DYNAMIC-0b,%ebx # %ebx = _DYNAMIC 53 | 54 | pushl %ebx # pass _DYNAMIC as second argument 55 | pushl %eax # pass ldbase as first argument 56 | call _relocate 57 | popl %ebx 58 | popl %ebx 59 | testl %eax,%eax 60 | jne .exit 61 | 62 | call efi_main # call app with "image" and "systab" argument 63 | 64 | .exit: leave 65 | ret 66 | 67 | // hand-craft a dummy .reloc section so EFI knows it's a relocatable executable: 68 | 69 | .data 70 | dummy: .long 0 71 | 72 | #define IMAGE_REL_ABSOLUTE 0 73 | .section .reloc 74 | .long dummy // Page RVA 75 | .long 10 // Block Size (2*4+2) 76 | .word (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy 77 | -------------------------------------------------------------------------------- /gnu-efi/gnuefi/crt0-efi-ia64.S: -------------------------------------------------------------------------------- 1 | /* crt0-efi-ia64.S - IA-64 EFI startup code. 2 | Copyright (C) 1999 Hewlett-Packard Co. 3 | Contributed by David Mosberger . 4 | 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above 14 | copyright notice, this list of conditions and the following 15 | disclaimer in the documentation and/or other materials 16 | provided with the distribution. 17 | * Neither the name of Hewlett-Packard Co. nor the names of its 18 | contributors may be used to endorse or promote products derived 19 | from this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 22 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 23 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 26 | BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 27 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 31 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 32 | THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 | SUCH DAMAGE. 34 | */ 35 | .text 36 | .psr abi64 37 | .psr lsb 38 | .lsb 39 | 40 | .proc _start 41 | _start: 42 | alloc loc0=ar.pfs,2,2,2,0 43 | mov loc1=rp 44 | movl out0=@gprel(ImageBase) // out0 <- ImageBase (ldbase) 45 | ;; 46 | add out0=out0,gp 47 | movl out1=@gprel(_DYNAMIC) // out1 <- _DYNAMIC 48 | ;; // avoid WAW on CFM 49 | add out1=out1,gp 50 | br.call.sptk.few rp=_relocate 51 | .Lret0: 52 | cmp.ne p6,p0=r0,r8 // r8 == EFI_SUCCESS? 53 | (p6) br.cond.sptk.few .exit // no -> 54 | 55 | .Lret1: 56 | 57 | mov out0=in0 // image handle 58 | mov out1=in1 // systab 59 | br.call.sptk.few rp=efi_main 60 | .Lret2: 61 | .exit: 62 | mov ar.pfs=loc0 63 | mov rp=loc1 64 | ;; 65 | br.ret.sptk.few rp 66 | 67 | .endp _start 68 | 69 | 70 | // PE32+ wants a PLABEL, not the code address of the entry point: 71 | 72 | .align 16 73 | .global _start_plabel 74 | .section .plabel, "a" 75 | _start_plabel: 76 | data8 _start 77 | data8 __gp 78 | 79 | // hand-craft a .reloc section for the plabel: 80 | 81 | #define IMAGE_REL_BASED_DIR64 10 82 | 83 | .section .reloc, "a" 84 | data4 _start_plabel // Page RVA 85 | data4 12 // Block Size (2*4+2*2) 86 | data2 (IMAGE_REL_BASED_DIR64<<12) + 0 // reloc for plabel's entry point 87 | data2 (IMAGE_REL_BASED_DIR64<<12) + 8 // reloc for plabel's global pointer 88 | -------------------------------------------------------------------------------- /gnu-efi/gnuefi/crt0-efi-x86_64.S: -------------------------------------------------------------------------------- 1 | /* crt0-efi-x86_64.S - x86_64 EFI startup code. 2 | Copyright (C) 1999 Hewlett-Packard Co. 3 | Contributed by David Mosberger . 4 | Copyright (C) 2005 Intel Co. 5 | Contributed by Fenghua Yu . 6 | 7 | All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions 11 | are met: 12 | 13 | * Redistributions of source code must retain the above copyright 14 | notice, this list of conditions and the following disclaimer. 15 | * Redistributions in binary form must reproduce the above 16 | copyright notice, this list of conditions and the following 17 | disclaimer in the documentation and/or other materials 18 | provided with the distribution. 19 | * Neither the name of Hewlett-Packard Co. nor the names of its 20 | contributors may be used to endorse or promote products derived 21 | from this software without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 28 | BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 29 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 30 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 33 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 34 | THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 | SUCH DAMAGE. 36 | */ 37 | .text 38 | .align 4 39 | 40 | .globl _start 41 | _start: 42 | subq $8, %rsp 43 | pushq %rcx 44 | pushq %rdx 45 | 46 | 0: 47 | lea ImageBase(%rip), %rdi 48 | lea _DYNAMIC(%rip), %rsi 49 | 50 | popq %rcx 51 | popq %rdx 52 | pushq %rcx 53 | pushq %rdx 54 | call _relocate 55 | 56 | popq %rdi 57 | popq %rsi 58 | 59 | call efi_main 60 | addq $8, %rsp 61 | 62 | .exit: 63 | ret 64 | 65 | // hand-craft a dummy .reloc section so EFI knows it's a relocatable executable: 66 | 67 | .data 68 | dummy: .long 0 69 | 70 | #define IMAGE_REL_ABSOLUTE 0 71 | .section .reloc, "a" 72 | label1: 73 | .long dummy-label1 // Page RVA 74 | .long 10 // Block Size (2*4+2) 75 | .word (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy 76 | 77 | -------------------------------------------------------------------------------- /gnu-efi/gnuefi/elf_aarch64_efi.lds: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf64-littleaarch64", "elf64-littleaarch64", "elf64-littleaarch64") 2 | OUTPUT_ARCH(aarch64) 3 | ENTRY(_start) 4 | SECTIONS 5 | { 6 | .text 0x0 : { 7 | *(.text.head) 8 | *(.text) 9 | *(.text.*) 10 | *(.gnu.linkonce.t.*) 11 | *(.srodata) 12 | *(.rodata*) 13 | . = ALIGN(16); 14 | _etext = .; 15 | } 16 | .dynamic : { *(.dynamic) } 17 | .data : 18 | { 19 | *(.sdata) 20 | *(.data) 21 | *(.data1) 22 | *(.data.*) 23 | *(.got.plt) 24 | *(.got) 25 | 26 | /* the EFI loader doesn't seem to like a .bss section, so we stick 27 | it all into .data: */ 28 | . = ALIGN(16); 29 | _bss = .; 30 | *(.sbss) 31 | *(.scommon) 32 | *(.dynbss) 33 | *(.bss) 34 | *(COMMON) 35 | . = ALIGN(16); 36 | _bss_end = .; 37 | } 38 | .rela.dyn : { *(.rela.dyn) } 39 | .rela.plt : { *(.rela.plt) } 40 | .rela.got : { *(.rela.got) } 41 | .rela.data : { *(.rela.data) *(.rela.data*) } 42 | _edata = .; 43 | _data_size = . - _etext; 44 | 45 | . = ALIGN(4096); 46 | .dynsym : { *(.dynsym) } 47 | . = ALIGN(4096); 48 | .dynstr : { *(.dynstr) } 49 | . = ALIGN(4096); 50 | /DISCARD/ : 51 | { 52 | *(.rel.reloc) 53 | *(.eh_frame) 54 | *(.note.GNU-stack) 55 | } 56 | .comment 0 : { *(.comment) } 57 | } 58 | -------------------------------------------------------------------------------- /gnu-efi/gnuefi/elf_arm_efi.lds: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") 2 | OUTPUT_ARCH(arm) 3 | ENTRY(_start) 4 | SECTIONS 5 | { 6 | .text 0x0 : { 7 | *(.text.head) 8 | *(.text) 9 | *(.text.*) 10 | *(.gnu.linkonce.t.*) 11 | *(.srodata) 12 | *(.rodata*) 13 | . = ALIGN(16); 14 | _etext = .; 15 | } 16 | .dynamic : { *(.dynamic) } 17 | .data : 18 | { 19 | *(.sdata) 20 | *(.data) 21 | *(.data1) 22 | *(.data) 23 | *(.got.plt) 24 | *(.got) 25 | 26 | /* the EFI loader doesn't seem to like a .bss section, so we stick 27 | it all into .data: */ 28 | . = ALIGN(16); 29 | _bss = .; 30 | *(.sbss) 31 | *(.scommon) 32 | *(.dynbss) 33 | *(.bss) 34 | *(COMMON) 35 | . = ALIGN(16); 36 | _bss_end = .; 37 | } 38 | .rel.dyn : { *(.rel.dyn) } 39 | .rel.plt : { *(.rel.plt) } 40 | .rel.got : { *(.rel.got) } 41 | .rel.data : { *(.rel.data) *(.rel.data*) } 42 | _edata = .; 43 | _data_size = . - _etext; 44 | 45 | . = ALIGN(4096); 46 | .dynsym : { *(.dynsym) } 47 | . = ALIGN(4096); 48 | .dynstr : { *(.dynstr) } 49 | . = ALIGN(4096); 50 | /DISCARD/ : 51 | { 52 | *(.rel.reloc) 53 | *(.eh_frame) 54 | *(.note.GNU-stack) 55 | } 56 | .comment 0 : { *(.comment) } 57 | } 58 | -------------------------------------------------------------------------------- /gnu-efi/gnuefi/elf_ia32_efi.lds: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") 2 | OUTPUT_ARCH(i386) 3 | ENTRY(_start) 4 | SECTIONS 5 | { 6 | . = 0; 7 | ImageBase = .; 8 | .hash : { *(.hash) } /* this MUST come first! */ 9 | . = ALIGN(4096); 10 | .text : 11 | { 12 | *(.text) 13 | *(.text.*) 14 | *(.gnu.linkonce.t.*) 15 | } 16 | . = ALIGN(4096); 17 | .sdata : 18 | { 19 | *(.got.plt) 20 | *(.got) 21 | *(.srodata) 22 | *(.sdata) 23 | *(.sbss) 24 | *(.scommon) 25 | } 26 | . = ALIGN(4096); 27 | .data : 28 | { 29 | *(.rodata*) 30 | *(.data) 31 | *(.data1) 32 | *(.data.*) 33 | *(.sdata) 34 | *(.got.plt) 35 | *(.got) 36 | /* the EFI loader doesn't seem to like a .bss section, so we stick 37 | it all into .data: */ 38 | *(.sbss) 39 | *(.scommon) 40 | *(.dynbss) 41 | *(.bss) 42 | *(COMMON) 43 | } 44 | . = ALIGN(4096); 45 | .dynamic : { *(.dynamic) } 46 | . = ALIGN(4096); 47 | .rel : 48 | { 49 | *(.rel.data) 50 | *(.rel.data.*) 51 | *(.rel.got) 52 | *(.rel.stab) 53 | *(.data.rel.ro.local) 54 | *(.data.rel.local) 55 | *(.data.rel.ro) 56 | *(.data.rel*) 57 | } 58 | . = ALIGN(4096); 59 | .reloc : /* This is the PECOFF .reloc section! */ 60 | { 61 | *(.reloc) 62 | } 63 | . = ALIGN(4096); 64 | .dynsym : { *(.dynsym) } 65 | . = ALIGN(4096); 66 | .dynstr : { *(.dynstr) } 67 | . = ALIGN(4096); 68 | /DISCARD/ : 69 | { 70 | *(.rel.reloc) 71 | *(.eh_frame) 72 | *(.note.GNU-stack) 73 | } 74 | .comment 0 : { *(.comment) } 75 | } 76 | -------------------------------------------------------------------------------- /gnu-efi/gnuefi/elf_ia32_fbsd_efi.lds: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-i386-freebsd", "elf32-i386-freebsd", "elf32-i386-freebsd") 2 | OUTPUT_ARCH(i386) 3 | ENTRY(_start) 4 | SECTIONS 5 | { 6 | . = 0; 7 | ImageBase = .; 8 | .hash : { *(.hash) } /* this MUST come first! */ 9 | . = ALIGN(4096); 10 | .text : 11 | { 12 | *(.text) 13 | *(.text.*) 14 | *(.gnu.linkonce.t.*) 15 | } 16 | . = ALIGN(4096); 17 | .sdata : 18 | { 19 | *(.got.plt) 20 | *(.got) 21 | *(.srodata) 22 | *(.sdata) 23 | *(.sbss) 24 | *(.scommon) 25 | } 26 | . = ALIGN(4096); 27 | .data : 28 | { 29 | *(.rodata*) 30 | *(.data) 31 | *(.data1) 32 | *(.data.*) 33 | *(.sdata) 34 | *(.got.plt) 35 | *(.got) 36 | /* the EFI loader doesn't seem to like a .bss section, so we stick 37 | it all into .data: */ 38 | *(.sbss) 39 | *(.scommon) 40 | *(.dynbss) 41 | *(.bss) 42 | *(COMMON) 43 | } 44 | . = ALIGN(4096); 45 | .dynamic : { *(.dynamic) } 46 | . = ALIGN(4096); 47 | .rel : 48 | { 49 | *(.rel.data) 50 | *(.rel.data.*) 51 | *(.rel.got) 52 | *(.rel.stab) 53 | *(.data.rel.ro.local) 54 | *(.data.rel.local) 55 | *(.data.rel.ro) 56 | *(.data.rel*) 57 | } 58 | . = ALIGN(4096); 59 | .reloc : /* This is the PECOFF .reloc section! */ 60 | { 61 | *(.reloc) 62 | } 63 | . = ALIGN(4096); 64 | .dynsym : { *(.dynsym) } 65 | . = ALIGN(4096); 66 | .dynstr : { *(.dynstr) } 67 | . = ALIGN(4096); 68 | /DISCARD/ : 69 | { 70 | *(.rel.reloc) 71 | *(.eh_frame) 72 | *(.note.GNU-stack) 73 | } 74 | .comment 0 : { *(.comment) } 75 | } 76 | -------------------------------------------------------------------------------- /gnu-efi/gnuefi/elf_ia64_efi.lds: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf64-ia64-little") 2 | OUTPUT_ARCH(ia64) 3 | ENTRY(_start_plabel) 4 | SECTIONS 5 | { 6 | . = 0; 7 | ImageBase = .; 8 | .hash : { *(.hash) } /* this MUST come first! */ 9 | . = ALIGN(4096); 10 | .text : 11 | { 12 | *(.text) 13 | *(.text.*) 14 | *(.gnu.linkonce.t.*) 15 | } 16 | . = ALIGN(4096); 17 | __gp = ALIGN (8) + 0x200000; 18 | .sdata : 19 | { 20 | *(.got.plt) 21 | *(.got) 22 | *(.srodata) 23 | *(.sdata) 24 | *(.sbss) 25 | *(.scommon) 26 | } 27 | . = ALIGN(4096); 28 | .data : 29 | { 30 | *(.rodata*) 31 | *(.ctors) 32 | *(.data*) 33 | *(.gnu.linkonce.d*) 34 | *(.plabel) /* data whose relocs we want to ignore */ 35 | /* the EFI loader doesn't seem to like a .bss section, so we stick 36 | it all into .data: */ 37 | *(.dynbss) 38 | *(.bss) 39 | *(COMMON) 40 | } 41 | . = ALIGN(4096); 42 | .dynamic : { *(.dynamic) } 43 | . = ALIGN(4096); 44 | .rela : 45 | { 46 | *(.rela.text) 47 | *(.rela.data*) 48 | *(.rela.sdata) 49 | *(.rela.got) 50 | *(.rela.gnu.linkonce.d*) 51 | *(.rela.stab) 52 | *(.rela.ctors) 53 | } 54 | . = ALIGN(4096); 55 | .reloc : /* This is the PECOFF .reloc section! */ 56 | { 57 | *(.reloc) 58 | } 59 | . = ALIGN(4096); 60 | .dynsym : { *(.dynsym) } 61 | . = ALIGN(4096); 62 | .dynstr : { *(.dynstr) } 63 | /DISCARD/ : 64 | { 65 | *(.rela.plabel) 66 | *(.rela.reloc) 67 | *(.IA_64.unwind*) 68 | *(.IA64.unwind*) 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /gnu-efi/gnuefi/elf_x86_64_efi.lds: -------------------------------------------------------------------------------- 1 | /* Same as elf_x86_64_fbsd_efi.lds, except for OUTPUT_FORMAT below - KEEP IN SYNC */ 2 | OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64") 3 | OUTPUT_ARCH(i386:x86-64) 4 | ENTRY(_start) 5 | SECTIONS 6 | { 7 | . = 0; 8 | ImageBase = .; 9 | .hash : { *(.hash) } /* this MUST come first! */ 10 | . = ALIGN(4096); 11 | .eh_frame : 12 | { 13 | *(.eh_frame) 14 | } 15 | . = ALIGN(4096); 16 | .text : 17 | { 18 | *(.text) 19 | *(.text.*) 20 | *(.gnu.linkonce.t.*) 21 | } 22 | . = ALIGN(4096); 23 | .reloc : 24 | { 25 | *(.reloc) 26 | } 27 | . = ALIGN(4096); 28 | .data : 29 | { 30 | *(.rodata*) 31 | *(.got.plt) 32 | *(.got) 33 | *(.data*) 34 | *(.sdata) 35 | /* the EFI loader doesn't seem to like a .bss section, so we stick 36 | it all into .data: */ 37 | *(.sbss) 38 | *(.scommon) 39 | *(.dynbss) 40 | *(.bss) 41 | *(COMMON) 42 | *(.rel.local) 43 | } 44 | . = ALIGN(4096); 45 | .dynamic : { *(.dynamic) } 46 | . = ALIGN(4096); 47 | .rela : 48 | { 49 | *(.rela.data*) 50 | *(.rela.got) 51 | *(.rela.stab) 52 | } 53 | . = ALIGN(4096); 54 | .dynsym : { *(.dynsym) } 55 | . = ALIGN(4096); 56 | .dynstr : { *(.dynstr) } 57 | . = ALIGN(4096); 58 | .ignored.reloc : 59 | { 60 | *(.rela.reloc) 61 | *(.eh_frame) 62 | *(.note.GNU-stack) 63 | } 64 | .comment 0 : { *(.comment) } 65 | } 66 | -------------------------------------------------------------------------------- /gnu-efi/gnuefi/elf_x86_64_fbsd_efi.lds: -------------------------------------------------------------------------------- 1 | /* Same as elf_x86_64_efi.lds, except for OUTPUT_FORMAT below - KEEP IN SYNC */ 2 | OUTPUT_FORMAT("elf64-x86-64-freebsd", "elf64-x86-64-freebsd", "elf64-x86-64-freebsd") 3 | OUTPUT_ARCH(i386:x86-64) 4 | ENTRY(_start) 5 | SECTIONS 6 | { 7 | . = 0; 8 | ImageBase = .; 9 | .hash : { *(.hash) } /* this MUST come first! */ 10 | . = ALIGN(4096); 11 | .eh_frame : 12 | { 13 | *(.eh_frame) 14 | } 15 | . = ALIGN(4096); 16 | .text : 17 | { 18 | *(.text) 19 | } 20 | .reloc : 21 | { 22 | *(.reloc) 23 | } 24 | . = ALIGN(4096); 25 | .data : 26 | { 27 | *(.rodata*) 28 | *(.got.plt) 29 | *(.got) 30 | *(.data*) 31 | *(.sdata) 32 | /* the EFI loader doesn't seem to like a .bss section, so we stick 33 | it all into .data: */ 34 | *(.sbss) 35 | *(.scommon) 36 | *(.dynbss) 37 | *(.bss) 38 | *(COMMON) 39 | *(.rel.local) 40 | } 41 | . = ALIGN(4096); 42 | .dynamic : { *(.dynamic) } 43 | . = ALIGN(4096); 44 | .rela : 45 | { 46 | *(.rela.data*) 47 | *(.rela.got) 48 | *(.rela.stab) 49 | } 50 | . = ALIGN(4096); 51 | .dynsym : { *(.dynsym) } 52 | . = ALIGN(4096); 53 | .dynstr : { *(.dynstr) } 54 | . = ALIGN(4096); 55 | .ignored.reloc : 56 | { 57 | *(.rela.reloc) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /gnu-efi/gnuefi/reloc_aarch64.c: -------------------------------------------------------------------------------- 1 | /* reloc_aarch64.c - position independent x86 ELF shared object relocator 2 | Copyright (C) 2014 Linaro Ltd. 3 | Copyright (C) 1999 Hewlett-Packard Co. 4 | Contributed by David Mosberger . 5 | 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 12 | * Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | * Redistributions in binary form must reproduce the above 15 | copyright notice, this list of conditions and the following 16 | disclaimer in the documentation and/or other materials 17 | provided with the distribution. 18 | * Neither the name of Hewlett-Packard Co. nor the names of its 19 | contributors may be used to endorse or promote products derived 20 | from this software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 27 | BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 28 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 32 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 33 | THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 | SUCH DAMAGE. 35 | */ 36 | 37 | #include 38 | #include 39 | 40 | #include 41 | 42 | EFI_STATUS _relocate (long ldbase, Elf64_Dyn *dyn, EFI_HANDLE image, EFI_SYSTEM_TABLE *systab) 43 | { 44 | long relsz = 0, relent = 0; 45 | Elf64_Rela *rel = 0; 46 | unsigned long *addr; 47 | int i; 48 | 49 | for (i = 0; dyn[i].d_tag != DT_NULL; ++i) { 50 | switch (dyn[i].d_tag) { 51 | case DT_RELA: 52 | rel = (Elf64_Rela*) 53 | ((unsigned long)dyn[i].d_un.d_ptr 54 | + ldbase); 55 | break; 56 | 57 | case DT_RELASZ: 58 | relsz = dyn[i].d_un.d_val; 59 | break; 60 | 61 | case DT_RELAENT: 62 | relent = dyn[i].d_un.d_val; 63 | break; 64 | 65 | default: 66 | break; 67 | } 68 | } 69 | 70 | if (!rel && relent == 0) 71 | return EFI_SUCCESS; 72 | 73 | if (!rel || relent == 0) 74 | return EFI_LOAD_ERROR; 75 | 76 | while (relsz > 0) { 77 | /* apply the relocs */ 78 | switch (ELF64_R_TYPE (rel->r_info)) { 79 | case R_AARCH64_NONE: 80 | break; 81 | 82 | case R_AARCH64_RELATIVE: 83 | addr = (unsigned long *) 84 | (ldbase + rel->r_offset); 85 | *addr = ldbase + rel->r_addend; 86 | break; 87 | 88 | default: 89 | break; 90 | } 91 | rel = (Elf64_Rela*) ((char *) rel + relent); 92 | relsz -= relent; 93 | } 94 | return EFI_SUCCESS; 95 | } 96 | -------------------------------------------------------------------------------- /gnu-efi/gnuefi/reloc_arm.c: -------------------------------------------------------------------------------- 1 | /* reloc_arm.c - position independent x86 ELF shared object relocator 2 | Copyright (C) 2014 Linaro Ltd. 3 | Copyright (C) 1999 Hewlett-Packard Co. 4 | Contributed by David Mosberger . 5 | 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 12 | * Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | * Redistributions in binary form must reproduce the above 15 | copyright notice, this list of conditions and the following 16 | disclaimer in the documentation and/or other materials 17 | provided with the distribution. 18 | * Neither the name of Hewlett-Packard Co. nor the names of its 19 | contributors may be used to endorse or promote products derived 20 | from this software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 27 | BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 28 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 32 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 33 | THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 | SUCH DAMAGE. 35 | */ 36 | 37 | #include 38 | #include 39 | 40 | #include 41 | 42 | EFI_STATUS _relocate (long ldbase, Elf32_Dyn *dyn, EFI_HANDLE image, EFI_SYSTEM_TABLE *systab) 43 | { 44 | long relsz = 0, relent = 0; 45 | Elf32_Rel *rel = 0; 46 | unsigned long *addr; 47 | int i; 48 | 49 | for (i = 0; dyn[i].d_tag != DT_NULL; ++i) { 50 | switch (dyn[i].d_tag) { 51 | case DT_REL: 52 | rel = (Elf32_Rel*) 53 | ((unsigned long)dyn[i].d_un.d_ptr 54 | + ldbase); 55 | break; 56 | 57 | case DT_RELSZ: 58 | relsz = dyn[i].d_un.d_val; 59 | break; 60 | 61 | case DT_RELENT: 62 | relent = dyn[i].d_un.d_val; 63 | break; 64 | 65 | default: 66 | break; 67 | } 68 | } 69 | 70 | if (!rel && relent == 0) 71 | return EFI_SUCCESS; 72 | 73 | if (!rel || relent == 0) 74 | return EFI_LOAD_ERROR; 75 | 76 | while (relsz > 0) { 77 | /* apply the relocs */ 78 | switch (ELF32_R_TYPE (rel->r_info)) { 79 | case R_ARM_NONE: 80 | break; 81 | 82 | case R_ARM_RELATIVE: 83 | addr = (unsigned long *) 84 | (ldbase + rel->r_offset); 85 | *addr += ldbase; 86 | break; 87 | 88 | default: 89 | break; 90 | } 91 | rel = (Elf32_Rel*) ((char *) rel + relent); 92 | relsz -= relent; 93 | } 94 | return EFI_SUCCESS; 95 | } 96 | -------------------------------------------------------------------------------- /gnu-efi/gnuefi/reloc_ia32.c: -------------------------------------------------------------------------------- 1 | /* reloc_ia32.c - position independent x86 ELF shared object relocator 2 | Copyright (C) 1999 Hewlett-Packard Co. 3 | Contributed by David Mosberger . 4 | 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above 14 | copyright notice, this list of conditions and the following 15 | disclaimer in the documentation and/or other materials 16 | provided with the distribution. 17 | * Neither the name of Hewlett-Packard Co. nor the names of its 18 | contributors may be used to endorse or promote products derived 19 | from this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 22 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 23 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 26 | BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 27 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 31 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 32 | THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 | SUCH DAMAGE. 34 | */ 35 | 36 | #include 37 | #include 38 | 39 | #include 40 | 41 | EFI_STATUS _relocate (long ldbase, Elf32_Dyn *dyn, EFI_HANDLE image, EFI_SYSTEM_TABLE *systab) 42 | { 43 | long relsz = 0, relent = 0; 44 | Elf32_Rel *rel = 0; 45 | unsigned long *addr; 46 | int i; 47 | 48 | for (i = 0; dyn[i].d_tag != DT_NULL; ++i) { 49 | switch (dyn[i].d_tag) { 50 | case DT_REL: 51 | rel = (Elf32_Rel*) 52 | ((unsigned long)dyn[i].d_un.d_ptr 53 | + ldbase); 54 | break; 55 | 56 | case DT_RELSZ: 57 | relsz = dyn[i].d_un.d_val; 58 | break; 59 | 60 | case DT_RELENT: 61 | relent = dyn[i].d_un.d_val; 62 | break; 63 | 64 | case DT_RELA: 65 | break; 66 | 67 | default: 68 | break; 69 | } 70 | } 71 | 72 | if (!rel && relent == 0) 73 | return EFI_SUCCESS; 74 | 75 | if (!rel || relent == 0) 76 | return EFI_LOAD_ERROR; 77 | 78 | while (relsz > 0) { 79 | /* apply the relocs */ 80 | switch (ELF32_R_TYPE (rel->r_info)) { 81 | case R_386_NONE: 82 | break; 83 | 84 | case R_386_RELATIVE: 85 | addr = (unsigned long *) 86 | (ldbase + rel->r_offset); 87 | *addr += ldbase; 88 | break; 89 | 90 | default: 91 | break; 92 | } 93 | rel = (Elf32_Rel*) ((char *) rel + relent); 94 | relsz -= relent; 95 | } 96 | return EFI_SUCCESS; 97 | } 98 | -------------------------------------------------------------------------------- /gnu-efi/gnuefi/reloc_x86_64.c: -------------------------------------------------------------------------------- 1 | /* reloc_x86_64.c - position independent x86_64 ELF shared object relocator 2 | Copyright (C) 1999 Hewlett-Packard Co. 3 | Contributed by David Mosberger . 4 | Copyright (C) 2005 Intel Co. 5 | Contributed by Fenghua Yu . 6 | 7 | All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions 11 | are met: 12 | 13 | * Redistributions of source code must retain the above copyright 14 | notice, this list of conditions and the following disclaimer. 15 | * Redistributions in binary form must reproduce the above 16 | copyright notice, this list of conditions and the following 17 | disclaimer in the documentation and/or other materials 18 | provided with the distribution. 19 | * Neither the name of Hewlett-Packard Co. nor the names of its 20 | contributors may be used to endorse or promote products derived 21 | from this software without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 28 | BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 29 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 30 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 33 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 34 | THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 | SUCH DAMAGE. 36 | */ 37 | 38 | #include 39 | #include 40 | 41 | #include 42 | 43 | EFI_STATUS _relocate (long ldbase, Elf64_Dyn *dyn, EFI_HANDLE image, EFI_SYSTEM_TABLE *systab) 44 | { 45 | long relsz = 0, relent = 0; 46 | Elf64_Rel *rel = 0; 47 | unsigned long *addr; 48 | int i; 49 | 50 | for (i = 0; dyn[i].d_tag != DT_NULL; ++i) { 51 | switch (dyn[i].d_tag) { 52 | case DT_RELA: 53 | rel = (Elf64_Rel*) 54 | ((unsigned long)dyn[i].d_un.d_ptr 55 | + ldbase); 56 | break; 57 | 58 | case DT_RELASZ: 59 | relsz = dyn[i].d_un.d_val; 60 | break; 61 | 62 | case DT_RELAENT: 63 | relent = dyn[i].d_un.d_val; 64 | break; 65 | 66 | default: 67 | break; 68 | } 69 | } 70 | 71 | if (!rel && relent == 0) 72 | return EFI_SUCCESS; 73 | 74 | if (!rel || relent == 0) 75 | return EFI_LOAD_ERROR; 76 | 77 | while (relsz > 0) { 78 | /* apply the relocs */ 79 | switch (ELF64_R_TYPE (rel->r_info)) { 80 | case R_X86_64_NONE: 81 | break; 82 | 83 | case R_X86_64_RELATIVE: 84 | addr = (unsigned long *) 85 | (ldbase + rel->r_offset); 86 | *addr += ldbase; 87 | break; 88 | 89 | default: 90 | break; 91 | } 92 | rel = (Elf64_Rel*) ((char *) rel + relent); 93 | relsz -= relent; 94 | } 95 | return EFI_SUCCESS; 96 | } 97 | -------------------------------------------------------------------------------- /gnu-efi/inc/Makefile: -------------------------------------------------------------------------------- 1 | SRCDIR = . 2 | 3 | VPATH = $(SRCDIR) 4 | 5 | include $(SRCDIR)/../Make.defaults 6 | 7 | TOPDIR = $(SRCDIR)/.. 8 | 9 | CDIR=$(TOPDIR)/.. 10 | 11 | all: 12 | 13 | clean: 14 | 15 | install: 16 | mkdir -p $(INSTALLROOT)$(PREFIX)/include/efi 17 | mkdir -p $(INSTALLROOT)$(PREFIX)/include/efi/protocol 18 | mkdir -p $(INSTALLROOT)$(PREFIX)/include/efi/$(ARCH) 19 | $(INSTALL) -m 644 $(SRCDIR)/*.h $(INSTALLROOT)$(PREFIX)/include/efi 20 | $(INSTALL) -m 644 $(SRCDIR)/protocol/*.h $(INSTALLROOT)$(PREFIX)/include/efi/protocol 21 | $(INSTALL) -m 644 $(SRCDIR)/$(ARCH)/*.h $(INSTALLROOT)$(PREFIX)/include/efi/$(ARCH) 22 | ifeq ($(ARCH),ia64) 23 | mkdir -p $(INSTALLROOT)$(PREFIX)/include/efi/protocol/ia64 24 | $(INSTALL) -m 644 $(SRCDIR)/protocol/ia64/*.h $(INSTALLROOT)$(PREFIX)/include/efi/protocol/ia64 25 | endif 26 | 27 | include $(SRCDIR)/../Make.rules 28 | -------------------------------------------------------------------------------- /gnu-efi/inc/aarch64/efibind.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | // 5 | // Basic EFI types of various widths 6 | // 7 | 8 | #ifndef __WCHAR_TYPE__ 9 | # define __WCHAR_TYPE__ short 10 | #endif 11 | 12 | typedef uint64_t UINT64; 13 | typedef int64_t INT64; 14 | 15 | typedef uint32_t UINT32; 16 | typedef int32_t INT32; 17 | 18 | typedef uint16_t UINT16; 19 | typedef int16_t INT16; 20 | typedef uint8_t UINT8; 21 | typedef int8_t INT8; 22 | typedef __WCHAR_TYPE__ WCHAR; 23 | 24 | #undef VOID 25 | #define VOID void 26 | 27 | typedef int64_t INTN; 28 | typedef uint64_t UINTN; 29 | 30 | #define EFIERR(a) (0x8000000000000000 | a) 31 | #define EFI_ERROR_MASK 0x8000000000000000 32 | #define EFIERR_OEM(a) (0xc000000000000000 | a) 33 | 34 | #define BAD_POINTER 0xFBFBFBFBFBFBFBFB 35 | #define MAX_ADDRESS 0xFFFFFFFFFFFFFFFF 36 | 37 | #define BREAKPOINT() while (TRUE); // Make it hang on Bios[Dbg]32 38 | 39 | // 40 | // Pointers must be aligned to these address to function 41 | // 42 | 43 | #define MIN_ALIGNMENT_SIZE 8 44 | 45 | #define ALIGN_VARIABLE(Value ,Adjustment) \ 46 | (UINTN)Adjustment = 0; \ 47 | if((UINTN)Value % MIN_ALIGNMENT_SIZE) \ 48 | (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \ 49 | Value = (UINTN)Value + (UINTN)Adjustment 50 | 51 | 52 | // 53 | // Define macros to build data structure signatures from characters. 54 | // 55 | 56 | #define EFI_SIGNATURE_16(A,B) ((A) | (B<<8)) 57 | #define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16)) 58 | #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)) 59 | 60 | // 61 | // EFIAPI - prototype calling convention for EFI function pointers 62 | // BOOTSERVICE - prototype for implementation of a boot service interface 63 | // RUNTIMESERVICE - prototype for implementation of a runtime service interface 64 | // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service 65 | // RUNTIME_CODE - pragma macro for declaring runtime code 66 | // 67 | 68 | #ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options 69 | #define EFIAPI // Substitute expresion to force C calling convention 70 | #endif 71 | 72 | #define BOOTSERVICE 73 | #define RUNTIMESERVICE 74 | #define RUNTIMEFUNCTION 75 | 76 | 77 | #define RUNTIME_CODE(a) alloc_text("rtcode", a) 78 | #define BEGIN_RUNTIME_DATA() data_seg("rtdata") 79 | #define END_RUNTIME_DATA() data_seg("") 80 | 81 | #define VOLATILE volatile 82 | 83 | #define MEMORY_FENCE __sync_synchronize 84 | 85 | // 86 | // When build similiar to FW, then link everything together as 87 | // one big module. 88 | // 89 | 90 | #define EFI_DRIVER_ENTRY_POINT(InitFunction) \ 91 | UINTN \ 92 | InitializeDriver ( \ 93 | VOID *ImageHandle, \ 94 | VOID *SystemTable \ 95 | ) \ 96 | { \ 97 | return InitFunction(ImageHandle, \ 98 | SystemTable); \ 99 | } \ 100 | \ 101 | EFI_STATUS efi_main( \ 102 | EFI_HANDLE image, \ 103 | EFI_SYSTEM_TABLE *systab \ 104 | ) __attribute__((weak, \ 105 | alias ("InitializeDriver"))); 106 | 107 | #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \ 108 | (_if)->LoadInternal(type, name, entry) 109 | 110 | 111 | // 112 | // Some compilers don't support the forward reference construct: 113 | // typedef struct XXXXX 114 | // 115 | // The following macro provide a workaround for such cases. 116 | 117 | #define INTERFACE_DECL(x) struct x 118 | 119 | #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__) 120 | #define EFI_FUNCTION 121 | -------------------------------------------------------------------------------- /gnu-efi/inc/aarch64/efilibplat.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 1998 Intel Corporation 4 | 5 | Module Name: 6 | 7 | efilibplat.h 8 | 9 | Abstract: 10 | 11 | EFI to compile bindings 12 | 13 | 14 | 15 | 16 | Revision History 17 | 18 | --*/ 19 | 20 | VOID 21 | InitializeLibPlatform ( 22 | IN EFI_HANDLE ImageHandle, 23 | IN EFI_SYSTEM_TABLE *SystemTable 24 | ); 25 | 26 | -------------------------------------------------------------------------------- /gnu-efi/inc/arm/efilibplat.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 1998 Intel Corporation 4 | 5 | Module Name: 6 | 7 | efilibplat.h 8 | 9 | Abstract: 10 | 11 | EFI to compile bindings 12 | 13 | 14 | 15 | 16 | Revision History 17 | 18 | --*/ 19 | 20 | VOID 21 | InitializeLibPlatform ( 22 | IN EFI_HANDLE ImageHandle, 23 | IN EFI_SYSTEM_TABLE *SystemTable 24 | ); 25 | 26 | -------------------------------------------------------------------------------- /gnu-efi/inc/efi.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 1998 Intel Corporation 4 | 5 | Module Name: 6 | 7 | efi.h 8 | 9 | Abstract: 10 | 11 | Public EFI header files 12 | 13 | 14 | 15 | Revision History 16 | 17 | --*/ 18 | 19 | // 20 | // Build flags on input 21 | // EFI32 22 | // EFI_DEBUG - Enable debugging code 23 | // EFI_NT_EMULATOR - Building for running under NT 24 | // 25 | 26 | 27 | #ifndef _EFI_INCLUDE_ 28 | #define _EFI_INCLUDE_ 29 | 30 | #define EFI_FIRMWARE_VENDOR L"INTEL" 31 | #define EFI_FIRMWARE_MAJOR_REVISION 12 32 | #define EFI_FIRMWARE_MINOR_REVISION 33 33 | #define EFI_FIRMWARE_REVISION ((EFI_FIRMWARE_MAJOR_REVISION <<16) | (EFI_FIRMWARE_MINOR_REVISION)) 34 | 35 | #include "efibind.h" 36 | #include "efidef.h" 37 | #include "efidevp.h" 38 | #include "efipciio.h" 39 | #include "efiprot.h" 40 | #include "eficon.h" 41 | #include "efiser.h" 42 | #include "efi_nii.h" 43 | #include "efipxebc.h" 44 | #include "efinet.h" 45 | #include "efiapi.h" 46 | #include "efifs.h" 47 | #include "efierr.h" 48 | #include "efiui.h" 49 | #include "efiip.h" 50 | #include "efiudp.h" 51 | #include "efitcp.h" 52 | #include "efipoint.h" 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /gnu-efi/inc/efi_nii.h: -------------------------------------------------------------------------------- 1 | #ifndef _EFI_NII_H 2 | #define _EFI_NII_H 3 | 4 | /*++ 5 | Copyright (c) 2000 Intel Corporation 6 | 7 | Module name: 8 | efi_nii.h 9 | 10 | Abstract: 11 | 12 | Revision history: 13 | 2000-Feb-18 M(f)J GUID updated. 14 | Structure order changed for machine word alignment. 15 | Added StringId[4] to structure. 16 | 17 | 2000-Feb-14 M(f)J Genesis. 18 | --*/ 19 | 20 | #define EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL \ 21 | { 0xE18541CD, 0xF755, 0x4f73, {0x92, 0x8D, 0x64, 0x3C, 0x8A, 0x79, 0xB2, 0x29} } 22 | 23 | #define EFI_NETWORK_INTERFACE_IDENTIFIER_INTERFACE_REVISION 0x00010000 24 | 25 | typedef enum { 26 | EfiNetworkInterfaceUndi = 1 27 | } EFI_NETWORK_INTERFACE_TYPE; 28 | 29 | typedef struct { 30 | 31 | UINT64 Revision; 32 | // Revision of the network interface identifier protocol interface. 33 | 34 | UINT64 ID; 35 | // Address of the first byte of the identifying structure for this 36 | // network interface. This is set to zero if there is no structure. 37 | // 38 | // For PXE/UNDI this is the first byte of the !PXE structure. 39 | 40 | UINT64 ImageAddr; 41 | // Address of the UNrelocated driver/ROM image. This is set 42 | // to zero if there is no driver/ROM image. 43 | // 44 | // For 16-bit UNDI, this is the first byte of the option ROM in 45 | // upper memory. 46 | // 47 | // For 32/64-bit S/W UNDI, this is the first byte of the EFI ROM 48 | // image. 49 | // 50 | // For H/W UNDI, this is set to zero. 51 | 52 | UINT32 ImageSize; 53 | // Size of the UNrelocated driver/ROM image of this network interface. 54 | // This is set to zero if there is no driver/ROM image. 55 | 56 | CHAR8 StringId[4]; 57 | // 4 char ASCII string to go in class identifier (option 60) in DHCP 58 | // and Boot Server discover packets. 59 | // For EfiNetworkInterfaceUndi this field is "UNDI". 60 | // For EfiNetworkInterfaceSnp this field is "SNPN". 61 | 62 | UINT8 Type; 63 | UINT8 MajorVer; 64 | UINT8 MinorVer; 65 | // Information to be placed into the PXE DHCP and Discover packets. 66 | // This is the network interface type and version number that will 67 | // be placed into DHCP option 94 (client network interface identifier). 68 | BOOLEAN Ipv6Supported; 69 | UINT8 IfNum; // interface number to be used with pxeid structure 70 | } EFI_NETWORK_INTERFACE_IDENTIFIER_INTERFACE; 71 | 72 | extern EFI_GUID NetworkInterfaceIdentifierProtocol; 73 | 74 | #endif // _EFI_NII_H 75 | -------------------------------------------------------------------------------- /gnu-efi/inc/efidebug.h: -------------------------------------------------------------------------------- 1 | #ifndef _EFI_DEBUG_H 2 | #define _EFI_DEBUG_H 3 | 4 | /*++ 5 | 6 | Copyright (c) 1998 Intel Corporation 7 | 8 | Module Name: 9 | 10 | efidebug.h 11 | 12 | Abstract: 13 | 14 | EFI library debug functions 15 | 16 | 17 | 18 | Revision History 19 | 20 | --*/ 21 | 22 | extern UINTN EFIDebug; 23 | 24 | #if EFI_DEBUG 25 | 26 | #define DBGASSERT(a) DbgAssert(__FILE__, __LINE__, #a) 27 | #define DEBUG(a) DbgPrint a 28 | 29 | #else 30 | 31 | #define DBGASSERT(a) 32 | #define DEBUG(a) 33 | 34 | #endif 35 | 36 | #if EFI_DEBUG_CLEAR_MEMORY 37 | 38 | #define DBGSETMEM(a,l) SetMem(a,l,(CHAR8)BAD_POINTER) 39 | 40 | #else 41 | 42 | #define DBGSETMEM(a,l) 43 | 44 | #endif 45 | 46 | #define D_INIT 0x00000001 // Initialization style messages 47 | #define D_WARN 0x00000002 // Warnings 48 | #define D_LOAD 0x00000004 // Load events 49 | #define D_FS 0x00000008 // EFI File system 50 | #define D_POOL 0x00000010 // Alloc & Free's 51 | #define D_PAGE 0x00000020 // Alloc & Free's 52 | #define D_INFO 0x00000040 // Verbose 53 | #define D_VAR 0x00000100 // Variable 54 | #define D_PARSE 0x00000200 // Command parsing 55 | #define D_BM 0x00000400 // Boot manager 56 | #define D_BLKIO 0x00001000 // BlkIo Driver 57 | #define D_BLKIO_ULTRA 0x00002000 // BlkIo Driver 58 | #define D_NET 0x00004000 // SNI Driver 59 | #define D_NET_ULTRA 0x00008000 // SNI Driver 60 | #define D_TXTIN 0x00010000 // Simple Input Driver 61 | #define D_TXTOUT 0x00020000 // Simple Text Output Driver 62 | #define D_ERROR_ATA 0x00040000 // ATA error messages 63 | #define D_ERROR 0x80000000 // Error 64 | 65 | #define D_RESERVED 0x7fffC880 // Bits not reserved above 66 | 67 | // 68 | // Current Debug level of the system, value of EFIDebug 69 | // 70 | //#define EFI_DBUG_MASK (D_ERROR | D_WARN | D_LOAD | D_BLKIO | D_INIT) 71 | #define EFI_DBUG_MASK (D_ERROR) 72 | 73 | // 74 | // 75 | // 76 | 77 | #if EFI_DEBUG 78 | 79 | #define ASSERT(a) if(!(a)) DBGASSERT(a) 80 | #define ASSERT_LOCKED(l) if(!(l)->Lock) DBGASSERT(l not locked) 81 | #define ASSERT_STRUCT(p,t) DBGASSERT(t not structure), p 82 | 83 | #else 84 | 85 | #define ASSERT(a) 86 | #define ASSERT_LOCKED(l) 87 | #define ASSERT_STRUCT(p,t) 88 | 89 | #endif 90 | 91 | // 92 | // Prototypes 93 | // 94 | 95 | INTN 96 | DbgAssert ( 97 | CHAR8 *file, 98 | INTN lineno, 99 | CHAR8 *string 100 | ); 101 | 102 | INTN 103 | DbgPrint ( 104 | INTN mask, 105 | CHAR8 *format, 106 | ... 107 | ); 108 | 109 | #endif 110 | 111 | -------------------------------------------------------------------------------- /gnu-efi/inc/efierr.h: -------------------------------------------------------------------------------- 1 | #ifndef _EFI_ERR_H 2 | #define _EFI_ERR_H 3 | 4 | /*++ 5 | 6 | Copyright (c) 1998 Intel Corporation 7 | 8 | Module Name: 9 | 10 | efierr.h 11 | 12 | Abstract: 13 | 14 | EFI error codes 15 | 16 | 17 | 18 | 19 | Revision History 20 | 21 | --*/ 22 | 23 | 24 | #define EFIWARN(a) (a) 25 | #define EFI_ERROR(a) (((INTN) a) < 0) 26 | 27 | 28 | #define EFI_SUCCESS 0 29 | #define EFI_LOAD_ERROR EFIERR(1) 30 | #define EFI_INVALID_PARAMETER EFIERR(2) 31 | #define EFI_UNSUPPORTED EFIERR(3) 32 | #define EFI_BAD_BUFFER_SIZE EFIERR(4) 33 | #define EFI_BUFFER_TOO_SMALL EFIERR(5) 34 | #define EFI_NOT_READY EFIERR(6) 35 | #define EFI_DEVICE_ERROR EFIERR(7) 36 | #define EFI_WRITE_PROTECTED EFIERR(8) 37 | #define EFI_OUT_OF_RESOURCES EFIERR(9) 38 | #define EFI_VOLUME_CORRUPTED EFIERR(10) 39 | #define EFI_VOLUME_FULL EFIERR(11) 40 | #define EFI_NO_MEDIA EFIERR(12) 41 | #define EFI_MEDIA_CHANGED EFIERR(13) 42 | #define EFI_NOT_FOUND EFIERR(14) 43 | #define EFI_ACCESS_DENIED EFIERR(15) 44 | #define EFI_NO_RESPONSE EFIERR(16) 45 | #define EFI_NO_MAPPING EFIERR(17) 46 | #define EFI_TIMEOUT EFIERR(18) 47 | #define EFI_NOT_STARTED EFIERR(19) 48 | #define EFI_ALREADY_STARTED EFIERR(20) 49 | #define EFI_ABORTED EFIERR(21) 50 | #define EFI_ICMP_ERROR EFIERR(22) 51 | #define EFI_TFTP_ERROR EFIERR(23) 52 | #define EFI_PROTOCOL_ERROR EFIERR(24) 53 | #define EFI_INCOMPATIBLE_VERSION EFIERR(25) 54 | #define EFI_SECURITY_VIOLATION EFIERR(26) 55 | #define EFI_CRC_ERROR EFIERR(27) 56 | #define EFI_END_OF_MEDIA EFIERR(28) 57 | #define EFI_END_OF_FILE EFIERR(31) 58 | #define EFI_INVALID_LANGUAGE EFIERR(32) 59 | #define EFI_COMPROMISED_DATA EFIERR(33) 60 | 61 | #define EFI_WARN_UNKOWN_GLYPH EFIWARN(1) 62 | #define EFI_WARN_DELETE_FAILURE EFIWARN(2) 63 | #define EFI_WARN_WRITE_FAILURE EFIWARN(3) 64 | #define EFI_WARN_BUFFER_TOO_SMALL EFIWARN(4) 65 | 66 | #endif 67 | 68 | -------------------------------------------------------------------------------- /gnu-efi/inc/efifs.h: -------------------------------------------------------------------------------- 1 | #ifndef _EFI_FS_H 2 | #define _EFI_FS_H 3 | 4 | /*++ 5 | 6 | Copyright (c) 1998 Intel Corporation 7 | 8 | Module Name: 9 | 10 | efifs.h 11 | 12 | Abstract: 13 | 14 | EFI File System structures 15 | 16 | 17 | 18 | Revision History 19 | 20 | --*/ 21 | 22 | 23 | // 24 | // EFI Partition header (normaly starts in LBA 1) 25 | // 26 | 27 | #define EFI_PARTITION_SIGNATURE 0x5053595320494249 28 | #define EFI_PARTITION_REVISION 0x00010001 29 | #define MIN_EFI_PARTITION_BLOCK_SIZE 512 30 | #define EFI_PARTITION_LBA 1 31 | 32 | typedef struct _EFI_PARTITION_HEADER { 33 | EFI_TABLE_HEADER Hdr; 34 | UINT32 DirectoryAllocationNumber; 35 | UINT32 BlockSize; 36 | EFI_LBA FirstUsableLba; 37 | EFI_LBA LastUsableLba; 38 | EFI_LBA UnusableSpace; 39 | EFI_LBA FreeSpace; 40 | EFI_LBA RootFile; 41 | EFI_LBA SecutiryFile; 42 | } EFI_PARTITION_HEADER; 43 | 44 | 45 | // 46 | // File header 47 | // 48 | 49 | #define EFI_FILE_HEADER_SIGNATURE 0x454c494620494249 50 | #define EFI_FILE_HEADER_REVISION 0x00010000 51 | #define EFI_FILE_STRING_SIZE 260 52 | 53 | typedef struct _EFI_FILE_HEADER { 54 | EFI_TABLE_HEADER Hdr; 55 | UINT32 Class; 56 | UINT32 LBALOffset; 57 | EFI_LBA Parent; 58 | UINT64 FileSize; 59 | UINT64 FileAttributes; 60 | EFI_TIME FileCreateTime; 61 | EFI_TIME FileModificationTime; 62 | EFI_GUID VendorGuid; 63 | CHAR16 FileString[EFI_FILE_STRING_SIZE]; 64 | } EFI_FILE_HEADER; 65 | 66 | 67 | // 68 | // Return the file's first LBAL which is in the same 69 | // logical block as the file header 70 | // 71 | 72 | #define EFI_FILE_LBAL(a) ((EFI_LBAL *) (((CHAR8 *) (a)) + (a)->LBALOffset)) 73 | 74 | #define EFI_FILE_CLASS_FREE_SPACE 1 75 | #define EFI_FILE_CLASS_EMPTY 2 76 | #define EFI_FILE_CLASS_NORMAL 3 77 | 78 | 79 | // 80 | // Logical Block Address List - the fundemental block 81 | // description structure 82 | // 83 | 84 | #define EFI_LBAL_SIGNATURE 0x4c41424c20494249 85 | #define EFI_LBAL_REVISION 0x00010000 86 | 87 | typedef struct _EFI_LBAL { 88 | EFI_TABLE_HEADER Hdr; 89 | UINT32 Class; 90 | EFI_LBA Parent; 91 | EFI_LBA Next; 92 | UINT32 ArraySize; 93 | UINT32 ArrayCount; 94 | } EFI_LBAL; 95 | 96 | // Array size 97 | #define EFI_LBAL_ARRAY_SIZE(lbal,offs,blks) \ 98 | (((blks) - (offs) - (lbal)->Hdr.HeaderSize) / sizeof(EFI_RL)) 99 | 100 | // 101 | // Logical Block run-length 102 | // 103 | 104 | typedef struct { 105 | EFI_LBA Start; 106 | UINT64 Length; 107 | } EFI_RL; 108 | 109 | // 110 | // Return the run-length structure from an LBAL header 111 | // 112 | 113 | #define EFI_LBAL_RL(a) ((EFI_RL*) (((CHAR8 *) (a)) + (a)->Hdr.HeaderSize)) 114 | 115 | #endif 116 | 117 | -------------------------------------------------------------------------------- /gnu-efi/inc/efigpt.h: -------------------------------------------------------------------------------- 1 | #ifndef _EFI_GPT_H 2 | #define _EFI_GPT_H 3 | /*++ 4 | 5 | Copyright (c) 1998 Intel Corporation 6 | 7 | Module Name: 8 | 9 | EfiGpt.h 10 | 11 | Abstract: 12 | Include file for EFI partitioning scheme 13 | 14 | 15 | 16 | Revision History 17 | 18 | --*/ 19 | 20 | #define PRIMARY_PART_HEADER_LBA 1 21 | 22 | typedef struct { 23 | EFI_TABLE_HEADER Header; 24 | EFI_LBA MyLBA; 25 | EFI_LBA AlternateLBA; 26 | EFI_LBA FirstUsableLBA; 27 | EFI_LBA LastUsableLBA; 28 | EFI_GUID DiskGUID; 29 | EFI_LBA PartitionEntryLBA; 30 | UINT32 NumberOfPartitionEntries; 31 | UINT32 SizeOfPartitionEntry; 32 | UINT32 PartitionEntryArrayCRC32; 33 | } EFI_PARTITION_TABLE_HEADER; 34 | 35 | #define EFI_PTAB_HEADER_ID "EFI PART" 36 | 37 | typedef struct { 38 | EFI_GUID PartitionTypeGUID; 39 | EFI_GUID UniquePartitionGUID; 40 | EFI_LBA StartingLBA; 41 | EFI_LBA EndingLBA; 42 | UINT64 Attributes; 43 | CHAR16 PartitionName[36]; 44 | } EFI_PARTITION_ENTRY; 45 | 46 | // 47 | // EFI Partition Attributes 48 | // 49 | #define EFI_PART_USED_BY_EFI 0x0000000000000001 50 | #define EFI_PART_REQUIRED_TO_FUNCTION 0x0000000000000002 51 | #define EFI_PART_USED_BY_OS 0x0000000000000004 52 | #define EFI_PART_REQUIRED_BY_OS 0x0000000000000008 53 | #define EFI_PART_BACKUP_REQUIRED 0x0000000000000010 54 | #define EFI_PART_USER_DATA 0x0000000000000020 55 | #define EFI_PART_CRITICAL_USER_DATA 0x0000000000000040 56 | #define EFI_PART_REDUNDANT_PARTITION 0x0000000000000080 57 | 58 | #define EFI_PART_TYPE_UNUSED_GUID \ 59 | { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} } 60 | 61 | #define EFI_PART_TYPE_EFI_SYSTEM_PART_GUID \ 62 | { 0xc12a7328, 0xf81f, 0x11d2, {0xba, 0x4b, 0x00, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b} } 63 | 64 | #define EFI_PART_TYPE_LEGACY_MBR_GUID \ 65 | { 0x024dee41, 0x33e7, 0x11d3, {0x9d, 0x69, 0x00, 0x08, 0xc7, 0x81, 0xf3, 0x9f} } 66 | 67 | #endif 68 | 69 | -------------------------------------------------------------------------------- /gnu-efi/inc/efipart.h: -------------------------------------------------------------------------------- 1 | #ifndef _EFI_PART_H 2 | #define _EFI_PART_H 3 | 4 | /*++ 5 | 6 | Copyright (c) 1998 Intel Corporation 7 | 8 | Module Name: 9 | 10 | efipart.h 11 | 12 | Abstract: 13 | Info about disk partitions and Master Boot Records 14 | 15 | 16 | 17 | 18 | Revision History 19 | 20 | --*/ 21 | 22 | // 23 | // 24 | // 25 | 26 | #define EFI_PARTITION 0xef 27 | #define MBR_SIZE 512 28 | 29 | #pragma pack(1) 30 | 31 | typedef struct { 32 | UINT8 BootIndicator; 33 | UINT8 StartHead; 34 | UINT8 StartSector; 35 | UINT8 StartTrack; 36 | UINT8 OSIndicator; 37 | UINT8 EndHead; 38 | UINT8 EndSector; 39 | UINT8 EndTrack; 40 | UINT8 StartingLBA[4]; 41 | UINT8 SizeInLBA[4]; 42 | } MBR_PARTITION_RECORD; 43 | 44 | #define EXTRACT_UINT32(D) (UINT32)(D[0] | (D[1] << 8) | (D[2] << 16) | (D[3] << 24)) 45 | 46 | #define MBR_SIGNATURE 0xaa55 47 | #define MIN_MBR_DEVICE_SIZE 0x80000 48 | #define MBR_ERRATA_PAD 0x40000 // 128 MB 49 | 50 | #define MAX_MBR_PARTITIONS 4 51 | typedef struct { 52 | UINT8 BootStrapCode[440]; 53 | UINT8 UniqueMbrSignature[4]; 54 | UINT8 Unknown[2]; 55 | MBR_PARTITION_RECORD Partition[MAX_MBR_PARTITIONS]; 56 | UINT16 Signature; 57 | } MASTER_BOOT_RECORD; 58 | #pragma pack() 59 | 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /gnu-efi/inc/efipoint.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2014 by John Cronin 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | * THE SOFTWARE. 20 | */ 21 | 22 | #ifndef _EFI_POINT_H 23 | #define _EFI_POINT_H 24 | 25 | #define EFI_SIMPLE_POINTER_PROTOCOL_GUID \ 26 | { 0x31878c87, 0xb75, 0x11d5, { 0x9a, 0x4f, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } } 27 | 28 | INTERFACE_DECL(_EFI_SIMPLE_POINTER); 29 | 30 | typedef struct { 31 | INT32 RelativeMovementX; 32 | INT32 RelativeMovementY; 33 | INT32 RelativeMovementZ; 34 | BOOLEAN LeftButton; 35 | BOOLEAN RightButton; 36 | } EFI_SIMPLE_POINTER_STATE; 37 | 38 | typedef struct { 39 | UINT64 ResolutionX; 40 | UINT64 ResolutionY; 41 | UINT64 ResolutionZ; 42 | BOOLEAN LeftButton; 43 | BOOLEAN RightButton; 44 | } EFI_SIMPLE_POINTER_MODE; 45 | 46 | typedef 47 | EFI_STATUS 48 | (EFIAPI *EFI_SIMPLE_POINTER_RESET) ( 49 | IN struct _EFI_SIMPLE_POINTER *This, 50 | IN BOOLEAN ExtendedVerification 51 | ); 52 | 53 | typedef 54 | EFI_STATUS 55 | (EFIAPI *EFI_SIMPLE_POINTER_GET_STATE) ( 56 | IN struct _EFI_SIMPLE_POINTER *This, 57 | IN OUT EFI_SIMPLE_POINTER_STATE *State 58 | ); 59 | 60 | typedef struct _EFI_SIMPLE_POINTER { 61 | EFI_SIMPLE_POINTER_RESET Reset; 62 | EFI_SIMPLE_POINTER_GET_STATE GetState; 63 | EFI_EVENT WaitForInput; 64 | EFI_SIMPLE_POINTER_MODE *Mode; 65 | } EFI_SIMPLE_POINTER_PROTOCOL; 66 | 67 | #define EFI_ABSOLUTE_POINTER_PROTOCOL_GUID \ 68 | { 0x8D59D32B, 0xC655, 0x4AE9, { 0x9B, 0x15, 0xF2, 0x59, 0x04, 0x99, 0x2A, 0x43 } } 69 | 70 | INTERFACE_DECL(_EFI_ABSOLUTE_POINTER_PROTOCOL); 71 | 72 | typedef struct { 73 | UINT64 AbsoluteMinX; 74 | UINT64 AbsoluteMinY; 75 | UINT64 AbsoluteMinZ; 76 | UINT64 AbsoluteMaxX; 77 | UINT64 AbsoluteMaxY; 78 | UINT64 AbsoluteMaxZ; 79 | UINT32 Attributes; 80 | } EFI_ABSOLUTE_POINTER_MODE; 81 | 82 | typedef struct { 83 | UINT64 CurrentX; 84 | UINT64 CurrentY; 85 | UINT64 CurrentZ; 86 | UINT32 ActiveButtons; 87 | } EFI_ABSOLUTE_POINTER_STATE; 88 | 89 | #define EFI_ABSP_SupportsAltActive 0x00000001 90 | #define EFI_ABSP_SupportsPressureAsZ 0x00000002 91 | #define EFI_ABSP_TouchActive 0x00000001 92 | #define EFI_ABS_AltActive 0x00000002 93 | 94 | typedef 95 | EFI_STATUS 96 | (EFIAPI *EFI_ABSOLUTE_POINTER_RESET) ( 97 | IN struct _EFI_ABSOLUTE_POINTER_PROTOCOL *This, 98 | IN BOOLEAN ExtendedVerification 99 | ); 100 | 101 | typedef 102 | EFI_STATUS 103 | (EFIAPI *EFI_ABSOLUTE_POINTER_GET_STATE) ( 104 | IN struct _EFI_ABSOLUTE_POINTER_PROTOCOL *This, 105 | IN OUT EFI_ABSOLUTE_POINTER_STATE *State 106 | ); 107 | 108 | typedef struct _EFI_ABSOLUTE_POINTER_PROTOCOL { 109 | EFI_ABSOLUTE_POINTER_RESET Reset; 110 | EFI_ABSOLUTE_POINTER_GET_STATE GetState; 111 | EFI_EVENT WaitForInput; 112 | EFI_ABSOLUTE_POINTER_MODE *Mode; 113 | } EFI_ABSOLUTE_POINTER_PROTOCOL; 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /gnu-efi/inc/efirtlib.h: -------------------------------------------------------------------------------- 1 | #ifndef _EFI_RT_LIB_INCLUDE_ 2 | #define _EFI_RT_LIB_INCLUDE_ 3 | /*++ 4 | 5 | Copyright (c) 1998 Intel Corporation 6 | 7 | Module Name: 8 | 9 | efilib.h 10 | 11 | Abstract: 12 | 13 | EFI Runtime library functions 14 | 15 | 16 | 17 | Revision History 18 | 19 | --*/ 20 | 21 | #include "efidebug.h" 22 | #include "efipart.h" 23 | #include "efilibplat.h" 24 | 25 | 26 | VOID 27 | RUNTIMEFUNCTION 28 | RtZeroMem ( 29 | IN VOID *Buffer, 30 | IN UINTN Size 31 | ); 32 | 33 | VOID 34 | RUNTIMEFUNCTION 35 | RtSetMem ( 36 | IN VOID *Buffer, 37 | IN UINTN Size, 38 | IN UINT8 Value 39 | ); 40 | 41 | VOID 42 | RUNTIMEFUNCTION 43 | RtCopyMem ( 44 | IN VOID *Dest, 45 | IN CONST VOID *Src, 46 | IN UINTN len 47 | ); 48 | 49 | INTN 50 | RUNTIMEFUNCTION 51 | RtCompareMem ( 52 | IN CONST VOID *Dest, 53 | IN CONST VOID *Src, 54 | IN UINTN len 55 | ); 56 | 57 | INTN 58 | RUNTIMEFUNCTION 59 | RtStrCmp ( 60 | IN CONST CHAR16 *s1, 61 | IN CONST CHAR16 *s2 62 | ); 63 | 64 | 65 | VOID 66 | RUNTIMEFUNCTION 67 | RtStrCpy ( 68 | IN CHAR16 *Dest, 69 | IN CONST CHAR16 *Src 70 | ); 71 | 72 | VOID 73 | RUNTIMEFUNCTION 74 | RtStrCat ( 75 | IN CHAR16 *Dest, 76 | IN CONST CHAR16 *Src 77 | ); 78 | 79 | UINTN 80 | RUNTIMEFUNCTION 81 | RtStrLen ( 82 | IN CONST CHAR16 *s1 83 | ); 84 | 85 | UINTN 86 | RUNTIMEFUNCTION 87 | RtStrSize ( 88 | IN CONST CHAR16 *s1 89 | ); 90 | 91 | INTN 92 | RUNTIMEFUNCTION 93 | RtCompareGuid ( 94 | IN EFI_GUID *Guid1, 95 | IN EFI_GUID *Guid2 96 | ); 97 | 98 | UINT8 99 | RUNTIMEFUNCTION 100 | RtDecimaltoBCD( 101 | IN UINT8 BcdValue 102 | ); 103 | 104 | UINT8 105 | RUNTIMEFUNCTION 106 | RtBCDtoDecimal( 107 | IN UINT8 BcdValue 108 | ); 109 | 110 | // 111 | // Virtual mapping transition support. (Only used during 112 | // the virtual address change transisition) 113 | // 114 | 115 | VOID 116 | RUNTIMEFUNCTION 117 | RtLibEnableVirtualMappings ( 118 | VOID 119 | ); 120 | 121 | VOID 122 | RUNTIMEFUNCTION 123 | RtConvertList ( 124 | IN UINTN DebugDisposition, 125 | IN OUT LIST_ENTRY *ListHead 126 | ); 127 | 128 | VOID 129 | RUNTIMEFUNCTION 130 | RtAcquireLock ( 131 | IN FLOCK *Lock 132 | ); 133 | 134 | VOID 135 | RUNTIMEFUNCTION 136 | RtReleaseLock ( 137 | IN FLOCK *Lock 138 | ); 139 | 140 | 141 | #endif 142 | -------------------------------------------------------------------------------- /gnu-efi/inc/efiser.h: -------------------------------------------------------------------------------- 1 | #ifndef _EFI_SER_H 2 | #define _EFI_SER_H 3 | 4 | /*++ 5 | 6 | Copyright (c) 1998 Intel Corporation 7 | 8 | Module Name: 9 | 10 | efiser.h 11 | 12 | Abstract: 13 | 14 | EFI serial protocol 15 | 16 | Revision History 17 | 18 | --*/ 19 | 20 | // 21 | // Serial protocol 22 | // 23 | 24 | #define SERIAL_IO_PROTOCOL \ 25 | { 0xBB25CF6F, 0xF1D4, 0x11D2, {0x9A, 0x0C, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0xFD} } 26 | 27 | INTERFACE_DECL(_SERIAL_IO_INTERFACE); 28 | 29 | typedef enum { 30 | DefaultParity, 31 | NoParity, 32 | EvenParity, 33 | OddParity, 34 | MarkParity, 35 | SpaceParity 36 | } EFI_PARITY_TYPE; 37 | 38 | typedef enum { 39 | DefaultStopBits, 40 | OneStopBit, // 1 stop bit 41 | OneFiveStopBits, // 1.5 stop bits 42 | TwoStopBits // 2 stop bits 43 | } EFI_STOP_BITS_TYPE; 44 | 45 | #define EFI_SERIAL_CLEAR_TO_SEND 0x0010 // RO 46 | #define EFI_SERIAL_DATA_SET_READY 0x0020 // RO 47 | #define EFI_SERIAL_RING_INDICATE 0x0040 // RO 48 | #define EFI_SERIAL_CARRIER_DETECT 0x0080 // RO 49 | #define EFI_SERIAL_REQUEST_TO_SEND 0x0002 // WO 50 | #define EFI_SERIAL_DATA_TERMINAL_READY 0x0001 // WO 51 | #define EFI_SERIAL_INPUT_BUFFER_EMPTY 0x0100 // RO 52 | #define EFI_SERIAL_OUTPUT_BUFFER_EMPTY 0x0200 // RO 53 | #define EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE 0x1000 // RW 54 | #define EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE 0x2000 // RW 55 | #define EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE 0x4000 // RW 56 | 57 | typedef 58 | EFI_STATUS 59 | (EFIAPI *EFI_SERIAL_RESET) ( 60 | IN struct _SERIAL_IO_INTERFACE *This 61 | ); 62 | 63 | typedef 64 | EFI_STATUS 65 | (EFIAPI *EFI_SERIAL_SET_ATTRIBUTES) ( 66 | IN struct _SERIAL_IO_INTERFACE *This, 67 | IN UINT64 BaudRate, 68 | IN UINT32 ReceiveFifoDepth, 69 | IN UINT32 Timeout, 70 | IN EFI_PARITY_TYPE Parity, 71 | IN UINT8 DataBits, 72 | IN EFI_STOP_BITS_TYPE StopBits 73 | ); 74 | 75 | typedef 76 | EFI_STATUS 77 | (EFIAPI *EFI_SERIAL_SET_CONTROL_BITS) ( 78 | IN struct _SERIAL_IO_INTERFACE *This, 79 | IN UINT32 Control 80 | ); 81 | 82 | typedef 83 | EFI_STATUS 84 | (EFIAPI *EFI_SERIAL_GET_CONTROL_BITS) ( 85 | IN struct _SERIAL_IO_INTERFACE *This, 86 | OUT UINT32 *Control 87 | ); 88 | 89 | typedef 90 | EFI_STATUS 91 | (EFIAPI *EFI_SERIAL_WRITE) ( 92 | IN struct _SERIAL_IO_INTERFACE *This, 93 | IN OUT UINTN *BufferSize, 94 | IN VOID *Buffer 95 | ); 96 | 97 | typedef 98 | EFI_STATUS 99 | (EFIAPI *EFI_SERIAL_READ) ( 100 | IN struct _SERIAL_IO_INTERFACE *This, 101 | IN OUT UINTN *BufferSize, 102 | OUT VOID *Buffer 103 | ); 104 | 105 | typedef struct { 106 | UINT32 ControlMask; 107 | 108 | // current Attributes 109 | UINT32 Timeout; 110 | UINT64 BaudRate; 111 | UINT32 ReceiveFifoDepth; 112 | UINT32 DataBits; 113 | UINT32 Parity; 114 | UINT32 StopBits; 115 | } SERIAL_IO_MODE; 116 | 117 | #define SERIAL_IO_INTERFACE_REVISION 0x00010000 118 | 119 | typedef struct _SERIAL_IO_INTERFACE { 120 | UINT32 Revision; 121 | EFI_SERIAL_RESET Reset; 122 | EFI_SERIAL_SET_ATTRIBUTES SetAttributes; 123 | EFI_SERIAL_SET_CONTROL_BITS SetControl; 124 | EFI_SERIAL_GET_CONTROL_BITS GetControl; 125 | EFI_SERIAL_WRITE Write; 126 | EFI_SERIAL_READ Read; 127 | 128 | SERIAL_IO_MODE *Mode; 129 | } SERIAL_IO_INTERFACE; 130 | 131 | #endif 132 | 133 | -------------------------------------------------------------------------------- /gnu-efi/inc/efishellintf.h: -------------------------------------------------------------------------------- 1 | /** @file 2 | SHELL_INTERFACE_PROTOCOL from EDK shell (no spec). 3 | 4 | Shell Interface - additional information (over image_info) provided 5 | to an application started by the shell. 6 | 7 | ConIo provides a file-style interface to the console. 8 | 9 | The shell interface's and data (including ConIo) are only valid during 10 | the applications Entry Point. Once the application returns from it's 11 | entry point the data is freed by the invoking shell. 12 | 13 | Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
14 | This program and the accompanying materials 15 | are licensed and made available under the terms and conditions of the BSD License 16 | which accompanies this distribution. The full text of the license may be found at 17 | http://opensource.org/licenses/bsd-license.php 18 | 19 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 20 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 21 | 22 | **/ 23 | /* 24 | * This is based on ShellPkg/Include/Protocol/EfiShellInterface.h from EDK II. 25 | */ 26 | 27 | #ifndef _SHELLINTERFACE_H_ 28 | #define _SHELLINTERFACE_H_ 29 | 30 | 31 | #define SHELL_INTERFACE_PROTOCOL_GUID \ 32 | { \ 33 | 0x47c7b223, 0xc42a, 0x11d2, {0x8e, 0x57, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b} \ 34 | } 35 | 36 | /// 37 | /// Bit definitions for EFI_SHELL_ARG_INFO 38 | /// 39 | typedef enum { 40 | ARG_NO_ATTRIB = 0x0, 41 | ARG_IS_QUOTED = 1<<0, 42 | ARG_PARTIALLY_QUOTED = 1<<1, 43 | ARG_FIRST_HALF_QUOTED = 1<<2, 44 | ARG_FIRST_CHAR_IS_ESC = 1<<3 45 | } EFI_SHELL_ARG_INFO_TYPES; 46 | 47 | /// 48 | /// Attributes for an argument. 49 | /// 50 | typedef struct _EFI_SHELL_ARG_INFO { 51 | UINT32 Attributes; 52 | } EFI_SHELL_ARG_INFO; 53 | 54 | /// 55 | /// This protocol provides access to additional information about a shell application. 56 | /// 57 | typedef struct { 58 | /// 59 | /// Handle back to original image handle & image information. 60 | /// 61 | EFI_HANDLE ImageHandle; 62 | EFI_LOADED_IMAGE *Info; 63 | 64 | /// 65 | /// Parsed arg list converted more C-like format. 66 | /// 67 | CHAR16 **Argv; 68 | UINTN Argc; 69 | 70 | /// 71 | /// Storage for file redirection args after parsing. 72 | /// 73 | CHAR16 **RedirArgv; 74 | UINTN RedirArgc; 75 | 76 | /// 77 | /// A file style handle for console io. 78 | /// 79 | EFI_FILE *StdIn; 80 | EFI_FILE *StdOut; 81 | EFI_FILE *StdErr; 82 | 83 | /// 84 | /// List of attributes for each argument. 85 | /// 86 | EFI_SHELL_ARG_INFO *ArgInfo; 87 | 88 | /// 89 | /// Whether we are echoing. 90 | /// 91 | BOOLEAN EchoOn; 92 | } EFI_SHELL_INTERFACE; 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /gnu-efi/inc/efishellparm.h: -------------------------------------------------------------------------------- 1 | /** @file 2 | EFI_SHELL_PARAMETERS_PROTOCOL as defined in the UEFI Shell 2.0 specification. 3 | 4 | Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.
5 | This program and the accompanying materials 6 | are licensed and made available under the terms and conditions of the BSD License 7 | which accompanies this distribution. The full text of the license may be found at 8 | http://opensource.org/licenses/bsd-license.php 9 | 10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 | 13 | **/ 14 | /* 15 | * This is based on ShellPkg/Include/Protocol/EfiShellParameters.h from EDK II. 16 | */ 17 | 18 | #ifndef __EFI_SHELL_PARAMETERS_PROTOCOL__ 19 | #define __EFI_SHELL_PARAMETERS_PROTOCOL__ 20 | 21 | 22 | // EDK2's ShellBase.h 23 | typedef VOID *SHELL_FILE_HANDLE; 24 | 25 | #define EFI_SHELL_PARAMETERS_PROTOCOL_GUID \ 26 | { \ 27 | 0x752f3136, 0x4e16, 0x4fdc, { 0xa2, 0x2a, 0xe5, 0xf4, 0x68, 0x12, 0xf4, 0xca } \ 28 | } 29 | 30 | typedef struct _EFI_SHELL_PARAMETERS_PROTOCOL { 31 | /// 32 | /// Points to an Argc-element array of points to NULL-terminated strings containing 33 | /// the command-line parameters. The first entry in the array is always the full file 34 | /// path of the executable. Any quotation marks that were used to preserve 35 | /// whitespace have been removed. 36 | /// 37 | CHAR16 **Argv; 38 | 39 | /// 40 | /// The number of elements in the Argv array. 41 | /// 42 | UINTN Argc; 43 | 44 | /// 45 | /// The file handle for the standard input for this executable. This may be different 46 | /// from the ConInHandle in EFI_SYSTEM_TABLE. 47 | /// 48 | SHELL_FILE_HANDLE StdIn; 49 | 50 | /// 51 | /// The file handle for the standard output for this executable. This may be different 52 | /// from the ConOutHandle in EFI_SYSTEM_TABLE. 53 | /// 54 | SHELL_FILE_HANDLE StdOut; 55 | 56 | /// 57 | /// The file handle for the standard error output for this executable. This may be 58 | /// different from the StdErrHandle in EFI_SYSTEM_TABLE. 59 | /// 60 | SHELL_FILE_HANDLE StdErr; 61 | } EFI_SHELL_PARAMETERS_PROTOCOL; 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /gnu-efi/inc/efistdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef _EFISTDARG_H_ 2 | #define _EFISTDARG_H_ 3 | 4 | /*++ 5 | 6 | Copyright (c) 1998 Intel Corporation 7 | 8 | Module Name: 9 | 10 | devpath.h 11 | 12 | Abstract: 13 | 14 | Defines for parsing the EFI Device Path structures 15 | 16 | 17 | 18 | Revision History 19 | 20 | --*/ 21 | 22 | #ifndef GNU_EFI_USE_EXTERNAL_STDARG 23 | typedef __builtin_va_list va_list; 24 | 25 | # define va_start(v,l) __builtin_va_start(v,l) 26 | # define va_end(v) __builtin_va_end(v) 27 | # define va_arg(v,l) __builtin_va_arg(v,l) 28 | # define va_copy(d,s) __builtin_va_copy(d,s) 29 | #else 30 | # include 31 | #endif 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /gnu-efi/inc/efiui.h: -------------------------------------------------------------------------------- 1 | #ifndef _EFI_UI_H 2 | #define _EFI_UI_H 3 | 4 | /*++ 5 | 6 | Copyright (c) 200 Intel Corporation 7 | 8 | Module Name: 9 | 10 | EfiUi.h 11 | 12 | Abstract: 13 | Protocol used to build User Interface (UI) stuff. 14 | 15 | This protocol is just data. It is a multi dimentional array. 16 | For each string there is an array of UI_STRING_ENTRY. Each string 17 | is for a different language translation of the same string. The list 18 | is terminated by a NULL UiString. There can be any number of 19 | UI_STRING_ENTRY arrays. A NULL array terminates the list. A NULL array 20 | entry contains all zeros. 21 | 22 | Thus the shortest possible EFI_UI_PROTOCOL has three UI_STRING_ENTRY. 23 | The String, it's NULL terminator, and the NULL terminator for the entire 24 | thing. 25 | 26 | 27 | Revision History 28 | 29 | --*/ 30 | 31 | #define EFI_UI_PROTOCOL \ 32 | { 0x32dd7981, 0x2d27, 0x11d4, {0xbc, 0x8b, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81} } 33 | 34 | 35 | typedef enum { 36 | UiDeviceString, 37 | UiVendorString, 38 | UiMaxString 39 | } UI_STRING_TYPE; 40 | 41 | typedef struct { 42 | ISO_639_2 *LangCode; 43 | CHAR16 *UiString; 44 | } UI_STRING_ENTRY; 45 | 46 | #define EFI_UI_VERSION 0x00010000 47 | 48 | typedef struct _UI_INTERFACE { 49 | UINT32 Version; 50 | UI_STRING_ENTRY *Entry; 51 | } UI_INTERFACE; 52 | 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /gnu-efi/inc/ia32/efilibplat.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 1998 Intel Corporation 4 | 5 | Module Name: 6 | 7 | efilibplat.h 8 | 9 | Abstract: 10 | 11 | EFI to compile bindings 12 | 13 | 14 | 15 | 16 | Revision History 17 | 18 | --*/ 19 | 20 | VOID 21 | InitializeLibPlatform ( 22 | IN EFI_HANDLE ImageHandle, 23 | IN EFI_SYSTEM_TABLE *SystemTable 24 | ); 25 | 26 | 27 | -------------------------------------------------------------------------------- /gnu-efi/inc/ia64/efilibplat.h: -------------------------------------------------------------------------------- 1 | #ifndef _EFI_LIB_PLAT_H 2 | #define _EFI_LIB_PLAT_H 3 | /*++ 4 | 5 | Copyright (c) 1998 Intel Corporation 6 | 7 | Module Name: 8 | 9 | efilibplat.h 10 | 11 | Abstract: 12 | 13 | EFI to compile bindings 14 | 15 | 16 | 17 | Revision History 18 | 19 | --*/ 20 | 21 | #include "salproc.h" 22 | 23 | 24 | VOID 25 | InitializeLibPlatform ( 26 | IN EFI_HANDLE ImageHandle, 27 | IN EFI_SYSTEM_TABLE *SystemTable 28 | ); 29 | 30 | VOID 31 | LibInitSalAndPalProc( 32 | OUT PLABEL *SalPlabel, 33 | OUT UINT64 *PalEntry 34 | ); 35 | 36 | EFI_STATUS 37 | LibGetSalIoPortMapping ( 38 | OUT UINT64 *IoPortMapping 39 | ); 40 | 41 | EFI_STATUS 42 | LibGetSalIpiBlock ( 43 | OUT UINT64 *IpiBlock 44 | ); 45 | 46 | EFI_STATUS 47 | LibGetSalWakeupVector ( 48 | OUT UINT64 *WakeVector 49 | ); 50 | 51 | VOID * 52 | LibSearchSalSystemTable ( 53 | IN UINT8 EntryType 54 | ); 55 | 56 | 57 | VOID 58 | LibSalProc ( 59 | IN UINT64 Arg1, 60 | IN UINT64 Arg2, 61 | IN UINT64 Arg3, 62 | IN UINT64 Arg4, 63 | IN UINT64 Arg5, 64 | IN UINT64 Arg6, 65 | IN UINT64 Arg7, 66 | IN UINT64 Arg8, 67 | OUT rArg *Results OPTIONAL 68 | ); 69 | 70 | VOID 71 | LibPalProc ( 72 | IN UINT64 Arg1, 73 | IN UINT64 Arg2, 74 | IN UINT64 Arg3, 75 | IN UINT64 Arg4, 76 | OUT rArg *Results OPTIONAL 77 | ); 78 | 79 | #endif 80 | 81 | -------------------------------------------------------------------------------- /gnu-efi/inc/inc.mak: -------------------------------------------------------------------------------- 1 | 2 | 3 | INC_DEPS = $(INC_DEPS) \ 4 | efi.h \ 5 | efiapi.h \ 6 | efibind.h \ 7 | eficon.h \ 8 | efidebug.h \ 9 | efidef.h \ 10 | efidevp.h \ 11 | efierr.h \ 12 | efifs.h \ 13 | efilib.h \ 14 | efipart.h \ 15 | efipciio.h \ 16 | efiprot.h \ 17 | efipxe.h \ 18 | efivar.h \ 19 | pe.h \ 20 | efiip.h \ 21 | efiudp.h \ 22 | efitcp.h \ 23 | stdarg.h 24 | -------------------------------------------------------------------------------- /gnu-efi/inc/libsmbios.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIB_SMBIOS_H 2 | #define _LIB_SMBIOS_H 3 | /*++ 4 | 5 | Copyright (c) 2000 Intel Corporation 6 | 7 | Module Name: 8 | 9 | LibSmbios.h 10 | 11 | Abstract: 12 | 13 | Lib include for SMBIOS services. Used to get system serial number and GUID 14 | 15 | Revision History 16 | 17 | --*/ 18 | 19 | // 20 | // Define SMBIOS tables. 21 | // 22 | #pragma pack(1) 23 | typedef struct { 24 | UINT8 AnchorString[4]; 25 | UINT8 EntryPointStructureChecksum; 26 | UINT8 EntryPointLength; 27 | UINT8 MajorVersion; 28 | UINT8 MinorVersion; 29 | UINT16 MaxStructureSize; 30 | UINT8 EntryPointRevision; 31 | UINT8 FormattedArea[5]; 32 | UINT8 IntermediateAnchorString[5]; 33 | UINT8 IntermediateChecksum; 34 | UINT16 TableLength; 35 | UINT32 TableAddress; 36 | UINT16 NumberOfSmbiosStructures; 37 | UINT8 SmbiosBcdRevision; 38 | } SMBIOS_STRUCTURE_TABLE; 39 | 40 | // 41 | // Please note that SMBIOS structures can be odd byte aligned since the 42 | // unformated section of each record is a set of arbitrary size strings. 43 | // 44 | 45 | typedef struct { 46 | UINT8 Type; 47 | UINT8 Length; 48 | UINT8 Handle[2]; 49 | } SMBIOS_HEADER; 50 | 51 | typedef UINT8 SMBIOS_STRING; 52 | 53 | typedef struct { 54 | SMBIOS_HEADER Hdr; 55 | SMBIOS_STRING Vendor; 56 | SMBIOS_STRING BiosVersion; 57 | UINT8 BiosSegment[2]; 58 | SMBIOS_STRING BiosReleaseDate; 59 | UINT8 BiosSize; 60 | UINT8 BiosCharacteristics[8]; 61 | } SMBIOS_TYPE0; 62 | 63 | typedef struct { 64 | SMBIOS_HEADER Hdr; 65 | SMBIOS_STRING Manufacturer; 66 | SMBIOS_STRING ProductName; 67 | SMBIOS_STRING Version; 68 | SMBIOS_STRING SerialNumber; 69 | 70 | // 71 | // always byte copy this data to prevent alignment faults! 72 | // 73 | EFI_GUID Uuid; 74 | 75 | UINT8 WakeUpType; 76 | } SMBIOS_TYPE1; 77 | 78 | typedef struct { 79 | SMBIOS_HEADER Hdr; 80 | SMBIOS_STRING Manufacturer; 81 | SMBIOS_STRING ProductName; 82 | SMBIOS_STRING Version; 83 | SMBIOS_STRING SerialNumber; 84 | } SMBIOS_TYPE2; 85 | 86 | typedef struct { 87 | SMBIOS_HEADER Hdr; 88 | SMBIOS_STRING Manufacturer; 89 | UINT8 Type; 90 | SMBIOS_STRING Version; 91 | SMBIOS_STRING SerialNumber; 92 | SMBIOS_STRING AssetTag; 93 | UINT8 BootupState; 94 | UINT8 PowerSupplyState; 95 | UINT8 ThermalState; 96 | UINT8 SecurityStatus; 97 | UINT8 OemDefined[4]; 98 | } SMBIOS_TYPE3; 99 | 100 | typedef struct { 101 | SMBIOS_HEADER Hdr; 102 | UINT8 Socket; 103 | UINT8 ProcessorType; 104 | UINT8 ProcessorFamily; 105 | SMBIOS_STRING ProcessorManufacture; 106 | UINT8 ProcessorId[8]; 107 | SMBIOS_STRING ProcessorVersion; 108 | UINT8 Voltage; 109 | UINT8 ExternalClock[2]; 110 | UINT8 MaxSpeed[2]; 111 | UINT8 CurrentSpeed[2]; 112 | UINT8 Status; 113 | UINT8 ProcessorUpgrade; 114 | UINT8 L1CacheHandle[2]; 115 | UINT8 L2CacheHandle[2]; 116 | UINT8 L3CacheHandle[2]; 117 | } SMBIOS_TYPE4; 118 | 119 | typedef union { 120 | SMBIOS_HEADER *Hdr; 121 | SMBIOS_TYPE0 *Type0; 122 | SMBIOS_TYPE1 *Type1; 123 | SMBIOS_TYPE2 *Type2; 124 | SMBIOS_TYPE3 *Type3; 125 | SMBIOS_TYPE4 *Type4; 126 | UINT8 *Raw; 127 | } SMBIOS_STRUCTURE_POINTER; 128 | #pragma pack() 129 | 130 | 131 | #endif 132 | 133 | -------------------------------------------------------------------------------- /gnu-efi/inc/make.inf: -------------------------------------------------------------------------------- 1 | # 2 | # 3 | # 4 | 5 | [sources] 6 | efi.h 7 | efiapi.h 8 | eficon.h 9 | efidebug.h 10 | efidef.h 11 | efidevp.h 12 | efierr.h 13 | efifs.h 14 | efilib.h 15 | efipart.h 16 | efipciio.h 17 | efiprot.h 18 | efipxebc.h 19 | efistdarg.h 20 | efinet.h 21 | efiip.h 22 | efiudp.h 23 | efitcp.h 24 | 25 | [ia32sources] 26 | efibind.h 27 | pe.h 28 | efilibplat.h 29 | 30 | [ia64sources] 31 | efibind.h 32 | pe.h 33 | efilibplat.h 34 | -------------------------------------------------------------------------------- /gnu-efi/inc/makefile.hdr: -------------------------------------------------------------------------------- 1 | 2 | # 3 | # This is a machine generated file - DO NOT EDIT 4 | # Generated by genmake.exe 5 | # Generated from make.inf 6 | # Copyright (c) 1998 Intel Corporation 7 | # 8 | 9 | INC_DEPS = $(INC_DEPS) \ 10 | $(SDK_INSTALL_DIR)\include\efi\efi.h \ 11 | $(SDK_INSTALL_DIR)\include\efi\efiapi.h \ 12 | $(SDK_INSTALL_DIR)\include\efi\eficon.h \ 13 | $(SDK_INSTALL_DIR)\include\efi\efidebug.h \ 14 | $(SDK_INSTALL_DIR)\include\efi\efidef.h \ 15 | $(SDK_INSTALL_DIR)\include\efi\efidevp.h \ 16 | $(SDK_INSTALL_DIR)\include\efi\efierr.h \ 17 | $(SDK_INSTALL_DIR)\include\efi\efifs.h \ 18 | $(SDK_INSTALL_DIR)\include\efi\efilib.h \ 19 | $(SDK_INSTALL_DIR)\include\efi\efipart.h \ 20 | $(SDK_INSTALL_DIR)\include\efi\efipciio.h \ 21 | $(SDK_INSTALL_DIR)\include\efi\efiprot.h \ 22 | $(SDK_INSTALL_DIR)\include\efi\efipxebc.h \ 23 | $(SDK_INSTALL_DIR)\include\efi\efistdarg.h \ 24 | $(SDK_INSTALL_DIR)\include\efi\efinet.h \ 25 | $(SDK_INSTALL_DIR)\include\efi\efiip.h \ 26 | $(SDK_INSTALL_DIR)\include\efi\efiudp.h \ 27 | $(SDK_INSTALL_DIR)\include\efi\efitcp.h \ 28 | 29 | 30 | !IF "$(PROCESSOR)" == "Ia32" 31 | INC_DEPS = $(INC_DEPS) \ 32 | $(SDK_INSTALL_DIR)\include\efi\Ia32\efibind.h \ 33 | $(SDK_INSTALL_DIR)\include\efi\Ia32\pe.h \ 34 | $(SDK_INSTALL_DIR)\include\efi\Ia32\efilibplat.h \ 35 | 36 | 37 | !ENDIF 38 | 39 | 40 | !IF "$(PROCESSOR)" == "Ia64" 41 | INC_DEPS = $(INC_DEPS) \ 42 | $(SDK_INSTALL_DIR)\include\efi\Ia64\efibind.h \ 43 | $(SDK_INSTALL_DIR)\include\efi\Ia64\pe.h \ 44 | $(SDK_INSTALL_DIR)\include\efi\Ia64\efilibplat.h \ 45 | 46 | 47 | !ENDIF 48 | 49 | -------------------------------------------------------------------------------- /gnu-efi/inc/protocol/adapterdebug.h: -------------------------------------------------------------------------------- 1 | #ifndef _ADAPTER_DEBUG_H 2 | #define _ADAPTER_DEBUG_H 3 | 4 | /*++ 5 | 6 | Copyright (c) 1999 Intel Corporation 7 | 8 | Module Name: 9 | 10 | AdapterDebug.h 11 | 12 | Abstract: 13 | 14 | Protocol to debug the EDD 3.0 enablement of BIOS option ROMs 15 | 16 | 17 | 18 | Revision History 19 | 20 | --*/ 21 | 22 | // {82F86881-282B-11d4-BC7D-0080C73C8881} 23 | #define ADAPTER_DEBUG_PROTOCOL \ 24 | { 0x82f86881, 0x282b, 0x11d4, {0xbc, 0x7d, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81} } 25 | 26 | // 27 | // This protocol points to the BIOS_LEGACY_DRIVE data structure 28 | // see edd.h for more details 29 | // 30 | 31 | #endif 32 | 33 | -------------------------------------------------------------------------------- /gnu-efi/inc/protocol/eficonsplit.h: -------------------------------------------------------------------------------- 1 | #ifndef _EFI_CONFORK_H 2 | #define _EFI_CONFORK_H 3 | /*++ 4 | 5 | Copyright (c) 1999 Intel Corporation 6 | 7 | Module Name: 8 | 9 | Abstract: 10 | 11 | 12 | 13 | Revision History 14 | 15 | --*/ 16 | 17 | 18 | 19 | // 20 | // ConOut Forker Protocol 21 | // 22 | 23 | #define TEXT_OUT_SPLITER_PROTOCOL \ 24 | { 0x56d830a0, 0x7e7a, 0x11d3, {0xbb, 0xa0, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b} } 25 | 26 | #define ERROR_OUT_SPLITER_PROTOCOL \ 27 | { 0xf0ba9039, 0x68f1, 0x425e, {0xaa, 0x7f, 0xd9, 0xaa, 0xf9, 0x1b, 0x82, 0xa1}} 28 | 29 | #define TEXT_IN_SPLITER_PROTOCOL \ 30 | { 0xf9a3c550, 0x7fb5, 0x11d3, {0xbb, 0xa0, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b} } 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /gnu-efi/inc/protocol/intload.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 1999 Intel Corporation 4 | 5 | Module Name: 6 | 7 | intload 8 | 9 | Abstract: 10 | 11 | EFI support for loading internally linked in apps 12 | 13 | 14 | 15 | Revision History 16 | 17 | --*/ 18 | 19 | #ifndef _INTERNAL_LOAD_INCLUDE_ 20 | #define _INTERNAL_LOAD_INCLUDE_ 21 | 22 | // {D65A6B8C-71E5-4df0-A909-F0D2992B5AA9} 23 | #define INTERNAL_SHELL_GUID \ 24 | { 0xd65a6b8c, 0x71e5, 0x4df0, {0xa9, 0x09, 0xf0, 0xd2, 0x99, 0x2b, 0x5a, 0xa9} } 25 | 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /gnu-efi/inc/protocol/legacyboot.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 1999 Intel Corporation 4 | 5 | Module Name: 6 | 7 | legacyboot 8 | 9 | Abstract: 10 | 11 | EFI support for legacy boot 12 | 13 | 14 | 15 | Revision History 16 | 17 | --*/ 18 | 19 | #ifndef _LEGACY_BOOT_INCLUDE_ 20 | #define _LEGACY_BOOT_INCLUDE_ 21 | 22 | #define LEGACY_BOOT_PROTOCOL \ 23 | { 0x376e5eb2, 0x30e4, 0x11d3, { 0xba, 0xe5, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } } 24 | 25 | #pragma pack(1) 26 | 27 | // 28 | // BBS 1.01 (See Appendix A) IPL and BCV Table Entry Data structure. 29 | // Seg:Off pointers have been converted to EFI pointers in this data structure 30 | // This is the structure that also maps to the EFI device path for the boot selection 31 | // 32 | typedef struct { 33 | UINT16 DeviceType; 34 | UINT16 StatusFlag; 35 | UINT32 Reserved; 36 | VOID *BootHandler; // Not an EFI entry point 37 | CHAR8 *DescString; 38 | } BBS_TABLE_ENTRY; 39 | #pragma pack() 40 | 41 | typedef 42 | EFI_STATUS 43 | (EFIAPI *LEGACY_BOOT_CALL) ( 44 | IN EFI_DEVICE_PATH *DevicePath 45 | ); 46 | 47 | 48 | // 49 | // BBS support functions 50 | // PnP Call numbers and BiosSelector hidden in implementation 51 | // 52 | 53 | typedef enum { 54 | IplRelative, 55 | BcvRelative 56 | } BBS_TYPE; 57 | 58 | INTERFACE_DECL(_LEGACY_BOOT_INTERFACE); 59 | 60 | // 61 | // == PnP Function 0x60 then BbsVersion == 0x0101 if this call fails then BbsVersion == 0x0000 62 | // 63 | 64 | // 65 | // == PnP Function 0x61 66 | // 67 | typedef 68 | EFI_STATUS 69 | (EFIAPI *GET_DEVICE_COUNT) ( 70 | IN struct _LEGACY_BOOT_INTERFACE *This, 71 | IN BBS_TYPE *TableType, 72 | OUT UINTN *DeviceCount, 73 | OUT UINTN *MaxCount 74 | ); 75 | 76 | // 77 | // == PnP Function 0x62 78 | // 79 | typedef 80 | EFI_STATUS 81 | (EFIAPI *GET_PRIORITY_AND_TABLE) ( 82 | IN struct _LEGACY_BOOT_INTERFACE *This, 83 | IN BBS_TYPE *TableType, 84 | IN OUT UINTN *PrioritySize, // MaxCount * sizeof(UINT8) 85 | OUT UINTN *Priority, 86 | IN OUT UINTN *TableSize, // MaxCount * sizeof(BBS_TABLE_ENTRY) 87 | OUT BBS_TABLE_ENTRY *TableEntrySize 88 | ); 89 | 90 | // 91 | // == PnP Function 0x63 92 | // 93 | typedef 94 | EFI_STATUS 95 | (EFIAPI *SET_PRIORITY) ( 96 | IN struct _LEGACY_BOOT_INTERFACE *This, 97 | IN BBS_TYPE *TableType, 98 | IN OUT UINTN *PrioritySize, 99 | OUT UINTN *Priority 100 | ); 101 | 102 | typedef struct _LEGACY_BOOT_INTERFACE { 103 | LEGACY_BOOT_CALL BootIt; 104 | 105 | // 106 | // New functions to allow BBS booting to be configured from EFI 107 | // 108 | UINTN BbsVersion; // Currently 0x0101 109 | GET_DEVICE_COUNT GetDeviceCount; 110 | GET_PRIORITY_AND_TABLE GetPriorityAndTable; 111 | SET_PRIORITY SetPriority; 112 | } LEGACY_BOOT_INTERFACE; 113 | 114 | EFI_STATUS 115 | PlInitializeLegacyBoot ( 116 | VOID 117 | ); 118 | 119 | #endif 120 | -------------------------------------------------------------------------------- /gnu-efi/inc/protocol/make.inf: -------------------------------------------------------------------------------- 1 | # 2 | # 3 | # 4 | 5 | [sources] 6 | efivar.h 7 | legacyboot.h 8 | VgaClass.h 9 | intload.h 10 | 11 | [ia32sources] 12 | 13 | [ia64sources] 14 | -------------------------------------------------------------------------------- /gnu-efi/inc/protocol/makefile.hdr: -------------------------------------------------------------------------------- 1 | 2 | # 3 | # This is a machine generated file - DO NOT EDIT 4 | # Generated by genmake.exe 5 | # Generated from make.inf 6 | # Copyright (c) 1998 Intel Corporation 7 | # 8 | 9 | INC_DEPS = $(INC_DEPS) \ 10 | $(SDK_INSTALL_DIR)\include\efi\protocol\efivar.h \ 11 | $(SDK_INSTALL_DIR)\include\efi\protocol\legacyboot.h \ 12 | $(SDK_INSTALL_DIR)\include\efi\protocol\vgaclass.h \ 13 | $(SDK_INSTALL_DIR)\include\efi\protocol\efidbg.h \ 14 | 15 | 16 | !IF "$(PROCESSOR)" == "Ia32" 17 | INC_DEPS = $(INC_DEPS) \ 18 | 19 | 20 | !ENDIF 21 | 22 | 23 | !IF "$(PROCESSOR)" == "Ia64" 24 | INC_DEPS = $(INC_DEPS) \ 25 | $(SDK_INSTALL_DIR)\include\efi\protocol\$(PROCESSOR)\eficontext.h \ 26 | 27 | 28 | !ENDIF 29 | 30 | -------------------------------------------------------------------------------- /gnu-efi/inc/protocol/piflash64.h: -------------------------------------------------------------------------------- 1 | #ifndef _PIFLASH64_H 2 | #define _PIFLASH64_H 3 | 4 | /*++ 5 | 6 | Copyright (c) 1999 Intel Corporation 7 | 8 | Module Name: 9 | 10 | PIflash64.h 11 | 12 | Abstract: 13 | 14 | Iflash64.efi protocol to abstract iflash from 15 | the system. 16 | 17 | Revision History 18 | 19 | --*/ 20 | 21 | // 22 | // Guid that identifies the IFLASH protocol 23 | // 24 | #define IFLASH64_PROTOCOL_PROTOCOL \ 25 | { 0x65cba110, 0x74ab, 0x11d3, 0xbb, 0x89, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 }; 26 | 27 | // 28 | // Unlock FLASH from StartAddress to EndAddress and return a LockKey 29 | // 30 | typedef 31 | EFI_STATUS 32 | (EFIAPI *UNLOCK_FLASH_API)( 33 | IN struct _IFLASH64_PROTOCOL_INTERFACE *This 34 | ); 35 | 36 | // 37 | // Lock the flash represented by the LockKey 38 | // 39 | typedef 40 | EFI_STATUS 41 | (EFIAPI *LOCK_FLASH_API)( 42 | IN struct _IFLASH64_PROTOCOL_INTERFACE *This 43 | ); 44 | 45 | // 46 | // Status callback for a utility like IFLASH64 47 | // 48 | // Token would map to a list like Ted proposed. The utility has no idea what 49 | // happens on the other side. 50 | // ErrorStatus - Level of Error or success. Independent of Token. If you 51 | // don't know the token you will at least know pass or fail. 52 | // String - Optional extra information about the error. Could be used for 53 | // debug or future expansion 54 | // 55 | // Attributes - Options screen attributes for String. Could allow the string to be different colors. 56 | // 57 | typedef 58 | EFI_STATUS 59 | (EFIAPI *UTILITY_PROGRESS_API)( 60 | IN struct _IFLASH64_PROTOCOL_INTERFACE *This, 61 | IN UINTN Token, 62 | IN EFI_STATUS ErrorStatus, 63 | IN CHAR16 *String, OPTIONAL 64 | IN UINTN *Attributes OPTIONAL 65 | ); 66 | 67 | // 68 | // Token Values 69 | // 70 | // IFlash64 Token Codes 71 | #define IFLASH_TOKEN_IFLASHSTART 0xB0 // IFlash64 has started 72 | #define IFLASH_TOKEN_READINGFILE 0xB1 // Reading File 73 | #define IFLASH_TOKEN_INITVPP 0xB2 // Initializing Vpp 74 | #define IFLASH_TOKEN_DISABLEVPP 0x10 // Disable Vpp 75 | #define IFLASH_TOKEN_FLASHUNLOCK 0xB3 // Unlocking FLASH Devices 76 | #define IFLASH_TOKEN_FLASHERASE 0xB4 // Erasing FLASH Devices 77 | #define IFLASH_TOKEN_FLASHPROGRAM 0xB5 // Programming FLASH 78 | #define IFLASH_TOKEN_FLASHVERIFY 0xB6 // Verifying FLASH 79 | #define IFLASH_TOKEN_UPDATESUCCES 0xB7 // FLASH Updage Success! 80 | 81 | #define IFLASH_TOKEN_PROGRESS_READINGFILE 0x11 // % Reading File 82 | #define IFLASH_TOKEN_PROGRESS_FLASHUNLOCK 0x13 // % Unlocking FLASH Devices 83 | #define IFLASH_TOKEN_PROGRESS_FLASHERASE 0x14 // % Erasing FLASH Devices 84 | #define IFLASH_TOKEN_PROGRESS_FLASHPROGRAM 0x15 // % Programming FLASH 85 | #define IFLASH_TOKEN_PROGRESS_FLASHVERIFY 0x16 // % Verifying FLASH 86 | 87 | #define IFLASH_TOKEN_READINGFILE_ER 0xB8 // File Read Error 88 | #define IFLASH_TOKEN_INITVPP_ER 0xB9 // Initialization of IFB Error 89 | #define IFLASH_TOKEN_FLASHUNLOCK_ER 0xBA // FLASH Unlock Error 90 | #define IFLASH_TOKEN_FLASHERASE_ER 0xBB // FLASH Erase Error 91 | #define IFLASH_TOKEN_FLASHVERIFY_ER 0xBC // FLASH Verify Error 92 | #define IFLASH_TOKEN_FLASHPROG_ER 0xBD // FLASH Program Error 93 | 94 | #define IFLASH_TABLE_END 0x00 95 | 96 | // 97 | // If this number changes one of the existing API's has changes 98 | // 99 | #define IFLASH_PI_MAJOR_VERSION 0x01 100 | 101 | // 102 | // This number changes when new APIs or data variables get added to the end 103 | // of the data structure 104 | // 105 | #define IFLASH_PI_MINOR_VERSION 0x01 106 | 107 | typedef struct _IFLASH64_PROTOCOL_INTERFACE { 108 | UINT32 MajorVersion; 109 | UINT32 MinorVersion; 110 | UNLOCK_FLASH_API UnlockFlash; 111 | LOCK_FLASH_API LockFlash; 112 | UTILITY_PROGRESS_API Progress; 113 | 114 | // 115 | // Future expansion goes here 116 | // 117 | 118 | } IFLASH64_PROTOCOL_INTERFACE; 119 | 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /gnu-efi/inc/protocol/readme.txt: -------------------------------------------------------------------------------- 1 | The protocol directory contains non Architectural 2 | Protocols that span the FW, Platform, or application 3 | space. -------------------------------------------------------------------------------- /gnu-efi/inc/protocol/vgaclass.h: -------------------------------------------------------------------------------- 1 | #ifndef _VGA_CLASS_H 2 | #define _VGA_CLASS_H 3 | 4 | /*++ 5 | 6 | Copyright (c) 1999 Intel Corporation 7 | 8 | Module Name: 9 | 10 | VgaClass.h 11 | 12 | Abstract: 13 | 14 | Vga Mini port binding to Vga Class protocol 15 | 16 | 17 | 18 | Revision History 19 | 20 | --*/ 21 | 22 | // 23 | // VGA Device Structure 24 | // 25 | 26 | // {0E3D6310-6FE4-11d3-BB81-0080C73C8881} 27 | #define VGA_CLASS_DRIVER_PROTOCOL \ 28 | { 0xe3d6310, 0x6fe4, 0x11d3, {0xbb, 0x81, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81} } 29 | 30 | typedef 31 | EFI_STATUS 32 | (* INIT_VGA_CARD) ( 33 | IN UINTN VgaMode, 34 | IN VOID *Context 35 | ); 36 | 37 | typedef struct { 38 | UINTN MaxColumns; 39 | UINTN MaxRows; 40 | } MAX_CONSOLE_GEOMETRY; 41 | 42 | #define VGA_CON_OUT_DEV_SIGNATURE EFI_SIGNATURE_32('c','v','g','a') 43 | typedef struct { 44 | UINTN Signature; 45 | 46 | EFI_HANDLE Handle; 47 | SIMPLE_TEXT_OUTPUT_INTERFACE ConOut; 48 | SIMPLE_TEXT_OUTPUT_MODE ConOutMode; 49 | EFI_DEVICE_PATH *DevicePath; 50 | 51 | UINT8 *Buffer; 52 | EFI_DEVICE_IO_INTERFACE *DeviceIo; 53 | 54 | // 55 | // Video Card Context 56 | // 57 | INIT_VGA_CARD InitVgaCard; 58 | VOID *VgaCardContext; 59 | MAX_CONSOLE_GEOMETRY *Geometry; 60 | // 61 | // Video buffer normally 0xb8000 62 | // 63 | UINT64 VideoBuffer; 64 | 65 | // 66 | // Clear Screen & Default Attribute 67 | // 68 | UINT32 Attribute; 69 | 70 | // 71 | // -1 means search for active VGA device 72 | // 73 | EFI_PCI_ADDRESS_UNION Pci; 74 | } VGA_CON_OUT_DEV; 75 | 76 | #define VGA_CON_OUT_DEV_FROM_THIS(a) CR(a, VGA_CON_OUT_DEV, ConOut, VGA_CON_OUT_DEV_SIGNATURE) 77 | 78 | // 79 | // Vga Class Driver Protocol. 80 | // GUID defined in EFI Lib 81 | // 82 | 83 | typedef 84 | EFI_STATUS 85 | (EFIAPI *INSTALL_VGA_DRIVER) ( 86 | IN VGA_CON_OUT_DEV *ConOutDev 87 | ); 88 | 89 | typedef struct { 90 | UINT32 Version; 91 | INSTALL_VGA_DRIVER InstallGenericVgaDriver; 92 | } INSTALL_VGA_DRIVER_INTERFACE; 93 | 94 | #endif 95 | 96 | -------------------------------------------------------------------------------- /gnu-efi/inc/romload.h: -------------------------------------------------------------------------------- 1 | #ifndef _EFI_ROMLOAD_H 2 | #define _EFI_ROMLOAD_H 3 | 4 | #define ROM_SIGNATURE 0xaa55 5 | #define PCIDS_SIGNATURE "PCIR" 6 | #pragma pack(push) 7 | #pragma pack(1) 8 | typedef struct 9 | { 10 | UINT8 Pcids_Sig[4]; 11 | UINT16 VendId; 12 | UINT16 DevId; 13 | UINT16 Vpd_Off; 14 | UINT16 Size; 15 | UINT8 Rev; 16 | UINT8 Class_Code[3]; 17 | UINT16 Image_Len; 18 | UINT16 Rev_Lvl; 19 | UINT8 Code_Type; 20 | UINT8 Indi; 21 | UINT16 Rsvd; 22 | }PciDataStructure; 23 | typedef struct 24 | { 25 | UINT16 Size; 26 | UINT32 Header_Sig; 27 | UINT16 SubSystem; 28 | UINT16 MachineType; 29 | UINT8 Resvd[10]; 30 | UINT16 EfiOffset; 31 | }ArchData; 32 | typedef struct 33 | { 34 | UINT16 Rom_Sig; 35 | ArchData Arch_Data; 36 | UINT16 Pcids_Off; 37 | UINT8 resvd[38]; 38 | }RomHeader; 39 | #pragma pack(pop) 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /gnu-efi/inc/x86_64/efilibplat.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 1998 Intel Corporation 4 | 5 | Module Name: 6 | 7 | efilibplat.h 8 | 9 | Abstract: 10 | 11 | EFI to compile bindings 12 | 13 | 14 | 15 | 16 | Revision History 17 | 18 | --*/ 19 | 20 | VOID 21 | InitializeLibPlatform ( 22 | IN EFI_HANDLE ImageHandle, 23 | IN EFI_SYSTEM_TABLE *SystemTable 24 | ); 25 | 26 | 27 | -------------------------------------------------------------------------------- /gnu-efi/lib/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 1999-2001 Hewlett-Packard Co. 3 | # Contributed by David Mosberger 4 | # Contributed by Stephane Eranian 5 | # 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # * Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # * Redistributions in binary form must reproduce the above 15 | # copyright notice, this list of conditions and the following 16 | # disclaimer in the documentation and/or other materials 17 | # provided with the distribution. 18 | # * Neither the name of Hewlett-Packard Co. nor the names of its 19 | # contributors may be used to endorse or promote products derived 20 | # from this software without specific prior written permission. 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 24 | # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 27 | # BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 28 | # OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 32 | # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 33 | # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 | # SUCH DAMAGE. 35 | # 36 | 37 | SRCDIR = . 38 | 39 | VPATH = $(SRCDIR) 40 | 41 | include $(SRCDIR)/../Make.defaults 42 | 43 | TOPDIR = $(SRCDIR)/.. 44 | 45 | CDIR = $(TOPDIR)/.. 46 | FILES = boxdraw smbios console crc data debug dpath \ 47 | error event guid hand hw init lock \ 48 | misc print sread str cmdline \ 49 | runtime/rtlock runtime/efirtlib runtime/rtstr runtime/vm runtime/rtdata \ 50 | $(ARCH)/initplat $(ARCH)/math 51 | 52 | ifeq ($(ARCH),ia64) 53 | FILES += $(ARCH)/salpal $(ARCH)/palproc 54 | endif 55 | 56 | ifeq ($(ARCH),x86_64) 57 | FILES += $(ARCH)/callwrap $(ARCH)/efi_stub 58 | endif 59 | 60 | ifeq ($(ARCH),arm) 61 | FILES += $(ARCH)/lib1funcs $(ARCH)/div64 62 | endif 63 | 64 | OBJS = $(FILES:%=%.o) 65 | 66 | SUBDIRS = ia32 x86_64 ia64 aarch64 arm runtime 67 | 68 | LIBDIRINSTALL = $(INSTALLROOT)$(LIBDIR) 69 | 70 | all: libsubdirs libefi.a 71 | 72 | .PHONY: libsubdirs 73 | libsubdirs: 74 | for sdir in $(SUBDIRS); do mkdir -p $$sdir; done 75 | 76 | libefi.a: $(patsubst %,libefi.a(%),$(OBJS)) 77 | 78 | clean: 79 | rm -f libefi.a *~ $(OBJS) */*.o 80 | 81 | $(LIBDIRINSTALL): 82 | mkdir -p $@ 83 | 84 | $(LIBDIRINSTALL)/libefi.a: libefi.a | $(LIBDIRINSTALL) 85 | $(INSTALL) -m 644 $< $(dir $@) 86 | 87 | install: $(LIBDIRINSTALL)/libefi.a 88 | 89 | include $(SRCDIR)/../Make.rules 90 | 91 | .PHONY: libsubdirs 92 | -------------------------------------------------------------------------------- /gnu-efi/lib/aarch64/efi_stub.S: -------------------------------------------------------------------------------- 1 | /* This stub is a stub to make the build happy */ 2 | -------------------------------------------------------------------------------- /gnu-efi/lib/aarch64/initplat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * aarch64/initplat.c 3 | * 4 | * Copright (C) 2014 Linaro Ltd. 5 | * Author: Ard Biesheuvel 6 | * 7 | * This program is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU General Public License as published by the Free 9 | * Software Foundation; either version 2 of the License, or (at your option) 10 | * any later version. 11 | */ 12 | 13 | #include "lib.h" 14 | 15 | VOID 16 | InitializeLibPlatform ( 17 | IN EFI_HANDLE ImageHandle, 18 | IN EFI_SYSTEM_TABLE *SystemTable 19 | ) 20 | 21 | { 22 | } 23 | 24 | /* 25 | * Calls to these functions may be emitted implicitly by GCC even when 26 | * -ffreestanding is in effect. 27 | */ 28 | void *memset(void *s, int c, __SIZE_TYPE__ n) 29 | { 30 | unsigned char *p = s; 31 | 32 | while (n--) 33 | *p++ = c; 34 | 35 | return s; 36 | } 37 | 38 | void *memcpy(void *dest, const void *src, __SIZE_TYPE__ n) 39 | { 40 | unsigned char *p = dest, *q = src; 41 | 42 | while (n--) 43 | *p++ = *q++; 44 | 45 | return dest; 46 | } 47 | -------------------------------------------------------------------------------- /gnu-efi/lib/aarch64/math.c: -------------------------------------------------------------------------------- 1 | /* 2 | * crt0-efi-aarch64.S - PE/COFF header for Aarch64 EFI applications 3 | * 4 | * Copright (C) 2014 Linaro Ltd. 5 | * Author: Ard Biesheuvel 6 | * 7 | * This program is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU General Public License as published by the Free 9 | * Software Foundation; either version 2 of the License, or (at your option) 10 | * any later version. 11 | */ 12 | 13 | #include "lib.h" 14 | 15 | UINT64 16 | LShiftU64 ( 17 | IN UINT64 Operand, 18 | IN UINTN Count 19 | ) 20 | // Left shift 64bit by 32bit and get a 64bit result 21 | { 22 | return Operand << Count; 23 | } 24 | 25 | UINT64 26 | RShiftU64 ( 27 | IN UINT64 Operand, 28 | IN UINTN Count 29 | ) 30 | // Right shift 64bit by 32bit and get a 64bit result 31 | { 32 | return Operand >> Count; 33 | } 34 | 35 | 36 | UINT64 37 | MultU64x32 ( 38 | IN UINT64 Multiplicand, 39 | IN UINTN Multiplier 40 | ) 41 | // Multiple 64bit by 32bit and get a 64bit result 42 | { 43 | return Multiplicand * Multiplier; 44 | } 45 | 46 | UINT64 47 | DivU64x32 ( 48 | IN UINT64 Dividend, 49 | IN UINTN Divisor, 50 | OUT UINTN *Remainder OPTIONAL 51 | ) 52 | // divide 64bit by 32bit and get a 64bit result 53 | // N.B. only works for 31bit divisors!! 54 | { 55 | if (Remainder) 56 | *Remainder = Dividend % Divisor; 57 | return Dividend / Divisor; 58 | } 59 | -------------------------------------------------------------------------------- /gnu-efi/lib/arm/efi_stub.S: -------------------------------------------------------------------------------- 1 | /* This stub is a stub to make the build happy */ 2 | -------------------------------------------------------------------------------- /gnu-efi/lib/arm/initplat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * aarch64/initplat.c 3 | * 4 | * Copright (C) 2014 Linaro Ltd. 5 | * Author: Ard Biesheuvel 6 | * 7 | * This program is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU General Public License as published by the Free 9 | * Software Foundation; either version 2 of the License, or (at your option) 10 | * any later version. 11 | */ 12 | 13 | #include "lib.h" 14 | 15 | VOID 16 | InitializeLibPlatform ( 17 | IN EFI_HANDLE ImageHandle, 18 | IN EFI_SYSTEM_TABLE *SystemTable 19 | ) 20 | 21 | { 22 | } 23 | 24 | /* 25 | * Calls to these functions may be emitted implicitly by GCC even when 26 | * -ffreestanding is in effect. 27 | */ 28 | void *memset(void *s, int c, __SIZE_TYPE__ n) 29 | { 30 | unsigned char *p = s; 31 | 32 | while (n--) 33 | *p++ = c; 34 | 35 | return s; 36 | } 37 | 38 | void *memcpy(void *dest, const void *src, __SIZE_TYPE__ n) 39 | { 40 | unsigned char *p = dest; 41 | unsigned char const *q = src; 42 | 43 | while (n--) 44 | *p++ = *q++; 45 | 46 | return dest; 47 | } 48 | 49 | void __div0(void) 50 | { 51 | // TODO handle divide by zero fault 52 | while (1); 53 | } 54 | 55 | -------------------------------------------------------------------------------- /gnu-efi/lib/arm/math.c: -------------------------------------------------------------------------------- 1 | /* 2 | * arm/math.c - math routines for ARM 3 | * 4 | * Copright (C) 2014 Linaro Ltd. 5 | * Author: Ard Biesheuvel 6 | * 7 | * This program is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU General Public License as published by the Free 9 | * Software Foundation; either version 2 of the License, or (at your option) 10 | * any later version. 11 | */ 12 | 13 | #include "lib.h" 14 | 15 | UINT64 16 | LShiftU64 ( 17 | IN UINT64 Operand, 18 | IN UINTN Count 19 | ) 20 | // Left shift 64bit by 32bit and get a 64bit result 21 | { 22 | return Operand << Count; 23 | } 24 | 25 | UINT64 26 | RShiftU64 ( 27 | IN UINT64 Operand, 28 | IN UINTN Count 29 | ) 30 | // Right shift 64bit by 32bit and get a 64bit result 31 | { 32 | return Operand >> Count; 33 | } 34 | 35 | 36 | UINT64 37 | MultU64x32 ( 38 | IN UINT64 Multiplicand, 39 | IN UINTN Multiplier 40 | ) 41 | // Multiple 64bit by 32bit and get a 64bit result 42 | { 43 | return Multiplicand * Multiplier; 44 | } 45 | -------------------------------------------------------------------------------- /gnu-efi/lib/console.c: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 1998 Intel Corporation 4 | 5 | Module Name: 6 | 7 | console.c 8 | 9 | Abstract: 10 | 11 | 12 | 13 | 14 | Revision History 15 | 16 | --*/ 17 | 18 | #include "lib.h" 19 | 20 | 21 | 22 | VOID 23 | Output ( 24 | IN CHAR16 *Str 25 | ) 26 | // Write a string to the console at the current cursor location 27 | { 28 | uefi_call_wrapper(ST->ConOut->OutputString, 2, ST->ConOut, Str); 29 | } 30 | 31 | 32 | VOID 33 | Input ( 34 | IN CHAR16 *Prompt OPTIONAL, 35 | OUT CHAR16 *InStr, 36 | IN UINTN StrLen 37 | ) 38 | // Input a string at the current cursor location, for StrLen 39 | { 40 | IInput ( 41 | ST->ConOut, 42 | ST->ConIn, 43 | Prompt, 44 | InStr, 45 | StrLen 46 | ); 47 | } 48 | 49 | VOID 50 | IInput ( 51 | IN SIMPLE_TEXT_OUTPUT_INTERFACE *ConOut, 52 | IN SIMPLE_INPUT_INTERFACE *ConIn, 53 | IN CHAR16 *Prompt OPTIONAL, 54 | OUT CHAR16 *InStr, 55 | IN UINTN StrLen 56 | ) 57 | // Input a string at the current cursor location, for StrLen 58 | { 59 | EFI_INPUT_KEY Key; 60 | EFI_STATUS Status; 61 | UINTN Len; 62 | 63 | if (Prompt) { 64 | ConOut->OutputString (ConOut, Prompt); 65 | } 66 | 67 | Len = 0; 68 | for (; ;) { 69 | WaitForSingleEvent (ConIn->WaitForKey, 0); 70 | 71 | Status = uefi_call_wrapper(ConIn->ReadKeyStroke, 2, ConIn, &Key); 72 | if (EFI_ERROR(Status)) { 73 | DEBUG((D_ERROR, "Input: error return from ReadKey %x\n", Status)); 74 | break; 75 | } 76 | 77 | if (Key.UnicodeChar == '\n' || 78 | Key.UnicodeChar == '\r') { 79 | break; 80 | } 81 | 82 | if (Key.UnicodeChar == '\b') { 83 | if (Len) { 84 | uefi_call_wrapper(ConOut->OutputString, 2, ConOut, L"\b \b"); 85 | Len -= 1; 86 | } 87 | continue; 88 | } 89 | 90 | if (Key.UnicodeChar >= ' ') { 91 | if (Len < StrLen-1) { 92 | InStr[Len] = Key.UnicodeChar; 93 | 94 | InStr[Len+1] = 0; 95 | uefi_call_wrapper(ConOut->OutputString, 2, ConOut, &InStr[Len]); 96 | 97 | Len += 1; 98 | } 99 | continue; 100 | } 101 | } 102 | 103 | InStr[Len] = 0; 104 | } 105 | -------------------------------------------------------------------------------- /gnu-efi/lib/debug.c: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 1998 Intel Corporation 4 | 5 | Module Name: 6 | 7 | debug.c 8 | 9 | Abstract: 10 | 11 | Debug library functions 12 | 13 | 14 | 15 | Revision History 16 | 17 | --*/ 18 | 19 | #include "lib.h" 20 | 21 | 22 | 23 | // 24 | // Declare runtime functions 25 | // 26 | 27 | // 28 | // 29 | // 30 | 31 | INTN 32 | DbgAssert ( 33 | IN CHAR8 *FileName, 34 | IN INTN LineNo, 35 | IN CHAR8 *Description 36 | ) 37 | { 38 | DbgPrint (D_ERROR, (CHAR8 *)"%EASSERT FAILED: %a(%d): %a%N\n", FileName, LineNo, Description); 39 | 40 | BREAKPOINT(); 41 | return 0; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /gnu-efi/lib/error.c: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 1998 Intel Corporation 4 | 5 | Module Name: 6 | 7 | error.c 8 | 9 | Abstract: 10 | 11 | 12 | 13 | 14 | Revision History 15 | 16 | --*/ 17 | 18 | #include "lib.h" 19 | 20 | 21 | struct { 22 | EFI_STATUS Code; 23 | WCHAR *Desc; 24 | } ErrorCodeTable[] = { 25 | { EFI_SUCCESS, L"Success"}, 26 | { EFI_LOAD_ERROR, L"Load Error"}, 27 | { EFI_INVALID_PARAMETER, L"Invalid Parameter"}, 28 | { EFI_UNSUPPORTED, L"Unsupported"}, 29 | { EFI_BAD_BUFFER_SIZE, L"Bad Buffer Size"}, 30 | { EFI_BUFFER_TOO_SMALL, L"Buffer Too Small"}, 31 | { EFI_NOT_READY, L"Not Ready"}, 32 | { EFI_DEVICE_ERROR, L"Device Error"}, 33 | { EFI_WRITE_PROTECTED, L"Write Protected"}, 34 | { EFI_OUT_OF_RESOURCES, L"Out of Resources"}, 35 | { EFI_VOLUME_CORRUPTED, L"Volume Corrupt"}, 36 | { EFI_VOLUME_FULL, L"Volume Full"}, 37 | { EFI_NO_MEDIA, L"No Media"}, 38 | { EFI_MEDIA_CHANGED, L"Media changed"}, 39 | { EFI_NOT_FOUND, L"Not Found"}, 40 | { EFI_ACCESS_DENIED, L"Access Denied"}, 41 | { EFI_NO_RESPONSE, L"No Response"}, 42 | { EFI_NO_MAPPING, L"No mapping"}, 43 | { EFI_TIMEOUT, L"Time out"}, 44 | { EFI_NOT_STARTED, L"Not started"}, 45 | { EFI_ALREADY_STARTED, L"Already started"}, 46 | { EFI_ABORTED, L"Aborted"}, 47 | { EFI_ICMP_ERROR, L"ICMP Error"}, 48 | { EFI_TFTP_ERROR, L"TFTP Error"}, 49 | { EFI_PROTOCOL_ERROR, L"Protocol Error"}, 50 | 51 | // warnings 52 | { EFI_WARN_UNKOWN_GLYPH, L"Warning Unknown Glyph"}, 53 | { EFI_WARN_DELETE_FAILURE, L"Warning Delete Failure"}, 54 | { EFI_WARN_WRITE_FAILURE, L"Warning Write Failure"}, 55 | { EFI_WARN_BUFFER_TOO_SMALL, L"Warning Buffer Too Small"}, 56 | { 0, NULL} 57 | } ; 58 | 59 | 60 | VOID 61 | StatusToString ( 62 | OUT CHAR16 *Buffer, 63 | IN EFI_STATUS Status 64 | ) 65 | { 66 | UINTN Index; 67 | 68 | for (Index = 0; ErrorCodeTable[Index].Desc; Index +=1) { 69 | if (ErrorCodeTable[Index].Code == Status) { 70 | StrCpy (Buffer, ErrorCodeTable[Index].Desc); 71 | return; 72 | } 73 | } 74 | 75 | SPrint (Buffer, 0, L"%X", Status); 76 | } 77 | -------------------------------------------------------------------------------- /gnu-efi/lib/event.c: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 1998 Intel Corporation 4 | 5 | Module Name: 6 | 7 | event.c 8 | 9 | Abstract: 10 | 11 | 12 | 13 | 14 | Revision History 15 | 16 | --*/ 17 | 18 | #include "lib.h" 19 | 20 | 21 | EFI_EVENT 22 | LibCreateProtocolNotifyEvent ( 23 | IN EFI_GUID *ProtocolGuid, 24 | IN EFI_TPL NotifyTpl, 25 | IN EFI_EVENT_NOTIFY NotifyFunction, 26 | IN VOID *NotifyContext, 27 | OUT VOID *Registration 28 | ) 29 | { 30 | EFI_STATUS Status; 31 | EFI_EVENT Event; 32 | 33 | // 34 | // Create the event 35 | // 36 | 37 | Status = uefi_call_wrapper( 38 | BS->CreateEvent, 39 | 5, 40 | EVT_NOTIFY_SIGNAL, 41 | NotifyTpl, 42 | NotifyFunction, 43 | NotifyContext, 44 | &Event 45 | ); 46 | if ( EFI_ERROR( Status ) ) return NULL ; 47 | ASSERT (!EFI_ERROR(Status)); 48 | 49 | // 50 | // Register for protocol notifactions on this event 51 | // 52 | 53 | Status = uefi_call_wrapper( 54 | BS->RegisterProtocolNotify, 55 | 3, 56 | ProtocolGuid, 57 | Event, 58 | Registration 59 | ); 60 | if ( EFI_ERROR( Status ) ) return NULL ; 61 | ASSERT (!EFI_ERROR(Status)); 62 | 63 | // 64 | // Kick the event so we will perform an initial pass of 65 | // current installed drivers 66 | // 67 | 68 | uefi_call_wrapper(BS->SignalEvent, 1, Event); 69 | return Event; 70 | } 71 | 72 | 73 | EFI_STATUS 74 | WaitForSingleEvent ( 75 | IN EFI_EVENT Event, 76 | IN UINT64 Timeout OPTIONAL 77 | ) 78 | { 79 | EFI_STATUS Status; 80 | UINTN Index; 81 | EFI_EVENT TimerEvent; 82 | EFI_EVENT WaitList[2]; 83 | 84 | if (Timeout) { 85 | // 86 | // Create a timer event 87 | // 88 | 89 | Status = uefi_call_wrapper(BS->CreateEvent, 5, EVT_TIMER, 0, NULL, NULL, &TimerEvent); 90 | if (!EFI_ERROR(Status)) { 91 | 92 | // 93 | // Set the timer event 94 | // 95 | 96 | uefi_call_wrapper(BS->SetTimer, 3, TimerEvent, TimerRelative, Timeout); 97 | 98 | // 99 | // Wait for the original event or the timer 100 | // 101 | 102 | WaitList[0] = Event; 103 | WaitList[1] = TimerEvent; 104 | Status = uefi_call_wrapper(BS->WaitForEvent, 3, 2, WaitList, &Index); 105 | uefi_call_wrapper(BS->CloseEvent, 1, TimerEvent); 106 | 107 | // 108 | // If the timer expired, change the return to timed out 109 | // 110 | 111 | if (!EFI_ERROR(Status) && Index == 1) { 112 | Status = EFI_TIMEOUT; 113 | } 114 | } 115 | 116 | } else { 117 | 118 | // 119 | // No timeout... just wait on the event 120 | // 121 | 122 | Status = uefi_call_wrapper(BS->WaitForEvent, 3, 1, &Event, &Index); 123 | ASSERT (!EFI_ERROR(Status)); 124 | ASSERT (Index == 0); 125 | } 126 | 127 | return Status; 128 | } 129 | 130 | VOID 131 | WaitForEventWithTimeout ( 132 | IN EFI_EVENT Event, 133 | IN UINTN Timeout, 134 | IN UINTN Row, 135 | IN UINTN Column, 136 | IN CHAR16 *String, 137 | IN EFI_INPUT_KEY TimeoutKey, 138 | OUT EFI_INPUT_KEY *Key 139 | ) 140 | { 141 | EFI_STATUS Status; 142 | 143 | do { 144 | PrintAt (Column, Row, String, Timeout); 145 | Status = WaitForSingleEvent (Event, 10000000); 146 | if (Status == EFI_SUCCESS) { 147 | if (!EFI_ERROR(uefi_call_wrapper(ST->ConIn->ReadKeyStroke, 2, ST->ConIn, Key))) { 148 | return; 149 | } 150 | } 151 | } while (Timeout > 0); 152 | *Key = TimeoutKey; 153 | } 154 | 155 | -------------------------------------------------------------------------------- /gnu-efi/lib/hw.c: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 1998 Intel Corporation 4 | 5 | Module Name: 6 | 7 | hw.c 8 | 9 | Abstract: 10 | 11 | Debug library functions for Hardware IO access 12 | 13 | 14 | 15 | Revision History 16 | 17 | --*/ 18 | 19 | #include "lib.h" 20 | 21 | 22 | EFI_STATUS 23 | InitializeGlobalIoDevice ( 24 | IN EFI_DEVICE_PATH *DevicePath, 25 | IN EFI_GUID *Protocol, 26 | IN CHAR8 *ErrorStr, 27 | OUT EFI_DEVICE_IO_INTERFACE **GlobalIoFncs 28 | ) 29 | /*++ 30 | 31 | Routine Description: 32 | 33 | Check to see if DevicePath exists for a given Protocol. Return Error if it 34 | exists. Return GlobalIoFuncs set match the DevicePath 35 | 36 | Arguments: 37 | 38 | DevicePath - to operate on 39 | Protocol - to check the DevicePath against 40 | ErrorStr - ASCII string to display on error 41 | GlobalIoFncs - Returned with DeviceIoProtocol for the DevicePath 42 | 43 | Returns: 44 | 45 | Pass or Fail based on wether GlobalIoFncs where found 46 | 47 | --*/ 48 | { 49 | EFI_STATUS Status; 50 | EFI_HANDLE Handle; 51 | 52 | // 53 | // Check to see if this device path already has Protocol on it. 54 | // if so we are loading recursivly and should exit with an error 55 | // 56 | Status = uefi_call_wrapper(BS->LocateDevicePath, 3, Protocol, &DevicePath, &Handle); 57 | if (!EFI_ERROR(Status)) { 58 | DEBUG ((D_INIT, "Device Already Loaded for %a device\n", ErrorStr)); 59 | return EFI_LOAD_ERROR; 60 | } 61 | 62 | Status = uefi_call_wrapper(BS->LocateDevicePath, 3, &DeviceIoProtocol, &DevicePath, &Handle); 63 | if (!EFI_ERROR(Status)) { 64 | Status = uefi_call_wrapper(BS->HandleProtocol, 3, Handle, &DeviceIoProtocol, (VOID*)GlobalIoFncs); 65 | } 66 | 67 | ASSERT (!EFI_ERROR(Status)); 68 | return Status; 69 | } 70 | 71 | UINT32 72 | ReadPort ( 73 | IN EFI_DEVICE_IO_INTERFACE *GlobalIoFncs, 74 | IN EFI_IO_WIDTH Width, 75 | IN UINTN Port 76 | ) 77 | { 78 | UINT32 Data; 79 | EFI_STATUS Status; 80 | 81 | Status = uefi_call_wrapper(GlobalIoFncs->Io.Read, 5, GlobalIoFncs, Width, (UINT64)Port, 1, &Data); 82 | ASSERT(!EFI_ERROR(Status)); 83 | return Data; 84 | } 85 | 86 | UINT32 87 | WritePort ( 88 | IN EFI_DEVICE_IO_INTERFACE *GlobalIoFncs, 89 | IN EFI_IO_WIDTH Width, 90 | IN UINTN Port, 91 | IN UINTN Data 92 | ) 93 | { 94 | EFI_STATUS Status; 95 | 96 | Status = uefi_call_wrapper(GlobalIoFncs->Io.Write, 5, GlobalIoFncs, Width, (UINT64)Port, 1, &Data); 97 | ASSERT(!EFI_ERROR(Status)); 98 | return (UINT32)Data; 99 | } 100 | 101 | UINT32 102 | ReadPciConfig ( 103 | IN EFI_DEVICE_IO_INTERFACE *GlobalIoFncs, 104 | IN EFI_IO_WIDTH Width, 105 | IN UINTN Address 106 | ) 107 | { 108 | UINT32 Data; 109 | EFI_STATUS Status; 110 | 111 | Status = uefi_call_wrapper(GlobalIoFncs->Pci.Read, 5, GlobalIoFncs, Width, (UINT64)Address, 1, &Data); 112 | ASSERT(!EFI_ERROR(Status)); 113 | return Data; 114 | } 115 | 116 | UINT32 117 | WritePciConfig ( 118 | IN EFI_DEVICE_IO_INTERFACE *GlobalIoFncs, 119 | IN EFI_IO_WIDTH Width, 120 | IN UINTN Address, 121 | IN UINTN Data 122 | ) 123 | { 124 | EFI_STATUS Status; 125 | 126 | Status = uefi_call_wrapper(GlobalIoFncs->Pci.Write, 5, GlobalIoFncs, Width, (UINT64)Address, 1, &Data); 127 | ASSERT(!EFI_ERROR(Status)); 128 | return (UINT32)Data; 129 | } 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /gnu-efi/lib/ia32/efi_stub.S: -------------------------------------------------------------------------------- 1 | /* This stub is a stub to make the build happy */ 2 | -------------------------------------------------------------------------------- /gnu-efi/lib/ia32/initplat.c: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 1998 Intel Corporation 4 | 5 | Module Name: 6 | 7 | initplat.c 8 | 9 | Abstract: 10 | 11 | 12 | 13 | 14 | Revision History 15 | 16 | --*/ 17 | 18 | #include "lib.h" 19 | 20 | VOID 21 | InitializeLibPlatform ( 22 | IN EFI_HANDLE ImageHandle, 23 | IN EFI_SYSTEM_TABLE *SystemTable 24 | ) 25 | 26 | { 27 | } 28 | 29 | -------------------------------------------------------------------------------- /gnu-efi/lib/ia32/math.c: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 1998 Intel Corporation 4 | 5 | Module Name: 6 | 7 | math.c 8 | 9 | Abstract: 10 | 11 | 12 | 13 | 14 | Revision History 15 | 16 | --*/ 17 | 18 | #include "lib.h" 19 | 20 | 21 | // 22 | // Declare runtime functions 23 | // 24 | 25 | #ifdef RUNTIME_CODE 26 | #ifndef __GNUC__ 27 | #pragma RUNTIME_CODE(LShiftU64) 28 | #pragma RUNTIME_CODE(RShiftU64) 29 | #pragma RUNTIME_CODE(MultU64x32) 30 | #pragma RUNTIME_CODE(DivU64x32) 31 | #endif 32 | #endif 33 | 34 | // 35 | // 36 | // 37 | 38 | UINT64 39 | LShiftU64 ( 40 | IN UINT64 Operand, 41 | IN UINTN Count 42 | ) 43 | // Left shift 64bit by 32bit and get a 64bit result 44 | { 45 | #ifdef __GNUC__ 46 | return Operand << Count; 47 | #else 48 | UINT64 Result; 49 | _asm { 50 | mov eax, dword ptr Operand[0] 51 | mov edx, dword ptr Operand[4] 52 | mov ecx, Count 53 | and ecx, 63 54 | 55 | shld edx, eax, cl 56 | shl eax, cl 57 | 58 | cmp ecx, 32 59 | jc short ls10 60 | 61 | mov edx, eax 62 | xor eax, eax 63 | 64 | ls10: 65 | mov dword ptr Result[0], eax 66 | mov dword ptr Result[4], edx 67 | } 68 | 69 | return Result; 70 | #endif 71 | } 72 | 73 | UINT64 74 | RShiftU64 ( 75 | IN UINT64 Operand, 76 | IN UINTN Count 77 | ) 78 | // Right shift 64bit by 32bit and get a 64bit result 79 | { 80 | #ifdef __GNUC__ 81 | return Operand >> Count; 82 | #else 83 | UINT64 Result; 84 | _asm { 85 | mov eax, dword ptr Operand[0] 86 | mov edx, dword ptr Operand[4] 87 | mov ecx, Count 88 | and ecx, 63 89 | 90 | shrd eax, edx, cl 91 | shr edx, cl 92 | 93 | cmp ecx, 32 94 | jc short rs10 95 | 96 | mov eax, edx 97 | xor edx, edx 98 | 99 | rs10: 100 | mov dword ptr Result[0], eax 101 | mov dword ptr Result[4], edx 102 | } 103 | 104 | return Result; 105 | #endif 106 | } 107 | 108 | 109 | UINT64 110 | MultU64x32 ( 111 | IN UINT64 Multiplicand, 112 | IN UINTN Multiplier 113 | ) 114 | // Multiple 64bit by 32bit and get a 64bit result 115 | { 116 | #ifdef __GNUC__ 117 | return Multiplicand * Multiplier; 118 | #else 119 | UINT64 Result; 120 | _asm { 121 | mov eax, dword ptr Multiplicand[0] 122 | mul Multiplier 123 | mov dword ptr Result[0], eax 124 | mov dword ptr Result[4], edx 125 | mov eax, dword ptr Multiplicand[4] 126 | mul Multiplier 127 | add dword ptr Result[4], eax 128 | } 129 | 130 | return Result; 131 | #endif 132 | } 133 | 134 | UINT64 135 | DivU64x32 ( 136 | IN UINT64 Dividend, 137 | IN UINTN Divisor, 138 | OUT UINTN *Remainder OPTIONAL 139 | ) 140 | // divide 64bit by 32bit and get a 64bit result 141 | // N.B. only works for 31bit divisors!! 142 | { 143 | #ifdef __GNUC__ 144 | if (Remainder) 145 | *Remainder = Dividend % Divisor; 146 | return Dividend / Divisor; 147 | #else 148 | UINT32 Rem; 149 | UINT32 bit; 150 | 151 | ASSERT (Divisor != 0); 152 | ASSERT ((Divisor >> 31) == 0); 153 | 154 | // 155 | // For each bit in the dividend 156 | // 157 | 158 | Rem = 0; 159 | for (bit=0; bit < 64; bit++) { 160 | _asm { 161 | shl dword ptr Dividend[0], 1 ; shift rem:dividend left one 162 | rcl dword ptr Dividend[4], 1 163 | rcl dword ptr Rem, 1 164 | 165 | mov eax, Rem 166 | cmp eax, Divisor ; Is Rem >= Divisor? 167 | cmc ; No - do nothing 168 | sbb eax, eax ; Else, 169 | sub dword ptr Dividend[0], eax ; set low bit in dividen 170 | and eax, Divisor ; and 171 | sub Rem, eax ; subtract divisor 172 | } 173 | } 174 | 175 | if (Remainder) { 176 | *Remainder = Rem; 177 | } 178 | 179 | return Dividend; 180 | #endif 181 | } 182 | -------------------------------------------------------------------------------- /gnu-efi/lib/ia64/initplat.c: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 1999 Intel Corporation 4 | 5 | Module Name: 6 | 7 | initplat.c 8 | 9 | Abstract: 10 | 11 | Functions to make SAL and PAL proc calls 12 | 13 | Revision History 14 | 15 | --*/ 16 | #include "lib.h" 17 | 18 | //#include "palproc.h" 19 | 20 | VOID 21 | InitializeLibPlatform ( 22 | IN EFI_HANDLE ImageHandle, 23 | IN EFI_SYSTEM_TABLE *SystemTable 24 | ) 25 | 26 | { 27 | PLABEL SalPlabel; 28 | UINT64 PalEntry; 29 | 30 | LibInitSalAndPalProc (&SalPlabel, &PalEntry); 31 | } 32 | -------------------------------------------------------------------------------- /gnu-efi/lib/ia64/math.c: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 1998 Intel Corporation 4 | 5 | Module Name: 6 | 7 | math.c 8 | 9 | Abstract: 10 | 11 | 12 | 13 | 14 | Revision History 15 | 16 | --*/ 17 | 18 | #include "lib.h" 19 | 20 | 21 | // 22 | // Declare runtime functions 23 | // 24 | 25 | #ifdef RUNTIME_CODE 26 | #ifndef __GNUC__ 27 | #pragma RUNTIME_CODE(LShiftU64) 28 | #pragma RUNTIME_CODE(RShiftU64) 29 | #pragma RUNTIME_CODE(MultU64x32) 30 | #pragma RUNTIME_CODE(DivU64x32) 31 | #endif 32 | #endif 33 | 34 | // 35 | // 36 | // 37 | 38 | 39 | 40 | 41 | UINT64 42 | LShiftU64 ( 43 | IN UINT64 Operand, 44 | IN UINTN Count 45 | ) 46 | // Left shift 64bit by 32bit and get a 64bit result 47 | { 48 | return Operand << Count; 49 | } 50 | 51 | UINT64 52 | RShiftU64 ( 53 | IN UINT64 Operand, 54 | IN UINTN Count 55 | ) 56 | // Right shift 64bit by 32bit and get a 64bit result 57 | { 58 | return Operand >> Count; 59 | } 60 | 61 | 62 | UINT64 63 | MultU64x32 ( 64 | IN UINT64 Multiplicand, 65 | IN UINTN Multiplier 66 | ) 67 | // Multiple 64bit by 32bit and get a 64bit result 68 | { 69 | return Multiplicand * Multiplier; 70 | } 71 | 72 | UINT64 73 | DivU64x32 ( 74 | IN UINT64 Dividend, 75 | IN UINTN Divisor, 76 | OUT UINTN *Remainder OPTIONAL 77 | ) 78 | // divide 64bit by 32bit and get a 64bit result 79 | // N.B. only works for 31bit divisors!! 80 | { 81 | ASSERT (Divisor != 0); 82 | 83 | if (Remainder) { 84 | *Remainder = Dividend % Divisor; 85 | } 86 | 87 | return Dividend / Divisor; 88 | } 89 | -------------------------------------------------------------------------------- /gnu-efi/lib/ia64/palproc.h: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // Copyright (c) 1996-99 Intel Corp. 4 | // 5 | // 6 | //Module Name: 7 | // 8 | // palproc.h 9 | // 10 | //Abstract: 11 | // 12 | // This module contains generic macros for an IA64 assembly writer. 13 | // 14 | // 15 | //Revision History 16 | // 17 | 18 | #ifndef _PALPROC_H 19 | #define _PALPROC_H 20 | 21 | #define PROCEDURE_ENTRY(name) .##text; \ 22 | .##type name, @function; \ 23 | .##global name; \ 24 | .##proc name; \ 25 | name: 26 | 27 | #define PROCEDURE_EXIT(name) .##endp name 28 | 29 | // Note: use of NESTED_SETUP requires number of locals (l) >= 3 30 | 31 | #define NESTED_SETUP(i,l,o,r) \ 32 | alloc loc1=ar##.##pfs,i,l,o,r ;\ 33 | mov loc0=b0 34 | 35 | #define NESTED_RETURN \ 36 | mov b0=loc0 ;\ 37 | mov ar##.##pfs=loc1 ;;\ 38 | br##.##ret##.##dpnt b0;; 39 | 40 | 41 | // defines needed in palproc.s 42 | 43 | #define PAL_MC_CLEAR_LOG 0x0015 44 | #define PAL_MC_DRAIN 0x0016 45 | #define PAL_MC_EXPECTED 0x0017 46 | #define PAL_MC_DYNAMIC_STATE 0x0018 47 | #define PAL_MC_ERROR_INFO 0x0019 48 | #define PAL_MC_RESUME 0x001a 49 | #define PAL_MC_REGISTER_MEM 0x001b 50 | 51 | #endif // _PALPROC_H 52 | -------------------------------------------------------------------------------- /gnu-efi/lib/lib.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 1998 Intel Corporation 4 | 5 | Module Name: 6 | 7 | lib.h 8 | 9 | Abstract: 10 | 11 | EFI library header files 12 | 13 | 14 | 15 | Revision History 16 | 17 | --*/ 18 | 19 | 20 | #include "efi.h" 21 | #include "efilib.h" 22 | #include "efirtlib.h" 23 | 24 | // 25 | // Include non architectural protocols 26 | // 27 | #include "efivar.h" 28 | #include "legacyboot.h" 29 | #include "intload.h" 30 | #include "vgaclass.h" 31 | #include "eficonsplit.h" 32 | #include "adapterdebug.h" 33 | #include "intload.h" 34 | 35 | #include "efigpt.h" 36 | #include "libsmbios.h" 37 | 38 | // 39 | // Prototypes 40 | // 41 | 42 | VOID 43 | InitializeGuid ( 44 | VOID 45 | ); 46 | 47 | INTN EFIAPI 48 | LibStubStriCmp ( 49 | IN EFI_UNICODE_COLLATION_INTERFACE *This, 50 | IN CHAR16 *S1, 51 | IN CHAR16 *S2 52 | ); 53 | 54 | BOOLEAN EFIAPI 55 | LibStubMetaiMatch ( 56 | IN EFI_UNICODE_COLLATION_INTERFACE *This, 57 | IN CHAR16 *String, 58 | IN CHAR16 *Pattern 59 | ); 60 | 61 | VOID EFIAPI 62 | LibStubStrLwrUpr ( 63 | IN EFI_UNICODE_COLLATION_INTERFACE *This, 64 | IN CHAR16 *Str 65 | ); 66 | 67 | BOOLEAN 68 | LibMatchDevicePaths ( 69 | IN EFI_DEVICE_PATH *Multi, 70 | IN EFI_DEVICE_PATH *Single 71 | ); 72 | 73 | EFI_DEVICE_PATH * 74 | LibDuplicateDevicePathInstance ( 75 | IN EFI_DEVICE_PATH *DevPath 76 | ); 77 | 78 | 79 | // 80 | // Globals 81 | // 82 | extern BOOLEAN LibInitialized; 83 | extern BOOLEAN LibFwInstance; 84 | extern SIMPLE_TEXT_OUTPUT_INTERFACE *LibRuntimeDebugOut; 85 | extern EFI_UNICODE_COLLATION_INTERFACE *UnicodeInterface; 86 | extern EFI_UNICODE_COLLATION_INTERFACE LibStubUnicodeInterface; 87 | extern EFI_RAISE_TPL LibRuntimeRaiseTPL; 88 | extern EFI_RESTORE_TPL LibRuntimeRestoreTPL; 89 | -------------------------------------------------------------------------------- /gnu-efi/lib/lock.c: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 1998 Intel Corporation 4 | 5 | Module Name: 6 | 7 | lock.c 8 | 9 | Abstract: 10 | 11 | Implements FLOCK 12 | 13 | 14 | 15 | Revision History 16 | 17 | --*/ 18 | 19 | 20 | #include "lib.h" 21 | 22 | 23 | VOID 24 | InitializeLock ( 25 | IN OUT FLOCK *Lock, 26 | IN EFI_TPL Priority 27 | ) 28 | /*++ 29 | 30 | Routine Description: 31 | 32 | Initialize a basic mutual exclusion lock. Each lock 33 | provides mutual exclusion access at it's task priority 34 | level. Since there is no-premption (at any TPL) or 35 | multiprocessor support, acquiring the lock only consists 36 | of raising to the locks TPL. 37 | 38 | Note on a debug build the lock is acquired and released 39 | to help ensure proper usage. 40 | 41 | Arguments: 42 | 43 | Lock - The FLOCK structure to initialize 44 | 45 | Priority - The task priority level of the lock 46 | 47 | 48 | Returns: 49 | 50 | An initialized F Lock structure. 51 | 52 | --*/ 53 | { 54 | Lock->Tpl = Priority; 55 | Lock->OwnerTpl = 0; 56 | Lock->Lock = 0; 57 | } 58 | 59 | 60 | VOID 61 | AcquireLock ( 62 | IN FLOCK *Lock 63 | ) 64 | /*++ 65 | 66 | Routine Description: 67 | 68 | Raising to the task priority level of the mutual exclusion 69 | lock, and then acquires ownership of the lock. 70 | 71 | Arguments: 72 | 73 | Lock - The lock to acquire 74 | 75 | Returns: 76 | 77 | Lock owned 78 | 79 | --*/ 80 | { 81 | RtAcquireLock (Lock); 82 | } 83 | 84 | 85 | VOID 86 | ReleaseLock ( 87 | IN FLOCK *Lock 88 | ) 89 | /*++ 90 | 91 | Routine Description: 92 | 93 | Releases ownership of the mutual exclusion lock, and 94 | restores the previous task priority level. 95 | 96 | Arguments: 97 | 98 | Lock - The lock to release 99 | 100 | Returns: 101 | 102 | Lock unowned 103 | 104 | --*/ 105 | { 106 | RtReleaseLock (Lock); 107 | } 108 | -------------------------------------------------------------------------------- /gnu-efi/lib/runtime/efirtlib.c: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 1999 Intel Corporation 4 | 5 | Module Name: 6 | 7 | EfiRtLib.h 8 | 9 | Abstract: 10 | 11 | EFI Runtime library functions 12 | 13 | 14 | 15 | Revision History 16 | 17 | --*/ 18 | 19 | #include "efi.h" 20 | #include "efilib.h" 21 | #include "efirtlib.h" 22 | 23 | #ifndef __GNUC__ 24 | #pragma RUNTIME_CODE(RtZeroMem) 25 | #endif 26 | VOID 27 | RUNTIMEFUNCTION 28 | RtZeroMem ( 29 | IN VOID *Buffer, 30 | IN UINTN Size 31 | ) 32 | { 33 | INT8 *pt; 34 | 35 | pt = Buffer; 36 | while (Size--) { 37 | *(pt++) = 0; 38 | } 39 | } 40 | 41 | #ifndef __GNUC__ 42 | #pragma RUNTIME_CODE(RtSetMem) 43 | #endif 44 | VOID 45 | RUNTIMEFUNCTION 46 | RtSetMem ( 47 | IN VOID *Buffer, 48 | IN UINTN Size, 49 | IN UINT8 Value 50 | ) 51 | { 52 | INT8 *pt; 53 | 54 | pt = Buffer; 55 | while (Size--) { 56 | *(pt++) = Value; 57 | } 58 | } 59 | 60 | #ifndef __GNUC__ 61 | #pragma RUNTIME_CODE(RtCopyMem) 62 | #endif 63 | VOID 64 | RUNTIMEFUNCTION 65 | RtCopyMem ( 66 | IN VOID *Dest, 67 | IN CONST VOID *Src, 68 | IN UINTN len 69 | ) 70 | { 71 | CHAR8 *d; 72 | CONST CHAR8 *s = Src; 73 | d = Dest; 74 | while (len--) { 75 | *(d++) = *(s++); 76 | } 77 | } 78 | 79 | #ifndef __GNUC__ 80 | #pragma RUNTIME_CODE(RtCompareMem) 81 | #endif 82 | INTN 83 | RUNTIMEFUNCTION 84 | RtCompareMem ( 85 | IN CONST VOID *Dest, 86 | IN CONST VOID *Src, 87 | IN UINTN len 88 | ) 89 | { 90 | CONST CHAR8 *d = Dest, *s = Src; 91 | while (len--) { 92 | if (*d != *s) { 93 | return *d - *s; 94 | } 95 | 96 | d += 1; 97 | s += 1; 98 | } 99 | 100 | return 0; 101 | } 102 | 103 | #ifndef __GNUC__ 104 | #pragma RUNTIME_CODE(RtCompareGuid) 105 | #endif 106 | INTN 107 | RUNTIMEFUNCTION 108 | RtCompareGuid ( 109 | IN EFI_GUID *Guid1, 110 | IN EFI_GUID *Guid2 111 | ) 112 | /*++ 113 | 114 | Routine Description: 115 | 116 | Compares to GUIDs 117 | 118 | Arguments: 119 | 120 | Guid1 - guid to compare 121 | Guid2 - guid to compare 122 | 123 | Returns: 124 | = 0 if Guid1 == Guid2 125 | 126 | --*/ 127 | { 128 | INT32 *g1, *g2, r; 129 | 130 | // 131 | // Compare 32 bits at a time 132 | // 133 | 134 | g1 = (INT32 *) Guid1; 135 | g2 = (INT32 *) Guid2; 136 | 137 | r = g1[0] - g2[0]; 138 | r |= g1[1] - g2[1]; 139 | r |= g1[2] - g2[2]; 140 | r |= g1[3] - g2[3]; 141 | 142 | return r; 143 | } 144 | 145 | 146 | -------------------------------------------------------------------------------- /gnu-efi/lib/runtime/rtdata.c: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 1998 Intel Corporation 4 | 5 | Module Name: 6 | 7 | data.c 8 | 9 | Abstract: 10 | 11 | EFI library global data 12 | 13 | 14 | 15 | Revision History 16 | 17 | --*/ 18 | 19 | #include "lib.h" 20 | 21 | 22 | // 23 | // These globals are runtime globals 24 | // 25 | // N.B. The Microsoft C compiler will only put the data in the 26 | // right data section if it is explicitly initialized.. 27 | // 28 | 29 | #ifndef __GNUC__ 30 | #pragma BEGIN_RUNTIME_DATA() 31 | #endif 32 | 33 | // 34 | // RT - pointer to the runtime table 35 | // 36 | 37 | EFI_RUNTIME_SERVICES *RT; 38 | 39 | // 40 | // LibStandalone - TRUE if lib is linked in as part of the firmware. 41 | // N.B. The EFI fw sets this value directly 42 | // 43 | 44 | BOOLEAN LibFwInstance; 45 | 46 | // 47 | // EFIDebug - Debug mask 48 | // 49 | 50 | UINTN EFIDebug = EFI_DBUG_MASK; 51 | 52 | // 53 | // LibRuntimeDebugOut - Runtime Debug Output device 54 | // 55 | 56 | SIMPLE_TEXT_OUTPUT_INTERFACE *LibRuntimeDebugOut; 57 | 58 | // 59 | // LibRuntimeRaiseTPL, LibRuntimeRestoreTPL - pointers to Runtime functions from the 60 | // Boot Services Table 61 | // 62 | 63 | EFI_RAISE_TPL LibRuntimeRaiseTPL = NULL; 64 | EFI_RESTORE_TPL LibRuntimeRestoreTPL = NULL; 65 | 66 | -------------------------------------------------------------------------------- /gnu-efi/lib/runtime/rtlock.c: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 1998 Intel Corporation 4 | 5 | Module Name: 6 | 7 | lock.c 8 | 9 | Abstract: 10 | 11 | Implements FLOCK 12 | 13 | 14 | 15 | Revision History 16 | 17 | --*/ 18 | 19 | 20 | #include "lib.h" 21 | 22 | 23 | 24 | #ifndef __GNUC__ 25 | #pragma RUNTIME_CODE(RtAcquireLock) 26 | #endif 27 | VOID 28 | RtAcquireLock ( 29 | IN FLOCK *Lock 30 | ) 31 | /*++ 32 | 33 | Routine Description: 34 | 35 | Raising to the task priority level of the mutual exclusion 36 | lock, and then acquires ownership of the lock. 37 | 38 | Arguments: 39 | 40 | Lock - The lock to acquire 41 | 42 | Returns: 43 | 44 | Lock owned 45 | 46 | --*/ 47 | { 48 | if (BS) { 49 | if (BS->RaiseTPL != NULL) { 50 | Lock->OwnerTpl = uefi_call_wrapper(BS->RaiseTPL, 1, Lock->Tpl); 51 | } 52 | } 53 | else { 54 | if (LibRuntimeRaiseTPL != NULL) { 55 | Lock->OwnerTpl = LibRuntimeRaiseTPL(Lock->Tpl); 56 | } 57 | } 58 | Lock->Lock += 1; 59 | ASSERT (Lock->Lock == 1); 60 | } 61 | 62 | 63 | #ifndef __GNUC__ 64 | #pragma RUNTIME_CODE(RtAcquireLock) 65 | #endif 66 | VOID 67 | RtReleaseLock ( 68 | IN FLOCK *Lock 69 | ) 70 | /*++ 71 | 72 | Routine Description: 73 | 74 | Releases ownership of the mutual exclusion lock, and 75 | restores the previous task priority level. 76 | 77 | Arguments: 78 | 79 | Lock - The lock to release 80 | 81 | Returns: 82 | 83 | Lock unowned 84 | 85 | --*/ 86 | { 87 | EFI_TPL Tpl; 88 | 89 | Tpl = Lock->OwnerTpl; 90 | ASSERT(Lock->Lock == 1); 91 | Lock->Lock -= 1; 92 | if (BS) { 93 | if (BS->RestoreTPL != NULL) { 94 | uefi_call_wrapper(BS->RestoreTPL, 1, Tpl); 95 | } 96 | } 97 | else { 98 | if (LibRuntimeRestoreTPL != NULL) { 99 | LibRuntimeRestoreTPL(Tpl); 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /gnu-efi/lib/runtime/rtstr.c: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 1998 Intel Corporation 4 | 5 | Module Name: 6 | 7 | str.c 8 | 9 | Abstract: 10 | 11 | String runtime functions 12 | 13 | 14 | Revision History 15 | 16 | --*/ 17 | 18 | #include "lib.h" 19 | 20 | #ifndef __GNUC__ 21 | #pragma RUNTIME_CODE(RtAcquireLock) 22 | #endif 23 | INTN 24 | RUNTIMEFUNCTION 25 | RtStrCmp ( 26 | IN CONST CHAR16 *s1, 27 | IN CONST CHAR16 *s2 28 | ) 29 | // compare strings 30 | { 31 | while (*s1) { 32 | if (*s1 != *s2) { 33 | break; 34 | } 35 | 36 | s1 += 1; 37 | s2 += 1; 38 | } 39 | 40 | return *s1 - *s2; 41 | } 42 | 43 | #ifndef __GNUC__ 44 | #pragma RUNTIME_CODE(RtStrCpy) 45 | #endif 46 | VOID 47 | RUNTIMEFUNCTION 48 | RtStrCpy ( 49 | IN CHAR16 *Dest, 50 | IN CONST CHAR16 *Src 51 | ) 52 | // copy strings 53 | { 54 | while (*Src) { 55 | *(Dest++) = *(Src++); 56 | } 57 | *Dest = 0; 58 | } 59 | 60 | #ifndef __GNUC__ 61 | #pragma RUNTIME_CODE(RtStrCat) 62 | #endif 63 | VOID 64 | RUNTIMEFUNCTION 65 | RtStrCat ( 66 | IN CHAR16 *Dest, 67 | IN CONST CHAR16 *Src 68 | ) 69 | { 70 | RtStrCpy(Dest+StrLen(Dest), Src); 71 | } 72 | 73 | #ifndef __GNUC__ 74 | #pragma RUNTIME_CODE(RtStrLen) 75 | #endif 76 | UINTN 77 | RUNTIMEFUNCTION 78 | RtStrLen ( 79 | IN CONST CHAR16 *s1 80 | ) 81 | // string length 82 | { 83 | UINTN len; 84 | 85 | for (len=0; *s1; s1+=1, len+=1) ; 86 | return len; 87 | } 88 | 89 | #ifndef __GNUC__ 90 | #pragma RUNTIME_CODE(RtStrSize) 91 | #endif 92 | UINTN 93 | RUNTIMEFUNCTION 94 | RtStrSize ( 95 | IN CONST CHAR16 *s1 96 | ) 97 | // string size 98 | { 99 | UINTN len; 100 | 101 | for (len=0; *s1; s1+=1, len+=1) ; 102 | return (len + 1) * sizeof(CHAR16); 103 | } 104 | 105 | #ifndef __GNUC__ 106 | #pragma RUNTIME_CODE(RtBCDtoDecimal) 107 | #endif 108 | UINT8 109 | RUNTIMEFUNCTION 110 | RtBCDtoDecimal( 111 | IN UINT8 BcdValue 112 | ) 113 | { 114 | UINTN High, Low; 115 | 116 | High = BcdValue >> 4; 117 | Low = BcdValue - (High << 4); 118 | 119 | return ((UINT8)(Low + (High * 10))); 120 | } 121 | 122 | 123 | #ifndef __GNUC__ 124 | #pragma RUNTIME_CODE(RtDecimaltoBCD) 125 | #endif 126 | UINT8 127 | RUNTIMEFUNCTION 128 | RtDecimaltoBCD ( 129 | IN UINT8 DecValue 130 | ) 131 | { 132 | UINTN High, Low; 133 | 134 | High = DecValue / 10; 135 | Low = DecValue - (High * 10); 136 | 137 | return ((UINT8)(Low + (High << 4))); 138 | } 139 | 140 | 141 | -------------------------------------------------------------------------------- /gnu-efi/lib/runtime/vm.c: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 1998 Intel Corporation 4 | 5 | Module Name: 6 | 7 | vm.c 8 | 9 | Abstract: 10 | 11 | EFI Hell to remap runtime address into the new virual address space 12 | that was registered by the OS for RT calls. 13 | 14 | So the code image needs to be relocated. All pointers need to be 15 | manually fixed up since the address map changes. 16 | 17 | GOOD LUCK NOT HAVING BUGS IN YOUR CODE! PLEASE TEST A LOT. MAKE SURE 18 | EXIT BOOTSERVICES OVER WRITES ALL BOOTSERVICE MEMORY & DATA SPACES WHEN 19 | YOU TEST. 20 | 21 | Revision History 22 | 23 | --*/ 24 | 25 | #include "lib.h" 26 | 27 | #ifndef __GNUC__ 28 | #pragma RUNTIME_CODE(RtLibEnableVirtualMappings) 29 | #endif 30 | VOID 31 | RUNTIMEFUNCTION 32 | RtLibEnableVirtualMappings ( 33 | VOID 34 | ) 35 | { 36 | EFI_CONVERT_POINTER ConvertPointer; 37 | 38 | // 39 | // If this copy of the lib is linked into the firmware, then 40 | // do not update the pointers yet. 41 | // 42 | 43 | if (!LibFwInstance) { 44 | 45 | // 46 | // Different components are updating to the new virtual 47 | // mappings at differnt times. The only function that 48 | // is safe to call at this notification is ConvertAddress 49 | // 50 | 51 | ConvertPointer = RT->ConvertPointer; 52 | 53 | // 54 | // Fix any pointers that the lib created, that may be needed 55 | // during runtime. 56 | // 57 | 58 | ConvertPointer (EFI_INTERNAL_PTR, (VOID **)&RT); 59 | ConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&LibRuntimeDebugOut); 60 | 61 | ConvertPointer (EFI_INTERNAL_PTR, (VOID **)&LibRuntimeRaiseTPL); 62 | ConvertPointer (EFI_INTERNAL_PTR, (VOID **)&LibRuntimeRestoreTPL); 63 | 64 | // that was it :^) 65 | } 66 | } 67 | 68 | 69 | #ifndef __GNUC__ 70 | #pragma RUNTIME_CODE(RtConvertList) 71 | #endif 72 | VOID 73 | RUNTIMEFUNCTION 74 | RtConvertList ( 75 | IN UINTN DebugDisposition, 76 | IN OUT LIST_ENTRY *ListHead 77 | ) 78 | { 79 | LIST_ENTRY *Link; 80 | LIST_ENTRY *NextLink; 81 | EFI_CONVERT_POINTER ConvertPointer; 82 | 83 | ConvertPointer = RT->ConvertPointer; 84 | 85 | // 86 | // Convert all the Flink & Blink pointers in the list 87 | // 88 | 89 | Link = ListHead; 90 | do { 91 | NextLink = Link->Flink; 92 | 93 | ConvertPointer ( 94 | Link->Flink == ListHead ? DebugDisposition : 0, 95 | (VOID **)&Link->Flink 96 | ); 97 | 98 | ConvertPointer ( 99 | Link->Blink == ListHead ? DebugDisposition : 0, 100 | (VOID **)&Link->Blink 101 | ); 102 | 103 | Link = NextLink; 104 | } while (Link != ListHead); 105 | } 106 | -------------------------------------------------------------------------------- /gnu-efi/lib/smbios.c: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 2000 Intel Corporation 4 | 5 | Module Name: 6 | 7 | Smbios.c 8 | 9 | Abstract: 10 | 11 | Lib fucntions for SMBIOS. Used to get system serial number and GUID 12 | 13 | Revision History 14 | 15 | --*/ 16 | 17 | #include "lib.h" 18 | 19 | /* 20 | * We convert 32 bit values to pointers. In 64 bit mode the compiler will issue a 21 | * warning stating that the value is too small for the pointer: 22 | * "warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]" 23 | * we can safely ignore them here. 24 | */ 25 | #ifdef __GNUC__ 26 | #pragma GCC diagnostic ignored "-Wint-to-pointer-cast" 27 | #endif 28 | 29 | EFI_STATUS 30 | LibGetSmbiosSystemGuidAndSerialNumber ( 31 | IN EFI_GUID *SystemGuid, 32 | OUT CHAR8 **SystemSerialNumber 33 | ) 34 | { 35 | EFI_STATUS Status; 36 | SMBIOS_STRUCTURE_TABLE *SmbiosTable; 37 | SMBIOS_STRUCTURE_POINTER Smbios; 38 | SMBIOS_STRUCTURE_POINTER SmbiosEnd; 39 | UINT16 Index; 40 | 41 | Status = LibGetSystemConfigurationTable(&SMBIOSTableGuid, (VOID**)&SmbiosTable); 42 | if (EFI_ERROR(Status)) { 43 | return EFI_NOT_FOUND; 44 | } 45 | 46 | Smbios.Hdr = (SMBIOS_HEADER *)SmbiosTable->TableAddress; 47 | SmbiosEnd.Raw = (UINT8 *)(SmbiosTable->TableAddress + SmbiosTable->TableLength); 48 | for (Index = 0; Index < SmbiosTable->TableLength ; Index++) { 49 | if (Smbios.Hdr->Type == 1) { 50 | if (Smbios.Hdr->Length < 0x19) { 51 | // 52 | // Older version did not support Guid and Serial number 53 | // 54 | continue; 55 | } 56 | 57 | // 58 | // SMBIOS tables are byte packed so we need to do a byte copy to 59 | // prevend alignment faults on IA-64. 60 | 61 | CopyMem (SystemGuid, &Smbios.Type1->Uuid, sizeof(EFI_GUID)); 62 | *SystemSerialNumber = LibGetSmbiosString(&Smbios, Smbios.Type1->SerialNumber); 63 | return EFI_SUCCESS; 64 | } 65 | 66 | // 67 | // Make Smbios point to the next record 68 | // 69 | LibGetSmbiosString (&Smbios, -1); 70 | 71 | if (Smbios.Raw >= SmbiosEnd.Raw) { 72 | // 73 | // SMBIOS 2.1 incorrectly stated the length of SmbiosTable as 0x1e. 74 | // given this we must double check against the lenght of 75 | /// the structure. My home PC has this bug.ruthard 76 | // 77 | return EFI_SUCCESS; 78 | } 79 | } 80 | 81 | return EFI_SUCCESS; 82 | } 83 | 84 | CHAR8* 85 | LibGetSmbiosString ( 86 | IN SMBIOS_STRUCTURE_POINTER *Smbios, 87 | IN UINT16 StringNumber 88 | ) 89 | /*++ 90 | 91 | Return SMBIOS string given the string number. 92 | 93 | Arguments: 94 | Smbios - Pointer to SMBIOS structure 95 | StringNumber - String number to return. -1 is used to skip all strings and 96 | point to the next SMBIOS structure. 97 | 98 | Returns: 99 | Pointer to string, or pointer to next SMBIOS strcuture if StringNumber == -1 100 | --*/ 101 | { 102 | UINT16 Index; 103 | CHAR8 *String; 104 | 105 | // 106 | // Skip over formatted section 107 | // 108 | String = (CHAR8 *)(Smbios->Raw + Smbios->Hdr->Length); 109 | 110 | // 111 | // Look through unformated section 112 | // 113 | for (Index = 1; Index <= StringNumber; Index++) { 114 | if (StringNumber == Index) { 115 | return String; 116 | } 117 | 118 | // 119 | // Skip string 120 | // 121 | for (; *String != 0; String++); 122 | String++; 123 | 124 | if (*String == 0) { 125 | // 126 | // If double NULL then we are done. 127 | // Retrun pointer to next structure in Smbios. 128 | // if you pass in a -1 you will always get here 129 | // 130 | Smbios->Raw = (UINT8 *)++String; 131 | return NULL; 132 | } 133 | } 134 | return NULL; 135 | } 136 | -------------------------------------------------------------------------------- /gnu-efi/lib/x86_64/callwrap.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Convert SysV calling convention to EFI x86_64 calling convention 3 | * 4 | * Copyright (C) 2007-2010 Intel Corp 5 | * Bibo Mao 6 | * Chandramouli Narayanan 7 | * Huang Ying 8 | * 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 15 | * - Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * - Redistributions in binary form must reproduce the above 18 | * copyright notice, this list of conditions and the following 19 | * disclaimer in the documentation and/or other materials 20 | * provided with the distribution. 21 | * - Neither the name of Hewlett-Packard Co. nor the names of its 22 | * contributors may be used to endorse or promote products derived 23 | * from this software without specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 26 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 27 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 30 | * BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 31 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 32 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 33 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 34 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 35 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 36 | * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 | * SUCH DAMAGE. 38 | */ 39 | 40 | /* uefi_call_wrapper() is a macro in efibind.h */ 41 | -------------------------------------------------------------------------------- /gnu-efi/lib/x86_64/initplat.c: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) 1998 Intel Corporation 4 | 5 | Module Name: 6 | 7 | initplat.c 8 | 9 | Abstract: 10 | 11 | 12 | 13 | 14 | Revision History 15 | 16 | --*/ 17 | 18 | #include "lib.h" 19 | 20 | VOID 21 | InitializeLibPlatform ( 22 | IN EFI_HANDLE ImageHandle, 23 | IN EFI_SYSTEM_TABLE *SystemTable 24 | ) 25 | 26 | { 27 | } 28 | 29 | -------------------------------------------------------------------------------- /hv_handlers.h: -------------------------------------------------------------------------------- 1 | #ifndef _HV_HANDLERS_ 2 | #define _HV_HANDLERS_ 3 | 4 | 5 | typedef void (*vmexit_handler_func)(GUEST_REGS * regs); 6 | typedef void (*vmx_exit_func)(void); 7 | typedef void (*unknown_exit_func)(uint64_t exit_reason); 8 | typedef void (*handle_msr_break_func)(uint64_t rdx, uint64_t rax); 9 | 10 | vmexit_handler_func ptr_vmexit_handler; 11 | vmx_exit_func ptr_vmx_exit; 12 | unknown_exit_func ptr_unknown_exit; 13 | handle_msr_break_func ptr_handle_msr_break; 14 | 15 | void vmexit_handler(GUEST_REGS * regs); 16 | void vmx_exit(void); 17 | void unknown_exit(uint64_t exit_reason); 18 | void handle_msr_break(uint64_t rdx, uint64_t rax); 19 | 20 | #endif -------------------------------------------------------------------------------- /lib_uefi.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIB_UEFI_ 2 | #define _LIB_UEFI_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | int strcmp(void * str1, void * str2); 9 | int strncmp(void * str1, void * str2, int n); 10 | void str2wstr(CHAR16 * wstr, char * str, int n); 11 | EFI_STATUS wait_for_key(VOID); 12 | EFI_STATUS print(CHAR16 * str); 13 | EFI_STATUS print_uint(uint64_t n); 14 | EFI_STATUS print_uintb(uint64_t n); 15 | EFI_STATUS print_uintx(uint64_t n); 16 | VOID init(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE * SystemTable); 17 | EFI_FILE_HANDLE LibOpenRoot(IN EFI_HANDLE DeviceHandle); 18 | EFI_DEVICE_PATH * DevicePathFromHandle(IN EFI_HANDLE Handle); 19 | EFI_DEVICE_PATH * FileDevicePath(IN EFI_HANDLE Device OPTIONAL, IN CHAR16 * FileName); 20 | UINTN StrSize(IN CONST CHAR16 * s1); 21 | VOID * AllocatePool(IN UINTN Size); 22 | VOID * AllocateZeroPool(IN UINTN Size); 23 | VOID ZeroMem(IN VOID * Buffer, IN UINTN Size); 24 | VOID CopyMem(IN VOID * Dest, IN CONST VOID * Src, IN UINTN len); 25 | EFI_DEVICE_PATH * AppendDevicePath(IN EFI_DEVICE_PATH * Src1, IN EFI_DEVICE_PATH * Src2); 26 | EFI_DEVICE_PATH * DuplicateDevicePath(IN EFI_DEVICE_PATH * DevPath); 27 | UINTN DevicePathSize(IN EFI_DEVICE_PATH * DevPath); 28 | VOID FreePool(IN VOID * Buffer); 29 | UINTN DevicePathInstanceCount(IN EFI_DEVICE_PATH * DevicePath); 30 | EFI_DEVICE_PATH * DevicePathInstance(IN OUT EFI_DEVICE_PATH **DevicePath, OUT UINTN * Size); 31 | 32 | #endif -------------------------------------------------------------------------------- /pic.asm: -------------------------------------------------------------------------------- 1 | global disable_pic 2 | 3 | section .text 4 | 5 | disable_pic: 6 | ; Remap PIC IRQ's 7 | mov al, 0x11 ; begin PIC 1 initialization 8 | out 0x20, al 9 | mov al, 0x11 ; begin PIC 2 initialization 10 | out 0xA0, al 11 | mov al, 0x20 ; IRQ 0-7: interrupts 20h-27h 12 | out 0x21, al 13 | mov al, 0x28 ; IRQ 8-15: interrupts 28h-2Fh 14 | out 0xA1, al 15 | mov al, 4 16 | out 0x21, al 17 | mov al, 2 18 | out 0xA1, al 19 | mov al, 1 20 | out 0x21, al 21 | out 0xA1, al 22 | 23 | ; Mask all PIC interrupts 24 | mov al, 0xFF 25 | out 0x21, al 26 | out 0xA1, al 27 | ret -------------------------------------------------------------------------------- /pic.h: -------------------------------------------------------------------------------- 1 | #ifndef _PIC_ 2 | #define _PIC_ 3 | 4 | void disable_pic(void); 5 | 6 | #endif -------------------------------------------------------------------------------- /realmode_emu.h: -------------------------------------------------------------------------------- 1 | #ifndef _REALMODE_EMU_ 2 | #define _REALMODE_EMU_ 3 | 4 | #include "regs.h" 5 | 6 | #define EMU_SUCCESS 1 7 | #define EMU_ERROR 0 8 | 9 | extern uint8_t test[]; 10 | 11 | int exec_instruction(GUEST_REGS * regs, uint8_t ** p_eip); 12 | 13 | #endif -------------------------------------------------------------------------------- /regs.asm: -------------------------------------------------------------------------------- 1 | global get_rbp 2 | global get_rsp 3 | global get_cs 4 | global get_ds 5 | global get_es 6 | global get_fs 7 | global get_gs 8 | global get_ss 9 | global get_tr 10 | global get_cr0 11 | global get_cr3 12 | global get_cr4 13 | global get_dr7 14 | global get_rflags 15 | global get_gdt_base_limit 16 | global get_idt_base_limit 17 | global get_ldtr 18 | global get_msr 19 | global set_msr 20 | global set_tr 21 | global set_gdt_base_limit 22 | 23 | section .text 24 | 25 | get_rbp: 26 | mov rax,rbp 27 | ret 28 | 29 | get_rsp: 30 | mov rax,rsp 31 | ret 32 | 33 | get_cs: 34 | mov rax,cs 35 | ret 36 | 37 | get_ds: 38 | mov rax,ds 39 | ret 40 | 41 | get_es: 42 | mov rax,es 43 | ret 44 | 45 | get_fs: 46 | mov rax,fs 47 | ret 48 | 49 | get_gs: 50 | mov rax,gs 51 | ret 52 | 53 | get_ss: 54 | mov rax,ss 55 | ret 56 | 57 | get_tr: 58 | str rax 59 | ret 60 | 61 | get_cr0: 62 | mov rax,cr0 63 | ret 64 | 65 | get_cr3: 66 | mov rax,cr3 67 | ret 68 | 69 | get_cr4: 70 | mov rax,cr4 71 | ret 72 | 73 | get_dr7: 74 | mov rax,dr7 75 | ret 76 | 77 | get_rflags: 78 | pushf 79 | pop rax 80 | ret 81 | 82 | get_gdt_base_limit: 83 | sub rsp,10 84 | sgdt [rsp] 85 | mov rax,[rsp+2] 86 | mov [rcx],rax 87 | mov ax,[rsp] 88 | mov [rdx],ax 89 | add rsp,10 90 | ret 91 | 92 | get_idt_base_limit: 93 | sub rsp,10 94 | sidt [rsp] 95 | mov rax,[rsp+2] 96 | mov [rcx],rax 97 | mov ax,[rsp] 98 | mov [rdx],ax 99 | add rsp,10 100 | ret 101 | 102 | get_ldtr: 103 | sldt rax 104 | ret 105 | 106 | get_msr: 107 | rdmsr 108 | shl rdx,32 109 | or rax,rdx 110 | ret 111 | 112 | set_msr: 113 | mov rax,rdx 114 | and rax,0FFFFFFFFh 115 | shr rdx,32 116 | wrmsr 117 | ret 118 | 119 | set_tr: 120 | push rcx 121 | cli 122 | ltr [rsp] 123 | sti 124 | pop rcx 125 | ret 126 | 127 | set_gdt_base_limit: 128 | sub rsp,10 129 | mov [rsp],dx 130 | mov [rsp+2],rcx 131 | cli 132 | lgdt [rsp] 133 | sti 134 | add rsp,10 135 | ret 136 | -------------------------------------------------------------------------------- /regs.h: -------------------------------------------------------------------------------- 1 | #ifndef _REGS_ 2 | #define _REGS_ 3 | 4 | #include 5 | #include "vmx_api.h" 6 | 7 | #define EFLAGS_VM (1 << 17) 8 | #define EFLAGS_IOPL3 (3 << 12) 9 | 10 | #define CPUID_PSE (1 << 3) 11 | 12 | typedef struct 13 | { 14 | uint16_t limit_0_15; 15 | uint16_t base_0_15; 16 | uint8_t base_16_23; 17 | uint8_t attr_0_7; 18 | uint8_t limit_16_19_attr_8_11; 19 | uint8_t base_24_31; 20 | } __attribute__ ((packed)) GDT_ENTRY; 21 | 22 | typedef struct 23 | { 24 | uint16_t offset_0_15; 25 | uint16_t segment_sel; 26 | uint8_t attr; 27 | uint8_t p_dpl_type; 28 | uint16_t offset_16_31; 29 | uint32_t offset_32_63; 30 | uint32_t reserved; 31 | } __attribute__ ((packed)) IDT_ENTRY; 32 | 33 | enum 34 | { 35 | ES = 0, 36 | CS, 37 | SS, 38 | DS, 39 | FS, 40 | GS, 41 | LDTR, 42 | TR 43 | }; 44 | 45 | typedef struct{ 46 | uint64_t rax; 47 | uint64_t rcx; 48 | uint64_t rdx; 49 | uint64_t rbx; 50 | uint64_t rsp; 51 | uint64_t rbp; 52 | uint64_t rsi; 53 | uint64_t rdi; 54 | uint64_t r8; 55 | uint64_t r9; 56 | uint64_t r10; 57 | uint64_t r11; 58 | uint64_t r12; 59 | uint64_t r13; 60 | uint64_t r14; 61 | uint64_t r15; 62 | HVM * hvm; 63 | } __attribute__ ((packed)) GUEST_REGS; 64 | 65 | uint64_t get_rbp(void); 66 | uint64_t get_rsp(void); 67 | uint64_t get_cs(void); 68 | uint64_t get_ds(void); 69 | uint64_t get_es(void); 70 | uint64_t get_fs(void); 71 | uint64_t get_gs(void); 72 | uint64_t get_ss(void); 73 | uint64_t get_tr(void); 74 | uint64_t get_cr0(void); 75 | uint64_t get_cr3(void); 76 | uint64_t get_cr4(void); 77 | uint64_t get_dr7(void); 78 | uint64_t get_rflags(void); 79 | void get_gdt_base_limit(uint64_t * base, uint16_t * limit); 80 | void get_idt_base_limit(uint64_t * base, uint16_t * limit); 81 | uint64_t get_ldtr(void); 82 | uint64_t get_msr(uint64_t index); 83 | uint64_t set_msr(uint64_t index, uint64_t value); 84 | 85 | void set_tr(uint64_t sel); 86 | void set_gdt_base_limit(uint64_t base, uint64_t limit); 87 | 88 | #endif -------------------------------------------------------------------------------- /reloc_pe.c: -------------------------------------------------------------------------------- 1 | #include "reloc_pe.h" 2 | #include "lib_uefi.h" 3 | 4 | int64_t reloc_image(IMAGE_DOS_HEADER * img, uint64_t new_base){ 5 | IMAGE_NT_HEADERS64 * nt_headers64 = (IMAGE_NT_HEADERS64*)((uint64_t)img + img->e_lfanew); 6 | IMAGE_BASE_RELOCATION * base_reloc = (IMAGE_BASE_RELOCATION*)((uint64_t)img + nt_headers64->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress); 7 | void * base_reloc_end = (void*)((uint64_t)base_reloc + nt_headers64->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size); 8 | int i; 9 | 10 | int64_t delta = new_base - (int64_t)img; 11 | 12 | //print(L"PE RELOCATIONS:\r\n"); 13 | while(base_reloc != base_reloc_end){ 14 | int items = (base_reloc->SizeOfBlock - 8) / 2; 15 | uint64_t block_base = base_reloc->VirtualAddress; 16 | 17 | for(i = 0; i < items; ++i){ 18 | uint8_t type = base_reloc->TypeOffset[i] >> 12; 19 | uint64_t offset = block_base + (base_reloc->TypeOffset[i] & 0xFFF); 20 | /*if(type == IMAGE_REL_BASED_ABSOLUTE){ 21 | print(L"ABSOL "); 22 | } 23 | else if(type == IMAGE_REL_BASED_DIR64){ 24 | print(L"DIR64 "); 25 | } 26 | 27 | print_uintx(offset); print(L" ");*/ 28 | if(type == IMAGE_REL_BASED_DIR64){ 29 | *(int64_t*)(new_base + offset) += delta; 30 | } 31 | } 32 | base_reloc = (IMAGE_BASE_RELOCATION*)((uint64_t)base_reloc + base_reloc->SizeOfBlock); 33 | } 34 | //print(L"Size of image [PE]: "); print_uint(nt_headers64->OptionalHeader.SizeOfImage); print(L"\r\n"); 35 | 36 | return 1; 37 | } -------------------------------------------------------------------------------- /smp.h: -------------------------------------------------------------------------------- 1 | #ifndef _SMP_ 2 | #define _SMP_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #define MSR_IA32_APIC_BASE 0x1B 9 | // IA32_APIC_BASE flags: 10 | #define APIC_ENABLED 1 << 11 11 | #define IS_BSP 1 << 8 12 | 13 | extern volatile int * CPUs_activated; 14 | extern volatile int CPU_notified; 15 | extern int CPU_count; 16 | extern uint64_t LAPIC_addr; 17 | 18 | extern void * ap_stacks; 19 | 20 | // Local APIC Register Addresses 21 | #define LAPIC_ID_REG 0x20 22 | #define SPURIOUS_INT_REG 0xF0 23 | #define INT_COMMAND_REG_LOW 0x300 24 | #define INT_COMMAND_REG_HIGH 0x310 25 | 26 | // Local x2APIC Registers 27 | #define MSR_LAPIC_ID_REG 0x802 28 | #define MSR_SPURIOUS_INT_REG 0x80F 29 | #define MSR_INT_COMMAND_REG 0x830 30 | 31 | // IPI flags 32 | #define DLV_STATUS 1 << 12 // 0: command completed, 1: command pending 33 | #define LVL_ASSERT 1 << 14 34 | #define DM_INIT 5 << 8 35 | #define DM_STARTUP 6 << 8 36 | 37 | extern uint8_t ProcAPIC_IDs[256]; 38 | extern uint32_t Proc_x2APIC_IDs[256]; 39 | 40 | typedef struct _RSDP{ 41 | // In ACPI >= 1 42 | char Signature[8]; 43 | uint8_t Checksum; 44 | char OEMID[6]; 45 | uint8_t Revision; 46 | uint32_t RsdtAddress; 47 | // In ACPI >= 2 48 | uint32_t Length; 49 | uint64_t XsdtAddress; 50 | uint8_t ExtendedChecksum; 51 | uint8_t reserved[3]; 52 | } __attribute__((packed)) RSDP; 53 | 54 | typedef struct _SDTHeader{ 55 | char Signature[4]; 56 | uint32_t Length; 57 | uint8_t Revision; 58 | uint8_t Checksum; 59 | char OEMID[6]; 60 | char OEMTableID[8]; 61 | uint32_t OEMRevision; 62 | uint32_t CreatorID; 63 | uint32_t CreatorRevision; 64 | } __attribute__((packed)) SDTHeader; 65 | 66 | typedef struct _XSDT{ 67 | SDTHeader h; 68 | uint64_t PointerToOtherSDT[1]; // Actual length according to h.Length 69 | } __attribute__((packed)) XSDT; 70 | 71 | 72 | typedef struct _APICStructHeader{ 73 | uint8_t Type; 74 | uint8_t Length; 75 | } __attribute__((packed)) APICStructHeader; 76 | 77 | typedef struct _MADT{ 78 | SDTHeader h; 79 | uint32_t LocalControllerAddress; // Important (LAPIC) 80 | uint32_t Flags; 81 | APICStructHeader APICStructs[1]; 82 | } __attribute__((packed)) MADT; 83 | 84 | enum{ 85 | TypeProcLocalAPIC, 86 | TypeIO_APIC, 87 | TypeProcLocal_x2APIC = 9 88 | /* ... */ 89 | }; 90 | 91 | #define PROC_ENABLED 1 // ProcLocalAPIC flag 92 | 93 | typedef struct _EntryProcLocalAPIC{ 94 | APICStructHeader h; 95 | uint8_t ProcID; 96 | uint8_t APIC_ID; 97 | uint32_t Flags; 98 | } __attribute__((packed)) EntryProcLocalAPIC; 99 | 100 | typedef struct _EntryProcLocal_x2APIC{ 101 | APICStructHeader h; 102 | uint16_t reserved; 103 | uint32_t x2APIC_ID; 104 | uint32_t Flags; 105 | uint32_t ProcUID; 106 | } __attribute__((packed)) EntryProcLocal_x2APIC; 107 | 108 | int init_smp(void); 109 | int start_smp(void); 110 | void ap_entry64(uint8_t cpu); 111 | void recv_msg(char * str); 112 | void send_msg(char * str); 113 | int bsp_printf(const char * format, ...); 114 | 115 | #endif -------------------------------------------------------------------------------- /spinlock.asm: -------------------------------------------------------------------------------- 1 | global acquire_lock 2 | global release_lock 3 | 4 | section .text 5 | 6 | acquire_lock: 7 | mov eax,0 8 | lock bts [ecx],eax 9 | jc spin 10 | ret 11 | 12 | spin: 13 | pause 14 | test dword [ecx],1 15 | jnz spin 16 | jmp acquire_lock 17 | 18 | release_lock: 19 | mov dword [ecx],0 20 | ret -------------------------------------------------------------------------------- /spinlock.h: -------------------------------------------------------------------------------- 1 | #ifndef _SPINLOCK_ 2 | #define _SPINLOCK_ 3 | 4 | typedef uint32_t lock_t; 5 | 6 | void acquire_lock(lock_t * lock); 7 | void release_lock(lock_t * lock); 8 | 9 | #endif -------------------------------------------------------------------------------- /string.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "string.h" 3 | 4 | int sprint_uintx(char * str, uint64_t n){ 5 | char num_str[256]; 6 | num_str[255] = 0; 7 | 8 | int i = 255, digit; 9 | if(n == 0){ 10 | *str = '0'; 11 | return 1; 12 | } 13 | while(n > 0){ 14 | --i; 15 | digit = n % 16; 16 | if(digit < 10){ 17 | num_str[i] = digit + '0'; 18 | } 19 | else{ 20 | num_str[i] = digit - 10 + 'A'; 21 | } 22 | n /= 16; 23 | } 24 | char * num = num_str + i; 25 | int len = strlen(num); 26 | CopyMem(str, num, len + 1); 27 | 28 | return len; 29 | } 30 | 31 | int sprint_uint(char * str, uint64_t n, int base){ 32 | char num_str[256] = {0}; 33 | num_str[255] = 0; 34 | 35 | if(base == 16){ 36 | return sprint_uintx(str, n); 37 | } 38 | 39 | int i = 255; 40 | if(n == 0){ 41 | *str = '0'; 42 | return 1; 43 | } 44 | while(n > 0){ 45 | --i; 46 | num_str[i] = (n % base) + '0'; 47 | n /= base; 48 | } 49 | 50 | char * num = num_str + i; 51 | int len = strlen(num); 52 | CopyMem(str, num, len + 1); 53 | 54 | return len; 55 | } 56 | 57 | int strlen(const char * str){ 58 | int len = 0; 59 | while(*str++){ 60 | ++len; 61 | } 62 | 63 | return len; 64 | } 65 | 66 | int printf(const char * format, ...){ 67 | int ret; 68 | char str[256]; 69 | CHAR16 wstr[256]; 70 | va_list params; 71 | va_start(params, format); 72 | 73 | ret = vsprintf(str, format, params); 74 | str2wstr(wstr, str, 256); 75 | print(wstr); 76 | 77 | va_end(params); 78 | return ret; 79 | } 80 | 81 | int sprintf(char * str, const char * format, ...){ 82 | int ret; 83 | va_list params; 84 | va_start(params, format); 85 | 86 | ret = vsprintf(str, format, params); 87 | 88 | va_end(params); 89 | return ret; 90 | } 91 | 92 | int vsprintf(char * str, const char * format, va_list params){ 93 | int written = 0; 94 | int amount; 95 | bool rejected_bad_specifier = false; 96 | int base; 97 | 98 | while(*format != 0){ 99 | if(*format != '%'){ 100 | print_c: 101 | amount = 1; 102 | while(format[amount] && format[amount] != '%'){ 103 | ++amount; 104 | } 105 | CopyMem(str, format, amount); 106 | format += amount; 107 | str += amount; 108 | written += amount; 109 | continue; 110 | } 111 | 112 | const char * format_start_at = format; 113 | 114 | if(*(++format) == '%'){ 115 | goto print_c; 116 | } 117 | 118 | if(rejected_bad_specifier){ 119 | bad_conversion: 120 | rejected_bad_specifier = true; 121 | format = format_start_at; 122 | goto print_c; 123 | } 124 | 125 | base = 0; 126 | switch(*format){ 127 | case 'c': { 128 | ++format; 129 | char c = (char)va_arg(params, int); 130 | CopyMem(str, &c, sizeof(c)); 131 | ++str; 132 | ++written; 133 | break; 134 | } 135 | case 's': { 136 | ++format; 137 | const char * s = va_arg(params, const char*); 138 | int len = strlen(s); 139 | CopyMem(str, s, len); 140 | str += len; 141 | written += len; 142 | break; 143 | } 144 | case 'x': 145 | base += 6; 146 | case 'u': 147 | base += 8; 148 | case 'b': 149 | base += 2; 150 | 151 | ++format; 152 | uint64_t n = va_arg(params, uint64_t); 153 | int len = sprint_uint(str, n, base); 154 | str += len; 155 | written += len; 156 | break; 157 | default: 158 | goto bad_conversion; 159 | } 160 | } 161 | 162 | *str = 0; 163 | return written; 164 | } -------------------------------------------------------------------------------- /string.h: -------------------------------------------------------------------------------- 1 | #ifndef _STRING_ 2 | #define _STRING_ 3 | 4 | #include 5 | #include "lib_uefi.h" 6 | 7 | int strlen(const char * str); 8 | int printf(const char * format, ...); 9 | int sprintf(char * str, const char * format, ...); 10 | int vsprintf(char * str, const char * format, va_list params); 11 | 12 | #endif -------------------------------------------------------------------------------- /vm_setup.h: -------------------------------------------------------------------------------- 1 | #ifndef _VMCS_ 2 | #define _VMCS_ 3 | 4 | #include "vmx_api.h" 5 | 6 | #define EPT_ENABLED 0 7 | 8 | typedef struct{ 9 | bool pse; 10 | bool ept; 11 | bool ug; 12 | bool vpid; 13 | bool ept_cap_2MB_page; 14 | bool ept_cap_1GB_page; 15 | } FEATURES; 16 | 17 | extern FEATURES features; 18 | 19 | void vmcs_init(HVM * hvm); 20 | int ept_init(HVM * hvm); 21 | void vm_start(void); 22 | uint32_t init_control_field(uint32_t ctl, uint32_t msr); 23 | void set_guest_selector(uint64_t gdt_base, uint32_t reg, uint64_t sel); 24 | 25 | #endif -------------------------------------------------------------------------------- /vmx_api.asm: -------------------------------------------------------------------------------- 1 | extern vmexit_handler 2 | 3 | global vmx_supported 4 | global vmx_ug_supported 5 | global vmx_ept_supported 6 | global vmx_vpid_supported 7 | global vmx_get_revision_and_struct_size 8 | global vmx_enable 9 | global vmx_switch_to_root_op 10 | global vmx_vmcs_activate 11 | global vmx_read 12 | global vmx_write 13 | global vmx_launch 14 | global vmx_exit 15 | global vmx_ret 16 | global vmx_enable_a20_line 17 | global vmx_disable_a20_line 18 | 19 | section .text 20 | 21 | vmx_supported: 22 | mov eax,1 23 | cpuid 24 | xor rax,rax 25 | bt ecx,5 26 | jnc vmx_s_end 27 | inc eax 28 | vmx_s_end: 29 | ret 30 | 31 | vmx_ug_supported: 32 | mov ecx,48bh ; IA32_VMX_PROCBASED_CTLS2 33 | mov r8,7 ; Unrestricted guest 34 | jmp vmx_check_capability_msr 35 | 36 | vmx_ept_supported: 37 | mov ecx,48bh ; IA32_VMX_PROCBASED_CTLS2 38 | mov r8,1 39 | jmp vmx_check_capability_msr 40 | 41 | vmx_vpid_supported: 42 | mov ecx,48bh ; IA32_VMX_PROCBASED_CTLS2 43 | mov r8,5 44 | jmp vmx_check_capability_msr 45 | 46 | vmx_check_capability_msr: 47 | rdmsr 48 | xor rax,rax 49 | bt rdx,r8 50 | jnc vmx_chk_cap_end 51 | inc eax 52 | vmx_chk_cap_end: 53 | ret 54 | 55 | 56 | vmx_get_revision_and_struct_size: 57 | push rdx 58 | push rcx 59 | mov ecx,480h 60 | rdmsr 61 | pop rcx 62 | mov [rcx],eax 63 | pop rcx 64 | and edx,0fffh 65 | mov [rcx],edx 66 | ret 67 | 68 | vmx_enable: 69 | mov rax,cr4 70 | bts rax,13 71 | mov cr4,rax 72 | mov rax,cr0 73 | bts rax,5 74 | mov cr0,rax 75 | ret 76 | 77 | vmx_switch_to_root_op: 78 | xor rax,rax 79 | push rcx 80 | vmxon [rsp] 81 | jc vmx_stro_end 82 | inc eax 83 | vmx_stro_end: 84 | pop rcx 85 | ret 86 | 87 | vmx_vmcs_activate: 88 | xor rax,rax 89 | push rcx 90 | vmclear [rsp] 91 | jc vmx_va_end 92 | vmptrld [rsp] 93 | jc vmx_va_end 94 | inc eax 95 | vmx_va_end: 96 | pop rcx 97 | ret 98 | 99 | vmx_read: 100 | vmread rax,rcx 101 | ret 102 | 103 | vmx_write: 104 | vmwrite rcx,rdx 105 | ret 106 | 107 | vmx_launch: 108 | vmlaunch 109 | ret 110 | 111 | vmx_exit: 112 | push r15 113 | push r14 114 | push r13 115 | push r12 116 | push r11 117 | push r10 118 | push r9 119 | push r8 120 | push rdi 121 | push rsi 122 | push rbp 123 | push rbp ; rsp 124 | push rbx 125 | push rdx 126 | push rcx 127 | push rax 128 | mov rcx,rsp 129 | sub rsp,28h 130 | call vmexit_handler 131 | add rsp,28h 132 | pop rax 133 | pop rcx 134 | pop rdx 135 | pop rbx 136 | pop rbp ; rsp 137 | pop rbp 138 | pop rsi 139 | pop rdi 140 | pop r8 141 | pop r9 142 | pop r10 143 | pop r11 144 | pop r12 145 | pop r13 146 | pop r14 147 | pop r15 148 | vmresume 149 | ret 150 | 151 | vmx_ret: 152 | pop rbp 153 | ret 154 | 155 | WaitKBC: 156 | mov cx,0ffffh 157 | A20L: 158 | in al,64h 159 | test al,2 160 | loopnz A20L 161 | ret 162 | 163 | vmx_enable_a20_line: 164 | call WaitKBC 165 | mov al,0d1h 166 | out 64h,al 167 | call WaitKBC 168 | mov al,0dfh ; use 0dfh to enable and 0ddh to disable. 169 | out 60h,al 170 | ret 171 | 172 | vmx_disable_a20_line: 173 | call WaitKBC 174 | mov al,0d1h 175 | out 64h,al 176 | call WaitKBC 177 | mov al,0ddh ; use 0dfh to enable and 0ddh to disable. 178 | out 60h,al 179 | ret -------------------------------------------------------------------------------- /vmx_api.c: -------------------------------------------------------------------------------- 1 | #include "regs.h" 2 | #include "vmx_api.h" 3 | 4 | int vmx_guest_efer_supported(void){ 5 | uint64_t entry_ctls = get_msr(MSR_IA32_VMX_ENTRY_CTLS); 6 | uint64_t exit_ctls = get_msr(MSR_IA32_VMX_EXIT_CTLS); 7 | 8 | if(entry_ctls & (1ULL << 55)){ 9 | entry_ctls = get_msr(MSR_IA32_VMX_TRUE_ENTRY_CTLS); 10 | } 11 | if(exit_ctls & (1ULL << 55)){ 12 | exit_ctls = get_msr(MSR_IA32_VMX_TRUE_EXIT_CTLS); 13 | } 14 | 15 | return (entry_ctls & (1ULL << 47)) && (exit_ctls & (1ULL << 52)); 16 | } -------------------------------------------------------------------------------- /vmx_emu.asm: -------------------------------------------------------------------------------- 1 | global emu_rdmsr 2 | global emu_wrmsr 3 | global emu_cpuid 4 | 5 | section .text 6 | 7 | emu_rdmsr: 8 | mov r9,rdx 9 | rdmsr 10 | mov [r9],rdx 11 | mov [r8],rax 12 | ret 13 | 14 | emu_wrmsr: 15 | mov rax,r8 16 | wrmsr 17 | ret 18 | 19 | emu_cpuid: 20 | mov r10,rcx 21 | mov r11,rdx 22 | mov rax,[r10] 23 | cpuid 24 | mov [r10],rax 25 | mov [r11],rbx 26 | mov [r8],rcx 27 | mov [r9],rdx 28 | ret -------------------------------------------------------------------------------- /vmx_emu.h: -------------------------------------------------------------------------------- 1 | #ifndef _VMX_EMU_ 2 | #define _VMX_EMU_ 3 | 4 | #include 5 | 6 | void emu_rdmsr(uint64_t rcx, uint64_t * rdx, uint64_t * rax); 7 | void emu_wrmsr(uint64_t rcx, uint64_t rdx, uint64_t rax); 8 | void emu_mov_reg_cr3(uint64_t * reg, uint64_t cr3); 9 | void emu_cpuid(uint64_t * rax, uint64_t * rbx, uint64_t * rcx, uint64_t * rdx); 10 | 11 | #endif -------------------------------------------------------------------------------- /win8_ap_tramp.asm: -------------------------------------------------------------------------------- 1 | ; 16-bit real mode 2 | 0x1000: jmp 0x1640 3 | 0x1640: cli 4 | 0x1641: sub eax,eax 5 | 0x1644: mov ax,cs 6 | 0x1646: mov ds,ax 7 | 0x1648: shl eax,0x4 8 | 0x164c: mov edi,eax 9 | 0x164f: o32 lgdt [dword 0xc] ; limit & base at 0x100c - limit = 0x3F, base = 0x1018 10 | 0x1658: mov eax,cr0 11 | 0x165b: or eax,0x11 12 | 0x165f: mov cr0,eax 13 | 0x1662: mov ax,0x20 14 | 0x1665: mov ds,ax ; ds = 0x20 15 | 0x1667: jmp dword far [edi+0x60] ; dst addr stored at 0x1060: 0x30:0x166c, cs = 0x30 (from 0x1064) 16 | ; 32-bit protected mode 17 | 0x166c: mov eax,[edi+0xa8] ; CR4 value stored at 0x10a8 18 | 0x1672: mov cr4,eax 19 | 0x1675: mov eax,[edi+0x58] ; CR3 value stored at 0x1058 20 | 0x1678: mov cr3,eax 21 | 0x167b: test dword [edi+0x8],0x1 ; if (*(uint32_t*)0x1008 & 1 == 1) 22 | 0x1682: jz 0x1690 23 | 0x1684: mov ecx,0x1a0 ; IA32_MISC_ENABLE 24 | 0x1689: rdmsr 25 | 0x168b: and edx,0xfffffffb ; mask 34th bit (Execute Disable Bit) - enabling XD bit feature for data only pages 26 | 0x168e: wrmsr 27 | 0x1690: mov ecx,0xc0000080 ; IA32_EFER 28 | 0x1695: rdmsr 29 | 0x1697: or eax,[edi+0x88] ; EFER low or mask at 0x1088: SCE (SYSCALL enable), LME (Long mode enable), NXE (XD Bit Enable) 30 | 0x169d: or edx,[edi+0x8c] ; EFER high or mask at 0x108c: reserved (0x0) 31 | 0x16a3: wrmsr 32 | 0x16a5: mov eax,[edi+0x90] ; CR0 value stored at 0x1090 33 | 0x16ab: mov cr0,eax 34 | 0x16ae: jmp dword far [edi+0x66] ; dst addr stored at 0x1066: 0x10:0x16b1, cs = 0x10 (from 0x106A) 35 | ; 64-bit long mode 36 | 0x16b1: mov edi,edi 37 | 0x16b3: mov rcx,[rdi+0x70] ; kernel entry point address stored at 0x1070, rcx = *0x1070 38 | 0x16b7: mov rax,[rdi+0xa0] ; rax = *0x10a0 39 | 0x16be: mov rdi,[rdi+0x78] ; rdi = *0x1078 40 | 0x16c2: jmp rcx 41 | --------------------------------------------------------------------------------