Commit 93996cf7 authored by longpanda's avatar longpanda
Browse files

1. Optimization for WIMBOOT mode.

2. Add WIMBOOT for UEFI mode.
parent ca62128f
VERSION := v2.7.3
OBJECTS := prefix.o startup.o callback.o main.o vsprintf.o string.o peloader.o
OBJECTS += int13.o vdisk.o cpio.o stdio.o lznt1.o xca.o die.o efi.o efimain.o
OBJECTS += efiguid.o efifile.o efipath.o efiboot.o efiblock.o cmdline.o
OBJECTS += wimpatch.o huffman.o lzx.o wim.o wimfile.o pause.o sha1.o cookie.o
OBJECTS += paging.o memmap.o
OBJECTS_i386 := $(patsubst %.o,%.i386.o,$(OBJECTS))
OBJECTS_x86_64 := $(patsubst %.o,%.x86_64.o,$(OBJECTS))
OBJECTS_i386_x86_64 := $(patsubst %.o,%.i386.x86_64.o,$(OBJECTS))
HEADERS := $(wildcard *.h)
HOST_CC := $(CC)
AS := $(AS)
ECHO := echo
OBJCOPY := objcopy
AR := ar
RANLIB := ranlib
CP := cp
RM := rm
GCAB := gcab
PESIGN := pesign
DIFF := diff
CUT := cut
BINUTILS_DIR := /usr
BFD_DIR := $(BINUTILS_DIR)
ZLIB_DIR := /usr
HOST_CFLAGS += -Wall -W -Werror
CFLAGS += -Os -ffreestanding -Wall -W -Werror -nostdinc -I. -fshort-wchar
CFLAGS += -DVERSION="\"$(VERSION)\""
CFLAGS_i386 += -m32 -march=i386 -malign-double -fno-pic
CFLAGS_x86_64 += -m64 -mno-red-zone -fpie
# Enable stack protection if available
#
SPG_TEST = $(CC) -fstack-protector-strong -mstack-protector-guard=global \
-x c -c /dev/null -o /dev/null >/dev/null 2>&1
SPG_FLAGS := $(shell $(SPG_TEST) && $(ECHO) '-fstack-protector-strong ' \
'-mstack-protector-guard=global')
CFLAGS += $(SPG_FLAGS)
# Inhibit unwanted debugging information
CFI_TEST = $(CC) -fno-dwarf2-cfi-asm -fno-exceptions -fno-unwind-tables \
-fno-asynchronous-unwind-tables -x c -c /dev/null \
-o /dev/null >/dev/null 2>&1
CFI_FLAGS := $(shell $(CFI_TEST) && \
$(ECHO) '-fno-dwarf2-cfi-asm -fno-exceptions ' \
'-fno-unwind-tables -fno-asynchronous-unwind-tables')
WORKAROUND_CFLAGS += $(CFI_FLAGS)
# Add -maccumulate-outgoing-args if required by this version of gcc
MS_ABI_TEST_CODE := extern void __attribute__ (( ms_abi )) ms_abi(); \
void sysv_abi ( void ) { ms_abi(); }
MS_ABI_TEST = $(ECHO) '$(MS_ABI_TEST_CODE)' | \
$(CC) -m64 -mno-accumulate-outgoing-args -x c -c - -o /dev/null \
>/dev/null 2>&1
MS_ABI_FLAGS := $(shell $(MS_ABI_TEST) || $(ECHO) '-maccumulate-outgoing-args')
WORKAROUND_CFLAGS += $(MS_ABI_FLAGS)
# Inhibit warnings from taking address of packed struct members
WNAPM_TEST = $(CC) -Wno-address-of-packed-member -x c -c /dev/null \
-o /dev/null >/dev/null 2>&1
WNAPM_FLAGS := $(shell $(WNAPM_TEST) && \
$(ECHO) '-Wno-address-of-packed-member')
WORKAROUND_CFLAGS += $(WNAPM_FLAGS)
# Inhibit LTO
LTO_TEST = $(CC) -fno-lto -x c -c /dev/null -o /dev/null >/dev/null 2>&1
LTO_FLAGS := $(shell $(LTO_TEST) && $(ECHO) '-fno-lto')
WORKAROUND_CFLAGS += $(LTO_FLAGS)
CFLAGS += $(WORKAROUND_CFLAGS)
CFLAGS += $(EXTRA_CFLAGS)
ifneq ($(DEBUG),)
CFLAGS += -DDEBUG=$(DEBUG)
endif
CFLAGS += -include compiler.h
###############################################################################
#
# Final targets
all : wimboot wimboot.i386 wimboot.x86_64 wimboot.cab
wimboot : wimboot.x86_64 Makefile
$(CP) $< $@
$(CP) $@ ../$@
wimboot.%.elf : prefix.%.o lib.%.a script.lds Makefile
$(LD) -m elf_$* -T script.lds -o $@ -q -Map wimboot.$*.map \
prefix.$*.o lib.$*.a
wimboot.%.unsigned : wimboot.%.elf efireloc Makefile
$(OBJCOPY) -Obinary $< $@
./efireloc $< $@
wimboot.%.unsigned.hash : wimboot.%.unsigned Makefile
$(PESIGN) -h -i $< | $(CUT) -d" " -f2- > $@
wimboot.%.efi : wimboot.%.unsigned Makefile
$(CP) $< $@
wimboot.%.efi.hash : wimboot.%.efi Makefile
$(PESIGN) -h -i $< | $(CUT) -d" " -f2- > $@
wimboot.% : wimboot.%.efi wimboot.%.efi.hash wimboot.%.unsigned.hash Makefile
$(DIFF) wimboot.$*.efi.hash wimboot.$*.unsigned.hash
$(CP) $< $@
wimboot.cab : wimboot.i386.efi wimboot.x86_64.efi Makefile
$(GCAB) -n -c $@ wimboot.i386.efi wimboot.x86_64.efi
###############################################################################
#
# i386 objects
%.i386.s : %.S $(HEADERS) Makefile
$(CC) $(CFLAGS) $(CFLAGS_i386) -DASSEMBLY -Ui386 -E $< -o $@
%.i386.s : %.c $(HEADERS) Makefile
$(CC) $(CFLAGS) $(CFLAGS_i386) -S $< -o $@
%.i386.o : %.i386.s i386.i Makefile
$(AS) --32 i386.i $< -o $@
lib.i386.a : $(OBJECTS_i386) Makefile
$(RM) -f $@
$(AR) r $@ $(OBJECTS_i386)
$(RANLIB) $@
###############################################################################
#
# i386 objects to be linked into an x86_64 binary
%.i386.x86_64.raw.o : %.i386.s i386.i Makefile
$(AS) --64 i386.i $< -o $@
%.i386.x86_64.o : %.i386.x86_64.raw.o Makefile
$(OBJCOPY) --prefix-symbols=__i386_ $< $@
###############################################################################
#
# x86_64 objects
%.x86_64.s : %.S $(HEADERS) Makefile
$(CC) $(CFLAGS) $(CFLAGS_x86_64) -DASSEMBLY -Ui386 -E $< -o $@
%.x86_64.s : %.c $(HEADERS) Makefile
$(CC) $(CFLAGS) $(CFLAGS_x86_64) -S $< -o $@
%.x86_64.o : %.x86_64.s x86_64.i Makefile
$(AS) --64 x86_64.i $< -o $@
lib.x86_64.a : $(OBJECTS_x86_64) $(OBJECTS_i386_x86_64) Makefile
$(RM) -f $@
$(AR) r $@ $(OBJECTS_x86_64) $(OBJECTS_i386_x86_64)
$(RANLIB) $@
###############################################################################
#
# EFI relocator
EFIRELOC_CFLAGS := -I$(BINUTILS_DIR)/include -I$(BFD_DIR)/include \
-I$(ZLIB_DIR)/include -idirafter .
EFIRELOC_LDFLAGS := -L$(BINUTILS_DIR)/lib -L$(BFD_DIR)/lib -L$(ZLIB_DIR)/lib \
-lbfd -ldl -liberty -lz -Wl,--no-warn-search-mismatch
efireloc : efireloc.c Makefile
$(CC) $(HOST_CFLAGS) $(EFIRELOC_CFLAGS) $< $(EFIRELOC_LDFLAGS) -o $@
###############################################################################
#
# Cleanup
clean :
$(RM) -f *.s *.o *.a *.elf *.map
$(RM) -f efireloc
$(RM) -f wimboot wimboot.i386 wimboot.x86_64 ../wimboot
$(RM) -f wimboot.i386.unsigned wimboot.x86_64.unsigned
$(RM) -f wimboot.i386.efi wimboot.x86_64.efi wimboot.cab
#ifndef _ASSERT_H
#define _ASSERT_H
/*
* Copyright (C) 2014 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/**
* @file
*
* Assertions
*
*/
#include "wimboot.h"
#define assert(x) do { \
if ( DEBUG && ! (x) ) { \
die ( "Assertion failed at %s line %d: %s\n", \
__FILE__, __LINE__, #x ); \
} \
} while ( 0 )
#endif /* _ASSERT_H */
#ifndef _BOOTAPP_H
#define _BOOTAPP_H
/*
* Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/**
* @file
*
* Boot application data structures
*
*/
#include <stdint.h>
/** A segment:offset address */
struct segoff {
/** Offset */
uint16_t offset;
/** Segment */
uint16_t segment;
} __attribute__ (( packed ));
/** A GUID */
struct guid {
/** 8 hex digits, big-endian */
uint32_t a;
/** 2 hex digits, big-endian */
uint16_t b;
/** 2 hex digits, big-endian */
uint16_t c;
/** 2 hex digits, big-endian */
uint16_t d;
/** 12 hex digits, big-endian */
uint8_t e[6];
} __attribute__ (( packed ));
/** Real-mode callback parameters */
struct bootapp_callback_params {
/** Vector */
union {
/** Interrupt number */
uint32_t interrupt;
/** Segment:offset address of real-mode function */
struct segoff function;
} vector;
/** %eax value */
union {
struct {
uint8_t al;
uint8_t ah;
} __attribute__ (( packed ));
uint16_t ax;
uint32_t eax;
};
/** %ebx value */
union {
struct {
uint8_t bl;
uint8_t bh;
} __attribute__ (( packed ));
uint16_t bx;
uint32_t ebx;
};
/** %ecx value */
union {
struct {
uint8_t cl;
uint8_t ch;
} __attribute__ (( packed ));
uint16_t cx;
uint32_t ecx;
};
/** %edx value */
union {
struct {
uint8_t dl;
uint8_t dh;
} __attribute__ (( packed ));
uint16_t dx;
uint32_t edx;
};
/** Placeholder (for %esp?) */
uint32_t unused_esp;
/** Placeholder (for %ebp?) */
uint32_t unused_ebp;
/** %esi value */
union {
uint16_t si;
uint32_t esi;
};
/** %edi value */
union {
uint16_t di;
uint32_t edi;
};
/** Placeholder (for %cs?) */
uint32_t unused_cs;
/** %ds value */
uint32_t ds;
/** Placeholder (for %ss?) */
uint32_t unused_ss;
/** %es value */
uint32_t es;
/** %fs value */
uint32_t fs;
/** %gs value */
uint32_t gs;
/** eflags value */
uint32_t eflags;
} __attribute__ (( packed ));
/** eflags bits */
enum eflags {
CF = ( 1 << 0 ),
PF = ( 1 << 2 ),
AF = ( 1 << 4 ),
ZF = ( 1 << 6 ),
SF = ( 1 << 7 ),
OF = ( 1 << 11 ),
};
/** Real-mode callback function table */
struct bootapp_callback_functions {
/**
* Call an arbitrary real-mode interrupt
*
* @v params Parameters
*/
void ( * call_interrupt ) ( struct bootapp_callback_params *params );
/**
* Call an arbitrary real-mode function
*
* @v params Parameters
*/
void ( * call_real ) ( struct bootapp_callback_params *params );
} __attribute__ (( packed ));
/** Real-mode callbacks */
struct bootapp_callback {
/** Real-mode callback function table */
struct bootapp_callback_functions *fns;
/** Drive number for INT13 calls */
uint32_t drive;
} __attribute__ (( packed ));
/** Boot application descriptor */
struct bootapp_descriptor {
/** Signature */
char signature[8];
/** Version */
uint32_t version;
/** Total length */
uint32_t len;
/** COFF machine type */
uint32_t arch;
/** Reserved */
uint32_t reserved_0x14;
/** Loaded PE image base address */
void *pe_base;
/** Reserved */
uint32_t reserved_0x1c;
/** Length of loaded PE image */
uint32_t pe_len;
/** Offset to memory descriptor */
uint32_t memory;
/** Offset to boot application entry descriptor */
uint32_t entry;
/** Offset to ??? */
uint32_t xxx;
/** Offset to callback descriptor */
uint32_t callback;
/** Offset to pointless descriptor */
uint32_t pointless;
/** Reserved */
uint32_t reserved_0x38;
} __attribute__ (( packed ));
/** "BOOT APP" magic signature */
#define BOOTAPP_SIGNATURE "BOOT APP"
/** Boot application descriptor version */
#define BOOTAPP_VERSION 2
/** i386 architecture */
#define BOOTAPP_ARCH_I386 0x014c
/** Memory region descriptor */
struct bootapp_memory_region {
/** Reserved (for struct list_head?) */
uint8_t reserved[8];
/** Start page address */
uint64_t start_page;
/** Reserved */
uint8_t reserved_0x10[8];
/** Number of pages */
uint64_t num_pages;
/** Reserved */
uint8_t reserved_0x20[4];
/** Flags */
uint32_t flags;
} __attribute__ (( packed ));
/** Memory descriptor */
struct bootapp_memory_descriptor {
/** Version */
uint32_t version;
/** Length of descriptor (excluding region descriptors) */
uint32_t len;
/** Number of regions */
uint32_t num_regions;
/** Length of each region descriptor */
uint32_t region_len;
/** Length of reserved area at start of each region descriptor */
uint32_t reserved_len;
} __attribute__ (( packed ));
/** Boot application memory descriptor version */
#define BOOTAPP_MEMORY_VERSION 1
/** Boot application entry descriptor */
struct bootapp_entry_descriptor {
/** Signature */
char signature[8];
/** Flags */
uint32_t flags;
/** GUID */
struct guid guid;
/** Reserved */
uint8_t reserved[16];
} __attribute__ (( packed ));
/** ??? */
struct bootapp_entry_wtf1_descriptor {
/** Flags */
uint32_t flags;
/** Length of descriptor */
uint32_t len;
/** Total length of following descriptors within BTAPENT */
uint32_t extra_len;
/** Reserved */
uint8_t reserved[12];
} __attribute__ (( packed ));
/** ??? */
struct bootapp_entry_wtf2_descriptor {
/** GUID */
struct guid guid;
} __attribute__ (( packed ));
/** ??? */
struct bootapp_entry_wtf3_descriptor {
/** Flags */
uint32_t flags;
/** Reserved */
uint32_t reserved_0x04;
/** Length of descriptor */
uint32_t len;
/** Reserved */
uint32_t reserved_0x0c;
/** Boot partition offset (in bytes) */
uint32_t boot_partition_offset;
/** Reserved */
uint8_t reserved_0x14[16];
/** MBR signature present? */
uint32_t xxx;
/** MBR signature */
uint32_t mbr_signature;
/** Reserved */
uint8_t reserved_0x2c[26];
} __attribute__ (( packed ));
/** "BTAPENT" magic signature */
#define BOOTAPP_ENTRY_SIGNATURE "BTAPENT\0"
/** Boot application entry flags
*
* pxeboot, etftboot, and fatboot all use a value of 0x21; I have no
* idea what it means.
*/
#define BOOTAPP_ENTRY_FLAGS 0x21
/** Boot application callback descriptor */
struct bootapp_callback_descriptor {
/** Real-mode callbacks */
struct bootapp_callback *callback;
/** Reserved */
uint32_t reserved;
} __attribute__ (( packed ));
/** Boot application pointless descriptor */
struct bootapp_pointless_descriptor {
/** Version */
uint32_t version;
/** Reserved */
uint8_t reserved[24];
} __attribute__ (( packed ));
/** Boot application pointless descriptor version */
#define BOOTAPP_POINTLESS_VERSION 1
#endif /* _BOOTAPP_H */
#ifndef _BITS_BYTESWAP_H
#define _BITS_BYTESWAP_H
/** @file
*
* Byte-order swapping functions
*
*/
#include <stdint.h>
static inline __attribute__ (( always_inline, const )) uint16_t
__bswap_variable_16 ( uint16_t x ) {
__asm__ ( "xchgb %b0,%h0" : "=Q" ( x ) : "0" ( x ) );
return x;
}
static inline __attribute__ (( always_inline )) void
__bswap_16s ( uint16_t *x ) {
__asm__ ( "rorw $8, %0" : "+m" ( *x ) );
}
static inline __attribute__ (( always_inline, const )) uint32_t
__bswap_variable_32 ( uint32_t x ) {
__asm__ ( "bswapl %k0" : "=r" ( x ) : "0" ( x ) );
return x;
}
static inline __attribute__ (( always_inline )) void
__bswap_32s ( uint32_t *x ) {
__asm__ ( "bswapl %k0" : "=r" ( *x ) : "0" ( *x ) );
}
#ifdef __x86_64__
static inline __attribute__ (( always_inline, const )) uint64_t
__bswap_variable_64 ( uint64_t x ) {
__asm__ ( "bswapq %q0" : "=r" ( x ) : "0" ( x ) );
return x;
}
#else /* __x86_64__ */
static inline __attribute__ (( always_inline, const )) uint64_t
__bswap_variable_64 ( uint64_t x ) {
uint32_t in_high = ( x >> 32 );
uint32_t in_low = ( x & 0xffffffffUL );
uint32_t out_high;
uint32_t out_low;
__asm__ ( "bswapl %0\n\t"
"bswapl %1\n\t"
"xchgl %0,%1\n\t"
: "=r" ( out_high ), "=r" ( out_low )
: "0" ( in_high ), "1" ( in_low ) );
return ( ( ( ( uint64_t ) out_high ) << 32 ) |
( ( uint64_t ) out_low ) );
}
#endif /* __x86_64__ */
static inline __attribute__ (( always_inline )) void
__bswap_64s ( uint64_t *x ) {
*x = __bswap_variable_64 ( *x );
}
/**
* Byte-swap a 16-bit constant
*
* @v value Constant value
* @ret swapped Byte-swapped value
*/
#define __bswap_constant_16( value ) \
( ( ( (value) & 0x00ff ) << 8 ) | \
( ( (value) & 0xff00 ) >> 8 ) )
/**
* Byte-swap a 32-bit constant
*
* @v value Constant value
* @ret swapped Byte-swapped value
*/
#define __bswap_constant_32( value ) \
( ( ( (value) & 0x000000ffUL ) << 24 ) | \
( ( (value) & 0x0000ff00UL ) << 8 ) | \
( ( (value) & 0x00ff0000UL ) >> 8 ) | \
( ( (value) & 0xff000000UL ) >> 24 ) )
/**
* Byte-swap a 64-bit constant
*
* @v value Constant value
* @ret swapped Byte-swapped value
*/
#define __bswap_constant_64( value ) \
( ( ( (value) & 0x00000000000000ffULL ) << 56 ) | \
( ( (value) & 0x000000000000ff00ULL ) << 40 ) | \
( ( (value) & 0x0000000000ff0000ULL ) << 24 ) | \
( ( (value) & 0x00000000ff000000ULL ) << 8 ) | \
( ( (value) & 0x000000ff00000000ULL ) >> 8 ) | \
( ( (value) & 0x0000ff0000000000ULL ) >> 24 ) | \
( ( (value) & 0x00ff000000000000ULL ) >> 40 ) | \
( ( (value) & 0xff00000000000000ULL ) >> 56 ) )
/**
* Byte-swap a 16-bit value
*
* @v value Value
* @ret swapped Byte-swapped value
*/
#define __bswap_16( value ) \
( __builtin_constant_p (value) ? \
( ( uint16_t ) __bswap_constant_16 ( ( uint16_t ) (value) ) ) \
: __bswap_variable_16 (value) )
#define bswap_16( value ) __bswap_16 (value)
/**
* Byte-swap a 32-bit value
*
* @v value Value
* @ret swapped Byte-swapped value
*/
#define __bswap_32( value ) \
( __builtin_constant_p (value) ? \
( ( uint32_t ) __bswap_constant_32 ( ( uint32_t ) (value) ) ) \
: __bswap_variable_32 (value) )
#define bswap_32( value ) __bswap_32 (value)
/**
* Byte-swap a 64-bit value
*
* @v value Value
* @ret swapped Byte-swapped value
*/
#define __bswap_64( value ) \
( __builtin_constant_p (value) ? \
( ( uint64_t ) __bswap_constant_64 ( ( uint64_t ) (value) ) ) \
: __bswap_variable_64 (value) )
#define bswap_64( value ) __bswap_64 (value)
#define __cpu_to_leNN( bits, value ) (value)
#define __cpu_to_beNN( bits, value ) __bswap_ ## bits (value)
#define __leNN_to_cpu( bits, value ) (value)
#define __beNN_to_cpu( bits, value ) __bswap_ ## bits (value)
#define __cpu_to_leNNs( bits, ptr ) do { } while ( 0 )
#define __cpu_to_beNNs( bits, ptr ) __bswap_ ## bits ## s (ptr)
#define __leNN_to_cpus( bits, ptr ) do { } while ( 0 )
#define __beNN_to_cpus( bits, ptr ) __bswap_ ## bits ## s (ptr)
#define cpu_to_le16( value ) __cpu_to_leNN ( 16, value )
#define cpu_to_le32( value ) __cpu_to_leNN ( 32, value )
#define cpu_to_le64( value ) __cpu_to_leNN ( 64, value )
#define cpu_to_be16( value ) __cpu_to_beNN ( 16, value )
#define cpu_to_be32( value ) __cpu_to_beNN ( 32, value )
#define cpu_to_be64( value ) __cpu_to_beNN ( 64, value )
#define le16_to_cpu( value ) __leNN_to_cpu ( 16, value )
#define le32_to_cpu( value ) __leNN_to_cpu ( 32, value )
#define le64_to_cpu( value ) __leNN_to_cpu ( 64, value )
#define be16_to_cpu( value ) __beNN_to_cpu ( 16, value )
#define be32_to_cpu( value ) __beNN_to_cpu ( 32, value )
#define be64_to_cpu( value ) __beNN_to_cpu ( 64, value )
#define cpu_to_le16s( ptr ) __cpu_to_leNNs ( 16, ptr )
#define cpu_to_le32s( ptr ) __cpu_to_leNNs ( 32, ptr )
#define cpu_to_le64s( ptr ) __cpu_to_leNNs ( 64, ptr )
#define cpu_to_be16s( ptr ) __cpu_to_beNNs ( 16, ptr )
#define cpu_to_be32s( ptr ) __cpu_to_beNNs ( 32, ptr )
#define cpu_to_be64s( ptr ) __cpu_to_beNNs ( 64, ptr )
#define le16_to_cpus( ptr ) __leNN_to_cpus ( 16, ptr )
#define le32_to_cpus( ptr ) __leNN_to_cpus ( 32, ptr )
#define le64_to_cpus( ptr ) __leNN_to_cpus ( 64, ptr )
#define be16_to_cpus( ptr ) __beNN_to_cpus ( 16, ptr )
#define be32_to_cpus( ptr ) __beNN_to_cpus ( 32, ptr )
#define be64_to_cpus( ptr ) __beNN_to_cpus ( 64, ptr )
#define htonll( value ) cpu_to_be64 (value)
#define ntohll( value ) be64_to_cpu (value)
#define htonl( value ) cpu_to_be32 (value)
#define ntohl( value ) be32_to_cpu (value)
#define htons( value ) cpu_to_be16 (value)
#define ntohs( value ) be16_to_cpu (value)
#endif /* _BITS_BYTESWAP_H */
/*
* Copyright (C) 2014 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/**
* @file
*
* Command line
*
*/
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "wimboot.h"
#include "cmdline.h"
/** Use raw (unpatched) BCD files */
int cmdline_rawbcd;
/** Use raw (unpatched) WIM files */
int cmdline_rawwim;
/** Inhibit debugging output */
int cmdline_quiet;
/** Allow graphical output from bootmgr/bootmgfw */
int cmdline_gui;
/** Pause before booting OS */
int cmdline_pause;
/** Pause without displaying any prompt */
int cmdline_pause_quiet;
/** Use linear (unpaged) memory model */
int cmdline_linear;
/** WIM boot index */
unsigned int cmdline_index;
int cmdline_vf_num;
char cmdline_vf_path[MAX_VF][64];
file_size_pf pfventoy_file_size;
file_read_pf pfventoy_file_read;
/**
* Process command line
*
* @v cmdline Command line
*/
void process_cmdline ( char *cmdline ) {
char *tmp = cmdline;
char *key;
char *value;
char *endp;
/* Do nothing if we have no command line */
if ( ( cmdline == NULL ) || ( cmdline[0] == '\0' ) )
return;
/* Parse command line */
while ( *tmp ) {
/* Skip whitespace */
while ( isspace ( *tmp ) )
tmp++;
/* Find value (if any) and end of this argument */
key = tmp;
value = NULL;
while ( *tmp ) {
if ( isspace ( *tmp ) ) {
*(tmp++) = '\0';
break;
} else if ( *tmp == '=' ) {
*(tmp++) = '\0';
value = tmp;
} else {
tmp++;
}
}
/* Process this argument */
if ( strcmp ( key, "rawbcd" ) == 0 ) {
cmdline_rawbcd = 1;
} else if ( strcmp ( key, "rawwim" ) == 0 ) {
cmdline_rawwim = 1;
} else if ( strcmp ( key, "gui" ) == 0 ) {
cmdline_gui = 1;
}
else if ((key[0] == 'v') && (key[1] == 'f') ) {
if (cmdline_vf_num >= MAX_VF)
die("Too many vf\n");
snprintf(cmdline_vf_path[cmdline_vf_num], 64, "%s", value);
cmdline_vf_num++;
}else if ( strcmp ( key, "pfsize" ) == 0 ) {
pfventoy_file_size = (file_size_pf)strtoul(value, &endp, 0);
} else if ( strcmp ( key, "pfread" ) == 0 ) {
pfventoy_file_read = (file_read_pf)strtoul(value, &endp, 0 );
}
else if ( strcmp ( key, "linear" ) == 0 ) {
cmdline_linear = 1;
} else if ( strcmp ( key, "quiet" ) == 0 ) {
cmdline_quiet = 1;
} else if ( strcmp ( key, "pause" ) == 0 ) {
cmdline_pause = 1;
if ( value && ( strcmp ( value, "quiet" ) == 0 ) )
cmdline_pause_quiet = 1;
} else if ( strcmp ( key, "index" ) == 0 ) {
if ( ( ! value ) || ( ! value[0] ) )
die ( "Argument \"index\" needs a value\n" );
cmdline_index = strtoul ( value, &endp, 0 );
if ( *endp )
die ( "Invalid index \"%s\"\n", value );
} else if ( strcmp ( key, "initrdfile" ) == 0 ) {
/* Ignore this keyword to allow for use with syslinux */
} else if ( key == cmdline ) {
/* Ignore unknown initial arguments, which may
* be the program name.
*/
} else {
die ( "Unrecognised argument \"%s%s%s\"\n", key,
( value ? "=" : "" ), ( value ? value : "" ) );
}
}
/* Show command line (after parsing "quiet" option) */
DBG ( "Command line: \"%s\" vf=%d pfsize=%p pfread=%p\n",
cmdline, cmdline_vf_num, pfventoy_file_size, pfventoy_file_read);
}
#ifndef _CMDLINE_H
#define _CMDLINE_H
/*
* Copyright (C) 2014 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/**
* @file
*
* Command line
*
*/
extern int cmdline_rawbcd;
extern int cmdline_rawwim;
extern int cmdline_quiet;
extern int cmdline_gui;
extern int cmdline_pause;
extern int cmdline_pause_quiet;
extern int cmdline_linear;
extern unsigned int cmdline_index;
extern void process_cmdline ( char *cmdline );
typedef int (*file_size_pf)(const char *path);
typedef int (*file_read_pf)(const char *path, int offset, int len, void *buf);
extern file_size_pf pfventoy_file_size;
extern file_read_pf pfventoy_file_read;
#define MAX_VF 16
extern char cmdline_vf_path[MAX_VF][64];
extern int cmdline_vf_num;
#endif /* _CMDLINE_H */
#ifndef _COMPILER_H
#define _COMPILER_H
/*
* Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/**
* @file
*
* Global compiler definitions
*
*/
/* Force visibility of all symbols to "hidden", i.e. inform gcc that
* all symbol references resolve strictly within our final binary.
* This avoids unnecessary PLT/GOT entries on x86_64.
*
* This is a stronger claim than specifying "-fvisibility=hidden",
* since it also affects symbols marked with "extern".
*/
#ifndef ASSEMBLY
#if __GNUC__ >= 4
#pragma GCC visibility push(hidden)
#endif
#endif /* ASSEMBLY */
#endif /* _COMPILER_H */
/*
* Copyright (C) 2021 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/**
* @file
*
* Stack cookie
*
*/
#include "wimboot.h"
/** Stack cookie */
unsigned long __stack_chk_guard;
/**
* Construct stack cookie value
*
*/
static __attribute__ (( noinline )) unsigned long make_cookie ( void ) {
union {
struct {
uint32_t eax;
uint32_t edx;
} __attribute__ (( packed ));
unsigned long tsc;
} u;
unsigned long cookie;
/* We have no viable source of entropy. Use the CPU timestamp
* counter, which will have at least some minimal randomness
* in the low bits by the time we are invoked.
*/
__asm__ ( "rdtsc" : "=a" ( u.eax ), "=d" ( u.edx ) );
cookie = u.tsc;
/* Ensure that the value contains a NUL byte, to act as a
* runaway string terminator. Construct the NUL using a shift
* rather than a mask, to avoid losing valuable entropy in the
* lower-order bits.
*/
cookie <<= 8;
return cookie;
}
/**
* Initialise stack cookie
*
* This function must not itself use stack guard
*/
void init_cookie ( void ) {
/* Set stack cookie value
*
* This function must not itself use stack protection, since
* the change in the stack guard value would trigger a false
* positive.
*
* There is unfortunately no way to annotate a function to
* exclude the use of stack protection. We must therefore
* rely on correctly anticipating the compiler's decision on
* the use of stack protection.
*/
__stack_chk_guard = make_cookie();
}
/**
* Abort on stack check failure
*
*/
void __stack_chk_fail ( void ) {
/* Abort program */
die ( "Stack check failed\n" );
}
/*
* Coverity modelling file
*
*/
typedef unsigned short wchar_t;
typedef void mbstate_t;
/* Inhibit use of built-in models for functions where Coverity's
* assumptions about the modelled function are incorrect for wimboot.
*/
int getchar ( void ) {
}
size_t wcrtomb ( char *buf, wchar_t wc, mbstate_t *ps ) {
}
/*
* Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/**
* @file
*
* CPIO archives
*
*/
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "wimboot.h"
#include "cpio.h"
/**
* Align CPIO length to nearest dword
*
* @v len Length
* @ret len Aligned length
*/
static size_t cpio_align ( size_t len ) {
return ( ( len + 0x03 ) & ~0x03 );
}
/**
* Parse CPIO field value
*
* @v field ASCII field
* @ret value Field value
*/
static unsigned long cpio_value ( const char *field ) {
char buf[9];
memcpy ( buf, field, ( sizeof ( buf ) - 1 ) );
buf[ sizeof ( buf ) - 1 ] = '\0';
return strtoul ( buf, NULL, 16 );
}
/**
* Extract files from CPIO archive
*
* @v data CPIO archive
* @v len Maximum length of CPIO archive
* @v file File handler
* @ret rc Return status code
*/
int cpio_extract ( void *data, size_t len,
int ( * file ) ( const char *name, void *data,
size_t len ) ) {
const struct cpio_header *cpio;
const uint32_t *pad;
const char *file_name;
void *file_data;
size_t file_name_len;
size_t file_len;
size_t cpio_len;
int rc;
while ( 1 ) {
/* Skip over any padding */
while ( len >= sizeof ( *pad ) ) {
pad = data;
if ( *pad )
break;
data += sizeof ( *pad );
len -= sizeof ( *pad );
}
/* Stop if we have reached the end of the archive */
if ( ! len )
return 0;
/* Sanity check */
if ( len < sizeof ( *cpio ) ) {
DBG ( "Truncated CPIO header\n" );
return -1;
}
cpio = data;
/* Check magic */
if ( memcmp ( cpio->c_magic, CPIO_MAGIC,
sizeof ( cpio->c_magic ) ) != 0 ) {
DBG ( "Bad CPIO magic\n" );
return -1;
}
/* Extract file parameters */
file_name = ( ( void * ) ( cpio + 1 ) );
file_name_len = cpio_value ( cpio->c_namesize );
file_data = ( data + cpio_align ( sizeof ( *cpio ) +
file_name_len ) );
file_len = cpio_value ( cpio->c_filesize );
cpio_len = ( file_data + file_len - data );
if ( cpio_len < len )
cpio_len = cpio_align ( cpio_len );
if ( cpio_len > len ) {
DBG ( "Truncated CPIO file\n" );
return -1;
}
/* If we reach the trailer, we're done */
if ( strcmp ( file_name, CPIO_TRAILER ) == 0 )
return 0;
/* Process file */
if ( ( rc = file ( file_name, file_data, file_len ) ) != 0 )
return rc;
/* Move to next file */
data += cpio_len;
len -= cpio_len;
}
}
#ifndef _CPIO_H
#define _CPIO_H
/*
* Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/**
* @file
*
* CPIO archives
*
*/
#include <stdint.h>
/** A CPIO archive header
*
* All field are hexadecimal ASCII numbers padded with '0' on the
* left to the full width of the field.
*/
struct cpio_header {
/** The string "070701" or "070702" */
char c_magic[6];
/** File inode number */
char c_ino[8];
/** File mode and permissions */
char c_mode[8];
/** File uid */
char c_uid[8];
/** File gid */
char c_gid[8];
/** Number of links */
char c_nlink[8];
/** Modification time */
char c_mtime[8];
/** Size of data field */
char c_filesize[8];
/** Major part of file device number */
char c_maj[8];
/** Minor part of file device number */
char c_min[8];
/** Major part of device node reference */
char c_rmaj[8];
/** Minor part of device node reference */
char c_rmin[8];
/** Length of filename, including final NUL */
char c_namesize[8];
/** Checksum of data field if c_magic is 070702, othersize zero */
char c_chksum[8];
} __attribute__ (( packed ));
/** CPIO magic */
#define CPIO_MAGIC "070701"
/** CPIO trailer */
#define CPIO_TRAILER "TRAILER!!!"
extern int cpio_extract ( void *data, size_t len,
int ( * file ) ( const char *name, void *data,
size_t len ) );
#endif /* _CPIO_H */
#ifndef _CTYPE_H
#define _CTYPE_H
/*
* Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/**
* @file
*
* Character types
*
*/
static inline int islower ( int c ) {
return ( ( c >= 'a' ) && ( c <= 'z' ) );
}
static inline int isupper ( int c ) {
return ( ( c >= 'A' ) && ( c <= 'Z' ) );
}
static inline int toupper ( int c ) {
if ( islower ( c ) )
c -= ( 'a' - 'A' );
return c;
}
extern int isspace ( int c );
#endif /* _CTYPE_H */
/*
* Copyright (C) 2014 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/**
* @file
*
* Fatal errors
*
*/
#include <stdarg.h>
#include <stdio.h>
#include "wimboot.h"
#include "efi.h"
/**
* Handle fatal errors
*
* @v fmt Error message format string
* @v ... Arguments
*/
void die ( const char *fmt, ... ) {
EFI_BOOT_SERVICES *bs;
EFI_RUNTIME_SERVICES *rs;
va_list args;
/* Print message */
va_start ( args, fmt );
vprintf ( fmt, args );
va_end ( args );
/* Reboot or exit as applicable */
if ( efi_systab ) {
/* Exit */
bs = efi_systab->BootServices;
bs->Exit ( efi_image_handle, EFI_LOAD_ERROR, 0, NULL );
printf ( "Failed to exit\n" );
rs = efi_systab->RuntimeServices;
rs->ResetSystem ( EfiResetWarm, 0, 0, NULL );
printf ( "Failed to reboot\n" );
} else {
/* Wait for keypress */
printf ( "Press a key to reboot..." );
getchar();
printf ( "\n" );
/* Reboot system */
reboot();
}
/* Should be impossible to reach this */
__builtin_unreachable();
}
/*
* Copyright (C) 2014 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/**
* @file
*
* EFI interface
*
*/
#include "wimboot.h"
#include "efi.h"
/** EFI system table */
EFI_SYSTEM_TABLE *efi_systab;
/** EFI image handle */
EFI_HANDLE efi_image_handle;
#ifndef _EFI_H
#define _EFI_H
/*
* Copyright (C) 2014 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/**
* @file
*
* EFI definitions
*
*/
/* EFIAPI definition */
#if __x86_64__
#define EFIAPI __attribute__ (( ms_abi ))
#else
#define EFIAPI
#endif
/* EFI headers rudely redefine NULL */
#undef NULL
#include "efi/Uefi.h"
#include "efi/Protocol/LoadedImage.h"
extern EFI_SYSTEM_TABLE *efi_systab;
extern EFI_HANDLE efi_image_handle;
extern EFI_GUID efi_block_io_protocol_guid;
extern EFI_GUID efi_device_path_protocol_guid;
extern EFI_GUID efi_graphics_output_protocol_guid;
extern EFI_GUID efi_loaded_image_protocol_guid;
extern EFI_GUID efi_simple_file_system_protocol_guid;
#endif /* _EFI_H */
/** @file
Root include file for Mde Package Base type modules
This is the include file for any module of type base. Base modules only use
types defined via this include file and can be ported easily to any
environment. There are a set of base libraries in the Mde Package that can
be used to implement base modules.
Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef __BASE_H__
#define __BASE_H__
//
// Include processor specific binding
//
#include "efi/ProcessorBind.h"
/**
Verifies the storage size of a given data type.
This macro generates a divide by zero error or a zero size array declaration in
the preprocessor if the size is incorrect. These are declared as "extern" so
the space for these arrays will not be in the modules.
@param TYPE The date type to determine the size of.
@param Size The expected size for the TYPE.
**/
#define VERIFY_SIZE_OF(TYPE, Size) extern UINT8 _VerifySizeof##TYPE[(sizeof(TYPE) == (Size)) / (sizeof(TYPE) == (Size))]
//
// Verify that ProcessorBind.h produced UEFI Data Types that are compliant with
// Section 2.3.1 of the UEFI 2.3 Specification.
//
VERIFY_SIZE_OF (BOOLEAN, 1);
VERIFY_SIZE_OF (INT8, 1);
VERIFY_SIZE_OF (UINT8, 1);
VERIFY_SIZE_OF (INT16, 2);
VERIFY_SIZE_OF (UINT16, 2);
VERIFY_SIZE_OF (INT32, 4);
VERIFY_SIZE_OF (UINT32, 4);
VERIFY_SIZE_OF (INT64, 8);
VERIFY_SIZE_OF (UINT64, 8);
VERIFY_SIZE_OF (CHAR8, 1);
VERIFY_SIZE_OF (CHAR16, 2);
//
// The Microsoft* C compiler can removed references to unreferenced data items
// if the /OPT:REF linker option is used. We defined a macro as this is a
// a non standard extension
//
#if defined(_MSC_EXTENSIONS) && !defined (MDE_CPU_EBC)
///
/// Remove global variable from the linked image if there are no references to
/// it after all compiler and linker optimizations have been performed.
///
///
#define GLOBAL_REMOVE_IF_UNREFERENCED __declspec(selectany)
#else
///
/// Remove the global variable from the linked image if there are no references
/// to it after all compiler and linker optimizations have been performed.
///
///
#define GLOBAL_REMOVE_IF_UNREFERENCED
#endif
//
// For symbol name in GNU assembly code, an extra "_" is necessary
//
#if defined(__GNUC__)
///
/// Private worker functions for ASM_PFX()
///
#define _CONCATENATE(a, b) __CONCATENATE(a, b)
#define __CONCATENATE(a, b) a ## b
///
/// The __USER_LABEL_PREFIX__ macro predefined by GNUC represents the prefix
/// on symbols in assembly language.
///
#define ASM_PFX(name) _CONCATENATE (__USER_LABEL_PREFIX__, name)
#endif
#if __APPLE__
//
// Apple extension that is used by the linker to optimize code size
// with assembly functions. Put at the end of your .S files
//
#define ASM_FUNCTION_REMOVE_IF_UNREFERENCED .subsections_via_symbols
#else
#define ASM_FUNCTION_REMOVE_IF_UNREFERENCED
#endif
#ifdef __CC_ARM
//
// Older RVCT ARM compilers don't fully support #pragma pack and require __packed
// as a prefix for the structure.
//
#define PACKED __packed
#else
#define PACKED
#endif
///
/// 128 bit buffer containing a unique identifier value.
/// Unless otherwise specified, aligned on a 64 bit boundary.
///
typedef struct {
UINT32 Data1;
UINT16 Data2;
UINT16 Data3;
UINT8 Data4[8];
} GUID;
//
// 8-bytes unsigned value that represents a physical system address.
//
typedef UINT64 PHYSICAL_ADDRESS;
///
/// LIST_ENTRY structure definition.
///
typedef struct _LIST_ENTRY LIST_ENTRY;
///
/// _LIST_ENTRY structure definition.
///
struct _LIST_ENTRY {
LIST_ENTRY *ForwardLink;
LIST_ENTRY *BackLink;
};
//
// Modifiers to abstract standard types to aid in debug of problems
//
///
/// Datum is read-only.
///
#define CONST const
///
/// Datum is scoped to the current file or function.
///
#define STATIC static
///
/// Undeclared type.
///
#define VOID void
//
// Modifiers for Data Types used to self document code.
// This concept is borrowed for UEFI specification.
//
///
/// Datum is passed to the function.
///
#define IN
///
/// Datum is returned from the function.
///
#define OUT
///
/// Passing the datum to the function is optional, and a NULL
/// is passed if the value is not supplied.
///
#define OPTIONAL
//
// UEFI specification claims 1 and 0. We are concerned about the
// complier portability so we did it this way.
//
///
/// Boolean true value. UEFI Specification defines this value to be 1,
/// but this form is more portable.
///
#define TRUE ((BOOLEAN)(1==1))
///
/// Boolean false value. UEFI Specification defines this value to be 0,
/// but this form is more portable.
///
#define FALSE ((BOOLEAN)(0==1))
///
/// NULL pointer (VOID *)
///
#define NULL ((VOID *) 0)
///
/// Maximum values for common UEFI Data Types
///
#define MAX_INT8 ((INT8)0x7F)
#define MAX_UINT8 ((UINT8)0xFF)
#define MAX_INT16 ((INT16)0x7FFF)
#define MAX_UINT16 ((UINT16)0xFFFF)
#define MAX_INT32 ((INT32)0x7FFFFFFF)
#define MAX_UINT32 ((UINT32)0xFFFFFFFF)
#define MAX_INT64 ((INT64)0x7FFFFFFFFFFFFFFFULL)
#define MAX_UINT64 ((UINT64)0xFFFFFFFFFFFFFFFFULL)
#define BIT0 0x00000001
#define BIT1 0x00000002
#define BIT2 0x00000004
#define BIT3 0x00000008
#define BIT4 0x00000010
#define BIT5 0x00000020
#define BIT6 0x00000040
#define BIT7 0x00000080
#define BIT8 0x00000100
#define BIT9 0x00000200
#define BIT10 0x00000400
#define BIT11 0x00000800
#define BIT12 0x00001000
#define BIT13 0x00002000
#define BIT14 0x00004000
#define BIT15 0x00008000
#define BIT16 0x00010000
#define BIT17 0x00020000
#define BIT18 0x00040000
#define BIT19 0x00080000
#define BIT20 0x00100000
#define BIT21 0x00200000
#define BIT22 0x00400000
#define BIT23 0x00800000
#define BIT24 0x01000000
#define BIT25 0x02000000
#define BIT26 0x04000000
#define BIT27 0x08000000
#define BIT28 0x10000000
#define BIT29 0x20000000
#define BIT30 0x40000000
#define BIT31 0x80000000
#define BIT32 0x0000000100000000ULL
#define BIT33 0x0000000200000000ULL
#define BIT34 0x0000000400000000ULL
#define BIT35 0x0000000800000000ULL
#define BIT36 0x0000001000000000ULL
#define BIT37 0x0000002000000000ULL
#define BIT38 0x0000004000000000ULL
#define BIT39 0x0000008000000000ULL
#define BIT40 0x0000010000000000ULL
#define BIT41 0x0000020000000000ULL
#define BIT42 0x0000040000000000ULL
#define BIT43 0x0000080000000000ULL
#define BIT44 0x0000100000000000ULL
#define BIT45 0x0000200000000000ULL
#define BIT46 0x0000400000000000ULL
#define BIT47 0x0000800000000000ULL
#define BIT48 0x0001000000000000ULL
#define BIT49 0x0002000000000000ULL
#define BIT50 0x0004000000000000ULL
#define BIT51 0x0008000000000000ULL
#define BIT52 0x0010000000000000ULL
#define BIT53 0x0020000000000000ULL
#define BIT54 0x0040000000000000ULL
#define BIT55 0x0080000000000000ULL
#define BIT56 0x0100000000000000ULL
#define BIT57 0x0200000000000000ULL
#define BIT58 0x0400000000000000ULL
#define BIT59 0x0800000000000000ULL
#define BIT60 0x1000000000000000ULL
#define BIT61 0x2000000000000000ULL
#define BIT62 0x4000000000000000ULL
#define BIT63 0x8000000000000000ULL
#define SIZE_1KB 0x00000400
#define SIZE_2KB 0x00000800
#define SIZE_4KB 0x00001000
#define SIZE_8KB 0x00002000
#define SIZE_16KB 0x00004000
#define SIZE_32KB 0x00008000
#define SIZE_64KB 0x00010000
#define SIZE_128KB 0x00020000
#define SIZE_256KB 0x00040000
#define SIZE_512KB 0x00080000
#define SIZE_1MB 0x00100000
#define SIZE_2MB 0x00200000
#define SIZE_4MB 0x00400000
#define SIZE_8MB 0x00800000
#define SIZE_16MB 0x01000000
#define SIZE_32MB 0x02000000
#define SIZE_64MB 0x04000000
#define SIZE_128MB 0x08000000
#define SIZE_256MB 0x10000000
#define SIZE_512MB 0x20000000
#define SIZE_1GB 0x40000000
#define SIZE_2GB 0x80000000
#define SIZE_4GB 0x0000000100000000ULL
#define SIZE_8GB 0x0000000200000000ULL
#define SIZE_16GB 0x0000000400000000ULL
#define SIZE_32GB 0x0000000800000000ULL
#define SIZE_64GB 0x0000001000000000ULL
#define SIZE_128GB 0x0000002000000000ULL
#define SIZE_256GB 0x0000004000000000ULL
#define SIZE_512GB 0x0000008000000000ULL
#define SIZE_1TB 0x0000010000000000ULL
#define SIZE_2TB 0x0000020000000000ULL
#define SIZE_4TB 0x0000040000000000ULL
#define SIZE_8TB 0x0000080000000000ULL
#define SIZE_16TB 0x0000100000000000ULL
#define SIZE_32TB 0x0000200000000000ULL
#define SIZE_64TB 0x0000400000000000ULL
#define SIZE_128TB 0x0000800000000000ULL
#define SIZE_256TB 0x0001000000000000ULL
#define SIZE_512TB 0x0002000000000000ULL
#define SIZE_1PB 0x0004000000000000ULL
#define SIZE_2PB 0x0008000000000000ULL
#define SIZE_4PB 0x0010000000000000ULL
#define SIZE_8PB 0x0020000000000000ULL
#define SIZE_16PB 0x0040000000000000ULL
#define SIZE_32PB 0x0080000000000000ULL
#define SIZE_64PB 0x0100000000000000ULL
#define SIZE_128PB 0x0200000000000000ULL
#define SIZE_256PB 0x0400000000000000ULL
#define SIZE_512PB 0x0800000000000000ULL
#define SIZE_1EB 0x1000000000000000ULL
#define SIZE_2EB 0x2000000000000000ULL
#define SIZE_4EB 0x4000000000000000ULL
#define SIZE_8EB 0x8000000000000000ULL
#define BASE_1KB 0x00000400
#define BASE_2KB 0x00000800
#define BASE_4KB 0x00001000
#define BASE_8KB 0x00002000
#define BASE_16KB 0x00004000
#define BASE_32KB 0x00008000
#define BASE_64KB 0x00010000
#define BASE_128KB 0x00020000
#define BASE_256KB 0x00040000
#define BASE_512KB 0x00080000
#define BASE_1MB 0x00100000
#define BASE_2MB 0x00200000
#define BASE_4MB 0x00400000
#define BASE_8MB 0x00800000
#define BASE_16MB 0x01000000
#define BASE_32MB 0x02000000
#define BASE_64MB 0x04000000
#define BASE_128MB 0x08000000
#define BASE_256MB 0x10000000
#define BASE_512MB 0x20000000
#define BASE_1GB 0x40000000
#define BASE_2GB 0x80000000
#define BASE_4GB 0x0000000100000000ULL
#define BASE_8GB 0x0000000200000000ULL
#define BASE_16GB 0x0000000400000000ULL
#define BASE_32GB 0x0000000800000000ULL
#define BASE_64GB 0x0000001000000000ULL
#define BASE_128GB 0x0000002000000000ULL
#define BASE_256GB 0x0000004000000000ULL
#define BASE_512GB 0x0000008000000000ULL
#define BASE_1TB 0x0000010000000000ULL
#define BASE_2TB 0x0000020000000000ULL
#define BASE_4TB 0x0000040000000000ULL
#define BASE_8TB 0x0000080000000000ULL
#define BASE_16TB 0x0000100000000000ULL
#define BASE_32TB 0x0000200000000000ULL
#define BASE_64TB 0x0000400000000000ULL
#define BASE_128TB 0x0000800000000000ULL
#define BASE_256TB 0x0001000000000000ULL
#define BASE_512TB 0x0002000000000000ULL
#define BASE_1PB 0x0004000000000000ULL
#define BASE_2PB 0x0008000000000000ULL
#define BASE_4PB 0x0010000000000000ULL
#define BASE_8PB 0x0020000000000000ULL
#define BASE_16PB 0x0040000000000000ULL
#define BASE_32PB 0x0080000000000000ULL
#define BASE_64PB 0x0100000000000000ULL
#define BASE_128PB 0x0200000000000000ULL
#define BASE_256PB 0x0400000000000000ULL
#define BASE_512PB 0x0800000000000000ULL
#define BASE_1EB 0x1000000000000000ULL
#define BASE_2EB 0x2000000000000000ULL
#define BASE_4EB 0x4000000000000000ULL
#define BASE_8EB 0x8000000000000000ULL
//
// Support for variable length argument lists using the ANSI standard.
//
// Since we are using the ANSI standard we used the standard naming and
// did not follow the coding convention
//
// VA_LIST - typedef for argument list.
// VA_START (VA_LIST Marker, argument before the ...) - Init Marker for use.
// VA_END (VA_LIST Marker) - Clear Marker
// VA_ARG (VA_LIST Marker, var arg size) - Use Marker to get an argument from
// the ... list. You must know the size and pass it in this macro.
// VA_COPY (VA_LIST Dest, VA_LIST Start) - Initialize Dest as a copy of Start.
//
// example:
//
// UINTN
// ExampleVarArg (
// IN UINTN NumberOfArgs,
// ...
// )
// {
// VA_LIST Marker;
// UINTN Index;
// UINTN Result;
//
// //
// // Initialize the Marker
// //
// VA_START (Marker, NumberOfArgs);
// for (Index = 0, Result = 0; Index < NumberOfArgs; Index++) {
// //
// // The ... list is a series of UINTN values, so average them up.
// //
// Result += VA_ARG (Marker, UINTN);
// }
//
// VA_END (Marker);
// return Result
// }
//
/**
Return the size of argument that has been aligned to sizeof (UINTN).
@param n The parameter size to be aligned.
@return The aligned size.
**/
#define _INT_SIZE_OF(n) ((sizeof (n) + sizeof (UINTN) - 1) &~(sizeof (UINTN) - 1))
#if defined(__CC_ARM)
//
// RVCT ARM variable argument list support.
//
///
/// Variable used to traverse the list of arguments. This type can vary by
/// implementation and could be an array or structure.
///
#ifdef __APCS_ADSABI
typedef int *va_list[1];
#define VA_LIST va_list
#else
typedef struct __va_list { void *__ap; } va_list;
#define VA_LIST va_list
#endif
#define VA_START(Marker, Parameter) __va_start(Marker, Parameter)
#define VA_ARG(Marker, TYPE) __va_arg(Marker, TYPE)
#define VA_END(Marker) ((void)0)
// For some ARM RVCT compilers, __va_copy is not defined
#ifndef __va_copy
#define __va_copy(dest, src) ((void)((dest) = (src)))
#endif
#define VA_COPY(Dest, Start) __va_copy (Dest, Start)
#elif defined(__GNUC__) && !defined(NO_BUILTIN_VA_FUNCS)
//
// Use GCC built-in macros for variable argument lists.
//
///
/// Variable used to traverse the list of arguments. This type can vary by
/// implementation and could be an array or structure.
///
typedef __builtin_va_list VA_LIST;
#define VA_START(Marker, Parameter) __builtin_va_start (Marker, Parameter)
#define VA_ARG(Marker, TYPE) ((sizeof (TYPE) < sizeof (UINTN)) ? (TYPE)(__builtin_va_arg (Marker, UINTN)) : (TYPE)(__builtin_va_arg (Marker, TYPE)))
#define VA_END(Marker) __builtin_va_end (Marker)
#define VA_COPY(Dest, Start) __builtin_va_copy (Dest, Start)
#else
///
/// Variable used to traverse the list of arguments. This type can vary by
/// implementation and could be an array or structure.
///
typedef CHAR8 *VA_LIST;
/**
Retrieves a pointer to the beginning of a variable argument list, based on
the name of the parameter that immediately precedes the variable argument list.
This function initializes Marker to point to the beginning of the variable
argument list that immediately follows Parameter. The method for computing the
pointer to the next argument in the argument list is CPU-specific following the
EFIAPI ABI.
@param Marker The VA_LIST used to traverse the list of arguments.
@param Parameter The name of the parameter that immediately precedes
the variable argument list.
@return A pointer to the beginning of a variable argument list.
**/
#define VA_START(Marker, Parameter) (Marker = (VA_LIST) ((UINTN) & (Parameter) + _INT_SIZE_OF (Parameter)))
/**
Returns an argument of a specified type from a variable argument list and updates
the pointer to the variable argument list to point to the next argument.
This function returns an argument of the type specified by TYPE from the beginning
of the variable argument list specified by Marker. Marker is then updated to point
to the next argument in the variable argument list. The method for computing the
pointer to the next argument in the argument list is CPU-specific following the EFIAPI ABI.
@param Marker VA_LIST used to traverse the list of arguments.
@param TYPE The type of argument to retrieve from the beginning
of the variable argument list.
@return An argument of the type specified by TYPE.
**/
#define VA_ARG(Marker, TYPE) (*(TYPE *) ((Marker += _INT_SIZE_OF (TYPE)) - _INT_SIZE_OF (TYPE)))
/**
Terminates the use of a variable argument list.
This function initializes Marker so it can no longer be used with VA_ARG().
After this macro is used, the only way to access the variable argument list is
by using VA_START() again.
@param Marker VA_LIST used to traverse the list of arguments.
**/
#define VA_END(Marker) (Marker = (VA_LIST) 0)
/**
Initializes a VA_LIST as a copy of an existing VA_LIST.
This macro initializes Dest as a copy of Start, as if the VA_START macro had been applied to Dest
followed by the same sequence of uses of the VA_ARG macro as had previously been used to reach
the present state of Start.
@param Dest VA_LIST used to traverse the list of arguments.
@param Start VA_LIST used to traverse the list of arguments.
**/
#define VA_COPY(Dest, Start) ((void)((Dest) = (Start)))
#endif
///
/// Pointer to the start of a variable argument list stored in a memory buffer. Same as UINT8 *.
///
typedef UINTN *BASE_LIST;
/**
Returns the size of a data type in sizeof(UINTN) units rounded up to the nearest UINTN boundary.
@param TYPE The date type to determine the size of.
@return The size of TYPE in sizeof (UINTN) units rounded up to the nearest UINTN boundary.
**/
#define _BASE_INT_SIZE_OF(TYPE) ((sizeof (TYPE) + sizeof (UINTN) - 1) / sizeof (UINTN))
/**
Returns an argument of a specified type from a variable argument list and updates
the pointer to the variable argument list to point to the next argument.
This function returns an argument of the type specified by TYPE from the beginning
of the variable argument list specified by Marker. Marker is then updated to point
to the next argument in the variable argument list. The method for computing the
pointer to the next argument in the argument list is CPU specific following the EFIAPI ABI.
@param Marker The pointer to the beginning of a variable argument list.
@param TYPE The type of argument to retrieve from the beginning
of the variable argument list.
@return An argument of the type specified by TYPE.
**/
#define BASE_ARG(Marker, TYPE) (*(TYPE *) ((Marker += _BASE_INT_SIZE_OF (TYPE)) - _BASE_INT_SIZE_OF (TYPE)))
/**
The macro that returns the byte offset of a field in a data structure.
This function returns the offset, in bytes, of field specified by Field from the
beginning of the data structure specified by TYPE. If TYPE does not contain Field,
the module will not compile.
@param TYPE The name of the data structure that contains the field specified by Field.
@param Field The name of the field in the data structure.
@return Offset, in bytes, of field.
**/
#ifdef __GNUC__
#if __GNUC__ >= 4
#define OFFSET_OF(TYPE, Field) ((UINTN) __builtin_offsetof(TYPE, Field))
#endif
#endif
#ifndef OFFSET_OF
#define OFFSET_OF(TYPE, Field) ((UINTN) &(((TYPE *)0)->Field))
#endif
/**
Macro that returns a pointer to the data structure that contains a specified field of
that data structure. This is a lightweight method to hide information by placing a
public data structure inside a larger private data structure and using a pointer to
the public data structure to retrieve a pointer to the private data structure.
This function computes the offset, in bytes, of field specified by Field from the beginning
of the data structure specified by TYPE. This offset is subtracted from Record, and is
used to return a pointer to a data structure of the type specified by TYPE. If the data type
specified by TYPE does not contain the field specified by Field, then the module will not compile.
@param Record Pointer to the field specified by Field within a data structure of type TYPE.
@param TYPE The name of the data structure type to return. This data structure must
contain the field specified by Field.
@param Field The name of the field in the data structure specified by TYPE to which Record points.
@return A pointer to the structure from one of it's elements.
**/
#define BASE_CR(Record, TYPE, Field) ((TYPE *) ((CHAR8 *) (Record) - (CHAR8 *) &(((TYPE *) 0)->Field)))
/**
Rounds a value up to the next boundary using a specified alignment.
This function rounds Value up to the next boundary using the specified Alignment.
This aligned value is returned.
@param Value The value to round up.
@param Alignment The alignment boundary used to return the aligned value.
@return A value up to the next boundary.
**/
#define ALIGN_VALUE(Value, Alignment) ((Value) + (((Alignment) - (Value)) & ((Alignment) - 1)))
/**
Adjust a pointer by adding the minimum offset required for it to be aligned on
a specified alignment boundary.
This function rounds the pointer specified by Pointer to the next alignment boundary
specified by Alignment. The pointer to the aligned address is returned.
@param Pointer The pointer to round up.
@param Alignment The alignment boundary to use to return an aligned pointer.
@return Pointer to the aligned address.
**/
#define ALIGN_POINTER(Pointer, Alignment) ((VOID *) (ALIGN_VALUE ((UINTN)(Pointer), (Alignment))))
/**
Rounds a value up to the next natural boundary for the current CPU.
This is 4-bytes for 32-bit CPUs and 8-bytes for 64-bit CPUs.
This function rounds the value specified by Value up to the next natural boundary for the
current CPU. This rounded value is returned.
@param Value The value to round up.
@return Rounded value specified by Value.
**/
#define ALIGN_VARIABLE(Value) ALIGN_VALUE ((Value), sizeof (UINTN))
/**
Return the maximum of two operands.
This macro returns the maximum of two operand specified by a and b.
Both a and b must be the same numerical types, signed or unsigned.
@param a The first operand with any numerical type.
@param b The second operand. Can be any numerical type as long as is
the same type as a.
@return Maximum of two operands.
**/
#define MAX(a, b) \
(((a) > (b)) ? (a) : (b))
/**
Return the minimum of two operands.
This macro returns the minimal of two operand specified by a and b.
Both a and b must be the same numerical types, signed or unsigned.
@param a The first operand with any numerical type.
@param b The second operand. It should be the same any numerical type with a.
@return Minimum of two operands.
**/
#define MIN(a, b) \
(((a) < (b)) ? (a) : (b))
/**
Return the absolute value of a signed operand.
This macro returns the absolute value of the signed operand specified by a.
@param a The signed operand.
@return The absolute value of the signed operand.
**/
#define ABS(a) \
(((a) < 0) ? (-(a)) : (a))
//
// Status codes common to all execution phases
//
typedef UINTN RETURN_STATUS;
/**
Produces a RETURN_STATUS code with the highest bit set.
@param StatusCode The status code value to convert into a warning code.
StatusCode must be in the range 0x00000000..0x7FFFFFFF.
@return The value specified by StatusCode with the highest bit set.
**/
#define ENCODE_ERROR(StatusCode) ((RETURN_STATUS)(MAX_BIT | (StatusCode)))
/**
Produces a RETURN_STATUS code with the highest bit clear.
@param StatusCode The status code value to convert into a warning code.
StatusCode must be in the range 0x00000000..0x7FFFFFFF.
@return The value specified by StatusCode with the highest bit clear.
**/
#define ENCODE_WARNING(StatusCode) ((RETURN_STATUS)(StatusCode))
/**
Returns TRUE if a specified RETURN_STATUS code is an error code.
This function returns TRUE if StatusCode has the high bit set. Otherwise, FALSE is returned.
@param StatusCode The status code value to evaluate.
@retval TRUE The high bit of StatusCode is set.
@retval FALSE The high bit of StatusCode is clear.
**/
#define RETURN_ERROR(StatusCode) (((INTN)(RETURN_STATUS)(StatusCode)) < 0)
///
/// The operation completed successfully.
///
#define RETURN_SUCCESS 0
///
/// The image failed to load.
///
#define RETURN_LOAD_ERROR ENCODE_ERROR (1)
///
/// The parameter was incorrect.
///
#define RETURN_INVALID_PARAMETER ENCODE_ERROR (2)
///
/// The operation is not supported.
///
#define RETURN_UNSUPPORTED ENCODE_ERROR (3)
///
/// The buffer was not the proper size for the request.
///
#define RETURN_BAD_BUFFER_SIZE ENCODE_ERROR (4)
///
/// The buffer was not large enough to hold the requested data.
/// The required buffer size is returned in the appropriate
/// parameter when this error occurs.
///
#define RETURN_BUFFER_TOO_SMALL ENCODE_ERROR (5)
///
/// There is no data pending upon return.
///
#define RETURN_NOT_READY ENCODE_ERROR (6)
///
/// The physical device reported an error while attempting the
/// operation.
///
#define RETURN_DEVICE_ERROR ENCODE_ERROR (7)
///
/// The device can not be written to.
///
#define RETURN_WRITE_PROTECTED ENCODE_ERROR (8)
///
/// The resource has run out.
///
#define RETURN_OUT_OF_RESOURCES ENCODE_ERROR (9)
///
/// An inconsistency was detected on the file system causing the
/// operation to fail.
///
#define RETURN_VOLUME_CORRUPTED ENCODE_ERROR (10)
///
/// There is no more space on the file system.
///
#define RETURN_VOLUME_FULL ENCODE_ERROR (11)
///
/// The device does not contain any medium to perform the
/// operation.
///
#define RETURN_NO_MEDIA ENCODE_ERROR (12)
///
/// The medium in the device has changed since the last
/// access.
///
#define RETURN_MEDIA_CHANGED ENCODE_ERROR (13)
///
/// The item was not found.
///
#define RETURN_NOT_FOUND ENCODE_ERROR (14)
///
/// Access was denied.
///
#define RETURN_ACCESS_DENIED ENCODE_ERROR (15)
///
/// The server was not found or did not respond to the request.
///
#define RETURN_NO_RESPONSE ENCODE_ERROR (16)
///
/// A mapping to the device does not exist.
///
#define RETURN_NO_MAPPING ENCODE_ERROR (17)
///
/// A timeout time expired.
///
#define RETURN_TIMEOUT ENCODE_ERROR (18)
///
/// The protocol has not been started.
///
#define RETURN_NOT_STARTED ENCODE_ERROR (19)
///
/// The protocol has already been started.
///
#define RETURN_ALREADY_STARTED ENCODE_ERROR (20)
///
/// The operation was aborted.
///
#define RETURN_ABORTED ENCODE_ERROR (21)
///
/// An ICMP error occurred during the network operation.
///
#define RETURN_ICMP_ERROR ENCODE_ERROR (22)
///
/// A TFTP error occurred during the network operation.
///
#define RETURN_TFTP_ERROR ENCODE_ERROR (23)
///
/// A protocol error occurred during the network operation.
///
#define RETURN_PROTOCOL_ERROR ENCODE_ERROR (24)
///
/// A function encountered an internal version that was
/// incompatible with a version requested by the caller.
///
#define RETURN_INCOMPATIBLE_VERSION ENCODE_ERROR (25)
///
/// The function was not performed due to a security violation.
///
#define RETURN_SECURITY_VIOLATION ENCODE_ERROR (26)
///
/// A CRC error was detected.
///
#define RETURN_CRC_ERROR ENCODE_ERROR (27)
///
/// The beginning or end of media was reached.
///
#define RETURN_END_OF_MEDIA ENCODE_ERROR (28)
///
/// The end of the file was reached.
///
#define RETURN_END_OF_FILE ENCODE_ERROR (31)
///
/// The language specified was invalid.
///
#define RETURN_INVALID_LANGUAGE ENCODE_ERROR (32)
///
/// The security status of the data is unknown or compromised
/// and the data must be updated or replaced to restore a valid
/// security status.
///
#define RETURN_COMPROMISED_DATA ENCODE_ERROR (33)
///
/// The string contained one or more characters that
/// the device could not render and were skipped.
///
#define RETURN_WARN_UNKNOWN_GLYPH ENCODE_WARNING (1)
///
/// The handle was closed, but the file was not deleted.
///
#define RETURN_WARN_DELETE_FAILURE ENCODE_WARNING (2)
///
/// The handle was closed, but the data to the file was not
/// flushed properly.
///
#define RETURN_WARN_WRITE_FAILURE ENCODE_WARNING (3)
///
/// The resulting buffer was too small, and the data was
/// truncated to the buffer size.
///
#define RETURN_WARN_BUFFER_TOO_SMALL ENCODE_WARNING (4)
///
/// The data has not been updated within the timeframe set by
/// local policy for this type of data.
///
#define RETURN_WARN_STALE_DATA ENCODE_WARNING (5)
/**
Returns a 16-bit signature built from 2 ASCII characters.
This macro returns a 16-bit value built from the two ASCII characters specified
by A and B.
@param A The first ASCII character.
@param B The second ASCII character.
@return A 16-bit value built from the two ASCII characters specified by A and B.
**/
#define SIGNATURE_16(A, B) ((A) | (B << 8))
/**
Returns a 32-bit signature built from 4 ASCII characters.
This macro returns a 32-bit value built from the four ASCII characters specified
by A, B, C, and D.
@param A The first ASCII character.
@param B The second ASCII character.
@param C The third ASCII character.
@param D The fourth ASCII character.
@return A 32-bit value built from the two ASCII characters specified by A, B,
C and D.
**/
#define SIGNATURE_32(A, B, C, D) (SIGNATURE_16 (A, B) | (SIGNATURE_16 (C, D) << 16))
/**
Returns a 64-bit signature built from 8 ASCII characters.
This macro returns a 64-bit value built from the eight ASCII characters specified
by A, B, C, D, E, F, G,and H.
@param A The first ASCII character.
@param B The second ASCII character.
@param C The third ASCII character.
@param D The fourth ASCII character.
@param E The fifth ASCII character.
@param F The sixth ASCII character.
@param G The seventh ASCII character.
@param H The eighth ASCII character.
@return A 64-bit value built from the two ASCII characters specified by A, B,
C, D, E, F, G and H.
**/
#define SIGNATURE_64(A, B, C, D, E, F, G, H) \
(SIGNATURE_32 (A, B, C, D) | ((UINT64) (SIGNATURE_32 (E, F, G, H)) << 32))
#endif
/** @file
Provides a GUID and a data structure that can be used with EFI_FILE_PROTOCOL.SetInfo()
and EFI_FILE_PROTOCOL.GetInfo() to set or get generic file information.
This GUID is defined in UEFI specification.
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef __FILE_INFO_H__
#define __FILE_INFO_H__
#define EFI_FILE_INFO_ID \
{ \
0x9576e92, 0x6d3f, 0x11d2, {0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \
}
typedef struct {
///
/// The size of the EFI_FILE_INFO structure, including the Null-terminated FileName string.
///
UINT64 Size;
///
/// The size of the file in bytes.
///
UINT64 FileSize;
///
/// PhysicalSize The amount of physical space the file consumes on the file system volume.
///
UINT64 PhysicalSize;
///
/// The time the file was created.
///
EFI_TIME CreateTime;
///
/// The time when the file was last accessed.
///
EFI_TIME LastAccessTime;
///
/// The time when the file's contents were last modified.
///
EFI_TIME ModificationTime;
///
/// The attribute bits for the file.
///
UINT64 Attribute;
///
/// The Null-terminated name of the file.
///
CHAR16 FileName[1];
} EFI_FILE_INFO;
///
/// The FileName field of the EFI_FILE_INFO data structure is variable length.
/// Whenever code needs to know the size of the EFI_FILE_INFO data structure, it needs to
/// be the size of the data structure without the FileName field. The following macro
/// computes this size correctly no matter how big the FileName array is declared.
/// This is required to make the EFI_FILE_INFO data structure ANSI compilant.
///
#define SIZE_OF_EFI_FILE_INFO OFFSET_OF (EFI_FILE_INFO, FileName)
extern EFI_GUID gEfiFileInfoGuid;
#endif
/** @file
Guid used to identify HII FormMap configuration method.
Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@par Revision Reference:
GUID defined in UEFI 2.2 spec.
**/
#ifndef __EFI_HII_FORMMAP_GUID_H__
#define __EFI_HII_FORMMAP_GUID_H__
#define EFI_HII_STANDARD_FORM_GUID \
{ 0x3bd2f4ec, 0xe524, 0x46e4, { 0xa9, 0xd8, 0x51, 0x1, 0x17, 0x42, 0x55, 0x62 } }
extern EFI_GUID gEfiHiiStandardFormGuid;
#endif
/** @file
Terminal Device Path Vendor Guid.
Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@par Revision Reference:
GUIDs defined in UEFI 2.0 spec.
**/
#ifndef __PC_ANSI_H__
#define __PC_ANSI_H__
#define EFI_PC_ANSI_GUID \
{ \
0xe0c14753, 0xf9be, 0x11d2, {0x9a, 0x0c, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \
}
#define EFI_VT_100_GUID \
{ \
0xdfa66065, 0xb419, 0x11d3, {0x9a, 0x2d, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \
}
#define EFI_VT_100_PLUS_GUID \
{ \
0x7baec70b, 0x57e0, 0x4c76, {0x8e, 0x87, 0x2f, 0x9e, 0x28, 0x08, 0x83, 0x43 } \
}
#define EFI_VT_UTF8_GUID \
{ \
0xad15a0d6, 0x8bec, 0x4acf, {0xa0, 0x73, 0xd0, 0x1d, 0xe7, 0x7e, 0x2d, 0x88 } \
}
#define DEVICE_PATH_MESSAGING_UART_FLOW_CONTROL \
{ \
0x37499a9d, 0x542f, 0x4c89, {0xa0, 0x26, 0x35, 0xda, 0x14, 0x20, 0x94, 0xe4 } \
}
#define EFI_SAS_DEVICE_PATH_GUID \
{ \
0xd487ddb4, 0x008b, 0x11d9, {0xaf, 0xdc, 0x00, 0x10, 0x83, 0xff, 0xca, 0x4d } \
}
extern EFI_GUID gEfiPcAnsiGuid;
extern EFI_GUID gEfiVT100Guid;
extern EFI_GUID gEfiVT100PlusGuid;
extern EFI_GUID gEfiVTUTF8Guid;
extern EFI_GUID gEfiUartDevicePathGuid;
extern EFI_GUID gEfiSasDevicePathGuid;
#endif
/** @file
GUID for UEFI WIN_CERTIFICATE structure.
Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@par Revision Reference:
GUID defined in UEFI 2.0 spec.
**/
#ifndef __EFI_WIN_CERTIFICATE_H__
#define __EFI_WIN_CERTIFICATE_H__
//
// _WIN_CERTIFICATE.wCertificateType
//
#define WIN_CERT_TYPE_PKCS_SIGNED_DATA 0x0002
#define WIN_CERT_TYPE_EFI_PKCS115 0x0EF0
#define WIN_CERT_TYPE_EFI_GUID 0x0EF1
///
/// The WIN_CERTIFICATE structure is part of the PE/COFF specification.
///
typedef struct {
///
/// The length of the entire certificate,
/// including the length of the header, in bytes.
///
UINT32 dwLength;
///
/// The revision level of the WIN_CERTIFICATE
/// structure. The current revision level is 0x0200.
///
UINT16 wRevision;
///
/// The certificate type. See WIN_CERT_TYPE_xxx for the UEFI
/// certificate types. The UEFI specification reserves the range of
/// certificate type values from 0x0EF0 to 0x0EFF.
///
UINT16 wCertificateType;
///
/// The following is the actual certificate. The format of
/// the certificate depends on wCertificateType.
///
/// UINT8 bCertificate[ANYSIZE_ARRAY];
///
} WIN_CERTIFICATE;
///
/// WIN_CERTIFICATE_UEFI_GUID.CertType
///
#define EFI_CERT_TYPE_RSA2048_SHA256_GUID \
{0xa7717414, 0xc616, 0x4977, {0x94, 0x20, 0x84, 0x47, 0x12, 0xa7, 0x35, 0xbf } }
///
/// WIN_CERTIFICATE_UEFI_GUID.CertData
///
typedef struct {
EFI_GUID HashType;
UINT8 PublicKey[256];
UINT8 Signature[256];
} EFI_CERT_BLOCK_RSA_2048_SHA256;
///
/// Certificate which encapsulates a GUID-specific digital signature
///
typedef struct {
///
/// This is the standard WIN_CERTIFICATE header, where
/// wCertificateType is set to WIN_CERT_TYPE_EFI_GUID.
///
WIN_CERTIFICATE Hdr;
///
/// This is the unique id which determines the
/// format of the CertData. .
///
EFI_GUID CertType;
///
/// The following is the certificate data. The format of
/// the data is determined by the CertType.
/// If CertType is EFI_CERT_TYPE_RSA2048_SHA256_GUID,
/// the CertData will be EFI_CERT_BLOCK_RSA_2048_SHA256 structure.
///
UINT8 CertData[1];
} WIN_CERTIFICATE_UEFI_GUID;
///
/// Certificate which encapsulates the RSASSA_PKCS1-v1_5 digital signature.
///
/// The WIN_CERTIFICATE_UEFI_PKCS1_15 structure is derived from
/// WIN_CERTIFICATE and encapsulate the information needed to
/// implement the RSASSA-PKCS1-v1_5 digital signature algorithm as
/// specified in RFC2437.
///
typedef struct {
///
/// This is the standard WIN_CERTIFICATE header, where
/// wCertificateType is set to WIN_CERT_TYPE_UEFI_PKCS1_15.
///
WIN_CERTIFICATE Hdr;
///
/// This is the hashing algorithm which was performed on the
/// UEFI executable when creating the digital signature.
///
EFI_GUID HashAlgorithm;
///
/// The following is the actual digital signature. The
/// size of the signature is the same size as the key
/// (1024-bit key is 128 bytes) and can be determined by
/// subtracting the length of the other parts of this header
/// from the total length of the certificate as found in
/// Hdr.dwLength.
///
/// UINT8 Signature[];
///
} WIN_CERTIFICATE_EFI_PKCS1_15;
extern EFI_GUID gEfiCertTypeRsa2048Sha256Guid;
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment