You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Base.h 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /** @file
  2. Root include file for Mde Package Base type modules
  3. This is the include file for any module of type base. Base modules only use
  4. types defined via this include file and can be ported easily to any
  5. environment. There are a set of base libraries in the Mde Package that can
  6. be used to implement base modules.
  7. Copyright (c) 2006 - 2008, Intel Corporation
  8. All rights reserved. This program and the accompanying materials
  9. are licensed and made available under the terms and conditions of the BSD License
  10. which accompanies this distribution. The full text of the license may be found at
  11. http://opensource.org/licenses/bsd-license.php
  12. THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  13. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
  14. **/
  15. #ifndef __BASE_H__
  16. #define __BASE_H__
  17. //
  18. // Include processor specific binding
  19. //
  20. #include <gpxe/efi/ProcessorBind.h>
  21. typedef struct {
  22. UINT32 Data1;
  23. UINT16 Data2;
  24. UINT16 Data3;
  25. UINT8 Data4[8];
  26. } GUID;
  27. typedef UINT64 PHYSICAL_ADDRESS;
  28. ///
  29. /// LIST_ENTRY definition
  30. ///
  31. typedef struct _LIST_ENTRY LIST_ENTRY;
  32. struct _LIST_ENTRY {
  33. LIST_ENTRY *ForwardLink;
  34. LIST_ENTRY *BackLink;
  35. };
  36. //
  37. // Modifiers to absract standard types to aid in debug of problems
  38. //
  39. #define CONST const
  40. #define STATIC static
  41. #define VOID void
  42. //
  43. // Modifiers for Data Types used to self document code.
  44. // This concept is borrowed for UEFI specification.
  45. //
  46. #define IN
  47. #define OUT
  48. #define OPTIONAL
  49. //
  50. // UEFI specification claims 1 and 0. We are concerned about the
  51. // complier portability so we did it this way.
  52. //
  53. #define TRUE ((BOOLEAN)(1==1))
  54. #define FALSE ((BOOLEAN)(0==1))
  55. #define NULL ((VOID *) 0)
  56. #define BIT0 0x00000001
  57. #define BIT1 0x00000002
  58. #define BIT2 0x00000004
  59. #define BIT3 0x00000008
  60. #define BIT4 0x00000010
  61. #define BIT5 0x00000020
  62. #define BIT6 0x00000040
  63. #define BIT7 0x00000080
  64. #define BIT8 0x00000100
  65. #define BIT9 0x00000200
  66. #define BIT10 0x00000400
  67. #define BIT11 0x00000800
  68. #define BIT12 0x00001000
  69. #define BIT13 0x00002000
  70. #define BIT14 0x00004000
  71. #define BIT15 0x00008000
  72. #define BIT16 0x00010000
  73. #define BIT17 0x00020000
  74. #define BIT18 0x00040000
  75. #define BIT19 0x00080000
  76. #define BIT20 0x00100000
  77. #define BIT21 0x00200000
  78. #define BIT22 0x00400000
  79. #define BIT23 0x00800000
  80. #define BIT24 0x01000000
  81. #define BIT25 0x02000000
  82. #define BIT26 0x04000000
  83. #define BIT27 0x08000000
  84. #define BIT28 0x10000000
  85. #define BIT29 0x20000000
  86. #define BIT30 0x40000000
  87. #define BIT31 0x80000000
  88. #define BIT32 0x0000000100000000UL
  89. #define BIT33 0x0000000200000000UL
  90. #define BIT34 0x0000000400000000UL
  91. #define BIT35 0x0000000800000000UL
  92. #define BIT36 0x0000001000000000UL
  93. #define BIT37 0x0000002000000000UL
  94. #define BIT38 0x0000004000000000UL
  95. #define BIT39 0x0000008000000000UL
  96. #define BIT40 0x0000010000000000UL
  97. #define BIT41 0x0000020000000000UL
  98. #define BIT42 0x0000040000000000UL
  99. #define BIT43 0x0000080000000000UL
  100. #define BIT44 0x0000100000000000UL
  101. #define BIT45 0x0000200000000000UL
  102. #define BIT46 0x0000400000000000UL
  103. #define BIT47 0x0000800000000000UL
  104. #define BIT48 0x0001000000000000UL
  105. #define BIT49 0x0002000000000000UL
  106. #define BIT50 0x0004000000000000UL
  107. #define BIT51 0x0008000000000000UL
  108. #define BIT52 0x0010000000000000UL
  109. #define BIT53 0x0020000000000000UL
  110. #define BIT54 0x0040000000000000UL
  111. #define BIT55 0x0080000000000000UL
  112. #define BIT56 0x0100000000000000UL
  113. #define BIT57 0x0200000000000000UL
  114. #define BIT58 0x0400000000000000UL
  115. #define BIT59 0x0800000000000000UL
  116. #define BIT60 0x1000000000000000UL
  117. #define BIT61 0x2000000000000000UL
  118. #define BIT62 0x4000000000000000UL
  119. #define BIT63 0x8000000000000000UL
  120. //
  121. // Support for variable length argument lists using the ANSI standard.
  122. //
  123. // Since we are using the ANSI standard we used the standard nameing and
  124. // did not folow the coding convention
  125. //
  126. // VA_LIST - typedef for argument list.
  127. // VA_START (VA_LIST Marker, argument before the ...) - Init Marker for use.
  128. // VA_END (VA_LIST Marker) - Clear Marker
  129. // VA_ARG (VA_LIST Marker, var arg size) - Use Marker to get an argumnet from
  130. // the ... list. You must know the size and pass it in this macro.
  131. //
  132. // example:
  133. //
  134. // UINTN
  135. // ExampleVarArg (
  136. // IN UINTN NumberOfArgs,
  137. // ...
  138. // )
  139. // {
  140. // VA_LIST Marker;
  141. // UINTN Index;
  142. // UINTN Result;
  143. //
  144. // //
  145. // // Initialize the Marker
  146. // //
  147. // VA_START (Marker, NumberOfArgs);
  148. // for (Index = 0, Result = 0; Index < NumberOfArgs; Index++) {
  149. // //
  150. // // The ... list is a series of UINTN values, so average them up.
  151. // //
  152. // Result += VA_ARG (Marker, UINTN);
  153. // }
  154. //
  155. // VA_END (Marker);
  156. // return Result
  157. // }
  158. //
  159. #define _INT_SIZE_OF(n) ((sizeof (n) + sizeof (UINTN) - 1) &~(sizeof (UINTN) - 1))
  160. //
  161. // Also support coding convention rules for var arg macros
  162. //
  163. typedef CHAR8 *VA_LIST;
  164. #define VA_START(ap, v) (ap = (VA_LIST) & (v) + _INT_SIZE_OF (v))
  165. #define VA_ARG(ap, t) (*(t *) ((ap += _INT_SIZE_OF (t)) - _INT_SIZE_OF (t)))
  166. #define VA_END(ap) (ap = (VA_LIST) 0)
  167. //
  168. // Macro that returns the byte offset of a field in a data structure.
  169. //
  170. #define OFFSET_OF(TYPE, Field) ((UINTN) &(((TYPE *)0)->Field))
  171. ///
  172. /// CONTAINING_RECORD - returns a pointer to the structure
  173. /// from one of it's elements.
  174. ///
  175. #define _CR(Record, TYPE, Field) ((TYPE *) ((CHAR8 *) (Record) - (CHAR8 *) &(((TYPE *) 0)->Field)))
  176. ///
  177. /// ALIGN_VALUE - aligns a value up to the next boundary of the given alignment.
  178. ///
  179. #define ALIGN_VALUE(Value, Alignment) ((Value) + (((Alignment) - (Value)) & ((Alignment) - 1)))
  180. ///
  181. /// ALIGN_POINTER - aligns a pointer to the lowest boundry
  182. ///
  183. #define ALIGN_POINTER(Pointer, Alignment) ((VOID *) (ALIGN_VALUE ((UINTN)(Pointer), (Alignment))))
  184. ///
  185. /// ALIGN_VARIABLE - aligns a variable up to the next natural boundry for int size of a processor
  186. ///
  187. #define ALIGN_VARIABLE(Value) ALIGN_VALUE ((Value), sizeof (UINTN))
  188. //
  189. // Return the maximum of two operands.
  190. // This macro returns the maximum of two operand specified by a and b.
  191. // Both a and b must be the same numerical types, signed or unsigned.
  192. //
  193. #define MAX(a, b) \
  194. (((a) > (b)) ? (a) : (b))
  195. //
  196. // Return the minimum of two operands.
  197. // This macro returns the minimal of two operand specified by a and b.
  198. // Both a and b must be the same numerical types, signed or unsigned.
  199. //
  200. #define MIN(a, b) \
  201. (((a) < (b)) ? (a) : (b))
  202. //
  203. // EFI Error Codes common to all execution phases
  204. //
  205. typedef INTN RETURN_STATUS;
  206. ///
  207. /// Set the upper bit to indicate EFI Error.
  208. ///
  209. #define ENCODE_ERROR(a) (MAX_BIT | (a))
  210. #define ENCODE_WARNING(a) (a)
  211. #define RETURN_ERROR(a) ((INTN) (a) < 0)
  212. #define RETURN_SUCCESS 0
  213. #define RETURN_LOAD_ERROR ENCODE_ERROR (1)
  214. #define RETURN_INVALID_PARAMETER ENCODE_ERROR (2)
  215. #define RETURN_UNSUPPORTED ENCODE_ERROR (3)
  216. #define RETURN_BAD_BUFFER_SIZE ENCODE_ERROR (4)
  217. #define RETURN_BUFFER_TOO_SMALL ENCODE_ERROR (5)
  218. #define RETURN_NOT_READY ENCODE_ERROR (6)
  219. #define RETURN_DEVICE_ERROR ENCODE_ERROR (7)
  220. #define RETURN_WRITE_PROTECTED ENCODE_ERROR (8)
  221. #define RETURN_OUT_OF_RESOURCES ENCODE_ERROR (9)
  222. #define RETURN_VOLUME_CORRUPTED ENCODE_ERROR (10)
  223. #define RETURN_VOLUME_FULL ENCODE_ERROR (11)
  224. #define RETURN_NO_MEDIA ENCODE_ERROR (12)
  225. #define RETURN_MEDIA_CHANGED ENCODE_ERROR (13)
  226. #define RETURN_NOT_FOUND ENCODE_ERROR (14)
  227. #define RETURN_ACCESS_DENIED ENCODE_ERROR (15)
  228. #define RETURN_NO_RESPONSE ENCODE_ERROR (16)
  229. #define RETURN_NO_MAPPING ENCODE_ERROR (17)
  230. #define RETURN_TIMEOUT ENCODE_ERROR (18)
  231. #define RETURN_NOT_STARTED ENCODE_ERROR (19)
  232. #define RETURN_ALREADY_STARTED ENCODE_ERROR (20)
  233. #define RETURN_ABORTED ENCODE_ERROR (21)
  234. #define RETURN_ICMP_ERROR ENCODE_ERROR (22)
  235. #define RETURN_TFTP_ERROR ENCODE_ERROR (23)
  236. #define RETURN_PROTOCOL_ERROR ENCODE_ERROR (24)
  237. #define RETURN_INCOMPATIBLE_VERSION ENCODE_ERROR (25)
  238. #define RETURN_SECURITY_VIOLATION ENCODE_ERROR (26)
  239. #define RETURN_CRC_ERROR ENCODE_ERROR (27)
  240. #define RETURN_END_OF_MEDIA ENCODE_ERROR (28)
  241. #define RETURN_END_OF_FILE ENCODE_ERROR (31)
  242. #define RETURN_INVALID_LANGUAGE ENCODE_ERROR (32)
  243. #define RETURN_WARN_UNKNOWN_GLYPH ENCODE_WARNING (1)
  244. #define RETURN_WARN_DELETE_FAILURE ENCODE_WARNING (2)
  245. #define RETURN_WARN_WRITE_FAILURE ENCODE_WARNING (3)
  246. #define RETURN_WARN_BUFFER_TOO_SMALL ENCODE_WARNING (4)
  247. /**
  248. Returns a 16-bit signature built from 2 ASCII characters.
  249. @param A The first ASCII character.
  250. @param B The second ASCII character.
  251. @return A 16-bit value built from the two ASCII characters specified by A and B.
  252. **/
  253. #define SIGNATURE_16(A, B) ((A) | (B << 8))
  254. /**
  255. Returns a 32-bit signature built from 4 ASCII characters.
  256. @param A The first ASCII character.
  257. @param B The second ASCII character.
  258. @param C The third ASCII character.
  259. @param D The fourth ASCII character.
  260. @return A 32-bit value built from the two ASCII characters specified by A, B,
  261. C and D.
  262. **/
  263. #define SIGNATURE_32(A, B, C, D) (SIGNATURE_16 (A, B) | (SIGNATURE_16 (C, D) << 16))
  264. /**
  265. Returns a 64-bit signature built from 8 ASCII characters.
  266. @param A The first ASCII character.
  267. @param B The second ASCII character.
  268. @param C The third ASCII character.
  269. @param D The fourth ASCII character.
  270. @param E The fifth ASCII character.
  271. @param F The sixth ASCII character.
  272. @param G The seventh ASCII character.
  273. @param H The eighth ASCII character.
  274. @return A 64-bit value built from the two ASCII characters specified by A, B,
  275. C, D, E, F, G and H.
  276. **/
  277. #define SIGNATURE_64(A, B, C, D, E, F, G, H) \
  278. (SIGNATURE_32 (A, B, C, D) | ((UINT64) (SIGNATURE_32 (E, F, G, H)) << 32))
  279. #endif