5 #include "barectf-platform-qemu-arm-uart.h"
8 #define TIMER_CTRL_32BIT (1 << 1)
9 #define TIMER_CTRL_ENABLE (1 << 7)
11 volatile uint32_t * const uart0
= (uint32_t *) 0x101f1000;
12 volatile uint32_t * const uart1
= (uint32_t *) 0x101f2000;
13 volatile uint32_t * const timer0_ctrl
= (uint32_t *) 0x101e2008;
14 volatile uint32_t * const timer0_value
= (uint32_t *) 0x101e2004;
16 static struct barectf_default_ctx barectf_ctx
;
18 static uint8_t buf
[BUF_SIZE
];
20 static uint64_t get_clock(void* data
)
22 return (uint64_t) -*timer0_value
;
25 static void flush_packet(void)
29 /* flush packet to UART 1 */
30 for (i
= 0; i
< BUF_SIZE
; ++i
) {
31 *uart1
= (uint32_t) buf
[i
];
35 static int is_backend_full(void *data
)
40 static void open_packet(void *data
)
42 barectf_default_open_packet(&barectf_ctx
);
45 static void close_packet(void *data
)
47 /* close packet now */
48 barectf_default_close_packet(&barectf_ctx
);
50 /* flush current packet */
54 void barectf_platform_qemu_arm_uart_init(void)
56 struct barectf_platform_callbacks cbs
= {
57 .default_clock_get_value
= get_clock
,
58 .is_backend_full
= is_backend_full
,
59 .open_packet
= open_packet
,
60 .close_packet
= close_packet
,
63 /* enable/start timer (clock source) */
64 *timer0_ctrl
|= TIMER_CTRL_32BIT
| TIMER_CTRL_ENABLE
;
66 /* initialize barectf context */
67 barectf_init(&barectf_ctx
, buf
, BUF_SIZE
, cbs
, NULL
);
69 /* open first packet */
72 /* indicate that tracing is starting */
73 puts("tracing: starting");
76 void barectf_platform_qemu_arm_uart_fini(void)
78 /* close last packet if it contains at least one event */
79 if (barectf_packet_is_open(&barectf_ctx
) &&
80 !barectf_packet_is_empty(&barectf_ctx
)) {
84 /* indicate that tracing is done */
85 puts("tracing: done");
88 struct barectf_default_ctx
*barectf_platform_qemu_arm_uart_get_barectf_ctx()
96 /* custom write "syscall" for newlib's stdio: write to UART 0 */
97 int _write(int file
, char *ptr
, int len
) {
98 if (file
== STDOUT
|| file
== STDERR
) {
101 for (i
= 0; i
< len
; i
++) {
102 *uart0
= (uint32_t) ptr
[i
];