From f97343c268b0fc19bf93d509a019f3d13c7af5a4 Mon Sep 17 00:00:00 2001
From: Marvin Borner
Date: Sat, 8 May 2021 19:07:20 +0200
Subject: Better cmdline parsing

---
 kernel/drivers/serial.c |  2 ++
 kernel/main.c           |  4 ----
 kernel/multiboot.c      |  4 +++-
 libs/libc/inc/def.h     | 22 ++++++++++++++++++++--
 4 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/kernel/drivers/serial.c b/kernel/drivers/serial.c
index e56c91b..06403f6 100644
--- a/kernel/drivers/serial.c
+++ b/kernel/drivers/serial.c
@@ -20,6 +20,8 @@ CLEAR void serial_enable(void)
 {
 	outb(PORT + 4, 0x0f);
 	serial_enabled = 1;
+
+	serial_print("Serial connected!\n");
 }
 
 CLEAR void serial_install(void)
diff --git a/kernel/main.c b/kernel/main.c
index 023190a..c51adc9 100644
--- a/kernel/main.c
+++ b/kernel/main.c
@@ -23,13 +23,9 @@ PROTECTED u32 __stack_chk_guard;
 int kernel_main(u32 magic, u32 addr, u32 esp); // Decl
 int kernel_main(u32 magic, u32 addr, u32 esp)
 {
-	// Serial connection
 	serial_install();
-	serial_print("\nKernel was compiled at " __TIME__ " on " __DATE__ "\n");
-	serial_print("Serial connected!\n");
 
 	gdt_install(esp);
-
 	multiboot_init(magic, addr);
 
 	memory_install();
diff --git a/kernel/multiboot.c b/kernel/multiboot.c
index c99959c..12d2475 100644
--- a/kernel/multiboot.c
+++ b/kernel/multiboot.c
@@ -16,7 +16,7 @@ CLEAR static void multiboot_parse_cmdline(const char *line)
 		if (*p == ' ')
 			start = p + 1;
 
-		if (memcmp(start, "log", 3) == 0) {
+		if (memcmp(start, "log", 3) == 0 && !ALPHANUMERIC(start[3])) {
 			serial_enable();
 			start += 3;
 		}
@@ -30,6 +30,8 @@ CLEAR void multiboot_init(u32 magic, u32 addr)
 
 	if (info->flags & MULTIBOOT_INFO_CMDLINE)
 		multiboot_parse_cmdline((const char *)info->cmdline);
+
+	serial_print("Kernel was compiled at " __TIME__ " on " __DATE__ "\n");
 }
 
 CLEAR u32 multiboot_vbe(void)
diff --git a/libs/libc/inc/def.h b/libs/libc/inc/def.h
index 6253371..191a818 100644
--- a/libs/libc/inc/def.h
+++ b/libs/libc/inc/def.h
@@ -20,7 +20,7 @@ typedef signed long long s64;
 typedef unsigned long long u64;
 
 /**
- * Macros
+ * Useful macros
  */
 
 #define UNUSED(a) ((void)(a))
@@ -30,10 +30,20 @@ typedef unsigned long long u64;
 
 #define ABS(a) ((u32)(((s32)(a) < 0) ? -(a) : (a)))
 
+#define COUNT(a) (sizeof(a) / sizeof 0 [a])
+
+#define UPPER(a) ((a) >= 'A' && ((a) <= 'Z'))
+#define LOWER(a) ((a) >= 'a' && ((a) <= 'z'))
+#define ALPHA(a) (UPPER(a) || LOWER(a))
+#define NUMERIC(a) ((a) >= '0' && ((a) <= '9'))
+#define ALPHANUMERIC(a) (ALPHA(a) || NUMERIC(a))
+
 #define __STRINGIFY(a) #a
 #define STRINGIFY(a) __STRINGIFY(a)
 
-#define COUNT(a) (sizeof(a) / sizeof 0 [a])
+/**
+ * Compiler attribute wrappers
+ */
 
 #define ATTR __attribute__
 #define NORETURN ATTR((noreturn))
@@ -52,11 +62,19 @@ typedef unsigned long long u64;
 #define NO_SANITIZE ATTR((no_sanitize("undefined")))
 #define ALIGNED(align) ATTR((aligned(align)))
 
+/**
+ * Kernel section macros
+ */
+
 #ifdef KERNEL
 #define CLEAR NOINLINE ATTR((section(".temp_clear")))
 #define PROTECTED ATTR((section(".temp_protect")))
 #endif
 
+/**
+ * General macro numbers
+ */
+
 #define EOF (-1)
 #define NULL ((void *)0)
 
-- 
cgit v1.2.3