Index: arch/l4-i386/kernel/irq.c
===================================================================
RCS file: /home/cvs/linux/arch/l4-i386/kernel/irq.c,v
retrieving revision 1.54
diff -u -r1.54 irq.c
--- irq.c	1998/06/29 11:21:59	1.54
+++ irq.c	1998/08/03 14:37:36
@@ -272,7 +272,7 @@
 			   L4_IPC_TIMEOUT(0,1,0,0,0,0), /* rcv = inf,
 							   snd = 0 */
 			   &dummydope))
-	kd_display("wake_up_process: ipc failed\\r\\n");
+	kd_display("wake_idle_if_needed: ipc failed\\r\\n");
     }
 }
 
@@ -394,7 +394,7 @@
 			   L4_IPC_TIMEOUT(0,1,0,0,0,0), /* rcv = inf,
 							   snd = 0 */
 			   &dummydope))
-	kd_display("wake_up_process: ipc failed\\r\\n");
+	kd_display("execute_bottom_halfs: ipc failed\\r\\n");
     }
 #else
 #ifdef BH_THREAD
@@ -523,18 +523,29 @@
 
 /* XXX is this safe in the L4 environment? */
 #define ACK_SECOND(mask) \
-	"inb $0xA1,%%al\n\t" \
-	"jmp 1f\n" \
-	"1:\tjmp 1f\n" \
-	"1:\torb $" #mask ",%%al\n\t" \
-	"outb %%al,$0xA1\n\t" \
-	"jmp 1f\n" \
-	"1:\tjmp 1f\n" \
-	"1:\tmovb $0x20,%%al\n\t" \
-	"outb %%al,$0xA0\n\t" \
-	"jmp 1f\n" \
-	"1:\tjmp 1f\n" \
-	"1:\toutb %%al,$0x20\n\t"
+	"   inb $0xA1,%%al \n" \
+	"   jmp 1f \n" \
+	"1: jmp 1f \n" \
+	"1: orb $" #mask ",%%al \n" \
+	"   outb %%al,$0xA1 \n" \
+	"   jmp 1f \n" \
+	"1: jmp 1f \n" \
+	"1: movb $0x20,%%al \n" \
+	"   outb %%al,$0xA0 \n" \
+	"   jmp 1f \n" \
+	"1: jmp 1f \n" \
+	"1: movb $0x0B,%%al \n" \
+	"   outb %%al,$0xA0 \n" \
+        "   jmp 1f \n" \
+        "1: jmp 1f \n" \
+	"1: inb $0xA0,%%al \n" \
+	"   testb %%al,%%al \n" \
+	"   jnz 2f \n" \
+	"   jmp 1f \n" \
+	"1: jmp 1f \n" \
+	"1: movb $0x20,%%al \n" \
+	"   outb %%al,$0x20 \n" \
+	"2:"
 
 #define UNBLK_FIRST(mask) \
 	"inb $0x21,%%al\n\t" \
@@ -965,7 +976,7 @@
    interrupts.  That's why, this thread needs to run with a relatively
    high priority. */
 
-static void irq_thread(unsigned irq)
+static void irq_thread(unsigned irq, l4_threadid_t sync_with_me)
 {
   dword_t dummy, d1;
   l4_msgdope_t dummydope;
@@ -1001,6 +1012,10 @@
 	     (unsigned) code);
 
     error:
+      l4_i386_ipc_send(sync_with_me, 
+		       0, 0xffffffff, 0xffffffff,
+		       L4_IPC_NEVER, &dummydope);
+
       /* sleep forever */
       l4_i386_ipc_receive(L4_NIL_ID, 0,
 			  &dummy, &dummy,
@@ -1011,6 +1026,10 @@
 #endif
     }
 
+  l4_i386_ipc_send(sync_with_me, 
+		   0, 0, 0,
+		   L4_IPC_NEVER, &dummydope);
+
   /* now wait for irq messages and handle them appropriately */
 
   __cli();			/* we run with irq disabled by default */
@@ -1071,6 +1090,7 @@
   unsigned i;
   unsigned *sp;
   dword_t dummy, routine;
+  l4_msgdope_t dummydope;
 
   l4_threadid_t preempter, pager, my_preempter, my_pager;
 
@@ -1144,8 +1164,8 @@
 
       /* push parameters on the stack */
 #ifdef SANITY
-      *(--sp) = newthid.lh.low;	/* push the thread id */
-      *(--sp) = newthid.lh.high;
+      *(--sp) = newthid.lh.high; /* push the thread id */
+      *(--sp) = newthid.lh.low;
 #endif
 
       if (i == TIMER_IRQ)	/* must be handled differently */
@@ -1154,7 +1174,10 @@
 	}
       else
 	{
-	  *(--sp) = i;
+	  *(--sp) = me.lh.high;	/* pass my thread id as arg for sync */
+	  *(--sp) = me.lh.low;
+
+	  *(--sp) = i;		/* pass irq number as arg */
 
 	  routine = (dword_t) irq_thread;
 	}
@@ -1178,10 +1201,14 @@
       rmgr_set_prio(newthid, PRIO_IRQ(i));
 #endif
   
-      /* give the new thread some time to initialize.  this prevents
-	 races because the new thread runs with high priority (we
-	 won't preempt it) */
-      l4_thread_switch(newthid);
+      /* give the new thread some time to initialize: wait for
+         synchronization message */
+      if (i != TIMER_IRQ)
+	l4_i386_ipc_receive(newthid, 
+			    0, &dummy, &dummy,
+			    L4_IPC_NEVER,
+			    &dummydope);
+      
     }
 #ifdef USE_PRIOS
   rmgr_set_prio(l4_myself(), PRIO_KERNEL);
@@ -1192,3 +1219,28 @@
   setup_x86_irq(2, &irq2);
   setup_x86_irq(13, &irq13);
 }
+
+#if 1 
+void dump_irq_state(void)
+{
+  
+  printk("master: mask=%02x  isr=%02x  irr=%02x\n", 
+	 (unsigned) inb(0x21), (outb(0x0b, 0x20), inb(0x20)),
+	 (outb(0x0a, 0x20), inb(0x20)));
+
+  printk("slave : mask=%02x  isr=%02x  irr=%02x\n", 
+	 (unsigned) inb(0xa1), (outb(0x0b, 0xa0), inb(0xa0)),
+	 (outb(0x0a, 0xa0), inb(0xa0)));
+
+}
+
+unsigned do_inb(unsigned p)
+{
+  return inb(p);
+}
+
+void do_outb(unsigned p, unsigned v)
+{
+  outb(v, p);
+}
+#endif
Index: arch/l4-i386/kernel/process.c
===================================================================
RCS file: /home/cvs/linux/arch/l4-i386/kernel/process.c,v
retrieving revision 1.53
diff -u -r1.53 process.c
--- process.c	1998/07/16 15:00:18	1.53
+++ process.c	1998/08/03 16:36:48
@@ -338,6 +338,7 @@
 #ifndef USE_SUPER_CLAN
   /* XXX should set prio of user task here if desired differently from
      kernel prio */
+  foo_id = L4_INVALID_ID;
   l4_thread_schedule(task, template_schedparam, &foo_id, &foo_id, 
 		     &schedparam);
 #endif  
Index: arch/l4-i386/lib/task.c
===================================================================
RCS file: /home/cvs/linux/arch/l4-i386/lib/task.c,v
retrieving revision 1.52
diff -u -r1.52 task.c
--- task.c	1998/07/16 14:16:41	1.52
+++ task.c	1998/08/03 16:35:58
@@ -167,7 +167,8 @@
 {
   static dword_t __server_eip, __server_esp;
   static l4_threadid_t __server_id; 
-  l4_threadid_t foo_id;
+
+  l4_threadid_t foo_id = L4_INVALID_ID;
   task_no_init();
 
   __server_id = l4_myself();
