From 28309db7b9c5891cae61f5cf589118704105d1f4 Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Thu, 11 Apr 2019 22:32:50 +0200 Subject: [PATCH] Add printf for debug: pr_devel Taken from linux kernel --- drivers/vga.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/vga.h b/drivers/vga.h index fd041fc..5c90649 100644 --- a/drivers/vga.h +++ b/drivers/vga.h @@ -1,5 +1,6 @@ #pragma once #include "stdarg.h" +#include "stdint.h" // https://wiki.osdev.org/Text_UI #define BLACK 0x00 @@ -16,6 +17,10 @@ #define VGA_WIDTH 80 #define VGA_HEIGHT 25 +#ifndef pr_fmt +#define pr_fmt(fmt) fmt +#endif + void vprintf(const char *format, va_list ap); void printf(const char *format, ...); int VGASetup(uint bgColor, uint color); @@ -31,3 +36,22 @@ void vgaScrollUp(void); void cursorEnable(uint8_t cursor_start, uint8_t cursor_end); void cursorDisable(void); void cursorMove(int x, int y); + +/* + * Dummy printk for disabled debugging statements to use whilst maintaining + * gcc's format checking. + */ +#define no_printf(fmt, ...) \ +({ \ + if (0) \ + printf(fmt, ##__VA_ARGS__); \ + 0; \ +}) + +#ifdef DEBUG +#define pr_devel(fmt, ...) \ + printf(pr_fmt(fmt), ##__VA_ARGS__) +#else +#define pr_devel(fmt, ...) \ + no_printf(pr_fmt(fmt), ##__VA_ARGS__) +#endif