exoparg1.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125
  1. /******************************************************************************
  2. *
  3. * Module Name: exoparg1 - AML execution - opcodes with 1 argument
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2015, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include "acpi.h"
  43. #include "accommon.h"
  44. #include "acparser.h"
  45. #include "acdispat.h"
  46. #include "acinterp.h"
  47. #include "amlcode.h"
  48. #include "acnamesp.h"
  49. #define _COMPONENT ACPI_EXECUTER
  50. ACPI_MODULE_NAME ("exoparg1")
  51. /*!
  52. * Naming convention for AML interpreter execution routines.
  53. *
  54. * The routines that begin execution of AML opcodes are named with a common
  55. * convention based upon the number of arguments, the number of target operands,
  56. * and whether or not a value is returned:
  57. *
  58. * AcpiExOpcode_xA_yT_zR
  59. *
  60. * Where:
  61. *
  62. * xA - ARGUMENTS: The number of arguments (input operands) that are
  63. * required for this opcode type (0 through 6 args).
  64. * yT - TARGETS: The number of targets (output operands) that are required
  65. * for this opcode type (0, 1, or 2 targets).
  66. * zR - RETURN VALUE: Indicates whether this opcode type returns a value
  67. * as the function return (0 or 1).
  68. *
  69. * The AcpiExOpcode* functions are called via the Dispatcher component with
  70. * fully resolved operands.
  71. !*/
  72. /*******************************************************************************
  73. *
  74. * FUNCTION: AcpiExOpcode_0A_0T_1R
  75. *
  76. * PARAMETERS: WalkState - Current state (contains AML opcode)
  77. *
  78. * RETURN: Status
  79. *
  80. * DESCRIPTION: Execute operator with no operands, one return value
  81. *
  82. ******************************************************************************/
  83. ACPI_STATUS
  84. AcpiExOpcode_0A_0T_1R (
  85. ACPI_WALK_STATE *WalkState)
  86. {
  87. ACPI_STATUS Status = AE_OK;
  88. ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
  89. ACPI_FUNCTION_TRACE_STR (ExOpcode_0A_0T_1R,
  90. AcpiPsGetOpcodeName (WalkState->Opcode));
  91. /* Examine the AML opcode */
  92. switch (WalkState->Opcode)
  93. {
  94. case AML_TIMER_OP: /* Timer () */
  95. /* Create a return object of type Integer */
  96. ReturnDesc = AcpiUtCreateIntegerObject (AcpiOsGetTimer ());
  97. if (!ReturnDesc)
  98. {
  99. Status = AE_NO_MEMORY;
  100. goto Cleanup;
  101. }
  102. break;
  103. default: /* Unknown opcode */
  104. ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
  105. WalkState->Opcode));
  106. Status = AE_AML_BAD_OPCODE;
  107. break;
  108. }
  109. Cleanup:
  110. /* Delete return object on error */
  111. if ((ACPI_FAILURE (Status)) || WalkState->ResultObj)
  112. {
  113. AcpiUtRemoveReference (ReturnDesc);
  114. WalkState->ResultObj = NULL;
  115. }
  116. else
  117. {
  118. /* Save the return value */
  119. WalkState->ResultObj = ReturnDesc;
  120. }
  121. return_ACPI_STATUS (Status);
  122. }
  123. /*******************************************************************************
  124. *
  125. * FUNCTION: AcpiExOpcode_1A_0T_0R
  126. *
  127. * PARAMETERS: WalkState - Current state (contains AML opcode)
  128. *
  129. * RETURN: Status
  130. *
  131. * DESCRIPTION: Execute Type 1 monadic operator with numeric operand on
  132. * object stack
  133. *
  134. ******************************************************************************/
  135. ACPI_STATUS
  136. AcpiExOpcode_1A_0T_0R (
  137. ACPI_WALK_STATE *WalkState)
  138. {
  139. ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
  140. ACPI_STATUS Status = AE_OK;
  141. ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_0T_0R,
  142. AcpiPsGetOpcodeName (WalkState->Opcode));
  143. /* Examine the AML opcode */
  144. switch (WalkState->Opcode)
  145. {
  146. case AML_RELEASE_OP: /* Release (MutexObject) */
  147. Status = AcpiExReleaseMutex (Operand[0], WalkState);
  148. break;
  149. case AML_RESET_OP: /* Reset (EventObject) */
  150. Status = AcpiExSystemResetEvent (Operand[0]);
  151. break;
  152. case AML_SIGNAL_OP: /* Signal (EventObject) */
  153. Status = AcpiExSystemSignalEvent (Operand[0]);
  154. break;
  155. case AML_SLEEP_OP: /* Sleep (MsecTime) */
  156. Status = AcpiExSystemDoSleep (Operand[0]->Integer.Value);
  157. break;
  158. case AML_STALL_OP: /* Stall (UsecTime) */
  159. Status = AcpiExSystemDoStall ((UINT32) Operand[0]->Integer.Value);
  160. break;
  161. case AML_UNLOAD_OP: /* Unload (Handle) */
  162. Status = AcpiExUnloadTable (Operand[0]);
  163. break;
  164. default: /* Unknown opcode */
  165. ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
  166. WalkState->Opcode));
  167. Status = AE_AML_BAD_OPCODE;
  168. break;
  169. }
  170. return_ACPI_STATUS (Status);
  171. }
  172. /*******************************************************************************
  173. *
  174. * FUNCTION: AcpiExOpcode_1A_1T_0R
  175. *
  176. * PARAMETERS: WalkState - Current state (contains AML opcode)
  177. *
  178. * RETURN: Status
  179. *
  180. * DESCRIPTION: Execute opcode with one argument, one target, and no
  181. * return value.
  182. *
  183. ******************************************************************************/
  184. ACPI_STATUS
  185. AcpiExOpcode_1A_1T_0R (
  186. ACPI_WALK_STATE *WalkState)
  187. {
  188. ACPI_STATUS Status = AE_OK;
  189. ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
  190. ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_1T_0R,
  191. AcpiPsGetOpcodeName (WalkState->Opcode));
  192. /* Examine the AML opcode */
  193. switch (WalkState->Opcode)
  194. {
  195. case AML_LOAD_OP:
  196. Status = AcpiExLoadOp (Operand[0], Operand[1], WalkState);
  197. break;
  198. default: /* Unknown opcode */
  199. ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
  200. WalkState->Opcode));
  201. Status = AE_AML_BAD_OPCODE;
  202. goto Cleanup;
  203. }
  204. Cleanup:
  205. return_ACPI_STATUS (Status);
  206. }
  207. /*******************************************************************************
  208. *
  209. * FUNCTION: AcpiExOpcode_1A_1T_1R
  210. *
  211. * PARAMETERS: WalkState - Current state (contains AML opcode)
  212. *
  213. * RETURN: Status
  214. *
  215. * DESCRIPTION: Execute opcode with one argument, one target, and a
  216. * return value.
  217. *
  218. ******************************************************************************/
  219. ACPI_STATUS
  220. AcpiExOpcode_1A_1T_1R (
  221. ACPI_WALK_STATE *WalkState)
  222. {
  223. ACPI_STATUS Status = AE_OK;
  224. ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
  225. ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
  226. ACPI_OPERAND_OBJECT *ReturnDesc2 = NULL;
  227. UINT32 Temp32;
  228. UINT32 i;
  229. UINT64 PowerOfTen;
  230. UINT64 Digit;
  231. ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_1T_1R,
  232. AcpiPsGetOpcodeName (WalkState->Opcode));
  233. /* Examine the AML opcode */
  234. switch (WalkState->Opcode)
  235. {
  236. case AML_BIT_NOT_OP:
  237. case AML_FIND_SET_LEFT_BIT_OP:
  238. case AML_FIND_SET_RIGHT_BIT_OP:
  239. case AML_FROM_BCD_OP:
  240. case AML_TO_BCD_OP:
  241. case AML_COND_REF_OF_OP:
  242. /* Create a return object of type Integer for these opcodes */
  243. ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
  244. if (!ReturnDesc)
  245. {
  246. Status = AE_NO_MEMORY;
  247. goto Cleanup;
  248. }
  249. switch (WalkState->Opcode)
  250. {
  251. case AML_BIT_NOT_OP: /* Not (Operand, Result) */
  252. ReturnDesc->Integer.Value = ~Operand[0]->Integer.Value;
  253. break;
  254. case AML_FIND_SET_LEFT_BIT_OP: /* FindSetLeftBit (Operand, Result) */
  255. ReturnDesc->Integer.Value = Operand[0]->Integer.Value;
  256. /*
  257. * Acpi specification describes Integer type as a little
  258. * endian unsigned value, so this boundary condition is valid.
  259. */
  260. for (Temp32 = 0; ReturnDesc->Integer.Value &&
  261. Temp32 < ACPI_INTEGER_BIT_SIZE; ++Temp32)
  262. {
  263. ReturnDesc->Integer.Value >>= 1;
  264. }
  265. ReturnDesc->Integer.Value = Temp32;
  266. break;
  267. case AML_FIND_SET_RIGHT_BIT_OP: /* FindSetRightBit (Operand, Result) */
  268. ReturnDesc->Integer.Value = Operand[0]->Integer.Value;
  269. /*
  270. * The Acpi specification describes Integer type as a little
  271. * endian unsigned value, so this boundary condition is valid.
  272. */
  273. for (Temp32 = 0; ReturnDesc->Integer.Value &&
  274. Temp32 < ACPI_INTEGER_BIT_SIZE; ++Temp32)
  275. {
  276. ReturnDesc->Integer.Value <<= 1;
  277. }
  278. /* Since the bit position is one-based, subtract from 33 (65) */
  279. ReturnDesc->Integer.Value =
  280. Temp32 == 0 ? 0 : (ACPI_INTEGER_BIT_SIZE + 1) - Temp32;
  281. break;
  282. case AML_FROM_BCD_OP: /* FromBcd (BCDValue, Result) */
  283. /*
  284. * The 64-bit ACPI integer can hold 16 4-bit BCD characters
  285. * (if table is 32-bit, integer can hold 8 BCD characters)
  286. * Convert each 4-bit BCD value
  287. */
  288. PowerOfTen = 1;
  289. ReturnDesc->Integer.Value = 0;
  290. Digit = Operand[0]->Integer.Value;
  291. /* Convert each BCD digit (each is one nybble wide) */
  292. for (i = 0; (i < AcpiGbl_IntegerNybbleWidth) && (Digit > 0); i++)
  293. {
  294. /* Get the least significant 4-bit BCD digit */
  295. Temp32 = ((UINT32) Digit) & 0xF;
  296. /* Check the range of the digit */
  297. if (Temp32 > 9)
  298. {
  299. ACPI_ERROR ((AE_INFO,
  300. "BCD digit too large (not decimal): 0x%X",
  301. Temp32));
  302. Status = AE_AML_NUMERIC_OVERFLOW;
  303. goto Cleanup;
  304. }
  305. /* Sum the digit into the result with the current power of 10 */
  306. ReturnDesc->Integer.Value +=
  307. (((UINT64) Temp32) * PowerOfTen);
  308. /* Shift to next BCD digit */
  309. Digit >>= 4;
  310. /* Next power of 10 */
  311. PowerOfTen *= 10;
  312. }
  313. break;
  314. case AML_TO_BCD_OP: /* ToBcd (Operand, Result) */
  315. ReturnDesc->Integer.Value = 0;
  316. Digit = Operand[0]->Integer.Value;
  317. /* Each BCD digit is one nybble wide */
  318. for (i = 0; (i < AcpiGbl_IntegerNybbleWidth) && (Digit > 0); i++)
  319. {
  320. (void) AcpiUtShortDivide (Digit, 10, &Digit, &Temp32);
  321. /*
  322. * Insert the BCD digit that resides in the
  323. * remainder from above
  324. */
  325. ReturnDesc->Integer.Value |=
  326. (((UINT64) Temp32) << ACPI_MUL_4 (i));
  327. }
  328. /* Overflow if there is any data left in Digit */
  329. if (Digit > 0)
  330. {
  331. ACPI_ERROR ((AE_INFO,
  332. "Integer too large to convert to BCD: 0x%8.8X%8.8X",
  333. ACPI_FORMAT_UINT64 (Operand[0]->Integer.Value)));
  334. Status = AE_AML_NUMERIC_OVERFLOW;
  335. goto Cleanup;
  336. }
  337. break;
  338. case AML_COND_REF_OF_OP: /* CondRefOf (SourceObject, Result) */
  339. /*
  340. * This op is a little strange because the internal return value is
  341. * different than the return value stored in the result descriptor
  342. * (There are really two return values)
  343. */
  344. if ((ACPI_NAMESPACE_NODE *) Operand[0] == AcpiGbl_RootNode)
  345. {
  346. /*
  347. * This means that the object does not exist in the namespace,
  348. * return FALSE
  349. */
  350. ReturnDesc->Integer.Value = 0;
  351. goto Cleanup;
  352. }
  353. /* Get the object reference, store it, and remove our reference */
  354. Status = AcpiExGetObjectReference (Operand[0],
  355. &ReturnDesc2, WalkState);
  356. if (ACPI_FAILURE (Status))
  357. {
  358. goto Cleanup;
  359. }
  360. Status = AcpiExStore (ReturnDesc2, Operand[1], WalkState);
  361. AcpiUtRemoveReference (ReturnDesc2);
  362. /* The object exists in the namespace, return TRUE */
  363. ReturnDesc->Integer.Value = ACPI_UINT64_MAX;
  364. goto Cleanup;
  365. default:
  366. /* No other opcodes get here */
  367. break;
  368. }
  369. break;
  370. case AML_STORE_OP: /* Store (Source, Target) */
  371. /*
  372. * A store operand is typically a number, string, buffer or lvalue
  373. * Be careful about deleting the source object,
  374. * since the object itself may have been stored.
  375. */
  376. Status = AcpiExStore (Operand[0], Operand[1], WalkState);
  377. if (ACPI_FAILURE (Status))
  378. {
  379. return_ACPI_STATUS (Status);
  380. }
  381. /* It is possible that the Store already produced a return object */
  382. if (!WalkState->ResultObj)
  383. {
  384. /*
  385. * Normally, we would remove a reference on the Operand[0]
  386. * parameter; But since it is being used as the internal return
  387. * object (meaning we would normally increment it), the two
  388. * cancel out, and we simply don't do anything.
  389. */
  390. WalkState->ResultObj = Operand[0];
  391. WalkState->Operands[0] = NULL; /* Prevent deletion */
  392. }
  393. return_ACPI_STATUS (Status);
  394. /*
  395. * ACPI 2.0 Opcodes
  396. */
  397. case AML_COPY_OP: /* Copy (Source, Target) */
  398. Status = AcpiUtCopyIobjectToIobject (
  399. Operand[0], &ReturnDesc, WalkState);
  400. break;
  401. case AML_TO_DECSTRING_OP: /* ToDecimalString (Data, Result) */
  402. Status = AcpiExConvertToString (
  403. Operand[0], &ReturnDesc, ACPI_EXPLICIT_CONVERT_DECIMAL);
  404. if (ReturnDesc == Operand[0])
  405. {
  406. /* No conversion performed, add ref to handle return value */
  407. AcpiUtAddReference (ReturnDesc);
  408. }
  409. break;
  410. case AML_TO_HEXSTRING_OP: /* ToHexString (Data, Result) */
  411. Status = AcpiExConvertToString (
  412. Operand[0], &ReturnDesc, ACPI_EXPLICIT_CONVERT_HEX);
  413. if (ReturnDesc == Operand[0])
  414. {
  415. /* No conversion performed, add ref to handle return value */
  416. AcpiUtAddReference (ReturnDesc);
  417. }
  418. break;
  419. case AML_TO_BUFFER_OP: /* ToBuffer (Data, Result) */
  420. Status = AcpiExConvertToBuffer (Operand[0], &ReturnDesc);
  421. if (ReturnDesc == Operand[0])
  422. {
  423. /* No conversion performed, add ref to handle return value */
  424. AcpiUtAddReference (ReturnDesc);
  425. }
  426. break;
  427. case AML_TO_INTEGER_OP: /* ToInteger (Data, Result) */
  428. Status = AcpiExConvertToInteger (
  429. Operand[0], &ReturnDesc, ACPI_ANY_BASE);
  430. if (ReturnDesc == Operand[0])
  431. {
  432. /* No conversion performed, add ref to handle return value */
  433. AcpiUtAddReference (ReturnDesc);
  434. }
  435. break;
  436. case AML_SHIFT_LEFT_BIT_OP: /* ShiftLeftBit (Source, BitNum) */
  437. case AML_SHIFT_RIGHT_BIT_OP: /* ShiftRightBit (Source, BitNum) */
  438. /* These are two obsolete opcodes */
  439. ACPI_ERROR ((AE_INFO,
  440. "%s is obsolete and not implemented",
  441. AcpiPsGetOpcodeName (WalkState->Opcode)));
  442. Status = AE_SUPPORT;
  443. goto Cleanup;
  444. default: /* Unknown opcode */
  445. ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
  446. WalkState->Opcode));
  447. Status = AE_AML_BAD_OPCODE;
  448. goto Cleanup;
  449. }
  450. if (ACPI_SUCCESS (Status))
  451. {
  452. /* Store the return value computed above into the target object */
  453. Status = AcpiExStore (ReturnDesc, Operand[1], WalkState);
  454. }
  455. Cleanup:
  456. /* Delete return object on error */
  457. if (ACPI_FAILURE (Status))
  458. {
  459. AcpiUtRemoveReference (ReturnDesc);
  460. }
  461. /* Save return object on success */
  462. else if (!WalkState->ResultObj)
  463. {
  464. WalkState->ResultObj = ReturnDesc;
  465. }
  466. return_ACPI_STATUS (Status);
  467. }
  468. /*******************************************************************************
  469. *
  470. * FUNCTION: AcpiExOpcode_1A_0T_1R
  471. *
  472. * PARAMETERS: WalkState - Current state (contains AML opcode)
  473. *
  474. * RETURN: Status
  475. *
  476. * DESCRIPTION: Execute opcode with one argument, no target, and a return value
  477. *
  478. ******************************************************************************/
  479. ACPI_STATUS
  480. AcpiExOpcode_1A_0T_1R (
  481. ACPI_WALK_STATE *WalkState)
  482. {
  483. ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
  484. ACPI_OPERAND_OBJECT *TempDesc;
  485. ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
  486. ACPI_STATUS Status = AE_OK;
  487. UINT32 Type;
  488. UINT64 Value;
  489. ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_0T_1R,
  490. AcpiPsGetOpcodeName (WalkState->Opcode));
  491. /* Examine the AML opcode */
  492. switch (WalkState->Opcode)
  493. {
  494. case AML_LNOT_OP: /* LNot (Operand) */
  495. ReturnDesc = AcpiUtCreateIntegerObject ((UINT64) 0);
  496. if (!ReturnDesc)
  497. {
  498. Status = AE_NO_MEMORY;
  499. goto Cleanup;
  500. }
  501. /*
  502. * Set result to ONES (TRUE) if Value == 0. Note:
  503. * ReturnDesc->Integer.Value is initially == 0 (FALSE) from above.
  504. */
  505. if (!Operand[0]->Integer.Value)
  506. {
  507. ReturnDesc->Integer.Value = ACPI_UINT64_MAX;
  508. }
  509. break;
  510. case AML_DECREMENT_OP: /* Decrement (Operand) */
  511. case AML_INCREMENT_OP: /* Increment (Operand) */
  512. /*
  513. * Create a new integer. Can't just get the base integer and
  514. * increment it because it may be an Arg or Field.
  515. */
  516. ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
  517. if (!ReturnDesc)
  518. {
  519. Status = AE_NO_MEMORY;
  520. goto Cleanup;
  521. }
  522. /*
  523. * Since we are expecting a Reference operand, it can be either a
  524. * NS Node or an internal object.
  525. */
  526. TempDesc = Operand[0];
  527. if (ACPI_GET_DESCRIPTOR_TYPE (TempDesc) == ACPI_DESC_TYPE_OPERAND)
  528. {
  529. /* Internal reference object - prevent deletion */
  530. AcpiUtAddReference (TempDesc);
  531. }
  532. /*
  533. * Convert the Reference operand to an Integer (This removes a
  534. * reference on the Operand[0] object)
  535. *
  536. * NOTE: We use LNOT_OP here in order to force resolution of the
  537. * reference operand to an actual integer.
  538. */
  539. Status = AcpiExResolveOperands (AML_LNOT_OP, &TempDesc, WalkState);
  540. if (ACPI_FAILURE (Status))
  541. {
  542. ACPI_EXCEPTION ((AE_INFO, Status,
  543. "While resolving operands for [%s]",
  544. AcpiPsGetOpcodeName (WalkState->Opcode)));
  545. goto Cleanup;
  546. }
  547. /*
  548. * TempDesc is now guaranteed to be an Integer object --
  549. * Perform the actual increment or decrement
  550. */
  551. if (WalkState->Opcode == AML_INCREMENT_OP)
  552. {
  553. ReturnDesc->Integer.Value = TempDesc->Integer.Value + 1;
  554. }
  555. else
  556. {
  557. ReturnDesc->Integer.Value = TempDesc->Integer.Value - 1;
  558. }
  559. /* Finished with this Integer object */
  560. AcpiUtRemoveReference (TempDesc);
  561. /*
  562. * Store the result back (indirectly) through the original
  563. * Reference object
  564. */
  565. Status = AcpiExStore (ReturnDesc, Operand[0], WalkState);
  566. break;
  567. case AML_OBJECT_TYPE_OP: /* ObjectType (SourceObject) */
  568. /*
  569. * Note: The operand is not resolved at this point because we want to
  570. * get the associated object, not its value. For example, we don't
  571. * want to resolve a FieldUnit to its value, we want the actual
  572. * FieldUnit object.
  573. */
  574. /* Get the type of the base object */
  575. Status = AcpiExResolveMultiple (WalkState, Operand[0], &Type, NULL);
  576. if (ACPI_FAILURE (Status))
  577. {
  578. goto Cleanup;
  579. }
  580. /* Allocate a descriptor to hold the type. */
  581. ReturnDesc = AcpiUtCreateIntegerObject ((UINT64) Type);
  582. if (!ReturnDesc)
  583. {
  584. Status = AE_NO_MEMORY;
  585. goto Cleanup;
  586. }
  587. break;
  588. case AML_SIZE_OF_OP: /* SizeOf (SourceObject) */
  589. /*
  590. * Note: The operand is not resolved at this point because we want to
  591. * get the associated object, not its value.
  592. */
  593. /* Get the base object */
  594. Status = AcpiExResolveMultiple (
  595. WalkState, Operand[0], &Type, &TempDesc);
  596. if (ACPI_FAILURE (Status))
  597. {
  598. goto Cleanup;
  599. }
  600. /*
  601. * The type of the base object must be integer, buffer, string, or
  602. * package. All others are not supported.
  603. *
  604. * NOTE: Integer is not specifically supported by the ACPI spec,
  605. * but is supported implicitly via implicit operand conversion.
  606. * rather than bother with conversion, we just use the byte width
  607. * global (4 or 8 bytes).
  608. */
  609. switch (Type)
  610. {
  611. case ACPI_TYPE_INTEGER:
  612. Value = AcpiGbl_IntegerByteWidth;
  613. break;
  614. case ACPI_TYPE_STRING:
  615. Value = TempDesc->String.Length;
  616. break;
  617. case ACPI_TYPE_BUFFER:
  618. /* Buffer arguments may not be evaluated at this point */
  619. Status = AcpiDsGetBufferArguments (TempDesc);
  620. Value = TempDesc->Buffer.Length;
  621. break;
  622. case ACPI_TYPE_PACKAGE:
  623. /* Package arguments may not be evaluated at this point */
  624. Status = AcpiDsGetPackageArguments (TempDesc);
  625. Value = TempDesc->Package.Count;
  626. break;
  627. default:
  628. ACPI_ERROR ((AE_INFO,
  629. "Operand must be Buffer/Integer/String/Package"
  630. " - found type %s",
  631. AcpiUtGetTypeName (Type)));
  632. Status = AE_AML_OPERAND_TYPE;
  633. goto Cleanup;
  634. }
  635. if (ACPI_FAILURE (Status))
  636. {
  637. goto Cleanup;
  638. }
  639. /*
  640. * Now that we have the size of the object, create a result
  641. * object to hold the value
  642. */
  643. ReturnDesc = AcpiUtCreateIntegerObject (Value);
  644. if (!ReturnDesc)
  645. {
  646. Status = AE_NO_MEMORY;
  647. goto Cleanup;
  648. }
  649. break;
  650. case AML_REF_OF_OP: /* RefOf (SourceObject) */
  651. Status = AcpiExGetObjectReference (
  652. Operand[0], &ReturnDesc, WalkState);
  653. if (ACPI_FAILURE (Status))
  654. {
  655. goto Cleanup;
  656. }
  657. break;
  658. case AML_DEREF_OF_OP: /* DerefOf (ObjReference | String) */
  659. /* Check for a method local or argument, or standalone String */
  660. if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) == ACPI_DESC_TYPE_NAMED)
  661. {
  662. TempDesc = AcpiNsGetAttachedObject (
  663. (ACPI_NAMESPACE_NODE *) Operand[0]);
  664. if (TempDesc &&
  665. ((TempDesc->Common.Type == ACPI_TYPE_STRING) ||
  666. (TempDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE)))
  667. {
  668. Operand[0] = TempDesc;
  669. AcpiUtAddReference (TempDesc);
  670. }
  671. else
  672. {
  673. Status = AE_AML_OPERAND_TYPE;
  674. goto Cleanup;
  675. }
  676. }
  677. else
  678. {
  679. switch ((Operand[0])->Common.Type)
  680. {
  681. case ACPI_TYPE_LOCAL_REFERENCE:
  682. /*
  683. * This is a DerefOf (LocalX | ArgX)
  684. *
  685. * Must resolve/dereference the local/arg reference first
  686. */
  687. switch (Operand[0]->Reference.Class)
  688. {
  689. case ACPI_REFCLASS_LOCAL:
  690. case ACPI_REFCLASS_ARG:
  691. /* Set Operand[0] to the value of the local/arg */
  692. Status = AcpiDsMethodDataGetValue (
  693. Operand[0]->Reference.Class,
  694. Operand[0]->Reference.Value,
  695. WalkState, &TempDesc);
  696. if (ACPI_FAILURE (Status))
  697. {
  698. goto Cleanup;
  699. }
  700. /*
  701. * Delete our reference to the input object and
  702. * point to the object just retrieved
  703. */
  704. AcpiUtRemoveReference (Operand[0]);
  705. Operand[0] = TempDesc;
  706. break;
  707. case ACPI_REFCLASS_REFOF:
  708. /* Get the object to which the reference refers */
  709. TempDesc = Operand[0]->Reference.Object;
  710. AcpiUtRemoveReference (Operand[0]);
  711. Operand[0] = TempDesc;
  712. break;
  713. default:
  714. /* Must be an Index op - handled below */
  715. break;
  716. }
  717. break;
  718. case ACPI_TYPE_STRING:
  719. break;
  720. default:
  721. Status = AE_AML_OPERAND_TYPE;
  722. goto Cleanup;
  723. }
  724. }
  725. if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) != ACPI_DESC_TYPE_NAMED)
  726. {
  727. if ((Operand[0])->Common.Type == ACPI_TYPE_STRING)
  728. {
  729. /*
  730. * This is a DerefOf (String). The string is a reference
  731. * to a named ACPI object.
  732. *
  733. * 1) Find the owning Node
  734. * 2) Dereference the node to an actual object. Could be a
  735. * Field, so we need to resolve the node to a value.
  736. */
  737. Status = AcpiNsGetNode (WalkState->ScopeInfo->Scope.Node,
  738. Operand[0]->String.Pointer,
  739. ACPI_NS_SEARCH_PARENT,
  740. ACPI_CAST_INDIRECT_PTR (
  741. ACPI_NAMESPACE_NODE, &ReturnDesc));
  742. if (ACPI_FAILURE (Status))
  743. {
  744. goto Cleanup;
  745. }
  746. Status = AcpiExResolveNodeToValue (
  747. ACPI_CAST_INDIRECT_PTR (
  748. ACPI_NAMESPACE_NODE, &ReturnDesc),
  749. WalkState);
  750. goto Cleanup;
  751. }
  752. }
  753. /* Operand[0] may have changed from the code above */
  754. if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) == ACPI_DESC_TYPE_NAMED)
  755. {
  756. /*
  757. * This is a DerefOf (ObjectReference)
  758. * Get the actual object from the Node (This is the dereference).
  759. * This case may only happen when a LocalX or ArgX is
  760. * dereferenced above.
  761. */
  762. ReturnDesc = AcpiNsGetAttachedObject (
  763. (ACPI_NAMESPACE_NODE *) Operand[0]);
  764. AcpiUtAddReference (ReturnDesc);
  765. }
  766. else
  767. {
  768. /*
  769. * This must be a reference object produced by either the
  770. * Index() or RefOf() operator
  771. */
  772. switch (Operand[0]->Reference.Class)
  773. {
  774. case ACPI_REFCLASS_INDEX:
  775. /*
  776. * The target type for the Index operator must be
  777. * either a Buffer or a Package
  778. */
  779. switch (Operand[0]->Reference.TargetType)
  780. {
  781. case ACPI_TYPE_BUFFER_FIELD:
  782. TempDesc = Operand[0]->Reference.Object;
  783. /*
  784. * Create a new object that contains one element of the
  785. * buffer -- the element pointed to by the index.
  786. *
  787. * NOTE: index into a buffer is NOT a pointer to a
  788. * sub-buffer of the main buffer, it is only a pointer to a
  789. * single element (byte) of the buffer!
  790. *
  791. * Since we are returning the value of the buffer at the
  792. * indexed location, we don't need to add an additional
  793. * reference to the buffer itself.
  794. */
  795. ReturnDesc = AcpiUtCreateIntegerObject ((UINT64)
  796. TempDesc->Buffer.Pointer[Operand[0]->Reference.Value]);
  797. if (!ReturnDesc)
  798. {
  799. Status = AE_NO_MEMORY;
  800. goto Cleanup;
  801. }
  802. break;
  803. case ACPI_TYPE_PACKAGE:
  804. /*
  805. * Return the referenced element of the package. We must
  806. * add another reference to the referenced object, however.
  807. */
  808. ReturnDesc = *(Operand[0]->Reference.Where);
  809. if (!ReturnDesc)
  810. {
  811. /*
  812. * Element is NULL, do not allow the dereference.
  813. * This provides compatibility with other ACPI
  814. * implementations.
  815. */
  816. return_ACPI_STATUS (AE_AML_UNINITIALIZED_ELEMENT);
  817. }
  818. AcpiUtAddReference (ReturnDesc);
  819. break;
  820. default:
  821. ACPI_ERROR ((AE_INFO,
  822. "Unknown Index TargetType 0x%X in reference object %p",
  823. Operand[0]->Reference.TargetType, Operand[0]));
  824. Status = AE_AML_OPERAND_TYPE;
  825. goto Cleanup;
  826. }
  827. break;
  828. case ACPI_REFCLASS_REFOF:
  829. ReturnDesc = Operand[0]->Reference.Object;
  830. if (ACPI_GET_DESCRIPTOR_TYPE (ReturnDesc) ==
  831. ACPI_DESC_TYPE_NAMED)
  832. {
  833. ReturnDesc = AcpiNsGetAttachedObject (
  834. (ACPI_NAMESPACE_NODE *) ReturnDesc);
  835. if (!ReturnDesc)
  836. {
  837. break;
  838. }
  839. /*
  840. * June 2013:
  841. * BufferFields/FieldUnits require additional resolution
  842. */
  843. switch (ReturnDesc->Common.Type)
  844. {
  845. case ACPI_TYPE_BUFFER_FIELD:
  846. case ACPI_TYPE_LOCAL_REGION_FIELD:
  847. case ACPI_TYPE_LOCAL_BANK_FIELD:
  848. case ACPI_TYPE_LOCAL_INDEX_FIELD:
  849. Status = AcpiExReadDataFromField (
  850. WalkState, ReturnDesc, &TempDesc);
  851. if (ACPI_FAILURE (Status))
  852. {
  853. goto Cleanup;
  854. }
  855. ReturnDesc = TempDesc;
  856. break;
  857. default:
  858. /* Add another reference to the object */
  859. AcpiUtAddReference (ReturnDesc);
  860. break;
  861. }
  862. }
  863. break;
  864. default:
  865. ACPI_ERROR ((AE_INFO,
  866. "Unknown class in reference(%p) - 0x%2.2X",
  867. Operand[0], Operand[0]->Reference.Class));
  868. Status = AE_TYPE;
  869. goto Cleanup;
  870. }
  871. }
  872. break;
  873. default:
  874. ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
  875. WalkState->Opcode));
  876. Status = AE_AML_BAD_OPCODE;
  877. goto Cleanup;
  878. }
  879. Cleanup:
  880. /* Delete return object on error */
  881. if (ACPI_FAILURE (Status))
  882. {
  883. AcpiUtRemoveReference (ReturnDesc);
  884. }
  885. /* Save return object on success */
  886. else
  887. {
  888. WalkState->ResultObj = ReturnDesc;
  889. }
  890. return_ACPI_STATUS (Status);
  891. }