summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/sparc/leon3/console/debugprintf.c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2006-04-24 16:58:41 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2006-04-24 16:58:41 +0000
commitcadb5d1641059adb5bbef5900e2cefee653f2b74 (patch)
tree6353a9fe2f02c1b89b69e6cf55eef27d24710ce7 /c/src/lib/libbsp/sparc/leon3/console/debugprintf.c
parent2006-04-24 Joel Sherrill <joel@OARcorp.com> (diff)
downloadrtems-cadb5d1641059adb5bbef5900e2cefee653f2b74.tar.bz2
2006-04-24 Jiri Gaisler <jiri@gaisler.com>
Edvin Catovic <edvin@gaisler.com> PR bsps/972 * ChangeLog, Makefile.am, configure.ac, amba/amba.c, clock/ckinit.c, console/Makefile.am, console/console.c, console/debugputs.c, include/Makefile.am, include/amba.h, include/bsp.h, include/leon.h, leon_smc91111/leon_smc91111.c, startup/bspstart.c, timer/timer.c, tools/Makefile.am, wrapup/Makefile.am: Added Shared Memory Support Driver. Added Leon Gaisler Research Ethernet support. Enhanced AMBA bus support. * console/debugprintf.c, console/spacewire.c, include/spacewire.h, leon_greth/.cvsignore, leon_greth/Makefile.am, leon_greth/leon_greth.c, shmsupp/.cvsignore, shmsupp/Makefile.am, shmsupp/addrconv.c, shmsupp/getcfg.c, shmsupp/lock.c, shmsupp/mpisr.c: New files.
Diffstat (limited to 'c/src/lib/libbsp/sparc/leon3/console/debugprintf.c')
-rw-r--r--c/src/lib/libbsp/sparc/leon3/console/debugprintf.c180
1 files changed, 180 insertions, 0 deletions
diff --git a/c/src/lib/libbsp/sparc/leon3/console/debugprintf.c b/c/src/lib/libbsp/sparc/leon3/console/debugprintf.c
new file mode 100644
index 0000000000..39d80d0cf6
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/leon3/console/debugprintf.c
@@ -0,0 +1,180 @@
+/*
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * Modified for LEON3 BSP.
+ * COPYRIGHT (c) 2004.
+ * Gaisler Research.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <bsp.h>
+#include <rtems/libio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <stdarg.h>
+
+static size_t lo_strnlen(const char * s, size_t count)
+{
+ const char *sc;
+
+ for (sc = s; count-- && *sc != '\0'; ++sc)
+ /* nothing */;
+ return sc - s;
+}
+
+static int lo_vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
+{
+ int len;
+ unsigned long long num;
+ int i,j,n;
+ char *str, *end, c;
+ const char *s;
+ int flags;
+ int field_width;
+ int precision;
+ int qualifier;
+
+ str = buf;
+ end = buf + size - 1;
+
+ if (end < buf - 1) {
+ end = ((void *) -1);
+ size = end - buf + 1;
+ }
+
+ for (; *fmt ; ++fmt) {
+ if (*fmt != '%') {
+ if (str <= end)
+ *str = *fmt;
+ ++str;
+ continue;
+ }
+
+ /* process flags */
+ flags = 0;
+ /* get field width */
+ field_width = -1;
+ /* get the precision */
+ precision = -1;
+ /* get the conversion qualifier */
+ qualifier = 'l';
+
+ ++fmt;
+ /* default base */
+ switch (*fmt) {
+ case 'c':
+ c = (unsigned char) va_arg(args, int);
+ if (str <= end)
+ *str = c;
+ ++str;
+ while (--field_width > 0) {
+ if (str <= end)
+ *str = ' ';
+ ++str;
+ }
+ continue;
+
+ case 's':
+ s = va_arg(args, char *);
+ if (!s)
+ s = "<NULL>";
+
+ len = lo_strnlen(s, precision);
+
+ for (i = 0; i < len; ++i) {
+ if (str <= end)
+ *str = *s;
+ ++str; ++s;
+ }
+ while (len < field_width--) {
+ if (str <= end)
+ *str = ' ';
+ ++str;
+ }
+ continue;
+
+
+ case '%':
+ if (str <= end)
+ *str = '%';
+ ++str;
+ continue;
+
+ case 'x':
+ break;
+
+ default:
+ if (str <= end)
+ *str = '%';
+ ++str;
+ if (*fmt) {
+ if (str <= end)
+ *str = *fmt;
+ ++str;
+ } else {
+ --fmt;
+ }
+ continue;
+ }
+ num = va_arg(args, unsigned long);
+ for (j=0,i=0;i<8 && str <= end;i++) {
+ if ( (n = ((unsigned long)(num & (0xf0000000ul>>(i*4)))) >> ((7-i)*4)) || j != 0) {
+ j = 1;
+ if (n >= 10)
+ n += 'a'-10;
+ else
+ n += '0';
+ *str = n;
+ ++str;
+ }
+ }
+ if (j == 0 && str <= end) {
+ *str = '0';
+ ++str;
+ }
+ }
+ if (str <= end)
+ *str = '\0';
+ else if (size > 0)
+ /* don't write out a null byte if the buf size is zero */
+ *end = '\0';
+ /* the trailing null byte doesn't count towards the total
+ * ++str;
+ */
+ return str-buf;
+}
+
+int DEBUG_sprintf(char *buf, size_t size, const char *fmt, ...) {
+ va_list args;
+ int printed_len;
+
+ va_start(args, fmt);
+ printed_len = lo_vsnprintf(buf, size, fmt, args);
+ va_end(args);
+ return printed_len;
+}
+
+int scan_uarts();
+void DEBUG_puts( char *string );
+int DEBUG_printf(const char *fmt, ...)
+{
+ va_list args;
+ int printed_len;
+ char printk_buf[1024+1];
+
+ /* Emit the output into the temporary buffer */
+ va_start(args, fmt);
+ printed_len = lo_vsnprintf(printk_buf, sizeof(printk_buf)-1, fmt, args);
+ printk_buf[printed_len] = 0;
+ va_end(args);
+
+ scan_uarts();
+ /*DEBUG_puts(printk_buf);*/
+ return printed_len;
+}