1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Dump Buffer |
---|
5 | * @ingroup libmisc_dumpbuf Print Memory Buffer |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1997-2007. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may in |
---|
13 | * the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #ifdef HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <stdio.h> |
---|
22 | #include <string.h> |
---|
23 | #include <ctype.h> |
---|
24 | #include <rtems/dumpbuf.h> |
---|
25 | #include <rtems/bspIo.h> |
---|
26 | |
---|
27 | /* |
---|
28 | * Put the body below rtems_print_buffer so it won't get inlined. |
---|
29 | */ |
---|
30 | |
---|
31 | static inline void Dump_Line( |
---|
32 | const unsigned char *buffer, |
---|
33 | int length |
---|
34 | ); |
---|
35 | |
---|
36 | void rtems_print_buffer( |
---|
37 | const unsigned char *buffer, |
---|
38 | int length |
---|
39 | ) |
---|
40 | { |
---|
41 | |
---|
42 | int i, mod, max; |
---|
43 | |
---|
44 | if ( !length ) return; |
---|
45 | |
---|
46 | mod = length % 16; |
---|
47 | |
---|
48 | max = length - mod; |
---|
49 | |
---|
50 | for ( i=0 ; i<max ; i+=16 ) |
---|
51 | Dump_Line( &buffer[ i ], 16 ); |
---|
52 | |
---|
53 | if ( mod ) |
---|
54 | Dump_Line( &buffer[ max ], mod ); |
---|
55 | } |
---|
56 | |
---|
57 | static inline void Dump_Line( |
---|
58 | const unsigned char *buffer, |
---|
59 | int length |
---|
60 | ) |
---|
61 | { |
---|
62 | |
---|
63 | int i; |
---|
64 | char line_buffer[120]; |
---|
65 | |
---|
66 | line_buffer[0] = '\0'; |
---|
67 | |
---|
68 | for( i=0 ; i<length ; i++ ) |
---|
69 | sprintf( line_buffer, "%s%02x ", line_buffer, buffer[ i ] ); |
---|
70 | |
---|
71 | for( ; i<16 ; i++ ) |
---|
72 | strcat( line_buffer, " " ); |
---|
73 | |
---|
74 | strcat( line_buffer, "|" ); |
---|
75 | for( i=0 ; i<length ; i++ ) |
---|
76 | sprintf( line_buffer, "%s%c", line_buffer, |
---|
77 | isprint( buffer[ i ] ) ? buffer[ i ] : '.' ); |
---|
78 | |
---|
79 | for( ; i<16 ; i++ ) |
---|
80 | strcat( line_buffer, " " ); |
---|
81 | |
---|
82 | strcat( line_buffer, "|\n" ); |
---|
83 | |
---|
84 | printk( line_buffer ); |
---|
85 | } |
---|