efibind.h 5.1 KB

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