efibind.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #include <stdint.h>
  2. //
  3. // Basic EFI types of various widths
  4. //
  5. #ifndef __WCHAR_TYPE__
  6. # define __WCHAR_TYPE__ short
  7. #endif
  8. typedef uint64_t UINT64;
  9. typedef int64_t INT64;
  10. typedef uint32_t UINT32;
  11. typedef int32_t INT32;
  12. typedef uint16_t UINT16;
  13. typedef int16_t INT16;
  14. typedef uint8_t UINT8;
  15. typedef int8_t INT8;
  16. typedef __WCHAR_TYPE__ WCHAR;
  17. #undef VOID
  18. #define VOID void
  19. typedef int64_t INTN;
  20. typedef uint64_t UINTN;
  21. #define EFIERR(a) (0x8000000000000000 | a)
  22. #define EFI_ERROR_MASK 0x8000000000000000
  23. #define EFIERR_OEM(a) (0xc000000000000000 | a)
  24. #define BAD_POINTER 0xFBFBFBFBFBFBFBFB
  25. #define MAX_ADDRESS 0xFFFFFFFFFFFFFFFF
  26. #define BREAKPOINT() while (TRUE); // Make it hang on Bios[Dbg]32
  27. //
  28. // Pointers must be aligned to these address to function
  29. //
  30. #define MIN_ALIGNMENT_SIZE 8
  31. #define ALIGN_VARIABLE(Value ,Adjustment) \
  32. (UINTN)Adjustment = 0; \
  33. if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
  34. (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
  35. Value = (UINTN)Value + (UINTN)Adjustment
  36. //
  37. // Define macros to build data structure signatures from characters.
  38. //
  39. #define EFI_SIGNATURE_16(A,B) ((A) | (B<<8))
  40. #define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16))
  41. #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))
  42. //
  43. // EFIAPI - prototype calling convention for EFI function pointers
  44. // BOOTSERVICE - prototype for implementation of a boot service interface
  45. // RUNTIMESERVICE - prototype for implementation of a runtime service interface
  46. // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
  47. // RUNTIME_CODE - pragma macro for declaring runtime code
  48. //
  49. #ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options
  50. #define EFIAPI // Substitute expresion to force C calling convention
  51. #endif
  52. #define BOOTSERVICE
  53. #define RUNTIMESERVICE
  54. #define RUNTIMEFUNCTION
  55. #define RUNTIME_CODE(a) alloc_text("rtcode", a)
  56. #define BEGIN_RUNTIME_DATA() data_seg("rtdata")
  57. #define END_RUNTIME_DATA() data_seg("")
  58. #define VOLATILE volatile
  59. #define MEMORY_FENCE __sync_synchronize
  60. //
  61. // When build similiar to FW, then link everything together as
  62. // one big module.
  63. //
  64. #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
  65. UINTN \
  66. InitializeDriver ( \
  67. VOID *ImageHandle, \
  68. VOID *SystemTable \
  69. ) \
  70. { \
  71. return InitFunction(ImageHandle, \
  72. SystemTable); \
  73. } \
  74. \
  75. EFI_STATUS efi_main( \
  76. EFI_HANDLE image, \
  77. EFI_SYSTEM_TABLE *systab \
  78. ) __attribute__((weak, \
  79. alias ("InitializeDriver")));
  80. #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \
  81. (_if)->LoadInternal(type, name, entry)
  82. //
  83. // Some compilers don't support the forward reference construct:
  84. // typedef struct XXXXX
  85. //
  86. // The following macro provide a workaround for such cases.
  87. #define INTERFACE_DECL(x) struct x
  88. #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__)
  89. #define EFI_FUNCTION