efibind.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * Copright (C) 2014 - 2015 Linaro Ltd.
  3. * Author: Ard Biesheuvel <ard.biesheuvel@linaro.org>
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice and this list of conditions, without modification.
  10. * 2. The name of the author may not be used to endorse or promote products
  11. * derived from this software without specific prior written permission.
  12. *
  13. * Alternatively, this software may be distributed under the terms of the
  14. * GNU General Public License as published by the Free Software Foundation;
  15. * either version 2 of the License, or (at your option) any later version.
  16. */
  17. #if !defined(_MSC_VER) && (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L )) && !defined(__cplusplus)
  18. // ANSI C 1999/2000 stdint.h integer width declarations
  19. typedef unsigned long long uint64_t;
  20. typedef long long int64_t;
  21. typedef unsigned int uint32_t;
  22. typedef int int32_t;
  23. typedef unsigned short uint16_t;
  24. typedef short int16_t;
  25. typedef unsigned char uint8_t;
  26. typedef signed char int8_t; // unqualified 'char' is unsigned on ARM
  27. typedef uint32_t uintptr_t;
  28. typedef int32_t intptr_t;
  29. #else
  30. #include <stdint.h>
  31. #endif
  32. /*
  33. * This prevents GCC from emitting GOT based relocations, and use R_ARM_REL32
  34. * relative relocations instead, which are more suitable for static binaries.
  35. */
  36. #if defined(__GNUC__) && !__STDC_HOSTED__
  37. #pragma GCC visibility push (hidden)
  38. #endif
  39. //
  40. // Basic EFI types of various widths
  41. //
  42. #ifndef __WCHAR_TYPE__
  43. # define __WCHAR_TYPE__ short
  44. #endif
  45. #ifndef __CHAR16_TYPE__
  46. # define __CHAR16_TYPE__ unsigned short
  47. #endif
  48. typedef uint64_t UINT64;
  49. typedef int64_t INT64;
  50. typedef uint32_t UINT32;
  51. typedef int32_t INT32;
  52. typedef uint16_t UINT16;
  53. typedef __CHAR16_TYPE__ CHAR16;
  54. typedef int16_t INT16;
  55. typedef uint8_t UINT8;
  56. typedef char CHAR8;
  57. typedef int8_t INT8;
  58. typedef __WCHAR_TYPE__ WCHAR;
  59. #undef VOID
  60. #define VOID void
  61. typedef int32_t INTN;
  62. typedef uint32_t UINTN;
  63. #define EFIERR(a) (0x80000000 | a)
  64. #define EFI_ERROR_MASK 0x80000000
  65. #define EFIERR_OEM(a) (0xc0000000 | a)
  66. #define BAD_POINTER 0xFBFBFBFB
  67. #define MAX_ADDRESS 0xFFFFFFFF
  68. #define BREAKPOINT() while (TRUE);
  69. //
  70. // Pointers must be aligned to these address to function
  71. //
  72. #define MIN_ALIGNMENT_SIZE 4
  73. #define ALIGN_VARIABLE(Value ,Adjustment) \
  74. (UINTN)Adjustment = 0; \
  75. if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
  76. (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
  77. Value = (UINTN)Value + (UINTN)Adjustment
  78. //
  79. // Define macros to build data structure signatures from characters.
  80. //
  81. #define EFI_SIGNATURE_16(A,B) ((A) | (B<<8))
  82. #define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16))
  83. #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))
  84. //
  85. // EFIAPI - prototype calling convention for EFI function pointers
  86. // BOOTSERVICE - prototype for implementation of a boot service interface
  87. // RUNTIMESERVICE - prototype for implementation of a runtime service interface
  88. // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
  89. // RUNTIME_CODE - pragma macro for declaring runtime code
  90. //
  91. #ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options
  92. #define EFIAPI // Substitute expresion to force C calling convention
  93. #endif
  94. #define BOOTSERVICE
  95. #define RUNTIMESERVICE
  96. #define RUNTIMEFUNCTION
  97. #define RUNTIME_CODE(a) alloc_text("rtcode", a)
  98. #define BEGIN_RUNTIME_DATA() data_seg("rtdata")
  99. #define END_RUNTIME_DATA() data_seg("")
  100. #define VOLATILE volatile
  101. #define MEMORY_FENCE __sync_synchronize
  102. //
  103. // When build similiar to FW, then link everything together as
  104. // one big module. For the MSVC toolchain, we simply tell the
  105. // linker what our driver init function is using /ENTRY.
  106. //
  107. #if defined(_MSC_EXTENSIONS)
  108. #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
  109. __pragma(comment(linker, "/ENTRY:" # InitFunction))
  110. #else
  111. #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
  112. UINTN \
  113. InitializeDriver ( \
  114. VOID *ImageHandle, \
  115. VOID *SystemTable \
  116. ) \
  117. { \
  118. return InitFunction(ImageHandle, \
  119. SystemTable); \
  120. } \
  121. \
  122. EFI_STATUS efi_main( \
  123. EFI_HANDLE image, \
  124. EFI_SYSTEM_TABLE *systab \
  125. ) __attribute__((weak, \
  126. alias ("InitializeDriver")));
  127. #endif
  128. #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \
  129. (_if)->LoadInternal(type, name, entry)
  130. //
  131. // Some compilers don't support the forward reference construct:
  132. // typedef struct XXXXX
  133. //
  134. // The following macro provide a workaround for such cases.
  135. #define INTERFACE_DECL(x) struct x
  136. #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__)
  137. #define EFI_FUNCTION