BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / commit / 960f398b67fe616dfc3bc5c319e5c4cbabdbdaaa / task

// Related

Nucleus

Barry Uninterruptable clone() 960f398 (3 years, 3 months ago)
diff --git a/task/clone.c b/task/clone.c
index f7496c9..2d9b8ea 100644
--- a/task/clone.c
+++ b/task/clone.c
@@ -21,6 +21,8 @@ read_eip(void)
 pid_t
 clone(int flags)
 {
+	asm volatile("cli");
+
 	Task *parent = current, *child = new(&taskType), *tmp;
 	pid_t tid = 0;
 
@@ -28,17 +30,13 @@ clone(int flags)
 	child->pageDir = clone_dir();
 
 	/* Split tasks here */
-	uintptr_t esp, ebp, eip;
-	eip = (uintptr_t) &&end;
-
-	asm volatile("mov %%esp, %0" : "=r" (esp));
-	asm volatile("mov %%ebp, %0" : "=r" (ebp));
-	child->esp = esp;
-	child->ebp = ebp;
-	child->eip = eip;
+	child->eip = (uintptr_t) &&end;
+	asm volatile("mov %%esp, %0" : "=r" (child->esp));
+	asm volatile("mov %%ebp, %0" : "=r" (child->ebp));
 	add_to_queue(readyQueue[child->priority], child);
 	tid = child->tid;
 	put(child);
 end:
+	asm volatile("sti");
 	return tid;
 }
diff --git a/task/scheduler.c b/task/scheduler.c
index 37e8345..85cc904 100644
--- a/task/scheduler.c
+++ b/task/scheduler.c
@@ -26,19 +26,12 @@ read_eip(void)
 static void
 switch_to_task(Task *task)
 {
-	uintptr_t esp, ebp, eip;
-	asm volatile("mov %%esp, %0" : "=r" (esp));
-	asm volatile("mov %%ebp, %0" : "=r" (ebp));
-	eip = (uintptr_t) &&end;
+	asm volatile("mov %%esp, %0" : "=r" (current->esp));
+	asm volatile("mov %%ebp, %0" : "=r" (current->ebp));
+	current->eip = (uintptr_t) &&end;
 
-	current->esp = esp;
-	current->ebp = ebp;
-	current->eip = eip;
 	put(current);
 	current = task; /* Use the passed reference */
-	esp = current->esp;
-	ebp = current->ebp;
-	eip = current->eip;
 
 	asm volatile (
 		"cli;"
@@ -48,7 +41,8 @@ switch_to_task(Task *task)
 		"movl %3, %%cr3;"
 		"sti;"
 		"jmp *%%ecx"
-		:: "g" (eip), "g" (esp), "g" (ebp), "g" (current->pageDir)
+		:: "g" (current->eip), "g" (current->esp),
+		   "g" (current->ebp), "g" (current->pageDir)
 	);
 end:
 }