Updates to Freedom SoCs
[freedom-sifive.git] / bootrom / sdboot / kprintf.h
1 // See LICENSE for license details.
2 #ifndef _SDBOOT_KPRINTF_H
3 #define _SDBOOT_KPRINTF_H
4
5 #include <platform.h>
6 #include <stdint.h>
7
8 #define REG32(p, i) ((p)[(i) >> 2])
9
10 #ifndef UART_CTRL_ADDR
11 #ifndef UART_NUM
12 #define UART_NUM 0
13 #endif
14
15 #define _CONCAT3(A, B, C) A ## B ## C
16 #define _UART_CTRL_ADDR(UART_NUM) _CONCAT3(UART, UART_NUM, _CTRL_ADDR)
17 #define UART_CTRL_ADDR _UART_CTRL_ADDR(UART_NUM)
18 #endif
19 static volatile uint32_t * const uart = (void *)(UART_CTRL_ADDR);
20
21 static inline void kputc(char c)
22 {
23 volatile uint32_t *tx = &REG32(uart, UART_REG_TXFIFO);
24 #ifdef __riscv_atomic
25 int32_t r;
26 do {
27 __asm__ __volatile__ (
28 "amoor.w %0, %2, %1\n"
29 : "=r" (r), "+A" (*tx)
30 : "r" (c));
31 } while (r < 0);
32 #else
33 while ((int32_t)(*tx) < 0);
34 *tx = c;
35 #endif
36 }
37
38 extern void kputs(const char *);
39 extern void kprintf(const char *, ...);
40
41 #ifdef DEBUG
42 #define dprintf(s, ...) kprintf((s), ##__VA_ARGS__)
43 #define dputs(s) kputs((s))
44 #else
45 #define dprintf(s, ...) do { } while (0)
46 #define dputs(s) do { } while (0)
47 #endif
48
49 #endif /* _SDBOOT_KPRINTF_H */