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