Software APIs
dbg_print.h
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #ifndef OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_DBG_PRINT_H_
6 #define OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_DBG_PRINT_H_
7 
9 #include "sw/device/silicon_creator/lib/error.h"
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif // __cplusplus
14 
15 /**
16  * An intentionally pared-down implementation of `printf()` that writes
17  * to UART0.
18  *
19  * This function only supports the format specifiers required by the
20  * ROM:
21  * - %c prints a single character.
22  * - %C prints a 'FourCC' style uint32_t (ASCII bytes in little-endian order).
23  * - %d prints a signed int in decimal.
24  * - %u prints an unsigned int in decimal.
25  * - %s prints a nul-terminated string.
26  * - %p prints pointer in hexadecimal.
27  * - %x prints an `unsigned int` in hexadecimal using lowercase characters.
28  *
29  * No modifiers are supported and the leading zeros in hexidecimal
30  * values are always printed.
31  *
32  * Note: unfortunately `uint32_t` is not necessarily an alias for
33  * `unsigned int`. An explicit cast is therefore necessary when printing
34  * `uint32_t` values using the `%x` format specifier in order to satisfy
35  * the `printf` format checker (`-Wformat`).
36  *
37  * @param format The format specifier.
38  * @param ... The values to interpolate in the format.
39  * @return The result of the operation.
40  */
41 void dbg_printf(const char *format, ...) __attribute__((format(printf, 1, 2)));
42 
43 /**
44  * Print the string to the console.
45  *
46  * Note: `dbg_puts` will NOT output an additional newline character '\n' after
47  * `str`, unlike the standard C puts.
48  */
49 void dbg_puts(const char *str);
50 
51 /**
52  * Print the ePMP configuration to the console.
53  */
54 void dbg_print_epmp(void);
55 
56 /**
57  * Hexdump a region of memory.
58  *
59  * @param data The memory to dump.
60  * @param len The length of the region to dump.
61  */
62 void dbg_hexdump(const void *data, size_t len);
63 
64 #ifdef __cplusplus
65 } // extern "C"
66 #endif // __cplusplus
67 
68 #endif // OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_DBG_PRINT_H_