]>
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 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "memory_options.h"
10 #include "general_definitions.h"
12 // Resource programmed to PCI bridge, 1MB bound alignment is needed.
13 // The default value is overwritten by MRC parameter, assuming code
14 // relocated to eSRAM.
15 uint32_t UartMmioBase
= 0;
17 // Serial port registers based on SerialPortLib.c
18 #define R_UART_BAUD_THR 0
21 #define B_UART_LSR_RXRDY BIT0
22 #define B_UART_LSR_TXRDY BIT5
23 #define B_UART_LSR_TEMT BIT6
25 // Print mask see DPF and D_Xxxx
26 #define DPF_MASK DpfPrintMask
28 // Select class of messages enabled for printing
29 uint32_t DpfPrintMask
=
39 // Don't generate debug code
40 void dpf( uint32_t mask
, char_t
* bla
, ...)
58 // Use Vpi console in simulation environment
61 void dpf( uint32_t mask
, char_t
* bla
, ...)
65 if( 0 == (mask
& DPF_MASK
)) return;
68 vpi_vprintf( bla
, va
);
75 // Use standard console in windows environment
79 // Read character from serial port
84 // Emulation in Windows environment uses console
90 while ((*(volatile uint8_t*) (UartMmioBase
+ R_UART_LSR
) & B_UART_LSR_RXRDY
) == 0);
91 c
= *(volatile uint8_t*) (UartMmioBase
+ R_UART_BAUD_THR
);
105 if((*(volatile uint8_t*) (UartMmioBase
+ R_UART_LSR
) & B_UART_LSR_RXRDY
) != 0)
107 c
= *(volatile uint8_t*) (UartMmioBase
+ R_UART_BAUD_THR
);
114 // Print single character
120 // Emulation in Windows environment uses console output
126 // Use MMIO access to serial port on PCI
127 // while( 0 == (0x20 & inp(0x3f8 + 5)));
128 // outp(0x3f8 + 0, c);
131 == (B_UART_LSR_TEMT
& *((volatile uint8_t*) (UartMmioBase
+ R_UART_LSR
))))
133 *((volatile uint8_t*) (UartMmioBase
+ R_UART_BAUD_THR
)) = c
;
137 // Print 0 terminated string on serial console
138 static void printstr(
146 // Print 64bit number as hex string on serial console
147 // the width parameters allows skipping leading zeros
148 static void printhexx(
156 // 64bit number has 16 characters in hex representation
157 for (i
= 16; i
> 0; i
--)
159 c
= *(((uint8_t *)&val
) + ((i
- 1) >> 1));
160 if (((i
- 1) & 1) != 0)
171 // end of leading zeros
175 // don't print leading zero
176 if (!empty
|| i
<= width
)
182 // Print 32bit number as hex string on serial console
183 // the width parameters allows skipping leading zeros
184 static void printhex(
192 // 32bit number has 8 characters in hex representation
193 for (i
= 8; i
> 0; i
--)
195 c
= (uint8_t) ((val
>> 28) & 0x0F);
205 // end of leading zeros
209 // don't print leading zero
210 if (!empty
|| i
<= width
)
216 // Print 32bit number as decimal string on serial console
217 // the width parameters allows skipping leading zeros
218 static void printdec(
226 // Ten digits is enough for 32bit number in decimal
229 for (i
= 0; i
< sizeof(buf
); i
++)
231 c
= (uint8_t) (val
% 10);
242 // end of leading zeros
246 // don't print leading zero
247 if (!empty
|| i
< width
)
254 // Consume numeric substring leading the given string
255 // Return pointer to the first non-numeric character
256 // Buffer reference by width is updated with number
257 // converted from the numeric substring.
258 static char_t
*getwidth(
264 while (*bla
>= '0' && *bla
<= '9')
266 val
= val
* 10 + *bla
- '0';
277 // Consume print format designator from the head of given string
278 // Return pointer to first character after format designator
285 static char_t
*getformat(
294 else if (bla
[0] == 'd')
299 else if (bla
[0] == 'X' || bla
[0] == 'x')
304 else if (bla
[0] == 'l' && bla
[1] == 'l' && bla
[2] == 'X')
313 // Simplified implementation of standard printf function
314 // The output is directed to serial console. Only selected
315 // class of messages is printed (mask has to match DpfPrintMask)
316 // Supported print formats: %[n]s,%[n]d,%[n]X,,%[n]llX
317 // The width is ignored for %s format.
323 uint32_t* arg
= (uint32_t*) (&bla
+ 1);
325 // Check UART MMIO base configured
326 if (0 == UartMmioBase
)
329 // Check event not masked
330 if (0 == (mask
& DPF_MASK
))
349 bla
= getwidth(bla
, &width
);
350 bla
= getformat(bla
, &fmt
);
355 printdec(*arg
, width
);
360 printhex(*arg
, width
);
365 printhexx(*(uint64_t*) arg
, width
);
370 printstr(*(char**) arg
);