exoparg3.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /******************************************************************************
  2. *
  3. * Module Name: exoparg3 - AML execution - opcodes with 3 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("exoparg3")
  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_opcode_3A_0T_0R
  72. *
  73. * PARAMETERS: walk_state - Current walk state
  74. *
  75. * RETURN: Status
  76. *
  77. * DESCRIPTION: Execute Triadic operator (3 operands)
  78. *
  79. ******************************************************************************/
  80. acpi_status acpi_ex_opcode_3A_0T_0R(struct acpi_walk_state *walk_state)
  81. {
  82. union acpi_operand_object **operand = &walk_state->operands[0];
  83. struct acpi_signal_fatal_info *fatal;
  84. acpi_status status = AE_OK;
  85. ACPI_FUNCTION_TRACE_STR("ex_opcode_3A_0T_0R",
  86. acpi_ps_get_opcode_name(walk_state->opcode));
  87. switch (walk_state->opcode) {
  88. case AML_FATAL_OP: /* Fatal (fatal_type fatal_code fatal_arg) */
  89. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  90. "fatal_op: Type %X Code %X Arg %X <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n",
  91. (u32) operand[0]->integer.value,
  92. (u32) operand[1]->integer.value,
  93. (u32) operand[2]->integer.value));
  94. fatal =
  95. ACPI_MEM_ALLOCATE(sizeof(struct acpi_signal_fatal_info));
  96. if (fatal) {
  97. fatal->type = (u32) operand[0]->integer.value;
  98. fatal->code = (u32) operand[1]->integer.value;
  99. fatal->argument = (u32) operand[2]->integer.value;
  100. }
  101. /* Always signal the OS! */
  102. status = acpi_os_signal(ACPI_SIGNAL_FATAL, fatal);
  103. /* Might return while OS is shutting down, just continue */
  104. ACPI_MEM_FREE(fatal);
  105. break;
  106. default:
  107. ACPI_REPORT_ERROR(("acpi_ex_opcode_3A_0T_0R: Unknown opcode %X\n", walk_state->opcode));
  108. status = AE_AML_BAD_OPCODE;
  109. goto cleanup;
  110. }
  111. cleanup:
  112. return_ACPI_STATUS(status);
  113. }
  114. /*******************************************************************************
  115. *
  116. * FUNCTION: acpi_ex_opcode_3A_1T_1R
  117. *
  118. * PARAMETERS: walk_state - Current walk state
  119. *
  120. * RETURN: Status
  121. *
  122. * DESCRIPTION: Execute Triadic operator (3 operands)
  123. *
  124. ******************************************************************************/
  125. acpi_status acpi_ex_opcode_3A_1T_1R(struct acpi_walk_state *walk_state)
  126. {
  127. union acpi_operand_object **operand = &walk_state->operands[0];
  128. union acpi_operand_object *return_desc = NULL;
  129. char *buffer = NULL;
  130. acpi_status status = AE_OK;
  131. acpi_integer index;
  132. acpi_size length;
  133. ACPI_FUNCTION_TRACE_STR("ex_opcode_3A_1T_1R",
  134. acpi_ps_get_opcode_name(walk_state->opcode));
  135. switch (walk_state->opcode) {
  136. case AML_MID_OP: /* Mid (Source[0], Index[1], Length[2], Result[3]) */
  137. /*
  138. * Create the return object. The Source operand is guaranteed to be
  139. * either a String or a Buffer, so just use its type.
  140. */
  141. return_desc =
  142. acpi_ut_create_internal_object(ACPI_GET_OBJECT_TYPE
  143. (operand[0]));
  144. if (!return_desc) {
  145. status = AE_NO_MEMORY;
  146. goto cleanup;
  147. }
  148. /* Get the Integer values from the objects */
  149. index = operand[1]->integer.value;
  150. length = (acpi_size) operand[2]->integer.value;
  151. /*
  152. * If the index is beyond the length of the String/Buffer, or if the
  153. * requested length is zero, return a zero-length String/Buffer
  154. */
  155. if (index >= operand[0]->string.length) {
  156. length = 0;
  157. }
  158. /* Truncate request if larger than the actual String/Buffer */
  159. else if ((index + length) > operand[0]->string.length) {
  160. length = (acpi_size) operand[0]->string.length -
  161. (acpi_size) index;
  162. }
  163. /* Strings always have a sub-pointer, not so for buffers */
  164. switch (ACPI_GET_OBJECT_TYPE(operand[0])) {
  165. case ACPI_TYPE_STRING:
  166. /* Always allocate a new buffer for the String */
  167. buffer = ACPI_MEM_CALLOCATE((acpi_size) length + 1);
  168. if (!buffer) {
  169. status = AE_NO_MEMORY;
  170. goto cleanup;
  171. }
  172. break;
  173. case ACPI_TYPE_BUFFER:
  174. /* If the requested length is zero, don't allocate a buffer */
  175. if (length > 0) {
  176. /* Allocate a new buffer for the Buffer */
  177. buffer = ACPI_MEM_CALLOCATE(length);
  178. if (!buffer) {
  179. status = AE_NO_MEMORY;
  180. goto cleanup;
  181. }
  182. }
  183. break;
  184. default: /* Should not happen */
  185. status = AE_AML_OPERAND_TYPE;
  186. goto cleanup;
  187. }
  188. if (length > 0) {
  189. /* Copy the portion requested */
  190. ACPI_MEMCPY(buffer, operand[0]->string.pointer + index,
  191. length);
  192. }
  193. /* Set the length of the new String/Buffer */
  194. return_desc->string.pointer = buffer;
  195. return_desc->string.length = (u32) length;
  196. /* Mark buffer initialized */
  197. return_desc->buffer.flags |= AOPOBJ_DATA_VALID;
  198. break;
  199. default:
  200. ACPI_REPORT_ERROR(("acpi_ex_opcode_3A_0T_0R: Unknown opcode %X\n", walk_state->opcode));
  201. status = AE_AML_BAD_OPCODE;
  202. goto cleanup;
  203. }
  204. /* Store the result in the target */
  205. status = acpi_ex_store(return_desc, operand[3], walk_state);
  206. cleanup:
  207. /* Delete return object on error */
  208. if (ACPI_FAILURE(status) || walk_state->result_obj) {
  209. acpi_ut_remove_reference(return_desc);
  210. }
  211. /* Set the return object and exit */
  212. else {
  213. walk_state->result_obj = return_desc;
  214. }
  215. return_ACPI_STATUS(status);
  216. }