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.

2205 lines
72 KiB

  1. /*** parseasl.c - Parse ASL source file
  2. *
  3. * Copyright (c) 1996,1997 Microsoft Corporation
  4. * Author: Michael Tsang (MikeTs)
  5. * Created: 09/07/96
  6. *
  7. * This module implements a recursive decent parser for the ASL language.
  8. *
  9. * MODIFICATION HISTORY
  10. */
  11. #include "pch.h"
  12. /***LP ParseASLFile - Parse the ASL source file
  13. *
  14. * ENTRY
  15. * pszFile -> file name string
  16. *
  17. * EXIT-SUCCESS
  18. * returns ASLERR_NONE
  19. * EXIT-FAILURE
  20. * returns negative error code
  21. */
  22. int LOCAL ParseASLFile(PSZ pszFile)
  23. {
  24. int rc = ASLERR_NONE;
  25. FILE *pfileSrc;
  26. PTOKEN ptoken;
  27. PSZ pszOldFile;
  28. ENTER((1, "ParseASLFile(File=%s)\n", pszFile));
  29. if ((pfileSrc = fopen(pszFile, "r")) == NULL)
  30. {
  31. ERROR(("ParseASLFile: failed to open source file - %s", pszFile));
  32. rc = ASLERR_OPEN_FILE;
  33. }
  34. else
  35. {
  36. if ((ptoken = OpenScan(pfileSrc)) == NULL)
  37. {
  38. ERROR(("ParseASLFile: failed to initialize scanner"));
  39. rc = ASLERR_INIT_SCANNER;
  40. }
  41. else
  42. {
  43. pszOldFile = gpszASLFile;
  44. gpszASLFile = pszFile;
  45. printf("%s:\n", pszFile);
  46. if ((rc = ParseASLTerms(ptoken, 0)) == TOKERR_EOF)
  47. rc = ASLERR_NONE;
  48. else if (rc == ASLERR_EXPECT_EOF)
  49. {
  50. PrintTokenErr(ptoken, "Expecting end-of-file", TRUE);
  51. }
  52. gpszASLFile = pszOldFile;
  53. CloseScan(ptoken);
  54. }
  55. fclose(pfileSrc);
  56. }
  57. EXIT((1, "ParseASLFile=%d\n", rc));
  58. return rc;
  59. } //ParseASLFile
  60. /***LP ParseASLTerms - Parse all ASL statements
  61. *
  62. * ENTRY
  63. * ptoken - token stream
  64. * iNestLevel - nesting level of current file
  65. *
  66. * EXIT-SUCCESS
  67. * returns ASLERR_NONE
  68. * EXIT-FAILURE
  69. * returns negative error code
  70. */
  71. int LOCAL ParseASLTerms(PTOKEN ptoken, int iNestLevel)
  72. {
  73. int rc = ASLERR_NONE;
  74. PCODEOBJ pcode;
  75. ENTER((1, "ParseASLTerms(ptoken=%p,Level=%d)\n", ptoken, iNestLevel));
  76. do
  77. {
  78. if ((pcode = (PCODEOBJ)MEMALLOC(sizeof(CODEOBJ))) == NULL)
  79. {
  80. ERROR(("ParseASLTerms: failed to allocate code object"));
  81. rc = ASLERR_OUT_OF_MEM;
  82. }
  83. else
  84. {
  85. memset(pcode, 0, sizeof(CODEOBJ));
  86. if (gpcodeRoot == NULL)
  87. gpcodeRoot = pcode;
  88. else if (gpcodeScope != NULL)
  89. {
  90. pcode->pcParent = gpcodeScope;
  91. ListInsertTail(&pcode->list,
  92. (PPLIST)&gpcodeScope->pcFirstChild);
  93. }
  94. gpcodeScope = pcode;
  95. rc = ParseASLTerm(ptoken, iNestLevel);
  96. gpcodeScope = pcode->pcParent;
  97. if (rc != ASLERR_NONE)
  98. {
  99. if (gpcodeRoot == pcode)
  100. gpcodeRoot = NULL;
  101. else if (gpcodeScope != NULL)
  102. {
  103. ListRemoveEntry(&pcode->list,
  104. (PPLIST)&gpcodeScope->pcFirstChild);
  105. }
  106. MEMFREE(pcode);
  107. }
  108. }
  109. } while (rc == ASLERR_NONE);
  110. EXIT((1, "ParseASLTerms=%d\n", rc));
  111. return rc;
  112. } //ParseASLTerms
  113. /***LP ValidateTermClass - Validate term class with parent
  114. *
  115. * ENTRY
  116. * dwTermClass - term class of child
  117. * pcParent -> parent
  118. *
  119. * EXIT-SUCCESS
  120. * returns TRUE
  121. * EXIT-FAILURE
  122. * returns FALSE
  123. */
  124. BOOL LOCAL ValidateTermClass(DWORD dwTermClass, PCODEOBJ pcParent)
  125. {
  126. BOOL rc = TRUE;
  127. ENTER((2, "ValidateTermClass(TermClass=%x,Parent=%p)\n",
  128. dwTermClass, pcParent));
  129. if ((dwTermClass & TC_COMPILER_DIRECTIVE) == 0)
  130. {
  131. while (pcParent != NULL)
  132. {
  133. //
  134. // Go upward to find a parent that is not "Include".
  135. //
  136. if (TermTable[pcParent->dwTermIndex].lID == ID_INCLUDE)
  137. {
  138. pcParent = pcParent->pcParent;
  139. }
  140. else
  141. {
  142. break;
  143. }
  144. }
  145. if ((pcParent != NULL) && (pcParent->dwfCode & CF_PARSING_VARLIST))
  146. {
  147. rc = (dwTermClass & TermTable[pcParent->dwTermIndex].dwfTerm) != 0;
  148. }
  149. }
  150. EXIT((2, "ValidateTermClass=%d\n", rc));
  151. return rc;
  152. } //ValidateTermClass
  153. /***LP ParseASLTerm - Parse an ASL statement
  154. *
  155. * ENTRY
  156. * ptoken - token stream
  157. * iNestLevel - nesting level of current file
  158. *
  159. * EXIT-SUCCESS
  160. * returns ASLERR_NONE
  161. * EXIT-FAILURE
  162. * returns negative error code
  163. */
  164. int LOCAL ParseASLTerm(PTOKEN ptoken, int iNestLevel)
  165. {
  166. int rc;
  167. ENTER((1, "ParseASLTerm(ptoken=%p,Level=%d)\n", ptoken, iNestLevel));
  168. if ((rc = MatchToken(ptoken, TOKTYPE_SYMBOL, SYM_RBRACE, MTF_NOT_ERR,
  169. NULL)) == TOKERR_NONE)
  170. {
  171. if (iNestLevel == 0)
  172. rc = ASLERR_EXPECT_EOF;
  173. else
  174. {
  175. //
  176. // We have no more terms in the current scope
  177. //
  178. UnGetToken(ptoken);
  179. rc = TOKERR_NO_MATCH;
  180. }
  181. }
  182. else if ((rc != TOKERR_EOF) &&
  183. ((rc = MatchToken(ptoken, TOKTYPE_ID, 0, MTF_ANY_VALUE, NULL)) ==
  184. TOKERR_NONE))
  185. {
  186. if ((gpcodeRoot == NULL) &&
  187. ((ptoken->llTokenValue < 0) ||
  188. (TermTable[ptoken->llTokenValue].lID != ID_DEFBLK)))
  189. {
  190. //
  191. // outside of definition block
  192. //
  193. rc = ASLERR_EXPECT_EOF;
  194. }
  195. else if (ptoken->llTokenValue == ID_USER) //user term
  196. {
  197. if ((rc = ParseUserTerm(ptoken, FALSE)) == TOKERR_NO_MATCH)
  198. {
  199. PrintTokenErr(ptoken, "User ID is not a method", TRUE);
  200. rc = ASLERR_SYNTAX;
  201. }
  202. }
  203. else if (ptoken->llTokenValue >= 0) //ASL term
  204. {
  205. PNSOBJ pnsScopeSave = gpnsCurrentScope;
  206. PNSOBJ pnsOwnerSave = gpnsCurrentOwner;
  207. PASLTERM pterm;
  208. int iNumArgs;
  209. pterm = &TermTable[ptoken->llTokenValue];
  210. iNumArgs = pterm->pszArgTypes? strlen(pterm->pszArgTypes): 0;
  211. gpcodeScope->dwCodeType = CODETYPE_ASLTERM;
  212. gpcodeScope->dwTermIndex = (DWORD)ptoken->llTokenValue;
  213. gpcodeScope->dwCodeValue = pterm->dwOpcode;
  214. gpcodeScope->dwDataLen = (DWORD)iNumArgs;
  215. if (!ValidateTermClass(pterm->dwfTermClass, gpcodeScope->pcParent))
  216. {
  217. PrintTokenErr(ptoken, "unexpected ASL term type", TRUE);
  218. rc = ASLERR_SYNTAX;
  219. }
  220. else if (pterm->pszArgTypes != NULL) //there is a fixed list
  221. rc = ParseArgs(ptoken, pterm, iNumArgs);
  222. if ((rc == ASLERR_NONE) && (pterm->dwfTerm & TF_ACTION_FLIST))
  223. {
  224. ASSERT(pterm->pfnTerm != NULL);
  225. rc = pterm->pfnTerm(ptoken, TRUE);
  226. }
  227. if (rc == ASLERR_NONE)
  228. {
  229. if (pterm->dwfTerm & TF_ALL_LISTS)
  230. {
  231. if ((rc = MatchToken(ptoken, TOKTYPE_SYMBOL, SYM_LBRACE, 0,
  232. NULL)) == TOKERR_NONE)
  233. {
  234. if (pterm->dwfTerm & TF_CHANGE_CHILDSCOPE)
  235. {
  236. ASSERT(gpcodeScope->pnsObj != NULL);
  237. gpnsCurrentScope = gpcodeScope->pnsObj;
  238. }
  239. if (pterm->lID == ID_METHOD)
  240. {
  241. gpnsCurrentOwner = gpcodeScope->pnsObj;
  242. }
  243. gpcodeScope->dwfCode |= CF_PARSING_VARLIST;
  244. if (pterm->dwfTerm & TF_FIELD_LIST)
  245. rc = ParseFieldList(ptoken);
  246. else if (pterm->dwfTerm & TF_PACKAGE_LIST)
  247. rc = ParsePackageList(ptoken);
  248. else if (pterm->dwfTerm & TF_DATA_LIST)
  249. rc = ParseBuffList(ptoken);
  250. else if (pterm->dwfTerm & TF_BYTE_LIST)
  251. rc = ParseDataList(ptoken, sizeof(BYTE));
  252. else if (pterm->dwfTerm & TF_DWORD_LIST)
  253. rc = ParseDataList(ptoken, sizeof(DWORD));
  254. else
  255. rc = ParseASLTerms(ptoken, iNestLevel + 1);
  256. gpcodeScope->dwfCode &= ~CF_PARSING_VARLIST;
  257. if (((rc == TOKERR_NO_MATCH) || (rc == TOKERR_EOF)) &&
  258. ((rc = MatchToken(ptoken, TOKTYPE_SYMBOL,
  259. SYM_RBRACE, 0, NULL)) ==
  260. TOKERR_NONE))
  261. {
  262. ComputeChkSumLen(gpcodeScope);
  263. if (pterm->dwfTerm & TF_ACTION_VLIST)
  264. {
  265. ASSERT(pterm->pfnTerm != NULL);
  266. rc = pterm->pfnTerm(ptoken, FALSE);
  267. }
  268. }
  269. }
  270. }
  271. else
  272. {
  273. ComputeChkSumLen(gpcodeScope);
  274. }
  275. }
  276. gpnsCurrentScope = pnsScopeSave;
  277. gpnsCurrentOwner = pnsOwnerSave;
  278. }
  279. else
  280. {
  281. PrintTokenErr(ptoken, "unexpected term type", TRUE);
  282. rc = ASLERR_SYNTAX;
  283. }
  284. }
  285. EXIT((1, "ParseASLTerm=%d\n", rc));
  286. return rc;
  287. } //ParseASLTerm
  288. /***LP ParseFieldList - Parse Field List
  289. *
  290. * ENTRY
  291. * ptoken - token stream
  292. *
  293. * EXIT-SUCCESS
  294. * returns ASLERR_NONE
  295. * EXIT-FAILURE
  296. * returns negative error code
  297. */
  298. int LOCAL ParseFieldList(PTOKEN ptoken)
  299. {
  300. int rc = ASLERR_NONE;
  301. NAMESEG NameSeg;
  302. DWORD dwcbLen;
  303. DWORD dwcBits = 0, dwcTotalBits = 0;
  304. PCODEOBJ pc;
  305. PNSOBJ pns;
  306. ENTER((1, "ParseFieldList(ptoken=%p,AccSize=%ld)\n",
  307. ptoken, gdwFieldAccSize));
  308. while ((rc == ASLERR_NONE) &&
  309. (((rc = MatchToken(ptoken, TOKTYPE_ID, 0,
  310. MTF_ANY_VALUE | MTF_NOT_ERR, NULL)) ==
  311. TOKERR_NONE) ||
  312. ((rc = MatchToken(ptoken, TOKTYPE_SYMBOL, SYM_COMMA, MTF_NOT_ERR,
  313. NULL)) == TOKERR_NONE)))
  314. {
  315. pns = NULL;
  316. if (ptoken->iTokenType == TOKTYPE_SYMBOL)
  317. {
  318. NameSeg = 0;
  319. rc = MatchToken(ptoken, TOKTYPE_NUMBER, 0, MTF_ANY_VALUE, NULL);
  320. dwcBits = (DWORD)ptoken->llTokenValue;
  321. }
  322. else if (ptoken->llTokenValue >= 0)
  323. {
  324. if (TermTable[ptoken->llTokenValue].lID == ID_OFFSET)
  325. {
  326. if (((rc = MatchToken(ptoken, TOKTYPE_SYMBOL, SYM_LPARAN, 0,
  327. NULL)) == TOKERR_NONE) &&
  328. ((rc = MatchToken(ptoken, TOKTYPE_NUMBER, 0, MTF_ANY_VALUE,
  329. NULL)) == TOKERR_NONE))
  330. {
  331. NameSeg = 0;
  332. if ((DWORD)ptoken->llTokenValue*8 >= dwcTotalBits)
  333. {
  334. dwcBits = (DWORD)ptoken->llTokenValue*8 - dwcTotalBits;
  335. rc = MatchToken(ptoken, TOKTYPE_SYMBOL, SYM_RPARAN, 0,
  336. NULL);
  337. }
  338. else
  339. {
  340. PrintTokenErr(ptoken, "backward offset is not allowed",
  341. TRUE);
  342. rc = ASLERR_SYNTAX;
  343. }
  344. }
  345. }
  346. else if (TermTable[ptoken->llTokenValue].lID == ID_ACCESSAS)
  347. {
  348. PCODEOBJ pcode;
  349. UnGetToken(ptoken);
  350. if ((pcode = (PCODEOBJ)MEMALLOC(sizeof(CODEOBJ))) == NULL)
  351. {
  352. ERROR(("ParseFieldList: failed to allocate code object"));
  353. rc = ASLERR_OUT_OF_MEM;
  354. }
  355. else
  356. {
  357. ASSERT(gpcodeScope != NULL);
  358. memset(pcode, 0, sizeof(CODEOBJ));
  359. pcode->pcParent = gpcodeScope;
  360. ListInsertTail(&pcode->list,
  361. (PPLIST)&gpcodeScope->pcFirstChild);
  362. gpcodeScope = pcode;
  363. rc = ParseASLTerm(ptoken, 0);
  364. gpcodeScope = pcode->pcParent;
  365. if (rc != ASLERR_NONE)
  366. {
  367. ListRemoveEntry(&pcode->list,
  368. (PPLIST)&gpcodeScope->pcFirstChild);
  369. MEMFREE(pcode);
  370. }
  371. else if ((rc = MatchToken(ptoken, TOKTYPE_SYMBOL, SYM_COMMA,
  372. MTF_NOT_ERR, NULL)) ==
  373. TOKERR_NONE)
  374. {
  375. continue;
  376. }
  377. }
  378. }
  379. else
  380. {
  381. PrintTokenErr(ptoken, "unexpected ASL term in field list",
  382. TRUE);
  383. rc = ASLERR_SYNTAX;
  384. }
  385. }
  386. else
  387. {
  388. //
  389. // expecting a NameSeg and an integer
  390. //
  391. dwcbLen = sizeof(NAMESEG);
  392. if ((ptoken->llTokenValue >= 0) || //an ASL term?
  393. !ValidASLNameSeg(ptoken, ptoken->szToken, strlen(ptoken->szToken)) ||
  394. ((rc = EncodeName(ptoken->szToken, (PBYTE)&NameSeg, &dwcbLen)) !=
  395. ASLERR_NONE) ||
  396. (dwcbLen != sizeof(NAMESEG)))
  397. {
  398. PrintTokenErr(ptoken, "not a valid NameSeg", TRUE);
  399. rc = ASLERR_SYNTAX;
  400. }
  401. else if ((rc = CreateNameSpaceObj(ptoken, ptoken->szToken,
  402. gpnsCurrentScope,
  403. gpnsCurrentOwner,
  404. &pns, NSF_EXIST_ERR)) ==
  405. ASLERR_NONE)
  406. {
  407. pns->ObjData.dwDataType = OBJTYPE_FIELDUNIT;
  408. if ((rc = MatchToken(ptoken, TOKTYPE_SYMBOL, SYM_COMMA, 0,
  409. NULL)) == TOKERR_NONE)
  410. {
  411. rc = MatchToken(ptoken, TOKTYPE_NUMBER, 0, MTF_ANY_VALUE, NULL);
  412. dwcBits = (DWORD)ptoken->llTokenValue;
  413. }
  414. }
  415. }
  416. if (rc == ASLERR_NONE)
  417. {
  418. if ((NameSeg == 0) && (dwcBits == 0))
  419. {
  420. rc = MatchToken(ptoken, TOKTYPE_SYMBOL, SYM_COMMA, MTF_NOT_ERR,
  421. NULL);
  422. }
  423. else if ((pc = MEMALLOC(sizeof(CODEOBJ))) == NULL)
  424. {
  425. ERROR(("ParseFieldList: failed to allocate field code object"));
  426. rc = ASLERR_OUT_OF_MEM;
  427. }
  428. else
  429. {
  430. int icb;
  431. memset(pc, 0, sizeof(CODEOBJ));
  432. if ((rc = EncodePktLen(dwcBits, &pc->dwDataLen, &icb)) ==
  433. ASLERR_NONE)
  434. {
  435. dwcTotalBits += dwcBits;
  436. if (gpcodeScope->pnsObj != NULL)
  437. {
  438. ASSERT(gpcodeScope->pnsObj->ObjData.dwDataType ==
  439. OBJTYPE_OPREGION);
  440. if ((gpcodeScope->pnsObj->ObjData.uipDataValue !=
  441. 0xffffffff) &&
  442. ((dwcTotalBits + 7)/8 >
  443. gpcodeScope->pnsObj->ObjData.uipDataValue))
  444. {
  445. char szMsg[MAX_MSG_LEN + 1];
  446. sprintf(szMsg,
  447. "field offset is exceeding operation region range (offset=0x%x)",
  448. (dwcTotalBits + 7)/8);
  449. PrintTokenErr(ptoken, szMsg, TRUE);
  450. rc = ASLERR_SYNTAX;
  451. break;
  452. }
  453. }
  454. pc->pcParent = gpcodeScope;
  455. ListInsertTail(&pc->list,
  456. (PPLIST)&gpcodeScope->pcFirstChild);
  457. pc->dwCodeType = CODETYPE_FIELDOBJ;
  458. if (pns != NULL)
  459. {
  460. pc->dwfCode |= CF_CREATED_NSOBJ;
  461. pc->pnsObj = pns;
  462. pns->Context = pc;
  463. }
  464. pc->dwCodeValue = NameSeg;
  465. pc->dwCodeLen = (NameSeg == 0)? sizeof(BYTE):
  466. sizeof(NAMESEG);
  467. pc->dwCodeLen += icb;
  468. pc->bCodeChkSum = ComputeDataChkSum((PBYTE)&NameSeg,
  469. sizeof(NAMESEG));
  470. pc->bCodeChkSum = (BYTE)
  471. (pc->bCodeChkSum +
  472. ComputeDataChkSum((PBYTE)&pc->dwDataLen, icb));
  473. rc = MatchToken(ptoken, TOKTYPE_SYMBOL, SYM_COMMA,
  474. MTF_NOT_ERR, NULL);
  475. }
  476. else
  477. {
  478. MEMFREE(pc);
  479. PrintTokenErr(ptoken, "exceeding maximum encoding limit",
  480. TRUE);
  481. }
  482. }
  483. }
  484. }
  485. EXIT((1, "ParseFieldList=%d\n", rc));
  486. return rc;
  487. } //ParseFieldList
  488. /***LP ParsePackageList - Parse Package List
  489. *
  490. * ENTRY
  491. * ptoken - token stream
  492. *
  493. * EXIT-SUCCESS
  494. * returns ASLERR_NONE
  495. * EXIT-FAILURE
  496. * returns negative error code
  497. */
  498. int LOCAL ParsePackageList(PTOKEN ptoken)
  499. {
  500. int rc;
  501. PCODEOBJ pc;
  502. int icElements = 0;
  503. PCODEOBJ pArgs;
  504. ENTER((1, "ParsePackageList(ptoken=%p)\n", ptoken));
  505. do
  506. {
  507. if ((pc = MEMALLOC(sizeof(CODEOBJ))) == NULL)
  508. {
  509. ERROR(("ParsePackageList: failed to allocate package object"));
  510. rc = ASLERR_OUT_OF_MEM;
  511. }
  512. else
  513. {
  514. memset(pc, 0, sizeof(CODEOBJ));
  515. pc->pcParent = gpcodeScope;
  516. ListInsertTail(&pc->list, (PPLIST)&gpcodeScope->pcFirstChild);
  517. gpcodeScope = pc;
  518. if ((rc = ParseData(ptoken)) == TOKERR_NO_MATCH)
  519. {
  520. UnGetToken(ptoken);
  521. rc = ParseName(ptoken, TRUE);
  522. }
  523. gpcodeScope = pc->pcParent;
  524. if (rc != ASLERR_NONE)
  525. {
  526. ListRemoveEntry(&pc->list, (PPLIST)&gpcodeScope->pcFirstChild);
  527. MEMFREE(pc);
  528. }
  529. else if ((rc = MatchToken(ptoken, TOKTYPE_SYMBOL, 0, MTF_ANY_VALUE,
  530. NULL)) == TOKERR_NONE)
  531. {
  532. icElements++;
  533. if (ptoken->llTokenValue == SYM_RBRACE)
  534. {
  535. UnGetToken(ptoken);
  536. rc = TOKERR_NO_MATCH;
  537. }
  538. else if (ptoken->llTokenValue != SYM_COMMA)
  539. {
  540. PrintTokenErr(ptoken, "expecting ',' or '}'", TRUE);
  541. rc = ASLERR_SYNTAX;
  542. }
  543. }
  544. }
  545. } while (rc == ASLERR_NONE);
  546. if (rc == TOKERR_NO_MATCH)
  547. {
  548. pArgs = (PCODEOBJ)gpcodeScope->pbDataBuff;
  549. if (pArgs[0].dwfCode & CF_MISSING_ARG)
  550. {
  551. pArgs[0].dwfCode &= ~CF_MISSING_ARG;
  552. SetIntObject(&pArgs[0], (DWORD)icElements, sizeof(BYTE));
  553. }
  554. else if (pArgs[0].dwCodeValue < (DWORD)icElements)
  555. {
  556. PrintTokenErr(ptoken, "Package has too many elements", TRUE);
  557. rc = ASLERR_SYNTAX;
  558. }
  559. }
  560. EXIT((1, "ParsePackageList=%d\n", rc));
  561. return rc;
  562. } //ParsePackageList
  563. /***LP ParseBuffList - Parse Buffer List
  564. *
  565. * ENTRY
  566. * ptoken - token stream
  567. *
  568. * EXIT-SUCCESS
  569. * returns ASLERR_NONE
  570. * EXIT-FAILURE
  571. * returns negative error code
  572. */
  573. int LOCAL ParseBuffList(PTOKEN ptoken)
  574. {
  575. int rc = ASLERR_NONE;
  576. PCODEOBJ pc;
  577. ENTER((1, "ParseBuffList(ptoken=%p)\n", ptoken));
  578. if ((pc = (PCODEOBJ)MEMALLOC(sizeof(CODEOBJ))) == NULL)
  579. {
  580. ERROR(("ParseBuffList: failed to allocate buffer code object"))
  581. rc = ASLERR_OUT_OF_MEM;
  582. }
  583. else
  584. {
  585. #define MAX_TEMP_BUFF 256
  586. PCODEOBJ pArgs;
  587. DWORD dwReservedLen;
  588. PBYTE pbBuff;
  589. DWORD dwBuffSize = MAX_TEMP_BUFF;
  590. memset(pc, 0, sizeof(CODEOBJ));
  591. pc->pcParent = gpcodeScope;
  592. ListInsertTail(&pc->list, (PPLIST)&gpcodeScope->pcFirstChild);
  593. pArgs = (PCODEOBJ)gpcodeScope->pbDataBuff;
  594. pc->dwCodeType = CODETYPE_DATAOBJ;
  595. if ((rc = MatchToken(ptoken, TOKTYPE_STRING, 0,
  596. MTF_ANY_VALUE | MTF_NOT_ERR, NULL)) == TOKERR_NONE)
  597. {
  598. pc->dwDataLen = strlen(ptoken->szToken) + 1;
  599. if (!(pArgs[0].dwfCode & CF_MISSING_ARG) &&
  600. (pArgs[0].dwCodeType == CODETYPE_DATAOBJ) &&
  601. ((rc = GetIntData(&pArgs[0], &dwReservedLen)) == ASLERR_NONE) &&
  602. (pc->dwDataLen > dwReservedLen))
  603. {
  604. PrintTokenErr(ptoken, "Buffer has too many initializers", TRUE);
  605. rc = ASLERR_SYNTAX;
  606. }
  607. else
  608. {
  609. if ((pc->pbDataBuff = MEMALLOC((size_t)pc->dwDataLen)) == NULL)
  610. {
  611. ERROR(("ParseBuffList: failed to allocate string object - %s",
  612. ptoken->szToken));
  613. rc = ASLERR_OUT_OF_MEM;
  614. }
  615. else
  616. {
  617. memset(pc->pbDataBuff, 0, pc->dwDataLen);
  618. memcpy(pc->pbDataBuff, ptoken->szToken, pc->dwDataLen);
  619. pc->dwCodeLen = pc->dwDataLen;
  620. pc->bCodeChkSum =
  621. ComputeDataChkSum(pc->pbDataBuff, pc->dwDataLen);
  622. }
  623. }
  624. }
  625. else if ((pbBuff = MEMALLOC(dwBuffSize)) == NULL)
  626. {
  627. ERROR(("ParseBuffList: failed to allocate temp. buffer"))
  628. rc = ASLERR_OUT_OF_MEM;
  629. }
  630. else
  631. {
  632. DWORD dwLen = 0;
  633. while ((rc = MatchToken(ptoken, TOKTYPE_NUMBER, 0,
  634. MTF_ANY_VALUE | MTF_NOT_ERR, NULL)) ==
  635. TOKERR_NONE)
  636. {
  637. if (ptoken->llTokenValue > MAX_BYTE)
  638. {
  639. PrintTokenErr(ptoken, "expecting byte value", TRUE);
  640. rc = ASLERR_SYNTAX;
  641. break;
  642. }
  643. else if (dwLen >= MAX_PACKAGE_LEN)
  644. {
  645. PrintTokenErr(ptoken, "data exceeding Buffer limit", TRUE);
  646. rc = ASLERR_SYNTAX;
  647. break;
  648. }
  649. else
  650. {
  651. if (dwLen >= dwBuffSize)
  652. {
  653. PBYTE pb;
  654. dwBuffSize += MAX_TEMP_BUFF;
  655. if ((pb = MEMALLOC(dwBuffSize)) == NULL)
  656. {
  657. ERROR(("ParseBuffList: failed to resize temp. buffer (size=%ld)",
  658. dwBuffSize))
  659. rc = ASLERR_OUT_OF_MEM;
  660. break;
  661. }
  662. else
  663. {
  664. memcpy(pb, pbBuff, dwLen);
  665. MEMFREE(pbBuff);
  666. pbBuff = pb;
  667. }
  668. }
  669. pbBuff[dwLen++] = (BYTE)ptoken->llTokenValue;
  670. if ((rc = MatchToken(ptoken, TOKTYPE_SYMBOL, 0,
  671. MTF_ANY_VALUE, NULL)) == TOKERR_NONE)
  672. {
  673. if (ptoken->llTokenValue == SYM_RBRACE)
  674. {
  675. UnGetToken(ptoken);
  676. break;
  677. }
  678. else if (ptoken->llTokenValue != SYM_COMMA)
  679. {
  680. PrintTokenErr(ptoken, "expecting ',' or '}'", TRUE);
  681. rc = ASLERR_SYNTAX;
  682. break;
  683. }
  684. }
  685. else
  686. break;
  687. }
  688. }
  689. if (rc == TOKERR_NO_MATCH)
  690. rc = ASLERR_NONE;
  691. if (rc == ASLERR_NONE)
  692. {
  693. pc->dwDataLen = dwLen;
  694. if (!(pArgs[0].dwfCode & CF_MISSING_ARG) &&
  695. (pArgs[0].dwCodeType == CODETYPE_DATAOBJ) &&
  696. ((rc = GetIntData(&pArgs[0], &dwReservedLen)) ==
  697. ASLERR_NONE) &&
  698. (pc->dwDataLen > dwReservedLen))
  699. {
  700. PrintTokenErr(ptoken, "Buffer has too many initializers",
  701. TRUE);
  702. rc = ASLERR_SYNTAX;
  703. }
  704. else
  705. {
  706. if ((pc->pbDataBuff = MEMALLOC((size_t)pc->dwDataLen)) ==
  707. NULL)
  708. {
  709. ERROR(("ParseBuffList: failed to allocate data object"));
  710. rc = ASLERR_OUT_OF_MEM;
  711. }
  712. else
  713. {
  714. memset(pc->pbDataBuff, 0, pc->dwDataLen);
  715. memcpy(pc->pbDataBuff, pbBuff, pc->dwDataLen);
  716. pc->dwCodeLen = pc->dwDataLen;
  717. pc->bCodeChkSum =
  718. ComputeDataChkSum(pc->pbDataBuff, pc->dwDataLen);
  719. }
  720. }
  721. }
  722. MEMFREE(pbBuff);
  723. }
  724. if ((rc == ASLERR_NONE) && (pArgs[0].dwfCode & CF_MISSING_ARG))
  725. {
  726. pArgs[0].dwfCode &= ~CF_MISSING_ARG;
  727. rc = MakeIntData(pc->dwDataLen, &pArgs[0]);
  728. }
  729. if (rc == ASLERR_NONE)
  730. rc = TOKERR_NO_MATCH;
  731. }
  732. EXIT((1, "ParseBuffList=%d\n", rc));
  733. return rc;
  734. } //ParseBuffList
  735. /***LP ParseDataList - Parse Data List
  736. *
  737. * ENTRY
  738. * ptoken - token stream
  739. * icbDataSize - data size in bytes
  740. *
  741. * EXIT-SUCCESS
  742. * returns ASLERR_NONE
  743. * EXIT-FAILURE
  744. * returns negative error code
  745. */
  746. int LOCAL ParseDataList(PTOKEN ptoken, int icbDataSize)
  747. {
  748. int rc = ASLERR_NONE;
  749. PCODEOBJ pc;
  750. ENTER((1, "ParseDataList(ptoken=%p,DataSize=%d)\n", ptoken, icbDataSize));
  751. if ((pc = (PCODEOBJ)MEMALLOC(sizeof(CODEOBJ))) == NULL)
  752. {
  753. ERROR(("ParseDataList: failed to allocate buffer code object"))
  754. rc = ASLERR_OUT_OF_MEM;
  755. }
  756. else
  757. {
  758. #define MAX_TEMP_BUFF 256
  759. PBYTE pbBuff;
  760. DWORD dwBuffSize = MAX_TEMP_BUFF*icbDataSize;
  761. memset(pc, 0, sizeof(CODEOBJ));
  762. pc->pcParent = gpcodeScope;
  763. ListInsertTail(&pc->list, (PPLIST)&gpcodeScope->pcFirstChild);
  764. pc->dwCodeType = CODETYPE_DATAOBJ;
  765. if ((pbBuff = MEMALLOC(dwBuffSize)) == NULL)
  766. {
  767. ERROR(("ParseDataList: failed to allocate temp. buffer"))
  768. rc = ASLERR_OUT_OF_MEM;
  769. }
  770. else
  771. {
  772. DWORD dwLen = 0;
  773. while ((rc = MatchToken(ptoken, TOKTYPE_NUMBER, 0,
  774. MTF_ANY_VALUE | MTF_NOT_ERR, NULL)) ==
  775. TOKERR_NONE)
  776. {
  777. switch (icbDataSize)
  778. {
  779. case sizeof(BYTE):
  780. if (ptoken->llTokenValue > MAX_BYTE)
  781. {
  782. PrintTokenErr(ptoken, "expecting byte value", TRUE);
  783. rc = ASLERR_SYNTAX;
  784. }
  785. break;
  786. case sizeof(WORD):
  787. if (ptoken->llTokenValue > MAX_WORD)
  788. {
  789. PrintTokenErr(ptoken, "expecting word value", TRUE);
  790. rc = ASLERR_SYNTAX;
  791. }
  792. break;
  793. case sizeof(DWORD):
  794. if (ptoken->llTokenValue > MAX_DWORD)
  795. {
  796. PrintTokenErr(ptoken, "expecting dword value", TRUE);
  797. rc = ASLERR_SYNTAX;
  798. }
  799. break;
  800. default:
  801. ERROR(("ParseDataList: unexpected data size - %d",
  802. icbDataSize));
  803. rc = ASLERR_INTERNAL_ERROR;
  804. }
  805. if (rc != ASLERR_NONE)
  806. break;
  807. if (dwLen + icbDataSize > MAX_PACKAGE_LEN)
  808. {
  809. PrintTokenErr(ptoken, "data exceeding Buffer limit", TRUE);
  810. rc = ASLERR_SYNTAX;
  811. break;
  812. }
  813. else
  814. {
  815. if (dwLen + icbDataSize > dwBuffSize)
  816. {
  817. PBYTE pb;
  818. dwBuffSize += MAX_TEMP_BUFF*icbDataSize;
  819. if ((pb = MEMALLOC(dwBuffSize)) == NULL)
  820. {
  821. ERROR(("ParseDataList: failed to resize temp. buffer (size=%ld)",
  822. dwBuffSize))
  823. rc = ASLERR_OUT_OF_MEM;
  824. break;
  825. }
  826. else
  827. {
  828. memcpy(pb, pbBuff, dwLen);
  829. MEMFREE(pbBuff);
  830. pbBuff = pb;
  831. }
  832. }
  833. switch (icbDataSize)
  834. {
  835. case sizeof(BYTE):
  836. pbBuff[dwLen] = (BYTE)ptoken->llTokenValue;
  837. break;
  838. case sizeof(WORD):
  839. *((PWORD)&pbBuff[dwLen]) = (WORD)
  840. ptoken->llTokenValue;
  841. break;
  842. case sizeof(DWORD):
  843. *((PDWORD)&pbBuff[dwLen]) = (DWORD)
  844. ptoken->llTokenValue;
  845. break;
  846. }
  847. dwLen += icbDataSize;
  848. if ((rc = MatchToken(ptoken, TOKTYPE_SYMBOL, 0,
  849. MTF_ANY_VALUE, NULL)) == TOKERR_NONE)
  850. {
  851. if (ptoken->llTokenValue == SYM_RBRACE)
  852. {
  853. UnGetToken(ptoken);
  854. break;
  855. }
  856. else if (ptoken->llTokenValue != SYM_COMMA)
  857. {
  858. PrintTokenErr(ptoken, "expecting ',' or '}'", TRUE);
  859. rc = ASLERR_SYNTAX;
  860. break;
  861. }
  862. }
  863. else
  864. break;
  865. }
  866. }
  867. if (rc == TOKERR_NO_MATCH)
  868. rc = ASLERR_NONE;
  869. if (rc == ASLERR_NONE)
  870. {
  871. pc->dwDataLen = dwLen;
  872. if ((pc->pbDataBuff = MEMALLOC(pc->dwDataLen)) == NULL)
  873. {
  874. ERROR(("ParseDataList: failed to allocate data object"));
  875. rc = ASLERR_OUT_OF_MEM;
  876. }
  877. else
  878. {
  879. memcpy(pc->pbDataBuff, pbBuff, pc->dwDataLen);
  880. pc->dwCodeLen = pc->dwDataLen;
  881. pc->bCodeChkSum =
  882. ComputeDataChkSum(pc->pbDataBuff, pc->dwDataLen);
  883. }
  884. }
  885. MEMFREE(pbBuff);
  886. }
  887. if (rc == ASLERR_NONE)
  888. rc = TOKERR_NO_MATCH;
  889. }
  890. EXIT((1, "ParseDataList=%d\n", rc));
  891. return rc;
  892. } //ParseDataList
  893. /***LP ParseArgs - Parse ASL term arguments
  894. *
  895. * ENTRY
  896. * ptoken - token stream
  897. * pterm -> asl term
  898. * iNumArgs - number of arguments
  899. *
  900. * EXIT-SUCCESS
  901. * returns ASLERR_NONE
  902. * EXIT-FAILURE
  903. * returns negative error code
  904. */
  905. int LOCAL ParseArgs(PTOKEN ptoken, PASLTERM pterm, int iNumArgs)
  906. {
  907. int rc = ASLERR_NONE;
  908. ENTER((1, "ParseArgs(ptoken=%p,pterm=%p,NumArgs=%d)\n",
  909. ptoken, pterm, iNumArgs));
  910. if ((rc = MatchToken(ptoken, TOKTYPE_SYMBOL, SYM_LPARAN, 0, NULL)) ==
  911. TOKERR_NONE)
  912. {
  913. PCODEOBJ pArgs = NULL;
  914. if ((iNumArgs != 0) &&
  915. ((pArgs = MEMALLOC(sizeof(CODEOBJ)*iNumArgs)) == NULL))
  916. {
  917. ERROR(("ParseArgs: failed to allocate argument objects"))
  918. rc = ASLERR_OUT_OF_MEM;
  919. }
  920. else
  921. {
  922. int i;
  923. char chArgType;
  924. char szNameBuff[MAX_NSPATH_LEN + 1];
  925. BOOL fOptional;
  926. PSZ pszArgType = "Unknown";
  927. gpcodeScope->dwfCode |= CF_PARSING_FIXEDLIST;
  928. if (pArgs != NULL)
  929. {
  930. gpcodeScope->pbDataBuff = (PBYTE)pArgs;
  931. memset(pArgs, 0, sizeof(CODEOBJ)*iNumArgs);
  932. }
  933. for (i = 0; (rc == ASLERR_NONE) && (i < iNumArgs); ++i)
  934. {
  935. chArgType = pterm->pszArgTypes[i];
  936. if (islower(chArgType))
  937. {
  938. chArgType = (char)_toupper(chArgType);
  939. fOptional = TRUE;
  940. }
  941. else
  942. fOptional = FALSE;
  943. pArgs[i].pcParent = gpcodeScope;
  944. gpcodeScope = &pArgs[i];
  945. switch (chArgType)
  946. {
  947. case 'N':
  948. case 'R':
  949. rc = ParseName(ptoken, (chArgType == 'N')? TRUE: FALSE);
  950. pszArgType = "Name";
  951. break;
  952. case 'S':
  953. if (((rc = ParseSuperName(ptoken)) ==
  954. TOKERR_NO_MATCH) && fOptional)
  955. {
  956. pArgs[i].dwCodeType = CODETYPE_ASLTERM;
  957. pArgs[i].dwCodeValue = OP_ZERO;
  958. pArgs[i].dwCodeLen = 0;
  959. pArgs[i].bCodeChkSum = OP_ZERO;
  960. rc = LookupIDIndex(ID_ZERO,
  961. &pArgs[i].dwTermIndex);
  962. }
  963. pszArgType = "SuperName";
  964. break;
  965. case 'O':
  966. rc = ParseData(ptoken);
  967. pszArgType = "DataObject";
  968. break;
  969. case 'B':
  970. case 'W':
  971. case 'D':
  972. case 'U':
  973. case 'Q':
  974. rc = ParseInteger(ptoken, chArgType);
  975. if (chArgType == 'B')
  976. pszArgType = "ByteInteger";
  977. else if (chArgType == 'W')
  978. pszArgType = "WordInteger";
  979. else if (chArgType == 'D')
  980. pszArgType = "DWordInteger";
  981. else if (chArgType == 'Q')
  982. pszArgType = "QWordInteger";
  983. else
  984. pszArgType = "Integer";
  985. break;
  986. case 'C':
  987. case 'M':
  988. case 'P':
  989. rc = ParseOpcode(ptoken, chArgType);
  990. pszArgType = "Opcode";
  991. break;
  992. case 'E':
  993. case 'K':
  994. rc = ParseKeyword(ptoken, pterm->pszArgActions[i]);
  995. pszArgType = "Keyword";
  996. if ((chArgType == 'E') && (rc == TOKERR_NO_MATCH))
  997. {
  998. if ((rc = ParseInteger(ptoken, 'B')) == ASLERR_NONE)
  999. {
  1000. if ((pterm->pszArgActions[i] != 'Y') &&
  1001. //
  1002. // AccessAttribKeyword ( pszArgActions type 'Y' ) may be replaced
  1003. // by any integer value.
  1004. // Size checking is performed in AccessAs function.
  1005. //
  1006. ((gpcodeScope->dwCodeValue <
  1007. (pterm->dwTermData >> 24)) ||
  1008. (gpcodeScope->dwCodeValue >
  1009. ((pterm->dwTermData >> 16) & 0xff))))
  1010. {
  1011. PrintTokenErr(ptoken,
  1012. "invalid integer range",
  1013. TRUE);
  1014. rc = ASLERR_SYNTAX;
  1015. }
  1016. }
  1017. }
  1018. break;
  1019. case 'Z':
  1020. rc = ParseString(ptoken);
  1021. pszArgType = "String";
  1022. break;
  1023. }
  1024. gpcodeScope = pArgs[i].pcParent;
  1025. if (rc == TOKERR_NO_MATCH)
  1026. {
  1027. if (fOptional)
  1028. {
  1029. pArgs[i].dwfCode |= CF_MISSING_ARG;
  1030. rc = ASLERR_NONE;
  1031. }
  1032. else
  1033. {
  1034. char szMsg[MAX_MSG_LEN + 1];
  1035. sprintf(szMsg, "expecting argument type \"%s\"",
  1036. pszArgType);
  1037. PrintTokenErr(ptoken, szMsg, TRUE);
  1038. rc = ASLERR_SYNTAX;
  1039. }
  1040. }
  1041. if ((rc == ASLERR_NONE) && (pterm->pszArgActions != NULL) &&
  1042. ((chArgType == 'N') || (chArgType == 'S') ||
  1043. (chArgType == 'C') || (chArgType == 'M') ||
  1044. (chArgType == 'P')) &&
  1045. (pArgs[i].dwCodeType == CODETYPE_NAME) &&
  1046. ((rc = DecodeName(pArgs[i].pbDataBuff, szNameBuff,
  1047. sizeof(szNameBuff))) == ASLERR_NONE))
  1048. {
  1049. char chActType = pterm->pszArgActions[i];
  1050. if (islower(chActType))
  1051. {
  1052. rc = CreateObject(ptoken, szNameBuff,
  1053. (char)_toupper(chActType), NULL);
  1054. }
  1055. else
  1056. {
  1057. rc = ValidateObject(ptoken, szNameBuff, chActType,
  1058. chArgType);
  1059. }
  1060. }
  1061. if (rc == ASLERR_NONE)
  1062. { //
  1063. // expecting either a comma or a close paran.
  1064. //
  1065. if ((rc = MatchToken(ptoken, TOKTYPE_SYMBOL, 0,
  1066. MTF_ANY_VALUE, NULL)) == TOKERR_NONE)
  1067. {
  1068. if (ptoken->llTokenValue == SYM_RPARAN)
  1069. {
  1070. UnGetToken(ptoken);
  1071. }
  1072. else if (ptoken->llTokenValue != SYM_COMMA)
  1073. {
  1074. PrintTokenErr(ptoken, "expecting ',' or ')'", TRUE);
  1075. rc = ASLERR_SYNTAX;
  1076. }
  1077. else if (i == iNumArgs - 1) //last argument
  1078. {
  1079. PrintTokenErr(ptoken, "expecting ')'", TRUE);
  1080. rc = ASLERR_SYNTAX;
  1081. }
  1082. }
  1083. }
  1084. }
  1085. gpcodeScope->dwfCode &= ~CF_PARSING_FIXEDLIST;
  1086. if (rc == ASLERR_NONE)
  1087. rc = MatchToken(ptoken, TOKTYPE_SYMBOL, SYM_RPARAN, 0, NULL);
  1088. }
  1089. }
  1090. EXIT((1, "ParseArgs=%d\n", rc));
  1091. return rc;
  1092. } //ParseArgs
  1093. /***LP ParseUserTerm - Parse user method name
  1094. *
  1095. * ENTRY
  1096. * ptoken - token stream
  1097. * fNonMethodOK - if TRUE, user term can be a non-method
  1098. *
  1099. * EXIT-SUCCESS
  1100. * returns TOKERR_NONE
  1101. * EXIT-FAILURE
  1102. * returns negative error code
  1103. */
  1104. int LOCAL ParseUserTerm(PTOKEN ptoken, BOOL fNonMethodOK)
  1105. {
  1106. int rc;
  1107. ENTER((1, "ParseUserTerm(ptoken=%p,fNonMethodOK=%d)\n",
  1108. ptoken, fNonMethodOK));
  1109. //
  1110. // Max number of argument is 7 but we need to store the user term name too,
  1111. // we will store it in Arg0, so we will make it 8.
  1112. //
  1113. if ((gpcodeScope->pbDataBuff = MEMALLOC(sizeof(CODEOBJ)*(MAX_ARGS + 1))) ==
  1114. NULL)
  1115. {
  1116. ERROR(("ParseUserTerm: failed to allocate user term object"));
  1117. rc = ASLERR_OUT_OF_MEM;
  1118. }
  1119. else
  1120. {
  1121. PCODEOBJ pArgs = (PCODEOBJ)gpcodeScope->pbDataBuff;
  1122. int i;
  1123. gpcodeScope->dwCodeType = CODETYPE_USERTERM;
  1124. gpcodeScope->dwDataLen = MAX_ARGS + 1;
  1125. memset(pArgs, 0, sizeof(CODEOBJ)*gpcodeScope->dwDataLen);
  1126. pArgs[0].pcParent = gpcodeScope;
  1127. gpcodeScope = &pArgs[0];
  1128. UnGetToken(ptoken);
  1129. if ((rc = ParseName(ptoken, TRUE)) == TOKERR_NONE)
  1130. {
  1131. PNSOBJ pns;
  1132. char szName[MAX_NSPATH_LEN + 1];
  1133. strcpy(szName, ptoken->szToken);
  1134. GetNameSpaceObj(szName, gpnsCurrentScope, &pns, 0);
  1135. gpcodeScope = pArgs[0].pcParent;
  1136. if ((rc = MatchToken(ptoken, TOKTYPE_SYMBOL, SYM_LPARAN,
  1137. fNonMethodOK? MTF_NOT_ERR: 0, NULL)) ==
  1138. TOKERR_NONE)
  1139. {
  1140. for (i = 1;
  1141. (rc == TOKERR_NONE) && (i < (int)gpcodeScope->dwDataLen);
  1142. ++i)
  1143. {
  1144. pArgs[i].pcParent = gpcodeScope;
  1145. gpcodeScope = &pArgs[i];
  1146. if ((rc = ParseOpcode(ptoken, 'C')) == TOKERR_NONE)
  1147. {
  1148. if ((rc = MatchToken(ptoken, TOKTYPE_SYMBOL, 0,
  1149. MTF_ANY_VALUE, NULL)) ==
  1150. TOKERR_NONE)
  1151. {
  1152. if (ptoken->llTokenValue == SYM_RPARAN)
  1153. {
  1154. UnGetToken(ptoken);
  1155. gpcodeScope = pArgs[i].pcParent;
  1156. //
  1157. // Readjust the number of arguments
  1158. //
  1159. gpcodeScope->dwDataLen = i + 1;
  1160. break;
  1161. }
  1162. else if (ptoken->llTokenValue != SYM_COMMA)
  1163. {
  1164. PrintTokenErr(ptoken, "expecting ',' or ')'",
  1165. TRUE);
  1166. rc = ASLERR_SYNTAX;
  1167. }
  1168. }
  1169. }
  1170. else if (rc == TOKERR_NO_MATCH)
  1171. {
  1172. gpcodeScope = pArgs[i].pcParent;
  1173. //
  1174. // Readjust the number of arguments
  1175. //
  1176. gpcodeScope->dwDataLen = i;
  1177. rc = TOKERR_NONE;
  1178. break;
  1179. }
  1180. gpcodeScope = pArgs[i].pcParent;
  1181. }
  1182. if (rc == TOKERR_NONE)
  1183. {
  1184. ComputeArgsChkSumLen(gpcodeScope);
  1185. if ((rc = MatchToken(ptoken, TOKTYPE_SYMBOL, SYM_RPARAN, 0,
  1186. NULL)) == ASLERR_NONE)
  1187. {
  1188. char szMsg[MAX_MSG_LEN + 1];
  1189. if (pns == NULL)
  1190. {
  1191. rc = QueueNSChk(ptoken, szName, OBJTYPE_METHOD,
  1192. gpcodeScope->dwDataLen - 1);
  1193. }
  1194. else if (pns->ObjData.dwDataType != OBJTYPE_METHOD)
  1195. {
  1196. sprintf(szMsg, "%s is not a method", szName);
  1197. PrintTokenErr(ptoken, szMsg, TRUE);
  1198. rc = ASLERR_SYNTAX;
  1199. }
  1200. else if (pns->ObjData.uipDataValue <
  1201. gpcodeScope->dwDataLen - 1)
  1202. {
  1203. sprintf(szMsg, "%s has too many arguments", szName);
  1204. PrintTokenErr(ptoken, szMsg, TRUE);
  1205. rc = ASLERR_SYNTAX;
  1206. }
  1207. else if (pns->ObjData.uipDataValue >
  1208. gpcodeScope->dwDataLen - 1)
  1209. {
  1210. sprintf(szMsg, "%s has too few arguments", szName);
  1211. PrintTokenErr(ptoken, szMsg, TRUE);
  1212. rc = ASLERR_SYNTAX;
  1213. }
  1214. }
  1215. }
  1216. }
  1217. else if (rc == TOKERR_NO_MATCH)
  1218. {
  1219. gpcodeScope->dwCodeType = pArgs[0].dwCodeType;
  1220. gpcodeScope->dwDataLen = pArgs[0].dwDataLen;
  1221. gpcodeScope->pbDataBuff = pArgs[0].pbDataBuff;
  1222. gpcodeScope->dwCodeLen = pArgs[0].dwCodeLen;
  1223. gpcodeScope->bCodeChkSum = pArgs[0].bCodeChkSum;
  1224. MEMFREE(pArgs);
  1225. if (pns == NULL)
  1226. {
  1227. rc = QueueNSChk(ptoken, szName, OBJTYPE_UNKNOWN, 0);
  1228. }
  1229. else
  1230. {
  1231. rc = TOKERR_NONE;
  1232. }
  1233. }
  1234. }
  1235. }
  1236. EXIT((1, "ParseUserTerm=%d\n", rc));
  1237. return rc;
  1238. } //ParseUserTerm
  1239. /***LP ParseName - Parse ASL name
  1240. *
  1241. * ENTRY
  1242. * ptoken - token stream
  1243. * fEncode - TRUE if encode name else store it raw as string
  1244. *
  1245. * EXIT-SUCCESS
  1246. * returns TOKERR_NONE
  1247. * EXIT-FAILURE
  1248. * returns negative error code
  1249. */
  1250. int LOCAL ParseName(PTOKEN ptoken, BOOL fEncode)
  1251. {
  1252. int rc;
  1253. BYTE abBuff[MAX_NAMECODE_LEN];
  1254. DWORD dwLen = sizeof(abBuff);
  1255. ENTER((1, "ParseName(ptoken=%p,fEncode=%x)\n", ptoken, fEncode));
  1256. if ((rc = MatchToken(ptoken, TOKTYPE_ID, ID_USER, MTF_NOT_ERR, NULL)) ==
  1257. TOKERR_NONE)
  1258. {
  1259. if (!ValidASLName(ptoken, ptoken->szToken))
  1260. {
  1261. PrintTokenErr(ptoken, "expecting ASL name", TRUE);
  1262. rc = ASLERR_SYNTAX;
  1263. }
  1264. else if (fEncode)
  1265. {
  1266. if ((rc = EncodeName(ptoken->szToken, abBuff, &dwLen)) ==
  1267. ASLERR_NONE)
  1268. {
  1269. if ((gpcodeScope->pbDataBuff = MEMALLOC((size_t)dwLen)) == NULL)
  1270. {
  1271. ERROR(("ParseName: failed to allocate name string object - %s",
  1272. ptoken->szToken));
  1273. rc = ASLERR_OUT_OF_MEM;
  1274. }
  1275. else
  1276. {
  1277. memcpy(gpcodeScope->pbDataBuff, abBuff, (int)dwLen);
  1278. gpcodeScope->dwCodeType = CODETYPE_NAME;
  1279. gpcodeScope->dwDataLen = dwLen;
  1280. gpcodeScope->dwCodeLen = dwLen;
  1281. gpcodeScope->bCodeChkSum =
  1282. ComputeDataChkSum(gpcodeScope->pbDataBuff, dwLen);
  1283. }
  1284. }
  1285. else
  1286. {
  1287. PrintTokenErr(ptoken, "name too long", TRUE);
  1288. }
  1289. }
  1290. else
  1291. {
  1292. gpcodeScope->dwDataLen = strlen(ptoken->szToken) + 1;
  1293. if ((gpcodeScope->pbDataBuff = MEMALLOC(gpcodeScope->dwDataLen)) !=
  1294. NULL)
  1295. {
  1296. memcpy(gpcodeScope->pbDataBuff, ptoken->szToken,
  1297. gpcodeScope->dwDataLen);
  1298. gpcodeScope->dwCodeType = CODETYPE_STRING;
  1299. gpcodeScope->dwCodeLen = gpcodeScope->dwDataLen;
  1300. gpcodeScope->bCodeChkSum =
  1301. ComputeDataChkSum(gpcodeScope->pbDataBuff,
  1302. gpcodeScope->dwDataLen);
  1303. }
  1304. else
  1305. {
  1306. ERROR(("ParseName: failed to allocate raw name string object - %s",
  1307. ptoken->szToken));
  1308. rc = ASLERR_OUT_OF_MEM;
  1309. }
  1310. }
  1311. }
  1312. EXIT((1, "ParseName=%d (Name=%s)\n", rc, ptoken->szToken));
  1313. return rc;
  1314. } //ParseName
  1315. /***LP ParseSuperName - Parse ASL super name
  1316. *
  1317. * ENTRY
  1318. * ptoken - token stream
  1319. *
  1320. * EXIT-SUCCESS
  1321. * returns TOKERR_NONE
  1322. * EXIT-FAILURE
  1323. * returns negative error code
  1324. */
  1325. int LOCAL ParseSuperName(PTOKEN ptoken)
  1326. {
  1327. int rc;
  1328. ENTER((1, "ParseSuperName(ptoken=%p)\n", ptoken));
  1329. if ((rc = MatchToken(ptoken, TOKTYPE_ID, 0, MTF_ANY_VALUE | MTF_NOT_ERR,
  1330. NULL)) == TOKERR_NONE)
  1331. {
  1332. if (ptoken->llTokenValue == ID_USER)
  1333. {
  1334. UnGetToken(ptoken);
  1335. rc = ParseName(ptoken, TRUE);
  1336. }
  1337. else
  1338. {
  1339. if (TermTable[ptoken->llTokenValue].dwfTermClass &
  1340. TC_SHORT_NAME)
  1341. {
  1342. gpcodeScope->dwCodeType = CODETYPE_ASLTERM;
  1343. gpcodeScope->dwTermIndex = (DWORD)ptoken->llTokenValue;
  1344. gpcodeScope->dwCodeValue =
  1345. TermTable[ptoken->llTokenValue].dwOpcode;
  1346. }
  1347. else if (TermTable[ptoken->llTokenValue].dwfTermClass &
  1348. TC_REF_OBJECT)
  1349. {
  1350. UnGetToken(ptoken);
  1351. rc = ParseASLTerm(ptoken, 0);
  1352. }
  1353. else
  1354. {
  1355. UnGetToken(ptoken);
  1356. rc = TOKERR_NO_MATCH;
  1357. }
  1358. }
  1359. }
  1360. EXIT((1, "ParseSuperName=%d\n", rc));
  1361. return rc;
  1362. } //ParseSuperName
  1363. /***LP MakeIntData - make integer data object
  1364. *
  1365. * ENTRY
  1366. * dwData - integer data
  1367. * pc -> code object
  1368. *
  1369. * EXIT-SUCCESS
  1370. * returns ASLERR_NONE
  1371. * EXIT-FAILURE
  1372. * returns negative error code
  1373. */
  1374. int LOCAL MakeIntData(DWORD dwData, PCODEOBJ pc)
  1375. {
  1376. int rc = ASLERR_NONE;
  1377. DWORD dwLen;
  1378. BYTE bOp;
  1379. ENTER((1, "MakeIntData(Data=%lx,pc=%p)\n", dwData, pc));
  1380. pc->dwCodeType = CODETYPE_DATAOBJ;
  1381. if ((dwData & 0xffffff00) == 0)
  1382. {
  1383. bOp = OP_BYTE;
  1384. dwLen = 2;
  1385. }
  1386. else if ((dwData & 0xffff0000) == 0)
  1387. {
  1388. bOp = OP_WORD;
  1389. dwLen = 3;
  1390. }
  1391. else
  1392. {
  1393. bOp = OP_DWORD;
  1394. dwLen = 5;
  1395. }
  1396. if ((pc->pbDataBuff = MEMALLOC((size_t)dwLen)) == NULL)
  1397. {
  1398. ERROR(("MakeIntData: failed to allocate data object - %lx", dwData));
  1399. rc = ASLERR_OUT_OF_MEM;
  1400. }
  1401. else
  1402. {
  1403. pc->dwDataLen = dwLen;
  1404. pc->dwCodeLen = dwLen;
  1405. pc->pbDataBuff[0] = bOp;
  1406. memcpy(&pc->pbDataBuff[1], &dwData, (int)(dwLen - 1));
  1407. pc->bCodeChkSum = ComputeDataChkSum(pc->pbDataBuff, dwLen);
  1408. }
  1409. EXIT((1, "MakeIntData=%d\n", rc));
  1410. return rc;
  1411. } //MakeIntData
  1412. /***LP GetIntData - get integer from a data object
  1413. *
  1414. * ENTRY
  1415. * pc -> code object
  1416. * pdwData -> to hold integer data
  1417. *
  1418. * EXIT-SUCCESS
  1419. * returns ASLERR_NONE
  1420. * EXIT-FAILURE
  1421. * returns negative error code
  1422. */
  1423. int LOCAL GetIntData(PCODEOBJ pc, PDWORD pdwData)
  1424. {
  1425. int rc = ASLERR_NONE;
  1426. ENTER((1, "GetIntData(pc=%p,pdwData=%p)\n", pc, pdwData));
  1427. ASSERT(pc->dwCodeType == CODETYPE_DATAOBJ);
  1428. switch (pc->pbDataBuff[0])
  1429. {
  1430. case OP_BYTE:
  1431. *pdwData = (DWORD)(*((PBYTE)&pc->pbDataBuff[1]));
  1432. break;
  1433. case OP_WORD:
  1434. *pdwData = (DWORD)(*((PWORD)&pc->pbDataBuff[1]));
  1435. break;
  1436. case OP_DWORD:
  1437. *pdwData = *((PDWORD)&pc->pbDataBuff[1]);
  1438. break;
  1439. default:
  1440. ERROR(("GetIntData: data object is not integer type"));
  1441. rc = ASLERR_INVALID_OBJTYPE;
  1442. }
  1443. EXIT((1, "GetIntData=%d (Data=%lx)\n", rc, *pdwData));
  1444. return rc;
  1445. } //GetIntData
  1446. /***LP ParseData - Parse ASL data object
  1447. *
  1448. * ENTRY
  1449. * ptoken - token stream
  1450. *
  1451. * EXIT-SUCCESS
  1452. * returns TOKERR_NONE
  1453. * EXIT-FAILURE
  1454. * returns negative error code
  1455. */
  1456. int LOCAL ParseData(PTOKEN ptoken)
  1457. {
  1458. int rc;
  1459. ENTER((1, "ParseData(ptoken=%p)\n", ptoken));
  1460. if ((rc = GetToken(ptoken)) == TOKERR_NONE)
  1461. {
  1462. if (ptoken->iTokenType == TOKTYPE_NUMBER)
  1463. {
  1464. if (ptoken->llTokenValue <= MAX_DWORD)
  1465. {
  1466. rc = MakeIntData((DWORD)ptoken->llTokenValue, gpcodeScope);
  1467. }
  1468. else
  1469. {
  1470. PrintTokenErr(ptoken, "data value exceeding DWORD maximum",
  1471. TRUE);
  1472. rc = ASLERR_SYNTAX;
  1473. }
  1474. }
  1475. else if (ptoken->iTokenType == TOKTYPE_STRING)
  1476. {
  1477. DWORD dwLen;
  1478. gpcodeScope->dwCodeType = CODETYPE_DATAOBJ;
  1479. dwLen = strlen(ptoken->szToken) + 2;
  1480. if ((gpcodeScope->pbDataBuff = MEMALLOC((size_t)dwLen)) == NULL)
  1481. {
  1482. ERROR(("ParseData: failed to allocate string object - %s",
  1483. ptoken->szToken));
  1484. rc = ASLERR_OUT_OF_MEM;
  1485. }
  1486. else
  1487. {
  1488. gpcodeScope->dwDataLen = dwLen;
  1489. gpcodeScope->dwCodeLen = dwLen;
  1490. gpcodeScope->pbDataBuff[0] = OP_STRING;
  1491. memcpy(&gpcodeScope->pbDataBuff[1], ptoken->szToken,
  1492. (int)(dwLen - 1));
  1493. gpcodeScope->bCodeChkSum =
  1494. ComputeDataChkSum(gpcodeScope->pbDataBuff, dwLen);
  1495. }
  1496. }
  1497. else if ((ptoken->iTokenType != TOKTYPE_ID) ||
  1498. (ptoken->llTokenValue < 0) ||
  1499. ((TermTable[ptoken->llTokenValue].dwfTermClass &
  1500. (TC_DATA_OBJECT | TC_CONST_NAME)) == 0))
  1501. {
  1502. UnGetToken(ptoken);
  1503. rc = TOKERR_NO_MATCH;
  1504. }
  1505. else
  1506. {
  1507. UnGetToken(ptoken);
  1508. rc = ParseASLTerm(ptoken, 0);
  1509. }
  1510. }
  1511. EXIT((1, "ParseData=%d\n", rc));
  1512. return rc;
  1513. } //ParseData
  1514. /***LP ParseInteger - Parse integer data
  1515. *
  1516. * ENTRY
  1517. * ptoken - token stream
  1518. * c - integer type
  1519. *
  1520. * EXIT-SUCCESS
  1521. * returns TOKERR_NONE
  1522. * EXIT-FAILURE
  1523. * returns negative error code
  1524. */
  1525. int LOCAL ParseInteger(PTOKEN ptoken, char c)
  1526. {
  1527. int rc;
  1528. ENTER((1, "ParseInteger(ptoken=%p,ch=%c)\n", ptoken, c));
  1529. if ((rc = MatchToken(ptoken, TOKTYPE_NUMBER, 0, MTF_ANY_VALUE | MTF_NOT_ERR,
  1530. NULL)) == TOKERR_NONE)
  1531. {
  1532. gpcodeScope->dwCodeValue = 0;
  1533. if ((c == 'B') && ((ptoken->llTokenValue & 0xffffffffffffff00) != 0) ||
  1534. (c == 'W') && ((ptoken->llTokenValue & 0xffffffffffff0000) != 0) ||
  1535. (c == 'D') && ((ptoken->llTokenValue & 0xffffffff00000000) != 0))
  1536. {
  1537. char szMsg[MAX_MSG_LEN + 1];
  1538. sprintf(szMsg, "expecting %s value",
  1539. (c == 'B')? "byte":
  1540. (c == 'W')? "word": "dword");
  1541. PrintTokenErr(ptoken, szMsg, TRUE);
  1542. rc = ASLERR_SYNTAX;
  1543. }
  1544. else if (c == 'U')
  1545. {
  1546. if (ptoken->llTokenValue <= MAX_DWORD)
  1547. {
  1548. rc = MakeIntData((DWORD)ptoken->llTokenValue, gpcodeScope);
  1549. }
  1550. else
  1551. {
  1552. PrintTokenErr(ptoken, "data value exceeding DWORD maximum",
  1553. TRUE);
  1554. rc = ASLERR_SYNTAX;
  1555. }
  1556. }
  1557. else if (c != 'Q')
  1558. {
  1559. gpcodeScope->dwCodeType = CODETYPE_INTEGER;
  1560. gpcodeScope->dwDataLen = (c == 'B')? sizeof(BYTE):
  1561. (c == 'W')? sizeof(WORD):
  1562. (c == 'D')? sizeof(DWORD):
  1563. ((ptoken->llTokenValue &
  1564. 0xffffffffffffff00) == 0)? sizeof(BYTE):
  1565. ((ptoken->llTokenValue &
  1566. 0xffffffffffff0000) == 0)? sizeof(WORD):
  1567. sizeof(DWORD);
  1568. gpcodeScope->dwCodeLen = gpcodeScope->dwDataLen;
  1569. gpcodeScope->dwCodeValue = (DWORD)ptoken->llTokenValue;
  1570. gpcodeScope->bCodeChkSum =
  1571. ComputeDataChkSum((PBYTE)&ptoken->llTokenValue,
  1572. gpcodeScope->dwDataLen);
  1573. }
  1574. else if ((gpcodeScope->pbDataBuff =
  1575. MEMALLOC(gpcodeScope->dwDataLen = sizeof(QWORD))) != NULL)
  1576. {
  1577. gpcodeScope->dwCodeType = CODETYPE_QWORD;
  1578. memcpy(gpcodeScope->pbDataBuff, &ptoken->llTokenValue,
  1579. gpcodeScope->dwDataLen);
  1580. gpcodeScope->dwCodeLen = gpcodeScope->dwDataLen;
  1581. gpcodeScope->bCodeChkSum =
  1582. ComputeDataChkSum(gpcodeScope->pbDataBuff,
  1583. gpcodeScope->dwDataLen);
  1584. }
  1585. else
  1586. {
  1587. ERROR(("ParseInteger: failed to allocate QWord object - %s",
  1588. ptoken->szToken));
  1589. rc = ASLERR_OUT_OF_MEM;
  1590. }
  1591. }
  1592. EXIT((1, "ParseInteger=%d\n", rc));
  1593. return rc;
  1594. } //ParseInteger
  1595. /***LP ParseOpcode - Parse ASL opcode: MachineCode, FunctionCode, SuperName
  1596. *
  1597. * ENTRY
  1598. * ptoken - token stream
  1599. * c - opcode type
  1600. *
  1601. * EXIT-SUCCESS
  1602. * returns TOKERR_NONE
  1603. * EXIT-FAILURE
  1604. * returns negative error code
  1605. */
  1606. int LOCAL ParseOpcode(PTOKEN ptoken, char c)
  1607. {
  1608. int rc;
  1609. ENTER((1, "ParseOpcode(ptoken=%p,ch=%c)\n", ptoken, c));
  1610. if ((rc = MatchToken(ptoken, TOKTYPE_ID, 0, MTF_ANY_VALUE | MTF_NOT_ERR,
  1611. NULL)) == TOKERR_NONE)
  1612. {
  1613. if (ptoken->llTokenValue == ID_USER)
  1614. {
  1615. PNSOBJ pns;
  1616. if ((GetNameSpaceObj(ptoken->szToken, gpnsCurrentScope, &pns, 0) ==
  1617. ASLERR_NONE) &&
  1618. (pns->ObjData.dwDataType == OBJTYPE_RES_FIELD) &&
  1619. ((c == 'M') || (c == 'P')))
  1620. {
  1621. DWORD dwValue = 0;
  1622. if (c == 'P')
  1623. {
  1624. dwValue = pns->ObjData.uipDataValue;
  1625. }
  1626. else if (pns->ObjData.uipDataValue%8 == 0)
  1627. {
  1628. dwValue = pns->ObjData.uipDataValue/8;
  1629. }
  1630. else
  1631. {
  1632. PrintTokenErr(ptoken,
  1633. "object can only be used in CreateField "
  1634. "or CreateBitField statements",
  1635. TRUE);
  1636. rc = ASLERR_SYNTAX;
  1637. }
  1638. if (rc == ASLERR_NONE)
  1639. {
  1640. rc = MakeIntData(dwValue, gpcodeScope);
  1641. }
  1642. }
  1643. else
  1644. {
  1645. rc = ParseUserTerm(ptoken, TRUE);
  1646. }
  1647. }
  1648. else
  1649. {
  1650. UnGetToken(ptoken);
  1651. if (TermTable[ptoken->llTokenValue].dwfTermClass & TC_OPCODE)
  1652. {
  1653. rc = ParseASLTerm(ptoken, 0);
  1654. }
  1655. else
  1656. {
  1657. rc = TOKERR_NO_MATCH;
  1658. }
  1659. }
  1660. }
  1661. else
  1662. rc = ParseData(ptoken);
  1663. EXIT((1, "ParseOpcode=%d\n", rc));
  1664. return rc;
  1665. } //ParseOpcode
  1666. /***LP ParseKeyword - Parse ASL keyword
  1667. *
  1668. * ENTRY
  1669. * ptoken - token stream
  1670. * chExpectType - expected keyword type
  1671. *
  1672. * EXIT-SUCCESS
  1673. * returns TOKERR_NONE
  1674. * EXIT-FAILURE
  1675. * returns negative error code
  1676. *
  1677. * NOTE
  1678. * DATATYPE_KEYWORD is a transient type. It will be lumped together with
  1679. * other keyword type arguments and be converted into one DATATYPE_INTEGER.
  1680. */
  1681. int LOCAL ParseKeyword(PTOKEN ptoken, char chExpectType)
  1682. {
  1683. int rc;
  1684. ENTER((1, "ParseKeyword(ptoken=%p,ExpectedType=%c)\n",
  1685. ptoken, chExpectType));
  1686. if ((rc = MatchToken(ptoken, TOKTYPE_ID, 0, MTF_ANY_VALUE | MTF_NOT_ERR,
  1687. NULL)) == TOKERR_NONE)
  1688. {
  1689. if ((ptoken->llTokenValue == ID_USER) ||
  1690. !(TermTable[ptoken->llTokenValue].dwfTermClass & TC_KEYWORD))
  1691. {
  1692. UnGetToken(ptoken);
  1693. rc = TOKERR_NO_MATCH;
  1694. }
  1695. else if (TermTable[ptoken->llTokenValue].pszArgActions[0] !=
  1696. chExpectType)
  1697. {
  1698. PrintTokenErr(ptoken, "incorrect keyword type", TRUE);
  1699. rc = ASLERR_SYNTAX;
  1700. }
  1701. else
  1702. {
  1703. gpcodeScope->dwCodeType = CODETYPE_KEYWORD;
  1704. gpcodeScope->dwTermIndex = (DWORD)ptoken->llTokenValue;
  1705. gpcodeScope->dwCodeValue = TOKID(ptoken->llTokenValue);
  1706. }
  1707. }
  1708. EXIT((1, "ParseKeyword=%d\n", rc));
  1709. return rc;
  1710. } //ParseKeyword
  1711. /***LP ParseString - Parse string object
  1712. *
  1713. * ENTRY
  1714. * ptoken - token stream
  1715. *
  1716. * EXIT-SUCCESS
  1717. * returns TOKERR_NONE
  1718. * EXIT-FAILURE
  1719. * returns negative error code
  1720. */
  1721. int LOCAL ParseString(PTOKEN ptoken)
  1722. {
  1723. int rc;
  1724. ENTER((1, "ParseString(ptoken=%p)\n", ptoken));
  1725. if ((rc = MatchToken(ptoken, TOKTYPE_STRING, 0, MTF_ANY_VALUE | MTF_NOT_ERR,
  1726. NULL)) == TOKERR_NONE)
  1727. {
  1728. gpcodeScope->dwDataLen = strlen(ptoken->szToken) + 1;
  1729. if (gpcodeScope->dwDataLen > MAX_STRING_LEN + 1)
  1730. {
  1731. ERROR(("ParseString: string too big - %s", ptoken->szToken));
  1732. rc = ASLERR_SYNTAX;
  1733. }
  1734. else if ((gpcodeScope->pbDataBuff =
  1735. MEMALLOC((size_t)gpcodeScope->dwDataLen)) == NULL)
  1736. {
  1737. ERROR(("ParseString: failed to allocate string object - %s",
  1738. ptoken->szToken));
  1739. rc = ASLERR_OUT_OF_MEM;
  1740. }
  1741. else
  1742. {
  1743. gpcodeScope->dwCodeType = CODETYPE_STRING;
  1744. memcpy(gpcodeScope->pbDataBuff, ptoken->szToken,
  1745. (int)gpcodeScope->dwDataLen);
  1746. gpcodeScope->dwCodeLen = gpcodeScope->dwDataLen;
  1747. gpcodeScope->bCodeChkSum =
  1748. ComputeDataChkSum(gpcodeScope->pbDataBuff,
  1749. gpcodeScope->dwDataLen);
  1750. }
  1751. }
  1752. EXIT((1, "ParseString=%d\n", rc));
  1753. return rc;
  1754. } //ParseString
  1755. /***LP ValidateObject - Validate the existence and type of the object
  1756. *
  1757. * ENTRY
  1758. * ptoken -> TOKEN
  1759. * pszName -> object name
  1760. * chActType - action type
  1761. * chArgType - argument type
  1762. *
  1763. * EXIT-SUCCESS
  1764. * returns ASLERR_NONE
  1765. * EXIT-FAILURE
  1766. * returns negative error code
  1767. */
  1768. int LOCAL ValidateObject(PTOKEN ptoken, PSZ pszName, char chActType,
  1769. char chArgType)
  1770. {
  1771. int rc = ASLERR_NONE;
  1772. ULONG dwDataType = OBJTYPE_UNKNOWN;
  1773. ENTER((2, "ValidateObject(ptoken=%p,Name=%s,ActType=%c,ArgType=%c)\n",
  1774. ptoken, pszName, chActType, chArgType));
  1775. switch (chActType)
  1776. {
  1777. case NSTYPE_UNKNOWN:
  1778. case NSTYPE_SCOPE:
  1779. break;
  1780. case NSTYPE_FIELDUNIT:
  1781. dwDataType = OBJTYPE_FIELDUNIT;
  1782. break;
  1783. case NSTYPE_DEVICE:
  1784. dwDataType = OBJTYPE_DEVICE;
  1785. break;
  1786. case NSTYPE_EVENT:
  1787. dwDataType = OBJTYPE_EVENT;
  1788. break;
  1789. case NSTYPE_METHOD:
  1790. dwDataType = OBJTYPE_METHOD;
  1791. break;
  1792. case NSTYPE_MUTEX:
  1793. dwDataType = OBJTYPE_MUTEX;
  1794. break;
  1795. case NSTYPE_OPREGION:
  1796. dwDataType = OBJTYPE_OPREGION;
  1797. break;
  1798. case NSTYPE_POWERRES:
  1799. dwDataType = OBJTYPE_POWERRES;
  1800. break;
  1801. case NSTYPE_PROCESSOR:
  1802. dwDataType = OBJTYPE_PROCESSOR;
  1803. break;
  1804. case NSTYPE_THERMALZONE:
  1805. dwDataType = OBJTYPE_THERMALZONE;
  1806. break;
  1807. case NSTYPE_OBJALIAS:
  1808. dwDataType = OBJTYPE_OBJALIAS;
  1809. break;
  1810. case NSTYPE_BUFFFIELD:
  1811. dwDataType = OBJTYPE_BUFFFIELD;
  1812. break;
  1813. default:
  1814. ERROR(("ValidateObject: invalid object type %c", chActType));
  1815. rc = ASLERR_INVALID_OBJTYPE;
  1816. }
  1817. if ((rc == ASLERR_NONE) && (strcmp(pszName, "\\_OSI") != 0))
  1818. {
  1819. PNSOBJ pns;
  1820. char szMsg[MAX_MSG_LEN + 1];
  1821. if (((rc = GetNameSpaceObj(pszName, gpnsCurrentScope, &pns, 0)) ==
  1822. ASLERR_NONE) &&
  1823. ((pns->hOwner == NULL) ||
  1824. ((PNSOBJ)pns->hOwner == gpnsCurrentOwner)))
  1825. {
  1826. if ((pns->ObjData.dwDataType == OBJTYPE_RES_FIELD) &&
  1827. (chArgType != 'M') && (chArgType != 'P'))
  1828. {
  1829. PrintTokenErr(ptoken,
  1830. "object can only be used in the index argument "
  1831. "of CreateXField or Index statements",
  1832. TRUE);
  1833. rc = ASLERR_SYNTAX;
  1834. }
  1835. else if ((dwDataType != OBJTYPE_UNKNOWN) &&
  1836. (pns->ObjData.dwDataType != dwDataType))
  1837. {
  1838. sprintf(szMsg,
  1839. "%s has an incorrect type (ObjType=%s, ExpectedType=%s)",
  1840. pszName, GetObjectTypeName(pns->ObjData.dwDataType),
  1841. GetObjectTypeName(dwDataType));
  1842. PrintTokenErr(ptoken, szMsg, TRUE);
  1843. rc = ASLERR_SYNTAX;
  1844. }
  1845. else if ((chActType == NSTYPE_SCOPE) ||
  1846. (chActType == NSTYPE_OPREGION))
  1847. {
  1848. ASSERT(gpcodeScope->pnsObj == NULL);
  1849. gpcodeScope->pnsObj = pns;
  1850. }
  1851. }
  1852. else if ((rc == ASLERR_NSOBJ_NOT_FOUND) && (gpnsCurrentOwner != NULL))
  1853. {
  1854. //
  1855. // We are in a method referring to something not yet defined.
  1856. // Let's queue it and check it after we are done.
  1857. //
  1858. rc = QueueNSChk(ptoken, pszName, dwDataType, 0);
  1859. }
  1860. else
  1861. {
  1862. sprintf(szMsg, "%s does not exist or not in accessible scope",
  1863. pszName);
  1864. PrintTokenErr(ptoken, szMsg, FALSE);
  1865. rc = ASLERR_NONE;
  1866. }
  1867. }
  1868. EXIT((2, "ValidateObject=%d\n", rc));
  1869. return rc;
  1870. } //ValidateObject
  1871. /***LP ValidateNSChkList - Validate objects in NSCHK list
  1872. *
  1873. * ENTRY
  1874. * pnschkHead -> NSCHK list
  1875. *
  1876. * EXIT-SUCCESS
  1877. * returns ASLERR_NONE
  1878. * EXIT-FAILURE
  1879. * returns negative error code
  1880. */
  1881. int LOCAL ValidateNSChkList(PNSCHK pnschkHead)
  1882. {
  1883. int rc = ASLERR_NONE;
  1884. PNSOBJ pns;
  1885. ENTER((2, "ValidateNSChkList(Head=%p)\n", pnschkHead));
  1886. while ((rc == ASLERR_NONE) && (pnschkHead != NULL))
  1887. {
  1888. if ((GetNameSpaceObj(pnschkHead->szObjName, pnschkHead->pnsScope, &pns,
  1889. 0) == ASLERR_NONE) &&
  1890. ((pns->hOwner == NULL) ||
  1891. ((PNSOBJ)pns->hOwner == pnschkHead->pnsMethod)))
  1892. {
  1893. if (pns->ObjData.dwDataType == OBJTYPE_RES_FIELD)
  1894. {
  1895. ErrPrintf("%s(%d): error: cannot make forward reference to PNP resource object %s\n",
  1896. pnschkHead->pszFile, pnschkHead->wLineNum,
  1897. pnschkHead->szObjName);
  1898. rc = ASLERR_SYNTAX;
  1899. }
  1900. else if ((pnschkHead->dwExpectedType != OBJTYPE_UNKNOWN) &&
  1901. (pns->ObjData.dwDataType != pnschkHead->dwExpectedType))
  1902. {
  1903. ErrPrintf("%s(%d): warning: %s has incorrect type (ObjType=%s, ExpectedType=%s)\n",
  1904. pnschkHead->pszFile,
  1905. pnschkHead->wLineNum,
  1906. pnschkHead->szObjName,
  1907. GetObjectTypeName(pns->ObjData.dwDataType),
  1908. GetObjectTypeName(pnschkHead->dwExpectedType));
  1909. }
  1910. else if (pnschkHead->dwExpectedType == OBJTYPE_METHOD)
  1911. {
  1912. if (pns->ObjData.uipDataValue < pnschkHead->dwChkData)
  1913. {
  1914. ErrPrintf("%s(%d): error: %s has too many arguments\n",
  1915. pnschkHead->pszFile,
  1916. pnschkHead->wLineNum,
  1917. pnschkHead->szObjName);
  1918. rc = ASLERR_SYNTAX;
  1919. }
  1920. else if (pns->ObjData.uipDataValue > pnschkHead->dwChkData)
  1921. {
  1922. ErrPrintf("%s(%d): error: %s has too few arguments\n",
  1923. pnschkHead->pszFile,
  1924. pnschkHead->wLineNum,
  1925. pnschkHead->szObjName);
  1926. rc = ASLERR_SYNTAX;
  1927. }
  1928. }
  1929. }
  1930. else
  1931. {
  1932. if(strcmp(pnschkHead->szObjName, "\\_OSI") != 0)
  1933. {
  1934. ErrPrintf("%s(%d): warning: %s does not exist or not in accessible scope\n",
  1935. pnschkHead->pszFile,
  1936. pnschkHead->wLineNum,
  1937. pnschkHead->szObjName);
  1938. }
  1939. }
  1940. pnschkHead = pnschkHead->pnschkNext;
  1941. }
  1942. EXIT((2, "ValidateNSChkList=%d\n", rc));
  1943. return rc;
  1944. } //ValidateNSChkList
  1945. /***LP QueueNSChk - Queue a NSChk request
  1946. *
  1947. * ENTRY
  1948. * ptoken -> TOKEN
  1949. * pszObjName -> object name
  1950. * dwExpectedType - expected object type
  1951. * dwChkData - object specific check data
  1952. *
  1953. * EXIT-SUCCESS
  1954. * returns ASLERR_NONE
  1955. * EXIT-FAILURE
  1956. * returns negative error code
  1957. */
  1958. int LOCAL QueueNSChk(PTOKEN ptoken, PSZ pszObjName, ULONG dwExpectedType,
  1959. ULONG dwChkData)
  1960. {
  1961. int rc = ASLERR_NONE;
  1962. PNSCHK pnschk;
  1963. ENTER((2, "QueueNSChk(ptoken=%p,Obj=%s,ExpectedType=%s,ChkData=%x)\n",
  1964. ptoken, pszObjName, GetObjectTypeName(dwExpectedType), dwChkData));
  1965. if ((pnschk = MEMALLOC(sizeof(NSCHK))) == NULL)
  1966. {
  1967. ERROR(("QueueNSChk: failed to allocate NSCHK object"));
  1968. rc = ASLERR_OUT_OF_MEM;
  1969. }
  1970. else
  1971. {
  1972. memset(pnschk, 0, sizeof(NSCHK));
  1973. strcpy(pnschk->szObjName, pszObjName);
  1974. pnschk->pszFile = gpszASLFile;
  1975. pnschk->pnsScope = gpnsCurrentScope;
  1976. pnschk->pnsMethod = gpnsCurrentOwner;
  1977. pnschk->dwExpectedType = dwExpectedType;
  1978. pnschk->dwChkData = dwChkData;
  1979. pnschk->wLineNum = ptoken->pline->wLineNum;
  1980. if (gpnschkTail != NULL)
  1981. {
  1982. gpnschkTail->pnschkNext = pnschk;
  1983. gpnschkTail = pnschk;
  1984. }
  1985. else
  1986. {
  1987. gpnschkHead = gpnschkTail = pnschk;
  1988. }
  1989. }
  1990. EXIT((2, "QueueNSChk=%d\n"));
  1991. return rc;
  1992. } //QueueNSChk