aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kernel/CMakeLists.txt5
-rw-r--r--kernel/include/kernel/spinlock.h27
-rw-r--r--kernel/kernel/io.c (renamed from kernel/kernel/io/io.c)0
-rw-r--r--kernel/kernel/spinlock.c35
-rw-r--r--kernel/mm/virtual_mm/virtual_mm.c3
5 files changed, 67 insertions, 3 deletions
diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt
index ceb3740..7aa0889 100644
--- a/kernel/CMakeLists.txt
+++ b/kernel/CMakeLists.txt
@@ -10,8 +10,9 @@ set(SRC
drivers/vga_text_buffer/vga_text_buffer.c
kernel/halt.c
- kernel/io/io.c
+ kernel/io.c
kernel/kernel.c
+ kernel/spinlock.c
kernel/stack_smashing_protector.c
libk/printf.c
@@ -38,7 +39,7 @@ set(C_COMPILE_OPTIONS
-Wall
-Wextra
-pedantic
- -Werror
+ # -Werror
-g
)
diff --git a/kernel/include/kernel/spinlock.h b/kernel/include/kernel/spinlock.h
new file mode 100644
index 0000000..9398e65
--- /dev/null
+++ b/kernel/include/kernel/spinlock.h
@@ -0,0 +1,27 @@
+/*
+ * bubbl
+ * Copyright (C) 2024-2025 Raghuram Subramani <raghus2247@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __kernel_spinlock_h
+#define __kernel_spinlock_h
+
+#include <stdatomic.h>
+
+void spinlock_acquire(atomic_flag *lock);
+void spinlock_release(atomic_flag *lock);
+
+#endif
diff --git a/kernel/kernel/io/io.c b/kernel/kernel/io.c
index f8feb32..f8feb32 100644
--- a/kernel/kernel/io/io.c
+++ b/kernel/kernel/io.c
diff --git a/kernel/kernel/spinlock.c b/kernel/kernel/spinlock.c
new file mode 100644
index 0000000..1688a12
--- /dev/null
+++ b/kernel/kernel/spinlock.c
@@ -0,0 +1,35 @@
+/*
+ * bubbl
+ * Copyright (C) 2025 Raghuram Subramani <raghus2247@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdatomic.h>
+
+void
+spinlock_acquire(atomic_flag *lock)
+{
+ __asm__ volatile("cli");
+
+ while (atomic_flag_test_and_set_explicit(lock, memory_order_acquire))
+ __asm__ volatile("rep; nop");
+}
+
+void
+spinlock_release(atomic_flag *lock)
+{
+ atomic_flag_clear_explicit(lock, memory_order_release);
+ /* TODO: Enable interrupts here */
+}
diff --git a/kernel/mm/virtual_mm/virtual_mm.c b/kernel/mm/virtual_mm/virtual_mm.c
index ba2f472..9c8292e 100644
--- a/kernel/mm/virtual_mm/virtual_mm.c
+++ b/kernel/mm/virtual_mm/virtual_mm.c
@@ -67,7 +67,8 @@ virtual_mm_initialize(void)
for (uint32_t i = 0; i < 1024; i++)
table[i] = 0x2;
- /* Identity map the first 4MiB (maps 4KiB 1024 times) */
+ /* Identity map the first 4MiB, excluding the 4th MiB
+ * (maps 4KiB 1024 times) */
for (uint32_t i = 0; i < 1024; i++)
table[i] = PTE_FRAME(i) | PTE_PRESENT(1) | PTE_WRITABLE(1);