efibind.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* SPDX-License-Identifier: GPL-2.0+ OR BSD-2-Clause */
  2. /*
  3. * Copright (C) 2014 - 2015 Linaro Ltd.
  4. * Author: Ard Biesheuvel <ard.biesheuvel@linaro.org>
  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 wchar_t CHAR16;
  32. #define WCHAR CHAR16
  33. #ifndef BOOLEAN
  34. typedef uint8_t BOOLEAN;
  35. #endif
  36. #undef VOID
  37. typedef void VOID;
  38. typedef int64_t INTN;
  39. typedef uint64_t UINTN;
  40. #define EFI_ERROR_MASK 0x8000000000000000
  41. #define EFIERR(a) (EFI_ERROR_MASK | a)
  42. #define EFIERR_OEM(a) (0xc000000000000000 | a)
  43. #define BAD_POINTER 0xFBFBFBFBFBFBFBFB
  44. #define MAX_ADDRESS 0xFFFFFFFFFFFFFFFF
  45. #define BREAKPOINT() while(1);
  46. //
  47. // Pointers must be aligned to these address to function
  48. //
  49. #define MIN_ALIGNMENT_SIZE 8
  50. #define ALIGN_VARIABLE(Value, Adjustment) \
  51. (UINTN)Adjustment = 0; \
  52. if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
  53. (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
  54. Value = (UINTN)Value + (UINTN)Adjustment
  55. //
  56. // Define macros to build data structure signatures from characters.
  57. //
  58. #define EFI_SIGNATURE_16(A,B) ((A) | (B<<8))
  59. #define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16))
  60. #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))
  61. //
  62. // EFIAPI - prototype calling convention for EFI function pointers
  63. // BOOTSERVICE - prototype for implementation of a boot service interface
  64. // RUNTIMESERVICE - prototype for implementation of a runtime service interface
  65. // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
  66. // RUNTIME_CODE - pragma macro for declaring runtime code
  67. //
  68. #ifndef EFIAPI // Forces EFI calling conventions reguardless of compiler options
  69. #define EFIAPI // Substitute expresion to force C calling convention
  70. #endif
  71. #define BOOTSERVICE
  72. #define RUNTIMESERVICE
  73. #define RUNTIMEFUNCTION
  74. #define RUNTIME_CODE(a) alloc_text("rtcode", a)
  75. #define BEGIN_RUNTIME_DATA() data_seg("rtdata")
  76. #define END_RUNTIME_DATA() data_seg("")
  77. #define VOLATILE volatile
  78. #define MEMORY_FENCE __sync_synchronize
  79. //
  80. // When build similiar to FW, then link everything together as
  81. // one big module. For the MSVC toolchain, we simply tell the
  82. // linker what our driver init function is using /ENTRY.
  83. //
  84. #if defined(_MSC_EXTENSIONS)
  85. #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
  86. __pragma(comment(linker, "/ENTRY:" # InitFunction))
  87. #else
  88. #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
  89. UINTN \
  90. InitializeDriver ( \
  91. VOID *ImageHandle, \
  92. VOID *SystemTable \
  93. ) \
  94. { \
  95. return InitFunction(ImageHandle, \
  96. SystemTable); \
  97. } \
  98. \
  99. EFI_STATUS efi_main( \
  100. EFI_HANDLE image, \
  101. EFI_SYSTEM_TABLE *systab \
  102. ) __attribute__((weak, \
  103. alias ("InitializeDriver")));
  104. #endif
  105. #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \
  106. (_if)->LoadInternal(type, name, entry)
  107. //
  108. // Some compilers don't support the forward reference construct:
  109. // typedef struct XXXXX
  110. //
  111. // The following macro provide a workaround for such cases.
  112. #define INTERFACE_DECL(x) struct x
  113. #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__)
  114. #define EFI_FUNCTION