utbuffer.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /******************************************************************************
  2. *
  3. * Module Name: utbuffer - Buffer dump routines
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2015, 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. /*
  128. * Add comment characters so rest of line is ignored when
  129. * compiled
  130. */
  131. if (j == 0) {
  132. acpi_os_printf("// ");
  133. }
  134. buf_char = buffer[(acpi_size) i + j];
  135. if (isprint(buf_char)) {
  136. acpi_os_printf("%c", buf_char);
  137. } else {
  138. acpi_os_printf(".");
  139. }
  140. }
  141. /* Done with that line. */
  142. acpi_os_printf("\n");
  143. i += 16;
  144. }
  145. return;
  146. }
  147. /*******************************************************************************
  148. *
  149. * FUNCTION: acpi_ut_debug_dump_buffer
  150. *
  151. * PARAMETERS: buffer - Buffer to dump
  152. * count - Amount to dump, in bytes
  153. * display - BYTE, WORD, DWORD, or QWORD display:
  154. * DB_BYTE_DISPLAY
  155. * DB_WORD_DISPLAY
  156. * DB_DWORD_DISPLAY
  157. * DB_QWORD_DISPLAY
  158. * component_ID - Caller's component ID
  159. *
  160. * RETURN: None
  161. *
  162. * DESCRIPTION: Generic dump buffer in both hex and ascii.
  163. *
  164. ******************************************************************************/
  165. void
  166. acpi_ut_debug_dump_buffer(u8 *buffer, u32 count, u32 display, u32 component_id)
  167. {
  168. /* Only dump the buffer if tracing is enabled */
  169. if (!((ACPI_LV_TABLES & acpi_dbg_level) &&
  170. (component_id & acpi_dbg_layer))) {
  171. return;
  172. }
  173. acpi_ut_dump_buffer(buffer, count, display, 0);
  174. }
  175. #ifdef ACPI_APPLICATION
  176. /*******************************************************************************
  177. *
  178. * FUNCTION: acpi_ut_dump_buffer_to_file
  179. *
  180. * PARAMETERS: file - File descriptor
  181. * buffer - Buffer to dump
  182. * count - Amount to dump, in bytes
  183. * display - BYTE, WORD, DWORD, or QWORD display:
  184. * DB_BYTE_DISPLAY
  185. * DB_WORD_DISPLAY
  186. * DB_DWORD_DISPLAY
  187. * DB_QWORD_DISPLAY
  188. * base_offset - Beginning buffer offset (display only)
  189. *
  190. * RETURN: None
  191. *
  192. * DESCRIPTION: Generic dump buffer in both hex and ascii to a file.
  193. *
  194. ******************************************************************************/
  195. void
  196. acpi_ut_dump_buffer_to_file(ACPI_FILE file,
  197. u8 *buffer, u32 count, u32 display, u32 base_offset)
  198. {
  199. u32 i = 0;
  200. u32 j;
  201. u32 temp32;
  202. u8 buf_char;
  203. if (!buffer) {
  204. acpi_ut_file_printf(file,
  205. "Null Buffer Pointer in DumpBuffer!\n");
  206. return;
  207. }
  208. if ((count < 4) || (count & 0x01)) {
  209. display = DB_BYTE_DISPLAY;
  210. }
  211. /* Nasty little dump buffer routine! */
  212. while (i < count) {
  213. /* Print current offset */
  214. acpi_ut_file_printf(file, "%6.4X: ", (base_offset + i));
  215. /* Print 16 hex chars */
  216. for (j = 0; j < 16;) {
  217. if (i + j >= count) {
  218. /* Dump fill spaces */
  219. acpi_ut_file_printf(file, "%*s",
  220. ((display * 2) + 1), " ");
  221. j += display;
  222. continue;
  223. }
  224. switch (display) {
  225. case DB_BYTE_DISPLAY:
  226. default: /* Default is BYTE display */
  227. acpi_ut_file_printf(file, "%02X ",
  228. buffer[(acpi_size) i + j]);
  229. break;
  230. case DB_WORD_DISPLAY:
  231. ACPI_MOVE_16_TO_32(&temp32,
  232. &buffer[(acpi_size) i + j]);
  233. acpi_ut_file_printf(file, "%04X ", temp32);
  234. break;
  235. case DB_DWORD_DISPLAY:
  236. ACPI_MOVE_32_TO_32(&temp32,
  237. &buffer[(acpi_size) i + j]);
  238. acpi_ut_file_printf(file, "%08X ", temp32);
  239. break;
  240. case DB_QWORD_DISPLAY:
  241. ACPI_MOVE_32_TO_32(&temp32,
  242. &buffer[(acpi_size) i + j]);
  243. acpi_ut_file_printf(file, "%08X", temp32);
  244. ACPI_MOVE_32_TO_32(&temp32,
  245. &buffer[(acpi_size) i + j +
  246. 4]);
  247. acpi_ut_file_printf(file, "%08X ", temp32);
  248. break;
  249. }
  250. j += display;
  251. }
  252. /*
  253. * Print the ASCII equivalent characters but watch out for the bad
  254. * unprintable ones (printable chars are 0x20 through 0x7E)
  255. */
  256. acpi_ut_file_printf(file, " ");
  257. for (j = 0; j < 16; j++) {
  258. if (i + j >= count) {
  259. acpi_ut_file_printf(file, "\n");
  260. return;
  261. }
  262. buf_char = buffer[(acpi_size) i + j];
  263. if (isprint(buf_char)) {
  264. acpi_ut_file_printf(file, "%c", buf_char);
  265. } else {
  266. acpi_ut_file_printf(file, ".");
  267. }
  268. }
  269. /* Done with that line. */
  270. acpi_ut_file_printf(file, "\n");
  271. i += 16;
  272. }
  273. return;
  274. }
  275. #endif