]>
git.proxmox.com Git - mirror_edk2.git/blob - QuarkSocPkg/QuarkNorthCluster/MemoryInit/Pei/lprint.c
2 Serial conole output and string formating.
4 Copyright (c) 2013-2015 Intel Corporation.
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "memory_options.h"
16 #include "general_definitions.h"
18 // Resource programmed to PCI bridge, 1MB bound alignment is needed.
19 // The default value is overwritten by MRC parameter, assuming code
20 // relocated to eSRAM.
21 uint32_t UartMmioBase
= 0;
23 // Serial port registers based on SerialPortLib.c
24 #define R_UART_BAUD_THR 0
27 #define B_UART_LSR_RXRDY BIT0
28 #define B_UART_LSR_TXRDY BIT5
29 #define B_UART_LSR_TEMT BIT6
31 // Print mask see DPF and D_Xxxx
32 #define DPF_MASK DpfPrintMask
34 // Select class of messages enabled for printing
35 uint32_t DpfPrintMask
=
45 // Don't generate debug code
46 void dpf( uint32_t mask
, char_t
* bla
, ...)
64 // Use Vpi console in simulation environment
67 void dpf( uint32_t mask
, char_t
* bla
, ...)
71 if( 0 == (mask
& DPF_MASK
)) return;
74 vpi_vprintf( bla
, va
);
81 // Use standard console in windows environment
85 // Read character from serial port
90 // Emulation in Windows environment uses console
96 while ((*(volatile uint8_t*) (UartMmioBase
+ R_UART_LSR
) & B_UART_LSR_RXRDY
) == 0);
97 c
= *(volatile uint8_t*) (UartMmioBase
+ R_UART_BAUD_THR
);
111 if((*(volatile uint8_t*) (UartMmioBase
+ R_UART_LSR
) & B_UART_LSR_RXRDY
) != 0)
113 c
= *(volatile uint8_t*) (UartMmioBase
+ R_UART_BAUD_THR
);
120 // Print single character
126 // Emulation in Windows environment uses console output
132 // Use MMIO access to serial port on PCI
133 // while( 0 == (0x20 & inp(0x3f8 + 5)));
134 // outp(0x3f8 + 0, c);
137 == (B_UART_LSR_TEMT
& *((volatile uint8_t*) (UartMmioBase
+ R_UART_LSR
))))
139 *((volatile uint8_t*) (UartMmioBase
+ R_UART_BAUD_THR
)) = c
;
143 // Print 0 terminated string on serial console
144 static void printstr(
152 // Print 64bit number as hex string on serial console
153 // the width parameters allows skipping leading zeros
154 static void printhexx(
162 // 64bit number has 16 characters in hex representation
163 for (i
= 16; i
> 0; i
--)
165 c
= *(((uint8_t *)&val
) + ((i
- 1) >> 1));
166 if (((i
- 1) & 1) != 0)
177 // end of leading zeros
181 // don't print leading zero
182 if (!empty
|| i
<= width
)
188 // Print 32bit number as hex string on serial console
189 // the width parameters allows skipping leading zeros
190 static void printhex(
198 // 32bit number has 8 characters in hex representation
199 for (i
= 8; i
> 0; i
--)
201 c
= (uint8_t) ((val
>> 28) & 0x0F);
211 // end of leading zeros
215 // don't print leading zero
216 if (!empty
|| i
<= width
)
222 // Print 32bit number as decimal string on serial console
223 // the width parameters allows skipping leading zeros
224 static void printdec(
232 // Ten digits is enough for 32bit number in decimal
235 for (i
= 0; i
< sizeof(buf
); i
++)
237 c
= (uint8_t) (val
% 10);
248 // end of leading zeros
252 // don't print leading zero
253 if (!empty
|| i
< width
)
260 // Consume numeric substring leading the given string
261 // Return pointer to the first non-numeric character
262 // Buffer reference by width is updated with number
263 // converted from the numeric substring.
264 static char_t
*getwidth(
270 while (*bla
>= '0' && *bla
<= '9')
272 val
= val
* 10 + *bla
- '0';
283 // Consume print format designator from the head of given string
284 // Return pointer to first character after format designator
291 static char_t
*getformat(
300 else if (bla
[0] == 'd')
305 else if (bla
[0] == 'X' || bla
[0] == 'x')
310 else if (bla
[0] == 'l' && bla
[1] == 'l' && bla
[2] == 'X')
319 // Simplified implementation of standard printf function
320 // The output is directed to serial console. Only selected
321 // class of messages is printed (mask has to match DpfPrintMask)
322 // Supported print formats: %[n]s,%[n]d,%[n]X,,%[n]llX
323 // The width is ignored for %s format.
329 uint32_t* arg
= (uint32_t*) (&bla
+ 1);
331 // Check UART MMIO base configured
332 if (0 == UartMmioBase
)
335 // Check event not masked
336 if (0 == (mask
& DPF_MASK
))
355 bla
= getwidth(bla
, &width
);
356 bla
= getformat(bla
, &fmt
);
361 printdec(*arg
, width
);
366 printhex(*arg
, width
);
371 printhexx(*(uint64_t*) arg
, width
);
376 printstr(*(char**) arg
);