Leaked source code of windows server 2003
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.

543 lines
15 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 "pch.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 = (USHORT) pArgs[1].dwCodeValue;
  184. if (!(pArgs[2].dwfCode & CF_MISSING_ARG))
  185. {
  186. gpcodeScope->pnsObj->ObjData.uipDataValue = pArgs[2].dwCodeValue;
  187. }
  188. EXIT((1, "External=%d\n", rc));
  189. return rc;
  190. } //External
  191. /***LP Method - Parse Method statement
  192. *
  193. * ENTRY
  194. * ptoken -> token stream
  195. * fActionFL - TRUE if this is a fixed list action
  196. *
  197. * EXIT-SUCCESS
  198. * returns ASLERR_NONE
  199. * EXIT-FAILURE
  200. * returns negative error code
  201. */
  202. int LOCAL Method(PTOKEN ptoken, BOOL fActionFL)
  203. {
  204. int rc = ASLERR_NONE;
  205. PCODEOBJ pArgs;
  206. ENTER((1, "Method(ptoken=%p,fActionFL=%d)\n", ptoken, fActionFL));
  207. DEREF(fActionFL);
  208. ASSERT(fActionFL == TRUE);
  209. pArgs = (PCODEOBJ)gpcodeScope->pbDataBuff;
  210. if (pArgs[1].dwfCode & CF_MISSING_ARG)
  211. {
  212. pArgs[1].dwfCode &= ~CF_MISSING_ARG;
  213. SetIntObject(&pArgs[1], 0, sizeof(BYTE));
  214. }
  215. else if (pArgs[1].dwCodeValue > MAX_ARGS)
  216. {
  217. PrintTokenErr(ptoken, "Method has too many formal arguments", TRUE);
  218. rc = ASLERR_SYNTAX;
  219. }
  220. ASSERT(gpcodeScope->pnsObj != NULL);
  221. ASSERT(gpcodeScope->pnsObj->ObjData.dwDataType == OBJTYPE_METHOD);
  222. gpcodeScope->pnsObj->ObjData.uipDataValue = pArgs[1].dwCodeValue;
  223. if ((rc == ASLERR_NONE) &&
  224. ((rc = SetDefMissingKW(&pArgs[2], ID_NOTSERIALIZED)) == ASLERR_NONE))
  225. {
  226. pArgs[1].dwCodeValue |= TermTable[pArgs[2].dwTermIndex].dwTermData &
  227. 0xff;
  228. pArgs[1].bCodeChkSum = (BYTE)pArgs[1].dwCodeValue;
  229. }
  230. EXIT((1, "Method=%d\n", rc));
  231. return rc;
  232. } //Method
  233. /***LP Field - Parse Field statement
  234. *
  235. * ENTRY
  236. * ptoken -> token stream
  237. * fActionFL - TRUE if this is a fixed list action
  238. *
  239. * EXIT-SUCCESS
  240. * returns ASLERR_NONE
  241. * EXIT-FAILURE
  242. * returns negative error code
  243. */
  244. int LOCAL Field(PTOKEN ptoken, BOOL fActionFL)
  245. {
  246. int rc = ASLERR_NONE;
  247. ENTER((1, "Field(ptoken=%p,fActionFL=%d)\n", ptoken, fActionFL));
  248. DEREF(ptoken);
  249. DEREF(fActionFL);
  250. ASSERT(fActionFL == TRUE);
  251. EncodeKeywords((PCODEOBJ)gpcodeScope->pbDataBuff, 0x0e, 1);
  252. gdwFieldAccSize =
  253. ACCSIZE(((PCODEOBJ)gpcodeScope->pbDataBuff)[1].dwCodeValue);
  254. EXIT((1, "Field=%d\n", rc));
  255. return rc;
  256. } //Field
  257. /***LP IndexField - Parse IndexField statement
  258. *
  259. * ENTRY
  260. * ptoken -> token stream
  261. * fActionFL - TRUE if this is a fixed list action
  262. *
  263. * EXIT-SUCCESS
  264. * returns ASLERR_NONE
  265. * EXIT-FAILURE
  266. * returns negative error code
  267. */
  268. int LOCAL IndexField(PTOKEN ptoken, BOOL fActionFL)
  269. {
  270. int rc = ASLERR_NONE;
  271. ENTER((1, "IndexField(ptoken=%p,fActionFL=%d)\n", ptoken, fActionFL));
  272. DEREF(ptoken);
  273. DEREF(fActionFL);
  274. ASSERT(fActionFL == TRUE);
  275. EncodeKeywords((PCODEOBJ)gpcodeScope->pbDataBuff, 0x1c, 2);
  276. gdwFieldAccSize =
  277. ACCSIZE(((PCODEOBJ)gpcodeScope->pbDataBuff)[2].dwCodeValue);
  278. EXIT((1, "IndexField=%d\n", rc));
  279. return rc;
  280. } //IndexField
  281. /***LP BankField - Parse BankField statement
  282. *
  283. * ENTRY
  284. * ptoken -> token stream
  285. * fActionFL - TRUE if this is a fixed list action
  286. *
  287. * EXIT-SUCCESS
  288. * returns ASLERR_NONE
  289. * EXIT-FAILURE
  290. * returns negative error code
  291. */
  292. int LOCAL BankField(PTOKEN ptoken, BOOL fActionFL)
  293. {
  294. int rc = ASLERR_NONE;
  295. ENTER((1, "BankField(ptoken=%p,fActionFL=%d)\n", ptoken, fActionFL));
  296. DEREF(ptoken);
  297. DEREF(fActionFL);
  298. ASSERT(fActionFL == TRUE);
  299. EncodeKeywords((PCODEOBJ)gpcodeScope->pbDataBuff, 0x38, 3);
  300. gdwFieldAccSize =
  301. ACCSIZE(((PCODEOBJ)gpcodeScope->pbDataBuff)[3].dwCodeValue);
  302. EXIT((1, "BankField=%d\n", rc));
  303. return rc;
  304. } //BankField
  305. /***LP OpRegion - Parse OperationRegion statement
  306. *
  307. * ENTRY
  308. * ptoken -> token stream
  309. * fActionFL - TRUE if this is a fixed list action
  310. *
  311. * EXIT-SUCCESS
  312. * returns ASLERR_NONE
  313. * EXIT-FAILURE
  314. * returns negative error code
  315. */
  316. int LOCAL OpRegion(PTOKEN ptoken, BOOL fActionFL)
  317. {
  318. int rc = ASLERR_NONE;
  319. PCODEOBJ pArgs;
  320. ENTER((1, "OpRegion(ptoken=%p,fActionFL=%d)\n", ptoken, fActionFL));
  321. DEREF(ptoken);
  322. DEREF(fActionFL);
  323. ASSERT(fActionFL == TRUE);
  324. pArgs = (PCODEOBJ)gpcodeScope->pbDataBuff;
  325. EncodeKeywords(pArgs, 0x02, 1);
  326. ASSERT(gpcodeScope->pnsObj != NULL);
  327. ASSERT(gpcodeScope->pnsObj->ObjData.dwDataType == OBJTYPE_OPREGION);
  328. gpcodeScope->pnsObj->ObjData.uipDataValue =
  329. (pArgs[3].dwCodeType != CODETYPE_DATAOBJ)? 0xffffffff:
  330. (pArgs[3].pbDataBuff[0] == OP_BYTE)? pArgs[3].pbDataBuff[1]:
  331. (pArgs[3].pbDataBuff[0] == OP_WORD)? *(PWORD)(&pArgs[3].pbDataBuff[1]):
  332. *(PDWORD)(&pArgs[3].pbDataBuff[1]);
  333. EXIT((1, "OpRegion=%d\n", rc));
  334. return rc;
  335. } //OpRegion
  336. /***LP EISAID - Parse EISAID statement
  337. *
  338. * ENTRY
  339. * ptoken -> token stream
  340. * fActionFL - TRUE if this is a fixed list action
  341. *
  342. * EXIT-SUCCESS
  343. * returns ASLERR_NONE
  344. * EXIT-FAILURE
  345. * returns negative error code
  346. */
  347. int LOCAL EISAID(PTOKEN ptoken, BOOL fActionFL)
  348. {
  349. int rc;
  350. PCODEOBJ pArgs;
  351. DWORD dwEISAID;
  352. ENTER((1, "EISAID(ptoken=%p,fActionFL=%d)\n", ptoken, fActionFL));
  353. DEREF(ptoken);
  354. DEREF(fActionFL);
  355. ASSERT(fActionFL == TRUE);
  356. pArgs = (PCODEOBJ)gpcodeScope->pbDataBuff;
  357. if ((rc = ComputeEISAID((PSZ)pArgs[0].pbDataBuff, &dwEISAID)) ==
  358. ASLERR_NONE)
  359. {
  360. DWORD dwLen;
  361. MEMFREE(pArgs[0].pbDataBuff);
  362. pArgs[0].pbDataBuff = NULL;
  363. dwLen = (dwEISAID & 0xffff0000)? sizeof(DWORD):
  364. (dwEISAID & 0xffffff00)? sizeof(WORD): sizeof(BYTE);
  365. SetIntObject(&pArgs[0], dwEISAID, dwLen);
  366. pArgs[0].pcParent->dwCodeValue = (dwLen == sizeof(DWORD))? OP_DWORD:
  367. (dwLen == sizeof(WORD))? OP_WORD:
  368. OP_BYTE;
  369. }
  370. else
  371. {
  372. ERROR(("EISAID: invalid EISAID - %s", pArgs[0].pbDataBuff));
  373. }
  374. EXIT((1, "EISAID=%d\n", rc));
  375. return rc;
  376. } //EISAID
  377. /***LP Match - Parse Match statement
  378. *
  379. * ENTRY
  380. * ptoken -> token stream
  381. * fActionFL - TRUE if this is a fixed list action
  382. *
  383. * EXIT-SUCCESS
  384. * returns ASLERR_NONE
  385. * EXIT-FAILURE
  386. * returns negative error code
  387. */
  388. int LOCAL Match(PTOKEN ptoken, BOOL fActionFL)
  389. {
  390. int rc = ASLERR_NONE;
  391. ENTER((1, "Match(ptoken=%p,fActionFL=%d)\n", ptoken, fActionFL));
  392. DEREF(ptoken);
  393. DEREF(fActionFL);
  394. ASSERT(fActionFL == TRUE);
  395. EncodeKeywords((PCODEOBJ)gpcodeScope->pbDataBuff, 0x02, 1);
  396. EncodeKeywords((PCODEOBJ)gpcodeScope->pbDataBuff, 0x08, 3);
  397. EXIT((1, "Match=%d\n", rc));
  398. return rc;
  399. } //Match
  400. /***LP AccessAs - Parse AccessAs macro
  401. *
  402. * ENTRY
  403. * ptoken -> token stream
  404. * fActionFL - TRUE if this is a fixed list action
  405. *
  406. * EXIT-SUCCESS
  407. * returns ASLERR_NONE
  408. * EXIT-FAILURE
  409. * returns negative error code
  410. */
  411. int LOCAL AccessAs(PTOKEN ptoken, BOOL fActionFL)
  412. {
  413. int rc = ASLERR_NONE;
  414. PCODEOBJ pArgs;
  415. ENTER((1, "AccessAs(ptoken=%p,fActionFL=%d)\n", ptoken, fActionFL));
  416. DEREF(fActionFL);
  417. ASSERT(fActionFL == TRUE);
  418. pArgs = (PCODEOBJ)gpcodeScope->pbDataBuff;
  419. EncodeKeywords(pArgs, 0x01, 0);
  420. if (pArgs[1].dwfCode & CF_MISSING_ARG)
  421. {
  422. pArgs[1].dwfCode &= ~CF_MISSING_ARG;
  423. SetIntObject(&pArgs[1], 0, sizeof(BYTE));
  424. }
  425. else if (pArgs[1].dwCodeType == CODETYPE_KEYWORD) {
  426. EncodeKeywords(pArgs, 0x02, 1);
  427. }
  428. else if ((pArgs[1].dwCodeType == CODETYPE_INTEGER) && pArgs[1].dwCodeValue > MAX_BYTE)
  429. {
  430. PrintTokenErr(ptoken, "Access Attribute can only be a byte value",
  431. TRUE);
  432. rc = ASLERR_SYNTAX;
  433. }
  434. EXIT((1, "AccessAs=%d\n", rc));
  435. return rc;
  436. } //AccessAs
  437. /***LP Else - Parse Else statement
  438. *
  439. * ENTRY
  440. * ptoken -> token stream
  441. * fActionFL - TRUE if this is a fixed list action
  442. *
  443. * EXIT-SUCCESS
  444. * returns ASLERR_NONE
  445. * EXIT-FAILURE
  446. * returns negative error code
  447. */
  448. int LOCAL Else(PTOKEN ptoken, BOOL fActionFL)
  449. {
  450. int rc = ASLERR_NONE;
  451. PCODEOBJ pcPrevSibling = (PCODEOBJ)gpcodeScope->list.plistPrev;
  452. ENTER((1, "Else(ptoken=%p,fActionFL=%d)\n", ptoken, fActionFL));
  453. DEREF(fActionFL);
  454. ASSERT(fActionFL == TRUE);
  455. if ((pcPrevSibling->dwCodeType != CODETYPE_ASLTERM) ||
  456. (TermTable[pcPrevSibling->dwTermIndex].lID != ID_IF))
  457. {
  458. PrintTokenErr(ptoken, "Else statement has no matching If", TRUE);
  459. rc = ASLERR_SYNTAX;
  460. }
  461. EXIT((1, "Else=%d\n", rc));
  462. return rc;
  463. } //Else