aboutsummaryrefslogtreecommitdiff
path: root/kernel/include
diff options
context:
space:
mode:
authorAlex Auvolat <alex.auvolat@ens.fr>2014-12-06 23:15:06 +0100
committerAlex Auvolat <alex.auvolat@ens.fr>2014-12-06 23:15:06 +0100
commitacc786cb5805d057932ada3e7c571bb8e901cd67 (patch)
treefe6a9da99a9c5492f1004363a2a1a7aa8bfc8fed /kernel/include
parent0b5d6568c468075b6c1a2de065332b270345611b (diff)
downloadmacroscope-acc786cb5805d057932ada3e7c571bb8e901cd67.tar.gz
macroscope-acc786cb5805d057932ada3e7c571bb8e901cd67.zip
Begin review of taking model : making things thread safe.
Diffstat (limited to 'kernel/include')
-rw-r--r--kernel/include/gdt.h57
-rw-r--r--kernel/include/idt.h15
-rw-r--r--kernel/include/mutex.h21
-rw-r--r--kernel/include/region.h2
4 files changed, 28 insertions, 67 deletions
diff --git a/kernel/include/gdt.h b/kernel/include/gdt.h
index cd66676..a62d0db 100644
--- a/kernel/include/gdt.h
+++ b/kernel/include/gdt.h
@@ -7,58 +7,11 @@
Here, we don't use segmentation to separate processes from one another (this is done with paging).
We only use segmentation to make the difference between kernel mode (ring 3) and user mode (ring 0) */
-/* One entry of the table */
-struct gdt_entry {
- uint16_t limit_low;
- uint16_t base_low;
- uint8_t base_middle;
- uint8_t access;
- uint8_t granularity;
- uint8_t base_high;
-} __attribute__((packed));
-typedef struct gdt_entry gdt_entry_t;
-
-/* Structure defining the whole table : address and size (in bytes). */
-struct gdt_ptr {
- uint16_t limit;
- uint32_t base;
-} __attribute__((packed));
-typedef struct gdt_ptr gdt_ptr_t;
-
-/* The TSS is used for hardware multitasking.
- We don't use that, but we still need a TSS so that user mode process exceptions
- can be handled correctly by the kernel. */
-struct tss_entry {
- uint32_t prev_tss; // The previous TSS - if we used hardware task switching this would form a linked list.
- uint32_t esp0; // The stack pointer to load when we change to kernel mode.
- uint32_t ss0; // The stack segment to load when we change to kernel mode.
- uint32_t esp1; // Unused...
- uint32_t ss1;
- uint32_t esp2;
- uint32_t ss2;
- uint32_t cr3;
- uint32_t eip;
- uint32_t eflags;
- uint32_t eax;
- uint32_t ecx;
- uint32_t edx;
- uint32_t ebx;
- uint32_t esp;
- uint32_t ebp;
- uint32_t esi;
- uint32_t edi;
- uint32_t es; // The value to load into ES when we change to kernel mode.
- uint32_t cs; // The value to load into CS when we change to kernel mode.
- uint32_t ss; // The value to load into SS when we change to kernel mode.
- uint32_t ds; // The value to load into DS when we change to kernel mode.
- uint32_t fs; // The value to load into FS when we change to kernel mode.
- uint32_t gs; // The value to load into GS when we change to kernel mode.
- uint32_t ldt; // Unused...
- uint16_t trap;
- uint16_t iomap_base;
-} __attribute__((packed));
-typedef struct tss_entry tss_entry_t;
-
void gdt_init();
+#define K_CODE_SEGMENT 0x08
+#define K_DATA_SEGMENT 0x10
+#define U_CODE_SEGMENT 0x18
+#define U_DATA_SEGMENT 0x20
+
/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/kernel/include/idt.h b/kernel/include/idt.h
index e054ed5..b697dc3 100644
--- a/kernel/include/idt.h
+++ b/kernel/include/idt.h
@@ -58,21 +58,6 @@
#define EX_INTEL_RESERVED_13 30 // No
#define EX_INTEL_RESERVED_14 31 // No
-struct idt_entry {
- uint16_t base_lo; //Low part of address to jump to
- uint16_t sel; //Kernel segment selector
- uint8_t always0;
- uint8_t flags; //Flags
- uint16_t base_hi; //High part of address to jump to
-} __attribute__((packed));
-typedef struct idt_entry idt_entry_t;
-
-struct idt_ptr {
- uint16_t limit;
- uint32_t base;
-} __attribute__((packed));
-typedef struct idt_ptr idt_ptr_t;
-
struct registers {
uint32_t ds; // Data segment selector
uint32_t edi, esi, ebp, useless_esp, ebx, edx, ecx, eax; // Pushed by pusha.
diff --git a/kernel/include/mutex.h b/kernel/include/mutex.h
new file mode 100644
index 0000000..6814adf
--- /dev/null
+++ b/kernel/include/mutex.h
@@ -0,0 +1,21 @@
+#pragma once
+
+#include <stdint.h>
+
+#define MUTEX_LOCKED 1
+#define MUTEX_UNLOCKED 0
+
+
+typedef uint32_t mutex_t;
+
+void mutex_lock(mutex_t* mutex); //wait for mutex to be free
+int mutex_try_lock(mutex_t* mutex); //lock mutex only if free, returns !0 if locked, 0 if was busy
+void mutex_unlock(mutex_t* mutex);
+
+// the mutex code assumes a yield() function is defined somewhere
+void yield();
+
+#define STATIC_MUTEX(name) static mutex_t name __attribute__((section("locks"))) = MUTEX_UNLOCKED;
+
+
+/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/kernel/include/region.h b/kernel/include/region.h
index 4bc8917..5f44626 100644
--- a/kernel/include/region.h
+++ b/kernel/include/region.h
@@ -44,3 +44,5 @@ void region_free_unmap_free(void* addr);
void region_free_unmap(void* addr);
void dbg_print_region_stats();
+
+/* vim: set ts=4 sw=4 tw=0 noet :*/