BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / commit / b5be0ef94a970c5fba447e74f4b194428d9cd61d

// Related

Nucleus

Barry Safe interrupt disable and restore b5be0ef (3 years, 3 months ago)
diff --git a/include/nucleus/cpu.h b/include/nucleus/cpu.h
index 2a99c33..c379cb0 100644
--- a/include/nucleus/cpu.h
+++ b/include/nucleus/cpu.h
@@ -19,6 +19,20 @@ extern uint8_t lapicNums[];
 #define CPUID lapicNums[(uint8_t) (LAPIC(0x20) >> 24)]
 #define MAX_CPUS 2
 
+/* Push/pop interrupts */
+static inline uintptr_t
+irq_disable(void)
+{
+	uintptr_t flags;
+	asm volatile("pushf; cli; pop %0" : "=r" (flags) :: "memory");
+	return flags;
+}
+static inline void
+irq_restore(uintptr_t flags)
+{
+	asm volatile("push %0; popf" :: "rm" (flags) : "memory","cc");
+}
+
 void register_exception(int num, exc_handler_t addr);
 void register_interrupt(int num, int_handler_t addr);
 
diff --git a/task/clone.c b/task/clone.c
index 2d9b8ea..5e425fa 100644
--- a/task/clone.c
+++ b/task/clone.c
@@ -8,20 +8,11 @@
 
 extern TaskQueue *readyQueue[];
 
-/* Read the EIP */
-static uintptr_t
-read_eip(void)
-{
-	uintptr_t eip;
-	asm volatile("movl 4(%%ebp), %0" : "=r" (eip));
-	return eip;
-}
-
 /* Clone a task */
 pid_t
 clone(int flags)
 {
-	asm volatile("cli");
+	uintptr_t ints = irq_disable();
 
 	Task *parent = current, *child = new(&taskType), *tmp;
 	pid_t tid = 0;
@@ -37,6 +28,6 @@ clone(int flags)
 	tid = child->tid;
 	put(child);
 end:
-	asm volatile("sti");
+	irq_restore(ints);
 	return tid;
 }
diff --git a/task/scheduler.c b/task/scheduler.c
index 85cc904..115722e 100644
--- a/task/scheduler.c
+++ b/task/scheduler.c
@@ -13,15 +13,6 @@
 
 TaskQueue *readyQueue[PRIORITY_COUNT];
 
-/* Read the EIP */
-static uintptr_t
-read_eip(void)
-{
-	uintptr_t eip;
-	asm volatile("movl 4(%%ebp), %0" : "=r" (eip));
-	return eip;
-}
-
 /* Switch to a task */
 static void
 switch_to_task(Task *task)