Skip to content

Commit

Permalink
CM: Debug functions & types start with 'CM'
Browse files Browse the repository at this point in the history
This is to differentiate similarly named functions in the kernel.
  • Loading branch information
coderarjob committed Nov 30, 2024
1 parent 7c7c01c commit 72ba30c
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 36 deletions.
40 changes: 22 additions & 18 deletions include/cm/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,28 @@
#pragma once

#if defined(DEBUG) && defined(PORT_E9_ENABLED)
typedef enum DebugLogType {
DEBUG_LOG_TYPE_INFO,
DEBUG_LOG_TYPE_FUNC,
DEBUG_LOG_TYPE_ERROR,
DEBUG_LOG_TYPE_WARN,
} DebugLogType;
typedef enum CM_DebugLogType {
CM_DEBUG_LOG_TYPE_INFO,
CM_DEBUG_LOG_TYPE_FUNC,
CM_DEBUG_LOG_TYPE_ERROR,
CM_DEBUG_LOG_TYPE_WARN,
} CM_DebugLogType;

void debug_log_ndu (DebugLogType type, const char* func, UINT line, char* fmt, ...);
void cm_debug_log_ndu (CM_DebugLogType type, const char* func, UINT line, char* fmt, ...);

#define INFO(...) debug_log_ndu (DEBUG_LOG_TYPE_INFO, __func__, __LINE__, __VA_ARGS__)
#define ERROR(...) debug_log_ndu (DEBUG_LOG_TYPE_ERROR, __func__, __LINE__, __VA_ARGS__)
#define FUNC_ENTRY(...) debug_log_ndu (DEBUG_LOG_TYPE_FUNC, __func__, __LINE__, "" __VA_ARGS__)
#define WARN(...) debug_log_ndu (DEBUG_LOG_TYPE_WARN, __func__, __LINE__, __VA_ARGS__)
#define CM_DBG_INFO(...) \
cm_debug_log_ndu (CM_DEBUG_LOG_TYPE_INFO, __func__, __LINE__, __VA_ARGS__)
#define CM_DBG_ERROR(...) \
cm_debug_log_ndu (CM_DEBUG_LOG_TYPE_ERROR, __func__, __LINE__, __VA_ARGS__)
#define CM_DBG_FUNC_ENTRY(...) \
cm_debug_log_ndu (CM_DEBUG_LOG_TYPE_FUNC, __func__, __LINE__, "" __VA_ARGS__)
#define CM_DBG_WARN(...) \
cm_debug_log_ndu (CM_DEBUG_LOG_TYPE_WARN, __func__, __LINE__, __VA_ARGS__)
#else
#define INFO(...) (void)0
#define ERROR(...) (void)0
#define FUNC_ENTRY(...) (void)0
#define WARN(...) (void)0
#define CM_DBG_INFO(...) (void)0
#define CM_DBG_ERROR(...) (void)0
#define CM_DBG_FUNC_ENTRY(...) (void)0
#define CM_DBG_WARN(...) (void)0
#endif // PORT_E9_ENABLED

#if defined(DEBUG)
Expand All @@ -33,10 +37,10 @@
*
* @return Nothing
**************************************************************************************************/
#define bochs_breakpoint() __asm__ volatile("xchg bx, bx")
#define cm_debug_bochs_breakpoint() __asm__ volatile("xchg bx, bx")

#if ARCH == x86
#define x86_outb(p, v) __asm__ volatile("out dx, al;" : : "a"(v), "d"(p))
#define x86_inb(p, v) __asm__ volatile("in al, dx" : "=a"(v) : "d"(p))
#define cm_debug_x86_outb(p, v) __asm__ volatile("out dx, al;" : : "a"(v), "d"(p))
#define cm_debug_x86_inb(p, v) __asm__ volatile("in al, dx" : "=a"(v) : "d"(p))
#endif
#endif // DEBUG
10 changes: 5 additions & 5 deletions include/cm/err.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ static inline uint32_t cm_get_os_error()
}

/* Can be used to store an error code and return from a function */
#define CM_RETURN_ERROR__(errno, rval) \
do { \
ERROR ("Error %x.", errno); \
cm_error_num__ = errno; \
return rval; \
#define CM_RETURN_ERROR__(errno, rval) \
do { \
CM_DBG_ERROR ("Error %x.", errno); \
cm_error_num__ = errno; \
return rval; \
} while (0)
4 changes: 2 additions & 2 deletions src/apps/gui0.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ static OSIF_WindowFrameBufferInfo createWindow (const char* const title)
{
Handle h = cm_window_create (title);
if (h == INVALID_HANDLE) {
ERROR ("Window creation failed");
CM_DBG_ERROR ("Window creation failed");
HALT();
}

OSIF_WindowFrameBufferInfo fbi;
if (!cm_window_getFB (h, &fbi)) {
ERROR ("Window creation failed");
CM_DBG_ERROR ("Window creation failed");
HALT();
}

Expand Down
2 changes: 1 addition & 1 deletion src/cm/cm.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void event_handler_NDU_()
cm_process_yield();
break;
case OSIF_PROCESS_EVENT_PROCCESS_CHILD_KILLED:
INFO ("Child exitted with code: %x", e.data);
CM_DBG_INFO ("Child exitted with code: %x", e.data);
break;
case OSIF_PROCESS_EVENT_NONE:
break;
Expand Down
12 changes: 6 additions & 6 deletions src/cm/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static void qemu_putString (const CHAR* string)
CHAR c;
while ((c = *string++)) {
#if ARCH == x86
x86_outb (0xE9, c);
cm_debug_x86_outb (0xE9, c);
#else
#error "Not implemented"
#endif
Expand All @@ -42,27 +42,27 @@ static void qemu_putString (const CHAR* string)
*
* @return Nothing
**************************************************************************************************/
void debug_log_ndu (DebugLogType type, const char* func, UINT line, char* fmt, ...)
void cm_debug_log_ndu (CM_DebugLogType type, const char* func, UINT line, char* fmt, ...)
{
int len = 0;
char buffer[MAX_PRINTABLE_STRING_LENGTH];
char* message = NULL;
char* logColor = ANSI_COL_RESET;

switch (type) {
case DEBUG_LOG_TYPE_INFO: {
case CM_DEBUG_LOG_TYPE_INFO: {
message = "\n %s[%u][MLC][ INFO ]%s %s:%u %s|";
logColor = ANSI_COL_GREEN;
} break;
case DEBUG_LOG_TYPE_FUNC: {
case CM_DEBUG_LOG_TYPE_FUNC: {
message = "\n%s[%u][MLC]%s[ %s:%u ]%s|";
logColor = ANSI_COL_YELLOW;
} break;
case DEBUG_LOG_TYPE_ERROR: {
case CM_DEBUG_LOG_TYPE_ERROR: {
message = "\n %s[%u][MLC][ ERROR ]%s %s:%u %s|";
logColor = ANSI_COL_RED;
} break;
case DEBUG_LOG_TYPE_WARN: {
case CM_DEBUG_LOG_TYPE_WARN: {
message = "\n %s[%u][MLC][ WARN ]%s %s:%u %s|";
logColor = ANSI_COL_YELLOW;
} break;
Expand Down
8 changes: 4 additions & 4 deletions src/cm/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ typedef RGBColor32Bits GxColor;

void graphics_blit (const GraphicsContext* destg, UINT x, UINT y, const GraphicsContext* srcg)
{
FUNC_ENTRY ("area: %px, x: %u, y: %u, src area: %px", destg, x, y, srcg);
CM_DBG_FUNC_ENTRY ("area: %px, x: %u, y: %u, src area: %px", destg, x, y, srcg);

// k_assert (destg->bytesPerPixel == srcg->bytesPerPixel, "Graphics area mismatch");

Expand All @@ -64,7 +64,7 @@ void graphics_blit (const GraphicsContext* destg, UINT x, UINT y, const Graphics
void graphics_image_ppm (const GraphicsContext* g, UINT x, UINT y, UINT w, UINT h,
UINT bytesPerPixel, U8* bytes)
{
FUNC_ENTRY ("area: %px, x: %u, y: %u, w: %u, h: %u, bytes: %px", g, x, y, w, h, bytes);
CM_DBG_FUNC_ENTRY ("area: %px, x: %u, y: %u, w: %u, h: %u, bytes: %px", g, x, y, w, h, bytes);

SIZE bytesPerRow = g->bytesPerRow;
U8* start = (U8*)g->buffer + (y * bytesPerRow) + (x * g->bytesPerPixel);
Expand All @@ -89,7 +89,7 @@ void graphics_image_ppm (const GraphicsContext* g, UINT x, UINT y, UINT w, UINT

void graphics_putpixel (const GraphicsContext* g, UINT x, UINT y, Color color)
{
FUNC_ENTRY ("area: %px, x: %u, y: %u, color: %x", g, x, y, color);
CM_DBG_FUNC_ENTRY ("area: %px, x: %u, y: %u, color: %x", g, x, y, color);

GxColor* start = (GxColor*)(g->buffer + (y * g->bytesPerRow) + (x * g->bytesPerPixel));
GxColor* col = (GxColor*)&color;
Expand All @@ -98,7 +98,7 @@ void graphics_putpixel (const GraphicsContext* g, UINT x, UINT y, Color color)

void graphics_rect (const GraphicsContext* g, UINT x, UINT y, UINT w, UINT h, Color color)
{
FUNC_ENTRY ("area: %px, x: %u, y: %u, w: %u, h: %u, color: %x", g, x, y, w, h, color);
CM_DBG_FUNC_ENTRY ("area: %px, x: %u, y: %u, w: %u, h: %u, color: %x", g, x, y, w, h, color);

SIZE bytesPerRow = g->bytesPerRow;
U8* start = (U8*)g->buffer + (y * bytesPerRow) + (x * g->bytesPerPixel);
Expand Down

0 comments on commit 72ba30c

Please sign in to comment.