Source code of Windows XP (NT5)
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.

300 lines
8.9 KiB

  1. /*** aslp.h - ASL Private Definitions
  2. *
  3. * Copyright (c) 1996,1997 Microsoft Corporation
  4. * Author: Michael Tsang (MikeTs)
  5. * Created 09/05/96
  6. *
  7. * MODIFICATION HISTORY
  8. */
  9. #ifndef _ASLP_H
  10. #define _ASLP_H
  11. #pragma warning (disable: 4201)
  12. /*** Build Options
  13. */
  14. #ifdef DEBUG
  15. #define TRACING
  16. #define TUNE
  17. #endif
  18. #define ULONG_PTR ULONG
  19. #define SPEC_VER 99
  20. #ifndef EXCL_BASEDEF
  21. #include "basedef.h"
  22. #endif
  23. #include <stdio.h> //for FILE *
  24. #include <string.h> //for _stricmp
  25. #include <stdlib.h> //for malloc
  26. #include <memory.h> //for memset
  27. #include <ctype.h> //for isspace
  28. #ifdef WINNT
  29. #include <crt\io.h> //for _open, _close, _read, _write
  30. #else
  31. #include <io.h>
  32. #endif
  33. #include <fcntl.h> //for open flags
  34. #include <sys\stat.h> //for pmode flags
  35. #include "parsearg.h"
  36. #include "debug.h"
  37. #include "line.h"
  38. #define TOKERR_BASE -100
  39. #include "token.h"
  40. #include "scanasl.h"
  41. #include "acpitabl.h"
  42. #include "list.h"
  43. #define _INC_NSOBJ_ONLY
  44. #include "amli.h"
  45. #include "aml.h"
  46. #ifdef __UNASM
  47. #include "..\acpitab\acpitab.h"
  48. #define USE_CRUNTIME
  49. #include "binfmt.h"
  50. #endif
  51. /*** Constants
  52. */
  53. // String constants
  54. #define STR_PROGDESC "ACPI Source Language Assembler"
  55. #define STR_COPYRIGHT "Copyright (c) 1996,1999 Microsoft Corporation"
  56. #define STR_MS "MSFT"
  57. // Error codes
  58. #define ASLERR_NONE 0
  59. #define ASLERR_INVALID_PARAM -1
  60. #define ASLERR_OPEN_FILE -2
  61. #define ASLERR_CREATE_FILE -3
  62. #define ASLERR_READ_FILE -4
  63. #define ASLERR_WRITE_FILE -5
  64. #define ASLERR_SEEK_FILE -6
  65. #define ASLERR_INIT_SCANNER -7
  66. #define ASLERR_OUT_OF_MEM -8
  67. #define ASLERR_NAME_TOO_LONG -9
  68. #define ASLERR_NEST_DDB -10
  69. #define ASLERR_SYNTAX -11
  70. #define ASLERR_PKTLEN_TOO_LONG -12
  71. #define ASLERR_NAME_EXIST -13
  72. #define ASLERR_NSOBJ_EXIST -14
  73. #define ASLERR_NSOBJ_NOT_FOUND -15
  74. #define ASLERR_INVALID_NAME -16
  75. #define ASLERR_INTERNAL_ERROR -17
  76. #define ASLERR_INVALID_EISAID -18
  77. #define ASLERR_EXPECT_EOF -19
  78. #define ASLERR_INVALID_OPCODE -20
  79. #define ASLERR_SIG_NOT_FOUND -21
  80. #define ASLERR_GET_TABLE -22
  81. #define ASLERR_CHECKSUM -23
  82. #define ASLERR_INVALID_ARGTYPE -24
  83. #define ASLERR_INVALID_OBJTYPE -25
  84. #define ASLERR_OPEN_VXD -26
  85. // Misc. constants
  86. #define VERSION_MAJOR 1
  87. #define VERSION_MINOR 0
  88. #define VERSION_RELEASE 12
  89. #define VERSION_DWORD ((VERSION_MAJOR << 24) | \
  90. (VERSION_MINOR << 16) | \
  91. VERSION_RELEASE)
  92. #define NAMESEG_BLANK 0x5f5f5f5f // "____"
  93. #define NAMESEG_ROOT 0x5f5f5f5c // "\___"
  94. // Implementation constants
  95. #define MAX_STRING_LEN 199
  96. #define MAX_NAME_LEN 1599 //approx. 255*4 + 254 + 255
  97. #define MAX_NAMECODE_LEN 1300 //approx. 255*4 + 2 + 255
  98. #define MAX_MSG_LEN 127
  99. #define MAX_ARGS 7
  100. #define MAX_PACKAGE_LEN 0x0fffffff
  101. // gdwfASL flags
  102. #define ASLF_NOLOGO 0x00000001
  103. #define ASLF_UNASM 0x00000002
  104. #define ASLF_GENASM 0x00000004
  105. #define ASLF_GENSRC 0x00000008
  106. #define ASLF_NT 0x00000010
  107. #define ASLF_DUMP_NONASL 0x00000020
  108. #define ASLF_DUMP_BIN 0x00000040
  109. #define ASLF_CREAT_BIN 0x00000080
  110. // Term classes
  111. #define TC_PNP_MACRO 0x00100000
  112. #define TC_REF_OBJECT 0x00200000
  113. #define TC_FIELD_MACRO 0x00400000
  114. #define TC_DATA_OBJECT 0x00800000
  115. #define TC_NAMED_OBJECT 0x01000000
  116. #define TC_NAMESPACE_MODIFIER 0x02000000
  117. #define TC_OPCODE_TYPE1 0x04000000
  118. #define TC_OPCODE_TYPE2 0x08000000
  119. #define TC_CONST_NAME 0x10000000
  120. #define TC_SHORT_NAME 0x20000000
  121. #define TC_COMPILER_DIRECTIVE 0x40000000
  122. #define TC_KEYWORD 0x80000000
  123. #define TC_OPCODE (TC_OPCODE_TYPE1 | TC_OPCODE_TYPE2 | \
  124. TC_SHORT_NAME | TC_CONST_NAME | TC_DATA_OBJECT)
  125. // Term flags
  126. #define TF_ACTION_FLIST 0x00000001
  127. #define TF_ACTION_VLIST 0x00000002
  128. #define TF_PACKAGE_LEN 0x00000004
  129. #define TF_CHANGE_CHILDSCOPE 0x00000008
  130. #define TF_FIELD_MACRO TC_FIELD_MACRO
  131. #define TF_DATA_OBJECT TC_DATA_OBJECT
  132. #define TF_NAMED_OBJECT TC_NAMED_OBJECT
  133. #define TF_NAMESPACE_MODIFIER TC_NAMESPACE_MODIFIER
  134. #define TF_OPCODE_TYPE1 TC_OPCODE_TYPE1
  135. #define TF_OPCODE_TYPE2 TC_OPCODE_TYPE2
  136. #define TF_CONST_NAME TC_CONST_NAME
  137. #define TF_SHORT_NAME TC_SHORT_NAME
  138. #define TF_COMPILER_DIRECTIVE TC_COMPILER_DIRECTIVE
  139. #define TF_KEYWORD TC_KEYWORD
  140. #define TF_PNP_MACRO TC_PNP_MACRO
  141. #define TF_OBJECT_LIST (TC_NAMED_OBJECT | TC_NAMESPACE_MODIFIER)
  142. #define TF_CODE_LIST (TC_OPCODE_TYPE1 | TC_OPCODE_TYPE2)
  143. #define TF_DATA_LIST 0x00010000
  144. #define TF_FIELD_LIST 0x00020000
  145. #define TF_BYTE_LIST 0x00040000
  146. #define TF_DWORD_LIST 0x00080000
  147. #define TF_PACKAGE_LIST (TC_DATA_OBJECT | TC_SHORT_NAME | \
  148. TC_CONST_NAME)
  149. #define TF_ALL_LISTS (TF_DATA_OBJECT | TF_NAMED_OBJECT | \
  150. TF_NAMESPACE_MODIFIER | TF_OPCODE_TYPE1 | \
  151. TF_OPCODE_TYPE2 | TF_SHORT_NAME | \
  152. TF_CONST_NAME | TF_COMPILER_DIRECTIVE | \
  153. TF_DATA_LIST | TF_PACKAGE_LIST | \
  154. TF_FIELD_LIST | TF_PNP_MACRO | TF_BYTE_LIST |\
  155. TF_DWORD_LIST)
  156. // Code flags
  157. #define CF_MISSING_ARG 0x00000001
  158. #define CF_PARSING_FIXEDLIST 0x00000002
  159. #define CF_PARSING_VARLIST 0x00000004
  160. #define CF_CREATED_NSOBJ 0x00000008
  161. // NS flags
  162. #define NSF_EXIST_OK 0x00010000
  163. #define NSF_EXIST_ERR 0x00020000
  164. // Data types
  165. #define CODETYPE_UNKNOWN 0
  166. #define CODETYPE_ASLTERM 1
  167. #define CODETYPE_NAME 2
  168. #define CODETYPE_DATAOBJ 3
  169. #define CODETYPE_FIELDOBJ 4
  170. #define CODETYPE_INTEGER 5
  171. #define CODETYPE_STRING 6
  172. #define CODETYPE_KEYWORD 7
  173. #define CODETYPE_USERTERM 8
  174. #define CODETYPE_QWORD 9
  175. // NameSpace object types
  176. #define NSTYPE_UNKNOWN 'U'
  177. #define NSTYPE_SCOPE 'S'
  178. #define NSTYPE_FIELDUNIT 'F'
  179. #define NSTYPE_DEVICE 'D'
  180. #define NSTYPE_EVENT 'E'
  181. #define NSTYPE_METHOD 'M'
  182. #define NSTYPE_MUTEX 'X'
  183. #define NSTYPE_OPREGION 'O'
  184. #define NSTYPE_POWERRES 'P'
  185. #define NSTYPE_PROCESSOR 'C'
  186. #define NSTYPE_THERMALZONE 'T'
  187. #define NSTYPE_OBJALIAS 'A'
  188. #define NSTYPE_BUFFFIELD 'B'
  189. #define OBJTYPE_PRIVATE 0xf0
  190. #define OBJTYPE_PNP_RES (OBJTYPE_PRIVATE + 0x00)
  191. #define OBJTYPE_RES_FIELD (OBJTYPE_PRIVATE + 0x01)
  192. #define OBJTYPE_EXTERNAL (OBJTYPE_PRIVATE + 0x02)
  193. // Opcode classes
  194. #define OPCLASS_INVALID 0
  195. #define OPCLASS_DATA_OBJ 1
  196. #define OPCLASS_NAME_OBJ 2
  197. #define OPCLASS_CONST_OBJ 3
  198. #define OPCLASS_CODE_OBJ 4
  199. #define OPCLASS_ARG_OBJ 5
  200. #define OPCLASS_LOCAL_OBJ 6
  201. /*** Macros
  202. */
  203. #define MODNAME ProgInfo.pszProgName
  204. #define ISLEADNAMECHAR(c) (((c) >= 'A') && ((c) <= 'Z') || ((c) == '_'))
  205. #define ISNAMECHAR(c) (ISLEADNAMECHAR(c) || ((c) >= '0') && ((c) <= '9'))
  206. #define OPCODELEN(d) (((d) == OP_NONE)? 0: (((d) & 0x0000ff00)? 2: 1))
  207. #ifdef DEBUG
  208. #define MEMALLOC(n) (++gdwcMemObjs, malloc(n))
  209. #define MEMFREE(p) {ASSERT(gdwcMemObjs > 0); free(p); --gdwcMemObjs;}
  210. #else
  211. #define MEMALLOC(n) malloc(n)
  212. #define MEMFREE(p) free(p)
  213. #endif
  214. /*** Type definitions
  215. */
  216. typedef int (LOCAL *PFNTERM)(PTOKEN, BOOL);
  217. typedef struct _aslterm
  218. {
  219. PSZ pszID;
  220. LONG lID;
  221. DWORD dwfTermClass;
  222. DWORD dwTermData;
  223. DWORD dwOpcode;
  224. PSZ pszUnAsmArgTypes;
  225. PSZ pszArgTypes;
  226. PSZ pszArgActions;
  227. DWORD dwfTerm;
  228. PFNTERM pfnTerm;
  229. } ASLTERM, *PASLTERM;
  230. typedef struct _codeobj
  231. {
  232. LIST list; //link to siblings
  233. struct _codeobj *pcParent;
  234. struct _codeobj *pcFirstChild;
  235. PNSOBJ pnsObj;
  236. DWORD dwTermIndex;
  237. DWORD dwfCode;
  238. DWORD dwCodeType;
  239. DWORD dwCodeValue;
  240. DWORD dwDataLen;
  241. PBYTE pbDataBuff;
  242. DWORD dwCodeLen;
  243. BYTE bCodeChkSum;
  244. } CODEOBJ, *PCODEOBJ;
  245. typedef struct _nschk
  246. {
  247. struct _nschk *pnschkNext;
  248. char szObjName[MAX_NAME_LEN + 1];
  249. PSZ pszFile;
  250. PNSOBJ pnsScope;
  251. PNSOBJ pnsMethod;
  252. ULONG dwExpectedType;
  253. ULONG dwChkData;
  254. WORD wLineNum;
  255. } NSCHK, *PNSCHK;
  256. typedef struct _resfield
  257. {
  258. PSZ pszName;
  259. DWORD dwBitOffset;
  260. DWORD dwBitSize;
  261. } RESFIELD, *PRESFIELD;
  262. typedef struct _opmap
  263. {
  264. BYTE bExOp;
  265. BYTE bOpClass;
  266. } OPMAP, *POPMAP;
  267. #include "proto.h"
  268. #include "data.h"
  269. #endif //ifndef _ASLP_H