blob: 2caf8c4736868ef6027100ba809c95f07cd5c84f [file] [log] [blame]
Cindy Liu43879e42023-10-18 11:18:03 -07001/*
2 * Copyright 2023 Google LLC
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Lun Dong570bafc2023-07-19 15:03:09 -070016// Kelvin logging helper header
17
18#ifndef CRT_LOG_H_
19#define CRT_LOG_H_
20
21#include <stdio.h>
22
23#define LOG_MAX_SZ 256
24
25static inline void kelvin_simprint(const char *_string) {
26 __asm__ volatile("flog %0 \n\t" : : "r"(_string));
27}
28
29#define SIMLOG(fmt, ...) \
30 do { \
31 char tmp_log_msg[LOG_MAX_SZ]; \
32 snprintf(tmp_log_msg, LOG_MAX_SZ, fmt, __VA_ARGS__); \
33 kelvin_simprint(tmp_log_msg); \
34 } while (0)
35
36#define LOG_ERROR(msg, args...) SIMLOG("%s |" msg "\n", "ERROR", ##args)
37#define LOG_WARN(msg, args...) SIMLOG("%s |" msg "\n", "WARN", ##args)
38#define LOG_INFO(msg, args...) SIMLOG("%s |" msg "\n", "INFO", ##args)
39#define LOG_DEBUG(msg, args...) SIMLOG("%s |" msg "\n", "DEBUG", ##args)
40#define LOG_NOISY(msg, args...) SIMLOG("%s |" msg "\n", "NOISY", ##args)
41
42#endif // CRT_LOG_H_