diff -Naur linux-2.4.19-orig/Documentation/adeos.txt linux-2.4.19-adeos/Documentation/adeos.txt
--- linux-2.4.19-orig/Documentation/adeos.txt	Thu Jan  1 01:00:00 1970
+++ linux-2.4.19-adeos/Documentation/adeos.txt	Thu Oct 10 20:02:05 2002
@@ -0,0 +1,207 @@
+
+The Adeos nanokernel is based on research and publications made in the
+early '90s on the subject of nanokernels. Our basic method was to
+reverse the approach described in most of the papers on the subject.
+Instead of first building the nanokernel and then building the client
+OSes, we started from a live and known-to-be-functional OS, Linux, and
+inserted a nanokernel beneath it. Starting from Adeos, other client
+OSes can now be put side-by-side with the Linux kernel.
+
+To this end, Adeos enables multiple domains to exist simultaneously on
+the same hardware. None of these domains see each other, but all of
+them see Adeos. A domain is most probably a complete OS, but there is
+no assumption being made regarding the sophistication of what's in
+a domain.
+
+To share the hardware among the different OSes, Adeos implements an
+interrupt pipeline (ipipe). Every OS domain has an entry in the ipipe.
+Each interrupt that comes in the ipipe is passed on to every domain
+in the ipipe. Instead of disabling/enabling interrupts, each domain
+in the pipeline only needs to stall/unstall his pipeline stage. If
+an ipipe stage is stalled, then the interrupts do not progress in the
+ipipe until that stage has been unstalled. Each stage of the ipipe
+can, of course, decide to do a number of things with an interrupt.
+Among other things, it can decide that it's the last recipient of the
+interrupt. In that case, the ipipe does not propagate the interrupt
+to the rest of the domains in the ipipe.
+
+Regardless of the operations being done in the ipipe, the Adeos code
+does __not__ play with the interrupt masks. The only case where the
+hardware masks are altered is during the addition/removal of a domain
+from the ipipe. This also means that no OS is allowed to use the real
+hardware cli/sti. But this is OK, since the stall/unstall calls
+achieve the same functionality.
+
+Our approach is based on the following papers (links to these
+papers are provided at the bottom of this message):
+[1] D. Probert, J. Bruno, and M. Karzaorman. "Space: a new approach to
+operating system abstraction." In: International Workshop on Object
+Orientation in Operating Systems, pages 133-137, October 1991.
+[2] D. Probert, J. Bruno. "Building fundamentally extensible application-
+specific operating systems in Space", March 1995.
+[3] D. Cheriton, K. Duda. "A caching model of operating system kernel
+functionality". In: Proc. Symp. on Operating Systems Design and
+Implementation, pages 179-194, Monterey CA (USA), 1994.
+[4] D. Engler, M. Kaashoek, and J. O'Toole Jr. "Exokernel: an operating
+system architecture for application-specific resource management",
+December 1995.
+
+If you don't want to go fetch the complete papers, here's a summary.
+The first 2 discuss the Space nanokernel, the 3rd discussed the cache
+nanokernel, and the last discusses exokernel.
+
+The complete Adeos approach has been thoroughly documented in a whitepaper
+published more than a year ago entitled "Adaptive Domain Environment
+for Operating Systems" and available here: http://www.opersys.com/adeos
+The current implementation is slightly different. Mainly, we do not
+implement the functionality to move Linux out of ring 0. Although of
+interest, this approach is not very portable.
+
+Instead, our patch taps right into Linux's main source of control
+over the hardware, the interrupt dispatching code, and inserts an
+interrupt pipeline which can then serve all the nanokernel's clients,
+including Linux.
+
+This is not a novelty in itself. Other OSes have been modified in such
+a way for a wide range of purposes. One of the most interesting
+examples is described by Stodolsky, Chen, and Bershad in a paper
+entitled "Fast Interrupt Priority Management in Operating System
+Kernels" published in 1993 as part of the Usenix Microkernels and
+Other Kernel Architectures Symposium. In that case, cli/sti were
+replaced by virtual cli/sti which did not modify the real interrupt
+mask in any way. Instead, interrupts were defered and delivered to
+the OS upon a call to the virtualized sti.
+
+Mainly, this resulted in increased performance for the OS. Although
+we haven't done any measurements on Linux's interrupt handling
+performance with Adeos, our nanokernel includes by definition the
+code implementing the technique described in the abovementioned
+Stodolsky paper, which we use to redirect the hardware interrupt flow
+to the pipeline.
+
+In terms of implementation, the Adeos' code is rather short since we
+focused on setting the foundations for sharing interrupts between
+domains. Here are the files we added:
+kernel/adeos.c: Architecture-independent domain code.
+arch/i386/kernel/adeos.c: Architecture-dependent domain code.
+arch/i386/kernel/ipipe.c: Interrupt pipeline code.
+include/asm-i386/adeos.h: Arch-dependent Adeos header.
+include/linux/adeos.h: Main (arch-independent) Adeos header.
+
+As you can see, only the i386 is currently supported. Nonetheless,
+most of the architecture-dependent code is easily portable to other
+architectures.
+
+We also modified some files to tap into Linux interrupt and system
+event dispatching (all the modifications are encapsulated in #ifdef
+CONFIG_ADEOS/#endif):
+
+./arch/i386/kernel/process.c
+./arch/i386/kernel/irq.c
+./arch/i386/kernel/smp.c
+./arch/i386/kernel/entry.S
+./arch/i386/kernel/i386_ksyms.c
+./arch/i386/kernel/time.c
+./arch/i386/kernel/i8259.c
+./arch/i386/kernel/apic.c
+./arch/i386/kernel/io_apic.c
+./arch/i386/mm/fault.c
+./include/linux/sched.h
+./include/asm-i386/system.h
+./kernel/ksyms.c
+./kernel/fork.c
+./kernel/sysctl.c
+./kernel/sched.c
+./kernel/printk.c
+./kernel/signal.c
+./kernel/exit.c
+./init/main.c
+
+We modified the idle task so it gives control back to Adeos in order for
+the ipipe to continue propagation: arch/i386/kernel/process.c
+
+We modified init/main.c to initialize Adeos very early in the startup.
+
+Of course, we also added the appropriate makefile modifications and
+config options so that you can choose to enable/disable Adeos as
+part of the kernel build configuration.
+
+Adeos' public API is fully documented here:
+http://www.freesoftware.fsf.org/adeos/doc/api/index.html.
+
+In Linux's case, adeos_register_domain() is called very early during
+system startup.
+
+To add your domain to the ipipe, you need to:
+1) Register your domain with Adeos using adeos_register_domain()
+2) Call adeos_virtualize_irq() for all the IRQs you wish to be
+notified about in the ipipe.
+
+That's it. Provided you gave Adeos appropriate handlers in step
+#2, your interrupts will be delivered via the ipipe.
+
+During runtime, you may change your position in the ipipe using
+adeos_renice_domain(). You may also stall/unstall the pipeline
+and change the ipipe's handling of the interrupts according to your
+needs.
+
+Adeos supports SMP, and APIC support on UP.
+
+Here are some of the possible uses for Adeos (this list is far
+from complete):
+1) Much like User-Mode Linux, it should now be possible to have 2
+Linux kernels living side-by-side on the same hardware. In contrast
+to UML, this would not be 2 kernels one ontop of the other, but
+really side-by-side. Since Linux can be told at boot time to use
+only one portion of the available RAM, on a 128MB machine this
+would mean that the first could be made to use the 0-64MB space and
+the second would use the 64-128MB space. We realize that many
+modifications are required. Among other things, one of the 2 kernels
+will not need to conduct hardware initialization. Nevertheless, this
+possibility should be studied closer.
+
+2) It follows from #1 that adding other kernels beside Linux should
+be feasible. BSD is a prime candidate, but it would also be nice to
+see what virtualizers such as VMWare and Plex86 could do with Adeos.
+Proprietary operating systems could potentially also be accomodated.
+
+3) All the previous work that has been done on nanokernels should now
+be easily ported to Linux. Mainly, we would be very interested to
+hear about extensions to Adeos. Primarily, we have no mechanisms
+currently enabling multiple domains to share information. The papers
+mentioned earlier provide such mechanisms, but we'd like to see
+actual practical examples.
+
+4) Kernel debuggers' main problem (tapping into the kernel's
+interrupts) is solved and it should then be possible to provide
+patchless kernel debuggers. They would then become loadable kernel
+modules.
+
+5) Drivers who require absolute priority and dislike other kernel
+portions who use cli/sti can now create a domain of their own
+and place themselves before Linux in the ipipe. This provides a
+mechanism for the implementation of systems that can provide guaranteed
+realtime response.
+
+Philippe Gerum <rpm@xenomai.org>
+Karim Yaghmour <karim@opersys.com>
+
+----------------------------------------------------------------------
+Links to papers:
+1-
+http://citeseer.nj.nec.com/probert91space.html
+ftp://ftp.cs.ucsb.edu/pub/papers/space/iwooos91.ps.gz (not working)
+http://www4.informatik.uni-erlangen.de/~tsthiel/Papers/Space-iwooos91.ps.gz
+
+2-
+http://www.cs.ucsb.edu/research/trcs/abstracts/1995-06.shtml
+http://www4.informatik.uni-erlangen.de/~tsthiel/Papers/Space-trcs95-06.ps.gz
+
+3-
+http://citeseer.nj.nec.com/kenneth94caching.html
+http://guir.cs.berkeley.edu/projects/osprelims/papers/cachmodel-OSkernel.ps.gz
+
+4-
+http://citeseer.nj.nec.com/engler95exokernel.html
+ftp://ftp.cag.lcs.mit.edu/multiscale/exokernel.ps.Z
+----------------------------------------------------------------------
diff -Naur linux-2.4.19-orig/Makefile linux-2.4.19-adeos/Makefile
--- linux-2.4.19-orig/Makefile	Sat Aug  3 02:39:46 2002
+++ linux-2.4.19-adeos/Makefile	Fri Sep 20 18:29:36 2002
@@ -1,7 +1,7 @@
 VERSION = 2
 PATCHLEVEL = 4
 SUBLEVEL = 19
-EXTRAVERSION =
+EXTRAVERSION = -adeos
 
 KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 
@@ -71,7 +71,7 @@
 # images.  Uncomment if you want to place them anywhere other than root.
 #
 
-#export	INSTALL_PATH=/boot
+export	INSTALL_PATH=/boot
 
 #
 # INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
diff -Naur linux-2.4.19-orig/arch/i386/config.in linux-2.4.19-adeos/arch/i386/config.in
--- linux-2.4.19-orig/arch/i386/config.in	Sat Aug  3 02:39:42 2002
+++ linux-2.4.19-adeos/arch/i386/config.in	Thu Oct 10 20:01:15 2002
@@ -209,6 +209,7 @@
 mainmenu_option next_comment
 comment 'General setup'
 
+bool 'Adaptive Domain Environment support' CONFIG_ADEOS
 bool 'Networking support' CONFIG_NET
 
 # Visual Workstation support is utterly broken.
diff -Naur linux-2.4.19-orig/arch/i386/kernel/Makefile linux-2.4.19-adeos/arch/i386/kernel/Makefile
--- linux-2.4.19-orig/arch/i386/kernel/Makefile	Fri Nov  9 23:21:21 2001
+++ linux-2.4.19-adeos/arch/i386/kernel/Makefile	Thu Oct 10 20:01:15 2002
@@ -14,7 +14,7 @@
 
 O_TARGET := kernel.o
 
-export-objs     := mca.o mtrr.o msr.o cpuid.o microcode.o i386_ksyms.o
+export-objs     := mca.o mtrr.o msr.o cpuid.o microcode.o i386_ksyms.o ipipe.o adeos.o
 
 obj-y	:= process.o semaphore.o signal.o entry.o traps.o irq.o vm86.o \
 		ptrace.o i8259.o ioport.o ldt.o setup.o time.o sys_i386.o \
@@ -40,5 +40,6 @@
 obj-$(CONFIG_X86_LOCAL_APIC)	+= mpparse.o apic.o nmi.o
 obj-$(CONFIG_X86_IO_APIC)	+= io_apic.o acpitable.o
 obj-$(CONFIG_X86_VISWS_APIC)	+= visws_apic.o
+obj-$(CONFIG_ADEOS)		+= ipipe.o adeos.o
 
 include $(TOPDIR)/Rules.make
diff -Naur linux-2.4.19-orig/arch/i386/kernel/adeos.c linux-2.4.19-adeos/arch/i386/kernel/adeos.c
--- linux-2.4.19-orig/arch/i386/kernel/adeos.c	Thu Jan  1 01:00:00 1970
+++ linux-2.4.19-adeos/arch/i386/kernel/adeos.c	Thu Oct 24 10:54:15 2002
@@ -0,0 +1,238 @@
+/*
+ *   linux/arch/i386/kernel/adeos.c
+ *
+ *   Copyright (C) 2002 Philippe Gerum.
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
+ *   USA; either version 2 of the License, or (at your option) any later
+ *   version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *   This code implements the architecture-dependent ADEOS support.
+ */
+
+#include <linux/config.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/irq.h>
+#include <asm/system.h>
+#include <asm/atomic.h>
+#include <asm/io.h>
+
+#ifdef CONFIG_SMP
+
+static volatile unsigned long adeos_cpu_sync_map;
+
+static volatile unsigned long adeos_cpu_lock_map;
+
+static spinlock_t adeos_cpu_barrier = SPIN_LOCK_UNLOCKED;
+
+static atomic_t adeos_critical_count = ATOMIC_INIT(0);
+
+static void (*adeos_cpu_sync)(void);
+
+void __adeos_do_critical_sync (unsigned irq)
+
+{
+    ipipe_declare_cpuid;
+
+    set_bit(cpuid,&adeos_cpu_sync_map);
+
+    /* Now we are in sync with the lock requestor running on another
+       CPU. Enter a spinning wait until he releases the global
+       lock. */
+    ipipe_hw_spin_lock_simple(&adeos_cpu_barrier);
+
+    /* Got it. Now get out. */
+
+    if (adeos_cpu_sync)
+	/* Call the sync routine if any. */
+	adeos_cpu_sync();
+
+    ipipe_hw_spin_unlock_simple(&adeos_cpu_barrier);
+
+    clear_bit(cpuid,&adeos_cpu_sync_map);
+}
+
+#endif /* CONFIG_SMP */
+
+void __adeos_init_domain (adomain_t *adp, adattr_t *attr)
+
+{
+    int estacksz = attr->estacksz > 0 ? attr->estacksz : 8192, _cpuid;
+    ipipe_declare_cpuid;
+
+    for (_cpuid = 0; _cpuid < ADEOS_NR_CPUS; _cpuid++)
+	{
+	int **psp = &adp->esp[_cpuid];
+
+	adp->estackbase[_cpuid] = (int *)kmalloc(estacksz,GFP_KERNEL);
+    
+	if (adp->estackbase[_cpuid] == NULL)
+	    panic("ADEOS: no memory for domain stack on CPU #%d",_cpuid);
+
+	adp->esp[_cpuid] = adp->estackbase[_cpuid];
+	**psp = 0;
+	*psp = (int *)(((unsigned long)*psp + estacksz - 0x10) & ~0xf);
+	*--(*psp) = (_cpuid == cpuid);
+	*--(*psp) = 0;
+	*--(*psp) = (int)attr->entry;
+	}
+}
+
+void __adeos_cleanup_domain (adomain_t *adp)
+
+{
+    int _cpuid;
+
+    for (_cpuid = 0; _cpuid < ADEOS_NR_CPUS; _cpuid++)
+	{
+	adp->cpudata[_cpuid].irq_pending_hi = 0;
+	clear_bit(IPIPE_XPEND_FLAG,&adp->cpudata[_cpuid].status);
+	kfree(adp->estackbase[_cpuid]);
+	}
+}
+
+/* __adeos_critical_enter() -- Grab the superlock excluding all CPUs
+   but the current one from a critical section. This lock is used when
+   we must enforce a global critical section for a single CPU in a
+   possibly SMP system whichever context the CPUs are running
+   (i.e. interrupt handler or regular thread). */
+
+unsigned long __adeos_critical_enter (void (*syncfn)(void))
+
+{
+    unsigned long flags;
+
+    ipipe_hw_save_flags_and_cli(flags);
+
+#ifdef CONFIG_SMP
+    if (smp_num_cpus > 1) /* We might be running a SMP-kernel on a UP box... */
+	{
+	ipipe_declare_cpuid;
+
+	if (!test_and_set_bit(cpuid,&adeos_cpu_lock_map))
+	    {
+	    while (test_and_set_bit(31,&adeos_cpu_lock_map))
+		{
+		/* Refer to the explanations found in
+		   linux/arch/asm-i386/irq.c about
+		   SUSPECTED_CPU_OR_CHIPSET_BUG_WORKAROUND for more about
+		   this strange loop. */
+		int n = 0;
+		do { cpu_relax(); } while (++n < cpuid);
+		}
+
+	    ipipe_hw_spin_lock_simple(&adeos_cpu_barrier);
+
+	    adeos_cpu_sync = syncfn;
+
+	    /* Send the sync IPI to all processors but the current one. */
+	    __adeos_send_IPI_allbutself(ADEOS_CRITICAL_VECTOR);
+
+	    while (adeos_cpu_sync_map != (cpu_online_map & ~adeos_cpu_lock_map))
+		cpu_relax();
+	    }
+
+	atomic_inc(&adeos_critical_count);
+	}
+#endif /* CONFIG_SMP */
+
+    return flags;
+}
+
+/* __adeos_critical_exit() -- Release the superlock. */
+
+void __adeos_critical_exit (unsigned long flags)
+
+{
+#ifdef CONFIG_SMP
+    if (smp_num_cpus > 1) /* We might be running a SMP-kernel on a UP box... */
+	{
+	ipipe_declare_cpuid;
+
+	if (atomic_dec_and_test(&adeos_critical_count))
+	    {
+	    ipipe_hw_spin_unlock_simple(&adeos_cpu_barrier);
+
+	    while (adeos_cpu_sync_map != 0)
+		cpu_relax();
+
+	    clear_bit(cpuid,&adeos_cpu_lock_map);
+	    clear_bit(31,&adeos_cpu_lock_map);
+	    }
+	}
+#endif /* CONFIG_SMP */
+
+    ipipe_hw_restore_flags(flags);
+}
+
+int __adeos_get_sysinfo (adsysinfo_t *info)
+
+{
+    info->timer.irq = 0;
+
+#ifdef CONFIG_SMP
+    info->ncpus = smp_num_cpus;
+#else /* !CONFIG_SMP */
+    info->ncpus = 1;
+#endif /* CONFIG_SMP */
+
+    if (cpu_has_tsc)
+	info->cpufreq = 1000 * cpu_khz;
+    else
+	info->cpufreq = CLOCK_TICK_RATE;
+
+    return 0;
+}
+
+int __adeos_tune_timer (unsigned long ns, int flags)
+
+{
+    unsigned ghz, latch;
+    unsigned long x;
+
+    if (flags & ADEOS_RESET_TIMER)
+	latch = LATCH;
+    else
+	{
+	if (ns < 122071 || ns > (1000 / HZ) * 1000000) /* HZ max, 8khz min */
+	    return -EINVAL;
+
+	ghz = 1000000000 / ns;
+	latch = (CLOCK_TICK_RATE + ghz/2) / ghz;
+	}
+
+    x = __adeos_critical_enter(NULL); /* Sync with all CPUs */
+
+    /* Shamelessly lifted from init_IRQ() in i8259.c */
+    outb_p(0x34,0x43);		/* binary, mode 2, LSB/MSB, ch 0 */
+    outb_p(latch & 0xff,0x40);	/* LSB */
+    outb(latch >> 8,0x40);	/* MSB */
+
+    __adeos_critical_exit(x);
+
+    return 0;
+}
+
+asmlinkage void __adeos_enter_syscall (struct pt_regs *regs) {
+
+    if (__adeos_event_monitors[ADEOS_SYSCALL_PROLOGUE] > 0)
+	ipipe_handle_event(ADEOS_SYSCALL_PROLOGUE,regs);
+}
+
+asmlinkage void __adeos_exit_syscall (void) {
+
+    if (__adeos_event_monitors[ADEOS_SYSCALL_EPILOGUE] > 0)
+	ipipe_handle_event(ADEOS_SYSCALL_EPILOGUE,NULL);
+}
diff -Naur linux-2.4.19-orig/arch/i386/kernel/apic.c linux-2.4.19-adeos/arch/i386/kernel/apic.c
--- linux-2.4.19-orig/arch/i386/kernel/apic.c	Sat Aug  3 02:39:42 2002
+++ linux-2.4.19-adeos/arch/i386/kernel/apic.c	Thu Oct 17 10:14:50 2002
@@ -1045,7 +1045,7 @@
 	 * Currently this isn't too much of an issue (performance wise),
 	 * we can take more than 100K local irqs per second on a 100 MHz P5.
 	 */
-}
+    }
 
 /*
  * Local APIC timer interrupt. This is the most natural way for doing
@@ -1070,6 +1070,9 @@
 	 * NOTE! We'd better ACK the irq immediately,
 	 * because timer handling can be slow.
 	 */
+#ifdef CONFIG_ADEOS
+	if (!adp_pipelined)
+#endif /* CONFIG_ADEOS */
 	ack_APIC_irq();
 	/*
 	 * update_process_times() expects us to have done irq_enter().
diff -Naur linux-2.4.19-orig/arch/i386/kernel/entry.S linux-2.4.19-adeos/arch/i386/kernel/entry.S
--- linux-2.4.19-orig/arch/i386/kernel/entry.S	Sat Aug  3 02:39:42 2002
+++ linux-2.4.19-adeos/arch/i386/kernel/entry.S	Thu Oct 10 20:01:15 2002
@@ -136,6 +136,12 @@
 	pushfl			# We get a different stack layout with call gates,
 	pushl %eax		# which has to be cleaned up later..
 	SAVE_ALL
+#ifdef CONFIG_ADEOS
+	movl %esp,%eax		# Use a "soon-to-be-clobbered" reg
+	pushl %eax
+	call SYMBOL_NAME(__adeos_enter_syscall)
+	addl $4,%esp
+#endif /* CONFIG_ADEOS */
 	movl EIP(%esp),%eax	# due to call gates, this is eflags, not eip..
 	movl CS(%esp),%edx	# this is eip..
 	movl EFLAGS(%esp),%ecx	# and this is cs..
@@ -150,6 +156,9 @@
 	pushl $0x7
 	call *%edx
 	addl $4, %esp
+#ifdef CONFIG_ADEOS
+	call SYMBOL_NAME(__adeos_exit_syscall)
+#endif /* CONFIG_ADEOS */
 	popl %eax
 	jmp ret_from_sys_call
 
@@ -157,6 +166,12 @@
 	pushfl			# We get a different stack layout with call gates,
 	pushl %eax		# which has to be cleaned up later..
 	SAVE_ALL
+#ifdef CONFIG_ADEOS
+	movl %esp,%eax		# Use a "soon-to-be-clobbered" reg
+	pushl %eax
+	call SYMBOL_NAME(__adeos_enter_syscall)
+	addl $4,%esp
+#endif /* CONFIG_ADEOS */
 	movl EIP(%esp),%eax	# due to call gates, this is eflags, not eip..
 	movl CS(%esp),%edx	# this is eip..
 	movl EFLAGS(%esp),%ecx	# and this is cs..
@@ -171,11 +186,17 @@
 	pushl $0x27
 	call *%edx
 	addl $4, %esp
+#ifdef CONFIG_ADEOS
+	call SYMBOL_NAME(__adeos_exit_syscall)
+#endif /* CONFIG_ADEOS */
 	popl %eax
 	jmp ret_from_sys_call
 
 
 ENTRY(ret_from_fork)
+#ifdef CONFIG_ADEOS
+	sti
+#endif /* CONFIG_ADEOS */	
 	pushl %ebx
 	call SYMBOL_NAME(schedule_tail)
 	addl $4, %esp
@@ -194,6 +215,14 @@
 ENTRY(system_call)
 	pushl %eax			# save orig_eax
 	SAVE_ALL
+#ifdef CONFIG_ADEOS
+	pushl %eax
+	movl %esp,%ebx			# Use a "soon-to-be-clobbered" reg
+	pushl %ebx
+	call SYMBOL_NAME(__adeos_enter_syscall)
+	addl $4,%esp
+	popl  %eax
+#endif /* CONFIG_ADEOS */
 	GET_CURRENT(%ebx)
 	testb $0x02,tsk_ptrace(%ebx)	# PT_TRACESYS
 	jne tracesys
@@ -201,18 +230,32 @@
 	jae badsys
 	call *SYMBOL_NAME(sys_call_table)(,%eax,4)
 	movl %eax,EAX(%esp)		# save the return value
+#ifdef CONFIG_ADEOS
+	call SYMBOL_NAME(__adeos_exit_syscall)
+#endif /* CONFIG_ADEOS */
 ENTRY(ret_from_sys_call)
-	cli				# need_resched and signals atomic test
+#ifdef CONFIG_ADEOS
+	call SYMBOL_NAME(ipipe_stall_root)
+#else /* !CONFIG_ADEOS */
+	cli
+#endif /* CONFIG_ADEOS */
 	cmpl $0,need_resched(%ebx)
 	jne reschedule
 	cmpl $0,sigpending(%ebx)
 	jne signal_return
+#ifdef CONFIG_ADEOS
+	call SYMBOL_NAME(ipipe_unstall_root)
+#endif /* CONFIG_ADEOS */
 restore_all:
 	RESTORE_ALL
 
 	ALIGN
 signal_return:
-	sti				# we can get here from an interrupt handler
+#ifdef CONFIG_ADEOS
+	call SYMBOL_NAME(ipipe_unstall_root)
+#else /* !CONFIG_ADEOS */
+	sti
+#endif /* CONFIG_ADEOS */
 	testl $(VM_MASK),EFLAGS(%esp)
 	movl %esp,%eax
 	jne v86_signal_return
diff -Naur linux-2.4.19-orig/arch/i386/kernel/i386_ksyms.c linux-2.4.19-adeos/arch/i386/kernel/i386_ksyms.c
--- linux-2.4.19-orig/arch/i386/kernel/i386_ksyms.c	Sat Aug  3 02:39:42 2002
+++ linux-2.4.19-adeos/arch/i386/kernel/i386_ksyms.c	Thu Oct 10 20:01:15 2002
@@ -179,3 +179,34 @@
 #ifdef CONFIG_MULTIQUAD
 EXPORT_SYMBOL(xquad_portio);
 #endif
+
+#ifdef CONFIG_ADEOS
+EXPORT_SYMBOL(ipipe_sync_irqs);
+EXPORT_SYMBOL(ipipe_resync_from);
+EXPORT_SYMBOL(ipipe_unstall_root);
+EXPORT_SYMBOL(ipipe_stall_root);
+EXPORT_SYMBOL(ipipe_restore_root);
+/* The following are per-platform convenience exports which might be
+   needed by some Adeos domains loaded as kernel modules. */
+extern irq_desc_t irq_desc[];
+EXPORT_SYMBOL(irq_desc);
+extern struct desc_struct idt_table[];
+EXPORT_SYMBOL(idt_table);
+extern void ret_from_intr(void);
+EXPORT_SYMBOL(ret_from_intr);
+extern struct tty_driver console_driver;
+EXPORT_SYMBOL(console_driver);
+extern void (*kd_mksound)(unsigned int hz, unsigned int ticks);
+EXPORT_SYMBOL(kd_mksound);
+#ifdef CONFIG_SMP
+EXPORT_SYMBOL(cpu_tlbstate);
+#ifdef CONFIG_MULTIQUAD
+EXPORT_SYMBOL(logical_apicid_2_cpu);
+#else
+EXPORT_SYMBOL(physical_apicid_2_cpu);
+#endif /* CONFIG_MULTIQUAD */
+#endif /* CONFIG_SMP */
+EXPORT_SYMBOL(set_ldt_desc);
+EXPORT_SYMBOL(default_ldt);
+EXPORT_SYMBOL(__switch_to);
+#endif /* CONFIG_ADEOS */
diff -Naur linux-2.4.19-orig/arch/i386/kernel/i8259.c linux-2.4.19-adeos/arch/i386/kernel/i8259.c
--- linux-2.4.19-orig/arch/i386/kernel/i8259.c	Tue Sep 18 08:03:09 2001
+++ linux-2.4.19-adeos/arch/i386/kernel/i8259.c	Thu Oct 10 20:01:15 2002
@@ -265,6 +265,36 @@
  */
 void mask_and_ack_8259A(unsigned int irq)
 {
+#ifdef CONFIG_ADEOS
+	unsigned int irqmask = 1 << irq;
+
+	spin_lock(&i8259A_lock);
+
+	if (cached_irq_mask & irqmask)
+		goto spurious_8259A_irq;
+
+	if (irq == 0) {
+	    /* Fast timer ack -- don't mask
+	      (unless supposedly spurious) */
+	    outb(0x20,0x20);
+	    spin_unlock(&i8259A_lock);
+	    return;
+	}
+
+	cached_irq_mask |= irqmask;
+
+handle_real_irq:
+	if (irq & 8) {
+		outb(cached_A1,0xA1);
+		outb(0x60+(irq&7),0xA0);/* 'Specific EOI' to slave */
+		outb(0x62,0x20);	/* 'Specific EOI' to master-IRQ2 */
+	} else {
+		outb(cached_21,0x21);
+		outb(0x60+irq,0x20);	/* 'Specific EOI' to master */
+	}
+	spin_unlock(&i8259A_lock);
+	return;
+#else /* !CONFIG_ADEOS */
 	unsigned int irqmask = 1 << irq;
 	unsigned long flags;
 
@@ -301,6 +331,7 @@
 	}
 	spin_unlock_irqrestore(&i8259A_lock, flags);
 	return;
+#endif /* CONFIG_ADEOS */
 
 spurious_8259A_irq:
 	/*
diff -Naur linux-2.4.19-orig/arch/i386/kernel/io_apic.c linux-2.4.19-adeos/arch/i386/kernel/io_apic.c
--- linux-2.4.19-orig/arch/i386/kernel/io_apic.c	Sat Aug  3 02:39:42 2002
+++ linux-2.4.19-adeos/arch/i386/kernel/io_apic.c	Sat Oct 12 12:23:32 2002
@@ -1207,6 +1207,25 @@
  * interrupt for real. This prevents IRQ storms from unhandled
  * devices.
  */
+
+#ifdef CONFIG_ADEOS
+
+static void ack_edge_ioapic_irq (unsigned irq)
+
+{
+    if ((irq_desc[irq].status & (IRQ_PENDING | IRQ_DISABLED)) == (IRQ_PENDING | IRQ_DISABLED))
+	{
+	unsigned long flags;
+	ipipe_hw_spin_lock(&ioapic_lock,flags);
+	__mask_IO_APIC_irq(irq);
+	ipipe_hw_spin_unlock(&ioapic_lock,flags);
+	}
+
+    ack_APIC_irq();
+}
+
+#else /* !CONFIG_ADEOS */
+
 static void ack_edge_ioapic_irq(unsigned int irq)
 {
 	if ((irq_desc[irq].status & (IRQ_PENDING | IRQ_DISABLED))
@@ -1215,6 +1234,8 @@
 	ack_APIC_irq();
 }
 
+#endif /* CONFIG_ADEOS */
+
 static void end_edge_ioapic_irq (unsigned int i) { /* nothing */ }
 
 
@@ -1243,6 +1264,65 @@
 #define enable_level_ioapic_irq		unmask_IO_APIC_irq
 #define disable_level_ioapic_irq	mask_IO_APIC_irq
 
+#ifdef CONFIG_ADEOS
+
+/* The standard Linux implementation for acknowledging IO-APIC
+   interrupts has been changed in order to guarantee that low priority
+   IRQs won't be delayed waiting for a high priority interrupt handler
+   to call end_level_ioapic_irq(). Therefore we immediately ack in
+   mask_and_ack_level_ioapic_irq(), still handling the 82093AA bugous
+   edge case. */
+
+static unsigned long bugous_edge_triggers;
+
+static void end_level_ioapic_irq (unsigned irq)
+
+{
+    if (test_and_clear_bit(irq,&bugous_edge_triggers))
+	{
+#ifdef APIC_MISMATCH_DEBUG
+	atomic_inc(&irq_mis_count);
+#endif
+	spin_lock(&ioapic_lock);
+	__unmask_and_level_IO_APIC_irq(irq);
+	spin_unlock(&ioapic_lock);
+	}
+    else
+	{
+	spin_lock(&ioapic_lock);
+	__unmask_IO_APIC_irq(irq);
+	spin_unlock(&ioapic_lock);
+	}
+}
+
+static void mask_and_ack_level_ioapic_irq (unsigned irq)
+
+{
+    unsigned long v;
+    int i;
+
+    i = IO_APIC_VECTOR(irq);
+    v = apic_read(APIC_TMR + ((i & ~0x1f) >> 1));
+
+    if (!(v & (1 << (i & 0x1f))))
+	{
+	set_bit(irq,&bugous_edge_triggers);
+	spin_lock(&ioapic_lock);
+	__mask_and_edge_IO_APIC_irq(irq);
+	spin_unlock(&ioapic_lock);
+	}
+    else
+	{
+	spin_lock(&ioapic_lock);
+	__mask_IO_APIC_irq(irq);
+	spin_unlock(&ioapic_lock);
+	}
+
+    ack_APIC_irq();
+}
+
+#else /* !CONFIG_ADEOS */
+
 static void end_level_ioapic_irq (unsigned int irq)
 {
 	unsigned long v;
@@ -1303,6 +1383,8 @@
 }
 
 static void mask_and_ack_level_ioapic_irq (unsigned int irq) { /* nothing */ }
+
+#endif /* CONFIG_ADEOS */
 
 static void set_ioapic_affinity (unsigned int irq, unsigned long mask)
 {
diff -Naur linux-2.4.19-orig/arch/i386/kernel/ipipe.c linux-2.4.19-adeos/arch/i386/kernel/ipipe.c
--- linux-2.4.19-orig/arch/i386/kernel/ipipe.c	Thu Jan  1 01:00:00 1970
+++ linux-2.4.19-adeos/arch/i386/kernel/ipipe.c	Tue Oct 22 19:17:30 2002
@@ -0,0 +1,1122 @@
+/*
+ *   linux/arch/i386/kernel/ipipe.c
+ *
+ *   Copyright (C) 2002 Philippe Gerum.
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
+ *   USA; either version 2 of the License, or (at your option) any later
+ *   version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *   This code implements the ADEOS interrupt pipeline mechanism.
+ */
+
+#include <linux/config.h>
+#include <linux/kernel.h>
+#include <linux/smp.h>
+#include <linux/sched.h>
+#include <linux/irq.h>
+#include <asm/system.h>
+#include <asm/hw_irq.h>
+#include <asm/irq.h>
+#include <asm/desc.h>
+#ifdef CONFIG_X86_LOCAL_APIC
+#include <asm/fixmap.h>
+#include <asm/bitops.h>
+#include <asm/mpspec.h>
+#ifdef CONFIG_X86_IO_APIC
+#include <asm/io_apic.h>
+#endif /* CONFIG_X86_IO_APIC */
+#include <asm/apic.h>
+#endif /* CONFIG_X86_LOCAL_APIC */
+
+extern struct desc_struct idt_table[];
+
+extern spinlock_t adeos_pipelock;
+
+extern struct list_head adeos_pipeline;
+
+static struct hw_interrupt_type ipipe_std_irq_dtype[NR_IRQS];
+
+static unsigned long ipipe_virtual_irq_map;
+
+/* Lifted from traps.c */ 
+#define ipipe_set_gate(gate_addr,type,dpl,addr)  \
+do { \
+  int __d0, __d1; \
+  __asm__ __volatile__ ("movw %%dx,%%ax\n\t" \
+	"movw %4,%%dx\n\t" \
+	"movl %%eax,%0\n\t" \
+	"movl %%edx,%1" \
+	:"=m" (*((long *) (gate_addr))), \
+	 "=m" (*(1+(long *) (gate_addr))), "=&a" (__d0), "=&d" (__d1) \
+	:"i" ((short) (0x8000+(dpl<<13)+(type<<8))), \
+	 "3" ((char *) (addr)),"2" (__KERNEL_CS << 16)); \
+} while (0)
+
+#define ipipe_get_gate_addr(v) \
+	((void *)((idt_table[v].b & 0xffff0000)|(idt_table[v].a & 0xffff)))
+
+#define ipipe_set_irq_gate(vector,addr) \
+ipipe_set_gate(idt_table+vector,14,0,addr)
+
+#define ipipe_set_trap_gate(vector,addr) \
+ipipe_set_gate(idt_table+vector,15,0,addr)
+
+#define ipipe_set_sys_gate(vector,addr) \
+ipipe_set_gate(idt_table+vector,15,3,addr)
+
+#define BUILD_IRQ_BODY() \
+__asm__( \
+	"\n" __ALIGN_STR"\n" \
+        SYMBOL_NAME_STR(ipipe_irq_common) ":\n\t" \
+	"pushl %es\n\t" \
+	"pushl %ds\n\t" \
+	"pushl %eax\n\t" \
+	"pushl %ebp\n\t" \
+	"pushl %edi\n\t" \
+	"pushl %esi\n\t" \
+	"pushl %edx\n\t" \
+	"pushl %ecx\n\t" \
+	"pushl %ebx\n\t" \
+	"movl $" STR(__KERNEL_DS) ",%edx\n\t" \
+	"movl %edx,%ds\n\t" \
+	"movl %edx,%es\n\t" \
+	"call " SYMBOL_NAME_STR(ipipe_handle_irq) "\n\t" \
+	"testl %eax,%eax\n\t" \
+	"jnz  1f\n\t" \
+        "popl %ebx\n\t" \
+	"popl %ecx\n\t" \
+	"popl %edx\n\t" \
+	"popl %esi\n\t" \
+	"popl %edi\n\t" \
+	"popl %ebp\n\t" \
+	"popl %eax\n\t" \
+	"popl %ds\n\t" \
+	"popl %es\n\t" \
+	"addl $4,%esp\n\t" \
+        "iret\n\t" \
+        "1: cld\n\t" \
+        "jmp " SYMBOL_NAME_STR(ret_from_intr) "\n");
+
+#define BUILD_IRQ_PROTO(irq)  ipipe_irq_##irq(void)
+#define BUILD_1_IRQ(irq) \
+asmlinkage void BUILD_IRQ_PROTO(irq); \
+__asm__( \
+	"\n" __ALIGN_STR"\n" \
+        SYMBOL_NAME_STR(ipipe_irq_) #irq ":\n\t" \
+	"pushl $"#irq"-256 \n\t" \
+	"jmp " SYMBOL_NAME_STR(ipipe_irq_common) "\n");
+
+#define BUILD_IRQ_N(x,y) \
+BUILD_1_IRQ(x##y)
+
+#define BUILD_16_IRQS(x) \
+BUILD_IRQ_N(x,0)  BUILD_IRQ_N(x,1)  BUILD_IRQ_N(x,2)  BUILD_IRQ_N(x,3) \
+BUILD_IRQ_N(x,4)  BUILD_IRQ_N(x,5)  BUILD_IRQ_N(x,6)  BUILD_IRQ_N(x,7) \
+BUILD_IRQ_N(x,8)  BUILD_IRQ_N(x,9)  BUILD_IRQ_N(x,a)  BUILD_IRQ_N(x,b) \
+BUILD_IRQ_N(x,c)  BUILD_IRQ_N(x,d)  BUILD_IRQ_N(x,e)  BUILD_IRQ_N(x,f)
+
+BUILD_IRQ_BODY();
+
+BUILD_16_IRQS(0x0)
+#if defined(CONFIG_X86_LOCAL_APIC) || defined(CONFIG_X86_IO_APIC)
+BUILD_16_IRQS(0x1)  BUILD_16_IRQS(0x2)  BUILD_16_IRQS(0x3) BUILD_16_IRQS(0x4)
+BUILD_16_IRQS(0x5)  BUILD_16_IRQS(0x6)  BUILD_16_IRQS(0x7) BUILD_16_IRQS(0x8)
+BUILD_16_IRQS(0x9)  BUILD_16_IRQS(0xa)  BUILD_16_IRQS(0xb) BUILD_16_IRQS(0xc)
+BUILD_16_IRQS(0xd)
+#endif /* CONFIG_X86_LOCAL_APIC || CONFIG_X86_IO_APIC */
+
+#define LIST_1_IRQ(irq) &ipipe_irq_ ## irq
+
+#define LIST_IRQ_N(x,y) \
+LIST_1_IRQ(x##y)
+
+#define LIST_16_IRQS(x) \
+LIST_IRQ_N(x,0),  LIST_IRQ_N(x,1),  LIST_IRQ_N(x,2), LIST_IRQ_N(x,3), \
+LIST_IRQ_N(x,4),  LIST_IRQ_N(x,5),  LIST_IRQ_N(x,6), LIST_IRQ_N(x,7), \
+LIST_IRQ_N(x,8),  LIST_IRQ_N(x,9),  LIST_IRQ_N(x,a), LIST_IRQ_N(x,b), \
+LIST_IRQ_N(x,c),  LIST_IRQ_N(x,d),  LIST_IRQ_N(x,e), LIST_IRQ_N(x,f)
+
+static void (*ipipe_irq_trampolines[])(void) = {
+    LIST_16_IRQS(0x0),
+#if defined(CONFIG_X86_LOCAL_APIC) || defined(CONFIG_X86_IO_APIC)
+    LIST_16_IRQS(0x1), LIST_16_IRQS(0x2), LIST_16_IRQS(0x3), LIST_16_IRQS(0x4),
+    LIST_16_IRQS(0x5), LIST_16_IRQS(0x6), LIST_16_IRQS(0x7), LIST_16_IRQS(0x8),
+    LIST_16_IRQS(0x9), LIST_16_IRQS(0xa), LIST_16_IRQS(0xb), LIST_16_IRQS(0xc),
+    LIST_16_IRQS(0xd)
+#endif /* CONFIG_X86_LOCAL_APIC || CONFIG_X86_IO_APIC */
+};
+
+#define ipipe_call_asm_irq_handler(adp,irq) \
+   __asm__ __volatile__ ("pushfl\n\t" \
+                         "push %%cs\n\t" \
+                         "call *%1\n" \
+			 : /* no output */ \
+			 : "a" (irq), "m" ((adp)->irqs[irq].handler))
+
+#define ipipe_call_c_irq_handler(adp,irq) \
+   __asm__ __volatile__ ("pushl %%ebp\n\t" \
+	                 "pushl %%edi\n\t" \
+                      	 "pushl %%esi\n\t" \
+	                 "pushl %%edx\n\t" \
+                         "pushl %%ecx\n\t" \
+	                 "pushl %%ebx\n\t" \
+                         "pushl %%eax\n\t" \
+                         "call *%1\n\t" \
+                         "addl $4,%%esp\n\t" \
+                         "popl %%ebx\n\t" \
+                         "popl %%ecx\n\t" \
+	                 "popl %%edx\n\t" \
+	                 "popl %%esi\n\t" \
+	                 "popl %%edi\n\t" \
+	                 "popl %%ebp\n" \
+			 : /* no output */ \
+			 : "a" (irq), "m" ((adp)->irqs[irq].handler))
+
+#define BUILD_TRAP_PROTO(trapnr)  ipipe_trap_##trapnr(void)
+
+#define BUILD_TRAP_ERRCODE(trapnr) \
+asmlinkage void BUILD_TRAP_PROTO(trapnr); \
+__asm__ ( \
+	"\n" __ALIGN_STR"\n\t" \
+        SYMBOL_NAME_STR(ipipe_trap_) #trapnr ":\n\t" \
+        "cld\n\t" \
+        "pushl %es\n\t" \
+        "pushl %ds\n\t" \
+        "pushl %eax\n\t" \
+        "pushl %ebp\n\t" \
+        "pushl %edi\n\t" \
+        "pushl %esi\n\t" \
+        "pushl %edx\n\t" \
+        "pushl %ecx\n\t" \
+        "pushl %ebx\n\t" \
+        "movl $" STR(__KERNEL_DS) ",%edx\n\t" \
+	"mov %dx,%ds\n\t" \
+	"mov %dx,%es\n\t" \
+        "movl ("SYMBOL_NAME_STR(__adeos_event_monitors + 4 * trapnr)"),%eax\n\t" \
+	"testl %eax,%eax\n\t" \
+	"jz 1f\n\t" \
+	"movl %esp,%eax\n\t" \
+        "pushl %eax\n\t" \
+	"pushl $"#trapnr"\n\t" \
+        "call " SYMBOL_NAME_STR(ipipe_handle_event) "\n\t" \
+	"addl $8,%esp\n\t" \
+	"testl %eax,%eax\n\t" \
+"1:      popl %ebx\n\t" \
+        "popl %ecx\n\t" \
+	"popl %edx\n\t" \
+        "popl %esi\n\t" \
+        "popl %edi\n\t" \
+	"popl %ebp\n\t" \
+	"jz 2f\n\t" \
+	"popl %eax\n\t" \
+	"popl %ds\n\t" \
+	"popl %es\n\t" \
+	"addl $4,%esp\n\t" \
+	"iret\n" \
+"2:
+         movl ("SYMBOL_NAME_STR(ipipe_root_traps + 4 * trapnr)"),%eax\n\t" \
+	"movl 8(%esp),%es\n\t" \
+	"movl %eax,8(%esp)\n\t" \
+	"popl %eax\n\t" \
+	"popl %ds\n\t" \
+	"ret\n");
+
+#define BUILD_TRAP_NOERRCODE(trapnr) \
+asmlinkage void BUILD_TRAP_PROTO(trapnr); \
+__asm__ ( \
+	"\n" __ALIGN_STR"\n\t" \
+        SYMBOL_NAME_STR(ipipe_trap_) #trapnr ":\n\t" \
+        "cld\n\t" \
+        "pushl $0\n\t" \
+        "pushl %es\n\t" \
+        "pushl %ds\n\t" \
+        "pushl %eax\n\t" \
+        "pushl %ebp\n\t" \
+        "pushl %edi\n\t" \
+        "pushl %esi\n\t" \
+        "pushl %edx\n\t" \
+        "pushl %ecx\n\t" \
+        "pushl %ebx\n\t" \
+        "movl $" STR(__KERNEL_DS) ",%edx\n\t" \
+	"mov %dx,%ds\n\t" \
+	"mov %dx,%es\n\t" \
+        "movl ("SYMBOL_NAME_STR(__adeos_event_monitors + 4 * trapnr)"),%eax\n\t" \
+	"testl %eax,%eax\n\t" \
+	"jz 1f\n\t" \
+	"movl %esp,%eax\n\t" \
+        "pushl %eax\n\t" \
+	"pushl $"#trapnr"\n\t" \
+        "call " SYMBOL_NAME_STR(ipipe_handle_event) "\n\t" \
+	"addl $8,%esp\n\t" \
+	"testl %eax,%eax\n\t" \
+"1:      popl %ebx\n\t" \
+        "popl %ecx\n\t" \
+	"popl %edx\n\t" \
+        "popl %esi\n\t" \
+        "popl %edi\n\t" \
+	"popl %ebp\n\t" \
+	"jz 2f\n\t" \
+	"popl %eax\n\t" \
+	"popl %ds\n\t" \
+	"popl %es\n\t" \
+	"addl $4,%esp\n\t" \
+	"iret\n" \
+"2:
+         movl ("SYMBOL_NAME_STR(ipipe_root_traps + 4 * trapnr)"),%eax\n\t" \
+	"movl %eax,12(%esp)\n\t" \
+	"popl %eax\n\t" \
+	"popl %ds\n\t" \
+	"popl %es\n\t" \
+	"ret\n");
+
+void (*ipipe_root_traps[ADEOS_NR_FAULTS])(void);
+
+BUILD_TRAP_NOERRCODE(0x0)   BUILD_TRAP_NOERRCODE(0x1)   BUILD_TRAP_NOERRCODE(0x2)
+BUILD_TRAP_NOERRCODE(0x3)   BUILD_TRAP_NOERRCODE(0x4)   BUILD_TRAP_NOERRCODE(0x5)
+BUILD_TRAP_NOERRCODE(0x6)   BUILD_TRAP_NOERRCODE(0x7)   BUILD_TRAP_ERRCODE(0x8)
+BUILD_TRAP_NOERRCODE(0x9)   BUILD_TRAP_ERRCODE(0xa)     BUILD_TRAP_ERRCODE(0xb)
+BUILD_TRAP_ERRCODE(0xc)     BUILD_TRAP_ERRCODE(0xd)     BUILD_TRAP_ERRCODE(0xe)
+BUILD_TRAP_NOERRCODE(0xf)   BUILD_TRAP_NOERRCODE(0x10)  BUILD_TRAP_ERRCODE(0x11)
+BUILD_TRAP_NOERRCODE(0x12)  BUILD_TRAP_NOERRCODE(0x13)  BUILD_TRAP_ERRCODE(0x14)
+BUILD_TRAP_ERRCODE(0x15)    BUILD_TRAP_ERRCODE(0x16)    BUILD_TRAP_ERRCODE(0x17)
+BUILD_TRAP_ERRCODE(0x18)    BUILD_TRAP_ERRCODE(0x19)    BUILD_TRAP_ERRCODE(0x1a)
+BUILD_TRAP_ERRCODE(0x1b)    BUILD_TRAP_ERRCODE(0x1c)    BUILD_TRAP_ERRCODE(0x1d)
+BUILD_TRAP_ERRCODE(0x1e)    BUILD_TRAP_ERRCODE(0x1f)
+
+#define LIST_TRAP(trapnr) &ipipe_trap_ ## trapnr
+
+void (*ipipe_trap_trampolines[])(void) = {
+    LIST_TRAP(0x0), LIST_TRAP(0x1), LIST_TRAP(0x2), LIST_TRAP(0x3),
+    LIST_TRAP(0x4), LIST_TRAP(0x5), LIST_TRAP(0x6), LIST_TRAP(0x7),
+    LIST_TRAP(0x8), LIST_TRAP(0x9), LIST_TRAP(0xa), LIST_TRAP(0xb),
+    LIST_TRAP(0xc), LIST_TRAP(0xd), LIST_TRAP(0xe), LIST_TRAP(0xf),
+    LIST_TRAP(0x10), LIST_TRAP(0x11), LIST_TRAP(0x12), LIST_TRAP(0x13),
+    LIST_TRAP(0x14), LIST_TRAP(0x15), LIST_TRAP(0x16), LIST_TRAP(0x17),
+    LIST_TRAP(0x18), LIST_TRAP(0x19), LIST_TRAP(0x1a), LIST_TRAP(0x1b),
+    LIST_TRAP(0x1c), LIST_TRAP(0x1d), LIST_TRAP(0x1e), LIST_TRAP(0x1f)
+};
+
+static __inline__ unsigned long ffnz (unsigned long word) {
+    /* Derived from bitops.h's ffs() */
+    __asm__("bsfl %1, %0"
+	    : "=r" (word)
+	    : "r"  (word));
+    return word;
+}
+
+int ipipe_ack_common_irq (unsigned irq)
+
+{
+    irq_desc_t *desc = irq_desc + irq;
+    desc->handler->ack(irq);
+    return 1;
+}
+
+int ipipe_ack_system_irq (unsigned irq) {
+#ifdef CONFIG_X86_LOCAL_APIC
+    ack_APIC_irq();
+#endif /* CONFIG_X86_LOCAL_APIC */
+    return 1;
+}
+
+unsigned ipipe_interpose_irq_startup (unsigned irq)
+
+{
+    unsigned long adflags, hwflags;
+    ipipe_declare_cpuid;
+    unsigned s;
+
+    adflags = adeos_test_and_stall_ipipe();
+    ipipe_hw_save_flags_and_cli(hwflags);
+    s = ipipe_std_irq_dtype[irq].startup(irq);
+    ipipe_hw_restore_flags(hwflags);
+    adeos_restore_ipipe_nosync(adp_cpu_current[cpuid],adflags,cpuid);
+
+    return s;
+}
+
+void ipipe_interpose_irq_shutdown (unsigned irq)
+
+{
+    unsigned long adflags, hwflags;
+    ipipe_declare_cpuid;
+
+    adflags = adeos_test_and_stall_ipipe();
+    ipipe_hw_save_flags_and_cli(hwflags);
+    ipipe_std_irq_dtype[irq].shutdown(irq);
+    ipipe_hw_restore_flags(hwflags);
+    adeos_restore_ipipe_nosync(adp_cpu_current[cpuid],adflags,cpuid);
+}
+
+void ipipe_interpose_irq_enable (unsigned irq)
+
+{
+    unsigned long adflags, hwflags;
+    ipipe_declare_cpuid;
+
+    adflags = adeos_test_and_stall_ipipe();
+    ipipe_hw_save_flags_and_cli(hwflags);
+    ipipe_std_irq_dtype[irq].enable(irq);
+    ipipe_hw_restore_flags(hwflags);
+    adeos_restore_ipipe_nosync(adp_cpu_current[cpuid],adflags,cpuid);
+}
+
+void ipipe_interpose_irq_disable (unsigned irq)
+
+{
+    unsigned long adflags, hwflags;
+    ipipe_declare_cpuid;
+
+    adflags = adeos_test_and_stall_ipipe();
+    ipipe_hw_save_flags_and_cli(hwflags);
+    ipipe_std_irq_dtype[irq].disable(irq);
+    ipipe_hw_restore_flags(hwflags);
+    adeos_restore_ipipe_nosync(adp_cpu_current[cpuid],adflags,cpuid);
+}
+
+void ipipe_interpose_irq_end (unsigned irq)
+
+{
+    unsigned long adflags, hwflags;
+    ipipe_declare_cpuid;
+
+    adflags = adeos_test_and_stall_ipipe();
+    ipipe_hw_save_flags_and_cli(hwflags);
+    ipipe_std_irq_dtype[irq].end(irq);
+    ipipe_hw_restore_flags(hwflags);
+    adeos_restore_ipipe_nosync(adp_cpu_current[cpuid],adflags,cpuid);
+}
+
+void ipipe_interpose_irq_affinity (unsigned irq, unsigned long mask)
+
+{
+    unsigned long adflags, hwflags;
+    ipipe_declare_cpuid;
+
+    adflags = adeos_test_and_stall_ipipe();
+    ipipe_hw_save_flags_and_cli(hwflags);
+    ipipe_std_irq_dtype[irq].set_affinity(irq,mask);
+    ipipe_hw_restore_flags(hwflags);
+    adeos_restore_ipipe_nosync(adp_cpu_current[cpuid],adflags,cpuid);
+}
+
+/* ipipe_takeover_root_domain() -- Take over the interrupt control
+   from the root domain (i.e. Linux). After this routine has returned,
+   all interrupts go through the pipeline. This code is expected to be
+   called by the CPU initializing the system, thus no spin locks are
+   held here. */
+
+void ipipe_takeover_root_domain (void)
+
+{
+    unsigned vector, irq;
+    unsigned long flags;
+    void *addr;
+
+    ipipe_hw_save_flags_and_cli(flags);
+
+    /* First, grab the ISA and IO-APIC interrupts. */
+
+    for (irq = 0; irq < NR_IRQS && irq + FIRST_EXTERNAL_VECTOR < FIRST_SYSTEM_VECTOR; irq++)
+	{
+#ifdef CONFIG_X86_IO_APIC
+	if (IO_APIC_IRQ(irq))
+	    {
+	    vector = IO_APIC_VECTOR(irq);
+
+	    if (vector == 0)
+		continue;
+	    }
+	else
+#endif /* CONFIG_X86_IO_APIC */
+	    {
+	    vector = irq + FIRST_EXTERNAL_VECTOR;
+
+	    if (vector == SYSCALL_VECTOR)
+		continue;
+	    }
+
+	addr = ipipe_get_gate_addr(vector);
+
+	ipipe_hook_irq(irq,
+		       (void (*)(unsigned))addr,
+		       &ipipe_ack_common_irq,
+		       IPIPE_CALLASM_MASK|IPIPE_HANDLE_MASK|IPIPE_PASS_MASK);
+
+	ipipe_set_irq_gate(vector,ipipe_irq_trampolines[irq]);
+	}
+
+    /* Interpose on the IRQ control routines so we can make them
+       atomic using hw masking and prevent the interrupt log from
+       being untimely flushed. Since we don't want to be too smart
+       about what's going on into irq.c and we want to change only
+       some of the controller members, let's be dumb and interpose the
+       rough way. */
+
+    for (irq = 0; irq < NR_IRQS; irq++)
+	ipipe_std_irq_dtype[irq] = *irq_desc[irq].handler;
+
+    /* The original controller structs are often shared, so we first
+       save them all before changing any of them. Notice that we don't
+       redirect the ack handler since the relevant XT-PIC/IO-APIC
+       management code is already Adeos-aware. */
+
+    for (irq = 0; irq < NR_IRQS; irq++)
+	{
+	irq_desc[irq].handler->startup = &ipipe_interpose_irq_startup;
+	irq_desc[irq].handler->shutdown = &ipipe_interpose_irq_shutdown;
+	irq_desc[irq].handler->enable = &ipipe_interpose_irq_enable;
+	irq_desc[irq].handler->disable = &ipipe_interpose_irq_disable;
+	irq_desc[irq].handler->end = &ipipe_interpose_irq_end;
+
+	if (irq_desc[irq].handler->set_affinity != NULL)
+	    irq_desc[irq].handler->set_affinity = &ipipe_interpose_irq_affinity;
+	}
+
+#ifdef CONFIG_X86_IO_APIC
+
+    /* We only need to hook the APIC timer vector in case the IO/APICs
+       are used. */
+
+    addr = ipipe_get_gate_addr(LOCAL_TIMER_VECTOR);
+
+    ipipe_hook_irq(LOCAL_TIMER_VECTOR - FIRST_EXTERNAL_VECTOR,
+		   (void (*)(unsigned))addr,
+		   &ipipe_ack_system_irq,
+		   IPIPE_CALLASM_MASK|IPIPE_HANDLE_MASK|IPIPE_PASS_MASK);
+
+    ipipe_set_irq_gate(LOCAL_TIMER_VECTOR,
+		       ipipe_irq_trampolines[LOCAL_TIMER_VECTOR - FIRST_EXTERNAL_VECTOR]);
+
+#endif /* CONFIG_X86_IO_APIC */
+
+#ifdef CONFIG_SMP
+    /* Notice that INVALIDATE_TLB_VECTOR is not virtualized because
+      it's very time critical, it's also vital for the root domain and
+      its handler won't cause any perceptible delays in processing.
+      SPURIOUS_APIC_VECTOR and ERROR_APIC_VECTOR are not virtualized
+      either since they are not expected to happen under Linux's SMP
+      architecture. If they do, correct interrupt prioritization won't
+      be the major problem to solve anyway... :o> */
+
+    addr = ipipe_get_gate_addr(RESCHEDULE_VECTOR);
+
+    ipipe_hook_irq(RESCHEDULE_VECTOR - FIRST_EXTERNAL_VECTOR,
+		   (void (*)(unsigned))addr,
+		   &ipipe_ack_system_irq,
+		   IPIPE_CALLASM_MASK|IPIPE_HANDLE_MASK|IPIPE_PASS_MASK);
+
+    ipipe_set_irq_gate(RESCHEDULE_VECTOR,
+		       ipipe_irq_trampolines[RESCHEDULE_VECTOR - FIRST_EXTERNAL_VECTOR]);
+
+    addr = ipipe_get_gate_addr(CALL_FUNCTION_VECTOR);
+
+    ipipe_hook_irq(CALL_FUNCTION_VECTOR - FIRST_EXTERNAL_VECTOR,
+		   (void (*)(unsigned))addr,
+		   &ipipe_ack_system_irq,
+		   IPIPE_CALLASM_MASK|IPIPE_HANDLE_MASK|IPIPE_PASS_MASK);
+
+    ipipe_set_irq_gate(CALL_FUNCTION_VECTOR,
+		       ipipe_irq_trampolines[CALL_FUNCTION_VECTOR - FIRST_EXTERNAL_VECTOR]);
+
+    ipipe_set_irq_gate(ADEOS_CRITICAL_VECTOR,
+		       ipipe_irq_trampolines[ADEOS_CRITICAL_IPI]);
+
+    ipipe_set_irq_gate(ADEOS_SERVICE_VECTOR,
+		       ipipe_irq_trampolines[ADEOS_SERVICE_IPI]);
+
+#endif /* CONFIG_SMP */
+
+    /* Redirect traps and exceptions (but NMI). */
+
+    for (vector = 0; vector < ADEOS_NR_FAULTS; vector++)
+	ipipe_root_traps[vector] = (void (*)(void))ipipe_get_gate_addr(vector);
+
+    ipipe_set_trap_gate(0,ipipe_trap_trampolines[0]);
+    ipipe_set_trap_gate(1,ipipe_trap_trampolines[1]);
+    ipipe_set_sys_gate(3,ipipe_trap_trampolines[3]);
+    ipipe_set_sys_gate(4,ipipe_trap_trampolines[4]);
+    ipipe_set_sys_gate(5,ipipe_trap_trampolines[5]);
+    ipipe_set_trap_gate(6,ipipe_trap_trampolines[6]);
+    ipipe_set_trap_gate(7,ipipe_trap_trampolines[7]);
+    ipipe_set_trap_gate(8,ipipe_trap_trampolines[8]);
+    ipipe_set_trap_gate(9,ipipe_trap_trampolines[9]);
+    ipipe_set_trap_gate(10,ipipe_trap_trampolines[10]);
+    ipipe_set_trap_gate(11,ipipe_trap_trampolines[11]);
+    ipipe_set_trap_gate(12,ipipe_trap_trampolines[12]);
+    ipipe_set_trap_gate(13,ipipe_trap_trampolines[13]);
+    ipipe_set_irq_gate(14,ipipe_trap_trampolines[14]);
+    ipipe_set_trap_gate(15,ipipe_trap_trampolines[15]);
+    ipipe_set_trap_gate(16,ipipe_trap_trampolines[16]);
+    ipipe_set_trap_gate(17,ipipe_trap_trampolines[17]);
+    ipipe_set_trap_gate(18,ipipe_trap_trampolines[18]);
+    ipipe_set_trap_gate(19,ipipe_trap_trampolines[19]);
+
+    adp_pipelined = 1;
+
+    ipipe_hw_restore_flags(flags);
+}
+
+int ipipe_hook_irq (unsigned irq,
+		    void (*handler)(unsigned irq),
+		    int (*acknowledge)(unsigned irq),
+		    unsigned modemask)
+{
+    unsigned long flags;
+
+    ipipe_hw_spin_lock(&adeos_pipelock,flags);
+
+    if (handler != NULL)
+	{
+	if ((modemask & IPIPE_EXCLUSIVE_MASK) != 0)
+	    {
+	    if (adp_current->irqs[irq].handler != NULL)
+		return -EBUSY;
+	    }
+
+	if ((modemask & IPIPE_STICKY_MASK) != 0)
+	    modemask |= IPIPE_HANDLE_MASK;
+	}
+    else
+	modemask &= ~(IPIPE_HANDLE_MASK|IPIPE_STICKY_MASK);
+
+    if (acknowledge == NULL)
+	acknowledge = adp_root->irqs[irq].acknowledge;
+
+    adp_current->irqs[irq].handler = handler;
+    adp_current->irqs[irq].acknowledge = acknowledge;
+    adp_current->irqs[irq].control = modemask;
+
+    if (!ipipe_virtual_irq_p(irq) && handler != NULL &&
+	(modemask & IPIPE_ENABLE_MASK) != 0 && irq < NR_IRQS)
+	irq_desc[irq].handler->enable(irq);
+
+    ipipe_hw_spin_unlock(&adeos_pipelock,flags);
+
+    return 0;
+}
+
+int ipipe_trigger_ipi (int _cpuid)
+
+{
+#ifdef CONFIG_SMP
+    ipipe_declare_cpuid;
+
+    if (unlikely(_cpuid == cpuid)) /* Self-posting the service interrupt? */
+	ipipe_trigger_irq(ADEOS_SERVICE_IPI);
+    else
+	{
+	unsigned long flags;
+
+	ipipe_hw_save_flags_and_cli(flags);
+
+	if (cpuid == ADEOS_OTHER_CPUS)
+	    {
+	    if (smp_num_cpus > 1)
+		/* Send the service IPI to all processors but the current one. */
+		__adeos_send_IPI_allbutself(ADEOS_SERVICE_VECTOR);
+	    }
+	else if (_cpuid >= 0 && _cpuid < smp_num_cpus)
+	    __adeos_send_IPI_other(_cpuid,ADEOS_SERVICE_VECTOR);
+
+	ipipe_hw_restore_flags(flags);
+	}
+
+    return cpuid != ADEOS_OTHER_CPUS ? 1 : smp_num_cpus - 1;
+#else  /* !CONFIG_SMP */
+    return 0;
+#endif /* CONFIG_SMP */
+}
+
+void ipipe_init_stage (adomain_t *adp)
+
+{
+    int cpuid, n;
+
+    for (cpuid = 0; cpuid < ADEOS_NR_CPUS; cpuid++)
+	{
+	adp->cpudata[cpuid].irq_pending_hi = 0;
+
+	for (n = 0; n < IPIPE_IRQ_IWORDS; n++)
+	    adp->cpudata[cpuid].irq_pending_lo[n] = 0;
+
+	for (n = 0; n < IPIPE_NR_IRQS; n++)
+	    adp->cpudata[cpuid].irq_hits[n] = 0;
+	}
+
+    for (n = 0; n < IPIPE_NR_IRQS; n++)
+	{
+	adp->irqs[n].acknowledge = NULL;
+	adp->irqs[n].handler = NULL;
+	adp->irqs[n].control = IPIPE_PASS_MASK;	/* Pass but don't handle */
+	}
+
+#ifdef CONFIG_SMP
+    adp->irqs[ADEOS_CRITICAL_IPI].acknowledge = &ipipe_ack_system_irq;
+    adp->irqs[ADEOS_CRITICAL_IPI].handler = &__adeos_do_critical_sync;
+    /* Immediately handle in the current domain but *never* pass */
+    adp->irqs[ADEOS_CRITICAL_IPI].control = IPIPE_HANDLE_MASK|IPIPE_STICKY_MASK;
+#endif /* CONFIG_SMP */
+}
+
+/* ipipe_sync_irqs() -- Flush the pending IRQs for the current domain
+   (and processor).  This routine flushes the interrupt log (see
+   "Optimistic interrupt protection" from D. Stodolsky et al. for more
+   on the deferred interrupt scheme). Every interrupt that occurred
+   while the pipeline was stalled gets played. */
+
+void ipipe_sync_irqs (void)
+
+{
+    unsigned long mask, submask;
+    struct adcpudata *cpudata;
+    ipipe_declare_cpuid;
+    int level, rank, s;
+    adomain_t *adp;
+    unsigned irq;
+
+    adp = adp_cpu_current[cpuid];
+    cpudata = &adp->cpudata[cpuid];
+
+    do
+	{
+	if (unlikely(test_and_set_bit(IPIPE_SYNC_FLAG,&cpudata->status)))
+	    return;
+
+	/* The policy here is to keep the dispatching code
+	   interrupt-free by stalling the current stage. If the upper
+	   domain handler (which we call) wants to re-enable
+	   interrupts while in a safe portion of code
+	   (e.g. SA_INTERRUPT flag unset for Linux's sigaction()), it
+	   will have to unstall (then stall again before returning to
+	   us!) the stage when it sees fit. */
+
+	s = test_and_set_bit(IPIPE_STALL_FLAG,&cpudata->status);
+
+	/* In order to update the pending irq mask atomically without
+	   fiddling with the processor interrupt state, the irq flag
+	   is first cleared, then reasserted if it appears that not
+	   all hits have been processed yet. */
+
+	while ((mask = cpudata->irq_pending_hi) != 0)
+	    {
+	    level = ffnz(mask);
+	    clear_bit(level,&cpudata->irq_pending_hi);
+
+	    while ((submask = cpudata->irq_pending_lo[level]) != 0)
+		{
+		rank = ffnz(submask);
+		clear_bit(rank,&cpudata->irq_pending_lo[level]);
+		irq = (level << 5) + rank;
+
+		if (likely(cpudata->irq_hits[irq]-- > 0))
+		    {
+		    set_bit(rank,&cpudata->irq_pending_lo[level]);
+		    set_bit(level,&cpudata->irq_pending_hi);
+		    }
+
+		/* Allow the sync routine to be reentered on behalf of
+		   the IRQ handler and any execution context switched
+		   in by the IRQ handler. The latter also means that
+		   returning from the switched out context is always
+		   safe even if the sync routine has been reentered in
+		   the meantime. */
+
+		clear_bit(IPIPE_SYNC_FLAG,&cpudata->status);
+
+		if (test_bit(IPIPE_CALLASM_FLAG,&adp->irqs[irq].control))
+		    ipipe_call_asm_irq_handler(adp,irq);
+		else
+		    ipipe_call_c_irq_handler(adp,irq);
+
+#ifdef CONFIG_SMP
+		/* If the execution context on entry has migrated to
+		   another CPU, exit immediately and let the initial
+		   CPU rerun the sync routine in its own context when
+		   it sees fit (which it might be currently doing in
+		   parallel to this CPU, who knows). */
+
+		if (unlikely(cpuid != adeos_processor_id()))
+		    {
+		    if (!s)
+			clear_bit(IPIPE_STALL_FLAG,&cpudata->status);
+
+		    return;
+		    }
+#endif /* CONFIG_SMP */
+
+		if (unlikely(test_and_set_bit(IPIPE_SYNC_FLAG,&cpudata->status)))
+		    return;
+		}
+	    }
+
+	if (!s)
+	    clear_bit(IPIPE_STALL_FLAG,&cpudata->status);
+
+	clear_bit(IPIPE_SYNC_FLAG,&cpudata->status);
+	}
+    while (cpudata->irq_pending_hi != 0);
+}
+
+static inline void ipipe_walk (struct list_head *pos, int cpuid)
+
+{
+    while (pos != &adeos_pipeline)
+	{
+    	adomain_t *_adp = list_entry(pos,adomain_t,link);
+
+	if (test_bit(IPIPE_STALL_FLAG,&_adp->cpudata[cpuid].status))
+	    break; /* Stalled stage -- do not go further. */
+
+	if (_adp->cpudata[cpuid].irq_pending_hi != 0)
+	    {
+	    /* Since the critical IPI might be serviced by the
+	       following actions, the current domain might not be
+	       linked to the pipeline anymore after its handler
+	       returns on SMP boxes, even if the domain remains valid
+	       (see adeos_unregister_domain()), so don't make any
+	       hazardous assumptions here. */
+
+	    if (_adp == adp_cpu_current[cpuid])
+		ipipe_sync_irqs();
+	    else
+		{
+		__adeos_switch_to(_adp,cpuid);
+
+		ipipe_reload_cpuid(); /* Processor might have changed. */
+
+		if (!test_bit(IPIPE_STALL_FLAG,&adp_cpu_current[cpuid]->cpudata[cpuid].status) &&
+		    adp_cpu_current[cpuid]->cpudata[cpuid].irq_pending_hi != 0)
+		    ipipe_sync_irqs();
+		}
+
+	    break;
+	    }
+	else if (_adp == adp_cpu_current[cpuid])
+	    break;
+
+	pos = _adp->link.next;
+	}
+}
+
+/* ipipe_handle_irq() -- ADEOS' generic IRQ handler. An optimistic
+   interrupt protection log is maintained here for each domain. */
+
+#define ipipe_set_irq_bit(adp,cpuid,irq) \
+do { \
+    set_bit(irq & 0x1f,&(adp)->cpudata[cpuid].irq_pending_lo[irq >> 5]); \
+    set_bit(irq >> 5,&(adp)->cpudata[cpuid].irq_pending_hi); \
+} while(0)
+
+static int ipipe_handle_irq(struct pt_regs regs) __attribute__ ((__unused__));
+
+static int ipipe_handle_irq (struct pt_regs regs)
+
+{
+    unsigned irq = regs.orig_eax & 0xff;
+    int acked = regs.orig_eax >= 0;
+    struct list_head *head, *pos;
+    ipipe_declare_cpuid;
+
+    if (unlikely(test_bit(IPIPE_STICKY_FLAG,&adp_cpu_current[cpuid]->irqs[irq].control)))
+	head = &adp_cpu_current[cpuid]->link;
+    else
+	head = adeos_pipeline.next;
+
+    /* Ack the interrupt. */
+
+    pos = head;
+
+    while (pos != &adeos_pipeline)
+	{
+    	adomain_t *_adp = list_entry(pos,adomain_t,link);
+
+	/* For each domain handling the incoming IRQ, mark it as
+           pending in its log. */
+
+	if (test_bit(IPIPE_HANDLE_FLAG,&_adp->irqs[irq].control))
+	    {
+	    /* Domains that handle this IRQ are polled for
+	       acknowledging it by decreasing priority order. The
+	       interrupt must be made pending _first_ in the domain's
+	       status flags before the PIC is unlocked. */
+
+	    _adp->cpudata[cpuid].irq_hits[irq]++;
+	    ipipe_set_irq_bit(_adp,cpuid,irq);
+
+	    if (!acked)
+		acked = _adp->irqs[irq].acknowledge(irq);
+	    }
+
+	/* If the domain does not want the IRQ to be passed down the
+	   interrupt pipe, exit the loop now. */
+
+	if (!test_bit(IPIPE_PASS_FLAG,&_adp->irqs[irq].control))
+	    break;
+
+	pos = _adp->link.next;
+	}
+
+    /* Now walk the pipeline, yielding control to the highest priority
+       domain that has pending interrupt(s) or immediately to the
+       current domain if the interrupt has been marked as
+       'sticky'. This search does not go beyond the current domain in
+       the pipeline. To understand this code properly, one must keep
+       in mind that domains having a higher priority than the current
+       one are sleeping on the adeos_suspend_domain() service. In
+       addition, domains having a lower priority have been preempted
+       by an interrupt dispatched to a more prioritary domain. Once
+       the first and most prioritary stage has been selected here, the
+       subsequent stages will be activated in turn when each visited
+       domain calls adeos_suspend_domain() to wake up its neighbour
+       down the pipeline. */
+
+    ipipe_walk(head,cpuid);
+    /* Processor might have changed. */
+    ipipe_reload_cpuid();
+
+    return (adp_cpu_current[cpuid] == adp_root &&
+	    !test_bit(IPIPE_STALL_FLAG,&adp_root->cpudata[cpuid].status));
+}
+
+void ipipe_resync_from (adomain_t *adp)
+
+{
+    ipipe_declare_cpuid;
+    ipipe_walk(&adp->link,cpuid);
+}
+
+int ipipe_control_irq (unsigned irq,
+		       unsigned clrmask,
+		       unsigned setmask)
+{
+    irq_desc_t *desc = irq_desc + irq;
+    unsigned long flags;
+
+    ipipe_hw_spin_lock(&adeos_pipelock,flags);
+
+    if (adp_current->irqs[irq].handler == NULL)
+	setmask &= ~(IPIPE_HANDLE_MASK|IPIPE_STICKY_MASK);
+
+    if ((setmask & IPIPE_STICKY_MASK) != 0)
+	setmask |= IPIPE_HANDLE_MASK;
+
+    if ((clrmask & (IPIPE_HANDLE_MASK|IPIPE_STICKY_MASK)) != 0)	/* If one goes, both go. */
+	clrmask |= (IPIPE_HANDLE_MASK|IPIPE_STICKY_MASK);
+
+    adp_current->irqs[irq].control &= ~clrmask;
+    adp_current->irqs[irq].control |= setmask;
+
+    if ((setmask & IPIPE_ENABLE_MASK) != 0)
+	desc->handler->enable(irq);
+    else if ((clrmask & IPIPE_ENABLE_MASK) != 0)
+	desc->handler->disable(irq);
+
+    ipipe_hw_spin_unlock(&adeos_pipelock,flags);
+
+    return 0;
+}
+
+unsigned long ipipe_set_irq_affinity (unsigned irq, unsigned long cpumask)
+
+{
+#ifdef CONFIG_SMP
+    if (smp_num_cpus > 1)
+	return __adeos_set_irq_affinity(irq,cpumask);
+#endif /* CONFIG_SMP */
+    return 0;
+}
+
+int ipipe_propagate_irq (unsigned irq)
+
+{
+    struct list_head *ln;
+    unsigned long flags;
+    ipipe_declare_cpuid;
+
+    ipipe_hw_save_flags_and_cli(flags);
+
+    ln = adp_current->link.next;
+
+    while (ln != &adeos_pipeline)
+	{
+	adomain_t *adp = list_entry(ln,adomain_t,link);
+
+	if (test_bit(IPIPE_HANDLE_FLAG,&adp->irqs[irq].control))
+	    {
+	    adp->cpudata[cpuid].irq_hits[irq]++;
+	    ipipe_set_irq_bit(adp,cpuid,irq);
+	    ipipe_hw_restore_flags(flags);
+	    return 1;
+	    }
+
+	ln = adp->link.next;
+	}
+
+    ipipe_hw_restore_flags(flags);
+
+    return 0;
+}
+
+unsigned ipipe_alloc_irq (void)
+
+{
+    unsigned long flags, irq = 0;
+    int ipos;
+
+    ipipe_hw_spin_lock(&adeos_pipelock,flags);
+
+    if (ipipe_virtual_irq_map != ~0)
+	{
+	ipos = ffz(ipipe_virtual_irq_map);
+	set_bit(ipos,&ipipe_virtual_irq_map);
+	irq = ipos + IPIPE_VIRQ_BASE;
+	}
+
+    ipipe_hw_spin_unlock(&adeos_pipelock,flags);
+
+    return irq;
+}
+
+void ipipe_free_irq (unsigned irq)
+
+{
+    int ipos = irq - IPIPE_VIRQ_BASE;
+    clear_bit(ipos,&ipipe_virtual_irq_map);
+}
+
+int ipipe_trigger_irq (unsigned irq)
+
+{
+    struct pt_regs regs;
+
+    if (ipipe_virtual_irq_p(irq) &&
+	!test_bit(irq - IPIPE_VIRQ_BASE,&ipipe_virtual_irq_map))
+	return -EINVAL;
+
+    regs.orig_eax = irq; /* Won't be acked */
+    return ipipe_handle_irq(regs);
+}
+
+/* ipipe_handle_event() -- Adeos' generic event handler. This routine
+calls the per-domain handlers registered for a given
+exception/event. Each domain before the one which raised the event in
+the pipeline will get a chance to process the event. The latter will
+eventually be allowed to process its own event too if a valid handler
+exists for it.  Handler executions are always scheduled by the domain
+which raised the event for the prioritary domains wanting to be
+notified of such event.  Note: evdata might be NULL. */
+
+int ipipe_handle_event(unsigned event,
+		       void *evdata) __attribute__ ((__unused__));
+
+int ipipe_handle_event (unsigned event, void *evdata)
+
+{
+    struct list_head *pos, *npos;
+    unsigned long flags;
+    ipipe_declare_cpuid;
+    adevinfo_t evinfo;
+    int propagate = 1;
+
+    flags = adeos_test_and_stall_ipipe();
+
+    list_for_each_safe(pos,npos,&adeos_pipeline) {
+
+    	adomain_t *adp = list_entry(pos,adomain_t,link);
+
+	if (adp->events[event].handler != NULL)
+	    {
+	    if (adp == adp_cpu_current[cpuid])
+		{
+		evinfo.domid = adp->domid;
+		evinfo.event = event;
+		evinfo.evdata = evdata;
+		evinfo.propagate = 0;
+		adp->events[event].handler(&evinfo);
+		propagate = evinfo.propagate;
+		break;
+		}
+
+	    adp->cpudata[cpuid].event_info.domid = adp_cpu_current[cpuid]->domid;
+	    adp->cpudata[cpuid].event_info.event = event;
+	    adp->cpudata[cpuid].event_info.evdata = evdata;
+	    adp->cpudata[cpuid].event_info.propagate = 0;
+	    set_bit(IPIPE_XPEND_FLAG,&adp->cpudata[cpuid].status);
+
+	    /* Let the prioritary domain process the event. */
+	    __adeos_switch_to(adp,cpuid);
+	    
+	    if (!adp->cpudata[cpuid].event_info.propagate)
+		{
+		propagate = 0;
+		break;
+		}
+	    }
+
+	if (adp == adp_cpu_current[cpuid])
+	    break;
+    }
+
+    adeos_restore_ipipe(flags);
+
+    return !propagate;
+}
+
+void ipipe_stall_root (void)
+
+{
+    ipipe_declare_cpuid;
+
+    set_bit(IPIPE_STALL_FLAG,&adp_root->cpudata[cpuid].status);
+
+    if (unlikely(!adp_pipelined))
+	ipipe_hw_cli();
+}
+
+void ipipe_unstall_root (void)
+
+{
+    ipipe_declare_cpuid;
+
+    clear_bit(IPIPE_STALL_FLAG,&adp_root->cpudata[cpuid].status);
+    ipipe_hw_sti();
+
+    if (adp_root->cpudata[cpuid].irq_pending_hi != 0)
+	ipipe_sync_irqs();
+}
+
+void ipipe_restore_root (unsigned long flags)
+
+{
+    ipipe_declare_cpuid;
+
+    if (flags)
+	{
+	if (!test_and_set_bit(IPIPE_STALL_FLAG,&adp_root->cpudata[cpuid].status) &&
+	    !adp_pipelined)
+	    ipipe_hw_cli();
+	}
+    else
+	{
+	clear_bit(IPIPE_STALL_FLAG,&adp_root->cpudata[cpuid].status);
+
+	if (unlikely(!adp_pipelined))
+	    ipipe_hw_sti();
+
+	if (adp_root->cpudata[cpuid].irq_pending_hi != 0)
+	    ipipe_sync_irqs();
+	}
+}
diff -Naur linux-2.4.19-orig/arch/i386/kernel/irq.c linux-2.4.19-adeos/arch/i386/kernel/irq.c
--- linux-2.4.19-orig/arch/i386/kernel/irq.c	Thu Oct 25 22:53:46 2001
+++ linux-2.4.19-adeos/arch/i386/kernel/irq.c	Thu Oct 17 10:16:17 2002
@@ -580,6 +580,9 @@
 
 	kstat.irqs[cpu][irq]++;
 	spin_lock(&desc->lock);
+#ifdef CONFIG_ADEOS
+	if (!adp_pipelined)
+#endif
 	desc->handler->ack(irq);
 	/*
 	   REPLAY is when Linux resends an IRQ that was dropped earlier
@@ -1110,6 +1113,27 @@
 	return full_count;
 }
 
+#ifdef CONFIG_ADEOS
+
+unsigned long __adeos_set_irq_affinity (unsigned irq, unsigned long cpumask)
+
+{
+    unsigned long oldmask = irq_affinity[irq];
+
+    if (!cpumask)
+	return oldmask; /* Return mask value -- no change. */
+
+    if (!(cpumask & cpu_online_map) || irq_desc[irq].handler->set_affinity == NULL)
+	return 0;	/* Error -- bad mask value or non-routable IRQ. */
+
+    irq_affinity[irq] = cpumask;
+    irq_desc[irq].handler->set_affinity(irq,cpumask);
+
+    return oldmask;
+}
+
+#endif /* CONFIG_ADEOS */
+
 #endif
 
 static int prof_cpu_mask_read_proc (char *page, char **start, off_t off,
@@ -1197,4 +1221,3 @@
 	for (i = 0; i < NR_IRQS; i++)
 		register_irq_proc(i);
 }
-
diff -Naur linux-2.4.19-orig/arch/i386/kernel/process.c linux-2.4.19-adeos/arch/i386/kernel/process.c
--- linux-2.4.19-orig/arch/i386/kernel/process.c	Sat Aug  3 02:39:42 2002
+++ linux-2.4.19-adeos/arch/i386/kernel/process.c	Thu Oct 10 20:01:15 2002
@@ -132,6 +132,9 @@
 		void (*idle)(void) = pm_idle;
 		if (!idle)
 			idle = default_idle;
+#ifdef CONFIG_ADEOS
+		adeos_suspend_domain();
+#endif /* CONFIG_ADEOS */
 		while (!current->need_resched)
 			idle();
 		schedule();
diff -Naur linux-2.4.19-orig/arch/i386/kernel/smp.c linux-2.4.19-adeos/arch/i386/kernel/smp.c
--- linux-2.4.19-orig/arch/i386/kernel/smp.c	Sat Aug  3 02:39:42 2002
+++ linux-2.4.19-adeos/arch/i386/kernel/smp.c	Thu Oct 17 10:16:26 2002
@@ -160,8 +160,12 @@
 	unsigned long cfg;
 	unsigned long flags;
 
+#ifdef CONFIG_ADEOS
+	ipipe_hw_save_flags_and_cli(flags);
+#else
 	__save_flags(flags);
 	__cli();
+#endif
 
 		
 	/*
@@ -185,7 +189,11 @@
 	 */
 	apic_write_around(APIC_ICR, cfg);
 
+#ifdef CONFIG_ADEOS
+	ipipe_hw_restore_flags(flags);
+#else
 	__restore_flags(flags);
+#endif
 }
 
 static inline void send_IPI_mask_sequence(int mask, int vector)
@@ -380,6 +388,7 @@
 			leave_mm(cpu);
 	}
 	ack_APIC_irq();
+
 	clear_bit(cpu, &flush_cpumask);
 }
 
@@ -600,6 +609,9 @@
  */
 asmlinkage void smp_reschedule_interrupt(void)
 {
+#ifdef CONFIG_ADEOS
+	if (!adp_pipelined)
+#endif /* CONFIG_ADEOS */
 	ack_APIC_irq();
 }
 
@@ -609,6 +621,9 @@
 	void *info = call_data->info;
 	int wait = call_data->wait;
 
+#ifdef CONFIG_ADEOS
+	if (!adp_pipelined)
+#endif /* CONFIG_ADEOS */
 	ack_APIC_irq();
 	/*
 	 * Notify initiating CPU that I've grabbed the data and am
@@ -626,3 +641,14 @@
 	}
 }
 
+#ifdef CONFIG_ADEOS
+
+void __adeos_send_IPI_allbutself (int vector) {
+    send_IPI_allbutself(vector);
+}
+
+void __adeos_send_IPI_other (int cpu, int vector) {
+    send_IPI_mask(1 << cpu,vector);
+}
+
+#endif /* CONFIG_ADEOS */
diff -Naur linux-2.4.19-orig/arch/i386/kernel/time.c linux-2.4.19-adeos/arch/i386/kernel/time.c
--- linux-2.4.19-orig/arch/i386/kernel/time.c	Mon Feb 25 20:37:53 2002
+++ linux-2.4.19-adeos/arch/i386/kernel/time.c	Thu Oct 10 20:01:15 2002
@@ -208,13 +208,22 @@
 
 			int i;
 
+#ifdef CONFIG_ADEOS
+			unsigned long flags;
+			ipipe_hw_spin_lock(&i8259A_lock, flags);
+#else /* !CONFIG_ADEOS */
 			spin_lock(&i8259A_lock);
+#endif /* CONFIG_ADEOS */
 			/*
 			 * This is tricky when I/O APICs are used;
 			 * see do_timer_interrupt().
 			 */
 			i = inb(0x20);
+#ifdef CONFIG_ADEOS
+			ipipe_hw_spin_unlock(&i8259A_lock, flags);
+#else /* !CONFIG_ADEOS */
 			spin_unlock(&i8259A_lock);
+#endif /* CONFIG_ADEOS */
 
 			/* assumption about timer being IRQ0 */
 			if (i & 0x01) {
@@ -400,11 +409,20 @@
 		 * This will also deassert NMI lines for the watchdog if run
 		 * on an 82489DX-based system.
 		 */
+#ifdef CONFIG_ADEOS
+		unsigned long flags;
+		ipipe_hw_spin_lock(&i8259A_lock, flags);
+#else /* !CONFIG_ADEOS */
 		spin_lock(&i8259A_lock);
+#endif /* CONFIG_ADEOS */
 		outb(0x0c, 0x20);
 		/* Ack the IRQ; AEOI will end it automatically. */
 		inb(0x20);
+#ifdef CONFIG_ADEOS
+		ipipe_hw_spin_unlock(&i8259A_lock, flags);
+#else /* !CONFIG_ADEOS */
 		spin_unlock(&i8259A_lock);
+#endif /* CONFIG_ADEOS */
 	}
 #endif
 
@@ -496,6 +514,7 @@
 
 		rdtscl(last_tsc_low);
 
+#ifndef CONFIG_ADEOS
 		spin_lock(&i8253_lock);
 		outb_p(0x00, 0x43);     /* latch the count ASAP */
 
@@ -505,6 +524,7 @@
 
 		count = ((LATCH-1) - count) * TICK_SIZE;
 		delay_at_last_interrupt = (count + LATCH/2) / LATCH;
+#endif /* !CONFIG_ADEOS */
 	}
  
 	do_timer_interrupt(irq, NULL, regs);
diff -Naur linux-2.4.19-orig/arch/i386/mm/fault.c linux-2.4.19-adeos/arch/i386/mm/fault.c
--- linux-2.4.19-orig/arch/i386/mm/fault.c	Sat Aug  3 02:39:42 2002
+++ linux-2.4.19-adeos/arch/i386/mm/fault.c	Thu Oct 10 20:01:15 2002
@@ -154,7 +154,11 @@
 
 	/* It's safe to allow irq's after cr2 has been saved */
 	if (regs->eflags & X86_EFLAGS_IF)
-		local_irq_enable();
+#ifdef CONFIG_ADEOS
+	    ipipe_hw_sti();
+#else
+	    local_irq_enable();
+#endif
 
 	tsk = current;
 
diff -Naur linux-2.4.19-orig/include/asm-i386/adeos.h linux-2.4.19-adeos/include/asm-i386/adeos.h
--- linux-2.4.19-orig/include/asm-i386/adeos.h	Thu Jan  1 01:00:00 1970
+++ linux-2.4.19-adeos/include/asm-i386/adeos.h	Sun Oct 27 12:34:40 2002
@@ -0,0 +1,343 @@
+/*
+ *   include/asm-i386/adeos.h
+ *
+ *   Copyright (C) 2002 Philippe Gerum.
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
+ *   USA; either version 2 of the License, or (at your option) any later
+ *   version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __I386_ADEOS_H
+#define __I386_ADEOS_H
+
+#include <asm/irq.h>
+#include <asm/siginfo.h>
+#include <asm/ptrace.h>
+#include <linux/list.h>
+#include <linux/threads.h>
+
+#ifdef CONFIG_SMP
+
+#include <asm/fixmap.h>
+#include <asm/apicdef.h>
+
+extern int smp_num_cpus;
+
+#define ADEOS_NR_CPUS          NR_CPUS
+#define ADEOS_CRITICAL_VECTOR  0xe1 /* Used by __adeos_critical_enter/exit */
+#define ADEOS_SERVICE_VECTOR   0xe9
+#define ADEOS_CRITICAL_IPI     (ADEOS_CRITICAL_VECTOR - FIRST_EXTERNAL_VECTOR)
+#define ADEOS_SERVICE_IPI      (ADEOS_SERVICE_VECTOR - FIRST_EXTERNAL_VECTOR)
+
+static __inline int adeos_smp_apic_id(void) {
+    return GET_APIC_ID(*(unsigned long *)(APIC_BASE+APIC_ID));
+}
+
+/* Cannot include asm/smpboot.h safely, so we define here the little
+   we need to know about CPU/apicid mappings. */
+
+#ifdef CONFIG_MULTIQUAD
+extern volatile int logical_apicid_2_cpu[];
+#define adeos_processor_id()   (smp_num_cpus > 1 ? logical_apicid_2_cpu[adeos_smp_apic_id()] : 0)
+#else /* !CONFIG_MULTIQUAD */		/* use physical IDs to bootstrap */
+extern volatile int physical_apicid_2_cpu[];
+#define adeos_processor_id()   (smp_num_cpus > 1 ? physical_apicid_2_cpu[adeos_smp_apic_id()] : 0)
+#endif /* CONFIG_MULTIQUAD */
+
+#define ipipe_declare_cpuid    int cpuid = adeos_processor_id()
+#define ipipe_reload_cpuid()   do { cpuid = adeos_processor_id(); } while(0)
+
+#else  /* !CONFIG_SMP */
+
+#define ADEOS_NR_CPUS          1
+#define adeos_processor_id()   0
+/* Array references using this index should be optimized out. */
+#define ipipe_declare_cpuid  const int cpuid = 0
+#define ipipe_reload_cpuid()  /* nop */
+
+#endif /* CONFIG_SMP */
+
+ /* IDT fault vectors */
+#define ADEOS_NR_FAULTS         32
+/* Pseudo-vectors used for kernel events */
+#define ADEOS_FIRST_KEVENT      ADEOS_NR_FAULTS
+#define ADEOS_SYSCALL_PROLOGUE  (ADEOS_FIRST_KEVENT)
+#define ADEOS_SYSCALL_EPILOGUE  (ADEOS_FIRST_KEVENT + 1)
+#define ADEOS_SCHEDULE_HEAD     (ADEOS_FIRST_KEVENT + 2)
+#define ADEOS_SCHEDULE_TAIL     (ADEOS_FIRST_KEVENT + 3)
+#define ADEOS_EXIT_PROCESS      (ADEOS_FIRST_KEVENT + 4)
+#define ADEOS_SIGNAL_PROCESS    (ADEOS_FIRST_KEVENT + 5)
+#define ADEOS_LAST_KEVENT       (ADEOS_SIGNAL_PROCESS)
+
+#define ADEOS_NR_EVENTS         (ADEOS_LAST_KEVENT + 1)
+
+typedef struct adevinfo {
+
+    unsigned domid;
+    unsigned event;
+    void *evdata;
+
+    int propagate;		/* Private */
+
+} adevinfo_t;
+
+typedef struct adsysinfo {
+
+    struct {
+	unsigned irq;		/* Real timer tick IRQ */
+    } timer;
+
+    int ncpus;			/* Number of CPUs on board */
+
+    unsigned long cpufreq;	/* CPU frequency (in Hz) */
+
+} adsysinfo_t;
+
+/* Number of virtual IRQs */
+#define IPIPE_NR_VIRQS    32
+/* First virtual IRQ # */
+#define IPIPE_VIRQ_BASE   NR_IRQS
+/* Total number of IRQs (external + virtual) */
+#define IPIPE_NR_IRQS     (NR_IRQS + IPIPE_NR_VIRQS)
+/* Number of indirect words needed to map the whole IRQ space. */
+#define IPIPE_IRQ_IWORDS  ((IPIPE_NR_IRQS + 31) / 32)
+
+typedef struct adomain {
+
+    /* -- Section: offset-based references are made on these fields
+       from inline assembly code. Please don't move or reorder. */
+    void (*dswitch)(void);	/* Domain switch hook */
+    int *esp[ADEOS_NR_CPUS];	/* Domain stack pointers */
+    /* -- End of section. */
+
+    int *estackbase[ADEOS_NR_CPUS];
+    unsigned domid;
+    const char *name;
+    int priority;
+
+    struct adcpudata {
+	unsigned long status;
+	unsigned long irq_pending_hi;
+	unsigned long irq_pending_lo[IPIPE_IRQ_IWORDS];
+	volatile unsigned irq_hits[IPIPE_NR_IRQS];
+	adevinfo_t event_info;
+    } cpudata[ADEOS_NR_CPUS];
+
+    struct {
+	int (*acknowledge)(unsigned irq);
+	void (*handler)(unsigned irq);
+	unsigned long control;
+    } irqs[IPIPE_NR_IRQS];
+
+    struct {
+	void (*handler)(adevinfo_t *evinfo);
+    } events[ADEOS_NR_EVENTS];
+
+    int ptd_keymax;
+    int ptd_keycount;
+    unsigned long ptd_keymap;
+    void (*ptd_setfun)(int, void *);
+    void *(*ptd_getfun)(int);
+
+    struct list_head link;
+
+} adomain_t;
+
+#define ipipe_virtual_irq_p(irq) ((irq) >= IPIPE_VIRQ_BASE && \
+				  (irq) < IPIPE_NR_IRQS)
+
+#define ipipe_hw_save_flags(x)	__asm__ __volatile__("pushfl ; popl %0":"=g" (x): /* no input */)
+#define ipipe_hw_save_flags_and_cli(x)	__asm__ __volatile__("pushfl ; popl %0 ; cli":"=g" (x): /* no input */)
+#define ipipe_hw_restore_flags(x) __asm__ __volatile__("pushl %0 ; popfl": /* no output */ :"g" (x):"memory", "cc")
+#define ipipe_hw_cli() 		__asm__ __volatile__("cli": : :"memory")
+#define ipipe_hw_sti()		__asm__ __volatile__("sti": : :"memory")
+#define ipipe_hw_local_irq_save(x)    __asm__ __volatile__("pushfl ; popl %0 ; cli":"=g" (x): /* no input */ :"memory")
+#define ipipe_hw_local_irq_restore(x) __asm__ __volatile__("pushl %0 ; popfl": /* no output */ :"g" (x):"memory", "cc")
+
+#define ipipe_hw_spin_lock_init(x)     spin_lock_init(x)
+#define ipipe_hw_spin_lock(x,flags)    do { ipipe_hw_local_irq_save(flags); spin_lock(x); } while (0)
+#define ipipe_hw_spin_unlock(x,flags)  do { spin_unlock(x); ipipe_hw_local_irq_restore(flags); } while (0)
+#define ipipe_hw_spin_lock_disable(x)  do { ipipe_hw_cli(); spin_lock(x); } while (0)
+#define ipipe_hw_spin_unlock_enable(x) do { spin_unlock(x); ipipe_hw_sti(); } while (0)
+#define ipipe_hw_spin_lock_simple(x)   spin_lock(x)
+#define ipipe_hw_spin_unlock_simple(x) spin_unlock(x)
+
+/* Private interface -- Internal use only */
+
+struct adattr;
+
+void __adeos_init(void);
+
+void __adeos_takeover(void);
+
+#ifdef CONFIG_PROC_FS
+void __adeos_init_proc(void);
+#endif /* CONFIG_PROC_FS */
+
+void __adeos_init_domain(adomain_t *adp,
+			 struct adattr *attr);
+
+void __adeos_cleanup_domain(adomain_t *adp);
+
+unsigned long __adeos_critical_enter(void (*sync)(void));
+
+void __adeos_critical_exit(unsigned long flags);
+
+int __adeos_get_sysinfo(adsysinfo_t *info);
+
+int __adeos_tune_timer(unsigned long ns,
+		       int flags);
+
+void __adeos_do_critical_sync(unsigned irq);
+
+void __adeos_send_IPI_allbutself(int vector);
+
+void __adeos_send_IPI_other(int cpu,
+			    int vector);
+
+#ifdef CONFIG_SMP
+
+/*
+ * __adeos_switch_to() -- Switch domain contexts. The current domain
+ * is switched out while the domain pointed by "adp" is switched
+ * in. The current cpu identifier which is always known from callers
+ * is also passed to save a few cycles.
+ * This code works out the following tasks:
+ * - build a resume frame for the suspended domain,
+ * - save it's stack pointer,
+ * - load the incoming domain's stack pointer,
+ * - update the global domain descriptor pointer,
+ * - then finally activate the resume frame of the incoming domain.
+ *
+ * SMP version also provides for safe CPU migration (i.e. the domain
+ * may be switched back in on behalf of a different CPU than the one
+ * which switched it out).
+ */
+
+static inline void __adeos_switch_to (adomain_t *adp, int cpuid) {
+
+    __asm__ __volatile__( \
+	"pushl %%ecx\n\t" \
+	"pushl %%ebx\n\t" \
+	"pushl %%ebp\n\t" \
+	"pushl %%edi\n\t" \
+	"pushl %%esi\n\t" \
+	"pushfl\n\t" \
+	"cli\n\t" \
+	"movl %%eax, %%ecx\n\t" \
+	"leal adp_cpu_current(,%%eax,4),%%eax\n\t" \
+	"xchg (%%eax), %%edx\n\t" \
+	"pushl %%edx\n\t" \
+	"pushl $1f\n\t" \
+	"sall $2,%%ecx\n\t" \
+	"addl $4,%%ecx\n\t" \
+	"movl %%esp, (%%ecx,%%edx)\n\t" \
+	"movl (%%eax), %%eax\n\t" \
+	"movl (%%ecx,%%eax), %%esp\n\t" \
+	"ret\n\t" \
+	  /* Call domain switch hook (if any) */
+"1:
+ 	 popl %%eax\n\t" \
+	"movl (%%eax), %%eax\n\t" \
+	"popfl\n\t" \
+	"testl %%eax,%%eax\n\t" \
+	"je 2f\n\t" \
+	"call *%%eax\n\t" \
+	  /* Domain resume point */
+"2:
+	 popl %%esi\n\t" \
+	"popl %%edi\n\t" \
+	"popl %%ebp\n\t" \
+	"popl %%ebx\n\t" \
+	"popl %%ecx\n\t" \
+	: /* no output */ \
+	: "a" (cpuid), "d" (adp));
+}
+
+unsigned long __adeos_set_irq_affinity(unsigned irq,
+				       unsigned long cpumask);
+
+#else /* !CONFIG_SMP */
+
+static inline void __adeos_switch_to (adomain_t *adp, int cpuid) {
+
+    __asm__ __volatile__( \
+	"pushl %%edx\n\t" \
+	"pushl %%ecx\n\t" \
+	"pushl %%ebx\n\t" \
+	"pushl %%ebp\n\t" \
+	"pushl %%edi\n\t" \
+	"pushl %%esi\n\t" \
+	"movl "SYMBOL_NAME_STR(adp_cpu_current)", %%edx\n\t" \
+	"pushl %%edx\n\t" \
+	"pushl $1f\n\t" \
+	"movl %%esp, 4(%%edx)\n\t" \
+	"movl 4(%%eax), %%esp\n\t" \
+	"movl %%eax, "SYMBOL_NAME_STR(adp_cpu_current)"\n\t" \
+	"ret\n\t" \
+	  /* Call domain switch hook (if any) */
+"1:
+	 popl %%eax\n\t" \
+	"movl (%%eax),%%eax\n\t" \
+	"testl %%eax,%%eax\n\t" \
+	"je 2f\n\t" \
+	"call *%%eax\n\t" \
+	  /* Domain resume point */
+"2:
+	 popl %%esi\n\t" \
+	"popl %%edi\n\t" \
+	"popl %%ebp\n\t" \
+	"popl %%ebx\n\t" \
+	"popl %%ecx\n\t" \
+	"popl %%edx\n\t" \
+	: /* no output */ \
+        : "a" (adp));
+}
+
+#endif /* CONFIG_SMP */
+
+void ipipe_init_stage(adomain_t *adp);
+
+void ipipe_takeover_root_domain(void);
+
+int ipipe_hook_irq(unsigned irq,
+		   void (*handler)(unsigned irq),
+		   int (*acknowledge)(unsigned irq),
+		   unsigned modemask);
+
+int ipipe_control_irq(unsigned irq,
+		      unsigned clrmask,
+		      unsigned setmask);
+
+unsigned ipipe_alloc_irq(void);
+
+void ipipe_free_irq(unsigned irq);
+
+int FASTCALL(ipipe_trigger_irq(unsigned irq));
+
+int FASTCALL(ipipe_trigger_ipi(int cpuid));
+
+int FASTCALL(ipipe_propagate_irq(unsigned irq));
+
+void ipipe_sync_irqs(void);
+
+int ipipe_handle_event(unsigned event,
+		       void *evdata);
+
+unsigned long ipipe_set_irq_affinity(unsigned irq,
+				     unsigned long cpumask);
+extern int __adeos_event_monitors[];
+
+#endif /* !__I386_ADEOS_H */
diff -Naur linux-2.4.19-orig/include/asm-i386/system.h linux-2.4.19-adeos/include/asm-i386/system.h
--- linux-2.4.19-orig/include/asm-i386/system.h	Thu Nov 22 20:46:18 2001
+++ linux-2.4.19-adeos/include/asm-i386/system.h	Sun Oct 27 12:34:40 2002
@@ -310,6 +310,28 @@
 #define set_wmb(var, value) do { var = value; wmb(); } while (0)
 
 /* interrupt control.. */
+
+#ifdef CONFIG_ADEOS
+
+#include <linux/adeos.h>
+
+#define safe_halt()		__asm__ __volatile__("call "SYMBOL_NAME_STR(ipipe_unstall_root)"; hlt": : :"memory")
+
+#define __save_flags(x)		((x) = ipipe_test_root())
+#define __restore_flags(x) 	ipipe_restore_root(x)
+#define __cli() 		ipipe_stall_root()
+#define __sti()			ipipe_unstall_root()
+/* used in the idle loop; sti takes one instruction cycle to complete */
+
+/* For spinlocks etc */
+
+#define local_irq_save(x)	((x) = ipipe_test_and_stall_root())
+#define local_irq_restore(x)	ipipe_restore_root(x)
+#define local_irq_disable()	ipipe_stall_root()
+#define local_irq_enable()	ipipe_unstall_root()
+
+#else /* !CONFIG_ADEOS */
+
 #define __save_flags(x)		__asm__ __volatile__("pushfl ; popl %0":"=g" (x): /* no input */)
 #define __restore_flags(x) 	__asm__ __volatile__("pushl %0 ; popfl": /* no output */ :"g" (x):"memory", "cc")
 #define __cli() 		__asm__ __volatile__("cli": : :"memory")
@@ -322,6 +344,8 @@
 #define local_irq_restore(x)	__restore_flags(x)
 #define local_irq_disable()	__cli()
 #define local_irq_enable()	__sti()
+
+#endif /* CONFIG_ADEOS */
 
 #ifdef CONFIG_SMP
 
diff -Naur linux-2.4.19-orig/include/linux/adeos.h linux-2.4.19-adeos/include/linux/adeos.h
--- linux-2.4.19-orig/include/linux/adeos.h	Thu Jan  1 01:00:00 1970
+++ linux-2.4.19-adeos/include/linux/adeos.h	Sun Oct 27 18:19:47 2002
@@ -0,0 +1,301 @@
+/*
+ *   include/linux/adeos.h
+ *
+ *   Copyright (C) 2002 Philippe Gerum.
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
+ *   USA; either version 2 of the License, or (at your option) any later
+ *   version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __LINUX_ADEOS_H
+#define __LINUX_ADEOS_H
+
+#include <asm/adeos.h>
+
+#define ADEOS_VERSION_STRING "2.4r5/x86"
+#define ADEOS_RELEASE_NUMBER 0x020405ff
+
+#define ADEOS_ROOT_PRI       100
+#define ADEOS_ROOT_ID        0
+#define ADEOS_ROOT_NPTDKEYS  4	/* Must be <= 32 */
+
+#define ADEOS_OTHER_CPUS   (-1)
+#define ADEOS_RESET_TIMER  0x1
+
+#define IPIPE_STALL_FLAG   0	/* Stalls a pipeline stage */
+#define IPIPE_SYNC_FLAG    1	/* IRQ sync is undergoing */
+#define IPIPE_XPEND_FLAG   2	/* Exception notification is pending */
+#define IPIPE_SLEEP_FLAG   3	/* Domain has suspended itself */
+
+#define IPIPE_HANDLE_FLAG    0
+#define IPIPE_PASS_FLAG      1
+#define IPIPE_CALLASM_FLAG   2
+#define IPIPE_ENABLE_FLAG    3
+#define IPIPE_DYNAMIC_FLAG   IPIPE_HANDLE_FLAG
+#define IPIPE_EXCLUSIVE_FLAG 4
+#define IPIPE_STICKY_FLAG    5
+
+#define IPIPE_HANDLE_MASK    (1 << IPIPE_HANDLE_FLAG)
+#define IPIPE_PASS_MASK      (1 << IPIPE_PASS_FLAG)
+#define IPIPE_CALLASM_MASK   (1 << IPIPE_CALLASM_FLAG)
+#define IPIPE_ENABLE_MASK    (1 << IPIPE_ENABLE_FLAG)
+#define IPIPE_DYNAMIC_MASK   IPIPE_HANDLE_MASK
+#define IPIPE_EXCLUSIVE_MASK (1 << IPIPE_EXCLUSIVE_FLAG)
+#define IPIPE_STICKY_MASK    (1 << IPIPE_STICKY_FLAG)
+
+#define IPIPE_DEFAULT_MASK  (IPIPE_HANDLE_MASK|IPIPE_PASS_MASK)
+
+typedef struct adattr {
+
+    unsigned domid;		/* Domain identifier -- Magic value set by caller */
+    const char *name;		/* Domain name -- Warning: won't be dup'ed! */
+    int priority;		/* Priority in interrupt pipeline */
+    void (*entry)(int);		/* Domain entry point */
+    int estacksz;		/* Stack size for entry context -- 0 means unspec */
+    void (*dswitch)(void);	/* Handler called each time the domain is switched in */
+    int nptdkeys;		/* Max. number of per-thread data keys */
+    void (*ptdset)(int,void *);	/* Routine to set pt values */
+    void *(*ptdget)(int);	/* Routine to get pt values */
+
+} adattr_t;
+
+extern adomain_t *adp_cpu_current[],
+                 *adp_root;
+
+extern int adp_pipelined;
+
+#define adp_current (adp_cpu_current[adeos_processor_id()])
+
+/* Private interface */
+
+static inline void __adeos_schedule_head(void *evdata) {
+
+    if (__adeos_event_monitors[ADEOS_SCHEDULE_HEAD] > 0)
+	ipipe_handle_event(ADEOS_SCHEDULE_HEAD,evdata);
+}
+
+static inline void __adeos_schedule_tail(void *evdata) {
+
+    if (__adeos_event_monitors[ADEOS_SCHEDULE_TAIL] > 0)
+	ipipe_handle_event(ADEOS_SCHEDULE_TAIL,evdata);
+}
+
+static inline void __adeos_exit_process(void *evdata) {
+
+    if (__adeos_event_monitors[ADEOS_EXIT_PROCESS] > 0)
+	ipipe_handle_event(ADEOS_EXIT_PROCESS,evdata);
+}
+
+static inline int __adeos_signal_process(void *evdata) {
+
+    if (__adeos_event_monitors[ADEOS_SIGNAL_PROCESS] > 0)
+	return ipipe_handle_event(ADEOS_SIGNAL_PROCESS,evdata);
+
+    return 0;
+}
+
+void FASTCALL(ipipe_resync_from(adomain_t *adp));
+
+void ipipe_stall_root(void);
+
+void ipipe_unstall_root(void);
+
+static inline unsigned long ipipe_test_root (void) {
+
+    ipipe_declare_cpuid;
+    return test_bit(IPIPE_STALL_FLAG,&adp_root->cpudata[cpuid].status);
+}
+
+static inline unsigned long ipipe_test_and_stall_root (void)
+
+{
+    ipipe_declare_cpuid;
+    unsigned long flags = test_and_set_bit(IPIPE_STALL_FLAG,&adp_root->cpudata[cpuid].status);
+
+    if (!flags && !adp_pipelined)
+	ipipe_hw_cli();
+
+    return flags;
+}
+
+void FASTCALL(ipipe_restore_root(unsigned long flags));
+
+/* Public interface */
+
+int adeos_register_domain(adomain_t *adp,
+			  adattr_t *attr);
+
+int adeos_unregister_domain(adomain_t *adp);
+
+void adeos_renice_domain(adomain_t *adp,
+			 int newpri);
+
+void adeos_suspend_domain(void);
+
+int adeos_virtualize_irq(unsigned irq,
+			 void (*handler)(unsigned irq),
+			 int (*acknowledge)(unsigned irq),
+			 unsigned modemask);
+
+int adeos_control_irq(unsigned irq,
+		      unsigned clrmask,
+		      unsigned setmask);
+
+int FASTCALL(adeos_propagate_irq(unsigned irq));
+
+unsigned long adeos_set_irq_affinity(unsigned irq,
+				     unsigned long cpumask);
+unsigned adeos_alloc_irq(void);
+
+int adeos_free_irq(unsigned irq);
+
+int FASTCALL(adeos_trigger_irq(unsigned irq));
+
+int FASTCALL(adeos_trigger_ipi(int cpuid));
+
+static inline void adeos_stall_ipipe_from (adomain_t *adp) {
+
+    ipipe_declare_cpuid;
+    set_bit(IPIPE_STALL_FLAG,&adp->cpudata[cpuid].status);
+}
+
+static inline void adeos_stall_ipipe (void) {
+
+    adeos_stall_ipipe_from(adp_current);
+}
+
+void adeos_unstall_ipipe_from(adomain_t *adp);
+
+static inline void adeos_unstall_ipipe (void) {
+
+    ipipe_declare_cpuid;
+
+    clear_bit(IPIPE_STALL_FLAG,&adp_current->cpudata[cpuid].status);
+    ipipe_hw_sti();
+
+    if (adp_current->cpudata[cpuid].irq_pending_hi != 0)
+	ipipe_sync_irqs();
+}
+
+static inline unsigned long adeos_test_ipipe_from (adomain_t *adp) {
+
+    return test_bit(IPIPE_STALL_FLAG,&adp->cpudata[adeos_processor_id()].status);
+}
+
+static inline unsigned long adeos_test_ipipe_remote (adomain_t *adp, int cpuid) {
+
+    return test_bit(IPIPE_STALL_FLAG,&adp->cpudata[cpuid].status);
+}
+
+static inline unsigned long adeos_test_ipipe (void) {
+
+    return adeos_test_ipipe_from(adp_current);
+}
+
+static inline unsigned long adeos_test_and_stall_ipipe_from (adomain_t *adp) {
+    
+    return test_and_set_bit(IPIPE_STALL_FLAG,&adp->cpudata[adeos_processor_id()].status);
+}
+
+static inline unsigned long adeos_test_and_stall_ipipe_remote (adomain_t *adp, int cpuid) {
+    
+    return test_and_set_bit(IPIPE_STALL_FLAG,&adp->cpudata[cpuid].status);
+}
+
+static inline unsigned long adeos_test_and_stall_ipipe (void) {
+    
+    return adeos_test_and_stall_ipipe_from(adp_current);
+}
+
+static inline void adeos_restore_ipipe_from (adomain_t *adp, unsigned long flags) {
+
+    ipipe_declare_cpuid;
+
+    if (flags)
+	set_bit(IPIPE_STALL_FLAG,&adp->cpudata[cpuid].status);
+    else
+	{
+	clear_bit(IPIPE_STALL_FLAG,&adp->cpudata[cpuid].status);
+
+	if (adp == adp_cpu_current[cpuid])
+	    {
+	    if (adp->cpudata[cpuid].irq_pending_hi != 0)
+		ipipe_sync_irqs();
+	    }
+	else
+	    ipipe_resync_from(adp);
+	}
+}
+
+static inline void adeos_restore_ipipe (unsigned long flags) {
+
+    ipipe_declare_cpuid;
+    adomain_t *adp = adp_cpu_current[cpuid];
+
+    if (flags)
+	set_bit(IPIPE_STALL_FLAG,&adp->cpudata[cpuid].status);
+    else
+	{
+	clear_bit(IPIPE_STALL_FLAG,&adp->cpudata[cpuid].status);
+
+	if (adp->cpudata[cpuid].irq_pending_hi != 0)
+	    ipipe_sync_irqs();
+	}
+}
+
+static inline void adeos_restore_ipipe_nosync (adomain_t *adp, unsigned long flags, int cpuid) {
+
+    if (flags)
+	set_bit(IPIPE_STALL_FLAG,&adp->cpudata[cpuid].status);
+    else
+	clear_bit(IPIPE_STALL_FLAG,&adp->cpudata[cpuid].status);
+}
+
+static inline void adeos_restore_ipipe_remote (adomain_t *adp, unsigned long flags, int cpuid) {
+
+    adeos_restore_ipipe_nosync(adp,flags,cpuid);
+}
+
+int adeos_catch_event(unsigned event,
+		      void (*handler)(adevinfo_t *));
+
+static inline void adeos_propagate_event(adevinfo_t *evinfo) {
+
+    evinfo->propagate = 1;
+}
+
+void (*adeos_hook_dswitch(void (*handler)(void)))(void);
+
+void adeos_init_attr(adattr_t *attr);
+
+int adeos_get_sysinfo(adsysinfo_t *sysinfo);
+
+int adeos_tune_timer(unsigned long ns,
+		     int flags);
+
+int adeos_alloc_ptdkey(void);
+
+int adeos_free_ptdkey(int key);
+
+int adeos_set_ptd(int key,
+		  void *value);
+
+void *adeos_get_ptd(int key);
+
+unsigned long adeos_critical_enter(void (*syncfn)(void));
+
+void adeos_critical_exit(unsigned long flags);
+
+#endif /* !__LINUX_ADEOS_H */
diff -Naur linux-2.4.19-orig/include/linux/sched.h linux-2.4.19-adeos/include/linux/sched.h
--- linux-2.4.19-orig/include/linux/sched.h	Sat Aug  3 02:39:45 2002
+++ linux-2.4.19-adeos/include/linux/sched.h	Sun Oct 27 12:34:40 2002
@@ -418,6 +418,10 @@
 
 /* journalling filesystem info */
 	void *journal_info;
+
+#ifdef CONFIG_ADEOS
+        void *ptd[ADEOS_ROOT_NPTDKEYS];
+#endif /* CONFIG_ADEOS */
 };
 
 /*
@@ -470,6 +474,51 @@
  *  INIT_TASK is used to set up the first task table, touch at
  * your own risk!. Base=0, limit=0x1fffff (=2MB)
  */
+#ifdef CONFIG_ADEOS
+#define INIT_TASK(tsk)	\
+{									\
+    state:		0,						\
+    flags:		0,						\
+    sigpending:		0,						\
+    addr_limit:		KERNEL_DS,					\
+    exec_domain:	&default_exec_domain,				\
+    lock_depth:		-1,						\
+    counter:		DEF_COUNTER,					\
+    nice:		DEF_NICE,					\
+    policy:		SCHED_OTHER,					\
+    mm:			NULL,						\
+    active_mm:		&init_mm,					\
+    cpus_runnable:	-1,						\
+    cpus_allowed:	-1,						\
+    run_list:		LIST_HEAD_INIT(tsk.run_list),			\
+    next_task:		&tsk,						\
+    prev_task:		&tsk,						\
+    p_opptr:		&tsk,						\
+    p_pptr:		&tsk,						\
+    thread_group:	LIST_HEAD_INIT(tsk.thread_group),		\
+    wait_chldexit:	__WAIT_QUEUE_HEAD_INITIALIZER(tsk.wait_chldexit),\
+    real_timer:		{						\
+	function:		it_real_fn				\
+    },									\
+    cap_effective:	CAP_INIT_EFF_SET,				\
+    cap_inheritable:	CAP_INIT_INH_SET,				\
+    cap_permitted:	CAP_FULL_SET,					\
+    keep_capabilities:	0,						\
+    rlim:		INIT_RLIMITS,					\
+    user:		INIT_USER,					\
+    comm:		"swapper",					\
+    thread:		INIT_THREAD,					\
+    fs:			&init_fs,					\
+    files:		&init_files,					\
+    sigmask_lock:	SPIN_LOCK_UNLOCKED,				\
+    sig:		&init_signals,					\
+    pending:		{ NULL, &tsk.pending.head, {{0}}},		\
+    blocked:		{{0}},						\
+    alloc_lock:		SPIN_LOCK_UNLOCKED,				\
+    journal_info:	NULL,						\
+    ptd:                { [ 0 ... ADEOS_ROOT_NPTDKEYS - 1] = 0 },       \
+}
+#else /* !CONFIG_ADEOS */
 #define INIT_TASK(tsk)	\
 {									\
     state:		0,						\
@@ -512,6 +561,7 @@
     alloc_lock:		SPIN_LOCK_UNLOCKED,				\
     journal_info:	NULL,						\
 }
+#endif /* CONFIG_ADEOS */
 
 
 #ifndef INIT_TASK_SIZE
diff -Naur linux-2.4.19-orig/init/main.c linux-2.4.19-adeos/init/main.c
--- linux-2.4.19-orig/init/main.c	Sat Aug  3 02:39:46 2002
+++ linux-2.4.19-adeos/init/main.c	Thu Oct 10 20:01:14 2002
@@ -358,6 +358,9 @@
 	setup_arch(&command_line);
 	printk("Kernel command line: %s\n", saved_command_line);
 	parse_options(command_line);
+#ifdef CONFIG_ADEOS
+	__adeos_init();
+#endif /* CONFIG_ADEOS */
 	trap_init();
 	init_IRQ();
 	sched_init();
@@ -432,6 +435,9 @@
 	 *	make syscalls (and thus be locked).
 	 */
 	smp_init();
+#ifdef CONFIG_ADEOS
+	__adeos_takeover();
+#endif /* CONFIG_ADEOS */
 	rest_init();
 }
 
diff -Naur linux-2.4.19-orig/kernel/Makefile linux-2.4.19-adeos/kernel/Makefile
--- linux-2.4.19-orig/kernel/Makefile	Mon Sep 17 06:22:40 2001
+++ linux-2.4.19-adeos/kernel/Makefile	Thu Oct 10 20:01:14 2002
@@ -9,7 +9,7 @@
 
 O_TARGET := kernel.o
 
-export-objs = signal.o sys.o kmod.o context.o ksyms.o pm.o exec_domain.o printk.o
+export-objs = signal.o sys.o kmod.o context.o ksyms.o pm.o exec_domain.o printk.o adeos.o
 
 obj-y     = sched.o dma.o fork.o exec_domain.o panic.o printk.o \
 	    module.o exit.o itimer.o info.o time.o softirq.o resource.o \
@@ -19,6 +19,7 @@
 obj-$(CONFIG_UID16) += uid16.o
 obj-$(CONFIG_MODULES) += ksyms.o
 obj-$(CONFIG_PM) += pm.o
+obj-$(CONFIG_ADEOS) += adeos.o
 
 ifneq ($(CONFIG_IA64),y)
 # According to Alan Modra <alan@linuxcare.com.au>, the -fno-omit-frame-pointer is
diff -Naur linux-2.4.19-orig/kernel/adeos.c linux-2.4.19-adeos/kernel/adeos.c
--- linux-2.4.19-orig/kernel/adeos.c	Thu Jan  1 01:00:00 1970
+++ linux-2.4.19-adeos/kernel/adeos.c	Thu Oct 24 15:57:15 2002
@@ -0,0 +1,713 @@
+/*
+ *   linux/kernel/adeos.c
+ *
+ *   Copyright (C) 2002 Philippe Gerum.
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
+ *   USA; either version 2 of the License, or (at your option) any later
+ *   version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *   This code implements the architecture-independent ADEOS support.
+ */
+
+#include <linux/config.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <asm/system.h>
+
+/* The pre-defined domain slot for the root domain. */
+static adomain_t adeos_root_domain;
+
+/* A constant pointer to the root domain. */
+adomain_t *adp_root = &adeos_root_domain;
+
+/* A pointer to the current domain. */
+adomain_t *adp_cpu_current[ADEOS_NR_CPUS] = { [ 0 ... ADEOS_NR_CPUS - 1] = &adeos_root_domain };
+
+/* A global flag telling whether Adeos pipelining is engaged. */
+int adp_pipelined = 0;
+
+/* The spinlock protecting from races while modifying the pipeline. */
+spinlock_t adeos_pipelock = SPIN_LOCK_UNLOCKED;
+
+/* The pipeline data structure. Enqueues adomain_t objects by priority. */
+struct list_head adeos_pipeline;
+
+/* An array of global counters tracking domains monitoring events. */
+int __adeos_event_monitors[ADEOS_NR_EVENTS] = { [ 0 ... ADEOS_NR_EVENTS - 1] = 0 };
+
+static void __adeos_set_root_ptd(int key,
+				 void *value);
+
+static void *__adeos_get_root_ptd(int key);
+
+/* adeos_init() -- Initialization routine of the ADEOS layer. Called
+   by the host kernel early during the boot procedure. */
+
+void __adeos_init (void)
+
+{
+    adattr_t attr;
+
+    printk("ADEOS %s enabled.\n",ADEOS_VERSION_STRING);
+
+    INIT_LIST_HEAD(&adeos_pipeline);
+
+    attr.domid = ADEOS_ROOT_ID;
+    attr.name = "Linux";
+    attr.entry = NULL;
+    attr.priority = ADEOS_ROOT_PRI;
+    attr.estacksz = 0;	/* Unused. */
+    attr.dswitch = NULL;
+    attr.nptdkeys = ADEOS_ROOT_NPTDKEYS;
+    attr.ptdset = &__adeos_set_root_ptd;
+    attr.ptdget = &__adeos_get_root_ptd;
+
+    adeos_register_domain(&adeos_root_domain,&attr);
+}
+
+void __adeos_takeover (void)
+
+{
+    ipipe_takeover_root_domain();
+    printk("ADEOS: Takeover completed for root domain %s.\n",adp_root->name);
+}
+
+#ifdef CONFIG_PROC_FS
+
+#include <linux/proc_fs.h>
+
+static struct proc_dir_entry *adeos_proc_entry;
+
+static int __adeos_read_proc (char *page,
+			      char **start,
+			      off_t off,
+			      int count,
+			      int *eof,
+			      void *data)
+{
+    struct list_head *pos;
+    unsigned long flags;
+    char *p = page;
+    int len;
+
+    p += sprintf(p,"Prio\tID\t\tDomain\n\n");
+
+    ipipe_hw_save_flags_and_cli(flags);
+
+    list_for_each(pos,&adeos_pipeline) {
+    	adomain_t *adp = list_entry(pos,adomain_t,link);
+	p += sprintf(p," %d\t0x%.8x\t%s\n",
+		     adp->priority,
+		     adp->domid,
+		     adp->name);
+    }
+
+    ipipe_hw_restore_flags(flags);
+
+    len = p - page;
+
+    if (len <= off + count)
+	*eof = 1;
+
+    *start = page + off;
+
+    len -= off;
+
+    if (len > count)
+	len = count;
+
+    if (len < 0)
+	len = 0;
+
+    return len;
+}
+
+void __adeos_init_proc (void) {
+
+    adeos_proc_entry = create_proc_read_entry("adeos",
+					      0444,
+					      NULL,
+					      &__adeos_read_proc,
+					      NULL);
+}
+
+#endif /* CONFIG_PROC_FS */
+
+/* adeos_register_domain() -- Add a new domain to the system. All
+   client domains must call this routine to register themselves to
+   ADEOS before using its services. */
+
+int adeos_register_domain (adomain_t *adp, adattr_t *attr)
+
+{
+    struct list_head *pos;
+    unsigned long flags;
+    ipipe_declare_cpuid;
+    int n;
+
+    if (adp_current != adp_root)
+	{
+	printk(KERN_WARNING "ADEOS: Only the root domain may register a new domain.\n");
+	return -EPERM;
+	}
+
+    for (n = 0; n < ADEOS_NR_CPUS; n++)
+	{
+	adp->cpudata[n].status = 0;
+
+	/* A special case for domains who won't process events. We
+	   need to act as if they had suspended themselves. */
+
+	if (adp != adp_root && attr->entry == NULL)
+	    set_bit(IPIPE_SLEEP_FLAG,&adp->cpudata[n].status);
+	}
+
+    /* A special case for domains who won't process events (i.e. no
+       entry). We have to mark them as suspended so that
+       adeos_suspend_domain() won't consider them, unless they
+       _actually_ receive events, which would lead to a panic
+       situation since they have no stack context... :o> */
+
+    if (attr->entry == NULL && adp != adp_root)
+	for (n = 0; n < ADEOS_NR_CPUS; n++)
+	    set_bit(IPIPE_SLEEP_FLAG,&adp->cpudata[n].status);
+
+    adp->name = attr->name;
+    adp->priority = attr->priority;
+    adp->domid = attr->domid;
+    adp->dswitch = attr->dswitch;
+    adp->ptd_setfun = attr->ptdset;
+    adp->ptd_getfun = attr->ptdget;
+    adp->ptd_keymap = 0;
+    adp->ptd_keycount = 0;
+    adp->ptd_keymax = attr->nptdkeys;
+
+    for (n = 0; n < ADEOS_NR_EVENTS; n++)
+	/* Event handlers must be cleared before the i-pipe stage is
+	   inserted since an exception may occur on behalf of the new
+	   emerging domain. */
+	adp->events[n].handler = NULL;
+
+    if (attr->entry != NULL)
+	__adeos_init_domain(adp,attr);
+
+    printk("ADEOS: Domain %s registered.\n",adp->name);
+
+    /* Insert the domain in the interrupt pipeline last, so it won't
+       be resumed for processing interrupts until it has a valid stack
+       context. */
+
+    ipipe_init_stage(adp);
+
+    INIT_LIST_HEAD(&adp->link);
+
+    flags = __adeos_critical_enter(NULL);
+
+    list_for_each(pos,&adeos_pipeline) {
+    	adomain_t *_adp = list_entry(pos,adomain_t,link);
+	if (adp->priority > _adp->priority)
+            break;
+    }
+
+    list_add_tail(&adp->link,pos);
+
+    __adeos_critical_exit(flags);
+
+    /* Finally, allow the new domain to perform its initialization
+       chores on behalf of its own stack context. */
+
+    if (attr->entry != NULL)
+	{
+	__adeos_switch_to(adp,cpuid);
+
+	ipipe_reload_cpuid();	/* Processor might have changed. */
+
+	if (!test_bit(IPIPE_STALL_FLAG,&adp_root->cpudata[cpuid].status) &&
+	    adp_root->cpudata[cpuid].irq_pending_hi != 0)
+	    ipipe_sync_irqs();
+	}
+
+    return 0;
+}
+
+/* adeos_unregister_domain() -- Remove a domain from the system. All
+   client domains must call this routine to unregister themselves from
+   the ADEOS layer. */
+
+int adeos_unregister_domain (adomain_t *adp)
+
+{
+    unsigned long flags;
+    unsigned event;
+
+    if (adp_current != adp_root)
+	{
+	printk(KERN_WARNING "ADEOS: Only the root domain may unregister a domain.\n");
+	return -EPERM;
+	}
+
+    if (adp == adp_root)
+	{
+	printk(KERN_WARNING "ADEOS: Cannot unregister the root domain.\n");
+	return -EPERM;
+	}
+
+    for (event = 0; event < ADEOS_NR_EVENTS; event++)
+	/* Need this to update the monitor count. */
+	adeos_catch_event(event,NULL);
+
+    /* Simply remove the domain from the pipeline and we are almost
+       done. */
+
+    flags = __adeos_critical_enter(NULL);
+    list_del_init(&adp->link);
+    __adeos_critical_exit(flags);
+
+    __adeos_cleanup_domain(adp);
+
+    printk("ADEOS: Domain %s unregistered.\n",adp->name);
+
+    return 0;
+}
+
+/* adeos_renice_domain() -- Change a domain's priority. This affects
+   the position of the domain in the interrupt pipeline. The greater
+   the priority value, the earlier the domain is informed of incoming
+   events when the pipeline is processed. */
+
+void adeos_renice_domain (adomain_t *adp, int newpri)
+
+{
+    struct list_head *pos;
+    unsigned long flags;
+
+    /* Allows round-robin effect if newpri == oldpri. */
+
+    flags = __adeos_critical_enter(NULL);
+
+    list_del_init(&adp->link);
+
+    list_for_each(pos,&adeos_pipeline) {
+    	adomain_t *_adp = list_entry(pos,adomain_t,link);
+	if (newpri > _adp->priority)
+            break;
+    }
+
+    list_add_tail(&adp->link,pos);
+    adp->priority = newpri;
+
+    __adeos_critical_exit(flags);
+}
+
+/* adeos_suspend_domain() -- tell the ADEOS layer that the current
+   domain is now dormant. The calling domain is switched out, while
+   the next domain with work in progress or pending in the pipeline is
+   switched in. */
+
+void adeos_suspend_domain (void)
+
+{
+    struct adcpudata *cpudata;
+    adomain_t *adp, *nadp;
+    struct list_head *ln;
+    unsigned long flags;
+    ipipe_declare_cpuid;
+
+    adp = nadp = adp_cpu_current[cpuid];
+    cpudata = &adp->cpudata[cpuid];
+
+    ipipe_hw_local_irq_save(flags);
+
+    for (;;)
+	{
+	ln = nadp->link.next;
+
+	if (ln == &adeos_pipeline)	/* End of pipeline reached? */
+	    {
+	    /* Caller should loop on its idle task on return. */
+	    ipipe_hw_local_irq_restore(flags);
+	    return;
+	    }
+
+	nadp = list_entry(ln,adomain_t,link);
+
+	/* Make sure the domain was preempted (i.e. not sleeping) or
+	   has some event to process before switching to it. */
+
+	if (!test_bit(IPIPE_SLEEP_FLAG,&nadp->cpudata[cpuid].status) ||
+	    nadp->cpudata[cpuid].irq_pending_hi != 0 ||
+	    test_bit(IPIPE_XPEND_FLAG,&nadp->cpudata[cpuid].status))
+	    break;
+	}
+
+    /* A suspending domain implicitely unstalls the pipeline. */
+    clear_bit(IPIPE_STALL_FLAG,&cpudata->status);
+
+    /* Mark the outgoing domain as aslept (i.e. not preempted). */
+    set_bit(IPIPE_SLEEP_FLAG,&cpudata->status);
+
+    /* Conversely, clear the sleep bit for the incoming domain. */
+    clear_bit(IPIPE_SLEEP_FLAG,&nadp->cpudata[cpuid].status);
+
+    /* Suspend the calling domain, switching to the next one. */
+    __adeos_switch_to(nadp,cpuid);
+
+#ifdef CONFIG_SMP
+    ipipe_reload_cpuid();	/* Processor might have changed. */
+    adp = adp_cpu_current[cpuid];
+    cpudata = &adp->cpudata[cpuid];
+#endif
+
+    /* Now, we are back into the calling domain. Flush the interrupt
+       log and fire the event interposition handler if needed. */
+
+    if (cpudata->irq_pending_hi != 0)
+	ipipe_sync_irqs();
+
+    ipipe_hw_local_irq_restore(flags);
+
+    /* Caution: CPU migration is allowed in SMP-mode on behalf of an
+       event handler provided that the current domain raised
+       it. Otherwise, it's not. */
+
+    if (test_and_clear_bit(IPIPE_XPEND_FLAG,&cpudata->status))
+	adp->events[cpudata->event_info.event].handler(&cpudata->event_info);
+
+    /* Return to the point of suspension in the calling domain. */
+}
+
+/* adeos_virtualize_irq() -- Attach a handler (and optionally an hw
+   acknowledge routine) to an interrupt for the current domain. */
+
+int adeos_virtualize_irq (unsigned irq,
+			  void (*handler)(unsigned irq),
+			  int (*acknowledge)(unsigned irq),
+			  unsigned modemask)
+{
+    if (irq >= IPIPE_NR_IRQS)
+	return -EINVAL;
+
+    return ipipe_hook_irq(irq,handler,acknowledge,modemask);
+}
+
+/* adeos_control_irq() -- Change an interrupt mode. This affects the
+   way a given interrupt is handled by ADEOS for the current
+   domain. setmask is a bitmask telling whether:
+   - the interrupt should be passed to the domain (IPIPE_HANDLE_MASK),
+     and/or
+   - the interrupt should be passed down to the lower priority domain(s)
+     in the pipeline (IPIPE_PASS_MASK).
+   This leads to four possibilities:
+   - PASS only => Ignore the interrupt
+   - HANDLE only => Terminate the interrupt (process but don't pass down)
+   - PASS + HANDLE => Accept the interrupt (process and pass down)
+   - <none> => Discard the interrupt
+   - DYNAMIC is currently an alias of HANDLE since it marks an interrupt
+   which is processed by the current domain but not implicitely passed
+   down to the pipeline, letting the domain's handler choose on a case-
+   by-case basis whether the interrupt propagation should be forced
+   using adeos_propagate_irq().
+   clrmask clears the corresponding bits from the control field before
+   setmask is applied.
+*/
+
+int adeos_control_irq (unsigned irq,
+		       unsigned clrmask,
+		       unsigned setmask) {
+
+    if (irq >= IPIPE_NR_IRQS)
+	return -EINVAL;
+
+    return ipipe_control_irq(irq,clrmask,setmask);
+}
+
+/* adeos_propagate_irq() -- Force a given IRQ propagation on behalf of
+   a running interrupt handler to the next domain down the pipeline.
+   Returns non-zero if a domain has received the interrupt
+   notification, zero otherwise.
+   This call is useful for handling shared interrupts among domains.
+   e.g. pipeline = [domain-A]---[domain-B]...
+   Both domains share IRQ #X.
+   - domain-A handles IRQ #X but does not pass it down (i.e. Terminate
+   or Dynamic interrupt control mode)
+   - domain-B handles IRQ #X (i.e. Terminate or Accept interrupt
+   control modes).
+   When IRQ #X is raised, domain-A's handler determines whether it
+   should process the interrupt by identifying its source. If not,
+   adeos_propagate_irq() is called so that the next domain down the
+   pipeline which handles IRQ #X is given a chance to process it. This
+   process can be repeated until the end of the pipeline is
+   reached. */
+
+int adeos_propagate_irq (unsigned irq) {
+
+    return irq < IPIPE_NR_IRQS ? ipipe_propagate_irq(irq) : -EINVAL;
+}
+
+unsigned long adeos_set_irq_affinity (unsigned irq, unsigned long cpumask) {
+
+    /* Allow changing affinity for external IRQ only. */
+    return irq < NR_IRQS ? ipipe_set_irq_affinity(irq,cpumask) : 0;
+}
+
+/* adeos_alloc_irq() -- Allocate a virtual/soft pipelined interrupt.
+   Virtual interrupts are handled in exactly the same way than their
+   hw-generated counterparts. This is a very basic, one-way only,
+   inter-domain communication system (see adeos_trigger_irq()).  Note:
+   it is not necessary for a domain to allocate a virtual interrupt to
+   trap it using adeos_virtualize_irq(). The newly allocated VIRQ
+   number which can be passed to other IRQ-related services is
+   returned on success, zero otherwise (i.e. no more virtual interrupt
+   channel is available). */
+
+unsigned adeos_alloc_irq (void) {
+
+    return ipipe_alloc_irq();
+}
+
+/* adeos_free_irq() -- Return a previously allocated virtual/soft
+   pipelined interrupt to the pool of allocatable interrupts. */
+
+int adeos_free_irq (unsigned irq)
+
+{
+    if (irq >= IPIPE_NR_IRQS)
+	return -EINVAL;
+
+    ipipe_free_irq(irq);
+
+    return 0;
+}
+
+/* adeos_trigger_irq() -- Push the interrupt to the pipeline entry
+   just like if it has been actually received from a hw source. This
+   both works for real and virtual interrupts. This also means that
+   the current domain might be immediately preempted by a more
+   prioritary domain who happens to handle this interrupt. */
+
+int adeos_trigger_irq (unsigned irq) {
+
+    return irq < IPIPE_NR_IRQS ? ipipe_trigger_irq(irq) : -EINVAL;
+}
+
+/* adeos_trigger_ipi() -- Send the ADEOS service IPI to other
+   processors. This leads to */
+
+int adeos_trigger_ipi (int cpuid) {
+
+    return ipipe_trigger_ipi(cpuid);
+}
+
+int adeos_get_sysinfo (adsysinfo_t *info) {
+
+    return __adeos_get_sysinfo(info);
+}
+
+/* adeos_unstall_ipipe_from() -- Unstall the interrupt pipeline and
+   synchronize pending events from a given domain. */
+
+void adeos_unstall_ipipe_from (adomain_t *adp)
+
+{
+    struct list_head *pos;
+    ipipe_declare_cpuid;
+
+    clear_bit(IPIPE_STALL_FLAG,&adp->cpudata[cpuid].status);
+
+    if (adp == adp_cpu_current[cpuid])
+	{
+	ipipe_hw_sti();
+
+	if (adp->cpudata[cpuid].irq_pending_hi != 0)
+	    ipipe_sync_irqs();
+
+	return;
+	}
+
+    /* Attempt to flush all events that might be pending at the
+       unstalled domain level. This code is roughly lifted from
+       ipipe.c:ipipe_walk(). */
+
+    list_for_each(pos,&adeos_pipeline) {
+
+    	adomain_t *_adp = list_entry(pos,adomain_t,link);
+
+	if (test_bit(IPIPE_STALL_FLAG,&_adp->cpudata[cpuid].status))
+	    break; /* Stalled stage -- do not go further. */
+
+	if (_adp->cpudata[cpuid].irq_pending_hi != 0)
+	    {
+	    /* Since the critical IPI might be serviced by the
+	       following actions, the current domain might not be
+	       linked to the pipeline anymore after its handler
+	       returns on SMP boxen, even if the domain remains valid
+	       (see adeos_unregister_domain()), so don't make any
+	       hazardous assumptions here. */
+
+	    ipipe_hw_sti();
+
+	    if (_adp == adp_cpu_current[cpuid])
+		ipipe_sync_irqs();
+	    else
+		{
+		__adeos_switch_to(_adp,cpuid);
+
+		ipipe_reload_cpuid(); /* Processor might have changed. */
+
+		if (!test_bit(IPIPE_STALL_FLAG,&adp_cpu_current[cpuid]->cpudata[cpuid].status) &&
+		    adp_cpu_current[cpuid]->cpudata[cpuid].irq_pending_hi != 0)
+		    ipipe_sync_irqs();
+		}
+	    
+	    break;
+	    }
+	else if (_adp == adp_cpu_current[cpuid])
+	    break;
+    }
+}
+
+/* adeos_catch_event() -- Interpose an event handler for the
+   current domain. */
+
+int adeos_catch_event (unsigned event, void (*handler)(adevinfo_t *))
+
+{
+    if (event >= ADEOS_NR_EVENTS)
+	return -EINVAL;
+
+    if (!xchg(&adp_current->events[event].handler,handler))
+	{
+	if (handler)
+	    __adeos_event_monitors[event]++;
+	}
+    else if (!handler)
+	__adeos_event_monitors[event]--;
+
+    return 0;
+}
+
+void (*adeos_hook_dswitch(void (*handler)(void))) (void) {
+
+    return (void (*)(void))xchg(&adp_current->dswitch,handler);
+}
+
+void adeos_init_attr (adattr_t *attr)
+
+{
+    attr->name = "Anonymous";
+    attr->domid = 1;
+    attr->entry = NULL;
+    attr->estacksz = 0;	/* Let ADEOS choose a reasonable stack size */
+    attr->priority = ADEOS_ROOT_PRI;
+    attr->dswitch = NULL;
+    attr->nptdkeys = 0;
+    attr->ptdset = NULL;
+    attr->ptdget = NULL;
+}
+
+int adeos_tune_timer (unsigned long ns, int flags) {
+
+    return __adeos_tune_timer(ns,flags);
+}
+
+static void __adeos_set_root_ptd (int key, void *value) {
+
+    current->ptd[key] = value;
+}
+
+static void *__adeos_get_root_ptd (int key) {
+
+    return current->ptd[key];
+}
+
+int adeos_alloc_ptdkey (void)
+
+{
+    unsigned long flags;
+    int key = -1;
+
+    ipipe_hw_spin_lock(&adeos_pipelock,flags);
+
+    if (adp_current->ptd_keycount < adp_current->ptd_keymax)
+	{
+	key = ffz(adp_current->ptd_keymap);
+	set_bit(key,&adp_current->ptd_keymap);
+	adp_current->ptd_keycount++;
+	}
+
+    ipipe_hw_spin_unlock(&adeos_pipelock,flags);
+
+    return key;
+}
+
+int adeos_free_ptdkey (int key)
+
+{
+    unsigned long flags; 
+
+    if (key < 0 || key >= adp_current->ptd_keymax)
+	return -EINVAL;
+
+    ipipe_hw_spin_lock(&adeos_pipelock,flags);
+
+    if (test_and_clear_bit(key,&adp_current->ptd_keymap))
+	adp_current->ptd_keycount--;
+
+    ipipe_hw_spin_unlock(&adeos_pipelock,flags);
+
+    return 0;
+}
+
+int adeos_set_ptd (int key, void *value)
+
+{
+    if (key < 0 || key >= adp_current->ptd_keymax)
+	return -EINVAL;
+
+    if (!adp_current->ptd_setfun)
+	{
+	printk(KERN_WARNING "ADEOS: not ptdset hook for %s\n",adp_current->name);
+	return -EINVAL;
+	}
+
+    adp_current->ptd_setfun(key,value);
+
+    return 0;
+}
+
+void *adeos_get_ptd (int key)
+
+{
+    if (key < 0 || key >= adp_current->ptd_keymax)
+	return NULL;
+
+    if (!adp_current->ptd_getfun)
+	{
+	printk(KERN_WARNING "ADEOS: not ptdget hook for %s\n",adp_current->name);
+	return NULL;
+	}
+
+    return adp_current->ptd_getfun(key);
+}
+
+unsigned long adeos_critical_enter (void (*syncfn)(void)) {
+
+    return __adeos_critical_enter(syncfn);
+}
+
+void adeos_critical_exit (unsigned long flags) {
+
+    __adeos_critical_exit(flags);
+}
diff -Naur linux-2.4.19-orig/kernel/exit.c linux-2.4.19-adeos/kernel/exit.c
--- linux-2.4.19-orig/kernel/exit.c	Sat Aug  3 02:39:46 2002
+++ linux-2.4.19-adeos/kernel/exit.c	Thu Oct 10 20:01:14 2002
@@ -453,6 +453,9 @@
 #ifdef CONFIG_BSD_PROCESS_ACCT
 	acct_process(code);
 #endif
+#ifdef CONFIG_ADEOS
+	__adeos_exit_process(tsk);
+#endif /* CONFIG_ADEOS */
 	__exit_mm(tsk);
 
 	lock_kernel();
diff -Naur linux-2.4.19-orig/kernel/fork.c linux-2.4.19-adeos/kernel/fork.c
--- linux-2.4.19-orig/kernel/fork.c	Sat Aug  3 02:39:46 2002
+++ linux-2.4.19-adeos/kernel/fork.c	Thu Oct 10 20:01:14 2002
@@ -232,7 +232,13 @@
 	atomic_set(&mm->mm_count, 1);
 	init_rwsem(&mm->mmap_sem);
 	mm->page_table_lock = SPIN_LOCK_UNLOCKED;
+#ifdef CONFIG_ADEOS
+	lock_kernel();
+#endif /* CONFIG_ADEOS */
 	mm->pgd = pgd_alloc(mm);
+#ifdef CONFIG_ADEOS
+	unlock_kernel();
+#endif /* CONFIG_ADEOS */
 	mm->def_flags = 0;
 	if (mm->pgd)
 		return mm;
@@ -264,7 +270,13 @@
 inline void __mmdrop(struct mm_struct *mm)
 {
 	BUG_ON(mm == &init_mm);
+#ifdef CONFIG_ADEOS
+	lock_kernel();
+#endif /* CONFIG_ADEOS */
 	pgd_free(mm->pgd);
+#ifdef CONFIG_ADEOS
+	unlock_kernel();
+#endif /* CONFIG_ADEOS */
 	destroy_context(mm);
 	free_mm(mm);
 }
@@ -747,6 +759,15 @@
 	hash_pid(p);
 	nr_threads++;
 	write_unlock_irq(&tasklist_lock);
+
+#ifdef CONFIG_ADEOS
+	{
+	int k;
+
+	for (k = 0; k < ADEOS_ROOT_NPTDKEYS; k++)
+	    p->ptd[k] = NULL;
+	}
+#endif /* CONFIG_ADEOS */
 
 	if (p->ptrace & PT_PTRACED)
 		send_sig(SIGSTOP, p, 1);
diff -Naur linux-2.4.19-orig/kernel/ksyms.c linux-2.4.19-adeos/kernel/ksyms.c
--- linux-2.4.19-orig/kernel/ksyms.c	Sat Aug  3 02:39:46 2002
+++ linux-2.4.19-adeos/kernel/ksyms.c	Wed Oct 16 20:10:40 2002
@@ -570,3 +570,38 @@
 
 EXPORT_SYMBOL(tasklist_lock);
 EXPORT_SYMBOL(pidhash);
+
+#ifdef CONFIG_ADEOS
+EXPORT_SYMBOL(adeos_register_domain);
+EXPORT_SYMBOL(adeos_unregister_domain);
+EXPORT_SYMBOL(adeos_renice_domain);
+EXPORT_SYMBOL(adeos_suspend_domain);
+EXPORT_SYMBOL(adeos_virtualize_irq);
+EXPORT_SYMBOL(adeos_control_irq);
+EXPORT_SYMBOL(adeos_propagate_irq);
+EXPORT_SYMBOL(adeos_alloc_irq);
+EXPORT_SYMBOL(adeos_free_irq);
+EXPORT_SYMBOL(adeos_trigger_irq);
+EXPORT_SYMBOL(adeos_trigger_ipi);
+EXPORT_SYMBOL(adeos_stall_ipipe);
+EXPORT_SYMBOL(adeos_unstall_ipipe);
+EXPORT_SYMBOL(adeos_unstall_ipipe_from);
+EXPORT_SYMBOL(adeos_catch_event);
+EXPORT_SYMBOL(adeos_hook_dswitch);
+EXPORT_SYMBOL(adeos_init_attr);
+EXPORT_SYMBOL(adeos_get_sysinfo);
+EXPORT_SYMBOL(adeos_tune_timer);
+EXPORT_SYMBOL(adeos_alloc_ptdkey);
+EXPORT_SYMBOL(adeos_free_ptdkey);
+EXPORT_SYMBOL(adeos_set_ptd);
+EXPORT_SYMBOL(adeos_get_ptd);
+EXPORT_SYMBOL(adeos_critical_enter);
+EXPORT_SYMBOL(adeos_critical_exit);
+EXPORT_SYMBOL(adeos_set_irq_affinity);
+EXPORT_SYMBOL(adp_cpu_current);
+EXPORT_SYMBOL(adp_root);
+/* The following are convenience exports which might be needed by some
+   Adeos domains loaded as kernel modules. */
+EXPORT_SYMBOL(__mmdrop);
+EXPORT_SYMBOL(do_fork);
+#endif /* CONFIG_ADEOS */
diff -Naur linux-2.4.19-orig/kernel/printk.c linux-2.4.19-adeos/kernel/printk.c
--- linux-2.4.19-orig/kernel/printk.c	Sat Aug  3 02:39:46 2002
+++ linux-2.4.19-adeos/kernel/printk.c	Thu Oct 10 20:01:14 2002
@@ -29,6 +29,17 @@
 
 #include <asm/uaccess.h>
 
+#ifdef CONFIG_ADEOS
+#undef spin_lock_irq
+#define	spin_lock_irq(lock)                 ipipe_hw_spin_lock_disable(lock)
+#undef spin_unlock_irq
+#define	spin_unlock_irq(lock)               ipipe_hw_spin_unlock_enable(lock)
+#undef spin_lock_irqsave
+#define	spin_lock_irqsave(lock, flags)      ipipe_hw_spin_lock(lock, flags)
+#undef spin_unlock_irqrestore
+#define spin_unlock_irqrestore(lock, flags) ipipe_hw_spin_unlock(lock, flags)
+#endif /* CONFIG_ADEOS */
+
 #if defined(CONFIG_MULTIQUAD) || defined(CONFIG_IA64)
 #define LOG_BUF_LEN	(65536)
 #elif defined(CONFIG_ARCH_S390)
diff -Naur linux-2.4.19-orig/kernel/sched.c linux-2.4.19-adeos/kernel/sched.c
--- linux-2.4.19-orig/kernel/sched.c	Sat Aug  3 02:39:46 2002
+++ linux-2.4.19-adeos/kernel/sched.c	Thu Oct 10 20:01:14 2002
@@ -674,6 +674,10 @@
 	{
 		struct mm_struct *mm = next->mm;
 		struct mm_struct *oldmm = prev->active_mm;
+#ifdef CONFIG_ADEOS
+		struct { struct task_struct *prev, *next; } arg = { prev, next };
+		__adeos_schedule_head(&arg);
+#endif /* CONFIG_ADEOS */
 		if (!mm) {
 			BUG_ON(next->active_mm);
 			next->active_mm = oldmm;
@@ -695,6 +699,9 @@
 	 * stack.
 	 */
 	switch_to(prev, next, prev);
+#ifdef CONFIG_ADEOS
+	__adeos_schedule_tail(prev);
+#endif /* CONFIG_ADEOS */
 	__schedule_tail(prev);
 
 same_process:
diff -Naur linux-2.4.19-orig/kernel/signal.c linux-2.4.19-adeos/kernel/signal.c
--- linux-2.4.19-orig/kernel/signal.c	Sat Aug  3 02:39:46 2002
+++ linux-2.4.19-adeos/kernel/signal.c	Thu Oct 10 20:01:14 2002
@@ -1015,6 +1015,21 @@
 {
 	struct siginfo info;
 
+#ifdef CONFIG_ADEOS
+	/* If some domain handler in the pipeline doesn't ask for
+	   propagation, return success pretending that 'sig' was
+	   delivered. */
+	{
+	struct { struct task_struct *task; int sig; } evdata;
+	
+	evdata.task = find_task_by_pid(pid);
+	evdata.sig = sig;
+
+	if (evdata.task != NULL && __adeos_signal_process(&evdata))
+	    return 0;
+	}
+#endif /* CONFIG_ADEOS */
+
 	info.si_signo = sig;
 	info.si_errno = 0;
 	info.si_code = SI_USER;
diff -Naur linux-2.4.19-orig/kernel/sysctl.c linux-2.4.19-adeos/kernel/sysctl.c
--- linux-2.4.19-orig/kernel/sysctl.c	Sat Aug  3 02:39:46 2002
+++ linux-2.4.19-adeos/kernel/sysctl.c	Thu Oct 10 20:01:14 2002
@@ -327,6 +327,9 @@
 #ifdef CONFIG_PROC_FS
 	register_proc_table(root_table, proc_sys_root);
 	init_irq_proc();
+#ifdef CONFIG_ADEOS
+	__adeos_init_proc();
+#endif /* CONFIG_ADEOS */
 #endif
 }
 
