exoparg3.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /******************************************************************************
  2. *
  3. * Module Name: exoparg3 - AML execution - opcodes with 3 arguments
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2016, 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/acpi.h>
  43. #include "accommon.h"
  44. #include "acinterp.h"
  45. #include "acparser.h"
  46. #include "amlcode.h"
  47. #define _COMPONENT ACPI_EXECUTER
  48. ACPI_MODULE_NAME("exoparg3")
  49. /*!
  50. * Naming convention for AML interpreter execution routines.
  51. *
  52. * The routines that begin execution of AML opcodes are named with a common
  53. * convention based upon the number of arguments, the number of target operands,
  54. * and whether or not a value is returned:
  55. *
  56. * AcpiExOpcode_xA_yT_zR
  57. *
  58. * Where:
  59. *
  60. * xA - ARGUMENTS: The number of arguments (input operands) that are
  61. * required for this opcode type (1 through 6 args).
  62. * yT - TARGETS: The number of targets (output operands) that are required
  63. * for this opcode type (0, 1, or 2 targets).
  64. * zR - RETURN VALUE: Indicates whether this opcode type returns a value
  65. * as the function return (0 or 1).
  66. *
  67. * The AcpiExOpcode* functions are called via the Dispatcher component with
  68. * fully resolved operands.
  69. !*/
  70. /*******************************************************************************
  71. *
  72. * FUNCTION: acpi_ex_opcode_3A_0T_0R
  73. *
  74. * PARAMETERS: walk_state - Current walk state
  75. *
  76. * RETURN: Status
  77. *
  78. * DESCRIPTION: Execute Triadic operator (3 operands)
  79. *
  80. ******************************************************************************/
  81. acpi_status acpi_ex_opcode_3A_0T_0R(struct acpi_walk_state *walk_state)
  82. {
  83. union acpi_operand_object **operand = &walk_state->operands[0];
  84. struct acpi_signal_fatal_info *fatal;
  85. acpi_status status = AE_OK;
  86. ACPI_FUNCTION_TRACE_STR(ex_opcode_3A_0T_0R,
  87. acpi_ps_get_opcode_name(walk_state->opcode));
  88. switch (walk_state->opcode) {
  89. case AML_FATAL_OP: /* Fatal (fatal_type fatal_code fatal_arg) */
  90. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  91. "FatalOp: Type %X Code %X Arg %X "
  92. "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n",
  93. (u32)operand[0]->integer.value,
  94. (u32)operand[1]->integer.value,
  95. (u32)operand[2]->integer.value));
  96. fatal = ACPI_ALLOCATE(sizeof(struct acpi_signal_fatal_info));
  97. if (fatal) {
  98. fatal->type = (u32) operand[0]->integer.value;
  99. fatal->code = (u32) operand[1]->integer.value;
  100. fatal->argument = (u32) operand[2]->integer.value;
  101. }
  102. /* Always signal the OS! */
  103. status = acpi_os_signal(ACPI_SIGNAL_FATAL, fatal);
  104. /* Might return while OS is shutting down, just continue */
  105. ACPI_FREE(fatal);
  106. goto cleanup;
  107. case AML_EXTERNAL_OP:
  108. /*
  109. * If the interpreter sees this opcode, just ignore it. The External
  110. * op is intended for use by disassemblers in order to properly
  111. * disassemble control method invocations. The opcode or group of
  112. * opcodes should be surrounded by an "if (0)" clause to ensure that
  113. * AML interpreters never see the opcode. Thus, something is
  114. * wrong if an external opcode ever gets here.
  115. */
  116. ACPI_ERROR((AE_INFO, "Executed External Op"));
  117. status = AE_OK;
  118. goto cleanup;
  119. default:
  120. ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
  121. walk_state->opcode));
  122. status = AE_AML_BAD_OPCODE;
  123. goto cleanup;
  124. }
  125. cleanup:
  126. return_ACPI_STATUS(status);
  127. }
  128. /*******************************************************************************
  129. *
  130. * FUNCTION: acpi_ex_opcode_3A_1T_1R
  131. *
  132. * PARAMETERS: walk_state - Current walk state
  133. *
  134. * RETURN: Status
  135. *
  136. * DESCRIPTION: Execute Triadic operator (3 operands)
  137. *
  138. ******************************************************************************/
  139. acpi_status acpi_ex_opcode_3A_1T_1R(struct acpi_walk_state *walk_state)
  140. {
  141. union acpi_operand_object **operand = &walk_state->operands[0];
  142. union acpi_operand_object *return_desc = NULL;
  143. char *buffer = NULL;
  144. acpi_status status = AE_OK;
  145. u64 index;
  146. acpi_size length;
  147. ACPI_FUNCTION_TRACE_STR(ex_opcode_3A_1T_1R,
  148. acpi_ps_get_opcode_name(walk_state->opcode));
  149. switch (walk_state->opcode) {
  150. case AML_MID_OP: /* Mid (Source[0], Index[1], Length[2], Result[3]) */
  151. /*
  152. * Create the return object. The Source operand is guaranteed to be
  153. * either a String or a Buffer, so just use its type.
  154. */
  155. return_desc = acpi_ut_create_internal_object((operand[0])->
  156. common.type);
  157. if (!return_desc) {
  158. status = AE_NO_MEMORY;
  159. goto cleanup;
  160. }
  161. /* Get the Integer values from the objects */
  162. index = operand[1]->integer.value;
  163. length = (acpi_size)operand[2]->integer.value;
  164. /*
  165. * If the index is beyond the length of the String/Buffer, or if the
  166. * requested length is zero, return a zero-length String/Buffer
  167. */
  168. if (index >= operand[0]->string.length) {
  169. length = 0;
  170. }
  171. /* Truncate request if larger than the actual String/Buffer */
  172. else if ((index + length) > operand[0]->string.length) {
  173. length =
  174. (acpi_size)operand[0]->string.length -
  175. (acpi_size)index;
  176. }
  177. /* Strings always have a sub-pointer, not so for buffers */
  178. switch ((operand[0])->common.type) {
  179. case ACPI_TYPE_STRING:
  180. /* Always allocate a new buffer for the String */
  181. buffer = ACPI_ALLOCATE_ZEROED((acpi_size)length + 1);
  182. if (!buffer) {
  183. status = AE_NO_MEMORY;
  184. goto cleanup;
  185. }
  186. break;
  187. case ACPI_TYPE_BUFFER:
  188. /* If the requested length is zero, don't allocate a buffer */
  189. if (length > 0) {
  190. /* Allocate a new buffer for the Buffer */
  191. buffer = ACPI_ALLOCATE_ZEROED(length);
  192. if (!buffer) {
  193. status = AE_NO_MEMORY;
  194. goto cleanup;
  195. }
  196. }
  197. break;
  198. default: /* Should not happen */
  199. status = AE_AML_OPERAND_TYPE;
  200. goto cleanup;
  201. }
  202. if (buffer) {
  203. /* We have a buffer, copy the portion requested */
  204. memcpy(buffer,
  205. operand[0]->string.pointer + index, length);
  206. }
  207. /* Set the length of the new String/Buffer */
  208. return_desc->string.pointer = buffer;
  209. return_desc->string.length = (u32) length;
  210. /* Mark buffer initialized */
  211. return_desc->buffer.flags |= AOPOBJ_DATA_VALID;
  212. break;
  213. default:
  214. ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
  215. walk_state->opcode));
  216. status = AE_AML_BAD_OPCODE;
  217. goto cleanup;
  218. }
  219. /* Store the result in the target */
  220. status = acpi_ex_store(return_desc, operand[3], walk_state);
  221. cleanup:
  222. /* Delete return object on error */
  223. if (ACPI_FAILURE(status) || walk_state->result_obj) {
  224. acpi_ut_remove_reference(return_desc);
  225. walk_state->result_obj = NULL;
  226. } else {
  227. /* Set the return object and exit */
  228. walk_state->result_obj = return_desc;
  229. }
  230. return_ACPI_STATUS(status);
  231. }