diff options
-rw-r--r-- | kernel/drivers/ata.c | 21 | ||||
-rw-r--r-- | kernel/include/lib/kio.h | 10 | ||||
-rw-r--r-- | kernel/include/lib/klib.h | 62 | ||||
-rw-r--r-- | kernel/lib/panic.c | 6 |
4 files changed, 75 insertions, 24 deletions
diff --git a/kernel/drivers/ata.c b/kernel/drivers/ata.c index 4c5896c..e940ad4 100644 --- a/kernel/drivers/ata.c +++ b/kernel/drivers/ata.c @@ -19,19 +19,24 @@ #define IDE_PROG_IF_SECONDARY_CHANNEL_CAN_SWITCH_TO_AND_FROM_PCI_NATIVE_FLAG 0x4 #define IDE_PROG_IF_DMA_SUPPORT_FLAG 0x7 -#include "comus/drivers/pci.h" -#include "comus/drivers/ata.h" +#include <comus/drivers/pci.h> +#include <comus/drivers/ata.h> +#include <lib.h> bool ata_find_primary_drive(struct pci_device *out) { if (!pci_findby_class(out, CLASS_MASS_STORAGE_CONTROLLER, - SUBCLASS_IDE_CONTROLLER, NULL)) { + SUBCLASS_IDE_CONTROLLER, NULL)) { + return false; + } + + const uint8_t prog_if = pci_rcfg_b(*out, PCI_PROG_IF_B); + const uint8_t header_type = pci_rcfg_b(*out, PCI_HEADER_TYPE_B); + + if (header_type != 0x0) { + TRACE("Wrong header type for IDE_CONTROLLER device, not reading BARs"); return false; } - const uint8_t prog_if = pci_rcfg_b(*out, PCI_PROG_IF_B); - - return true; + return true; } - - diff --git a/kernel/include/lib/kio.h b/kernel/include/lib/kio.h index 1b10a39..66efc7b 100644 --- a/kernel/include/lib/kio.h +++ b/kernel/include/lib/kio.h @@ -26,16 +26,6 @@ void kputc(char c); */ void kputs(const char *s); -#ifdef TRACING -#define TRACE(format, ...) \ - do { \ - kprintf("[TRACE] %s ", __FUNCTION__); \ - kprintf(format, ##__VA_ARGS__); \ - } while (0) -#else -#define TRACE(format, ...) -#endif - /** * prints out a formatted string * diff --git a/kernel/include/lib/klib.h b/kernel/include/lib/klib.h index 0d9797b..d9f6c4d 100644 --- a/kernel/include/lib/klib.h +++ b/kernel/include/lib/klib.h @@ -185,10 +185,64 @@ char *btoa(size_t bytes, char *buf); */ unsigned int bound(unsigned int min, unsigned int value, unsigned int max); -#define __PANIC_STR(x) __PANIC_STR2(x) -#define __PANIC_STR2(x) #x +enum log_level { + LOG_LVL_PANIC = 0, + LOG_LVL_ERROR = 1, + LOG_LVL_WARN = 2, + LOG_LVL_INFO = 3, + LOG_LVL_TRACE = 4, +}; + +// define LOG_LEVEL to disable logs above that number in the enum above +#ifndef LOG_LEVEL +#define LOG_LEVEL 4 +#endif + +// #define __AS_STR_LITERAL(x) __AS_STR_LITERAL_IMPL(x) +// #define __AS_STR_LITERAL_IMPL(x) #x + +#if LOG_LEVEL >= LOG_LEVEL_TRACE +#define TRACE(...) \ + do { \ + kprintf("[TRACE] [%s:%s:%d] : ", __FILE__, __FUNCTION__, __LINE__); \ + kprintf(__VA_ARGS__); \ + } while (0) +#else +#define TRACE(...) +#endif + +#if LOG_LEVEL >= LOG_LVL_INFO +#define INFO(...) \ + do { \ + kprintf("[INFO] [%s:%s:%d] : ", __FILE__, __FUNCTION__, __LINE__); \ + kprintf(__VA_ARGS__); \ + } while (0) +#else +#define INFO(...) +#endif + +#if LOG_LEVEL >= LOG_LVL_WARN +#define WARN(...) \ + do { \ + kprintf("[WARN] [%s:%s:%d] : ", __FILE__, __FUNCTION__, __LINE__); \ + kprintf(__VA_ARGS__); \ + } while (0) +#else +#define WARN(format, ...) +#endif + +#if LOG_LEVEL >= LOG_LVL_ERROR +#define ERROR(...) \ + do { \ + kprintf("[ERROR] [%s:%s:%d] : ", __FILE__, __FUNCTION__, __LINE__); \ + kprintf(__VA_ARGS__); \ + } while (0) +#else +#define ERROR(...) +#endif + +#define panic(...) __panic(__LINE__, __FILE__, __VA_ARGS__) -#define panic(...) __panic(__PANIC_STR(__LINE__), __FILE__, __VA_ARGS__) #define assert(val, ...) \ do { \ if (!(val)) { \ @@ -203,7 +257,7 @@ unsigned int bound(unsigned int min, unsigned int value, unsigned int max); * @param ... - variable args for the format */ __attribute__((noreturn, format(printf, 3, 4))) void -__panic(const char *line, const char *file, const char *format, ...); +__panic(unsigned int line, const char *file, const char *format, ...); /** * Fill dst with a stack trace consisting of return addresses in order diff --git a/kernel/lib/panic.c b/kernel/lib/panic.c index 72f5c51..3a6e029 100644 --- a/kernel/lib/panic.c +++ b/kernel/lib/panic.c @@ -2,17 +2,19 @@ #include <stdarg.h> #include <comus/asm.h> -__attribute__((noreturn)) void __panic(const char *line, const char *file, +__attribute__((noreturn)) void __panic(unsigned int line, const char *file, const char *format, ...) { cli(); +#if LOG_LEVEL >= LOG_LVL_PANIC va_list list; va_start(list, format); kprintf("\n\n!!! PANIC !!!\n"); - kprintf("In file %s at line %s:\n", file, line); + kprintf("In file %s at line %d:\n", file, line); kvprintf(format, list); kprintf("\n\n"); log_backtrace(); +#endif while (1) halt(); |