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.

536 lines
14 KiB

  1. /*** aslterms.c - Parse ASL terms
  2. *
  3. * Copyright (c) 1996,1997 Microsoft Corporation
  4. * Author: Michael Tsang (MikeTs)
  5. * Created: 10/10/96
  6. *
  7. * MODIFICATION HISTORY
  8. */
  9. #include "aslp.h"
  10. /***LP DefinitionBlock - Generate code for DefinitionBlock
  11. *
  12. * ENTRY
  13. * ptoken -> token stream
  14. * fActionFL - TRUE if this is a fixed list action
  15. *
  16. * EXIT-SUCCESS
  17. * returns ASLERR_NONE
  18. * EXIT-FAILURE
  19. * returns negative error code
  20. */
  21. int LOCAL DefinitionBlock(PTOKEN ptoken, BOOL fActionFL)
  22. {
  23. int rc = ASLERR_NONE;
  24. PCODEOBJ pArgs;
  25. #define OFLAGS (_O_BINARY | _O_CREAT | _O_RDWR | _O_TRUNC)
  26. #define PMODE (_S_IREAD | _S_IWRITE)
  27. ENTER((1, "DefinitionBlock(ptoken=%p,fActionFL=%d)\n", ptoken, fActionFL));
  28. pArgs = (PCODEOBJ)gpcodeScope->pbDataBuff;
  29. if (fActionFL)
  30. {
  31. if (gpcodeScope->pcParent != NULL)
  32. {
  33. PrintTokenErr(ptoken, "Definition block cannot nest", TRUE);
  34. rc = ASLERR_NEST_DDB;
  35. }
  36. else if (strlen((PSZ)pArgs[1].pbDataBuff) != sizeof(ghdrDDB.Signature))
  37. {
  38. ERROR(("DefinitionBlock: DDB signature too long - %s",
  39. pArgs[1].pbDataBuff));
  40. rc = ASLERR_SYNTAX;
  41. }
  42. else if (strlen((PSZ)pArgs[3].pbDataBuff) > sizeof(ghdrDDB.OEMID))
  43. {
  44. ERROR(("DefinitionBlock: OEM ID too long - %s",
  45. pArgs[3].pbDataBuff));
  46. rc = ASLERR_SYNTAX;
  47. }
  48. else if (strlen((PSZ)pArgs[4].pbDataBuff) > sizeof(ghdrDDB.OEMTableID))
  49. {
  50. ERROR(("DefinitionBlock: OEM Table ID too long - %s",
  51. pArgs[4].pbDataBuff));
  52. rc = ASLERR_SYNTAX;
  53. }
  54. else
  55. {
  56. memset(&ghdrDDB, 0, sizeof(DESCRIPTION_HEADER));
  57. memcpy(&ghdrDDB.Signature, pArgs[1].pbDataBuff,
  58. sizeof(ghdrDDB.Signature));
  59. memcpy(&ghdrDDB.Revision, &pArgs[2].dwCodeValue,
  60. sizeof(ghdrDDB.Revision));
  61. memcpy(ghdrDDB.OEMID, pArgs[3].pbDataBuff,
  62. strlen((PSZ)pArgs[3].pbDataBuff));
  63. memcpy(ghdrDDB.OEMTableID, pArgs[4].pbDataBuff,
  64. strlen((PSZ)pArgs[4].pbDataBuff));
  65. memcpy(&ghdrDDB.OEMRevision, &pArgs[5].dwCodeValue,
  66. sizeof(ghdrDDB.OEMRevision));
  67. memcpy(ghdrDDB.CreatorID, STR_MS, sizeof(ghdrDDB.CreatorID));
  68. ghdrDDB.CreatorRev = VERSION_DWORD;
  69. }
  70. }
  71. else
  72. {
  73. int fhAML = 0;
  74. PBYTE pb;
  75. DWORD dwCodeOffset = sizeof(ghdrDDB);
  76. ASSERT(gpcodeScope->pcParent == NULL);
  77. ghdrDDB.Length = gpcodeRoot->dwCodeLen + sizeof(DESCRIPTION_HEADER);
  78. ghdrDDB.Checksum = (BYTE)(-(gpcodeRoot->bCodeChkSum +
  79. ComputeDataChkSum((PBYTE)&ghdrDDB,
  80. sizeof(DESCRIPTION_HEADER))));
  81. if ((gpnschkHead == NULL) ||
  82. ((rc = ValidateNSChkList(gpnschkHead)) == ASLERR_NONE))
  83. {
  84. if (gpszAMLFile == NULL)
  85. {
  86. strncpy(gszAMLName, (PSZ)pArgs[0].pbDataBuff,
  87. _MAX_FNAME - 1);
  88. gpszAMLFile = gszAMLName;
  89. }
  90. if ((fhAML = _open(gpszAMLFile, OFLAGS, PMODE))== -1)
  91. {
  92. ERROR(("DefinitionBlock: failed to open AML file - %s",
  93. pArgs[0].pbDataBuff));
  94. rc = ASLERR_CREATE_FILE;
  95. }
  96. else if (_write(fhAML, &ghdrDDB, sizeof(ghdrDDB)) != sizeof(ghdrDDB))
  97. {
  98. ERROR(("DefinitionBlock: failed to write DDB header"));
  99. rc = ASLERR_WRITE_FILE;
  100. }
  101. else if ((rc = WriteAMLFile(fhAML, gpcodeRoot, &dwCodeOffset)) !=
  102. ASLERR_NONE)
  103. {
  104. ERROR(("DefinitionBlock: failed to write AML file"));
  105. }
  106. else if ((pb = MEMALLOC(ghdrDDB.Length)) != NULL)
  107. {
  108. if (_lseek(fhAML, 0, SEEK_SET) == -1)
  109. {
  110. ERROR(("DefinitionBlock: failed seeking to beginning of image file"));
  111. }
  112. else if (_read(fhAML, pb, ghdrDDB.Length) != (int)ghdrDDB.Length)
  113. {
  114. ERROR(("DefinitionBlock: failed to read back image file"));
  115. }
  116. else if (ComputeDataChkSum(pb, ghdrDDB.Length) != 0)
  117. {
  118. ERROR(("DefinitionBlock: failed to verify checksum of image file"));
  119. }
  120. MEMFREE(pb);
  121. }
  122. if (rc == ASLERR_NONE)
  123. {
  124. printf("%s(%s): Image Size=%ld, Image Checksum=0x%x\n\n",
  125. MODNAME, pArgs[0].pbDataBuff, ghdrDDB.Length, ghdrDDB.Checksum);
  126. }
  127. if (fhAML != 0)
  128. {
  129. _close(fhAML);
  130. }
  131. }
  132. FreeCodeObjs(gpcodeRoot);
  133. gpcodeRoot = NULL;
  134. }
  135. EXIT((1, "DefinitionBlock=%d\n", rc));
  136. return rc;
  137. } //DefinitionBlock
  138. /***LP Include - Include an ASL file
  139. *
  140. * ENTRY
  141. * ptoken -> token stream
  142. * fActionFL - TRUE if this is a fixed list action
  143. *
  144. * EXIT-SUCCESS
  145. * returns ASLERR_NONE
  146. * EXIT-FAILURE
  147. * returns negative error code
  148. */
  149. int LOCAL Include(PTOKEN ptoken, BOOL fActionFL)
  150. {
  151. int rc;
  152. PCODEOBJ pArgs;
  153. ENTER((1, "Include(ptoken=%p,fActionFL=%d)\n", ptoken, fActionFL));
  154. DEREF(ptoken);
  155. DEREF(fActionFL);
  156. ASSERT(fActionFL == TRUE);
  157. pArgs = (PCODEOBJ)gpcodeScope->pbDataBuff;
  158. rc = ParseASLFile((PSZ)pArgs[0].pbDataBuff);
  159. EXIT((1, "Include=%d\n", rc));
  160. return rc;
  161. } //Include
  162. /***LP External - Declaring external object
  163. *
  164. * ENTRY
  165. * ptoken -> token stream
  166. * fActionFL - TRUE if this is a fixed list action
  167. *
  168. * EXIT-SUCCESS
  169. * returns ASLERR_NONE
  170. * EXIT-FAILURE
  171. * returns negative error code
  172. */
  173. int LOCAL External(PTOKEN ptoken, BOOL fActionFL)
  174. {
  175. int rc = ASLERR_NONE;
  176. PCODEOBJ pArgs;
  177. ENTER((1, "External(ptoken=%p,fActionFL=%d)\n", ptoken, fActionFL));
  178. DEREF(ptoken);
  179. DEREF(fActionFL);
  180. ASSERT(fActionFL == TRUE);
  181. pArgs = (PCODEOBJ)gpcodeScope->pbDataBuff;
  182. EncodeKeywords(pArgs, 0x02, 1);
  183. gpcodeScope->pnsObj->ObjData.dwDataType = pArgs[1].dwCodeValue;
  184. EXIT((1, "External=%d\n", rc));
  185. return rc;
  186. } //External
  187. /***LP Method - Parse Method statement
  188. *
  189. * ENTRY
  190. * ptoken -> token stream
  191. * fActionFL - TRUE if this is a fixed list action
  192. *
  193. * EXIT-SUCCESS
  194. * returns ASLERR_NONE
  195. * EXIT-FAILURE
  196. * returns negative error code
  197. */
  198. int LOCAL Method(PTOKEN ptoken, BOOL fActionFL)
  199. {
  200. int rc = ASLERR_NONE;
  201. PCODEOBJ pArgs;
  202. ENTER((1, "Method(ptoken=%p,fActionFL=%d)\n", ptoken, fActionFL));
  203. DEREF(fActionFL);
  204. ASSERT(fActionFL == TRUE);
  205. pArgs = (PCODEOBJ)gpcodeScope->pbDataBuff;
  206. if (pArgs[1].dwfCode & CF_MISSING_ARG)
  207. {
  208. pArgs[1].dwfCode &= ~CF_MISSING_ARG;
  209. SetIntObject(&pArgs[1], 0, sizeof(BYTE));
  210. }
  211. else if (pArgs[1].dwCodeValue > MAX_ARGS)
  212. {
  213. PrintTokenErr(ptoken, "Method has too many formal arguments", TRUE);
  214. rc = ASLERR_SYNTAX;
  215. }
  216. ASSERT(gpcodeScope->pnsObj != NULL);
  217. ASSERT(gpcodeScope->pnsObj->ObjData.dwDataType == OBJTYPE_METHOD);
  218. gpcodeScope->pnsObj->ObjData.uipDataValue = pArgs[1].dwCodeValue;
  219. if ((rc == ASLERR_NONE) &&
  220. ((rc = SetDefMissingKW(&pArgs[2], ID_NOTSERIALIZED)) == ASLERR_NONE))
  221. {
  222. pArgs[1].dwCodeValue |= TermTable[pArgs[2].dwTermIndex].dwTermData &
  223. 0xff;
  224. pArgs[1].bCodeChkSum = (BYTE)pArgs[1].dwCodeValue;
  225. }
  226. EXIT((1, "Method=%d\n", rc));
  227. return rc;
  228. } //Method
  229. /***LP Field - Parse Field statement
  230. *
  231. * ENTRY
  232. * ptoken -> token stream
  233. * fActionFL - TRUE if this is a fixed list action
  234. *
  235. * EXIT-SUCCESS
  236. * returns ASLERR_NONE
  237. * EXIT-FAILURE
  238. * returns negative error code
  239. */
  240. int LOCAL Field(PTOKEN ptoken, BOOL fActionFL)
  241. {
  242. int rc = ASLERR_NONE;
  243. ENTER((1, "Field(ptoken=%p,fActionFL=%d)\n", ptoken, fActionFL));
  244. DEREF(ptoken);
  245. DEREF(fActionFL);
  246. ASSERT(fActionFL == TRUE);
  247. EncodeKeywords((PCODEOBJ)gpcodeScope->pbDataBuff, 0x0e, 1);
  248. gdwFieldAccSize =
  249. ACCSIZE(((PCODEOBJ)gpcodeScope->pbDataBuff)[1].dwCodeValue);
  250. EXIT((1, "Field=%d\n", rc));
  251. return rc;
  252. } //Field
  253. /***LP IndexField - Parse IndexField statement
  254. *
  255. * ENTRY
  256. * ptoken -> token stream
  257. * fActionFL - TRUE if this is a fixed list action
  258. *
  259. * EXIT-SUCCESS
  260. * returns ASLERR_NONE
  261. * EXIT-FAILURE
  262. * returns negative error code
  263. */
  264. int LOCAL IndexField(PTOKEN ptoken, BOOL fActionFL)
  265. {
  266. int rc = ASLERR_NONE;
  267. ENTER((1, "IndexField(ptoken=%p,fActionFL=%d)\n", ptoken, fActionFL));
  268. DEREF(ptoken);
  269. DEREF(fActionFL);
  270. ASSERT(fActionFL == TRUE);
  271. EncodeKeywords((PCODEOBJ)gpcodeScope->pbDataBuff, 0x1c, 2);
  272. gdwFieldAccSize =
  273. ACCSIZE(((PCODEOBJ)gpcodeScope->pbDataBuff)[2].dwCodeValue);
  274. EXIT((1, "IndexField=%d\n", rc));
  275. return rc;
  276. } //IndexField
  277. /***LP BankField - Parse BankField statement
  278. *
  279. * ENTRY
  280. * ptoken -> token stream
  281. * fActionFL - TRUE if this is a fixed list action
  282. *
  283. * EXIT-SUCCESS
  284. * returns ASLERR_NONE
  285. * EXIT-FAILURE
  286. * returns negative error code
  287. */
  288. int LOCAL BankField(PTOKEN ptoken, BOOL fActionFL)
  289. {
  290. int rc = ASLERR_NONE;
  291. ENTER((1, "BankField(ptoken=%p,fActionFL=%d)\n", ptoken, fActionFL));
  292. DEREF(ptoken);
  293. DEREF(fActionFL);
  294. ASSERT(fActionFL == TRUE);
  295. EncodeKeywords((PCODEOBJ)gpcodeScope->pbDataBuff, 0x38, 3);
  296. gdwFieldAccSize =
  297. ACCSIZE(((PCODEOBJ)gpcodeScope->pbDataBuff)[3].dwCodeValue);
  298. EXIT((1, "BankField=%d\n", rc));
  299. return rc;
  300. } //BankField
  301. /***LP OpRegion - Parse OperationRegion statement
  302. *
  303. * ENTRY
  304. * ptoken -> token stream
  305. * fActionFL - TRUE if this is a fixed list action
  306. *
  307. * EXIT-SUCCESS
  308. * returns ASLERR_NONE
  309. * EXIT-FAILURE
  310. * returns negative error code
  311. */
  312. int LOCAL OpRegion(PTOKEN ptoken, BOOL fActionFL)
  313. {
  314. int rc = ASLERR_NONE;
  315. PCODEOBJ pArgs;
  316. ENTER((1, "OpRegion(ptoken=%p,fActionFL=%d)\n", ptoken, fActionFL));
  317. DEREF(ptoken);
  318. DEREF(fActionFL);
  319. ASSERT(fActionFL == TRUE);
  320. pArgs = (PCODEOBJ)gpcodeScope->pbDataBuff;
  321. EncodeKeywords(pArgs, 0x02, 1);
  322. ASSERT(gpcodeScope->pnsObj != NULL);
  323. ASSERT(gpcodeScope->pnsObj->ObjData.dwDataType == OBJTYPE_OPREGION);
  324. gpcodeScope->pnsObj->ObjData.uipDataValue =
  325. (pArgs[3].dwCodeType != CODETYPE_DATAOBJ)? 0xffffffff:
  326. (pArgs[3].pbDataBuff[0] == OP_BYTE)? pArgs[3].pbDataBuff[1]:
  327. (pArgs[3].pbDataBuff[0] == OP_WORD)? *(PWORD)(&pArgs[3].pbDataBuff[1]):
  328. *(PDWORD)(&pArgs[3].pbDataBuff[1]);
  329. EXIT((1, "OpRegion=%d\n", rc));
  330. return rc;
  331. } //OpRegion
  332. /***LP EISAID - Parse EISAID statement
  333. *
  334. * ENTRY
  335. * ptoken -> token stream
  336. * fActionFL - TRUE if this is a fixed list action
  337. *
  338. * EXIT-SUCCESS
  339. * returns ASLERR_NONE
  340. * EXIT-FAILURE
  341. * returns negative error code
  342. */
  343. int LOCAL EISAID(PTOKEN ptoken, BOOL fActionFL)
  344. {
  345. int rc;
  346. PCODEOBJ pArgs;
  347. DWORD dwEISAID;
  348. ENTER((1, "EISAID(ptoken=%p,fActionFL=%d)\n", ptoken, fActionFL));
  349. DEREF(ptoken);
  350. DEREF(fActionFL);
  351. ASSERT(fActionFL == TRUE);
  352. pArgs = (PCODEOBJ)gpcodeScope->pbDataBuff;
  353. if ((rc = ComputeEISAID((PSZ)pArgs[0].pbDataBuff, &dwEISAID)) ==
  354. ASLERR_NONE)
  355. {
  356. DWORD dwLen;
  357. MEMFREE(pArgs[0].pbDataBuff);
  358. pArgs[0].pbDataBuff = NULL;
  359. dwLen = (dwEISAID & 0xffff0000)? sizeof(DWORD):
  360. (dwEISAID & 0xffffff00)? sizeof(WORD): sizeof(BYTE);
  361. SetIntObject(&pArgs[0], dwEISAID, dwLen);
  362. pArgs[0].pcParent->dwCodeValue = (dwLen == sizeof(DWORD))? OP_DWORD:
  363. (dwLen == sizeof(WORD))? OP_WORD:
  364. OP_BYTE;
  365. }
  366. else
  367. {
  368. ERROR(("EISAID: invalid EISAID - %s", pArgs[0].pbDataBuff));
  369. }
  370. EXIT((1, "EISAID=%d\n", rc));
  371. return rc;
  372. } //EISAID
  373. /***LP Match - Parse Match statement
  374. *
  375. * ENTRY
  376. * ptoken -> token stream
  377. * fActionFL - TRUE if this is a fixed list action
  378. *
  379. * EXIT-SUCCESS
  380. * returns ASLERR_NONE
  381. * EXIT-FAILURE
  382. * returns negative error code
  383. */
  384. int LOCAL Match(PTOKEN ptoken, BOOL fActionFL)
  385. {
  386. int rc = ASLERR_NONE;
  387. ENTER((1, "Match(ptoken=%p,fActionFL=%d)\n", ptoken, fActionFL));
  388. DEREF(ptoken);
  389. DEREF(fActionFL);
  390. ASSERT(fActionFL == TRUE);
  391. EncodeKeywords((PCODEOBJ)gpcodeScope->pbDataBuff, 0x02, 1);
  392. EncodeKeywords((PCODEOBJ)gpcodeScope->pbDataBuff, 0x08, 3);
  393. EXIT((1, "Match=%d\n", rc));
  394. return rc;
  395. } //Match
  396. /***LP AccessAs - Parse AccessAs macro
  397. *
  398. * ENTRY
  399. * ptoken -> token stream
  400. * fActionFL - TRUE if this is a fixed list action
  401. *
  402. * EXIT-SUCCESS
  403. * returns ASLERR_NONE
  404. * EXIT-FAILURE
  405. * returns negative error code
  406. */
  407. int LOCAL AccessAs(PTOKEN ptoken, BOOL fActionFL)
  408. {
  409. int rc = ASLERR_NONE;
  410. PCODEOBJ pArgs;
  411. ENTER((1, "AccessAs(ptoken=%p,fActionFL=%d)\n", ptoken, fActionFL));
  412. DEREF(fActionFL);
  413. ASSERT(fActionFL == TRUE);
  414. pArgs = (PCODEOBJ)gpcodeScope->pbDataBuff;
  415. EncodeKeywords(pArgs, 0x01, 0);
  416. if (pArgs[1].dwfCode & CF_MISSING_ARG)
  417. {
  418. pArgs[1].dwfCode &= ~CF_MISSING_ARG;
  419. SetIntObject(&pArgs[1], 0, sizeof(BYTE));
  420. }
  421. else if (pArgs[1].dwCodeValue > MAX_BYTE)
  422. {
  423. PrintTokenErr(ptoken, "Access Attribute can only be a byte value",
  424. TRUE);
  425. rc = ASLERR_SYNTAX;
  426. }
  427. EXIT((1, "AccessAs=%d\n", rc));
  428. return rc;
  429. } //AccessAs
  430. /***LP Else - Parse Else statement
  431. *
  432. * ENTRY
  433. * ptoken -> token stream
  434. * fActionFL - TRUE if this is a fixed list action
  435. *
  436. * EXIT-SUCCESS
  437. * returns ASLERR_NONE
  438. * EXIT-FAILURE
  439. * returns negative error code
  440. */
  441. int LOCAL Else(PTOKEN ptoken, BOOL fActionFL)
  442. {
  443. int rc = ASLERR_NONE;
  444. PCODEOBJ pcPrevSibling = (PCODEOBJ)gpcodeScope->list.plistPrev;
  445. ENTER((1, "Else(ptoken=%p,fActionFL=%d)\n", ptoken, fActionFL));
  446. DEREF(fActionFL);
  447. ASSERT(fActionFL == TRUE);
  448. if ((pcPrevSibling->dwCodeType != CODETYPE_ASLTERM) ||
  449. (TermTable[pcPrevSibling->dwTermIndex].lID != ID_IF))
  450. {
  451. PrintTokenErr(ptoken, "Else statement has no matching If", TRUE);
  452. rc = ASLERR_SYNTAX;
  453. }
  454. EXIT((1, "Else=%d\n", rc));
  455. return rc;
  456. } //Else