efibind.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #include <stdint.h>
  2. /*
  3. * This prevents GCC from emitting GOT based relocations, and use R_ARM_REL32
  4. * relative relocations instead, which are more suitable for static binaries.
  5. */
  6. #pragma GCC visibility push (hidden)
  7. //
  8. // Basic EFI types of various widths
  9. //
  10. #ifndef __WCHAR_TYPE__
  11. # define __WCHAR_TYPE__ short
  12. #endif
  13. typedef uint64_t UINT64;
  14. typedef int64_t INT64;
  15. typedef uint32_t UINT32;
  16. typedef int32_t INT32;
  17. typedef uint16_t UINT16;
  18. typedef int16_t INT16;
  19. typedef uint8_t UINT8;
  20. typedef int8_t INT8;
  21. typedef __WCHAR_TYPE__ WCHAR;
  22. #undef VOID
  23. #define VOID void
  24. typedef int32_t INTN;
  25. typedef uint32_t UINTN;
  26. #define EFIERR(a) (0x80000000 | a)
  27. #define EFI_ERROR_MASK 0x80000000
  28. #define EFIERR_OEM(a) (0xc0000000 | a)
  29. #define BAD_POINTER 0xFBFBFBFB
  30. #define MAX_ADDRESS 0xFFFFFFFF
  31. #define BREAKPOINT() while (TRUE);
  32. //
  33. // Pointers must be aligned to these address to function
  34. //
  35. #define MIN_ALIGNMENT_SIZE 4
  36. #define ALIGN_VARIABLE(Value ,Adjustment) \
  37. (UINTN)Adjustment = 0; \
  38. if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
  39. (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
  40. Value = (UINTN)Value + (UINTN)Adjustment
  41. //
  42. // Define macros to build data structure signatures from characters.
  43. //
  44. #define EFI_SIGNATURE_16(A,B) ((A) | (B<<8))
  45. #define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16))
  46. #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))
  47. //
  48. // EFIAPI - prototype calling convention for EFI function pointers
  49. // BOOTSERVICE - prototype for implementation of a boot service interface
  50. // RUNTIMESERVICE - prototype for implementation of a runtime service interface
  51. // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
  52. // RUNTIME_CODE - pragma macro for declaring runtime code
  53. //
  54. #ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options
  55. #define EFIAPI // Substitute expresion to force C calling convention
  56. #endif
  57. #define BOOTSERVICE
  58. #define RUNTIMESERVICE
  59. #define RUNTIMEFUNCTION
  60. #define RUNTIME_CODE(a) alloc_text("rtcode", a)
  61. #define BEGIN_RUNTIME_DATA() data_seg("rtdata")
  62. #define END_RUNTIME_DATA() data_seg("")
  63. #define VOLATILE volatile
  64. #define MEMORY_FENCE __sync_synchronize
  65. //
  66. // When build similiar to FW, then link everything together as
  67. // one big module.
  68. //
  69. #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
  70. UINTN \
  71. InitializeDriver ( \
  72. VOID *ImageHandle, \
  73. VOID *SystemTable \
  74. ) \
  75. { \
  76. return InitFunction(ImageHandle, \
  77. SystemTable); \
  78. } \
  79. \
  80. EFI_STATUS efi_main( \
  81. EFI_HANDLE image, \
  82. EFI_SYSTEM_TABLE *systab \
  83. ) __attribute__((weak, \
  84. alias ("InitializeDriver")));
  85. #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \
  86. (_if)->LoadInternal(type, name, entry)
  87. //
  88. // Some compilers don't support the forward reference construct:
  89. // typedef struct XXXXX
  90. //
  91. // The following macro provide a workaround for such cases.
  92. #define INTERFACE_DECL(x) struct x
  93. #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__)
  94. #define EFI_FUNCTION
  95. static inline UINT64 DivU64x32(UINT64 Dividend, UINTN Divisor, UINTN *Remainder)
  96. {
  97. /*
  98. * GCC turns a division into a multiplication and shift with precalculated
  99. * constants if the divisor is constant and the dividend fits into a 32 bit
  100. * variable. Otherwise, it will turn this into calls into the 32-bit div
  101. * library functions.
  102. */
  103. if (Remainder)
  104. *Remainder = Dividend % Divisor;
  105. Dividend = Dividend / Divisor;
  106. return Dividend;
  107. }