exoparg6.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /******************************************************************************
  2. *
  3. * Module Name: exoparg6 - AML execution - opcodes with 6 arguments
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2005, R. Byron Moore
  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/acpi.h>
  43. #include <acpi/acinterp.h>
  44. #include <acpi/acparser.h>
  45. #include <acpi/amlcode.h>
  46. #define _COMPONENT ACPI_EXECUTER
  47. ACPI_MODULE_NAME ("exoparg6")
  48. /*!
  49. * Naming convention for AML interpreter execution routines.
  50. *
  51. * The routines that begin execution of AML opcodes are named with a common
  52. * convention based upon the number of arguments, the number of target operands,
  53. * and whether or not a value is returned:
  54. *
  55. * AcpiExOpcode_xA_yT_zR
  56. *
  57. * Where:
  58. *
  59. * xA - ARGUMENTS: The number of arguments (input operands) that are
  60. * required for this opcode type (1 through 6 args).
  61. * yT - TARGETS: The number of targets (output operands) that are required
  62. * for this opcode type (0, 1, or 2 targets).
  63. * zR - RETURN VALUE: Indicates whether this opcode type returns a value
  64. * as the function return (0 or 1).
  65. *
  66. * The AcpiExOpcode* functions are called via the Dispatcher component with
  67. * fully resolved operands.
  68. !*/
  69. /*******************************************************************************
  70. *
  71. * FUNCTION: acpi_ex_do_match
  72. *
  73. * PARAMETERS: match_op - The AML match operand
  74. * package_obj - Object from the target package
  75. * match_obj - Object to be matched
  76. *
  77. * RETURN: TRUE if the match is successful, FALSE otherwise
  78. *
  79. * DESCRIPTION: Implements the low-level match for the ASL Match operator.
  80. * Package elements will be implicitly converted to the type of
  81. * the match object (Integer/Buffer/String).
  82. *
  83. ******************************************************************************/
  84. u8
  85. acpi_ex_do_match (
  86. u32 match_op,
  87. union acpi_operand_object *package_obj,
  88. union acpi_operand_object *match_obj)
  89. {
  90. u8 logical_result = TRUE;
  91. acpi_status status;
  92. /*
  93. * Note: Since the package_obj/match_obj ordering is opposite to that of
  94. * the standard logical operators, we have to reverse them when we call
  95. * do_logical_op in order to make the implicit conversion rules work
  96. * correctly. However, this means we have to flip the entire equation
  97. * also. A bit ugly perhaps, but overall, better than fussing the
  98. * parameters around at runtime, over and over again.
  99. *
  100. * Below, P[i] refers to the package element, M refers to the Match object.
  101. */
  102. switch (match_op) {
  103. case MATCH_MTR:
  104. /* Always true */
  105. break;
  106. case MATCH_MEQ:
  107. /*
  108. * True if equal: (P[i] == M)
  109. * Change to: (M == P[i])
  110. */
  111. status = acpi_ex_do_logical_op (AML_LEQUAL_OP, match_obj, package_obj,
  112. &logical_result);
  113. if (ACPI_FAILURE (status)) {
  114. return (FALSE);
  115. }
  116. break;
  117. case MATCH_MLE:
  118. /*
  119. * True if less than or equal: (P[i] <= M) (P[i] not_greater than M)
  120. * Change to: (M >= P[i]) (M not_less than P[i])
  121. */
  122. status = acpi_ex_do_logical_op (AML_LLESS_OP, match_obj, package_obj,
  123. &logical_result);
  124. if (ACPI_FAILURE (status)) {
  125. return (FALSE);
  126. }
  127. logical_result = (u8) !logical_result;
  128. break;
  129. case MATCH_MLT:
  130. /*
  131. * True if less than: (P[i] < M)
  132. * Change to: (M > P[i])
  133. */
  134. status = acpi_ex_do_logical_op (AML_LGREATER_OP, match_obj, package_obj,
  135. &logical_result);
  136. if (ACPI_FAILURE (status)) {
  137. return (FALSE);
  138. }
  139. break;
  140. case MATCH_MGE:
  141. /*
  142. * True if greater than or equal: (P[i] >= M) (P[i] not_less than M)
  143. * Change to: (M <= P[i]) (M not_greater than P[i])
  144. */
  145. status = acpi_ex_do_logical_op (AML_LGREATER_OP, match_obj, package_obj,
  146. &logical_result);
  147. if (ACPI_FAILURE (status)) {
  148. return (FALSE);
  149. }
  150. logical_result = (u8)!logical_result;
  151. break;
  152. case MATCH_MGT:
  153. /*
  154. * True if greater than: (P[i] > M)
  155. * Change to: (M < P[i])
  156. */
  157. status = acpi_ex_do_logical_op (AML_LLESS_OP, match_obj, package_obj,
  158. &logical_result);
  159. if (ACPI_FAILURE (status)) {
  160. return (FALSE);
  161. }
  162. break;
  163. default:
  164. /* Undefined */
  165. return (FALSE);
  166. }
  167. return logical_result;
  168. }
  169. /*******************************************************************************
  170. *
  171. * FUNCTION: acpi_ex_opcode_6A_0T_1R
  172. *
  173. * PARAMETERS: walk_state - Current walk state
  174. *
  175. * RETURN: Status
  176. *
  177. * DESCRIPTION: Execute opcode with 6 arguments, no target, and a return value
  178. *
  179. ******************************************************************************/
  180. acpi_status
  181. acpi_ex_opcode_6A_0T_1R (
  182. struct acpi_walk_state *walk_state)
  183. {
  184. union acpi_operand_object **operand = &walk_state->operands[0];
  185. union acpi_operand_object *return_desc = NULL;
  186. acpi_status status = AE_OK;
  187. u32 index;
  188. union acpi_operand_object *this_element;
  189. ACPI_FUNCTION_TRACE_STR ("ex_opcode_6A_0T_1R", acpi_ps_get_opcode_name (walk_state->opcode));
  190. switch (walk_state->opcode) {
  191. case AML_MATCH_OP:
  192. /*
  193. * Match (search_pkg[0], match_op1[1], match_obj1[2],
  194. * match_op2[3], match_obj2[4], start_index[5])
  195. */
  196. /* Validate both Match Term Operators (MTR, MEQ, etc.) */
  197. if ((operand[1]->integer.value > MAX_MATCH_OPERATOR) ||
  198. (operand[3]->integer.value > MAX_MATCH_OPERATOR)) {
  199. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Match operator out of range\n"));
  200. status = AE_AML_OPERAND_VALUE;
  201. goto cleanup;
  202. }
  203. /* Get the package start_index, validate against the package length */
  204. index = (u32) operand[5]->integer.value;
  205. if (index >= (u32) operand[0]->package.count) {
  206. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Index beyond package end\n"));
  207. status = AE_AML_PACKAGE_LIMIT;
  208. goto cleanup;
  209. }
  210. /* Create an integer for the return value */
  211. return_desc = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER);
  212. if (!return_desc) {
  213. status = AE_NO_MEMORY;
  214. goto cleanup;
  215. }
  216. /* Default return value if no match found */
  217. return_desc->integer.value = ACPI_INTEGER_MAX;
  218. /*
  219. * Examine each element until a match is found. Both match conditions
  220. * must be satisfied for a match to occur. Within the loop,
  221. * "continue" signifies that the current element does not match
  222. * and the next should be examined.
  223. *
  224. * Upon finding a match, the loop will terminate via "break" at
  225. * the bottom. If it terminates "normally", match_value will be
  226. * ACPI_INTEGER_MAX (Ones) (its initial value) indicating that no
  227. * match was found.
  228. */
  229. for ( ; index < operand[0]->package.count; index++) {
  230. /* Get the current package element */
  231. this_element = operand[0]->package.elements[index];
  232. /* Treat any uninitialized (NULL) elements as non-matching */
  233. if (!this_element) {
  234. continue;
  235. }
  236. /*
  237. * Both match conditions must be satisfied. Execution of a continue
  238. * (proceed to next iteration of enclosing for loop) signifies a
  239. * non-match.
  240. */
  241. if (!acpi_ex_do_match ((u32) operand[1]->integer.value,
  242. this_element, operand[2])) {
  243. continue;
  244. }
  245. if (!acpi_ex_do_match ((u32) operand[3]->integer.value,
  246. this_element, operand[4])) {
  247. continue;
  248. }
  249. /* Match found: Index is the return value */
  250. return_desc->integer.value = index;
  251. break;
  252. }
  253. break;
  254. case AML_LOAD_TABLE_OP:
  255. status = acpi_ex_load_table_op (walk_state, &return_desc);
  256. break;
  257. default:
  258. ACPI_REPORT_ERROR (("acpi_ex_opcode_3A_0T_0R: Unknown opcode %X\n",
  259. walk_state->opcode));
  260. status = AE_AML_BAD_OPCODE;
  261. goto cleanup;
  262. }
  263. walk_state->result_obj = return_desc;
  264. cleanup:
  265. /* Delete return object on error */
  266. if (ACPI_FAILURE (status)) {
  267. acpi_ut_remove_reference (return_desc);
  268. }
  269. return_ACPI_STATUS (status);
  270. }