utbuffer.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /******************************************************************************
  2. *
  3. * Module Name: utbuffer - Buffer dump routines
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2013, 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. #define _COMPONENT ACPI_UTILITIES
  45. ACPI_MODULE_NAME("utbuffer")
  46. /*******************************************************************************
  47. *
  48. * FUNCTION: acpi_ut_dump_buffer
  49. *
  50. * PARAMETERS: buffer - Buffer to dump
  51. * count - Amount to dump, in bytes
  52. * display - BYTE, WORD, DWORD, or QWORD display:
  53. * DB_BYTE_DISPLAY
  54. * DB_WORD_DISPLAY
  55. * DB_DWORD_DISPLAY
  56. * DB_QWORD_DISPLAY
  57. * base_offset - Beginning buffer offset (display only)
  58. *
  59. * RETURN: None
  60. *
  61. * DESCRIPTION: Generic dump buffer in both hex and ascii.
  62. *
  63. ******************************************************************************/
  64. void acpi_ut_dump_buffer(u8 *buffer, u32 count, u32 display, u32 base_offset)
  65. {
  66. u32 i = 0;
  67. u32 j;
  68. u32 temp32;
  69. u8 buf_char;
  70. if (!buffer) {
  71. acpi_os_printf("Null Buffer Pointer in DumpBuffer!\n");
  72. return;
  73. }
  74. if ((count < 4) || (count & 0x01)) {
  75. display = DB_BYTE_DISPLAY;
  76. }
  77. /* Nasty little dump buffer routine! */
  78. while (i < count) {
  79. /* Print current offset */
  80. acpi_os_printf("%6.4X: ", (base_offset + i));
  81. /* Print 16 hex chars */
  82. for (j = 0; j < 16;) {
  83. if (i + j >= count) {
  84. /* Dump fill spaces */
  85. acpi_os_printf("%*s", ((display * 2) + 1), " ");
  86. j += display;
  87. continue;
  88. }
  89. switch (display) {
  90. case DB_BYTE_DISPLAY:
  91. default: /* Default is BYTE display */
  92. acpi_os_printf("%02X ",
  93. buffer[(acpi_size) i + j]);
  94. break;
  95. case DB_WORD_DISPLAY:
  96. ACPI_MOVE_16_TO_32(&temp32,
  97. &buffer[(acpi_size) i + j]);
  98. acpi_os_printf("%04X ", temp32);
  99. break;
  100. case DB_DWORD_DISPLAY:
  101. ACPI_MOVE_32_TO_32(&temp32,
  102. &buffer[(acpi_size) i + j]);
  103. acpi_os_printf("%08X ", temp32);
  104. break;
  105. case DB_QWORD_DISPLAY:
  106. ACPI_MOVE_32_TO_32(&temp32,
  107. &buffer[(acpi_size) i + j]);
  108. acpi_os_printf("%08X", temp32);
  109. ACPI_MOVE_32_TO_32(&temp32,
  110. &buffer[(acpi_size) i + j +
  111. 4]);
  112. acpi_os_printf("%08X ", temp32);
  113. break;
  114. }
  115. j += display;
  116. }
  117. /*
  118. * Print the ASCII equivalent characters but watch out for the bad
  119. * unprintable ones (printable chars are 0x20 through 0x7E)
  120. */
  121. acpi_os_printf(" ");
  122. for (j = 0; j < 16; j++) {
  123. if (i + j >= count) {
  124. acpi_os_printf("\n");
  125. return;
  126. }
  127. buf_char = buffer[(acpi_size) i + j];
  128. if (ACPI_IS_PRINT(buf_char)) {
  129. acpi_os_printf("%c", buf_char);
  130. } else {
  131. acpi_os_printf(".");
  132. }
  133. }
  134. /* Done with that line. */
  135. acpi_os_printf("\n");
  136. i += 16;
  137. }
  138. return;
  139. }
  140. /*******************************************************************************
  141. *
  142. * FUNCTION: acpi_ut_debug_dump_buffer
  143. *
  144. * PARAMETERS: buffer - Buffer to dump
  145. * count - Amount to dump, in bytes
  146. * display - BYTE, WORD, DWORD, or QWORD display:
  147. * DB_BYTE_DISPLAY
  148. * DB_WORD_DISPLAY
  149. * DB_DWORD_DISPLAY
  150. * DB_QWORD_DISPLAY
  151. * component_ID - Caller's component ID
  152. *
  153. * RETURN: None
  154. *
  155. * DESCRIPTION: Generic dump buffer in both hex and ascii.
  156. *
  157. ******************************************************************************/
  158. void
  159. acpi_ut_debug_dump_buffer(u8 *buffer, u32 count, u32 display, u32 component_id)
  160. {
  161. /* Only dump the buffer if tracing is enabled */
  162. if (!((ACPI_LV_TABLES & acpi_dbg_level) &&
  163. (component_id & acpi_dbg_layer))) {
  164. return;
  165. }
  166. acpi_ut_dump_buffer(buffer, count, display, 0);
  167. }