source: rtems/c/src/lib/libbsp/i386/shared/io/printk.c @ bd8c8b2a

4.104.114.84.95
Last change on this file since bd8c8b2a was bd8c8b2a, checked in by Joel Sherrill <joel.sherrill@…>, on 08/05/98 at 16:51:39

Patch from Eric Valette <valette@…> which brings the i386ex BSP
inline with the new IRQ structure.

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*-------------------------------------------------------------------------+
2| printk.c v1.1 - PC386 BSP - 1997/08/07
3+--------------------------------------------------------------------------+
4| (C) Copyright 1997 -
5| - NavIST Group - Real-Time Distributed Systems and Industrial Automation
6|
7| http://pandora.ist.utl.pt
8|
9| Instituto Superior Tecnico * Lisboa * PORTUGAL
10+--------------------------------------------------------------------------+
11| Disclaimer:
12|
13| This file is provided "AS IS" without warranty of any kind, either
14| expressed or implied.
15+--------------------------------------------------------------------------+
16| This code is based on code by: Jose Rufino - IST
17|
18|  $Id$
19+--------------------------------------------------------------------------*/
20
21
22#include <stdarg.h>
23
24#include <bspIo.h>
25
26/*-------------------------------------------------------------------------+
27|         Function: printNum
28|      Description: print number in a given base.
29| Global Variables: None.
30|        Arguments: num - number to print, base - base used to print the number.
31|          Returns: Nothing.
32+--------------------------------------------------------------------------*/
33static void
34printNum(long int num, int base)
35{
36  long int n;
37
38  if ((n = num / base) > 0)
39    printNum(n, base);
40  BSP_output_char("0123456789ABCDEF"[(int)(num % base)]);
41} /* printNum */
42
43
44/*-------------------------------------------------------------------------+
45|         Function: printk
46|      Description: a simplified version of printf intended for use when the
47                    console is not yet initialized or in ISR's.
48| Global Variables: None.
49|        Arguments: as in printf: fmt - format string, ... - unnamed arguments.
50|          Returns: Nothing.
51+--------------------------------------------------------------------------*/
52void
53printk(char *fmt, ...)
54{
55  va_list  ap;      /* points to each unnamed argument in turn */
56  char     c, *str;
57  int      lflag, base;
58 
59  va_start(ap, fmt); /* make ap point to 1st unnamed arg */
60  for (; *fmt != '\0'; fmt++)
61  {
62    lflag = 0;
63    base  = 0;
64    if (*fmt == '%')
65    {
66      if ((c = *++fmt) == 'l')
67      {
68        lflag = 1;
69        c = *++fmt;
70      }
71      switch (c)
72      {
73        case 'o': case 'O': base = 8; break;
74        case 'd': case 'D': base = 10; break;
75        case 'x': case 'X': base = 16; break;
76        case 's':
77          for (str = va_arg(ap, char *); *str; str++)
78            BSP_output_char(*str);
79          break;
80        case 'c':
81          BSP_output_char(va_arg(ap, char));
82          break;
83        default:
84          BSP_output_char(c);
85          break;
86      } /* switch*/
87
88      if (base)
89        printNum(lflag ? va_arg(ap, long int) : (long int)va_arg(ap, int),
90                 base);
91    }
92    else
93    {
94      BSP_output_char(*fmt);
95    }
96  }
97  va_end(ap); /* clean up when done */
98} /* printk */
99
Note: See TracBrowser for help on using the repository browser.