exoparg3.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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
  81. acpi_ex_opcode_3A_0T_0R (
  82. struct acpi_walk_state *walk_state)
  83. {
  84. union acpi_operand_object **operand = &walk_state->operands[0];
  85. struct acpi_signal_fatal_info *fatal;
  86. acpi_status status = AE_OK;
  87. ACPI_FUNCTION_TRACE_STR ("ex_opcode_3A_0T_0R",
  88. acpi_ps_get_opcode_name (walk_state->opcode));
  89. switch (walk_state->opcode) {
  90. case AML_FATAL_OP: /* Fatal (fatal_type fatal_code fatal_arg) */
  91. ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
  92. "fatal_op: Type %X Code %X Arg %X <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n",
  93. (u32) operand[0]->integer.value,
  94. (u32) operand[1]->integer.value,
  95. (u32) operand[2]->integer.value));
  96. fatal = ACPI_MEM_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_MEM_FREE (fatal);
  106. break;
  107. default:
  108. ACPI_REPORT_ERROR (("acpi_ex_opcode_3A_0T_0R: Unknown opcode %X\n",
  109. walk_state->opcode));
  110. status = AE_AML_BAD_OPCODE;
  111. goto cleanup;
  112. }
  113. cleanup:
  114. return_ACPI_STATUS (status);
  115. }
  116. /*******************************************************************************
  117. *
  118. * FUNCTION: acpi_ex_opcode_3A_1T_1R
  119. *
  120. * PARAMETERS: walk_state - Current walk state
  121. *
  122. * RETURN: Status
  123. *
  124. * DESCRIPTION: Execute Triadic operator (3 operands)
  125. *
  126. ******************************************************************************/
  127. acpi_status
  128. acpi_ex_opcode_3A_1T_1R (
  129. struct acpi_walk_state *walk_state)
  130. {
  131. union acpi_operand_object **operand = &walk_state->operands[0];
  132. union acpi_operand_object *return_desc = NULL;
  133. char *buffer;
  134. acpi_status status = AE_OK;
  135. acpi_integer index;
  136. acpi_size length;
  137. ACPI_FUNCTION_TRACE_STR ("ex_opcode_3A_1T_1R",
  138. acpi_ps_get_opcode_name (walk_state->opcode));
  139. switch (walk_state->opcode) {
  140. case AML_MID_OP: /* Mid (Source[0], Index[1], Length[2], Result[3]) */
  141. /*
  142. * Create the return object. The Source operand is guaranteed to be
  143. * either a String or a Buffer, so just use its type.
  144. */
  145. return_desc = acpi_ut_create_internal_object (
  146. ACPI_GET_OBJECT_TYPE (operand[0]));
  147. if (!return_desc) {
  148. status = AE_NO_MEMORY;
  149. goto cleanup;
  150. }
  151. /* Get the Integer values from the objects */
  152. index = operand[1]->integer.value;
  153. length = (acpi_size) operand[2]->integer.value;
  154. /*
  155. * If the index is beyond the length of the String/Buffer, or if the
  156. * requested length is zero, return a zero-length String/Buffer
  157. */
  158. if ((index < operand[0]->string.length) &&
  159. (length > 0)) {
  160. /* Truncate request if larger than the actual String/Buffer */
  161. if ((index + length) >
  162. operand[0]->string.length) {
  163. length = (acpi_size) operand[0]->string.length -
  164. (acpi_size) index;
  165. }
  166. /* Allocate a new buffer for the String/Buffer */
  167. buffer = ACPI_MEM_CALLOCATE ((acpi_size) length + 1);
  168. if (!buffer) {
  169. status = AE_NO_MEMORY;
  170. goto cleanup;
  171. }
  172. /* Copy the portion requested */
  173. ACPI_MEMCPY (buffer, operand[0]->string.pointer + index,
  174. length);
  175. /* Set the length of the new String/Buffer */
  176. return_desc->string.pointer = buffer;
  177. return_desc->string.length = (u32) length;
  178. }
  179. /* Mark buffer initialized */
  180. return_desc->buffer.flags |= AOPOBJ_DATA_VALID;
  181. break;
  182. default:
  183. ACPI_REPORT_ERROR (("acpi_ex_opcode_3A_0T_0R: Unknown opcode %X\n",
  184. walk_state->opcode));
  185. status = AE_AML_BAD_OPCODE;
  186. goto cleanup;
  187. }
  188. /* Store the result in the target */
  189. status = acpi_ex_store (return_desc, operand[3], walk_state);
  190. cleanup:
  191. /* Delete return object on error */
  192. if (ACPI_FAILURE (status)) {
  193. acpi_ut_remove_reference (return_desc);
  194. }
  195. /* Set the return object and exit */
  196. if (!walk_state->result_obj) {
  197. walk_state->result_obj = return_desc;
  198. }
  199. return_ACPI_STATUS (status);
  200. }