]> wirehaze git hosting - ppos.git/blob - ppos/kernel/macros.h

wirehaze git hosting

add ppos/
[ppos.git] / ppos / kernel / macros.h
1 // PingPongOS - PingPong Operating System
2 // Prof. Carlos A. Maziero, DINF UFPR
3 // Versão 2.0 -- Junho de 2025
4
5 // ATENÇÃO: ESTE ARQUIVO NÃO DEVE SER ALTERADO;
6 // ALTERAÇÕES SERÃO DESCARTADAS NA CORREÇÃO.
7
8 #ifndef __MACROS__
9 #define __MACROS__
10
11 // este código deve ser compilado em sistemas UNIX-like
12 #ifndef __linux__
13 #error "Este codigo foi planejado para ambientes Linux."
14 #endif
15
16 #include <hardware/cpu.h>
17 #include "lib/libc.h"
18
19 // códigos de cor ANSI (terminal)
20 #define FONT_NORMAL "\x1B[0m"
21 #define FONT_BLACK "\x1B[30m"
22 #define FONT_RED "\x1B[31m"
23 #define FONT_GREEN "\x1B[32m"
24 #define FONT_YELLOW "\x1B[33m"
25 #define FONT_BLUE "\x1B[34m"
26 #define FONT_MAGENTA "\x1B[35m"
27 #define FONT_CYAN "\x1B[36m"
28 #define FONT_WHITE "\x1B[37m"
29 #define BACK_BLACK "\x1B[40m"
30 #define BACK_RED "\x1B[41m"
31 #define BACK_GREEN "\x1B[42m"
32 #define BACK_YELLOW "\x1B[43m"
33 #define BACK_BLUE "\x1B[44m"
34 #define BACK_MAGENTA "\x1B[45m"
35 #define BACK_CYAN "\x1B[46m"
36 #define BACK_WHITE "\x1B[47m"
37
38 // Imprime mensagem de depuração se DEBUG estiver definido;
39 // Uso igual ao printf: ppos_debug(format, arg1, arg2, ...)
40 #ifdef DEBUG
41 #define ppos_debug(...) \
42 do \
43 { \
44 printf(FONT_CYAN "DEBUG: "); \
45 printf(__VA_ARGS__); \
46 printf(FONT_NORMAL); \
47 } while (0)
48 #else
49 #define ppos_debug(...) // não faz nada
50 #endif
51
52 // Imprime mensagem de aviso, com arquivo e linha do código.
53 // Uso igual ao printf: ppos_warn(format, arg1, arg2, ...)
54 #define ppos_warn(...) \
55 do \
56 { \
57 printf(BACK_YELLOW "WARN (%s:%d)" FONT_NORMAL ": ", \
58 __FILE__, __LINE__); \
59 printf(__VA_ARGS__); \
60 } while (0)
61
62 // Imprime mensagem de erro com arquivo e linha do código e encerra.
63 // Uso igual ao printf: ppos_panic(format, arg1, arg2, ...)
64 #define ppos_panic(...) \
65 do \
66 { \
67 printf(BACK_RED "PANIC (%s:%d)" FONT_NORMAL ": ", \
68 __FILE__, __LINE__); \
69 printf(__VA_ARGS__); \
70 hw_poweroff(1); \
71 } while (0)
72
73 // Testa parâmetros de funções, imprime e retorna erro.
74 // Uso: check_parm(value < 0, "invalid value", NULL);
75 #define check_parm(error_cond, error_msg, ret_val) \
76 if (error_cond) \
77 { \
78 printf(BACK_YELLOW); \
79 printf("Error in %s():", __func__); \
80 printf(FONT_NORMAL); \
81 printf(" %s\n", error_msg); \
82 return ret_val; \
83 }
84
85 #endif