efibind.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* SPDX-License-Identifier: GPL-2.0+ OR BSD-2-Clause */
  2. /*
  3. * Copright (C) 2014 - 2015 Linaro Ltd.
  4. * Author: Ard Biesheuvel <[email protected]>
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice and this list of conditions, without modification.
  11. * 2. The name of the author may not be used to endorse or promote products
  12. * derived from this software without specific prior written permission.
  13. *
  14. * Alternatively, this software may be distributed under the terms of the
  15. * GNU General Public License as published by the Free Software Foundation;
  16. * either version 2 of the License, or (at your option) any later version.
  17. */
  18. #include <stdint.h>
  19. //
  20. // Basic EFI types of various widths
  21. //
  22. #include <stddef.h>
  23. typedef uint64_t UINT64;
  24. typedef int64_t INT64;
  25. typedef uint32_t UINT32;
  26. typedef int32_t INT32;
  27. typedef uint16_t UINT16;
  28. typedef int16_t INT16;
  29. typedef uint8_t UINT8;
  30. typedef int8_t INT8;
  31. typedef char CHAR8;
  32. typedef wchar_t CHAR16;
  33. #define WCHAR CHAR16
  34. #undef VOID
  35. typedef void VOID;
  36. typedef int64_t INTN;
  37. typedef uint64_t UINTN;
  38. #define EFI_ERROR_MASK 0x8000000000000000
  39. #define EFIERR(a) (EFI_ERROR_MASK | a)
  40. #define EFIERR_OEM(a) (0xc000000000000000 | a)
  41. #define BAD_POINTER 0xFBFBFBFBFBFBFBFB
  42. #define MAX_ADDRESS 0xFFFFFFFFFFFFFFFF
  43. #define BREAKPOINT() while(1);
  44. //
  45. // Pointers must be aligned to these address to function
  46. //
  47. #define MIN_ALIGNMENT_SIZE 8
  48. #define ALIGN_VARIABLE(Value, Adjustment) \
  49. (UINTN)Adjustment = 0; \
  50. if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
  51. (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
  52. Value = (UINTN)Value + (UINTN)Adjustment
  53. //
  54. // Define macros to build data structure signatures from characters.
  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. // EFIAPI - prototype calling convention for EFI function pointers
  61. // BOOTSERVICE - prototype for implementation of a boot service interface
  62. // RUNTIMESERVICE - prototype for implementation of a runtime service interface
  63. // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
  64. // RUNTIME_CODE - pragma macro for declaring runtime code
  65. //
  66. #ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options
  67. #define EFIAPI // Substitute expresion to force C calling convention
  68. #endif
  69. #define BOOTSERVICE
  70. #define RUNTIMESERVICE
  71. #define RUNTIMEFUNCTION
  72. #define RUNTIME_CODE(a) alloc_text("rtcode", a)
  73. #define BEGIN_RUNTIME_DATA() data_seg("rtdata")
  74. #define END_RUNTIME_DATA() data_seg("")
  75. #define VOLATILE volatile
  76. #define MEMORY_FENCE __sync_synchronize
  77. //
  78. // When build similiar to FW, then link everything together as
  79. // one big module. For the MSVC toolchain, we simply tell the
  80. // linker what our driver init function is using /ENTRY.
  81. //
  82. #if defined(_MSC_EXTENSIONS)
  83. #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
  84. __pragma(comment(linker, "/ENTRY:" # InitFunction))
  85. #else
  86. #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
  87. UINTN \
  88. InitializeDriver ( \
  89. VOID *ImageHandle, \
  90. VOID *SystemTable \
  91. ) \
  92. { \
  93. return InitFunction(ImageHandle, \
  94. SystemTable); \
  95. } \
  96. \
  97. EFI_STATUS efi_main( \
  98. EFI_HANDLE image, \
  99. EFI_SYSTEM_TABLE *systab \
  100. ) __attribute__((weak, \
  101. alias ("InitializeDriver")));
  102. #endif
  103. #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \
  104. (_if)->LoadInternal(type, name, entry)
  105. //
  106. // Some compilers don't support the forward reference construct:
  107. // typedef struct XXXXX
  108. //
  109. // The following macro provide a workaround for such cases.
  110. #define INTERFACE_DECL(x) struct x
  111. #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__)
  112. #define EFI_FUNCTION