summaryrefslogtreecommitdiffstats
path: root/cpukit/libmisc/dumpbuf
diff options
context:
space:
mode:
Diffstat (limited to 'cpukit/libmisc/dumpbuf')
-rw-r--r--cpukit/libmisc/dumpbuf/dumpbuf.c80
-rw-r--r--cpukit/libmisc/dumpbuf/dumpbuf.h39
2 files changed, 119 insertions, 0 deletions
diff --git a/cpukit/libmisc/dumpbuf/dumpbuf.c b/cpukit/libmisc/dumpbuf/dumpbuf.c
new file mode 100644
index 0000000000..97274ecbaa
--- /dev/null
+++ b/cpukit/libmisc/dumpbuf/dumpbuf.c
@@ -0,0 +1,80 @@
+/*
+ * COPYRIGHT (c) 1997-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may in
+ * the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <rtems/dumpbuf.h>
+#include <rtems/bspIo.h>
+
+/*
+ * Put the body below rtems_print_buffer so it won't get inlined.
+ */
+
+static inline void Dump_Line(
+ const unsigned char *buffer,
+ int length
+);
+
+void rtems_print_buffer(
+ const unsigned char *buffer,
+ int length
+)
+{
+
+ int i, mod, max;
+
+ if ( !length ) return;
+
+ mod = length % 16;
+
+ max = length - mod;
+
+ for ( i=0 ; i<max ; i+=16 )
+ Dump_Line( &buffer[ i ], 16 );
+
+ if ( mod )
+ Dump_Line( &buffer[ max ], mod );
+}
+
+static inline void Dump_Line(
+ const unsigned char *buffer,
+ int length
+)
+{
+
+ int i;
+ char line_buffer[120];
+
+ line_buffer[0] = '\0';
+
+ for( i=0 ; i<length ; i++ )
+ sprintf( line_buffer, "%s%02x ", line_buffer, buffer[ i ] );
+
+ for( ; i<16 ; i++ )
+ strcat( line_buffer, " " );
+
+ strcat( line_buffer, "|" );
+ for( i=0 ; i<length ; i++ )
+ sprintf( line_buffer, "%s%c", line_buffer,
+ isprint( buffer[ i ] ) ? buffer[ i ] : '.' );
+
+ for( ; i<16 ; i++ )
+ strcat( line_buffer, " " );
+
+ strcat( line_buffer, "|\n" );
+
+ printk( line_buffer );
+}
diff --git a/cpukit/libmisc/dumpbuf/dumpbuf.h b/cpukit/libmisc/dumpbuf/dumpbuf.h
new file mode 100644
index 0000000000..3502ace70a
--- /dev/null
+++ b/cpukit/libmisc/dumpbuf/dumpbuf.h
@@ -0,0 +1,39 @@
+/*
+ * COPYRIGHT (c) 1997-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may in
+ * the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef __DUMP_BUFFER_h
+#define __DUMP_BUFFER_h
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Print Memory Buffer
+ *
+ * This method prints @a length bytes beginning at @a buffer in
+ * a nice format similar to what one would expect from a debugger
+ * or ROM monitor.
+ *
+ * @param[in] buffer is the address of the buffer
+ * @param[in] length is the length of the buffer
+ */
+void rtems_print_buffer(
+ const unsigned char *buffer,
+ int length
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */