<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -159,7 +159,7 @@ void AkariDescriptorSubsystem::IRQT::ClearHandler(u8 irq) {
 	InstallHandler(irq, 0);
 }
 
-void AkariDescriptorSubsystem::IRQT::CallHandler(u8 irq, struct registers regs) {
+void AkariDescriptorSubsystem::IRQT::CallHandler(u8 irq, struct registers *regs) {
 	if (_routines[irq])
 		_routines[irq](regs);
 }</diff>
      <filename>AkariDescriptorSubsystem.cpp</filename>
    </modified>
    <modified>
      <diff>@@ -1,18 +1,8 @@
 #include &lt;AkariTaskSubsystem.hpp&gt;
 #include &lt;Akari.hpp&gt;
 
-AkariTaskSubsystem::AkariTaskSubsystem() {
-	u32 a;
-	Akari-&gt;Console-&gt;PutString(&quot;stack variable is at 0x&quot;);
-	Akari-&gt;Console-&gt;PutInt((u32)&amp;a, 16);
-	Akari-&gt;Console-&gt;PutChar('\n');
-	Akari-&gt;Console-&gt;PutString(&quot;Akari is at 0x&quot;);
-	Akari-&gt;Console-&gt;PutInt((u32)Akari, 16);
-	Akari-&gt;Console-&gt;PutChar('\n');
-	Akari-&gt;Console-&gt;PutString(&quot;&amp;Akari is at 0x&quot;);
-	Akari-&gt;Console-&gt;PutInt((u32)&amp;Akari, 16);
-	Akari-&gt;Console-&gt;PutChar('\n');
-}
+AkariTaskSubsystem::AkariTaskSubsystem(): current(0)
+{ }
 
 u8 AkariTaskSubsystem::VersionMajor() const { return 0; }
 u8 AkariTaskSubsystem::VersionMinor() const { return 1; }</diff>
      <filename>AkariTaskSubsystem.cpp</filename>
    </modified>
    <modified>
      <diff>@@ -6,13 +6,9 @@
 #define KERNEL_STACK_SIZE	0x2000
 
 static void AkariEntryCont();
+static void timer_func(struct registers *);
 
 multiboot_info_t *AkariMultiboot;
-void *AkariStack;
-
-void timer_func(struct registers r) {
-	// Akari-&gt;Console-&gt;PutString(&quot;timer run\n&quot;);
-}
 
 void AkariEntry() {
 	if ((AkariMultiboot-&gt;flags &amp; 0x41) != 0x41)
@@ -52,6 +48,16 @@ void AkariEntry() {
 }
 
 static void AkariEntryCont() {
+	__asm__ __volatile__(&quot;\
+			jmp 2f; \
+		.globl subProcessEntryPoint; \
+		subProcessEntryPoint:	\
+			mov $0, %%eax; \
+		1: \
+			inc %%eax; \
+			jmp 1b; \
+		2:	&quot; :);
+
 	u32 esp, ebp;
 	__asm__ __volatile__(&quot;\
 		mov %%esp, %0; \
@@ -62,21 +68,42 @@ static void AkariEntryCont() {
 	Akari-&gt;Console-&gt;PutInt(ebp, 16);
 	Akari-&gt;Console-&gt;PutString(&quot;\n&quot;);
 
-	ASSERT(Akari-&gt;Memory-&gt;_kernelDirectory == Akari-&gt;Memory-&gt;_activeDirectory);
-	AkariTaskSubsystem::Task *base = AkariTaskSubsystem::Task::BootstrapTask(1, 2, 3, Akari-&gt;Memory-&gt;_kernelDirectory);
+	u32 entryPoint;
+	__asm__ __volatile__(&quot;\
+		movl $subProcessEntryPoint, %0&quot; : &quot;=m&quot; (entryPoint));
 
+	Akari-&gt;Console-&gt;PutString(&quot;entry point: 0x&quot;);
+	Akari-&gt;Console-&gt;PutInt(entryPoint, 16);
+	Akari-&gt;Console-&gt;PutString(&quot;\n&quot;);
+
+	ASSERT(Akari-&gt;Memory-&gt;_kernelDirectory == Akari-&gt;Memory-&gt;_activeDirectory);
+	// esp, ebp, eip
+	AkariTaskSubsystem::Task *base = AkariTaskSubsystem::Task::BootstrapTask(0, 0, 0, Akari-&gt;Memory-&gt;_kernelDirectory);
+	Akari-&gt;Task-&gt;current = base;
 
+	u32 a = 0, b = 0;
 	Akari-&gt;Console-&gt;PutString(&quot;\ndoing sti\n&quot;);
 	asm volatile(&quot;sti&quot;);
-	while (1)
-		asm volatile(&quot;hlt&quot;);
-
-	__asm__ __volatile__(&quot;\
-		subProcessEntryPoint:	\
-			mov $0, %%eax; \
-		1: \
-			inc %%eax; \
-			jmp $1b&quot;);
+	while (1) {
+		// Something computationally differing so that interrupting at regular intervals
+		// won't be at the same instruction.
+		++a, --b;
+		if (a % 4 == 1) {
+			a += 3;
+			if (b % 2 == 1)
+				--b;
+		} else if (b % 7 == 2) {
+			--a;
+		}
+	}
 }
 
+void timer_func(struct registers *r) {
+	Akari-&gt;Console-&gt;PutString(&quot;\nHello from scheduler.  Executing EIP was &quot;);
+	Akari-&gt;Console-&gt;PutInt(r-&gt;eip, 16);
+	Akari-&gt;Console-&gt;PutString(&quot;. Executing task was &quot;);
+	Akari-&gt;Console-&gt;PutInt(Akari-&gt;Task-&gt;current-&gt;_id, 16);
+	Akari-&gt;Console-&gt;PutString(&quot;.\n&quot;);
 
+	// r-&gt;eip = 0;
+}</diff>
      <filename>entry.cpp</filename>
    </modified>
    <modified>
      <diff>@@ -107,7 +107,7 @@ class AkariDescriptorSubsystem : public AkariSubsystem {
 
 				void InstallHandler(u8, irq_handler_func_t);
 				void ClearHandler(u8);
-				void CallHandler(u8, struct registers);
+				void CallHandler(u8, struct registers *);
 
 			protected:
 				irq_handler_func_t _routines[16];</diff>
      <filename>inc/AkariDescriptorSubsystem.hpp</filename>
    </modified>
    <modified>
      <diff>@@ -14,12 +14,12 @@ class AkariTaskSubsystem : public AkariSubsystem {
 		const char *VersionProduct() const;
 
 		// void SwitchToUsermode();		XXX later
-	
+
 		class Task {
 			public:
 				static Task *BootstrapTask(u32, u32, u32, AkariMemorySubsystem::PageDirectory *);
 
-			protected:
+			// protected:
 				Task(u32, u32, u32);
 
 				u32 _esp, _ebp, _eip;
@@ -27,6 +27,8 @@ class AkariTaskSubsystem : public AkariSubsystem {
 
 				AkariMemorySubsystem::PageDirectory *_pageDir;
 		};
+
+		Task *current;
 };
 
 #endif</diff>
      <filename>inc/AkariTaskSubsystem.hpp</filename>
    </modified>
    <modified>
      <diff>@@ -8,7 +8,6 @@ extern &quot;C&quot; {
 	extern u8 __kstart, __kend;
 
 	extern multiboot_info_t *AkariMultiboot;
-	extern void *AkariStack;
 
 	void AkariEntry();
 }</diff>
      <filename>inc/entry.hpp</filename>
    </modified>
    <modified>
      <diff>@@ -13,10 +13,10 @@ struct registers {
 
 /* This needs to go somewhere better, the structure needs to be verified, and its purpose verified */
 typedef void (*isr_handler_func_t)(struct registers);
-typedef void (*irq_handler_func_t)(struct registers);
+typedef void (*irq_handler_func_t)(struct registers *);
 
 extern &quot;C&quot; void isr_handler(struct registers);
-extern &quot;C&quot; void irq_handler(struct registers);
+extern &quot;C&quot; void irq_handler(struct registers *);
 
 extern &quot;C&quot; void isr0();
 extern &quot;C&quot; void isr1();</diff>
      <filename>inc/interrupts.hpp</filename>
    </modified>
    <modified>
      <diff>@@ -50,11 +50,11 @@ void isr_handler(struct registers r) {
 	}
 }
 
-void irq_handler(struct registers r) {
-	if (r.int_no &gt;= 0x28)			// IRQ 9+
+void irq_handler(struct registers *r) {
+	if (r-&gt;int_no &gt;= 0x28)			// IRQ 9+
 		AkariOutB(0xA0, 0x20);		// EOI to slave IRQ controller
 	AkariOutB(0x20, 0x20);			// EOI to master IRQ controller
 
-	Akari-&gt;Descriptor-&gt;_irqt-&gt;CallHandler(r.int_no - 0x20, r);
+	Akari-&gt;Descriptor-&gt;_irqt-&gt;CallHandler(r-&gt;int_no - 0x20, r);
 }
 </diff>
      <filename>interrupts.cpp</filename>
    </modified>
    <modified>
      <diff>@@ -316,7 +316,7 @@ isr_common:
 
 	popa
 	add $8, %esp		#; cleans pushed error code, and pushed ISR number
-	sti
+	sti	
 	iret				#; pops CS, EIP, EFLAGS, SS, ESP
 
 .type irq_common, @function
@@ -326,6 +326,9 @@ irq_common:
 	mov %ds, %ax
 	push %eax
 
+	mov %esp, %eax		#; stack from here *up*: ds, `pusha', task switch
+	push %eax			#; ptr to said stack becomes parameter for _irq_handler
+
 	mov $0x10, %ax
 	mov %ax, %ds
 	mov %ax, %es
@@ -334,14 +337,16 @@ irq_common:
 
 	call _irq_handler
 
-	pop %ebx
-	mov %bx, %ds
-	mov %bx, %es
-	mov %bx, %fs
-	mov %bx, %gs
+	add $4, %esp		#; clean up pointer
+
+	pop %eax
+	mov %ax, %ds		#; restore from stack, which hopefully _irq_handler has changed
+	mov %ax, %es
+	mov %ax, %fs
+	mov %ax, %gs
 
 	popa
 	add $8, %esp
-	sti
+	sti					#; waits one instruction, remember?
 	iret
 </diff>
      <filename>interrupts.s</filename>
    </modified>
    <modified>
      <diff>@@ -14,7 +14,6 @@ AkariPreboot:
 
 .HasMultiboot:
 	mov %ebx, _AkariMultiboot
-	movl %esp, _AkariStack
 
 	jmp _AkariEntry
 </diff>
      <filename>preboot.s</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>16c703889f4ba441f8925601e991fab2b10abffa</id>
    </parent>
  </parents>
  <author>
    <name>Arlen Cuss</name>
    <email>celtic@sairyx.org</email>
  </author>
  <url>http://github.com/celtic/akari/commit/df8098def98183ef321f88572a9e4e16ea8d8d3e</url>
  <id>df8098def98183ef321f88572a9e4e16ea8d8d3e</id>
  <committed-date>2009-03-26T05:32:28-07:00</committed-date>
  <authored-date>2009-03-26T05:32:28-07:00</authored-date>
  <message>getting closer to what I want; we can modify the return task details from the irq</message>
  <tree>750890f32e33f51e979371be6e405f387ca1436b</tree>
  <committer>
    <name>Arlen Cuss</name>
    <email>celtic@sairyx.org</email>
  </committer>
</commit>
