]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/arm926ejs/mx28/debug.c
Unified codebase for TX28, TX48, TX51, TX53
[karo-tx-uboot.git] / arch / arm / cpu / arm926ejs / mx28 / debug.c
1 /*
2  * Boot Prep common file
3  *
4  * Copyright 2008-2009 Freescale Semiconductor
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19  */
20
21 #include <stdarg.h>
22 //#include <stdlib.h>
23
24 #include <common.h>
25
26 void printhex(int data)
27 {
28         int i;
29         char c;
30
31         for (i = sizeof(int) * 2 - 1; i >= 0; i--) {
32                 c = data >> (i * 4);
33                 c &= 0xf;
34                 if (c > 9)
35                         serial_putc(c - 10 + 'a');
36                 else
37                         serial_putc(c + '0');
38         }
39 }
40
41 void printdec(int data)
42 {
43         unsigned int m;
44         char str[10] = { 0, };
45         int i;
46
47         if (data == 0) {
48                 serial_putc('0');
49                 return;
50         } else if (data < 0) {
51                 serial_putc('-');
52                 data = -data;
53         }
54         m = data;
55         for (i = 0; m > 0; i++) {
56                 str[i] = m % 10 + '0';
57                 m /= 10;
58         }
59         for (i--; i >= 0; i--) {
60                 serial_putc(str[i]);
61         }
62 }
63
64 void dprintf(const char *fmt, ...)
65 {
66         va_list args;
67         const char *fp = fmt;
68
69         if (!fmt)
70                 return;
71
72         va_start(args, fmt);
73         while (*fp) {
74                 if (*fp == '%') {
75                         fp++;
76                         switch (*fp) {
77                         case 'c':
78                                 serial_putc(va_arg(args, int));
79                                 break;
80
81                         case 's':
82                                 serial_puts(va_arg(args, const char *));
83                                 break;
84
85                         case 'd':
86                         case 'u':
87                         case 'i':
88                                 printdec(va_arg(args, int));
89                                 break;
90
91                         case 'p':
92                                 serial_puts("0x");
93                         case 'x':
94                         case 'X':
95                                 printhex(va_arg(args, int));
96                                 break;
97
98                         case '%':
99                                 serial_putc('%');
100                                 break;
101
102                         default:
103                                 dprintf("\nUnsupported format string token '%c'(%x) in '%s'\n",
104                                         *fp, *fp, fmt);
105                         }
106                 } else {
107                         if (*fp == '\n')
108                                 serial_putc('\r');
109                         serial_putc(*fp);
110                 }
111                 fp++;
112         }
113         va_end(args);
114 }