Resent-Date: Mon, 21 Dec 1998 10:30:50 +0100 (MET)
From: zippel@fh-brandenburg.de (Roman Zippel)
Subject: experimental patches 2.1.131
To: linux-m68k@phil.uni-sb.de
Date: Mon, 21 Dec 1998 10:30:02 +0100 (MET)
Resent-From: linux-m68k@phil.uni-sb.de

Hi,

These patches include lots of experimental stuff, so I can only
say that they work on my machine and it's very likely that they
break everything else :). So I need comments especially for
non-Amigas and 020/030 cpus.
First a short list of changes:

- remove CONFIG_OPTIMIZE_0?0 completly
- make more use of the config include feature
- include some os support for the math emu stuff
- major update of the interrupt code
  (includes realtime interrupt)
- kbd_reset_setup() is a function in init/main.c, we defined
  it as pointer (unused anyway so a dummy function now)
- another head.S cleanup (this includes some minor memory
  management updates)
- using m68k_defs.h a bit more more (it's really removed now
  and should always be generated, after applying the patch
  you might still have to remove it by hand or do a make clean)
- moving of some declaration into amigadep.h and allow to use
  real function calls instead of function pointers if only
  compiled for a single machine (I needed/wanted that future
  for the realtime stuff)
- some serial stuff changes to support realtime interrupts
  (side effect: maximum of the builtin serial port is now
  115200 baud :) )
- first version of the atomic interface (it will change again
  as this lacks any support for Sparc/SMP), also needed for
  the realtime stuff.

Now some more comments about this. Basically everything is built
around the realtime interrupt support, which is only supported
on the amiga by now, besides that it includes the head.S changes,
some math emu os support for David and some small bug fixes.

Because of the realtime interrupts the general interrupt code
got a major update, which should make it very easy for most
machines. The general interrupt code does now only manage the
interrupt handler, there it now also supports user vector
interrupts and chained handlers. All there is left to do now
in the machine specific code is to install the entry code into
the vector table (process_int() is dead now). Just look into
asm/irq.h for this, there are some more comments about this.
There is still a default entry in entry.S (to be exactly there
are 4 versions of it).
More tricky is the realtime support. Here the interrupts are
never turned off by sti() instead a counter is incremented.
If interrupts occur in that time only realtime interrupts are
executed immediatly, soft interrupts are instead executed
together with the bottom half handlers, either at the end of
the interrupt or when interrupts are allowed again. To delay
the interrupt execution the interrupt source must be turned
off that is best done by some machine specific code in the
interrupt entry code. If that is not possible there should be
the (not yet implemented) possibility to set some flag to let
interrupt handler execute later and the entry code modifies
the saved status register on the stack to the current interupt
level to prevent reentrancy. With some sane interrupt priorities
this should work quite good.
Anyway the first real user of this is the amiga serial support,
that works even with 115200 now, the only problem that is left
every 5 second I get a error, but that is independent of the
direction and speed and transmitting is still nonrealtime, so
I must do some more tests on this, but of course I'm interested
in comments of results on other machines.

I made a lot of changes head.S, most of them are documented there.
The only real problem I have here (besides it must be tested on
other machines) is the mac stuff especially the mapping of
videomemory, where I don't completly understand the magic. Anyway
if it's that a problem it's possible to create a temporary mapping
and to free or move it later. The mmu printing code is completly
broken now, I didn't need it, so I didn't fix it, do other need it?
Anyway as the mmu can be turned off completly without transparent
translation register now, it's free for any use now, even the 030
tt register is supported (but untested of course), it seems the mac
could need it :).

I added a new kernel option "timer=ciaa|ciab" to choose which timer
to use for the system timer (e.g. to avoid the high priority timer
ciab). But it doesn't seem to work yet, as soon as ide tries to probe
for the drives everything stands (this is already before request_irq()).

Maybe someones remembers my perl request a few weeks ago, if you do
now a "make checkconfig" you know what I mean.

Hmm, I hope I didn't forgot anything important, these patches are
not meant yet for final integration and there are still some debugging
prints on, but maybe someone needs something to hack over christmas :-).
I'm going home at wednesday and I will be a bit offline for the rest
of the year, but I'm of course happy to answer any question to all the
stuff till then. If someone wants only to test a part of it, it should
be possible to left out the new head.S, but head.S itself requires the
changes under m68k/mm/, since the new map_chunk() and the kpointer stuff
doesn't rely on information from head.S anymore.

bye, Roman

Index: linux-2.1/Documentation/Configure.help
diff -u linux-2.1/Documentation/Configure.help:1.1.1.18.2.3 linux-2.1/Documentation/Configure.help:1.1.1.18.2.3.2.1
--- linux-2.1/Documentation/Configure.help:1.1.1.18.2.3	Sat Dec 19 18:51:07 1998
+++ linux-2.1/Documentation/Configure.help	Sat Dec 19 21:28:01 1998
@@ -9596,26 +9596,10 @@
   MC68EC040 will not work, as it does not include an MMU (Memory
   Management Unit).
 
-Use -m68040 flag for 68040 specific optimizations
-CONFIG_OPTIMIZE_040
-  If you will only be running this kernel on a 68040-series processor,
-  this will make the kernel run somewhat faster. However, it will no
-  longer run on a 68020 or 68030, no matter whether you included 68020
-  and 68030 support or not. Say N unless the only processor you are
-  compiling support for is the 68040 (or 68LC040).
-
 68060 support
 CONFIG_M68060
   If you anticipate running this kernel on a computer with a MC68060
   processor, say Y. Otherwise, say N.
-
-Use -m68060 flag for 68060 specific optimizations
-CONFIG_OPTIMIZE_060
-  If you will only be running this kernel on a 68060-series processor,
-  this will make the kernel run somewhat faster. However, it will no
-  longer run on a 68020, 68030 or 68040, no matter whether you
-  included support for those processors or not. Say N unless the only
-  processor you are compiling support for is the 68060.
 
 Advanced processor options
 CONFIG_ADVANCED_CPU
Index: linux-2.1/arch/m68k/Makefile
diff -u linux-2.1/arch/m68k/Makefile:1.1.1.1.6.3 linux-2.1/arch/m68k/Makefile:1.1.1.1.6.3.2.2
--- linux-2.1/arch/m68k/Makefile:1.1.1.1.6.3	Sat Dec 19 18:51:09 1998
+++ linux-2.1/arch/m68k/Makefile	Sun Dec 20 01:29:09 1998
@@ -29,14 +29,21 @@
 # without -fno-strength-reduce the 53c7xx.c driver fails ;-(
 CFLAGS += -pipe -fno-strength-reduce -ffixed-a2
 
-ifdef CONFIG_OPTIMIZE_040
+# enable processor switch if compiled only for a single cpu
+ifndef CONFIG_M68020
+ifndef CONFIG_M68030
+
+ifndef CONFIG_M68060
 CFLAGS := $(CFLAGS) -m68040
 endif
 
-ifdef CONFIG_OPTIMIZE_060
+ifndef CONFIG_M68040
 CFLAGS := $(CFLAGS) -m68060
 endif
 
+endif
+endif
+
 ifdef CONFIG_KGDB
 # If configured for kgdb support, include debugging infos and keep the
 # frame pointer
@@ -115,8 +122,7 @@
 endif
 
 archclean:
-	rm -f vmlinux.gz
-	rm -f kernel/m68k_defs.h kernel/m68k_defs.d
+	rm -f vmlinux.gz arch/m68k/kernel/m68k_defs.[hd]
 
 archmrproper:
 
Index: linux-2.1/arch/m68k/config.in
diff -u linux-2.1/arch/m68k/config.in:1.1.1.7.4.3 linux-2.1/arch/m68k/config.in:1.1.1.7.4.3.2.2
--- linux-2.1/arch/m68k/config.in:1.1.1.7.4.3	Sat Dec 19 18:51:10 1998
+++ linux-2.1/arch/m68k/config.in	Sun Dec 20 01:29:10 1998
@@ -22,12 +22,15 @@
 comment 'Platform dependent setup'
 
 bool 'Amiga support' CONFIG_AMIGA
+if [ "$CONFIG_AMIGA" = "y" ]; then
+  define_bool CONFIG_APUS n
+fi
 bool 'Atari support' CONFIG_ATARI
 if [ "$CONFIG_ATARI" = "y" ]; then
   bool '  Hades support' CONFIG_HADES
   if [ "$CONFIG_HADES" = "y" ]; then
     define_bool CONFIG_PCI y
-  fi  
+  fi
 fi
 bool 'Macintosh support' CONFIG_MAC
 if [ "$CONFIG_MAC" = "y" ]; then
@@ -44,6 +47,7 @@
 if [ "$CONFIG_HP300" = "y" ]; then
   bool 'DIO bus support' CONFIG_DIO
 fi
+define_bool CONFIG_SUN3 n
 if [ "$CONFIG_PCI" = "y" ]; then
   bool 'Backward-compatible /proc/pci' CONFIG_PCI_OLD_PROC
 fi
@@ -53,6 +57,12 @@
 bool '68030 support' CONFIG_M68030
 bool '68040 support' CONFIG_M68040
 bool '68060 support' CONFIG_M68060
+if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
+  bool 'Math emulation support' CONFIG_MATH_EMU
+  if [ "$CONFIG_MATH_EMU" = "y" ]; then
+    bool 'Math emulation only kernel' CONFIG_MATH_EMU_ONLY
+  fi
+fi
 bool 'Advanced configuration options' CONFIG_ADVANCED
 if [ "$CONFIG_ADVANCED" = "y" ]; then
   bool 'Use read-modify-write instructions' CONFIG_RMW_INSNS
@@ -60,6 +70,7 @@
   if [ "$CONFIG_M68060" = "y" ]; then
     bool 'Use write-through caching for 68060 supervisor accesses' CONFIG_060_WRITETHROUGH
   fi
+  bool 'Enable realtime interrupts' CONFIG_RT_INTERRUPT
 fi
 endmenu
 
Index: linux-2.1/arch/m68k/amiga/amiga_ksyms.c
diff -u linux-2.1/arch/m68k/amiga/amiga_ksyms.c:1.1.1.3.6.2 linux-2.1/arch/m68k/amiga/amiga_ksyms.c:1.1.1.3.6.2.2.1
--- linux-2.1/arch/m68k/amiga/amiga_ksyms.c:1.1.1.3.6.2	Sat Dec 19 18:51:11 1998
+++ linux-2.1/arch/m68k/amiga/amiga_ksyms.c	Sat Dec 19 21:28:06 1998
@@ -1,10 +1,19 @@
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/zorro.h>
+#include <asm/machdep.h>
 #include <asm/amigahw.h>
 #include <asm/amipcmcia.h>
 
+#include <config/experimental.h>
+#ifdef CONFIG_EXPERIMENTAL
+#include <config/amiga/pcmcia.h>
+#endif
+#include <config/advanced.h>
+#ifdef CONFIG_ADVANCED
+#include <config/rt/interrupt.h>
+#endif
+
 extern volatile u_short amiga_audio_min_period;
 extern u_short amiga_audio_period;
 
@@ -29,4 +38,7 @@
   EXPORT_SYMBOL(pcmcia_access_speed);
   EXPORT_SYMBOL(pcmcia_write_enable);
   EXPORT_SYMBOL(pcmcia_write_disable);
+#endif
+#ifdef CONFIG_RT_INTERRUPT
+EXPORT_SYMBOL(amiga_do_irqrequest);
 #endif
Index: linux-2.1/arch/m68k/amiga/amiints.c
diff -u linux-2.1/arch/m68k/amiga/amiints.c:1.1.1.3.6.2 linux-2.1/arch/m68k/amiga/amiints.c:1.1.1.3.6.2.2.2
--- linux-2.1/arch/m68k/amiga/amiints.c:1.1.1.3.6.2	Sat Dec 19 18:51:12 1998
+++ linux-2.1/arch/m68k/amiga/amiints.c	Sun Dec 20 01:29:11 1998
@@ -25,39 +25,47 @@
 #include <linux/kernel.h>
 #include <linux/sched.h>
 #include <linux/kernel_stat.h>
+#include <linux/interrupt.h>
 #include <linux/init.h>
+#include <linux/mm.h>
 
 #include <asm/system.h>
 #include <asm/irq.h>
+#include <asm/pgtable.h>
 #include <asm/traps.h>
 #include <asm/amigahw.h>
 #include <asm/amigaints.h>
 #include <asm/amipcmcia.h>
 
+#include <config/apus.h>
+#include <config/advanced.h>
+#ifdef CONFIG_ADVANCED
+#include <config/rt/interrupt.h>
+#endif
+
 extern int cia_request_irq(struct ciabase *base,int irq,
                            void (*handler)(int, void *, struct pt_regs *),
                            unsigned long flags, const char *devname, void *dev_id);
 extern void cia_free_irq(struct ciabase *base, unsigned int irq, void *dev_id);
-extern void cia_init_IRQ(struct ciabase *base);
-extern int cia_get_irq_list(struct ciabase *base, char *buf);
-
-/* irq node variables for amiga interrupt sources */
-static irq_node_t *ami_irq_list[AMI_STD_IRQS];
+extern void cia_init_IRQ(void);
 
 unsigned short ami_intena_vals[AMI_STD_IRQS] = {
-	IF_VERTB, IF_COPER, IF_AUD0, IF_AUD1, IF_AUD2, IF_AUD3, IF_BLIT,
-	IF_DSKSYN, IF_DSKBLK, IF_RBF, IF_TBE, IF_SOFT, IF_PORTS, IF_EXTER
+	IF_TBE, IF_DSKBLK, IF_SOFT, IF_PORTS, IF_COPPER, IF_VERTB, IF_BLIT,
+	IF_AUD0, IF_AUD1, IF_AUD2, IF_AUD3, IF_RBF, IF_DSKSYN, IF_EXTER
 };
-static const unsigned char ami_servers[AMI_STD_IRQS] = {
-	1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1
+static const unsigned char ami_servers[AMI_IRQS] = {
+	0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0
 };
 
 static short ami_ablecount[AMI_IRQS];
 
-static void ami_badint(int irq, void *dev_id, struct pt_regs *fp)
-{
-	num_spurious += 1;
-}
+static void ami_int1(int irq, void *dev_id, struct pt_regs *fp);
+static void ami_int2(int irq, void *dev_id, struct pt_regs *fp);
+static void ami_int3(int irq, void *dev_id, struct pt_regs *fp);
+static void ami_int4(int irq, void *dev_id, struct pt_regs *fp);
+static void ami_int5(int irq, void *dev_id, struct pt_regs *fp);
+static void ami_int6(int irq, void *dev_id, struct pt_regs *fp);
 
 /*
  * void amiga_init_IRQ(void)
@@ -70,26 +78,15 @@
  * the amiga IRQ handling routines.
  */
 
-__initfunc(void amiga_init_IRQ(void))
+void __init amiga_init_IRQ(void)
 {
 	int i;
 
-	/* initialize handlers */
-	for (i = 0; i < AMI_STD_IRQS; i++) {
-		if (ami_servers[i]) {
-			ami_irq_list[i] = NULL;
-		} else {
-			ami_irq_list[i] = new_irq_node();
-			ami_irq_list[i]->handler = ami_badint;
-			ami_irq_list[i]->flags   = IRQ_FLG_STD;
-			ami_irq_list[i]->dev_id  = NULL;
-			ami_irq_list[i]->devname = NULL;
-			ami_irq_list[i]->next    = NULL;
-		}
-	}
 	for (i = 0; i < AMI_IRQS; i++)
 		ami_ablecount[i] = 0;
 
+	vectors[VEC_INT7] = nmi_handler;
+
 	/* turn off PCMCIA interrupts */
 	if (AMIGAHW_PRESENT(PCMCIA))
 		pcmcia_disable_irq();
@@ -98,70 +95,23 @@
 	custom.intena = 0x7fff;
 	custom.intreq = 0x7fff;
 	custom.intena = IF_SETCLR | IF_INTEN;
-
-	cia_init_IRQ(&ciaa_base);
-	cia_init_IRQ(&ciab_base);
-}
-
-static inline void amiga_insert_irq(irq_node_t **list, irq_node_t *node)
-{
-	unsigned long flags;
-	irq_node_t *cur;
-
-	if (!node->dev_id)
-		printk("%s: Warning: dev_id of %s is zero\n",
-		       __FUNCTION__, node->devname);
-
-	save_flags(flags);
-	cli();
-
-	cur = *list;
-
-	if (node->flags & IRQ_FLG_FAST) {
-		node->flags &= ~IRQ_FLG_SLOW;
-		while (cur && cur->flags & IRQ_FLG_FAST) {
-			list = &cur->next;
-			cur = cur->next;
-		}
-	} else if (node->flags & IRQ_FLG_SLOW) {
-		while (cur) {
-			list = &cur->next;
-			cur = cur->next;
-		}
-	} else {
-		while (cur && !(cur->flags & IRQ_FLG_SLOW)) {
-			list = &cur->next;
-			cur = cur->next;
-		}
-	}
 
-	node->next = cur;
-	*list = node;
+	request_irq(IRQ_AMIGA_AUTO_1, ami_int1, IRQ_FLG_REALTIME,
+	            "int1 handler", NULL);
+	request_irq(IRQ_AMIGA_AUTO_2, ami_int2, IRQ_FLG_REALTIME,
+	            "int2 handler", NULL);
+	request_irq(IRQ_AMIGA_AUTO_3, ami_int3, IRQ_FLG_REALTIME,
+	            "int3 handler", NULL);
+	request_irq(IRQ_AMIGA_AUTO_4, ami_int4, IRQ_FLG_REALTIME,
+	            "int4 handler", NULL);
+	request_irq(IRQ_AMIGA_AUTO_5, ami_int5, IRQ_FLG_REALTIME,
+	            "int5 handler", NULL);
+	request_irq(IRQ_AMIGA_AUTO_6, ami_int6, IRQ_FLG_REALTIME,
+	            "int6 handler", NULL);
 
-	restore_flags(flags);
+	cia_init_IRQ();
 }
 
-static inline void amiga_delete_irq(irq_node_t **list, void *dev_id)
-{
-	unsigned long flags;
-	irq_node_t *node;
-
-	save_flags(flags);
-	cli();
-
-	for (node = *list; node; list = &node->next, node = *list) {
-		if (node->dev_id == dev_id) {
-			*list = node->next;
-			/* Mark it as free. */
-			node->handler = NULL;
-			restore_flags(flags);
-			return;
-		}
-	}
-	restore_flags(flags);
-	printk ("%s: tried to remove invalid irq\n", __FUNCTION__);
-}
-
 /*
  * amiga_request_irq : add an interrupt service routine for a particular
  *                     machine specific interrupt source.
@@ -171,17 +121,25 @@
 int amiga_request_irq(unsigned int irq, void (*handler)(int, void *, struct pt_regs *),
                       unsigned long flags, const char *devname, void *dev_id)
 {
-	irq_node_t *node;
+	unsigned int vec;
+	int res;
 
 	if (irq >= AMI_IRQS) {
 		printk ("%s: Unknown IRQ %d from %s\n", __FUNCTION__, irq, devname);
 		return -ENXIO;
 	}
+
+	printk("irq: %x-%s (%x,%x)\n", irq, devname, flags, dev_id);
+	if (irq >= IRQ_AMIGA_AUTO) {
+		vec = irq - IRQ_AMIGA_AUTO + VEC_SPUR;
 
-	if (irq >= IRQ_AMIGA_AUTO)
-		return sys_request_irq(irq - IRQ_AMIGA_AUTO, handler,
-		                       flags, devname, dev_id);
+		res = sys_request_irq(vec, handler, flags, devname, dev_id);
+		if (!res)
+			vectors[vec] = amiga_inthandler;
 
+		return res;
+	}
+
 	if (irq >= IRQ_AMIGA_CIAB)
 		return cia_request_irq(&ciab_base, irq - IRQ_AMIGA_CIAB,
 		                       handler, flags, devname, dev_id);
@@ -190,51 +148,48 @@
 		return cia_request_irq(&ciaa_base, irq - IRQ_AMIGA_CIAA,
 		                       handler, flags, devname, dev_id);
 
-	if (ami_servers[irq]) {
-		if (!(node = new_irq_node()))
-			return -ENOMEM;
-		node->handler = handler;
-		node->flags   = flags;
-		node->dev_id  = dev_id;
-		node->devname = devname;
-		node->next    = NULL;
-		amiga_insert_irq(&ami_irq_list[irq], node);
-	} else {
-		if (!(ami_irq_list[irq]->flags & IRQ_FLG_STD)) {
-			if (ami_irq_list[irq]->flags & IRQ_FLG_LOCK) {
-				printk("%s: IRQ %d from %s is not replaceable\n",
-				       __FUNCTION__, irq, ami_irq_list[irq]->devname);
-				return -EBUSY;
-			}
-			if (!(flags & IRQ_FLG_REPLACE)) {
-				printk("%s: %s can't replace IRQ %d from %s\n",
-				       __FUNCTION__, devname, irq, ami_irq_list[irq]->devname);
-				return -EBUSY;
-			}
-		}
-		ami_irq_list[irq]->handler = handler;
-		ami_irq_list[irq]->flags   = flags;
-		ami_irq_list[irq]->dev_id  = dev_id;
-		ami_irq_list[irq]->devname = devname;
-	}
-
-	/* enable the interrupt */
-	if (irq < IRQ_AMIGA_PORTS && !ami_ablecount[irq])
-		custom.intena = IF_SETCLR | ami_intena_vals[irq];
+	vec = irq + VEC_USER;
+	if (ami_servers[irq])
+		res = sys_request_listirq(vec, handler, flags, devname, dev_id);
+	else
+		res = sys_request_irq(vec, handler, flags, devname, dev_id);
+
+	if (!res) {
+#ifdef CONFIG_RT_INTERRUPT
+		if (flags & IRQ_FLG_REALTIME)
+			amiga_rtintmask |= 1 << irq;
+		else
+			amiga_slowintmask |= 1 << irq;
+		flush_icache_range((unsigned long)&amiga_slowintmask,
+		                   ((unsigned long)&amiga_rtintmask)+2);
+		printk("mask: %x,%x\n", amiga_rtintmask, amiga_slowintmask);
+#endif
 
+		/* enable the interrupt */
+		if (!ami_ablecount[irq])
+			custom.intena = IF_SETCLR | ami_intena_vals[irq];
+	}
 	return 0;
 }
 
 void amiga_free_irq(unsigned int irq, void *dev_id)
 {
+	unsigned int vec;
+
 	if (irq >= AMI_IRQS) {
 		printk ("%s: Unknown IRQ %d\n", __FUNCTION__, irq);
 		return;
 	}
 
-	if (irq >= IRQ_AMIGA_AUTO)
-		sys_free_irq(irq - IRQ_AMIGA_AUTO, dev_id);
+	if (irq >= IRQ_AMIGA_AUTO) {
+		vec = irq - IRQ_AMIGA_AUTO + VEC_SPUR;
+		sys_free_irq(vec, dev_id);
 
+		vectors[vec] = bad_interrupt;
+
+		return;
+	}
+
 	if (irq >= IRQ_AMIGA_CIAB) {
 		cia_free_irq(&ciab_base, irq - IRQ_AMIGA_CIAB, dev_id);
 		return;
@@ -245,21 +200,23 @@
 		return;
 	}
 
-	if (ami_servers[irq]) {
-		amiga_delete_irq(&ami_irq_list[irq], dev_id);
-		/* if server list empty, disable the interrupt */
-		if (!ami_irq_list[irq] && irq < IRQ_AMIGA_PORTS)
-			custom.intena = ami_intena_vals[irq];
-	} else {
-		if (ami_irq_list[irq]->dev_id != dev_id)
-			printk("%s: removing probably wrong IRQ %d from %s\n",
-			       __FUNCTION__, irq, ami_irq_list[irq]->devname);
-		ami_irq_list[irq]->handler = ami_badint;
-		ami_irq_list[irq]->flags   = IRQ_FLG_STD;
-		ami_irq_list[irq]->dev_id  = NULL;
-		ami_irq_list[irq]->devname = NULL;
+	vec = irq + VEC_USER;
+	sys_free_irq(vec, dev_id);
+
+	/* if list empty, disable the interrupt */
+#ifndef CONFIG_RT_INTERRUPT
+	if (!userirq_list[irq])
 		custom.intena = ami_intena_vals[irq];
-	}
+#else
+	if (!userirq_list[irq])
+		amiga_rtintmask &= ~(1 << irq);
+	if (!userirq_softlist[irq])
+		amiga_slowintmask &= ~(1 << irq);
+	flush_icache_range((unsigned long)&amiga_slowintmask,
+	                   ((unsigned long)&amiga_rtintmask)+2);
+	if (!userirq_list[irq] && !userirq_softlist[irq])
+		custom.intena = ami_intena_vals[irq];
+#endif
 }
 
 /*
@@ -336,123 +293,80 @@
 	custom.intena = ami_intena_vals[irq];
 }
 
-inline void amiga_do_irq(int irq, struct pt_regs *fp)
-{
-	kstat.irqs[0][SYS_IRQS + irq]++;
-	ami_irq_list[irq]->handler(irq, ami_irq_list[irq]->dev_id, fp);
-}
-
-void amiga_do_irq_list(int irq, struct pt_regs *fp, struct irq_server *server)
-{
-	irq_node_t *node, *slow_nodes;
-	unsigned short flags;
-
-	kstat.irqs[0][SYS_IRQS + irq]++;
-	if (server->count++)
-		server->reentrance = 1;
-	/* serve first fast and normal handlers */
-	for (node = ami_irq_list[irq];
-	     node && (!(node->flags & IRQ_FLG_SLOW));
-	     node = node->next)
-		node->handler(irq, node->dev_id, fp);
-	custom.intreq = ami_intena_vals[irq];
-	if (!node) {
-		server->count--;
-		return;
-	}
-	save_flags(flags);
-	restore_flags((flags & ~0x0700) | (fp->sr & 0x0700));
-	/* if slow handlers exists, serve them now */
-	slow_nodes = node;
-	for (;;) {
-		for (; node; node = node->next)
-			node->handler(irq, node->dev_id, fp);
-		/* if reentrance occured, serve slow handlers again */
-		custom.intena = ami_intena_vals[irq];
-		if (!server->reentrance) {
-			server->count--;
-			custom.intena = IF_SETCLR | ami_intena_vals[irq];
-			return;
-		}
-		server->reentrance = 0;
-		custom.intena = IF_SETCLR | ami_intena_vals[irq];
-		node = slow_nodes;
-	}
-}
-
 /*
  * The builtin Amiga hardware interrupt handlers.
  */
 
 static void ami_int1(int irq, void *dev_id, struct pt_regs *fp)
 {
-	unsigned short ints = custom.intreqr & custom.intenar;
-
 	/* if serial transmit buffer empty, interrupt */
-	if (ints & IF_TBE) {
+	if (irq & IF_TBE) {
 		custom.intreq = IF_TBE;
 		amiga_do_irq(IRQ_AMIGA_TBE, fp);
 	}
 
 	/* if floppy disk transfer complete, interrupt */
-	if (ints & IF_DSKBLK) {
+	if (irq & IF_DSKBLK) {
 		custom.intreq = IF_DSKBLK;
 		amiga_do_irq(IRQ_AMIGA_DSKBLK, fp);
 	}
 
 	/* if software interrupt set, interrupt */
-	if (ints & IF_SOFT) {
+	if (irq & IF_SOFT) {
 		custom.intreq = IF_SOFT;
 		amiga_do_irq(IRQ_AMIGA_SOFT, fp);
 	}
 }
 
-static void ami_int3(int irq, void *dev_id, struct pt_regs *fp)
+static void ami_int2(int irq, void *dev_id, struct pt_regs *fp)
 {
-	unsigned short ints = custom.intreqr & custom.intenar;
-	static struct irq_server server = {0, 0};
+	custom.intreq = IF_PORTS;
+	amiga_do_irq_list(IRQ_AMIGA_PORTS, fp);
+}
 
+static void ami_int3(int irq, void *dev_id, struct pt_regs *fp)
+{
 	/* if a blitter interrupt */
-	if (ints & IF_BLIT) {
+	if (irq & IF_BLIT) {
 		custom.intreq = IF_BLIT;
 		amiga_do_irq(IRQ_AMIGA_BLIT, fp);
 	}
 
 	/* if a copper interrupt */
-	if (ints & IF_COPER) {
-		custom.intreq = IF_COPER;
+	if (irq & IF_COPPER) {
+		custom.intreq = IF_COPPER;
 		amiga_do_irq(IRQ_AMIGA_COPPER, fp);
 	}
 
 	/* if a vertical blank interrupt */
-	if (ints & IF_VERTB)
-		amiga_do_irq_list(IRQ_AMIGA_VERTB, fp, &server);
+	if (irq & IF_VERTB) {
+		custom.intreq = IF_VERTB;
+		amiga_do_irq_list(IRQ_AMIGA_VERTB, fp);
+	}
 }
 
 static void ami_int4(int irq, void *dev_id, struct pt_regs *fp)
 {
-	unsigned short ints = custom.intreqr & custom.intenar;
-
 	/* if audio 0 interrupt */
-	if (ints & IF_AUD0) {
+	if (irq & IF_AUD0) {
 		custom.intreq = IF_AUD0;
 		amiga_do_irq(IRQ_AMIGA_AUD0, fp);
 	}
 
 	/* if audio 1 interrupt */
-	if (ints & IF_AUD1) {
+	if (irq & IF_AUD1) {
 		custom.intreq = IF_AUD1;
 		amiga_do_irq(IRQ_AMIGA_AUD1, fp);
 	}
 
 	/* if audio 2 interrupt */
-	if (ints & IF_AUD2) {
+	if (irq & IF_AUD2) {
 		custom.intreq = IF_AUD2;
 		amiga_do_irq(IRQ_AMIGA_AUD2, fp);
 	}
 
 	/* if audio 3 interrupt */
-	if (ints & IF_AUD3) {
+	if (irq & IF_AUD3) {
 		custom.intreq = IF_AUD3;
 		amiga_do_irq(IRQ_AMIGA_AUD3, fp);
 	}
@@ -460,64 +374,93 @@
 
 static void ami_int5(int irq, void *dev_id, struct pt_regs *fp)
 {
-	unsigned short ints = custom.intreqr & custom.intenar;
-
 	/* if serial receive buffer full interrupt */
-	if (ints & IF_RBF) {
+	if (irq & IF_RBF) {
 		/* acknowledge of IF_RBF must be done by the serial interrupt */
 		amiga_do_irq(IRQ_AMIGA_RBF, fp);
 	}
 
 	/* if a disk sync interrupt */
-	if (ints & IF_DSKSYN) {
+	if (irq & IF_DSKSYN) {
 		custom.intreq = IF_DSKSYN;
 		amiga_do_irq(IRQ_AMIGA_DSKSYN, fp);
 	}
 }
 
-static void ami_int7(int irq, void *dev_id, struct pt_regs *fp)
+static void ami_int6(int irq, void *dev_id, struct pt_regs *fp)
 {
-	panic ("level 7 interrupt received\n");
+	custom.intreq = IF_EXTER;
+	amiga_do_irq_list(IRQ_AMIGA_EXTER, fp);
 }
-
-void (*amiga_default_handler[SYS_IRQS])(int, void *, struct pt_regs *) = {
-	ami_badint, ami_int1, ami_badint, ami_int3,
-	ami_int4, ami_int5, ami_badint, ami_int7
-};
 
-int amiga_get_irq_list(char *buf)
+void amiga_do_irqrequest(void)
 {
-	int i, len = 0;
-	irq_node_t *node;
-
-	for (i = 0; i < AMI_STD_IRQS; i++) {
-		if (!(node = ami_irq_list[i]))
-			continue;
-		if (node->flags & IRQ_FLG_STD)
-			continue;
-		len += sprintf(buf+len, "ami  %2d: %10u ", i,
-		               kstat.irqs[0][SYS_IRQS + i]);
-		do {
-			if (ami_servers[i]) {
-				if (node->flags & IRQ_FLG_FAST)
-					len += sprintf(buf+len, "F ");
-				else if (node->flags & IRQ_FLG_SLOW)
-					len += sprintf(buf+len, "S ");
-				else
-					len += sprintf(buf+len, "  ");
-			} else {
-				if (node->flags & IRQ_FLG_LOCK)
-					len += sprintf(buf+len, "L ");
-				else
-					len += sprintf(buf+len, "  ");
-			}
-			len += sprintf(buf+len, "%s\n", node->devname);
-			if ((node = node->next))
-				len += sprintf(buf+len, "                    ");
-		} while (node);
+	unsigned int old_request, old_mask;
+#ifdef CONFIG_APUS
+	unsigned int oldcount;
+#else
+	unsigned char res;
+#endif
+	int irq;
+	static struct pt_regs dummy_regs;
+
+	if (local_irq_count[0]) {
+		printk("non rt safe int? (%p)\n", __builtin_return_address(0));
+		soft_irq_count = ~0;
+		return;
+	}
+	if (local_bh_count[0]) {
+		soft_irq_count++;
+		return;
 	}
 
-	len += cia_get_irq_list(&ciaa_base, buf+len);
-	len += cia_get_irq_list(&ciab_base, buf+len);
-	return len;
+	do {
+		soft_irq_count = 0;
+		hardirq_enter(0);
+		old_request = xchg(&rt_irqrequest, 0);
+
+		old_mask = old_request;
+		custom.intreq = old_mask & (0x3fff & ~IF_RBF);
+		while ( old_request ) {
+#ifdef CONFIG_APUS
+#else
+			asm ("bfffo %1{#0,#32},%0; bfclr %1{%0,#1}"
+			     : "=&d" (irq), "=d" (old_request)
+			     : "1" (old_request): "cc");
+			irq = 31 - irq;
+#endif
+#if 0
+			{
+				char ch = 'a'+irq;
+				amiga_serial_console_write(NULL, &ch, 1);
+			}
+#endif
+			if (ami_servers[irq])
+				amiga_do_softirq_list(irq, &dummy_regs);
+			else
+				amiga_do_softirq(irq, &dummy_regs);
+		}
+		custom.intena = IF_SETCLR | (old_mask & 0x3fff);
+		if ((old_mask >>= AMI_STD_IRQS)) {
+			cia_able_irq(&ciaa_base, CIA_ICR_SETCLR |
+			             (old_mask & CIA_ICR_ALL));
+			if ((old_mask >>= CIA_IRQS))
+				cia_able_irq(&ciab_base, CIA_ICR_SETCLR | old_mask);
+		}
+		hardirq_exit(0);
+		if (bh_active & bh_mask)
+			do_bottom_half();
+
+#ifdef CONFIG_APUS
+		asm ("1: lwarx %0,0,%2; addi %0,%0,-1; "
+		     "   stwcx. %0,0,%2; bne 1b"
+		     : "=&b" (oldcount), "=m" (soft_irq_count)
+		     : "r" (&soft_irq_count): "cr0");
+	} while (oldcount != ~0);
+#else
+		asm ("subql #1,%1; scc %0"
+		     : "=d" (res), "=m" (soft_irq_count)
+		     : "1" (soft_irq_count): "cc");
+	} while (res);
+#endif
 }
Index: linux-2.1/arch/m68k/amiga/cia.c
diff -u linux-2.1/arch/m68k/amiga/cia.c:1.1.1.1.6.2 linux-2.1/arch/m68k/amiga/cia.c:1.1.1.1.6.2.2.2
--- linux-2.1/arch/m68k/amiga/cia.c:1.1.1.1.6.2	Sat Dec 19 18:51:13 1998
+++ linux-2.1/arch/m68k/amiga/cia.c	Sun Dec 20 01:29:12 1998
@@ -20,25 +20,26 @@
 #include <asm/irq.h>
 #include <asm/amigahw.h>
 #include <asm/amigaints.h>
+#include <asm/traps.h>
 
+#include <config/advanced.h>
+#ifdef CONFIG_ADVANCED
+#include <config/rt/interrupt.h>
+#endif
+
 struct ciabase {
 	volatile struct CIA *cia;
-	u_char icr_mask, icr_data;
+	int cia_irq;
 	u_short int_mask;
-	int handler_irq, cia_irq, server_irq;
-	char *name;
-	struct irq_server server;
-	irq_handler_t irq_list[CIA_IRQS];
+	u_char allocmask, pad;
+	u_char icr_mask, icr_data;
+	u_char rtmask, slowmask;
 } ciaa_base = {
-	&ciaa, 0, 0, IF_PORTS,
-	IRQ_AMIGA_AUTO_2, IRQ_AMIGA_CIAA,
-	IRQ_AMIGA_PORTS,
-	"CIAA handler", {0, 0}
+	&ciaa, IRQ_AMIGA_CIAA,
+	IF_PORTS, CIA_ICR_ALL, 0, 0, 0, 0, 0
 }, ciab_base = {
-	&ciab, 0, 0, IF_EXTER,
-	IRQ_AMIGA_AUTO_6, IRQ_AMIGA_CIAB,
-	IRQ_AMIGA_EXTER,
-	"CIAB handler", {0, 0}
+	&ciab, IRQ_AMIGA_CIAB,
+	IF_EXTER, CIA_ICR_ALL, 0, 0, 0, 0, 0
 };
 
 /*
@@ -66,23 +67,17 @@
 
 unsigned char cia_able_irq(struct ciabase *base, unsigned char mask)
 {
-	u_char old, tmp;
-	int i;
+	u_char old;
 
 	old = base->icr_mask;
 	base->icr_data |= base->cia->icr;
+	mask &= CIA_ICR_SETCLR | base->allocmask;
 	base->cia->icr = mask;
 	if (mask & CIA_ICR_SETCLR)
 		base->icr_mask |= mask;
 	else
 		base->icr_mask &= ~mask;
 	base->icr_mask &= CIA_ICR_ALL;
-	for (i = 0, tmp = 1; i < CIA_IRQS; i++, tmp <<= 1) {
-		if ((tmp & base->icr_mask) && !base->irq_list[i].handler) {
-			base->icr_mask &= ~tmp;
-			base->cia->icr = tmp;
-		}
-	}
 	if (base->icr_data & base->icr_mask)
 		custom.intreq = IF_SETCLR | base->int_mask;
 	return old;
@@ -92,102 +87,100 @@
                     void (*handler)(int, void *, struct pt_regs *),
                     unsigned long flags, const char *devname, void *dev_id)
 {
+	unsigned int vec;
+	int res;
 	u_char mask;
 
-	if (!(base->irq_list[irq].flags & IRQ_FLG_STD)) {
-		if (base->irq_list[irq].flags & IRQ_FLG_LOCK) {
-			printk("%s: IRQ %i from %s is not replaceable\n",
-			       __FUNCTION__, base->cia_irq + irq,
-			       base->irq_list[irq].devname);
-			return -EBUSY;
-		}
-		if (!(flags & IRQ_FLG_REPLACE)) {
-			printk("%s: %s can't replace IRQ %i from %s\n", __FUNCTION__,
-			       devname, base->cia_irq + irq,
-			       base->irq_list[irq].devname);
-			return -EBUSY;
-		}
-	}
-	base->irq_list[irq].handler = handler;
-	base->irq_list[irq].flags   = flags;
-	base->irq_list[irq].dev_id  = dev_id;
-	base->irq_list[irq].devname = devname;
+	vec = VEC_USER + base->cia_irq + irq;
+	res = sys_request_irq(vec, handler, flags, devname, dev_id);
 
-	/* enable the interrupt */
-	mask = 1 << irq;
-	cia_set_irq(base, mask);
-	cia_able_irq(base, CIA_ICR_SETCLR | mask);
+	if (!res) {
+		mask = 1 << irq;
+#ifdef CONFIG_RT_INTERRUPT
+		if (!(flags & IRQ_FLG_REALTIME))
+			base->slowmask |= mask;
+		else
+			base->rtmask |=mask;
+#endif
+		/* enable the interrupt */
+		base->allocmask |= mask;
+		cia_set_irq(base, mask);
+		cia_able_irq(base, CIA_ICR_SETCLR | mask);
+	}
 	return 0;
 }
 
 void cia_free_irq(struct ciabase *base, unsigned int irq, void *dev_id)
 {
-	if (base->irq_list[irq].dev_id != dev_id)
-		printk("%s: removing probably wrong IRQ %i from %s\n",
-		       __FUNCTION__, base->cia_irq + irq,
-		       base->irq_list[irq].devname);
+	unsigned int vec;
+	u_char mask;
 
-	base->irq_list[irq].handler = NULL;
-	base->irq_list[irq].flags   = IRQ_FLG_STD;
+	vec = VEC_USER + base->cia_irq + irq;
+	sys_free_irq(vec, dev_id);
 
-	cia_able_irq(base, 1 << irq);
+	mask = 1 << irq;
+#ifndef CONFIG_RT_INTERRUPT
+	if (!userirq_list[base->cia_irq + irq]) {
+		cia_able_irq(base, mask);
+		base->allocmask &= ~mask;
+	}
+#else
+	if (!userirq_list[base->cia_irq + irq])
+		base->rtmask &= ~mask;
+	if (!userirq_softlist[base->cia_irq + irq])
+		base->slowmask &= ~mask;
+	if (!userirq_list[base->cia_irq + irq] &&
+	    !userirq_softlist[base->cia_irq + irq]) {
+		cia_able_irq(base, mask);
+		base->allocmask &= ~mask;
+	}
+#endif
 }
 
 static void cia_handler(int irq, void *dev_id, struct pt_regs *fp)
 {
 	struct ciabase *base = (struct ciabase *)dev_id;
-	int mach_irq, i;
 	unsigned char ints;
+#ifdef CONFIG_RT_INTERRUPT
+	unsigned char softints;
+#endif
 
-	mach_irq = base->cia_irq;
-	irq = SYS_IRQS + mach_irq;
 	ints = cia_set_irq(base, CIA_ICR_ALL);
+#ifdef CONFIG_RT_INTERRUPT
+	if ((softints = ints & base->slowmask)) {
+		rt_irqrequest |= softints << base->cia_irq;
+		cia_able_irq(base, softints);
+	}
+	ints &= base->rtmask;
+#endif
 	custom.intreq = base->int_mask;
-	for (i = 0; i < CIA_IRQS; i++, irq++, mach_irq++) {
-		if (ints & 1) {
-			kstat.irqs[0][irq]++;
-			base->irq_list[i].handler(mach_irq, base->irq_list[i].dev_id, fp);
+	if ( ints ) {
+		unsigned int irq = base->cia_irq + CIA_IRQS - 1;
+		irq_node_t **list = &userirq_list[irq];
+		unsigned int *stat = &kstat.irqs[0][irq + AUTO_IRQ_NR];
+		for (ints <<= 3; ints; ints <<= 1) {
+			if ( ints & 0x80 ) {
+				(*stat)++;
+				(*list)->handler(irq, (*list)->dev_id, fp);
+			}
+			stat--; list--; irq--;
 		}
-		ints >>= 1;
 	}
-	amiga_do_irq_list(base->server_irq, fp, &base->server);
 }
 
-__initfunc(void cia_init_IRQ(struct ciabase *base))
+void __init cia_init_IRQ(void)
 {
-	int i;
-
-	/* init isr handlers */
-	for (i = 0; i < CIA_IRQS; i++) {
-		base->irq_list[i].handler = NULL;
-		base->irq_list[i].flags   = IRQ_FLG_STD;
-	}
-
 	/* clear any pending interrupt and turn off all interrupts */
-	cia_set_irq(base, CIA_ICR_ALL);
-	cia_able_irq(base, CIA_ICR_ALL);
+	cia_set_irq(&ciaa_base, CIA_ICR_ALL);
+	cia_able_irq(&ciaa_base, CIA_ICR_ALL);
+	cia_set_irq(&ciab_base, CIA_ICR_ALL);
+	cia_able_irq(&ciab_base, CIA_ICR_ALL);
+	ciaa_base.allocmask = ciab_base.allocmask = 0;
 
 	/* install CIA handler */
-	request_irq(base->handler_irq, cia_handler, IRQ_FLG_LOCK, base->name, base);
+	request_irq(IRQ_AMIGA_PORTS, cia_handler, IRQ_FLG_REALTIME | IRQ_FLG_FAST,
+	            "ciaa handler", &ciaa_base);
+	request_irq(IRQ_AMIGA_EXTER, cia_handler, IRQ_FLG_REALTIME | IRQ_FLG_FAST,
+	            "ciab handler", &ciab_base);
 
-	custom.intena = IF_SETCLR | base->int_mask;
-}
-
-int cia_get_irq_list(struct ciabase *base, char *buf)
-{
-	int i, j, len = 0;
-
-	j = base->cia_irq;
-	for (i = 0; i < CIA_IRQS; i++) {
-		if (!(base->irq_list[i].flags & IRQ_FLG_STD)) {
-			len += sprintf(buf+len, "cia  %2d: %10d ", j + i,
-			               kstat.irqs[0][SYS_IRQS + j + i]);
-			if (base->irq_list[i].flags & IRQ_FLG_LOCK)
-				len += sprintf(buf+len, "L ");
-			else
-				len += sprintf(buf+len, "  ");
-			len += sprintf(buf+len, "%s\n", base->irq_list[i].devname);
-		}
-	}
-	return len;
 }
Index: linux-2.1/arch/m68k/amiga/config.c
diff -u linux-2.1/arch/m68k/amiga/config.c:1.1.1.4.6.2 linux-2.1/arch/m68k/amiga/config.c:1.1.1.4.6.2.2.1
--- linux-2.1/arch/m68k/amiga/config.c:1.1.1.4.6.2	Sat Dec 19 18:51:14 1998
+++ linux-2.1/arch/m68k/amiga/config.c	Sat Dec 19 21:28:09 1998
@@ -48,46 +48,15 @@
 
 extern char m68k_debug_device[];
 
-static void amiga_sched_init(void (*handler)(int, void *, struct pt_regs *));
-/* amiga specific keyboard functions */
-extern int amiga_keyb_init(void);
-extern int amiga_kbdrate (struct kbd_repeat *);
-extern void amiga_kbd_reset_setup(char*, int);
-/* amiga specific irq functions */
-extern void amiga_init_IRQ (void);
-extern void (*amiga_default_handler[]) (int, void *, struct pt_regs *);
-extern int amiga_request_irq (unsigned int irq,
-			      void (*handler)(int, void *, struct pt_regs *),
-                              unsigned long flags, const char *devname,
-			      void *dev_id);
-extern void amiga_free_irq (unsigned int irq, void *dev_id);
-extern void amiga_enable_irq (unsigned int);
-extern void amiga_disable_irq (unsigned int);
-static void amiga_get_model(char *model);
-static int amiga_get_hardware_list(char *buffer);
-extern int amiga_get_irq_list (char *);
-/* amiga specific timer functions */
-static unsigned long amiga_gettimeoffset (void);
-static void a3000_gettod (int *, int *, int *, int *, int *, int *);
-static void a2000_gettod (int *, int *, int *, int *, int *, int *);
-static int amiga_hwclk (int, struct hwclk_time *);
-static int amiga_set_clock_mmss (unsigned long);
-extern void amiga_mksound( unsigned int count, unsigned int ticks );
-#ifdef CONFIG_AMIGA_FLOPPY
-extern void amiga_floppy_setup(char *, int *);
-#endif
-static void amiga_reset (void);
+int amiga_cia_timer __initdata = 1;
+
 static int amiga_wait_key (struct console *co);
-extern void amiga_init_sound(void);
 static void amiga_savekmsg_init(void);
-static void amiga_mem_console_write(struct console *co, const char *b,
+static void amiga_mem_console_write(struct console *co, const char *s,
 				    unsigned int count);
 void amiga_serial_console_write(struct console *co, const char *s,
 				unsigned int count);
 static void amiga_debug_init(void);
-#ifdef CONFIG_HEARTBEAT
-static void amiga_heartbeat(int on);
-#endif
 
 static struct console amiga_console_driver = {
 	"debug",
@@ -174,7 +143,7 @@
      *  Identify builtin hardware
      */
 
-__initfunc(static void amiga_identify(void))
+static void __init amiga_identify(void)
 {
   /* Fill in some default values, if necessary */
   if (amiga_eclock == 0)
@@ -335,24 +304,23 @@
      *  Setup the Amiga configuration info
      */
 
-__initfunc(void config_amiga(void))
+void __init config_amiga(void)
 {
   amiga_debug_init();
   amiga_identify();
 
+#ifndef NO_MACH_DEFS
   mach_sched_init      = amiga_sched_init;
   mach_keyb_init       = amiga_keyb_init;
   mach_kbdrate         = amiga_kbdrate;
-  kbd_reset_setup      = amiga_kbd_reset_setup;
   mach_init_IRQ        = amiga_init_IRQ;
-  mach_default_handler = &amiga_default_handler;
   mach_request_irq     = amiga_request_irq;
   mach_free_irq        = amiga_free_irq;
   enable_irq           = amiga_enable_irq;
   disable_irq          = amiga_disable_irq;
+#endif
   mach_get_model       = amiga_get_model;
   mach_get_hardware_list = amiga_get_hardware_list;
-  mach_get_irq_list    = amiga_get_irq_list;
   mach_gettimeoffset   = amiga_gettimeoffset;
   if (AMIGAHW_PRESENT(A3000_CLK)){
     mach_gettod  = a3000_gettod;
@@ -448,42 +416,63 @@
 
 static unsigned short jiffy_ticks;
 
-__initfunc(static void amiga_sched_init(void (*timer_routine)(int, void *,
-					struct pt_regs *)))
+void __init amiga_sched_init(void (*timer_routine)(int, void *,
+				   struct pt_regs *))
 {
 	jiffy_ticks = (amiga_eclock+HZ/2)/HZ;
+
+	/* turn off timer A, continuous mode, from Eclk */
+	if (amiga_cia_timer) {
+		ciab.cra &= 0xC0;
+		ciab.talo = jiffy_ticks % 256;
+		ciab.tahi = jiffy_ticks / 256;
+	} else {
+		ciaa.cra &= 0xC0;
+		ciaa.talo = jiffy_ticks % 256;
+		ciaa.tahi = jiffy_ticks / 256;
+	}
 
-	ciab.cra &= 0xC0;   /* turn off timer A, continuous mode, from Eclk */
-	ciab.talo = jiffy_ticks % 256;
-	ciab.tahi = jiffy_ticks / 256;
-
-	/* install interrupt service routine for CIAB Timer A
-	 *
-	 * Please don't change this to use ciaa, as it interferes with the
-	 * SCSI code. We'll have to take a look at this later
+	/* install timer interrupt service routine 
+	 * default is to use CIAB to avoid problems with scsi drivers,
+	 * but it can be changed to CIAA to give the serial interrupt
+	 * more time.
 	 */
-	request_irq(IRQ_AMIGA_CIAB_TA, timer_routine, IRQ_FLG_LOCK,
-		    "timer", NULL);
+	request_irq(amiga_cia_timer ? IRQ_AMIGA_CIAB_TA : IRQ_AMIGA_CIAA_TA,
+	            timer_routine, IRQ_FLG_LOCK, "timer", NULL);
 	/* start timer */
-	ciab.cra |= 0x11;
+	if (amiga_cia_timer)
+		ciab.cra |= 0x11;
+	else
+		ciaa.cra |= 0x11;
 }
 
 #define TICK_SIZE 10000
 
 /* This is always executed with interrupts disabled.  */
-static unsigned long amiga_gettimeoffset (void)
+unsigned long amiga_gettimeoffset (void)
 {
 	unsigned short hi, lo, hi2;
 	unsigned long ticks, offset = 0;
 
-	/* read CIA B timer A current value */
-	hi  = ciab.tahi;
-	lo  = ciab.talo;
-	hi2 = ciab.tahi;
-
-	if (hi != hi2) {
-		lo = ciab.talo;
-		hi = hi2;
+	/* read CIA timer A current value */
+	if (amiga_cia_timer) {
+		hi  = ciab.tahi;
+		lo  = ciab.talo;
+		hi2 = ciab.tahi;
+
+		if (hi != hi2) {
+			lo = ciab.talo;
+			hi = hi2;
+		}
+	} else {
+		hi  = ciaa.tahi;
+		lo  = ciaa.talo;
+		hi2 = ciaa.tahi;
+
+		if (hi != hi2) {
+			lo = ciaa.talo;
+			hi = hi2;
+		}
 	}
 
 	ticks = hi << 8 | lo;
@@ -499,8 +488,8 @@
 	return ticks + offset;
 }
 
-static void a3000_gettod (int *yearp, int *monp, int *dayp,
-			  int *hourp, int *minp, int *secp)
+void a3000_gettod (int *yearp, int *monp, int *dayp,
+		   int *hourp, int *minp, int *secp)
 {
 	volatile struct tod3000 *tod = TOD_3000;
 
@@ -516,8 +505,8 @@
 	tod->cntrl1 = TOD3000_CNTRL1_FREE;
 }
 
-static void a2000_gettod (int *yearp, int *monp, int *dayp,
-			  int *hourp, int *minp, int *secp)
+void a2000_gettod (int *yearp, int *monp, int *dayp,
+		   int *hourp, int *minp, int *secp)
 {
 	volatile struct tod2000 *tod = TOD_2000;
 
@@ -543,7 +532,7 @@
 	tod->cntrl1 &= ~TOD2000_CNTRL1_HOLD;
 }
 
-static int amiga_hwclk(int op, struct hwclk_time *t)
+int amiga_hwclk(int op, struct hwclk_time *t)
 {
 	if (AMIGAHW_PRESENT(A3000_CLK)) {
 		volatile struct tod3000 *tod = TOD_3000;
@@ -628,7 +617,7 @@
 	return 0;
 }
 
-static int amiga_set_clock_mmss (unsigned long nowtime)
+int amiga_set_clock_mmss (unsigned long nowtime)
 {
 	short real_seconds = nowtime % 60, real_minutes = (nowtime / 60) % 60;
 
@@ -703,10 +692,9 @@
 	console_print (buf);
 }
 
-static NORET_TYPE void amiga_reset( void )
-    ATTRIB_NORET;
+NORET_TYPE void amiga_reset( void ) ATTRIB_NORET;
 
-static void amiga_reset (void)
+void amiga_reset (void)
 {
   unsigned long jmp_addr040 = virt_to_phys(&&jmp_addr_label040);
   unsigned long jmp_addr = virt_to_phys(&&jmp_addr_label);
@@ -816,13 +804,18 @@
 }
 
 void amiga_serial_console_write(struct console *co, const char *s,
-				       unsigned int count)
+				unsigned int count)
 {
+    unsigned long flags;
+
+    __save_flags(flags);
+    __cli();
     while (count--) {
 	if (*s == '\n')
 	    amiga_serial_putc('\r');
 	amiga_serial_putc(*s++);
     }
+    __restore_flags(flags);
 }
 
 #ifdef CONFIG_SERIAL_CONSOLE
@@ -882,7 +875,7 @@
 }
 #endif
 
-__initfunc(static void amiga_debug_init(void))
+static void __init amiga_debug_init(void)
 {
 	if (!strcmp( m68k_debug_device, "ser" )) {
 		/* no initialization required (?) */
@@ -892,7 +885,7 @@
 }
 
 #ifdef CONFIG_HEARTBEAT
-static void amiga_heartbeat(int on)
+void amiga_heartbeat(int on)
 {
     if (on)
 	ciaa.pra &= ~2;
@@ -905,7 +898,7 @@
      *  Amiga specific parts of /proc
      */
 
-static void amiga_get_model(char *model)
+void amiga_get_model(char *model)
 {
     strcpy(model, "Amiga ");
     if (amiga_model >= AMI_500 && amiga_model <= AMI_DRACO)
@@ -913,7 +906,7 @@
 }
 
 
-static int amiga_get_hardware_list(char *buffer)
+int amiga_get_hardware_list(char *buffer)
 {
     int len = 0;
 
Index: linux-2.1/arch/m68k/atari/atakeyb.c
diff -u linux-2.1/arch/m68k/atari/atakeyb.c:1.1.1.2.6.3 linux-2.1/arch/m68k/atari/atakeyb.c:1.1.1.2.6.3.2.1
--- linux-2.1/arch/m68k/atari/atakeyb.c:1.1.1.2.6.3	Sat Dec 19 18:51:15 1998
+++ linux-2.1/arch/m68k/atari/atakeyb.c	Sat Dec 19 21:28:10 1998
@@ -861,8 +861,3 @@
 	
 	return( 0 );
 }
-
-/* for "kbd-reset" cmdline param */
-__initfunc(void atari_kbd_reset_setup(char *str, int *ints))
-{
-}
Index: linux-2.1/arch/m68k/atari/config.c
diff -u linux-2.1/arch/m68k/atari/config.c:1.1.1.3.6.2 linux-2.1/arch/m68k/atari/config.c:1.1.1.3.6.2.2.1
--- linux-2.1/arch/m68k/atari/config.c:1.1.1.3.6.2	Sat Dec 19 18:51:17 1998
+++ linux-2.1/arch/m68k/atari/config.c	Sat Dec 19 21:28:13 1998
@@ -60,7 +60,6 @@
 extern int atari_keyb_init(void);
 extern int atari_kbdrate (struct kbd_repeat *);
 extern void atari_kbd_leds (unsigned int);
-extern void atari_kbd_reset_setup(char*, int);
 /* atari specific irq functions */
 extern void atari_init_IRQ (void);
 extern int atari_request_irq (unsigned int irq, void (*handler)(int, void *, struct pt_regs *),
@@ -251,7 +250,6 @@
     mach_keyb_init       = atari_keyb_init;
     mach_kbdrate         = atari_kbdrate;
     mach_kbd_leds        = atari_kbd_leds;
-    kbd_reset_setup      = atari_kbd_reset_setup;
     mach_init_IRQ        = atari_init_IRQ;
     mach_request_irq     = atari_request_irq;
     mach_free_irq        = atari_free_irq;
Index: linux-2.1/arch/m68k/hp300/config.c
diff -u linux-2.1/arch/m68k/hp300/config.c:1.1.1.2.6.2 linux-2.1/arch/m68k/hp300/config.c:1.1.1.2.6.2.2.1
--- linux-2.1/arch/m68k/hp300/config.c:1.1.1.2.6.2	Sat Dec 19 18:51:18 1998
+++ linux-2.1/arch/m68k/hp300/config.c	Sat Dec 19 21:28:14 1998
@@ -55,11 +55,6 @@
 {
 }
 
-/* for "kbd-reset" cmdline param */
-__initfunc(void hp300_kbd_reset_setup(char *str, int i))
-{
-}
-
 static void hp300_get_model(char *model)
 {
   strcpy(model, "HP9000/300");
@@ -74,7 +69,6 @@
   mach_init_IRQ        = hp300_init_IRQ;
   mach_request_irq     = hp300_request_irq;
   mach_free_irq        = hp300_free_irq;
-  kbd_reset_setup      = hp300_kbd_reset_setup;
   mach_get_model       = hp300_get_model;
   mach_get_irq_list    = hp300_get_irq_list;
   mach_gettimeoffset   = hp300_gettimeoffset;
Index: linux-2.1/arch/m68k/ifpsp060/iskeleton.S
diff -u linux-2.1/arch/m68k/ifpsp060/iskeleton.S:1.1.1.2.6.2 linux-2.1/arch/m68k/ifpsp060/iskeleton.S:1.1.1.2.6.2.2.1
--- linux-2.1/arch/m68k/ifpsp060/iskeleton.S:1.1.1.2.6.2	Sat Dec 19 18:51:19 1998
+++ linux-2.1/arch/m68k/ifpsp060/iskeleton.S	Sat Dec 19 21:28:15 1998
@@ -36,6 +36,7 @@
 
 #include <linux/linkage.h>
 #include <asm/entry.h>
+#include "../kernel/m68k_defs.h"
 
 
 |################################
@@ -69,12 +70,12 @@
 	.global		_060_isp_done
 _060_isp_done:
 	btst	#0x5,%sp@		| supervisor bit set in saved SR?
-	beq	Lnotkern
+	beq	.Lnotkern
 	rte
-Lnotkern:
+.Lnotkern:
 	SAVE_ALL_INT
 	GET_CURRENT(%d0)
-	tstl	%curptr@(LTASK_NEEDRESCHED)
+	tstl	%curptr@(TASK_NEEDRESCHED)
 	jne	SYMBOL_NAME(ret_from_exception)	| deliver signals,
 						| reschedule etc..
 	RESTORE_ALL
Index: linux-2.1/arch/m68k/kernel/entry.S
diff -u linux-2.1/arch/m68k/kernel/entry.S:1.1.1.5.6.2 linux-2.1/arch/m68k/kernel/entry.S:1.1.1.5.6.2.2.1
--- linux-2.1/arch/m68k/kernel/entry.S:1.1.1.5.6.2	Sat Dec 19 18:51:20 1998
+++ linux-2.1/arch/m68k/kernel/entry.S	Sat Dec 19 21:28:16 1998
@@ -31,12 +31,28 @@
  */
 
 #include <linux/sys.h>
-#include <linux/config.h>
 #include <linux/linkage.h>
 #include <asm/entry.h>
+#include <asm/errno.h>
+#include <asm/irq.h>
 #include <asm/setup.h>
 #include <asm/segment.h>
+#include <asm/traps.h>
 
+#include <config/amiga.h>
+#include <config/m68060.h>
+#include <config/advanced.h>
+#ifdef CONFIG_ADVANCED
+#include <config/rt/interrupt.h>
+#endif
+#include <config/experimental.h>
+#ifdef CONFIG_EXPERIMENTAL
+#include <config/math/emu.h>
+#ifdef CONFIG_MATH_EMU
+#include <config/math/emu/only.h>
+#endif
+#endif
+
 #include "m68k_defs.h"
 
 .globl SYMBOL_NAME(system_call), SYMBOL_NAME(buserr), SYMBOL_NAME(trap)
@@ -44,7 +60,6 @@
 .globl SYMBOL_NAME(ret_from_signal)
 .globl SYMBOL_NAME(inthandler), SYMBOL_NAME(sys_call_table)
 .globl SYMBOL_NAME(sys_fork), SYMBOL_NAME(sys_clone)
-.globl SYMBOL_NAME(ret_from_interrupt), SYMBOL_NAME(bad_interrupt)
 
 .text
 ENTRY(buserr)
@@ -65,24 +80,24 @@
 
 ENTRY(reschedule)
 	| save top of frame
-	movel	%sp,%curptr@(TS_ESP0)
+	movel	%sp,%curptr@(TASK_TSS+TSS_ESP0)
 
 	pea	SYMBOL_NAME(ret_from_exception)
 	jmp	SYMBOL_NAME(schedule)
 
 badsys:
-	movel	#-LENOSYS,LPT_OFF_D0(%sp)
+	movel	#-ENOSYS,PT_D0(%sp)
 	jra	SYMBOL_NAME(ret_from_exception)
 
 do_trace:
-	movel	#-LENOSYS,LPT_OFF_D0(%sp)	| needed for strace
+	movel	#-ENOSYS,PT_D0(%sp)	| needed for strace
 	subql	#4,%sp
 	SAVE_SWITCH_STACK
 	jbsr	SYMBOL_NAME(syscall_trace)
 	RESTORE_SWITCH_STACK
 	addql	#4,%sp
 	jbsr	@(SYMBOL_NAME(sys_call_table),%d2:l:4)@(0)
-	movel	%d0,%sp@(LPT_OFF_D0)	| save the return value
+	movel	%d0,%sp@(PT_D0)		| save the return value
 	subql	#4,%sp			| dummy return address
 	SAVE_SWITCH_STACK
 	jbsr	SYMBOL_NAME(syscall_trace)
@@ -98,34 +113,30 @@
 
 	GET_CURRENT(%d0)
 	| save top of frame
-	movel	%sp,%curptr@(TS_ESP0)
+	movel	%sp,%curptr@(TASK_TSS+TSS_ESP0)
 
 	cmpl	#NR_syscalls,%d2
 	jcc	badsys
-	btst	#LPF_TRACESYS_BIT,%curptr@(LTASK_FLAGS+LPF_TRACESYS_OFF)
+	btst	#PF_TRACESYS_BIT,%curptr@(TASK_FLAGS+PF_TRACESYS_OFF)
 	jne	do_trace
 	jbsr	@(SYMBOL_NAME(sys_call_table),%d2:l:4)@(0)
-	movel	%d0,%sp@(LPT_OFF_D0)	| save the return value
+	movel	%d0,%sp@(PT_D0)		| save the return value
 
 SYMBOL_NAME_LABEL(ret_from_exception)
-	btst	#5,%sp@(LPT_OFF_SR)	| check if returning to kernel
+	btst	#5,%sp@(PT_SR)		| check if returning to kernel
 	bnes	2f			| if so, skip resched, signals
-	| only allow interrupts when we are really the last one on the
-	| kernel stack, otherwise stack overflow can occur during
-	| heavy interupt load
-	andw	#ALLOWINT,%sr
-	tstl	%curptr@(LTASK_NEEDRESCHED)
+	tstl	%curptr@(TASK_NEEDRESCHED)
 	jne	SYMBOL_NAME(reschedule)
 	cmpl	#SYMBOL_NAME(task),%curptr	| task[0] cannot have signals
 	jeq	2f
 					| check for delayed trace
-	bclr	#LPF_DTRACE_BIT,%curptr@(LTASK_FLAGS+LPF_DTRACE_OFF)
+	bclr	#PF_DTRACE_BIT,%curptr@(TASK_FLAGS+PF_DTRACE_OFF)
 	jne	do_delayed_trace
 5:
-	tstl	%curptr@(LTASK_STATE)	| state
+	tstl	%curptr@(TASK_STATE)	| state
 	jne	SYMBOL_NAME(reschedule)
 
-	tstl	%curptr@(LTASK_SIGPENDING)
+	tstl	%curptr@(TASK_SIGPENDING)
 	jne	Lsignal_return
 2:	RESTORE_ALL
 
@@ -141,7 +152,7 @@
 	RESTORE_ALL
 
 do_delayed_trace:
-	bclr	#7,%sp@(LPT_OFF_SR)	| clear trace bit in SR
+	bclr	#7,%sp@(PT_SR)		| clear trace bit in SR
 	pea	1			| send SIGTRAP
 	movel	%curptr,%sp@-
 	pea	LSIGTRAP
@@ -151,46 +162,165 @@
 	jra	5b
 
 /*
-** This is the main interrupt handler, responsible for calling process_int()
+** This is the general autovector interrupt handler
 */
-SYMBOL_NAME_LABEL(inthandler)
-	SAVE_ALL_INT
-	GET_CURRENT(%d0)
+.macro	inthandler intnodes, firstvec, dolist
 	addql	#1,SYMBOL_NAME(local_irq_count)
-					|  put exception # in d0
-	bfextu %sp@(LPT_OFF_FORMATVEC){#4,#10},%d0
+	save_all_int
+	get_current
 
-	movel	%sp,%sp@-
-	movel	%d0,%sp@- 		|  put vector # on stack
-	jbsr	SYMBOL_NAME(process_int)|  process the IRQ
-	addql	#8,%sp			|  pop parameters off stack
+| extract exception vector, do some statistic and get int node
+	bfextu	%sp@(PT_VECTOR){#4,#12},%d0
+	movel	%d0,%a0
+	addql	#1,%a0@(SYMBOL_NAME(kstat)+STAT_IRQ-VECOFF(\firstvec))
+	movel	%a0@(SYMBOL_NAME(\intnodes)-VECOFF(\firstvec)),%a0
 
-SYMBOL_NAME_LABEL(ret_from_interrupt)
-	subql	#1,SYMBOL_NAME(local_irq_count)
-	jeq	1f
-2:	
-	RESTORE_ALL
-1:
-#if 1
-	bfextu  %sp@(LPT_OFF_SR){#5,#3},%d0	| Check for nested interrupt.
-#if MAX_NOINT_IPL > 0
-	cmpiw	#MAX_NOINT_IPL,%d0
-#endif
-	jhi	2b
+.if	\dolist
+	jra	2f
+ALIGN
+1:	movel	%a0@(IRQ_NEXT),%d0
+	jeq	SYMBOL_NAME(ret_from_interrupt)
+	movel	%d0,%a0
+	addql	#8,%sp
+	addql	#4,%sp
+.endif
+| prepare stack (push frame pointer, dev_id & vector #)
+2:	pea	%sp@
+	movel	%a0@(IRQ_DEVID),%sp@-
+	lsrl	#2,%d0
+	movel	%d0,%sp@-
+.if	\dolist
+	pea	%pc@(1b:w)
+.else
+	pea	%pc@(SYMBOL_NAME(ret_from_interrupt):w)
+.endif
+	jbra	@(IRQ_HANDLER,%a0)@(0)
+.endm
+
+#ifdef NEED_AUTO_IRQ_STD_HANDLER
+ENTRY(autoirq_handler)
+	inthandler autoirq_list, VEC_SPUR, 0
+#endif
+#ifdef NEED_AUTO_IRQ_STD_LISTHANDLER
+ENTRY(autoirq_listhandler)
+	inthandler autoirq_list, VEC_SPUR, 1
+#endif
+#ifdef NEED_USER_IRQ_STD_HANDLER
+ENTRY(userirq_handler)
+	inthandler userirq_list, VEC_USER, 0
+#endif
+#ifdef NEED_USER_IRQ_STD_USERHANDLER
+ENTRY(userirq_listhandler)
+	inthandler userirq_list, VEC_USER, 1
 #endif
-	/* check if we need to do software interrupts */
 
-	movel	SYMBOL_NAME(bh_active),%d0
+ENTRY(ret_from_interrupt)
+| clean up stack
+	addql	#8,%sp
+	addql	#4,%sp
+	subql	#1,SYMBOL_NAME(local_irq_count)
+| check for pending interrupts
+	movew	%sp@(PT_SR),%d0
+	andw	#0x0700,%d0
+	jeq	SYMBOL_NAME(do_softirq)
+1:	RESTORE_ALL
+
+| check for running software int
+ENTRY(do_softirq)
+	addql	#1,SYMBOL_NAME(soft_irq_count)
+	jcc	1b
+| we are last int on stack so we can reduce int mask
+	andw	#0xf8ff,%sr
+
+1:	movel	SYMBOL_NAME(bh_active),%d0
 	andl	SYMBOL_NAME(bh_mask),%d0
-	jeq	SYMBOL_NAME(ret_from_exception)
+	jeq	2f
+	jbsr	SYMBOL_NAME(do_bottom_half)
+
+| check if there was an interrupt, so we have to redo the soft ints
+2:	subql	#1,SYMBOL_NAME(soft_irq_count)
+	jcs	SYMBOL_NAME(ret_from_exception)
+	clrl	SYMBOL_NAME(soft_irq_count)
+	jbra	1b
 
+#ifdef CONFIG_AMIGA
+/*
+** Special Amiga interrupt handler
+*/
+.globl	SYMBOL_NAME(amiga_inthandler)
+.globl	SYMBOL_NAME(amiga_irqstat),SYMBOL_NAME(amiga_intnodes)
+
+ENTRY(amiga_inthandler)
+	addql	#1,SYMBOL_NAME(local_irq_count)
+	save_all_int
+	get_current
+
+| extract exception vector, do some statistic and get int node
+	bfextu	%sp@(PT_VECTOR){#4,#12},%d1
+	movel	%d1,%a0
+	addql	#1,%a0@(SYMBOL_NAME(kstat)+STAT_IRQ-VECOFF(VEC_SPUR))
+	movel	%a0@(SYMBOL_NAME(autoirq_list)-VECOFF(VEC_SPUR)),%a0
+
+| amiga vector int handler get the req mask instead of irq vector
+	lea	CUSTOMBASE,%a1
+	movew	%a1@(C_INTREQR),%d0
+	andw	%a1@(C_INTENAR),%d0
+
+#ifdef CONFIG_RT_INTERRUPT
+.globl	SYMBOL_NAME(amiga_slowintmask),SYMBOL_NAME(amiga_rtintmask)
+
+| disable slow ints and modify req mask
+	movew	%d0,%d1
+.equ	SYMBOL_NAME(amiga_slowintmask),.+2
+	andw	#0:w,%d1
+	jeq	1f
+	orw	%d1,SYMBOL_NAME(rt_irqrequest+2)
+|	movew	%d1,%a1@(C_INTREQ)
+	movew	%d1,%a1@(C_INTENA)
+.equ	SYMBOL_NAME(amiga_rtintmask),.+2
+1:	andw	#0:w,%d0
+	jeq	SYMBOL_NAME(amiga_fastret_from_irq)
+#endif /* CONFIG_RT_INTERRUPT */
+
+| prepare stack (push frame pointer, dev_id & req mask)
+	pea	%sp@
+	movel	%a0@(IRQ_DEVID),%sp@-
+	movel	%d0,%sp@-
+	pea	%pc@(SYMBOL_NAME(amiga_ret_from_irq):w)
+	jbra	@(IRQ_HANDLER,%a0)@(0)
+
+#ifdef CONFIG_RT_INTERRUPT
+ENTRY(amiga_ret_from_irq)
+	addql	#8,%sp
+	addql	#4,%sp
+
+SYMBOL_NAME_LABEL(amiga_fastret_from_irq)
+	subql	#1,SYMBOL_NAME(local_irq_count)
+| check for pending interrupts
+	movew	%sp@(PT_SR),%d0
+	andw	#0x0700,%d0
+	jeq	SYMBOL_NAME(amiga_do_softirq)
+1:	restore_all
+
+ENTRY(amiga_do_softirq)
+| check for running soft int
+	addql	#1,SYMBOL_NAME(soft_irq_count)
+	jcc	1b
+| we are last int on stack so we can reduce int mask
+	andw	#0xf8ff,%sr
 	pea	SYMBOL_NAME(ret_from_exception)
-	jra	SYMBOL_NAME(do_bottom_half)
+	jbra	SYMBOL_NAME(amiga_do_irqrequest)
+#else
+.equ	SYMBOL_NAME(amiga_ret_from_irq),SYMBOL_NAME(ret_from_interrupt)
+#endif /* CONFIG_RT_INTERRUPT */
 
+ENTRY(nmi_handler)
+	rte
+#endif /* CONFIG_AMIGA */
 
 /* Handler for uninitialized and spurious interrupts */
 
-SYMBOL_NAME_LABEL(bad_interrupt)
+ENTRY(bad_interrupt)
 	addql	#1,SYMBOL_NAME(num_spurious)
 	rte
 
@@ -240,37 +370,36 @@
 
 SYMBOL_NAME_LABEL(resume)
 	/*
-	 * Beware - when entering resume, offset of tss is in d1,
-	 * prev (the current task) is in a0, next (the new task)
-	 * is in a1 and d2.b is non-zero if the mm structure is
-	 * shared between the tasks, so don't change these
+	 * Beware - when entering resume, prev (the current task) is
+	 * in a0, next (the new task) is in a1,so don't change these
 	 * registers until their contents are no longer needed.
 	 */
 
-	/* offset of tss struct (processor state) from beginning
-	   of task struct */
-	addl	%d1,%a0
-
 	/* save sr */
-	movew	%sr,%a0@(LTSS_SR)
+	movew	%sr,%a0@(TASK_TSS+TSS_SR)
 
 	/* save fs (sfc,%dfc) (may be pointing to kernel memory) */
 	movec	%sfc,%d0
-	movew	%d0,%a0@(LTSS_FS)
+	movew	%d0,%a0@(TASK_TSS+TSS_FS)
 
 	/* save usp */
 	/* it is better to use a movel here instead of a movew 8*) */
 	movec	%usp,%d0
-	movel	%d0,%a0@(LTSS_USP)
+	movel	%d0,%a0@(TASK_TSS+TSS_USP)
 
 	/* save non-scratch registers on stack */
 	SAVE_SWITCH_STACK
 
 	/* save current kernel stack pointer */
-	movel	%sp,%a0@(LTSS_KSP)
+	movel	%sp,%a0@(TASK_TSS+TSS_KSP)
 
+#ifndef CONFIG_MATH_EMU_ONLY
+#ifdef CONFIG_MATH_EMU
+	tstl	SYMBOL_NAME(m68k_fputype)
+	jeq	3f
+#endif
 	/* save floating point context */
-	fsave	%a0@(LTSS_FPCTXT+27*4)
+	fsave	%a0@(TASK_TSS+TSS_FPSTATE)
 
 #if defined(CONFIG_M68060)
 #if !defined(CPU_M68060_ONLY)
@@ -278,27 +407,28 @@
 	beqs	1f
 #endif
 	/* The 060 FPU keeps status in bits 15-8 of the first longword */
-	tstb	%a0@(LTSS_FPCTXT+27*4+2)
+	tstb	%a0@(TASK_TSS+TSS_FPSTATE+2)
 	jeq	3f
 #if !defined(CPU_M68060_ONLY)
 	jra	2f
 #endif
 #endif /* CONFIG_M68060 */
 #if !defined(CPU_M68060_ONLY)
-1:	tstb	%a0@(LTSS_FPCTXT+27*4)
+1:	tstb	%a0@(TASK_TSS+TSS_FPSTATE)
 	jeq	3f
 #endif
-2:	fmovemx	%fp0-%fp7,%a0@(LTSS_FPCTXT)
-	fmoveml	%fpcr/%fpsr/%fpiar,%a0@(LTSS_FPCTXT+24*4)
+2:	fmovemx	%fp0-%fp7,%a0@(TASK_TSS+TSS_FPREG)
+	fmoveml	%fpcr/%fpsr/%fpiar,%a0@(TASK_TSS+TSS_FPCNTL)
 3:
+#endif
 
-	/* get pointer to tss struct (a1 contains new task) */
+	/* switch to new task (a1 contains new task) */
 	movel	%a1,%curptr
-	addl	%d1,%a1
 
 	/* Skip address space switching if they are the same. */
-	tstb	%d2
-	jne	4f
+	movel	%a0@(TASK_MM),%d0
+	cmpl	%a1@(TASK_MM),%d0
+	jeq	4f
 
 #if defined(CPU_M68020_OR_M68030) && defined(CPU_M68040_OR_M68060)
 	/* 68040 or 68060 ? */
@@ -316,7 +446,7 @@
 	movec	%d0,%cacr
 
 	/* switch the root pointer */
-	pmove	%a1@(LTSS_CRP),%crp
+	pmove	%a1@(TASK_TSS+TSS_CRP),%crp
 #endif
 
 #if defined(CPU_M68020_OR_M68030) && defined(CPU_M68040_OR_M68060)
@@ -333,7 +463,7 @@
 	pflushan
 
 	/* switch the root pointer */
-	movel	%a1@(LTSS_CRP+4),%d0
+	movel	%a1@(TASK_TSS+TSS_CRP+4),%d0
 	movec	%d0,%urp
 
 #if defined (CONFIG_M68060)
@@ -353,43 +483,50 @@
 4:
 	/* restore floating point context */
 
+#ifndef CONFIG_MATH_EMU_ONLY
+#ifdef CONFIG_MATH_EMU
+	tstl	SYMBOL_NAME(m68k_fputype)
+	jeq	4f
+#endif
 #if defined(CONFIG_M68060)
 #if !defined(CPU_M68060_ONLY)
 	btst	#3,SYMBOL_NAME(m68k_cputype)+3
 	beqs	1f
 #endif
 	/* The 060 FPU keeps status in bits 15-8 of the first longword */
-	tstb	%a1@(LTSS_FPCTXT+27*4+2)
+	tstb	%a1@(TASK_TSS+TSS_FPSTATE+2)
 	jeq	3f
 #if !defined(CPU_M68060_ONLY)
 	jra	2f
 #endif
 #endif /* CONFIG_M68060 */
 #if !defined(CPU_M68060_ONLY)
-1:	tstb	%a1@(LTSS_FPCTXT+27*4)
+1:	tstb	%a1@(TASK_TSS+TSS_FPSTATE)
 	jeq	3f
 #endif	
-2:	fmovemx	%a1@(LTSS_FPCTXT),%fp0-%fp7
-	fmoveml	%a1@(LTSS_FPCTXT+24*4),%fpcr/%fpsr/%fpiar
-3:	frestore %a1@(LTSS_FPCTXT+27*4)
+2:	fmovemx	%a1@(TASK_TSS+TSS_FPREG),%fp0-%fp7
+	fmoveml	%a1@(TASK_TSS+TSS_FPCNTL),%fpcr/%fpsr/%fpiar
+3:	frestore %a1@(TASK_TSS+TSS_FPSTATE)
+4:
+#endif
 
 	/* restore the kernel stack pointer */
-	movel	%a1@(LTSS_KSP),%sp
+	movel	%a1@(TASK_TSS+TSS_KSP),%sp
 
 	/* restore non-scratch registers */
 	RESTORE_SWITCH_STACK
 
 	/* restore user stack pointer */
-	movel	%a1@(LTSS_USP),%a0
+	movel	%a1@(TASK_TSS+TSS_USP),%a0
 	movel	%a0,%usp
 
 	/* restore fs (sfc,%dfc) */
-	movew	%a1@(LTSS_FS),%a0
+	movew	%a1@(TASK_TSS+TSS_FS),%a0
 	movec	%a0,%sfc
 	movec	%a0,%dfc
 
 	/* restore status register */
-	movew	%a1@(LTSS_SR),%sr
+	movew	%a1@(TASK_TSS+TSS_SR),%sr
 
 	rts
 
Index: linux-2.1/arch/m68k/kernel/head.S
diff -u linux-2.1/arch/m68k/kernel/head.S:1.1.1.1.6.2 linux-2.1/arch/m68k/kernel/head.S:1.1.1.1.6.2.2.3
--- linux-2.1/arch/m68k/kernel/head.S:1.1.1.1.6.2	Sat Dec 19 18:51:21 1998
+++ linux-2.1/arch/m68k/kernel/head.S	Sun Dec 20 01:54:00 1998
@@ -7,9 +7,12 @@
 **
 ** 68040 fixes by Michael Rausch
 ** 68060 fixes by Roman Hodek
+** MMU cleanup by Randy Thelen
+** Final MMU cleanup by Roman Zippel
 **
 ** Atari support by Andreas Schwab, using ideas of Robert de Vries
 ** and Bjoern Brauel
+** VME Support by Richard Hirst
 **
 ** 94/11/14 Andreas Schwab: put kernel at PAGESIZE
 ** 94/11/18 Andreas Schwab: remove identity mapping of STRAM for Atari
@@ -18,6 +21,8 @@
 ** 96/04/26 Guenther Kelleter: fixed identity mapping for Falcon with
 ** 			      Magnum- and FX-alternate ram
 ** 98/04/25 Phil Blundell: added HP300 support
+** 1998/08/30 David Kilzer: Added support for fbcon_font_desc structures
+**            for linux-2.1.115
 **
 ** This file is subject to the terms and conditions of the GNU General Public
 ** License. See the file README.legal in the main directory of this archive
@@ -34,63 +39,281 @@
  * Put us in supervisor state.
  *
  * The kernel setup code takes the following steps:
- *   Raise interrupt level
- *   Set up initial kernel memory mapping.
- *	This sets up a mapping of the 4M of memory the kernel
- *	is located in.	It also does a mapping of any initial
- *	machine specific areas.
- * Note that the kernel is located at virtual address 0x1000 == _start
- *   Enable cache memories
- *   Jump to kernel startup
- *
- * Register d6 contains the CPU flags and d4 the machine type
- * from the boot_info information for most of this file.
- * The upper word of d6 contains a bit for '040 or '060, since these two
- * are quite similar for initial mm setup. Another bit in d6 allows
- * distinction of the '060. The lower word of d6 contains the cache mode
- * that should be applied to pages containing descriptors. This mode is
- * non-cached/non-serialized for the '040 and cacheable/write-through for
- * the '060.
- *
- * General register usage:
- *   a6 - start of unused memory
- *	  new pages can be allocated from here
- *   a5 - mmu root table
- *   a4 - mmu pointer table
- *   a3 - mmu page tables
- *   a2 - points to the page table entry for a6
- *	  cache status can be changed (used for '0[46]0)
- *	  you must increase a2 if alloc a new page
- *   d7 - used for debug output and some macros
- *   d6 - cpu type and cache mode
- *   d5 - physical start address of kernel
- *   d4 - machine type
+ * .  Raise interrupt level
+ * .  Set up initial kernel memory mapping.
+ *    .  This sets up a mapping of the 4M of memory the kernel is located in.
+ *    .  It also does a mapping of any initial machine specific areas.
+ * .  Enable the MMU
+ * .  Enable cache memories
+ * .  Jump to kernel startup
+ *
+ * Much of the file restructuring was to accomplish:
+ * 1) Remove register dependency through-out the file.
+ * 2) Increase use of subroutines to perform functions
+ * 3) Increase readability of the code
+ *
+ * Of course, readability is a subjective issue, so it will never be
+ * argued that that goal was accomplished.  It was merely a goal.
+ * A key way to help make code more readable is to give good
+ * documentation.  So, the first thing you will find is exaustive
+ * write-ups on the structure of the file, and the features of the
+ * functional subroutines.
+ *
+ * General Structure:
+ * ------------------
+ *	Without a doubt the single largest chunk of head.S is spent
+ * mapping the kernel and I/O physical space into the logical range
+ * for the kernel.
+ *	There are new subroutines and data structures to make MMU
+ * support cleaner and easier to understand.
+ * 	First, you will find a routine call "mmu_map" which maps
+ * a logical to a physical region for some length given a cache
+ * type on behalf of the caller.  This routine makes writing the
+ * actual per-machine specific code very simple.
+ *	A central part of the code, but not a subroutine in itself,
+ * is the mmu_init code which is broken down into mapping the kernel
+ * (the same for all machines) and mapping machine-specific I/O
+ * regions.
+ *	Also, there will be a description of engaging the MMU and
+ * caches.
+ *	You will notice that there is a chunk of code which
+ * can emit the entire MMU mapping of the machine.  This is present
+ * only in debug modes and can be very helpful.
+ *	Further, there is a new console driver in head.S that is
+ * also only engaged in debug mode.  Currently, it's only supported
+ * on the Macintosh class of machines.  However, it is hoped that
+ * others will plug-in support for specific machines.
+ *
+ * ######################################################################
+ *
+ * mmu_map
+ * -------
+ *	mmu_map was written for two key reasons.  First, it was clear
+ * that it was very difficult to read the previous code for mapping
+ * regions of memory.  Second, the Macintosh required such extensive
+ * memory allocations that it didn't make sense to propogate the
+ * existing code any further.
+ *	mmu_map requires some parameters:
+ *
+ *	mmu_map (logical, physical, length, cache_type)
+ *
+ *	While this essentially describes the function in the abstract, you'll
+ * find more indepth description of other parameters at the implementation site.
+ * 
+ * mmu_get_root_table_entry
+ * ------------------------
+ * mmu_get_ptr_table_entry
+ * -----------------------
+ * mmu_get_page_table_entry
+ * ------------------------
+ * 
+ *	These routines are used by other mmu routines to get a pointer into
+ * a table, if necessary a new table is allocated. These routines are working
+ * basically like pmd_alloc() and pte_alloc() in <asm/pgtable.h>. The root
+ * table needs of course only to be allocated once in mmu_get_root_table_entry,
+ * so that here also some mmu specific initialization is done. The second page
+ * at the start of the kernel (the first page is unmapped later) is used for
+ * the kernel_pg_dir. It must be at a position known at link time (as it's used
+ * to initialize the init task struct) and since it's needs special cache
+ * settings, it's the easiest to use this page, the rest of the page is used
+ * for further pointer tables.
+ * mmu_get_page_table_entry allocates always a whole page for page tables, this
+ * means 1024 pages and so 4MB of memory can be mapped. It doesn't make sense
+ * to manage page tables in smaller pieces as nearly all mappings have that
+ * size.
+ *
+ * ######################################################################
+ *
+ *
+ * ######################################################################
+ *
+ * mmu_engage
+ * ----------
+ *	Thanks to a small helping routine enabling the mmu got quiet simple
+ * and there is only one way left. mmu_engage makes a complete a new mapping
+ * that only includes the absolute necessary to be able to jump to the final
+ * postion and to restore the original mapping.
+ * As this code doesn't need a transparent translation register anymore this
+ * means all registers are free to be used by machines that needs them for
+ * other purposes.
+ *
+ * ######################################################################
+ *
+ * mmu_print
+ * ---------
+ *	This algorithm will print out the page tables of the system as
+ * appropriate for an 030 or an 040.  This is useful for debugging purposes
+ * and as such is enclosed in #ifdef MMU_PRINT/#endif clauses.
+ * !!! BROKEN !!! STILL NEEDED ???
+ *
+ * ######################################################################
+ *
+ * console_init
+ * ------------
+ *	The console is also able to be turned off.  The console in head.S
+ * is specifically for debugging and can be very useful.  It is surrounded by
+ * #ifdef CONSOLE/#endif clauses so it doesn't have to ship in known-good
+ * kernels.  It's basic algorithm is to determine the size of the screen
+ * (in height/width and bit depth) and then use that information for
+ * displaying an 8x8 font or an 8x16 (widthxheight).  I prefer the 8x8 for
+ * debugging so I can see more good data.  But it was trivial to add support
+ * for both fonts, so I included it.
+ *	Also, the algorithm for plotting pixels is abstracted so that in
+ * theory other platforms could add support for different kinds of frame
+ * buffers.  This could be very useful.
+ *
+ * console_put_penguin
+ * -------------------
+ *	An important part of any Linux bring up is the penguin and there's
+ * nothing like getting the Penguin on the screen!  This algorithm will work
+ * on any machine for which there is a console_plot_pixel.
+ *
+ * console_scroll
+ * --------------
+ *	My hope is that the scroll algorithm does the right thing on the
+ * various platforms, but it wouldn't be hard to add the test conditions
+ * and new code if it doesn't.
+ *
+ * console_putc
+ * -------------
+ *
+ * ######################################################################
+ *
+ *	Register usage has greatly simplified within head.S. Every subroutine
+ * saves and restores all registers that it modifies (except it returns a
+ * value in there of course). So the only register that needs to be initialized
+ * is the stack pointer.
+ * All other init code and data is now placed in the init section, so it will
+ * be automatically freed at the end of the kernel initialization.
+ *
+ * ######################################################################
+ *
+ * options
+ * -------
+ *	There are many options availble in a build of this file.  I've
+ * taken the time to describe them here to save you the time of searching
+ * for them and trying to understand what they mean.
+ *
+ * CONFIG_xxx:	These are the obvious machine configuration defines created
+ * during configuration.  These are defined in include/linux/autoconf.h.
+ *
+ * CONSOLE:	There is support for head.S console in this file.  This
+ * console can talk to a Mac frame buffer, but could easily be extrapolated
+ * to extend it to support other platforms.
+ *
+ * TEST_MMU:	This is a test harness for running on any given machine but
+ * getting an MMU dump for another class of machine.  The classes of machines
+ * that can be tested are any of the makes (Atari, Amiga, Mac, VME, etc.)
+ * and any of the models (030, 040, 060, etc.).
+ *
+ *	NOTE:	TEST_MMU is NOT permanent!  It is scheduled to be removed
+ *		When head.S boots on Atari, Amiga, Macintosh, and VME
+ *		machines.  At that point the underlying logic will be
+ *		believed to be solid enough to be trusted, and TEST_MMU
+ *		can be dropped.  Do note that that will clean up the
+ *		head.S code significantly as large blocks of #if/#else
+ *		clauses can be removed.
+ *
+ * MMU_NOCACHE_KERNEL:	On the Macintosh platform there was an inquiry into
+ * determing why devices don't appear to work.  A test case was to remove
+ * the cacheability of the kernel bits.
+ *
+ * MMU_PRINT:	There is a routine built into head.S that can display the
+ * MMU data structures.  It outputs its result through the serial_putc
+ * interface.  So where ever that winds up driving data, that's where the
+ * mmu struct will appear.  On the Macintosh that's typically the console.
+ *
+ * SERIAL_DEBUG:	There are a series of putc() macro statements
+ * scattered through out the code to give progress of status to the
+ * person sitting at the console.  This constant determines whether those
+ * are used.
+ *
+ * DEBUG:	This is the standard DEBUG flag that can be set for building
+ *		the kernel.  It has the effect adding additional tests into
+ *		the code.
+ *
+ * MMU_PRINT_PAGE_USAGE:
+ *		Print the number of pages used by the MMU tables.
+ *
+ * FONT_6x11:
+ * FONT_8x8:
+ * FONT_8x16:
+ *		In theory these could be determined at run time or handed
+ *		over by the booter.  But, let's be real, it's a fine hard
+ *		coded value.  (But, you will notice the code is run-time
+ *		flexible!)  A pointer to the font's struct fbcon_font_desc
+ *		is kept locally in Lconsole_font.  It is used to determine
+ *		font size information dynamically.
+ *
+ * Atari constants:
+ * USE_PRINTER:	Use the printer port for serial debug.
+ * USE_SCC_B:	Use the SCC port A (Serial2) for serial debug.
+ * USE_SCC_A:	Use the SCC port B (Modem2) for serial debug.
+ * USE_MFP:	Use the ST-MFP port (Modem1) for serial debug.
+ *
+ * Macintosh constants:
+ * MAC_SERIAL_DEBUG:	Turns on serial debug output for the Macintosh.
+ * MAC_USE_SCC_A:	Use the SCC port A (modem) for serial debug.
+ * MAC_USE_SCC_B:	Use the SCC port B (printer) for serial debug (default).
  */
 
 #include <linux/config.h>
 #include <linux/linkage.h>
+#include <linux/init.h>
 #include <asm/bootinfo.h>
 #include <asm/setup.h>
 #include <asm/pgtable.h>
+#if defined(CONFIG_MAC)
+#include <video/font.h>		/* offsets for struct fbcon_font_desc */
+#endif
+#include "m68k_defs.h"
 
-.globl SYMBOL_NAME(kernel_pg_dir), SYMBOL_NAME(kpt)
-.globl SYMBOL_NAME(availmem)
-.globl SYMBOL_NAME(m68k_pgtable_cachemode)
-.globl SYMBOL_NAME(kernel_pmd_table), SYMBOL_NAME(swapper_pg_dir)
+#if defined(CONFIG_MAC)
 
-#if defined(CONFIG_MVME16x)
-.globl SYMBOL_NAME(mvme_bdid_ptr)
-#endif
+/*
+ * Macintosh console support
+ */
+#define CONSOLE
+
+/*
+ * Macintosh serial debug support; outputs boot info to the printer
+ *   and/or modem serial ports
+ */
+#undef MAC_SERIAL_DEBUG
+
+/*
+ * Macintosh serial debug port selection; define one or both;
+ *   requires MAC_SERIAL_DEBUG to be defined
+ */
+#undef  MAC_USE_SCC_A		/* Macintosh modem serial port */
+#define MAC_USE_SCC_B		/* Macintosh printer serial port */
+
+#endif	/* CONFIG_MAC */
 
+#undef MMU_PRINT
+#undef MMU_NOCACHE_KERNEL
+#define SERIAL_DEBUG
+#define DEBUG
+#undef MMU_PRINT_PAGE_USAGE
+
 /*
- * Added m68k_supervisor_cachemode for 68060 boards where some drivers
- * need writethrough caching for supervisor accesses.  Drivers known to
- * be effected are 53c7xx.c and apricot.c (when used on VME boards).
- * Richard Hirst.
+ * For the head.S console, there are three supported fonts, 6x11, 8x16 and 8x8.
+ * The 8x8 font is harder to read but fits more on the screen.
  */
+#define FONT_8x8 	/* default */
+/* #define FONT_8x16	/* 2nd choice */
+/* #define FONT_6x11	/* 3rd choice */
 
-#ifdef CONFIG_060_WRITETHROUGH
+.globl SYMBOL_NAME(kernel_pg_dir)
+.globl SYMBOL_NAME(kpt)
+.globl SYMBOL_NAME(availmem)
+.globl SYMBOL_NAME(m68k_pgtable_cachemode)
 .globl SYMBOL_NAME(m68k_supervisor_cachemode)
+.globl SYMBOL_NAME(kernel_pmd_table)
+.globl SYMBOL_NAME(swapper_pg_dir)
+
+#if defined(CONFIG_ATARI)
+.globl SYMBOL_NAME(atari_mch_type)
 #endif
 
 D6B_0460 = 16		/* indicates 680[46]0 in d6 */
@@ -98,6 +321,11 @@
 D6F_040  = 1<<D6B_0460
 D6F_060  = (1<<D6B_0460)+(1<<D6B_060)
 
+CPUTYPE_040	= 1	/* indicates an 040 */
+CPUTYPE_060	= 2	/* indicates an 060 */
+CPUTYPE_0460	= 3	/* if either above are set, this is set */
+CPUTYPE_020	= 4	/* indicates an 020 */
+
 /* Translation control register */
 TC_ENABLE = 0x8000
 TC_PAGE8K = 0x4000
@@ -144,6 +372,7 @@
 
 /* Miscellaneous definitions */
 PAGESIZE	= 4096
+PAGESHIFT	= 12
 
 ROOT_TABLE_SIZE	= 128
 PTR_TABLE_SIZE	= 128
@@ -152,32 +381,178 @@
 PTR_INDEX_SHIFT  = 18
 PAGE_INDEX_SHIFT = 12
 
-TABLENR_4MB	= 16	/* # of page tables needed to page 4 MB */
-TABLENR_16MB	= 64	/* same for 16 MB */
+/* Several macros to make the writing of subroutines easier:
+ * - func_start marks the beginning of the routine which setups the frame
+ *   register and saves the registers, it also defines another macro
+ *   to automatically restore the registers again.
+ * - func_return marks the end of the routine and simply calls the prepared
+ *   macro to restore registers and jump back to the caller.
+ * - func_define generates another macro to automatically put arguments
+ *   onto the stack call the subroutine and cleanup the stack again.
+ */
+
+/* Within subroutines these macros can be used to access the arguments
+ * on the stack. With STACK some allocated memory on the stack can be
+ * accessed and ARG0 points to the return address (used by mmu_engage).
+ */
+#define	STACK	%a6@(stackstart)
+#define ARG0	%a6@(4)
+#define ARG1	%a6@(8)
+#define ARG2	%a6@(12)
+#define ARG3	%a6@(16)
+#define ARG4	%a6@(20)
+
+.macro	func_start	name,saveregs,stack=0
+.L\name:
+	linkw	%a6,#-\stack
+	moveml	\saveregs,%sp@-
+.set	stackstart,-\stack	
+
+.macro	func_return_\name
+	moveml	%sp@+,\saveregs
+	unlk	%a6
+	rts
+.endm
+.endm
 
-#define putc(ch) moveq &ch,%d7; jbsr Lserial_putc
-#define putr() putc(13); putc(10)
-#define putn(nr) movel nr,%d7; jbsr Lserial_putnum
-
-#define is_not_amiga(lab) moveq &MACH_AMIGA,%d7; cmpl %d4,%d7; jne lab
-#define is_not_atari(lab) moveq &MACH_ATARI,%d7; cmpl %d4,%d7; jne lab
-#define is_not_mvme16x(lab) moveq &MACH_MVME16x,%d7; cmpl %d4,%d7; jne lab
-#define is_not_bvme6000(lab) moveq &MACH_BVME6000,%d7; cmpl %d4,%d7; jne lab
-#define is_not_hp300(lab) moveq &MACH_HP300,%d7	;  cmpl %d4,%d7; jne lab
-
-#define is_040_or_060(lab) btst &D6B_0460,%d6; jne lab
-#define is_not_040_or_060(lab) btst &D6B_0460,%d6; jeq lab
-#define is_060(lab) btst &D6B_060,%d6; jne lab
-#define is_not_060(lab) btst &D6B_060,%d6; jeq lab
+.macro	func_return	name
+	func_return_\name
+.endm
+
+.macro	func_call	name
+	jbsr	.L\name
+.endm
+
+.macro	move_stack	nr,arg1,arg2,arg3,arg4
+.if	\nr
+	move_stack	"(\nr-1)",\arg2,\arg3,\arg4
+	movel	\arg1,%sp@-
+.endif
+.endm
+
+.macro	func_define	name,nr
+.macro	\name	arg1,arg2,arg3,arg4
+	move_stack	\nr,\arg1,\arg2,\arg3,\arg4
+	func_call	\name
+.if	\nr
+	lea	%sp@(\nr*4),%sp
+.endif
+.endm
+.endm
+
+func_define	mmu_map,4
+func_define	mmu_fixup_page_mmu_cache,1
+func_define	mmu_temp_map,2
+func_define	mmu_engage,0
+func_define	mmu_get_root_table_entry,1
+func_define	mmu_get_ptr_table_entry,2
+func_define	mmu_get_page_table_entry,2
+func_define	get_new_page,0
+
+.macro	mmu_map_eq	arg1,arg2,arg3
+	mmu_map	\arg1,\arg1,\arg2,\arg3
+.endm
+
+.macro	get_bi_record	record
+	pea	\record
+	func_call	get_bi_record
+	addql	#4,%sp
+.endm
+
+func_define	serial_putc,1
+func_define	serial_putnum,1
+func_define	serial_puts,1
+func_define	console_putnum,1
+
+.macro	putc	ch
+#if defined(CONSOLE) || defined(SERIAL_DEBUG)
+	pea	\ch
+#endif
+#ifdef CONSOLE
+	func_call	console_putc
+#endif
+#ifdef SERIAL_DEBUG
+	func_call	serial_putc
+#endif
+#if defined(CONSOLE) || defined(SERIAL_DEBUG)
+	addql	#4,%sp
+#endif
+.endm
+
+.macro	dputc	ch
+#ifdef DEBUG
+	putc	\ch
+#endif
+.endm
+
+.macro	putn	nr
+#ifdef CONSOLE
+	console_putnum	\nr
+#endif
+#ifdef SERIAL_DEBUG
+	serial_putnum	\nr
+#endif
+.endm
+
+.macro	dputn	nr
+#ifdef DEBUG
+	putn	\nr
+#endif
+.endm
+
+.macro	puts		string
+#if defined(CONSOLE) || defined(SERIAL_DEBUG)
+	__INITDATA
+.Lstr\@:
+	.string	"\string"
+	__FINIT
+	pea	%pc@(.Lstr\@)
+#endif
+#ifdef CONSOLE
+	func_call	console_puts
+#endif
+#ifdef SERIAL_DEBUG
+	func_call	serial_puts
+#endif
+#if defined(CONSOLE) || defined(SERIAL_DEBUG)
+	addql	#4,%sp
+#endif
+.endm
+
+.macro	dputs	string
+#ifdef DEBUG
+	puts	"\string"
+#endif
+.endm
+
+
+#define is_not_amiga(lab) cmpl &MACH_AMIGA,%pc@(m68k_machtype); jne lab
+#define is_not_atari(lab) cmpl &MACH_ATARI,%pc@(m68k_machtype); jne lab
+#define is_not_mac(lab) cmpl &MACH_MAC,%pc@(m68k_machtype); jne lab
+#define is_not_mvme16x(lab) cmpl &MACH_MVME16x,%pc@(m68k_machtype); jne lab
+#define is_not_bvme6000(lab) cmpl &MACH_BVME6000,%pc@(m68k_machtype); jne lab
+#define is_not_hp300(lab) cmpl &MACH_HP300,%pc@(m68k_machtype); jne lab
+
+#define is_040_or_060(lab)	btst &CPUTYPE_0460,%pc@(.Lcputype+3); jne lab
+#define is_not_040_or_060(lab)	btst &CPUTYPE_0460,%pc@(.Lcputype+3); jeq lab
+#define is_040(lab)		btst &CPUTYPE_040,%pc@(.Lcputype+3); jne lab
+#define is_060(lab)		btst &CPUTYPE_060,%pc@(.Lcputype+3); jne lab
+#define is_not_060(lab)		btst &CPUTYPE_060,%pc@(.Lcputype+3); jeq lab
+#define is_020(lab)		btst &CPUTYPE_020,%pc@(.Lcputype+3); jne lab
+#define is_not_020(lab)		btst &CPUTYPE_020,%pc@(.Lcputype+3); jeq lab
 
 /* On the HP300 we use the on-board LEDs for debug output before
    the console is running.  Writing a 1 bit turns the corresponding LED
    _off_ - on the 340 bit 7 is towards the back panel of the machine.  */
+.macro	leds	mask
 #ifdef CONFIG_HP300
-#define leds(x) is_not_hp300(42f) ; moveb #(x),%d7 ; jbsr Lset_leds; 42:
-#else
-#define leds(x)
+	is_not_hp300(.Lled\@)
+	pea	\mask
+	func_call	leds
+	addql	#4,%sp
+.Lled\@:
 #endif
+.endm
 
 .text
 ENTRY(_stext)
@@ -192,81 +567,192 @@
 	.long	MACH_ATARI, ATARI_BOOTI_VERSION
 	.long	MACH_MVME16x, MVME16x_BOOTI_VERSION
 	.long	MACH_BVME6000, BVME6000_BOOTI_VERSION
+	.long	MACH_MAC, MAC_BOOTI_VERSION
 	.long	0
-1:	jra	SYMBOL_NAME(_start)
+1:	jra	SYMBOL_NAME(__start)
 
-.equ	SYMBOL_NAME(kernel_pmd_table),SYMBOL_NAME(_stext)
-.equ	SYMBOL_NAME(kernel_pg_dir),SYMBOL_NAME(kernel_pmd_table)
-.equ	SYMBOL_NAME(swapper_pg_dir),SYMBOL_NAME(kernel_pg_dir)+(ROOT_TABLE_SIZE<<2)
-.equ	Lavail_pmd_table,SYMBOL_NAME(swapper_pg_dir)+(ROOT_TABLE_SIZE<<2)
+.equ	SYMBOL_NAME(kernel_pg_dir),SYMBOL_NAME(_stext)
 
 .equ	.,SYMBOL_NAME(_stext)+PAGESIZE
 
 ENTRY(_start)
+	jra	SYMBOL_NAME(__start)
+__INIT
+ENTRY(__start)
 
 /*
  * Setup initial stack pointer
  */
-	lea	%pc@(SYMBOL_NAME(_stext):w),%sp
+	lea	%pc@(SYMBOL_NAME(_stext)),%sp
 
 /*
  * Record the CPU and machine type.
  */
 
-	movew	#BI_MACHTYPE,%d0
-	jbsr	Lget_bi_record
-	movel	%a0@,%d4
-	lea	%pc@(SYMBOL_NAME(m68k_machtype)),%a0
-	movel	%d4,%a0@
-	movew	#BI_FPUTYPE,%d0
-	jbsr	Lget_bi_record
-	movel	%a0@,%d0
-	lea	%pc@(SYMBOL_NAME(m68k_fputype)),%a0
-	movel	%d0,%a0@
-	movew	#BI_MMUTYPE,%d0
-	jbsr	Lget_bi_record
-	movel	%a0@,%d0
-	lea	%pc@(SYMBOL_NAME(m68k_mmutype)),%a0
-	movel	%d0,%a0@
-	movew	#BI_CPUTYPE,%d0
-	jbsr	Lget_bi_record
+	get_bi_record	BI_MACHTYPE
+	lea	%pc@(SYMBOL_NAME(m68k_machtype)),%a1
+	movel	%a0@,%a1@
+
+	get_bi_record	BI_FPUTYPE
+	lea	%pc@(SYMBOL_NAME(m68k_fputype)),%a1
+	movel	%a0@,%a1@
+
+	get_bi_record	BI_MMUTYPE
+	lea	%pc@(SYMBOL_NAME(m68k_mmutype)),%a1
+	movel	%a0@,%a1@
+
+	get_bi_record	BI_CPUTYPE
+	lea	%pc@(SYMBOL_NAME(m68k_cputype)),%a1
+	movel	%a0@,%a1@
+
+#if defined(CONFIG_MAC)
+/*
+ * For Macintosh, we need to determine the display parameters early (at least
+ * while debugging it).
+ */
+
+	is_not_mac(.Ltest_notmac)
+
+	get_bi_record	BI_MAC_VADDR
+	lea	%pc@(.Lmac_videobase),%a1
+	movel	%a0@,%a1@
+
+	get_bi_record	BI_MAC_VDEPTH
+	lea	%pc@(.Lmac_videodepth),%a1
+	movel	%a0@,%a1@
+
+	get_bi_record	BI_MAC_VDIM
+	lea	%pc@(.Lmac_dimensions),%a1
+	movel	%a0@,%a1@
+
+	get_bi_record	BI_MAC_VROW
+	lea	%pc@(.Lmac_rowbytes),%a1
+	movel	%a0@,%a1@
+
+#ifdef MAC_SERIAL_DEBUG
+	get_bi_record	BI_MAC_SCCBASE
+	lea	%pc@(.Lmac_sccbase),%a1
+	movel	%a0@,%a1@
+#endif /* MAC_SERIAL_DEBUG */
+
+#if 0
+	/*
+	 * Clear the screen
+	 */
+	lea	%pc@(.Lmac_videobase),%a0
+	movel	%a0@,%a1
+	lea	%pc@(.Lmac_dimensions),%a0
+	movel	%a0@,%d1
+	swap	%d1		/* #rows is high bytes */
+	andl	#0xFFFF,%d1	/* rows */
+	subl	#10,%d1
+	lea	%pc@(.Lmac_rowbytes),%a0
+loopy2:
 	movel	%a0@,%d0
-	lea	%pc@(SYMBOL_NAME(m68k_cputype)),%a0
-	movel	%d0,%a0@
+	subql	#1,%d0
+loopx2:
+	moveb	#0x55, %a1@+
+	dbra	%d0,loopx2
+	dbra	%d1,loopy2
+#endif
+
+.Ltest_notmac:
+#endif /* CONFIG_MAC */
+
+
+/*
+ * There are ultimately two pieces of information we want for all kinds of
+ * processors CpuType and CacheBits.  The CPUTYPE was passed in from booter
+ * and is converted here from a booter type definition to a separate bit
+ * number which allows for the standard is_0x0 macro tests.
+ */
+	movel	%pc@(SYMBOL_NAME(m68k_cputype)),%d0
+	/*
+	 * Assume it's an 020/030
+	 */
+	clrl	%d1
 
+	/*
+	 * Test the BootInfo cputype for 060
+	 */
 	btst	#CPUB_68060,%d0
-	jeq	1f
-	/* '060: d6 := BIT0460|BIT060, cache mode 0x60 (no-cache/non-ser) */
-	movel	#D6F_060+_PAGE_CACHE040W,%d6
-	jra	2f
-1:	btst	#CPUB_68040,%d0
 	jeq	1f
-	/* '040: d6 := BIT0460, cache mode 0x00 (write-through) */
-	movel	#D6F_040+_PAGE_CACHE040W,%d6
-	jra	2f
-1:	/* '020 or '030: d6 := no CPU bit, cache mode unused */
-	moveq	#0,%d6
+	bset	#CPUTYPE_060,%d1
+	bset	#CPUTYPE_0460,%d1
+	jra	3f
+1:
+	/*
+	 * Test the BootInfo cputype for 040
+	 */
+	btst	#CPUB_68040,%d0
+	jeq	2f
+	bset	#CPUTYPE_040,%d1
+	bset	#CPUTYPE_0460,%d1
+	jra	3f
+2:
+	/*
+	 * Test the BootInfo cputype for 020
+	 */
+	btst	#CPUB_68020,%d0
+	jeq	2f
+	bset	#CPUTYPE_020,%d1
+	jra	3f
+3:
+	/*
+	 * Record the cpu type
+	 */
+	lea	%pc@(.Lcputype),%a0
+	movel	%d1,%a0@
 
-2:	lea	%pc@(SYMBOL_NAME(m68k_pgtable_cachemode)),%a0
-	moveq	#0,%d0
-	movew	%d6,%d0
-	movel	%d0,%a0@		/* save cache mode for page tables */
+	/*
+	 * NOTE:
+	 *
+	 * Now the macros are valid:
+	 *	is_040_or_060
+	 *	is_not_040_or_060
+	 *	is_040
+	 *	is_060
+	 *	is_not_060
+	 */
 
 	/*
+	 * Determine the cache mode for pages holding MMU tables
+	 * and for supervisor mode, unused for '020 and '030
+	 */
+	clrl	%d0
+	clrl	%d1
+
+	is_not_040_or_060(.Lsave_cachetype)
+
+	/*
+	 * '040 or '060
+	 * d1 := cacheable write-through
+	 * NOTE: The 68040 manual strongly recommends non-cached for MMU tables,
+	 * but we have been using write-through since at least 2.0.29 so I
+	 * guess it is OK.
+	 */
+#if defined(CONFIG_060_WRITETHROUGH)
+	/*
 	 * If this is a 68060 board using drivers with cache coherency
 	 * problems, then supervisor memory accesses need to be write-through
-         * also; otherwise, we want copyback.
+	 * also; otherwise, we want copyback.
 	 */
 
-#if defined(CONFIG_060_WRITETHROUGH)
-	is_not_060(Lset_norm)
-	jra	1f
-Lset_norm:
-	move.w	#_PAGE_CACHE040,%d0
+	is_not_060(1f)
+	movel	#_PAGE_CACHE040W,%d0
+#endif /* CONFIG_060_WRITETHROUGH */
 1:
-  	lea	%pc@(SYMBOL_NAME(m68k_supervisor_cachemode)),%a0
+	movew	#_PAGE_CACHE040,%d0
+
+	movel	#_PAGE_CACHE040W,%d1
+
+.Lsave_cachetype:
+	/* Save cache mode for supervisor mode and page tables
+	 */
+	lea	%pc@(SYMBOL_NAME(m68k_supervisor_cachemode)),%a0
 	movel	%d0,%a0@
-#endif
+	lea	%pc@(SYMBOL_NAME(m68k_pgtable_cachemode)),%a0
+	movel	%d1,%a0@
 
 /*
  * raise interrupt level
@@ -293,288 +779,116 @@
  */
 
 #ifdef CONFIG_ATARI
-	is_not_atari(Lnotypetest)
+	is_not_atari(.Lnotypetest)
 
 	/* get special machine type (Medusa/Hades/AB40) */
 	moveq	#0,%d3 /* default if tag doesn't exist */
-	movew	#BI_ATARI_MCH_TYPE,%d0
-	jbsr	Lget_bi_record
+	get_bi_record	BI_ATARI_MCH_TYPE
 	tstl	%d0
 	jbmi	1f
 	movel	%a0@,%d3
-1:	
-	/* %d3 is not clobbered until Atari page tables are set up,
-	 * where it is used again. */
-
+	lea	%pc@(SYMBOL_NAME(atari_mch_type)),%a0
+	movel	%d3,%a0@
+1:
 	/* On the Hades, the iobase must be set up before opening the
 	 * serial port. There are no I/O regs at 0x00ffxxxx at all. */
 	moveq	#0,%d0
 	cmpl	#ATARI_MACH_HADES,%d3
 	jbne	1f
 	movel	#0xff000000,%d0		/* Hades I/O base addr: 0xff000000 */
-1:	lea     %pc@(Liobase),%a0
+1:	lea     %pc@(.Liobase),%a0
 	movel   %d0,%a0@
-Lnotypetest:
+
+.Lnotypetest:
 #endif
 
 /*
  * Initialize serial port
  */
+	jbsr	.Lserial_init
 
-	jbsr Lserial_init
-
-	putr()
-	putc('A')
-
 /*
- * Get address at end of bootinfo and mask off at a page boundary.
+ * Initialize console
  */
-	moveq	#0,%d0
-	jbsr	Lget_bi_record
-	addw	#PAGESIZE-1,%a0
-	movel	%a0,%d0
-	andl	#-PAGESIZE,%d0
-	movel	%d0,%a6
+#ifdef CONFIG_MAC
+	is_not_mac(.Lnocon)
+#ifdef CONSOLE
+	jbsr	.Lconsole_init
+#ifdef CONSOLE_PENGUIN
+	jbsr	.Lconsole_put_penguin
+#endif	/* CONSOLE_PENGUIN */
+	jbsr	.Lconsole_put_stats
+#endif	/* CONSOLE */
+.Lnocon:
+#endif	/* CONFIG_MAC */
 
-	putc('B')
 
-/*
- * Save physical start address of kernel
- */
-	lea	%pc@(SYMBOL_NAME(_stext)-PAGESIZE:w),%a0
-	movel	%a0,%d5
+	putc	'\n'
+	putc	'A'
 
 /*
- * initialize the kernel root table.
+ * Save physical start address of kernel
  */
-	lea	%pc@(SYMBOL_NAME(kernel_pg_dir):w),%a5
-	movel	%a5,%a0
-	moveq	#ROOT_TABLE_SIZE-1,%d1
-1:	clrl	%a0@+
-	dbra	%d1,1b
+	lea	%pc@(.Lphys_kernel_start),%a0
+	lea	%pc@(SYMBOL_NAME(_stext)),%a1
+	subl	#SYMBOL_NAME(_stext),%a1
+	movel	%a1,%a0@
 
-	/*
-	 * Initialize root table descriptor pointing to the kernel pointer
-	 * table.
-	 */
-	lea	%pc@(Lavail_pmd_table:w),%a4
-	moveq	#_PAGE_TABLE,%d0
-	addl	%a4,%d0
-	movel	%d0,%a5@
+	putc	'B'
 
-	putc('C')
+	leds	0x4
 
 /*
- * Initialize the pointer tables referred to above.  They either point
- * to page tables in the case of the 680[46]0 or contain early
- * termination page descriptors in the case of the 68851 or 68030.
- *
- * Each pointer table entry points to a 64 entry page table.  16 of these
- * page tables are grouped to form a single 1024 entry page table which
- * fits in a single 4096 byte page.
- *
- * Some register usages:
- *    a0 -> pointer table descriptor address
- *    a1 -> pointer table descriptor
- *    d1 -> counter
- *    d2 -> pointer table descriptor increment (varies according to CPU)
- */
-
-	/* clear the kernel pointer table */
-	movel	%a4,%a0
-	moveq	#PTR_TABLE_SIZE-1,%d1
-1:	clrl	%a0@+
-	dbra	%d1,1b
-
-	movel	%a4,%a0
-	moveq	#15,%d1
-
-	/*
-	 * base value of pointer table descriptor is either
-	 * the address of the first page table (680[46]0)
-	 * or the base address of physical memory (68030).
-	 */
-	is_040_or_060(1f)
-
-	/* 680[23]0 */
-	movel	%d5,%a1				/* base address */
-	addql	#_PAGE_PRESENT,%a1		/* descriptor type */
-	movel	#PAGE_TABLE_SIZE*PAGESIZE,%d2	/* increment */
-	jra	2f
-
-1:	/* 680[46]0 */
-	movel	%a6,%a3			/* base address */
-	addw	#PAGESIZE,%a6		/* allocate page for 16 page tables */
-	lea	%pc@(SYMBOL_NAME(kpt)),%a1
-	movel	%a3,%a1@		/* save address of page table */
-	movel	%a3,%a1
-	addw	#_PAGE_TABLE+_PAGE_ACCESSED,%a1	/* descriptor type */
-	movel	#PAGE_TABLE_SIZE<<2,%d2 /* increment */
-
-2:	movel	%a1,%a0@+
-	addl	%d2,%a1
-	dbra	%d1,2b
-
-	putc('D')
-
-/*
- * If we are running on a 680[46]0, we have a kernel page table and
- * must initialize it.	Make the entries point to the first
- * 4M of physical memory (the memory we are residing in).
- * Set the cache mode bits to Cacheable, Copyback.  Set the Global bits
- * in the descriptors also.
+ *	mmu_init
+ *
+ *	This block of code does what's necessary to map in the various kinds
+ *	of machines for execution of Linux.
+ *	First map the first 4 MB of kernel code & data
  */
-	is_not_040_or_060(Lnot040)
-
-	putc('F')
 
-	movel	%a3,%a0
-	movel	%d5,%a1
-#if defined(CONFIG_060_WRITETHROUGH)
-	addw	#_PAGE_GLOBAL040+_PAGE_PRESENT+_PAGE_ACCESSED,%a1
-	addl	m68k_supervisor_cachemode,%a1
-#else
-	addw    #_PAGE_GLOBAL040+_PAGE_CACHE040+_PAGE_PRESENT+_PAGE_ACCESSED,%a1
-#endif
-	movew	#(PAGE_TABLE_SIZE*TABLENR_4MB)-1,%d1
-	movel	#PAGESIZE,%d2
-1:	movel	%a1,%a0@+
-	addl	%d2,%a1
-	dbra	%d1,1b
+	mmu_map	#0,%pc@(.Lphys_kernel_start),#4*1024*1024,\
+		%pc@(SYMBOL_NAME(m68k_supervisor_cachemode))
 
-	/*
-	 * on the 68040, pages used to hold mmu tables should
-	 * be initialized as noncachable; the '060 allows write-through.
-	 * Do this for the root table page (which also contains
-	 * all pointer tables utilized thus far) and the
-	 * kernel page table.
-	 */
-	movel	%a5,%d0
-	subl	%d5,%d0
-	moveq	#PAGE_INDEX_SHIFT,%d2
-	lsrl	%d2,%d0
-	lea	%a3@(%d0:l:4),%a2
-	movel	%a2@,%d1
-	andw	#_CACHEMASK040,%d1
-	orw	%d6,%d1
-	movel	%d1,%a2@
+	putc	'C'
 
-	movel	%a3,%d0
-	subl	%d5,%d0
-	lsrl	%d2,%d0
-	lea	%a3@(%d0:l:4),%a2
-	movel	%a2@,%d1
-	andw	#_CACHEMASK040,%d1
-	orw	%d6,%d1
-	movel	%d1,%a2@+
-	/*
-	 * %a2 points now to the page table entry for available pages at %a6,
-	 * hence caching modes for new pages can easily set unless increasing
-	 * of %a2 are forgotten.
-	 */
-Lnot040:
+#if defined(CONFIG_AMIGA)
 
-	leds(0x4)
-	
-/*
- * Do any machine specific page table initializations.
- */
-#ifdef CONFIG_AMIGA
-	is_not_amiga(Lnotami)
+.Lmmu_init_amiga:
 
+	is_not_amiga(.Lmmu_init_not_amiga)
 /*
- * Setup a mapping of the first 16M of physical address space at virtual
- * address 0x80000000, using early termination page descriptors for the
- * 68030, and proper page tables for the 680[46]0.  Set this area as
- * non-cacheable.
+ * mmu_init_amiga
  */
-
-	putc('H')
-
-	is_040_or_060(Lspami68040)
-
-	/*
-	 * for the 68030, just setup a translation to map in the first
-	 * 32M of physical address space at virtual address 0x80000000
-         * using an early termination page descriptor.
-	 */
-
-	putc('I')
 
-	movel	#_PAGE_NOCACHE030+_PAGE_PRESENT+_PAGE_ACCESSED,%d0
-	movel	%d0,%a5@(0x40<<2)
-
-	jra	Lmapphys
+	putc	'D'
 
-Lspami68040:
+	is_not_040_or_060(1f)
 
 	/*
-	 * for the 680[46]0, use another pointer table, and allocate 4 more
-	 * page tables.  Initialize the pointer table to point to the
-	 * page tables.  Then initialize the page tables to point to
-	 * the first 16M of memory, with no caching (noncachable/serialized).
+	 * 040: Map the 16Meg range physical 0x0 upto logical 0x8000.0000
 	 */
-
-	/* clear the amiga pointer table */
-	lea	%a4@(PTR_TABLE_SIZE<<2),%a4
-	moveq	#PTR_TABLE_SIZE-1,%d1
-1:	clrl	%a0@+
-	dbra	%d1,1b
+	mmu_map	#0x80000000,#0,#0x01000000,#_PAGE_NOCACHE_S
 
-	/* allocate 4 pages for 64 page tables */
-	movel	%a6,%a3
-	addw	#4*PAGESIZE,%a6
-
-	/* initialize the pointer table */
-	movel	%a4,%a0
-	movel	%a3,%a1
-	addw	#_PAGE_TABLE+_PAGE_ACCESSED,%a1	/* base descriptor */
-	movel	#PAGE_TABLE_SIZE<<2,%d2 /* increment */
-	moveq	#TABLENR_16MB-1,%d1
-
-1:	movel	%a1,%a0@+
-	addl	%d2,%a1
-	dbra	%d1,1b
-
-	/* ensure that the root table points to the pointer table */
-	movel	%a4,%a0
-	addw	#_PAGE_TABLE+_PAGE_ACCESSED,%a0
-	movel	%a0,%a5@(0x40<<2)
+	jbra	.Lmmu_init_done
 
+1:
 	/*
-	 * initialize the page tables
-	 * descriptor bits include noncachable/serialized and global bits.
+	 * 030:	Map the 32Meg range physical 0x0 upto logical 0x8000.0000
 	 */
-	movel	%a3,%a0
-	movew	#_PAGE_GLOBAL040+_PAGE_NOCACHE_S+_PAGE_PRESENT+_PAGE_ACCESSED,%a1
-	movel	#PAGESIZE,%d2
-	movew	#(PAGE_TABLE_SIZE*TABLENR_16MB)-1,%d1
+	mmu_map	#0x80000000,#0,#0x02000000,#_PAGE_NOCACHE030
 
-1:	movel	%a1,%a0@+
-	addl	%d2,%a1
-	dbra	%d1,1b
+	jbra	.Lmmu_init_done
 
-	/*
-	 * Finally, since we just allocated 4 page tables, make sure that
-	 * the virtual mapping of the 4 page tables indicates
-	 * noncachable/serialized.
-	 */
-	moveq	#3,%d0
-1:	movel	%a2@,%d1	/* a2 already points to root table offset */
-	andw	#_CACHEMASK040,%d1
-	orw	%d6,%d1
-	movel	%d1,%a2@+
-	dbra	%d0,1b
+.Lmmu_init_not_amiga:
+#endif
 
-	jra	Lmapphys
+#if defined(CONFIG_ATARI)
 
-Lnotami:
-#endif
+.Lmmu_init_atari:
 
-#ifdef CONFIG_ATARI
-	is_not_atari(Lnotatari)
+	is_not_atari(.Lmmu_init_not_atari)
 
-	move.w	#PAGESIZE,%sp
+	putc	'E'
 
 /* On the Atari, we map the I/O region (phys. 0x00ffxxxx) by mapping
    the last 16 MB of virtual address space to the first 16 MB (i.e.
@@ -591,100 +905,58 @@
 
 	/* I/O base addr for non-Medusa, non-Hades: 0x00000000 */
 	moveq	#0,%d0
+	movel	%pc@(SYMBOL_NAME(atari_mch_type)),%d3
 	cmpl	#ATARI_MACH_MEDUSA,%d3
 	jbeq	2f
 	cmpl	#ATARI_MACH_HADES,%d3
 	jbne	1f
 2:	movel	#0xff000000,%d0 /* Medusa/Hades base addr: 0xff000000 */
 1:	movel	%d0,%d3
-	
-	/* Let the root table point to the new pointer table */
-	lea	%a4@(PTR_TABLE_SIZE<<2),%a4
-	movel	%a4,%a0
-	addw	#_PAGE_TABLE+_PAGE_ACCESSED,%a0
-	movel	%a0,%a5@(0x7f<<2)       /* 0xFE000000 - 0xFFFFFFFF */
 
-	/* clear lower half of the pointer table (0xfexxxxxx) */
-	movel	%a4,%a0
-	movel	#(PTR_TABLE_SIZE/2)-1,%d2
-1:	clrl	%a0@+
-	dbra	%d2,1b
-
-	is_040_or_060(Lspata68040)
-
-/* Mapping of the last 16M of virtual address space to the first 16M
-   for efficient addressing of hardware registers */
-	movel	#PAGE_TABLE_SIZE*PAGESIZE,%d1
-	movel	#(PTR_TABLE_SIZE/2)-1,%d2
-	movel	%d3,%d0
-	orw	#_PAGE_PRESENT+_PAGE_ACCESSED,%d0
-1:	movel	%d0,%a0@+
-	addl	%d1,%d0
-	dbra	%d2,1b
-	moveq	#_PAGE_NOCACHE030,%d0	/* make non-cachable */
-	addl	%d0,%a4@(0x7f<<2)	/* 0xFFFC0000-0xFFFFFFFF (I/O space) */
-/* GK: 0xFFF00000-0xFFF3FFFF (IDE-bus) has to be non-cachable too */
-	addl	%d0,%a4@(0x7c<<2)
-
-	jra	Lmapphys
-
-Lspata68040:
-	/* allocate 4 page tables */
-	movel	%a6,%a3
-	addw	#4*PAGESIZE,%a6
-
-	/* Initialize the upper half of the pointer table (a0 is still valid) */
-	movel	%a3,%a1
-	addw	#_PAGE_TABLE+_PAGE_ACCESSED,%a1
-	movel	#PAGE_TABLE_SIZE<<2,%d2
-	moveq	#TABLENR_16MB-1,%d1
-1:	movel	%a1,%a0@+
-	addl	%d2,%a1
-	dbra 	%d1,1b
-
-	/* Initialize the page tables as noncacheable/serialized! */
-	movel	%a3,%a0
-	movel	%d3,%a1
-	addw	#_PAGE_GLOBAL040+_PAGE_NOCACHE_S+_PAGE_PRESENT+_PAGE_ACCESSED,%a1
-	movel	#PAGESIZE,%d2
-	movew	#(PAGE_TABLE_SIZE*TABLENR_16MB)-1,%d1
-1:	movel	%a1,%a0@+
-	addl	%d2,%a1
-	dbra	%d1,1b
+	is_040_or_060(.Lspata68040)
 
-	/*
-	 * Finally, since we just allocated 4 page tables, make sure that
-	 * the virtual mapping of the 4 page tables indicates
-	 * noncachable or write-through.
-	 */
-	moveq	#3,%d0
-1:	movel	%a2@,%d1	/* a2 already points to root table offset */
-	andw	#_CACHEMASK040,%d1
-	orw	%d6,%d1
-	movel	%d1,%a2@+
-	dbra	%d0,1b
+	/* Map everything non-cacheable, though not all parts really
+	 * need to disable caches (crucial only for 0xffc000..0xffffff
+	 * (standard I/O) and 0xf00000..0xf3ffff (IDE)). The remainder
+	 * isn't really used, except for sometimes peeking into the
+	 * ROMs (mirror at phys. 0x0), so caching isn't necessary for
+	 * this. */
+	mmu_map	#0xff000000,%d3,#0x01000000,#_PAGE_NOCACHE030
+
+	jbra	.Lmmu_init_done
+
+.Lspata68040:
+
+	mmu_map	#0xff000000,%d3,#0x01000000,#_PAGE_NOCACHE_S
+
+	jbra	.Lmmu_init_done
 
-Lnotatari:
+.Lmmu_init_not_atari:
 #endif
 
 #ifdef CONFIG_HP300
-	is_not_hp300(Lnothp300)
+	is_not_hp300(.Lnothp300)
 
 /* On the HP300, we map the ROM, INTIO and DIO regions (phys. 0x00xxxxxx)
-   by mapping 32MB from 0xf0xxxxxx -> 0x00xxxxxx) using an 030 early 
-   termination page descriptor.  The ROM mapping is needed because the LEDs 
+   by mapping 32MB from 0xf0xxxxxx -> 0x00xxxxxx) using an 030 early
+   termination page descriptor.  The ROM mapping is needed because the LEDs
    are mapped there too.  */
 
+	mmu_map	#0xf0000000,#0,#0x01000000,#_PAGE_NOCACHE030
+
+#if 0
 	movel	#_PAGE_NOCACHE030+_PAGE_PRESENT+_PAGE_ACCESSED,%d0
 	movel	%d0,%a5@(0x78<<2)
+#endif
+
+.Lnothp300:
 
-Lnothp300:
-	
 #endif
 
 #if defined(CONFIG_MVME16x)
-	is_not_mvme16x(Lnot16x)
 
+	is_not_mvme16x(.Lnot16x)
+
 	/* Get pointer to board ID data */
 	movel	%d2,%sp@-
 	.long	0x4e4f0070		/* trap 0x70 - .BRD_ID */
@@ -696,392 +968,397 @@
 	 * On MVME16x we have already created kernel page tables for
 	 * 4MB of RAM at address 0, so now need to do a transparent
 	 * mapping of the top of memory space.  Make it 0.5GByte for now.
+	 * Supervisor only access, so transparent mapping doesn't
+	 * clash with User code virtual address space.
+	 * this covers IO devices, PROM and SRAM.  The PROM and SRAM
+	 * mapping is needed to allow 167Bug to run.
+	 * IO is in the range 0xfff00000 to 0xfffeffff.
+	 * PROM is 0xff800000->0xffbfffff and SRAM is
+	 * 0xffe00000->0xffe1ffff.
 	 */
 
-	movel	#0xe01f0000,%d2		/* logical address base */
-	orw	#0xa040,%d2		/* add in magic bits */
-	.long	0x4e7b2005		/* movec d2,ittr1 */
-	.long	0x4e7b2007		/* movec d2,dttr1 */
+	mmu_map_tt	#0xe0000000,#0x20000000,#_PAGE_NOCACHE_S
 
-Lnot16x:
-#endif
+	jbra	.Lmmu_init_done
 
+.Lnot16x:
+#endif	/* CONFIG_MVME162 | CONFIG_MVME167 */
+
 #if defined(CONFIG_BVME6000)
-	is_not_bvme6000(Lnotbvm)
+
+	is_not_bvme6000(.Lnot6000)
 
 	/*
 	 * On BVME6000 we have already created kernel page tables for
 	 * 4MB of RAM at address 0, so now need to do a transparent
-	 * mapping of the top of memory space.  Make it 0.5GByte for now.
+	 * mapping of the top of memory space.  Make it 0.5GByte for now,
+	 * so we can access on-board i/o areas.
+	 * Supervisor only access, so transparent mapping doesn't
+	 * clash with User code virtual address space.
 	 */
 
-	movel	#0xe01f0000,%d2		/* logical address base */
-	orw	#0xa040,%d2		/* add in magic bits */
-	.long	0x4e7b2005		/* movec d2,ittr1 */
-	.long	0x4e7b2007		/* movec d2,dttr1 */
-	.long	0x4e7b2004		/* movec d2,ittr0 */
-	.long	0x4e7b2006		/* movec d2,dttr0 */
+	mmu_map_tt	#0xe0000000,#0x20000000,#_PAGE_NOCACHE_S
 
-Lnotbvm:
-#endif
+	jbra	.Lmmu_init_done
 
+.Lnot6000:
+#endif /* CONFIG_BVME6000 */
+
 /*
- * Setup a transparent mapping of the physical memory we are executing in.
+ * mmu_init_mac
+ *
+ * The Macintosh mappings are less clear.
  *
- * Only do this if the physical memory is not in the first 16M Meg, or not on
- * an Amiga since the first 16M is already identity mapped on the Amiga.
+ * Even as of this writing, it is unclear how the
+ * Macintosh mappings will be done.  However, as
+ * the first author of this code I'm proposing the
+ * following model:
+ *
+ * Map the kernel (that's already done),
+ * Map the I/O (on most machines that's the
+ * 0x5000.0000 ... 0x5200.0000 range,
+ * Map the video frame buffer using as few pages
+ * as absolutely (this requirement mostly stems from
+ * the fact that when the frame buffer is at
+ * 0x0000.0000 then we know there is valid RAM just
+ * above the screen that we don't want to waste!).
+ *
+ * By the way, if the frame buffer is at 0x0000.0000
+ * then the Macintosh is known as an RBV based Mac.
+ *
+ * By the way 2, the code currently maps in a bunch of
+ * regions.  But I'd like to cut that out.  (And move most
+ * of the mappings up into the kernel proper ... or only
+ * map what's necessary.)
  */
-Lmapphys:
-	putc('J')
-	leds(0x8)
 
-#ifdef CONFIG_AMIGA
-	is_not_amiga(Lmapphysnotamiga)
+#if defined(CONFIG_MAC)
 
-/*
- * The virtual address of the start of the kernel is 0x1000. We transparently
- * translate the memory where we running in and can enable then the MMU. Hence
- * we have now two locations of the kernel in memory and can jump to the final
- * place. Except if the physical location is in the first 16MB, translation
- * will overlap later virtual location, but as we already mapped the first
- * 16MB to 0x80000000, we can jump there after translation and MMU is enabled
- * and then we can switch off translation and go to the final place.
- * On 020/030 we must emulate transparant translation, since 020 doesn't know
- * it, but due to early termination pointer this is easy to do.
- * When MMU is enabled, stack pointer and Lcustom will become again valid and
- * stack points to the unused first page.
- */
+.Lmmu_init_mac:
 
-/*
- * Setup Supervisor Root Pointer register to point to page directory,
- * setup translation register contents and enable translation.
- */
-	putc('K')
+	is_not_mac(.Lmmu_init_not_mac)
 
-	movew	#PAGESIZE,%sp
+	putc	'F'
 
-	/* fixup the Amiga custom register location before printing */
-	lea	%pc@(Lcustom),%a0
-	movel	#0x80000000,%a0@
+	lea	%pc@(.Lmac_videobase),%a0
+	lea	%pc@(.Lconsole_video_virtual),%a1
+	movel	%a0@,%a1@
 
-	is_040_or_060(Lamimmu68040)
+	is_not_040_or_060(1f)
 
-	moveq	#ROOT_INDEX_SHIFT,%d2
-	movel	%d5,%d0
-	lsrl	%d2,%d0
-	movel	%d0,%d1
-	lsll	%d2,%d1
-	orw	#_PAGE_PRESENT+_PAGE_ACCESSED,%d1
-	lsll	#2,%d0
-	movel	%a5@(%d0:w),%d2
-	movel	%d1,%a5@(%d0:w)
-	lea	%pc@(Lmmu),%a3
-	/* no limit, 4byte descriptors */
-	movel	#0x80000002,%a3@
-	movel	%a5,%a3@(4)
-	pmove	%a3@,%srp
-	pmove	%a3@,%crp
-	pflusha
+	moveq	#_PAGE_NOCACHE_S,%d3
+	jbra	2f
+1:
+	moveq	#_PAGE_NOCACHE030,%d3
+2:
 	/*
-	 * enable,super root enable,4096 byte pages,7 bit root index,
-	 * 7 bit pointer index, 6 bit page table index.
+	 * Mac Note: screen address of logical 0xF000.0000 -> <screen physical>
 	 */
-	movel	#0x82c07760,%a3@
-	pmove	%a3@,%tc	/* enable the MMU */
-	tstl	%d0
-	jne	1f
-	jmp	%pc@(2f+0x80000000)
-1:	jmp	2f:w
-2:	movel	%d2,%a5@(%d0:w)
-	pflusha
-	jmp	LdoneMMUenable:w
 
-Lamimmu68040:
+	/* Calculate screen size */
+	clrl	%d0
+	lea	%pc@(SYMBOL_NAME(mac_dimensions)),%a0
+	movew	%a0@,%d0		/* d0 = screen height in pixels */
 
-	.chip	68040
-	lea	2f:w,%a0
-	movel	%d5,%d0
-	andl	#0xff000000,%d0
-	jne	1f
-	lea	%pc@(2f+0x80000000),%a0
-1:	orw	#TTR_ENABLE+TTR_KERNELMODE+_PAGE_NOCACHE_S,%d0
-	movec	%d0,%itt0
-	movec	%a5,%urp
-	movec	%a5,%srp
-	pflusha
-	movel	#TC_ENABLE+TC_PAGE4K,%d0
-	/*
-	 * this value is also ok for the 68060, we don`t use the cache
-	 * mode/protection defaults
-	 */
-	movec	%d0,%tc		/* enable the MMU */
-	jmp	%a0@
-2:	moveq	#0,%d0
-	movec	%d0,%itt0
-	jmp	LdoneMMUenable:w
-	.chip	68k
+	lea	%pc@(.Lmac_rowbytes),%a0
+	mulul	%a0@,%d0		/* scan line bytes x num scan lines */
+	lea	%pc@(.Lmac_videobase),%a0
+	movel	%a0@,%d2		/* grab screen offset from start of a page */
+	andl	#PAGESIZE-1,%d2		/* ... offset from start of page ... */
+	addl	%d2,%d0			/* add it to N bytes needed for screen for mapping purposes! */
+	addl	#PAGESIZE-1,%d0		/* Round up to page alignment */
+	andl	#-PAGESIZE,%d0		/* d0 is now the number of 4K pages for the screen */
 
-Lmapphysnotamiga:
+	movel	%a0@,%d2
+	andl	#PAGESIZE-1,%d2
+	addl	#0xF0000000,%d2
+	lea	%pc@(.Lconsole_video_virtual),%a1
+	movel	%d2,%a1@		/* Update the console_video address */
+	movel	%a0@,%d2
+	andl	#-PAGESIZE,%d2
+
+	mmu_map		#0xf0000000,%d2,%d0,%d3
+	mmu_map_eq	#0x40800000,#0x02000000,%d3	/* rom ? */
+	mmu_map_eq	#0x50000000,#0x02000000,%d3
+	mmu_map_eq	#0x60000000,#0x00400000,%d3
+	mmu_map_eq	#0x9c000000,#0x00400000,%d3
+	mmu_map_tt	#0xf8000000,#0x08000000,%d3
+
+	jbra	mmu_init_done
+
+.Lmmu_init_not_mac:
 #endif
 
-#ifdef CONFIG_ATARI
-	is_not_atari(Lmapphysnotatari)
+.Lmmu_init_done:
 
+	putc	'G'
+	leds	0x8
+
 /*
- * If the kernel physical address is different from its virtual address, we
- * will temporarily set up an identity mapping of the 16MB chunk with
- * transparent translation where the kernel is executing.
+ * mmu_fixup
+ *
+ * On the 040 class machines, all pages that are used for the
+ * mmu have to be fixed up. According to Motorola, pages holding mmu
+ * tables should be non-cacheable on a '040 and write-through on a
+ * '060. But analysis of the reasons for this, and practical
+ * experience, showed that write-through also works on a '040.
+ *
+ * Allocated memory so far goes kernel_end to memory_start that
+ * is used for all kind of tables, for that the cache attributes
+ * are now fixed.
  */
-	putc('L')
+.Lmmu_fixup:
 
-	/* fixup the  Atari iobase register location before printing */
-	lea	%pc@(Liobase),%a0
-	movel	#0xff000000,%a0@
+	is_not_040_or_060(.Lmmu_fixup_done)
 
-	is_040_or_060(Latarimmu68040)
+#if defined(MMU_NOCACHE_KERNEL)
+	jbra	.Lmmu_fixup_done
+#endif
 
-	.chip	68030
-	lea	%pc@(Lmmu),%a3
-	movel	%d5,%d0
-	jne	1f
-	lea	LdoneMMUenable:w,%a0
-	jra	3f
-1:	lea	4f:w,%a0
-	andl	#0xff000000,%d0 /* logical address base */
-	jeq	2f
-	orw	#TTR_ENABLE+TTR_CI+TTR_RWM+TTR_FCB2+TTR_FCM1+TTR_FCM0,%d0
-	movel	%d0,%a3@
-	pmove	%a3@,%tt0
-	jra	3f
-	/* tt0 doesn't work if physical and virtual address of kernel is in
-	 * the same 16M area (Falcon with Magnum/FX, kernel in alternate ram)
-	 * Transparent translation through kernel pointer table
-	 * Requires that this code until after MMU enabling lies in
-	 * the 256K page around %d5
-	 */
-2:	movel	%a5@,%d1
-	andw	#0xfff0,%d1
-	movel	%d1,%a1
-	movel	%d5,%d1
-	moveq	#PTR_INDEX_SHIFT,%d0
-	lsrl	%d0,%d1
-	lea	%a1@(%d1:l:4),%a1
-	movel	%d5,%d1
-	orw	#_PAGE_PRESENT+_PAGE_ACCESSED,%d1
-	movel	%a1@,%d2
-	movel	%d1,%a1@
-	lea	5f:w,%a0
-	/* no limit, 4byte descriptors */
-3:	movel	#0x80000002,%a3@
-	movel	%a5,%a3@(4)
-	pmove	%a3@,%srp
-	pmove	%a3@,%crp
-	pflusha
-	/*
-	 * enable,super root enable,4096 byte pages,7 bit root index,
-	 * 7 bit pointer index, 6 bit page table index.
+	/* first fix the page at the start of the kernel, that
+         * contains also kernel_pg_dir.
 	 */
-	movel	#0x82c07760,%a3@
-	pmove	%a3@,%tc	/* enable the MMU */
-	jmp	%a0@
-4:	clrl	%a3@
-	pmove	%a3@,%tt0
-	jra	LdoneMMUenable
-5:	movel	%d2,%a1@
-	jra	LdoneMMUenable
-	.chip	68k
+	movel	%pc@(.Lphys_kernel_start),%d0
+	lea	%pc@(SYMBOL_NAME(_stext)),%a0
+	subl	%d0,%a0
+	mmu_fixup_page_mmu_cache	%a0
 
-Latarimmu68040:
-	.chip	68040
-	movel	%d5,%d0
-	jne	1f
-	lea	LdoneMMUenable:w,%a0
-	jra	2f
-1:	lea	3f:w,%a0
-	andl	#0xff000000,%d0 /* logical address base */
-	orw	#TTR_ENABLE+TTR_KERNELMODE+_PAGE_NOCACHE_S,%d0
-	movec	%d0,%itt0
-2:	nop
-	pflusha
-	movec	%a5,%srp
-	movec	%a5,%urp
-	movel	#TC_ENABLE+TC_PAGE4K,%d0
-	/*
-	 * this value is also ok for the 68060, we don`t use the cache
-	 * mode/protection defaults
-	 */
-	movec	%d0,%tc		/* enable the MMU */
-	jmp	%a0@
-3:	moveq	#0,%d0
-	movec	%d0,%itt0
-	jra	LdoneMMUenable
-	.chip	68k
+	movel	%pc@(.Lkernel_end),%a0
+	subl	%d0,%a0
+	movel	%pc@(.Lmemory_start),%a1
+	subl	%d0,%a1
+	bra	2f
+1:
+	mmu_fixup_page_mmu_cache	%a0
+	addw	#PAGESIZE,%a0
+2:
+	cmpl	%a0,%a1
+	jgt	1b
 
-Lmapphysnotatari:
+.Lmmu_fixup_done:
+
+#if defined(MMU_PRINT)
+	jbsr	mmu_print
 #endif
 
-#if defined(CONFIG_MVME16x)
-	is_not_mvme16x(Lmapphysnot16x)
-	/*
-	 * save physaddr of phys mem in register a3
-	 */
-	moveq	#'L',%d7
-	jbsr	Lserial_putc
+/*
+ * mmu_engage
+ *
+ * This chunk of code performs the gruesome task of engaging the MMU.
+ * The reason its gruesome is because when the MMU becomes engaged it
+ * maps logical addresses to physical addresses.  The Program Counter
+ * register is then passed through the MMU before the next instruction
+ * is fetched (the instruction following the engage MMU instruction).
+ * This may mean one of two things:
+ * 1. The Program Counter falls within the logical address space of
+ *    the kernel of which there are two sub-possibilities:
+ *    A. The PC maps to the correct instruction (logical PC == physical
+ *       code location), or
+ *    B. The PC does not map through and the processor will read some
+ *       data (or instruction) which is not the logically next instr.
+ *    As you can imagine, A is good and B is bad.
+ * Alternatively,
+ * 2. The Program Counter does not map through the MMU.  The processor
+ *    will take a Bus Error.
+ * Clearly, 2 is bad.
+ * It doesn't take a wiz kid to figure you want 1.A.
+ * This code creates that possibility.
+ * There are two possible 1.A. states (we now ignore the other above states):
+ * A. The kernel is located at physical memory addressed the same as
+ *    the logical memory for the kernel, i.e., 0x01000.
+ * B. The kernel is located some where else.  e.g., 0x0400.0000
+ *
+ *    Under some conditions the Macintosh can look like A or B.
+ * [A friend and I once noted that Apple hardware engineers should be
+ * wacked twice each day: once when they show up at work (as in, Whack!,
+ * "This is for the screwy hardware we know you're going to design today."),
+ * and also at the end of the day (as in, Whack! "I don't know what
+ * you designed today, but I'm sure it wasn't good."). -- rst]
+ *
+ * This code works on the following premise:
+ * If the kernel start (%d5) is within the first 16 Meg of RAM,
+ * then create a mapping for the kernel at logical 0x8000.0000 to
+ * the physical location of the pc.  And, create a transparent
+ * translation register for the first 16 Meg.  Then, after the MMU
+ * is engaged, the PC can be moved up into the 0x8000.0000 range
+ * and then the transparent translation can be turned off and then
+ * the PC can jump to the correct logical location and it will be
+ * home (finally).  This is essentially the code that the Amiga used
+ * to use.  Now, it's generalized for all processors.  Which means
+ * that a fresh (but temporary) mapping has to be created.  The mapping
+ * is made in page 0 (an as of yet unused location -- except for the
+ * stack!).  This temporary mapping will only require 1 pointer table
+ * and a single page table (it can map 256K).
+ *
+ * OK, alternatively, imagine that the Program Counter is not within
+ * the first 16 Meg.  Then, just use Transparent Translation registers
+ * to do the right thing.
+ *
+ * Last, if _start is already at 0x01000, then there's nothing special
+ * to do (in other words, in a degenerate case of the first case above,
+ * do nothing).
+ *
+ * Let's do it.
+ *
+ *
+ */
 
-	.word	0xf4d8		/* CINVA I/D    */
-	.word	0xf518		/* pflusha      */
-	.long	0x4e7bd807	/* movec a5,srp */
-	.long	0x4e7bd806	/* movec a5,urp */
-	movel	#(TC_ENABLE+TC_PAGE4K),%d0
-	.long	0x4e7b0003	/* movec d0,tc  (enable the MMU) */
-	jra	LdoneMMUenable	/* branch to continuation of startup */
+	putc	'H'
 
-Lmapphysnot16x:
+	mmu_engage
 
+#if defined(CONFIG_AMIGA)
+	is_not_amiga(1f)
+	/* fixup the Amiga custom register location before printing */
+	clrl	.Lcustom
+1:
 #endif
 
-#if defined(CONFIG_HP300)
-	is_not_hp300(Lmapphysnothp300)
-
-/*
- * Physical RAM is at 0xff000000.  We want to map the kernel at 0x00000000.
- * In order to avoid disaster when we enable the MMU we need to make a
- * transparent mapping of the RAM we're executing out of as well.
- */
-	/*
-	 * save physaddr of phys mem in register a3
-	 */
+#if defined(CONFIG_ATARI)
+	is_not_atari(1f)
+	/* fixup the Atari iobase register location before printing */
+	lea	%pc@(.Liobase),%a0
+	movel	#0xff000000,%a0@
+1:
+#endif
 
-	.chip	68030
-	lea	%pc@(Lmmu),%a3
-	movel	%d5,%d0
-	andl	#0xff000000,%d0 /* logical address base */
-	orw	#TTR_ENABLE+TTR_CI+TTR_RWM+TTR_FCB2+TTR_FCM1+TTR_FCM0,%d0
-	movel	%d0,%a3@
-	pmove	%a3@,%tt0
-	/* no limit, 4byte descriptors */
-	movel	#0x80000002,%a3@
-	movel	%a5,%a3@(4)
-	pmove	%a3@,%srp
-	pmove	%a3@,%crp
-	pflusha
-	/*
-	 * enable,super root enable,4096 byte pages,7 bit root index,
-	 * 7 bit pointer index, 6 bit page table index.
-	 */
-	movel	#0x82c07760,%a3@
-	pmove	%a3@,%tc	/* enable the MMU */
-	jmp	1f
-1:	
-	.chip	68k
+#if defined(CONFIG_MAC)
+	is_not_mac(1f)
+	lea	%pc@(.Lconsole_video_virtual),%a1
+	lea	%pc@(.Lmac_videobase),%a3
+	movel	%a1@,%a3@
+1:
+#endif
 
+#if defined(CONFIG_HP300)
+	is_not_hp300(1f)
 	/*
 	 * Fix up the custom register to point to the new location of the LEDs.
 	 */
-	lea	%pc@(Lcustom),%a1
+	lea	%pc@(.Lcustom),%a1
 	movel	#0xf0000000,%a1@
-
-	/*
-	 * Energise the FPU and caches.
-	 */
-	orl	#0x64, 0xf05f400c 
-	
-Lmapphysnothp300:
-
+1:
 #endif
 
-#if defined(CONFIG_BVME6000)
-	is_not_bvme6000(Lmapphysnotbvm)
-	/*
-	 * save physaddr of phys mem in register a3
-	 */
-	moveq	#'L',%d7
-	jbsr	Lserial_putc
-
-	.word	0xf4d8		/* CINVA I/D    */
-	.word	0xf518		/* pflusha      */
-	.long	0x4e7bd807	/* movec a5,srp */
-	.long	0x4e7bd806	/* movec a5,urp */
-	movel	#(TC_ENABLE+TC_PAGE4K),%d0
+#if defined(CONFIG_HP300)
+	is_not_hp300(1f)
 	/*
-	 * this value is also ok for the 68060, we don`t use the cache
-	 * mode/protection defaults
+	 * Energise the FPU and caches.
 	 */
-	.long	0x4e7b0003	/* movec d0,tc  (enable the MMU) */
-	jra	LdoneMMUenable	/* branch to continuation of startup */
-
-Lmapphysnotbvm:
-
+	movel	#0x60, 0xf05f400c
+1:
 #endif
-
-LdoneMMUenable:
+	movew	#PAGESIZE,%sp
 
 /*
  * Fixup the addresses for the kernel pointer table and availmem.
  * Convert them from physical addresses to virtual addresses.
  */
 
-	putc('M')
+	putc	'I'
 	leds(0x10)
 
-	/*
-	 * d5 contains physaddr of kernel start
+	/* d5 contains physaddr of kernel start
 	 */
-	subl	%d5,SYMBOL_NAME(kpt)
+|	lea	SYMBOL_NAME(kpt),%a0
+|	subl	%d5,%a0@
 
-	/*
-	 * do the same conversion on the first available memory
+	/* do the same conversion on the first available memory
 	 * address (in a6).
 	 */
-	subl	%d5,%a6
-	movel	%a6,SYMBOL_NAME(availmem) /* first available memory address */
+	movel	.Lmemory_start,%d0
+	movel	%d0,SYMBOL_NAME(availmem)
 
-	putc('N')
-
 /*
  * Enable caches
  */
-	is_040_or_060(Lcache680460)
 
-	movel	#CC3_ENABLE_DB+CC3_CLR_D+CC3_ENABLE_D+CC3_ENABLE_IB+CC3_CLR_I+CC3_ENABLE_I,%d0
-	movec	%d0,%cacr
-	jra	1f
+#if defined(CONFIG_M68040) || defined(CONFIG_M68060)
+	is_not_040_or_060(.Lcache_not_680460)
 
-Lcache680460:
+.Lcache680460:
 	.chip	68040
+	nop
 	cpusha	%bc
-	.chip	68k
+	nop
 
-	is_060(Lcache68060)
+	is_060(.Lcache68060)
 
 	movel	#CC6_ENABLE_D+CC6_ENABLE_I,%d0
 	/* MMU stuff works in copyback mode now, so enable the cache */
 	movec	%d0,%cacr
-	jra	1f
+	jra	.Lcache_done
 
-Lcache68060:
-	.chip	68060
+.Lcache68060:
 	movel	#CC6_ENABLE_D+CC6_ENABLE_I+CC6_ENABLE_SB+CC6_PUSH_DPI+CC6_ENABLE_B+CC6_CLRA_B,%d0
 	/* MMU stuff works in copyback mode now, so enable the cache */
 	movec	%d0,%cacr
 	/* enable superscalar dispatch in PCR */
 	moveq	#1,%d0
+	.chip	68060
 	movec	%d0,%pcr
+
+	jbra	.Lcache_done
+.Lcache_not_680460:
+#endif
+#if defined(CONFIG_M68020) || defined(CONFIG_M68030)
+.Lcache68030:
+	.chip	68030
+	movel	#CC3_ENABLE_DB+CC3_CLR_D+CC3_ENABLE_D+CC3_ENABLE_IB+CC3_CLR_I+CC3_ENABLE_I,%d0
+	movec	%d0,%cacr
+
+	jra	.Lcache_done
+#endif
 	.chip	68k
+.Lcache_done:
+
+	putc	'J'
+
+#if defined(MMU_PRINT_PAGE_USAGE)
+	/*
+	 * Print out the number of pages used by MMU above the kernel
+	 */
+	puts	"MMU #"
+	lea	%pc@(SYMBOL_NAME(_end)),%a0
+	addw	#PAGESIZE-1,%a0
+	movel	%a0,%d0
+	andl	#-PAGESIZE,%d0
+	movel	%a6,%d1
+	subl	%d0,%d1		/* d1 :	= d1 - d0 */
+	putn	%d1
+	putc	'\n'
+
+	puts	"Page #"
+	putn	%pc@(.Lmmu_num_page_tables)
+	putc	'\n'
+
+
+	puts	"Ptr #"
+	putn	%pc@(.Lmmu_num_pointer_tables)
+	putc	'\n'
+
+	puts	"Total #"
+	movel	%pc@(.Lmmu_num_page_tables),%d0
+	addl	%pc@(.Lmmu_num_pointer_tables),%d0
+	putn	%d0
+	putc	'\n'
+
+	puts	"Halting."
 1:
+	jbra	1b
+#endif /* MMU_PRINT_PAGE_USAGE */
 
 /*
  * Setup initial stack pointer
- * We need to get current loaded up with our first task...
  */
 	lea	SYMBOL_NAME(init_task_union),%a2
-	lea	8192(%a2),%sp
+	lea	0x2000(%a2),%sp
 
 /* jump to the kernel start */
-	putr()
-	leds(0x55)
+	putc	'\n'
+	leds	0x55
 
-	subl	%a6,%a6 /* clear a6 for gdb */
+	subl	%a6,%a6		/* clear a6 for gdb */
 	jbsr	SYMBOL_NAME(start_kernel)
 
 /*
@@ -1090,7 +1367,9 @@
  * Returns: d0: size (-1 if not found)
  *          a0: data pointer (end-of-records if not found)
  */
-Lget_bi_record:
+func_start	get_bi_record,%d1
+
+	movel	ARG1,%d0
 	lea	%pc@(SYMBOL_NAME(_end)),%a0
 1:	tstw	%a0@(BIR_tag)
 	jeq	3f
@@ -1101,23 +1380,1201 @@
 2:	moveq	#0,%d0
 	movew	%a0@(BIR_size),%d0
 	lea	%a0@(BIR_data),%a0
-	rts
+	jra	4f
 3:	moveq	#-1,%d0
 	lea	%a0@(BIR_size),%a0
+4:
+func_return	get_bi_record
+
+
+/*
+ *	MMU Initialization Begins Here
+ *
+ *	The structure of the MMU tables on the 68k machines
+ *	is thus:
+ *	Root Table
+ *		Logical addresses are translated through
+ *	a hierarchical translation mechanism where the high-order
+ *	seven bits of the logical address (LA) are used as an
+ *	index into the "root table."  Each entry in the root
+ *	table has a bit which specifies if it's a valid pointer to a
+ *	pointer table.  Each entry defines a 32KMeg range of memory.
+ *	If an entry is invalid then that logical range of 32M is
+ *	invalid and references to that range of memory (when the MMU
+ *	is enabled) will fault.  If the entry is valid, then it does
+ *	one of two things.  On 040/060 class machines, it points to
+ *	a pointer table which then describes more finely the memory
+ *	within that 32M range.  On 020/030 class machines, a technique
+ *	called "early terminating descriptors" are used.  This technique
+ *	allows an entire 32Meg to be described by a single entry in the
+ *	root table.  Thus, this entry in the root table, contains the
+ *	physical address of the memory or I/O at the logical address
+ *	which the entry represents and it also contains the necessary
+ *	cache bits for this region.
+ *
+ *	Pointer Tables
+ *		Per the Root Table, there will be one or more
+ *	pointer tables.  Each pointer table defines a 32M range.
+ *	Not all of the 32M range need be defined.  Again, the next
+ *	seven bits of the logical address are used an index into
+ *	the pointer table to point to page tables (if the pointer
+ *	is valid).  There will undoubtedly be more than one
+ *	pointer table for the kernel because each pointer table
+ *	defines a range of only 32M.  Valid pointer table entries
+ *	point to page tables, or are early terminating entries
+ *	themselves.
+ *
+ *	Page Tables
+ *		Per the Pointer Tables, each page table entry points
+ *	to the physical page in memory that supports the logical
+ *	address that translates to the particular index.
+ *
+ *	In short, the Logical Address gets translated as follows:
+ *		bits 31..26 - index into the Root Table
+ *		bits 25..18 - index into the Pointer Table
+ *		bits 17..12 - index into the Page Table
+ *		bits 11..0  - offset into a particular 4K page
+ *
+ *	The algorithms which follows do one thing: they abstract
+ *	the MMU hardware.  For example, there are three kinds of
+ *	cache settings that are relevant.  Either, memory is
+ *	being mapped in which case it is either Kernel Code (or
+ *	the RamDisk) or it is MMU data.  On the 030, the MMU data
+ *	option also describes the kernel.  Or, I/O is being mapped
+ *	in which case it has its own kind of cache bits.  There
+ *	are constants which abstract these notions from the code that
+ *	actually makes the call to map some range of memory.
+ *
+ *
+ *
+ */
+
+#if defined(MMU_PRINT)
+/*
+ *	mmu_print
+ *
+ *	This algorithm will print out the current MMU mappings.
+ *
+ *	Input:
+ *		%a5 points to the root table.  Everything else is calculated
+ *			from this.
+ */
+
+#define mmu_next_valid		0
+#define mmu_start_logical	4
+#define mmu_next_logical	8
+#define mmu_start_physical	12
+#define mmu_next_physical	16
+
+#define MMU_PRINT_INVALID		-1
+#define MMU_PRINT_VALID			1
+#define MMU_PRINT_UNINITED		0
+
+#define	putZc(z,n)		jbne 1f; putc(z); jbra 2f ; 1: putc(n); 2:
+
+mmu_print:
+	moveml	%a0-%a6/%d0-%d7,%sp@-
+
+	lea	%pc@(.Lmmu_print_data),%a0
+	movel	#MMU_PRINT_UNINITED,%a0@(mmu_next_valid)
+
+	is_not_040_or_060(mmu_030_print)
+
+mmu_040_print:
+	putr()
+	puts("MMU040")
+	putr()
+	putr()
+	puts("rp:")
+	movel	%a5,%d7
+	jbsr	.Lserial_putnum
+	putr()
+	puts("tc:")
+	movel	%d5,%d7
+	jbsr	.Lserial_putnum
+	putr()
+	putr()
+#if 0
+	/*
+	 * The following #if/#endif block is a tight algorithm for dumping the 040
+	 * MMU Map in gory detail.  It really isn't that practical unless the
+	 * MMU Map algorithm appears to go awry and you need to debug it at the
+	 * entry per entry level.
+	 */
+	movel	#ROOT_TABLE_SIZE-1,%d5
+	movel	%a5@+,%d7		/* Burn an entry to skip the kernel mappings, they work */
+1:	tstl	%d5
+	jbeq	mmu_print_done
+	subq	#1,%d5
+	movel	%a5@+,%d7
+	btst	#1,%d7
+	jbeq	1b
+
+2:	jbsr	.Lserial_putnum
+	andil	#0xFFFFFE00,%d7
+	movel	%d7,%a4
+	movel	#PTR_TABLE_SIZE,%d4
+	putc(' ')
+3:	tstl	%d4
+	jbeq	11f
+	subq	#1,%d4
+	movel	%a4@+,%d7
+	btst	#1,%d7
+	jbeq	3b
+
+4:	jbsr	.Lserial_putnum
+	andil	#0xFFFFFF00,%d7
+	movel	%d7,%a3
+	movel	#PAGE_TABLE_SIZE,%d3
+5:	movel	#8,%d2
+6:	tstl	%d3
+	jbeq	31f
+	subq	#1,%d3
+	movel	%a3@+,%d6
+	btst	#0,%d6
+	jbeq	6b
+7:	tstl	%d2
+	jbeq	8f
+	subq	#1,%d2
+	putc(' ')
+	jbra	91f
+8:	putr()
+	movel	#8+1+8+1+1,%d2
+9:	putc(' ')
+	dbra	%d2,9b
+	movel	#7,%d2
+91:	movel	%d6,%d7
+	jbsr	.Lserial_putnum
+	jbra	6b
+
+31:	putr()
+	movel	#8+1,%d2
+32:	putc(' ')
+	dbra	%d2,32b
+	jbra	3b
+
+11:	putr()
+	jbra	1b
+#endif /* MMU 040 Dumping code that's gory and detailed */
+
+	movel	%a5,%d0			/* a5 -> root table ptr */
+	andil	#0xfffffe00,%d0		/* I forget why this is here ? */
+	movel	%d0,%a0			/* a0 has the address of the root table ptr */
+	movel	#0x00000000,%a4		/* logical address */
+	moveql	#0,%d0
+40:
+	/* Increment the logical address and preserve in d5 */
+	movel	%a4,%d5
+	addil	#PAGESIZE<<13,%d5
+	movel	%a0@+,%d6
+	btst	#1,%d6
+	jbne	41f
+	jbsr	mmu_print_tuple_invalidate
+	jbra	48f
+41:
+	movel	#0,%d1
+	andil	#0xfffffe00,%d6
+	movel	%d6,%a1
+42:
+	movel	%a4,%d5
+	addil	#PAGESIZE<<6,%d5
+	movel	%a1@+,%d6
+	btst	#1,%d6
+	jbne	43f
+	jbsr	mmu_print_tuple_invalidate
+	jbra	47f
+43:
+	movel	#0,%d2
+	andil	#0xffffff00,%d6
+	movel	%d6,%a2
+44:
+	movel	%a4,%d5
+	addil	#PAGESIZE,%d5
+	movel	%a2@+,%d6
+	btst	#0,%d6
+	jbne	45f
+	jbsr	mmu_print_tuple_invalidate
+	jbra	46f
+45:
+	moveml	%d0-%d1,%sp@-
+	movel	%a4,%d0
+	movel	%d6,%d1
+	andil	#0xfffff4e0,%d1
+	lea	%pc@(mmu_040_print_flags),%a6
+	jbsr	mmu_print_tuple
+	moveml	%sp@+,%d0-%d1
+46:
+	movel	%d5,%a4
+	addq	#1,%d2
+	cmpib	#64,%d2
+	jbne	44b
+47:
+	movel	%d5,%a4
+	addq	#1,%d1
+	cmpib	#128,%d1
+	jbne	42b
+48:
+	movel	%d5,%a4			/* move to the next logical address */
+	addq	#1,%d0
+	cmpib	#128,%d0
+	jbne	40b
+
+	.long	0x4e7a0007		/* movec dtt1,%d0 */
+	movel	%d0,%d1
+	andiw	#0x8000,%d1		/* is it valid ? */
+	jbeq	49f			/* No, bail out */
+
+	movel	%d0,%d1
+	andil	#0xff000000,%d1		/* Get the address */
+	putn(%d1)
+	puts("==")
+	putn(%d1)
+
+	movel	%d0,%d6
+	jbsr	mmu_040_print_flags_tt
+
+49:
+	jbra	mmu_print_done
+
+mmu_040_print_flags:
+	btstl	#10,%d6
+	putZc(' ','G')	/* global bit */
+	btstl	#7,%d6
+	putZc(' ','S')	/* supervisor bit */
+mmu_040_print_flags_tt:
+	btstl	#6,%d6
+	jbne	3f
+	putc('C')
+	btstl	#5,%d6
+	putZc('w','c')	/* write through or copy-back */
+	jbra	4f
+3:
+	putc('N')
+	btstl	#5,%d6
+	putZc('s',' ')	/* serialized non-cacheable, or non-cacheable */
+4:
+	rts
+
+mmu_030_print_flags:
+	btstl	#6,%d6
+	putZc('C','I')	/* write through or copy-back */
+	rts
+
+mmu_030_print:
+	putr()
+	puts("rp:")
+	movel	%a5,%d7
+	jbsr	.Lserial_putnum
+	putr()
+	puts("tc:")
+	movel	%d5,%d7
+	jbsr	.Lserial_putnum
+	putr()
+	putr()
+	puts("MMU030")
+	putr()
+	movel	%a5,%d0
+	andil	#0xfffffff0,%d0
+	movel	%d0,%a0
+	movel	#0x00000000,%a4		/* logical address */
+	movel	#0,%d0
+30:
+	movel	%a4,%d5
+	addil	#PAGESIZE<<13,%d5
+	movel	%a0@+,%d6
+	btst	#1,%d6			/* is it a ptr? */
+	jbne	31f			/* yes */
+	btst	#0,%d6			/* is it early terminating? */
+	jbeq	1f			/* no */
+	jbsr	mmu_030_print_helper
+	jbra	38f
+1:
+	jbsr	mmu_print_tuple_invalidate
+	jbra	38f
+31:
+	movel	#0,%d1
+	andil	#0xfffffff0,%d6
+	movel	%d6,%a1
+32:
+	movel	%a4,%d5
+	addil	#PAGESIZE<<6,%d5
+	movel	%a1@+,%d6
+	btst	#1,%d6
+	jbne	33f
+	btst	#0,%d6
+	jbeq	1f			/* no */
+	jbsr	mmu_030_print_helper
+	jbra	37f
+1:
+	jbsr	mmu_print_tuple_invalidate
+	jbra	37f
+33:
+	movel	#0,%d2
+	andil	#0xfffffff0,%d6
+	movel	%d6,%a2
+34:
+	movel	%a4,%d5
+	addil	#PAGESIZE,%d5
+	movel	%a2@+,%d6
+	btst	#0,%d6
+	jbne	35f
+	jbsr	mmu_print_tuple_invalidate
+	jbra	36f
+35:
+	jbsr	mmu_030_print_helper
+36:
+	movel	%d5,%a4
+	addq	#1,%d2
+	cmpib	#64,%d2
+	jbne	34b
+37:
+	movel	%d5,%a4
+	addq	#1,%d1
+	cmpib	#128,%d1
+	jbne	32b
+38:
+	movel	%d5,%a4			/* move to the next logical address */
+	addq	#1,%d0
+	cmpib	#128,%d0
+	jbne	30b
+
+mmu_print_done:
+	putr()
+	putr()
+
+	moveml	%sp@+,%a0-%a6/%d0-%d7
+	rts
+
+mmu_030_print_helper:
+	moveml	%d0-%d1,%sp@-
+	movel	%a4,%d0
+	movel	%d6,%d1
+	lea	%pc@(mmu_030_print_flags),%a6
+	jbsr	mmu_print_tuple
+	moveml	%sp@+,%d0-%d1
 	rts
 
+mmu_print_tuple_invalidate:
+	moveml	%a0/%d7,%sp@-
+
+	lea	%pc@(.Lmmu_print_data),%a0
+	tstl	%a0@(mmu_next_valid)
+	jbmi	mmu_print_tuple_invalidate_exit
+
+	movel	#MMU_PRINT_INVALID,%a0@(mmu_next_valid)
+
+	movel	%a4,%d7
+	jbsr	.Lserial_putnum
+
+	puts("##")
+	putr()
+
+mmu_print_tuple_invalidate_exit:
+	moveml	%sp@+,%a0/%d7
+	rts
+
+
+mmu_print_tuple:
+	moveml	%d0-%d7/%a0,%sp@-
+
+	lea	%pc@(.Lmmu_print_data),%a0
+
+	tstl	%a0@(mmu_next_valid)
+	jbmi	mmu_print_tuple_print
+	jbeq	mmu_print_tuple_print
+	jbpl	mmu_print_tuple_test
+
+mmu_print_tuple_test:
+	cmpl	%a0@(mmu_next_physical),%d1
+	jbeq	mmu_print_tuple_increment
+
+mmu_print_tuple_print:
+	movel	%d0,%d7
+	jbsr	.Lserial_putnum
+
+	puts("->")
+
+	movel	%d1,%d7
+	jbsr	.Lserial_putnum
+
+	movel	%d1,%d6
+	jbsr	%a6@
+
+mmu_print_tuple_record:
+	movel	#MMU_PRINT_VALID,%a0@(mmu_next_valid)
+
+	movel	%d1,%a0@(mmu_next_physical)
+
+mmu_print_tuple_increment:
+	movel	%d5,%d7
+	subl	%a4,%d7
+	addl	%d7,%a0@(mmu_next_physical)
+
+mmu_print_tuple_exit:
+	moveml	%sp@+,%d0-%d7/%a0
+	rts
+
+mmu_print_machine_cpu_types:
+	puts("machine: ")
+
+	is_not_amiga(1f)
+	puts("amiga")
+	jbra	9f
+1:
+	is_not_atari(2f)
+	puts("atari")
+	jbra	9f
+2:
+	is_not_mac(3f)
+	puts("macintosh")
+	jbra	9f
+3:	puts("unknown")
+9:	putr()
+
+	puts("cputype: 0")
+	is_not_060(1f)
+	putc('6')
+	jbra	9f
+1:
+	is_not_040_or_060(2f)
+	putc('4')
+	jbra	9f
+2:	putc('3')
+9:	putc('0')
+	putr()
+
+	rts
+#endif /* MMU_PRINT */
+
+/*
+ * mmu_map_tt
+ *
+ * This is a specific function which works on all 680x0 machines.
+ * On 040 & 060 it will attempt to use Transparent Translation registers (tt1).
+ * On 020 & 030 it will call the standard mmu_map which will use early
+ * terminating descriptors.
+ */
+func_start	mmu_map_tt,%d0/%d1/%a0,4
+
+	is_020(.Ldo_map)
+
+	/* Extract the highest bit set
+	 */
+	bfffo	ARG2{#0,#32},%d1
+	cmpw	#8,%d0
+	jcc	.Ldo_map
+
+	/* And get the mask
+	 */
+	moveq	#-1,%d0
+	lsrl	%d1,%d0
+	lsrl	#1,%d0
+
+	/* Mask the address
+	 */
+	movel	%d0,%d1
+	notl	%d1
+	andl	ARG1,%d1
+
+	/* Generate the upper 16bit of the tt register
+	 */
+	lsrl	#8,%d0
+	orl	%d0,%d1
+	clrw	%d1
+
+	is_040_or_060(2f)
+
+	/* set 030 specific bits (read/write access for supervisor mode
+	 * (highest function code set, lower two bits masked)
+	 */
+	orw	#TTR_ENABLE+TTR_RWM+TTR_FCB2+TTR_FCM1+TTR_FCM0,%d1
+	move	ARG3,%d0
+	btst	#6,%d0
+	jeq	1f
+	orw	#TTR_CI,%d1
+
+1:	lea	STACK,%a0
+	movel	%d1,%a0@
+	.chip	68030
+	pmove	%a0@,%tt0
+	.chip	68k
+	jra	.Lmmu_map_tt_done
+
+	/* set 040 specific bits
+	 */
+2:
+	orw	#TTR_ENABLE+TTR_KERNELMODE,%d1
+	orl	ARG3,%d1
+
+	.chip	68040
+	movec	%d1,%itt1
+	movec	%d1,%dtt1
+	.chip	68k
+
+	jra	.Lmmu_map_tt_done
+
+.Ldo_map:
+	mmu_map_eq	ARG1,ARG2,ARG3
+
+.Lmmu_map_tt_done:
+
+func_return	mmu_map_tt
+
+/*
+ *	mmu_map
+ *
+ *	This routine will map a range of memory using a pointer
+ *	table and allocating the pages on the fly from the kernel.
+ *	The pointer table does not have to be already linked into
+ *	the root table, this routine will do that if necessary.
+ *
+ *	NOTE
+ *	This routine will assert failure and use the serial_putc
+ *	routines in the case of a run-time error.  For example,
+ *	if the address is already mapped.
+ *
+ *	NOTE-2
+ *	This routine will use early terminating descriptors
+ *	where possible for the 68020+68851 and 68030 type
+ *	processors.
+ */
+func_start	mmu_map,%d0-%d4/%a0-%a4
+
+	dputs	"mmu_map:"
+	dputn	ARG1
+	dputn	ARG2
+	dputn	ARG3
+	dputn	ARG4
+	dputc	'\n'
+
+	/* Get logical address and round it down to 256KB
+	 */
+	movel	ARG1,%d0
+	andl	#-(PAGESIZE*PAGE_TABLE_SIZE),%d0
+	movel	%d0,%a3
+
+	/* Get the end address
+	 */
+	movel	ARG1,%a4
+	addl	ARG3,%a4
+
+	/* Get physical address and round it down to 256KB
+	 */
+	movel	ARG2,%d0
+	andl	#-(PAGESIZE*PAGE_TABLE_SIZE),%d0
+	movel	%d0,%a2
+
+	/* Add page attributes to the physical address
+	 */
+	movel	ARG4,%d0
+	orw	#_PAGE_PRESENT+_PAGE_ACCESSED,%d0
+	addw	%d0,%a2
+
+	dputn	%a2
+	dputn	%a3
+	dputn	%a4
+
+	is_not_040_or_060(.Lmmu_map_030)
+
+	addw	#_PAGE_GLOBAL040,%a2
+/*
+ *	MMU 040 & 060 Support
+ *
+ *	The MMU usage for the 040 and 060 is different enough from
+ *	the 030 and 68851 that there is separate code.  This comment
+ *	block describes the data structures and algorithms built by
+ *	this code.
+ *
+ *	The 040 does not support early terminating descriptors, as
+ *	the 030 does.  Therefore, a third level of table is needed
+ *	for the 040, and that would be the page table.  In Linux,
+ *	page tables are allocated directly from the memory above the
+ *	kernel.
+ *
+ */
+
+.Lmmu_map_040:
+	/* Calculate the offset into the root table
+	 */
+	movel	%a3,%d0
+	moveq	#ROOT_INDEX_SHIFT,%d1
+	lsrl	%d1,%d0
+	mmu_get_root_table_entry	%d0
+
+	/* Calculate the offset into the pointer table
+	 */
+	movel	%a3,%d0
+	moveq	#PTR_INDEX_SHIFT,%d1
+	lsrl	%d1,%d0
+	andl	#PTR_TABLE_SIZE-1,%d0
+	mmu_get_ptr_table_entry		%a0,%d0
+
+	/* Calculate the offset into the page table
+	 */
+	movel	%a3,%d0
+	moveq	#PAGE_INDEX_SHIFT,%d1
+	lsrl	%d1,%d0
+	andl	#PAGE_TABLE_SIZE-1,%d0
+	mmu_get_page_table_entry	%a0,%d0
+
+	/* The page table entry must not no be busy
+	 */
+	tstl	%a0@
+	jne	.Lmmu_map_error
+
+	/* Do the mapping and advance the pointers
+	 */
+	movel	%a2,%a0@
+2:
+	addw	#PAGESIZE,%a2
+	addw	#PAGESIZE,%a3
+
+	/* Ready with mapping?
+	 */
+	cmpl	%a3,%a4
+	jhi	.Lmmu_map_040
+	jra	.Lmmu_map_done
+
+.Lmmu_map_030:
+	/* Calculate the offset into the root table
+	 */
+	movel	%a3,%d0
+	moveq	#ROOT_INDEX_SHIFT,%d1
+	lsrl	%d1,%d0
+	mmu_get_root_table_entry	%d0
+
+	/* Check if logical address 32MB aligned,
+	 * so we can try to map it once
+	 */
+	movel	%a3,%d0
+	andl	#(PTR_TABLE_SIZE*PAGE_TABLE_SIZE*PAGESIZE-1)&(-ROOT_TABLE_SIZE),%d0
+	jne	1f
+
+	/* Is there enough to map for 32MB at once
+	 */
+	lea	%a3@(PTR_TABLE_SIZE*PAGE_TABLE_SIZE*PAGESIZE),%a1
+	cmpl	%a1,%a4
+	jcs	1f
+
+	/* The root table entry must not no be busy
+	 */
+	tstl	%a0@
+	jeq	.Lmmu_map_error
+
+	/* Do the mapping and advance the pointers
+	 */
+	movel	%a2,%a0@
+
+	movel	%a1,%a3
+	lea	%a2@(PTR_TABLE_SIZE*PAGE_TABLE_SIZE*PAGESIZE),%a2
+	jra	.Lmmu_map_030
+1:
+	/* Calculate the offset into the pointer table
+	 */
+	movel	%a3,%d0
+	moveq	#PTR_INDEX_SHIFT,%d1
+	lsrl	%d1,%d0
+	andl	#PTR_TABLE_SIZE-1,%d0
+	mmu_get_ptr_table_entry		%a0,%d0
+
+	/* The pointer table entry must not no be busy
+	 */
+	tstl	%a0@
+	jeq	.Lmmu_map_error
+
+	/* Do the mapping and advance the pointers
+	 */
+	movel	%a2,%a0@
+
+	addl	#PAGE_TABLE_SIZE*PAGESIZE,%a2
+	addl	#PAGE_TABLE_SIZE*PAGESIZE,%a3
+
+	/* Ready with mapping?
+	 */
+	cmpl	%a3,%a4
+	jhi	.Lmmu_map_030
+	jra	.Lmmu_map_done
+
+.Lmmu_map_error:
+
+	dputs	"mmu_map error:"
+	dputn	%a2
+	dputn	%a3
+	dputc	'\n'
+
+.Lmmu_map_done:
+
+func_return	mmu_map
+
+/*
+ *	mmu_fixup
+ *
+ *	On the 040 class machines, all pages that are used for the
+ *	mmu have to be fixed up.
+ */
+
+func_start	mmu_fixup_page_mmu_cache,%d0/%a0
+
+	dputs	"mmu_fixup_page_mmu_cache"
+	dputn	ARG1
+	dputc	'\n'
+
+	/* Calculate the offset into the root table
+	 */
+	movel	ARG1,%d0
+	moveq	#ROOT_INDEX_SHIFT,%d1
+	lsrl	%d1,%d0
+	mmu_get_root_table_entry	%d0
+
+	/* Calculate the offset into the pointer table
+	 */
+	movel	ARG1,%d0
+	moveq	#PTR_INDEX_SHIFT,%d1
+	lsrl	%d1,%d0
+	andl	#PTR_TABLE_SIZE-1,%d0
+	mmu_get_ptr_table_entry		%a0,%d0
+
+	/* Calculate the offset into the page table
+	 */
+	movel	ARG1,%d0
+	moveq	#PAGE_INDEX_SHIFT,%d1
+	lsrl	%d1,%d0
+	andl	#PAGE_TABLE_SIZE-1,%d1
+	mmu_get_page_table_entry	%a0,%d0
+
+	movel	%a0@,%d0
+	andil	#_CACHEMASK040,%d0
+	orl	%pc@(SYMBOL_NAME(m68k_pgtable_cachemode)),%d0
+	movel	%d0,%a0@
+
+func_return	mmu_fixup_page_mmu_cache
+
+func_start	mmu_temp_map,%d0/%d1/%a0/%a1
+
+	dputs	"mmu_temp_map"
+	dputn	ARG1
+	dputn	ARG2
+	dputc	'\n'
+
+	lea	%pc@(.Ltemp_mmap_mem),%a1
+
+	/* Calculate the offset in the root table
+	 */
+	movel	ARG2,%d0
+	moveq	#ROOT_INDEX_SHIFT,%d1
+	lsrl	%d1,%d0
+	mmu_get_root_table_entry	%d0
+
+	/* Check if the table is temporary allocated, so we have to reuse it
+	 */
+	movel	%a0@,%d0
+	cmpl	%pc@(.Lmemory_start),%d0
+	jcc	1f
+
+	/* Temporary allocate a ptr table and insert it into the root table
+	 */
+	movel	%a1@,%d0
+	addl	#512,%a1@
+	orw	#_PAGE_TABLE+_PAGE_ACCESSED,%d0
+	movel	%d0,%a0@
+	dputs	" (new)"
+1:
+	dputn	%d0
+	/* Mask the root table entry for the ptr table
+	 */
+	andw	#-ROOT_TABLE_SIZE,%d0
+	movel	%d0,%a0
+
+	/* Calculate the offset into the pointer table
+	 */
+	movel	ARG2,%d0
+	moveq	#PTR_INDEX_SHIFT,%d1
+	lsrl	%d1,%d0
+	andl	#PTR_TABLE_SIZE-1,%d0
+	lea	%a0@(%d0*4),%a0
+	dputn	%a0
+
+	/* Check if a temporary page table is already allocated
+	 */
+	movel	%a0@,%d0
+	jne	1f
+
+	/* Temporary allocate a page table and insert it into the ptr table
+	 */
+	movel	%a1@,%d0
+	addl	#512,%a1@
+	orw	#_PAGE_TABLE+_PAGE_ACCESSED,%d0
+	movel	%d0,%a0@
+	dputs	" (new)"
+1:
+	dputn	%d0
+	/* Mask the ptr table entry for the page table
+	 */
+	andw	#-PTR_TABLE_SIZE,%d0
+	movel	%d0,%a0
+
+	/* Calculate the offset into the page table
+	 */
+	movel	ARG2,%d0
+	moveq	#PAGE_INDEX_SHIFT,%d1
+	lsrl	%d1,%d0
+	andl	#PAGE_TABLE_SIZE-1,%d0
+	lea	%a0@(%d0*4),%a0
+	dputn	%a0
+
+	/* Insert the address into the page table
+	 */
+	movel	ARG1,%d0
+	andl	#-PAGESIZE,%d0
+	orw	#_PAGE_PRESENT+_PAGE_ACCESSED,%d0
+	movel	%d0,%a0@
+
+	dputc	'\n'
+
+func_return	mmu_temp_map
+
+func_start	mmu_engage,%d0-%d2/%a0-%a4,8
+
+	moveq	#ROOT_TABLE_SIZE-1,%d0
+	movel	%pc@(.Lkernel_pgdir_ptr),%a0
+	movel	%pc@(.Lmemory_start),%a1
+1:
+	movel	%a0@+,%a1@+
+	dbra	%d0,1b
+
+	lea	%pc@(.Ltemp_mmap_mem),%a0
+	movel	%a1,%a0@
+
+	movew	#PAGESIZE-1,%d0
+1:
+	clrl	%a1@+
+	dbra	%d0,1b
+
+	lea	%pc@(1b),%a0
+	movel	#1b,%a1
+	mmu_temp_map	%a0,%a0
+	mmu_temp_map	%a0,%a1
+
+	addw	#PAGESIZE,%a0
+	addw	#PAGESIZE,%a1
+	mmu_temp_map	%a0,%a0
+	mmu_temp_map	%a0,%a1
+
+	movel	%pc@(.Lkernel_pgdir_ptr),%a2
+	mmu_temp_map	%a2,%a2
+	movel	%pc@(.Lmemory_start),%a3
+	mmu_temp_map	%a3,%a3
+	movel	%pc@(.Lphys_kernel_start),%d2
+
+	is_not_040_or_060(.Lmmu_engage_030)
+
+.Lmmu_engage_040:
+	.chip	68040
+	nop
+	cinva	%bc
+	nop
+	pflusha
+	nop
+	movec	%a2,%srp
+	movel	#TC_ENABLE+TC_PAGE4K,%d0
+	movec	%d0,%tc		/* enable the MMU */
+	.chip	68k
+	jmp	.Lmmu_engage_cleanup
+
+.Lmmu_engage_030:
+	.chip	68030
+	lea	STACK,%a0
+	movel	#0x80000002,%a0@
+	movel	%a2,%a0@(4)
+	movel	#0x0808,%d0
+	movec	%d0,%cacr
+	pmove	%a0@,%srp
+	pmove	%a0@,%crp
+	pflusha
+	/*
+	 * enable,super root enable,4096 byte pages,7 bit root index,
+	 * 7 bit pointer index, 6 bit page table index.
+	 */
+	movel	#0x82c07760,%a1@
+	pmove	%a1@,%tc	/* enable the MMU */
+	.chip	68k
+	jmp	.Lmmu_engage_cleanup
+
+.Lmmu_engage_cleanup:
+	moveq	#ROOT_TABLE_SIZE-1,%d0
+1:
+	movel	%a3@+,%a2@+
+	dbra	%d0,1b
+
+	is_not_040_or_060(1f)
+
+	.chip	68040
+	pflusha
+	nop
+	.chip	68k
+	jbra	2f
+1:
+	.chip	68030
+	pflusha
+	.chip	68k
+2:
+	subl	%d2,%fp
+	subl	%d2,%sp
+	subl	%d2,ARG0
+	subl	%d2,.Lmemory_start
+	clrl	.Lcustom
+
+func_return	mmu_engage
+
+func_start	mmu_get_root_table_entry,%d0/%a1
+
+|	dputs	"mmu_get_root_table_entry:"
+|	dputn	ARG1
+|	dputs	" ="
+
+	movel	%pc@(.Lkernel_pgdir_ptr),%a0
+	tstl	%a0
+	jne	2f
+
+	dputs	" (mmu_init:"
+
+	/* Find the start of free memory, get_bi_record does this for us,
+	 * as the bootinfo structure is located directly behind the kernel
+	 * and and we simply search for the last entry.
+	 */
+	get_bi_record	BI_LAST
+	addw	#PAGESIZE-1,%a0
+	movel	%a0,%d0
+	andw	#-PAGESIZE,%d0
+
+	dputn	%d0
+
+	lea	%pc@(.Lmemory_start),%a0
+	movel	%d0,%a0@
+	lea	%pc@(.Lkernel_end),%a0
+	movel	%d0,%a0@
+
+	/* we have to return the first page at _stext since the init code
+	 * in mm/init.c simply expects kernel_pg_dir there, the rest of
+	 * page is used for further ptr tables in get_ptr_table.
+	 */
+	lea	%pc@(SYMBOL_NAME(_stext)),%a0
+	lea	%pc@(.Lmmu_cached_pointer_tables),%a1
+	movel	%a0,%a1@
+	addl	#ROOT_TABLE_SIZE*4,%a1@
+
+	lea	%pc@(.Lmmu_num_pointer_tables),%a1
+	addql	#1,%a1@
+
+	/* clear the page
+	 */
+	movel	%a0,%a1
+	movew	#PAGESIZE/4-1,%d0
+1:
+	clrl	%a1@+
+	dbra	%d0,1b
+
+	lea	%pc@(.Lkernel_pgdir_ptr),%a1
+	movel	%a0,%a1@
+
+	dputn	%a0
+	dputs	")"
+2:
+	movel	ARG1,%d0
+	lea	%a0@(%d0*4),%a0
+
+|	dputn	%a0
+|	dputc	'\n'
+
+func_return	mmu_get_root_table_entry
+
+
+
+func_start	mmu_get_ptr_table_entry,%d0/%a1
+
+|	dputs	"mmu_get_ptr_table_entry:"
+|	dputn	ARG1
+|	dputn	ARG2
+|	dputs	" ="
+
+	movel	ARG1,%a0
+	movel	%a0@,%d0
+	jne	2f
+
+	/* Keep track of the number of pointer tables we use
+	 */
+	dputs	"(mmu_get_new_ptr_table:"
+	lea	%pc@(.Lmmu_num_pointer_tables),%a0
+	movel	%a0@,%d0
+	addql	#1,%a0@
+
+	/* See if there is a free pointer table in our cache of pointer tables
+	 */
+	lea	%pc@(.Lmmu_cached_pointer_tables),%a1
+	andw	#7,%d0
+	jne	1f
+
+	/* Get a new pointer table page from above the kernel memory
+	 */
+	get_new_page
+	movel	%a0,%a1@
+1:
+	/* There is an unused pointer table in our cache... use it
+	 */
+	movel	%a1@,%d0
+	addl	#PTR_TABLE_SIZE*4,%a1@
+
+	dputn	%d0
+	dputs	")"
+
+	/* Insert the new pointer table into the root table
+	 */
+	movel	ARG1,%a0
+	orw	#_PAGE_TABLE+_PAGE_ACCESSED,%d0
+	movel	%d0,%a0@
+2:
+	/* Extract the pointer table entry
+	 */
+	andw	#-PTR_TABLE_SIZE,%d0
+	movel	%d0,%a0
+	movel	ARG2,%d0
+	lea	%a0@(%d0*4),%a0
+
+|	dputn	%a0
+|	dputc	'\n'
+
+func_return	mmu_get_ptr_table_entry
+
+
+func_start	mmu_get_page_table_entry,%d0/%a1
+
+|	dputs	"mmu_get_page_table_entry:"
+|	dputn	ARG1
+|	dputn	ARG2
+|	dputs	" ="
+
+	movel	ARG1,%a0
+	movel	%a0@,%d0
+	jne	2f
+
+	/* If the page table entry doesn't exist, we allocate a complete new
+	 * page and use it as one continues big page table which can cover
+	 * 4MB of memory, nearly almost all mappings have that alignment.
+	 */
+	get_new_page
+	addw	#_PAGE_TABLE+_PAGE_ACCESSED,%a0
+
+	/* align pointer table entry for a page of page tables
+	 */
+	movel	ARG1,%d0
+	andw	#-(PAGESIZE/PAGE_TABLE_SIZE),%d0
+	movel	%d0,%a1
+
+	/* Insert the page tables into the pointer entries
+	 */
+	moveq	#PAGESIZE/PAGE_TABLE_SIZE/4-1,%d0
+1:
+	movel	%a0,%a1@+
+	lea	%a0@(PAGE_TABLE_SIZE*4),%a0
+	dbra	%d0,1b
+
+	/* Now we can get the initialized pointer table entry
+	 */
+	movel	ARG1,%a0
+	movel	%a0@,%d0
+2:
+	/* Extract the page table entry
+	 */
+	andw	#-PAGE_TABLE_SIZE,%d0
+	movel	%d0,%a0
+	movel	ARG2,%d0
+	lea	%a0@(%d0*4),%a0
+
+|	dputn	%a0
+|	dputc	'\n'
+
+func_return	mmu_get_page_table_entry
+
+/*
+ *	get_new_page
+ *
+ *	Return a new page from the memory start and clear it.
+ */
+func_start	get_new_page,%d0/%a1
+
+	dputs	"(get_new_page:"
+
+	/* allocate the page and adjust memory_start
+	 */
+	lea	%pc@(.Lmemory_start),%a0
+	movel	%a0@,%a1
+	addl	#PAGESIZE,%a0@
+
+	/* clear the new page
+	 */
+	movel	%a1,%a0
+	movew	#PAGESIZE/4-1,%d0
+1:
+	clrl	%a1@+
+	dbra	%d0,1b
+
+	dputn	%a0
+	dputs	")"
+
+func_return	get_new_page
+
+
+
 /*
  * Debug output support
  * Atarians have a choice between the parallel port, the serial port
  * from the MFP or a serial port of the SCC
  */
 
-#ifdef CONFIG_ATARI
+#if defined(CONFIG_MAC)
+
+.Lscc_initable_mac:
+	.byte	9,12		/* Reset */
+	.byte	4,0x44		/* x16, 1 stopbit, no parity */
+	.byte	3,0xc0		/* receiver: 8 bpc */
+	.byte	5,0xe2		/* transmitter: 8 bpc, assert dtr/rts */
+	.byte	9,0		/* no interrupts */
+	.byte	10,0		/* NRZ */
+	.byte	11,0x50		/* use baud rate generator */
+	.byte	12,10,13,0	/* 9600 baud */
+	.byte	14,1		/* Baud rate generator enable */
+	.byte	3,0xc1		/* enable receiver */
+	.byte	5,0xea		/* enable transmitter */
+	.byte	-1
+	.even
+#endif
+
+#if defined(CONFIG_ATARI)
 /* #define USE_PRINTER */
-/* #define USE_SCC */
+/* #define USE_SCC_B */
+/* #define USE_SCC_A */
 #define USE_MFP
+
+#if defined(USE_SCC_A) || defined(USE_SCC_B)
+#define USE_SCC
+/* Initialisation table for SCC */
+.Lscc_initable:
+	.byte	9,12		/* Reset */
+	.byte	4,0x44		/* x16, 1 stopbit, no parity */
+	.byte	3,0xc0		/* receiver: 8 bpc */
+	.byte	5,0xe2		/* transmitter: 8 bpc, assert dtr/rts */
+	.byte	9,0		/* no interrupts */
+	.byte	10,0		/* NRZ */
+	.byte	11,0x50		/* use baud rate generator */
+	.byte	12,24,13,0	/* 9600 baud */
+	.byte	14,2,14,3	/* use master clock for BRG, enable */
+	.byte	3,0xc1		/* enable receiver */
+	.byte	5,0xea		/* enable transmitter */
+	.byte	-1
+	.even
+#endif
 
-#ifdef USE_PRINTER
+#if defined(USE_PRINTER)
 
 LPSG_SELECT	= 0xff8800
 LPSG_READ	= 0xff8800
@@ -1129,13 +2586,18 @@
 LSTMFP_DDR	= 0xfffa05
 LSTMFP_IERB	= 0xfffa09
 
-#elif defined(USE_SCC)
- 
-LSCC_CTRL_B	= 0xff8c85
-LSCC_DATA_B	= 0xff8c87
+#elif defined(USE_SCC_B)
 
+LSCC_CTRL	= 0xff8c85
+LSCC_DATA	= 0xff8c87
+
+#elif defined(USE_SCC_A)
+
+LSCC_CTRL	= 0xff8c81
+LSCC_DATA	= 0xff8c83
+
 /* Initialisation table for SCC */
-scc_initable:
+.Lscc_initable:
 	.byte	9,12		/* Reset */
 	.byte	4,0x44		/* x16, 1 stopbit, no parity */
 	.byte	3,0xc0		/* receiver: 8 bpc */
@@ -1158,46 +2620,49 @@
 LMFP_TSR     = 0xfffa2d
 LMFP_UDR     = 0xfffa2f
 
-#endif
-#endif
-
-#if defined (CONFIG_BVME6000)
-BVME_SCC_CTRL_A = 0xffb0000b
-BVME_SCC_DATA_A = 0xffb0000f
 #endif
+#endif	/* CONFIG_ATARI */
 
 /*
  * Serial port output support.
  */
-LSERPER		= 0xdff032
-LSERDAT		= 0xdff030
-LSERDATR	= 0xdff018
-LSERIAL_CNTRL	= 0xbfd000
-LSERIAL_DTR	= 7
 
 /*
  * Initialize serial port hardware for 9600/8/1
- * a0 thrashed
- * Amiga d0 trashed
- * Atari d0 trashed (a1 in case of SCC)
  */
-	.even
-Lserial_init:
+func_start	serial_init,%d0/%d1/%a0/%a1
+	/*
+	 *	Some of the register usage that follows
+	 *	CONFIG_AMIGA
+	 *		a0 = pointer to boot info record
+	 *		d0 = boot info offset
+	 *	CONFIG_ATARI
+	 *		a0 = address of SCC
+	 *		a1 = Liobase address/address of scc_initable
+	 *		d0 = init data for serial port
+	 *	CONFIG_MAC
+	 *		a0 = address of SCC
+	 *		a1 = address of scc_initable_mac
+	 *		d0 = init data for serial port
+	 */
+
 #ifdef CONFIG_AMIGA
-	cmpil	#MACH_AMIGA,%d4
-	jne	1f
-	bclr	#LSERIAL_DTR,LSERIAL_CNTRL
-	movew	#BI_AMIGA_SERPER,%d0
-	jbsr	Lget_bi_record
-	movew	%a0@,LSERPER
-	jra	9f
+#define SERIAL_DTR	7
+#define SERIAL_CNTRL	CIABBASE+C_PRA
+
+	is_not_amiga(1f)
+	lea	%pc@(.Lcustom),%a0
+	movel	#-ZTWOBASE,%a0@
+	bclr	#SERIAL_DTR,SERIAL_CNTRL-ZTWOBASE
+	get_bi_record	BI_AMIGA_SERPER
+	movew	%a0@,CUSTOMBASE+C_SERPER-ZTWOBASE
+|	movew	#61,CUSTOMBASE+C_SERPER-ZTWOBASE
 1:
 #endif
-#ifdef CONFIG_ATARI
-	cmpil   #MACH_ATARI,%d4
-	jne	4f
-	movel	%pc@(Liobase),%a1
-#ifdef USE_PRINTER
+#if defined(CONFIG_ATARI)
+	is_not_atari(4f)
+	movel	%pc@(.Liobase),%a1
+#if defined(USE_PRINTER)
 	bclr	#0,%a1@(LSTMFP_IERB)
 	bclr	#0,%a1@(LSTMFP_DDR)
 	moveb	#LPSG_CONTROL,%a1@(LPSG_SELECT)
@@ -1209,8 +2674,8 @@
 	bset	#5,%d0
 	moveb	%d0,%a1@(LPSG_WRITE)
 #elif defined(USE_SCC)
-	lea	%a1@(LSCC_CTRL_B),%a0
-	lea	%pc@(scc_initable:w),%a1
+	lea	%a1@(LSCC_CTRL),%a0
+	lea	%pc@(.Lscc_initable),%a1
 2:	moveb	%a1@+,%d0
 	jmi	3f
 	moveb	%d0,%a0@
@@ -1225,174 +2690,857 @@
 	orb	#1,%a1@(LMFP_TDCDR)
 	bset	#1,%a1@(LMFP_TSR)
 #endif
+	jra	.Lserial_init_done
 4:
 #endif
-9:
-	rts
+#if defined(CONFIG_MAC)
+	is_not_mac(.Lserial_init_not_mac)
+#ifdef MAC_SERIAL_DEBUG
+#if !defined(MAC_USE_SCC_A) && !defined(MAC_USE_SCC_B)
+#define MAC_USE_SCC_B
+#endif
+#define mac_scc_cha_b_ctrl_offset	0x0
+#define mac_scc_cha_a_ctrl_offset	0x2
+#define mac_scc_cha_b_data_offset	0x4
+#define mac_scc_cha_a_data_offset	0x6
+
+#ifdef MAC_USE_SCC_A
+	/* Initialize channel A */
+	movel	%pc@(.Lmac_sccbase),%a0
+	lea	%pc@(.Lscc_initable_mac),%a1
+5:	moveb	%a1@+,%d0
+	jmi	6f
+	moveb	%d0,%a0@(mac_scc_cha_a_ctrl_offset)
+	moveb	%a1@+,%a0@(mac_scc_cha_a_ctrl_offset)
+	jra	5b
+6:
+#endif	/* MAC_USE_SCC_A */
+
+#ifdef MAC_USE_SCC_B
+	/* Initialize channel B */
+#ifndef MAC_USE_SCC_A	/* Load mac_sccbase only if needed */
+	movel	%pc@(.Lmac_sccbase),%a0
+#endif	/* MAC_USE_SCC_A */
+	lea	%pc@(.Lscc_initable_mac),%a1
+7:	moveb	%a1@+,%d0
+	jmi	8f
+	moveb	%d0,%a0@(mac_scc_cha_b_ctrl_offset)
+	moveb	%a1@+,%a0@(mac_scc_cha_b_ctrl_offset)
+	jra	7b
+8:
+#endif	/* MAC_USE_SCC_B */
+#endif	/* MAC_SERIAL_DEBUG */
+
+	jra	.Lserial_init_done
+.Lserial_init_not_mac:
+#endif	/* CONFIG_MAC */
+
+.Lserial_init_done:
+func_return	serial_init
 
-#ifdef CONFIG_HP300
-/* Set LEDs to %d7 */
-	.even
-Lset_leds:
-	moveml	%a0/%a1,%sp@-
-	movel	%pc@(Lcustom),%a1
-	moveb	%d7,%a1@(0x1ffff)
-	moveml	%sp@+,%a0/%a1
-	rts
-#endif
-	
 /*
- * Output character in d7 on serial port.
- * d7 thrashed.
+ * Output character on serial port.
  */
-Lserial_putc:
-	moveml	%a0/%a1,%sp@-
-#if defined(CONFIG_MVME16x)
-	cmpil	#MACH_MVME16x,%d4
-	jne	2f
-	moveb	%d7,%sp@-
-	.long	0x4e4f0020
-	jra	9f
-2:
-#endif
-#ifdef CONFIG_BVME6000
-	cmpil	#MACH_BVME6000,%d4
-	jne	2f
-1:	btst	#2,BVME_SCC_CTRL_A
-	jeq	1b
-	moveb	%d7,BVME_SCC_DATA_A
-	jra	9f
-2:
-#endif
-#ifdef CONFIG_AMIGA
-	cmpil	#MACH_AMIGA,%d4
-	jne	2f
-	andw	#0x00ff,%d7
-	oriw	#0x0100,%d7
-	movel	%pc@(Lcustom),%a1
-	movew	%d7,%a1@(LSERDAT)
-1:	movew	%a1@(LSERDATR),%d7
-	andw	#0x2000,%d7
+func_start	serial_putc,%d0/%d1/%a0/%a1
+
+	movel	ARG1,%d0
+	cmpib	#'\n',%d0
+	jbne	1f
+
+	/* A little safe recursion is good for the soul */
+	serial_putc	#'\r'
+1:
+
+#if defined(CONFIG_AMIGA)
+	is_not_amiga(2f)
+	andw	#0x00ff,%d0
+	oriw	#0x0100,%d0
+	movel	%pc@(.Lcustom),%a0
+	movew	%d0,%a0@(CUSTOMBASE+C_SERDAT)
+1:	movew	%a0@(CUSTOMBASE+C_SERDATR),%d0
+	andw	#0x2000,%d0
 	jeq	1b
-	jra	9f
+	jra	.Lserial_putc_done
 2:
 #endif
-#ifdef CONFIG_ATARI
-	cmpil   #MACH_ATARI,%d4
-	jne	4f
-	movel	%pc@(Liobase),%a1
-#ifdef USE_PRINTER
+
+#if defined(CONFIG_MAC)
+	is_not_mac(5f)
+
+#if defined(CONSOLE)
+	console_putc	%d0
+#endif /* CONSOLE */
+
+#if defined(MAC_SERIAL_DEBUG)
+
+#ifdef MAC_USE_SCC_A
+	movel	%pc@(.Lmac_sccbase),%a1
+3:	btst	#2,%a1@(mac_scc_cha_a_ctrl_offset)
+	jeq	3b
+	moveb	%d0,%a1@(mac_scc_cha_a_data_offset)
+#endif	/* MAC_USE_SCC_A */
+
+#ifdef MAC_USE_SCC_B
+#ifndef MAC_USE_SCC_A	/* Load mac_sccbase only if needed */
+	movel	%pc@(.Lmac_sccbase),%a1
+#endif	/* MAC_USE_SCC_A */
+4:	btst	#2,%a1@(mac_scc_cha_b_ctrl_offset)
+	jeq	4b
+	moveb	%d0,%a1@(mac_scc_cha_b_data_offset)
+#endif	/* MAC_USE_SCC_B */
+
+#endif	/* MAC_SERIAL_DEBUG */
+
+	jra	.Lserial_putc_done
+5:
+#endif	/* CONFIG_MAC */
+
+#if defined(CONFIG_ATARI)
+	is_not_atari(4f)
+	movel	%pc@(.Liobase),%a1
+#if defined(USE_PRINTER)
 3:	btst	#0,%a1@(LSTMFP_GPIP)
 	jne	3b
 	moveb	#LPSG_IO_B,%a1@(LPSG_SELECT)
-	moveb	%d7,%a1@(LPSG_WRITE)
+	moveb	%d0,%a1@(LPSG_WRITE)
 	moveb	#LPSG_IO_A,%a1@(LPSG_SELECT)
-	moveb	%a1@(LPSG_READ),%d7
-	bclr	#5,%d7
-	moveb	%d7,%a1@(LPSG_WRITE)
+	moveb	%a1@(LPSG_READ),%d0
+	bclr	#5,%d0
+	moveb	%d0,%a1@(LPSG_WRITE)
 	nop
 	nop
-	bset	#5,%d7
-	moveb	%d7,%a1@(LPSG_WRITE)
+	bset	#5,%d0
+	moveb	%d0,%a1@(LPSG_WRITE)
 #elif defined(USE_SCC)
-3:	btst	#2,%a1@(LSCC_CTRL_B)
+3:	btst	#2,%a1@(LSCC_CTRL)
 	jeq	3b
-	moveb	%d7,%a1@(LSCC_DATA_B)
+	moveb	%d0,%a1@(LSCC_DATA)
 #elif defined(USE_MFP)
 3:	btst	#7,%a1@(LMFP_TSR)
 	jeq	3b
-	moveb	%d7,%a1@(LMFP_UDR)
+	moveb	%d0,%a1@(LMFP_UDR)
 #endif
+	jra	.Lserial_putc_done
 4:
+#endif	/* CONFIG_ATARI */
+
+#if defined(CONFIG_MVME16x)
+	is_not_mvme16x(2f)
+	/*
+	 * The VME 16x class has PROM support for serial output
+	 * of some kind;  the TRAP table is still valid.
+	 */
+	moveml	%d0-%d7/%a2-%a6,%sp@-
+	moveb	%d0,%sp@-
+	.long	0x4e4f0020	/* TRAP 0x020 */
+	moveml	%sp@+,%d0-%d7/%a2-%a6
+	jbra	.Lserial_putc_done
+2:
+#endif CONFIG_MVME162 | CONFIG_MVME167
+
+#if defined(CONFIG_BVME6000)
+	is_not_bvme6000(2f)
+	/*
+	 * The BVME6000 machine has a serial port ...
+	 */
+1:	btst	#2,BVME_SCC_CTRL_A
+	jeq	1b
+	moveb	%d0,BVME_SCC_DATA_A
+	jbra	.Lserial_putc_done
+2:
+#endif
+
+.Lserial_putc_done:
+func_return	serial_putc
+
+/*
+ * Output string to serial port.
+ */
+func_start	serial_puts,%d0/%a0
+
+	movel	ARG1,%a0
+	jra	2f
+1:	serial_putc	%d0
+2:	moveb	%a0@+,%d0
+	jne	1b
+
+func_return	serial_puts
+
+/*
+ * Output number in hex notation on serial port.
+ */
+
+func_start	serial_putnum,%d0-%d2
+
+	serial_putc	#' '
+
+	movel	ARG1,%d0
+	moveq	#7,%d1
+1:	roll	#4,%d0
+	move	%d0,%d2
+	andb	#0x0f,%d2
+	addb	#'0',%d2
+	cmpb	#'9',%d2
+	jls	2f
+	addb	#'A'-('9'+1),%d2
+2:	serial_putc	%d2
+	dbra	%d1,1b
+
+func_return	serial_putnum
+
+#if defined(CONFIG_MAC)
+/*
+ *	mac_serial_print
+ *
+ *	This routine takes its parameters on the stack.  It then
+ *	turns around and calls the internal routine.  This routine
+ *	is used until the Linux console driver initializes itself.
+ *
+ *	The calling parameters are:
+ *		void mac_serial_print(const char *str);
+ *
+ *	This routine does NOT understand variable arguments only
+ *	simple strings!
+ */
+ENTRY(mac_serial_print)
+	movel	%a0,%sp@-
+#if 1
+	move	%sr,%sp@-
+	ori	#0x0700,%sr
+#endif
+	movel	%sp@(10),%a0		/* fetch parameter */
+	serial_puts	%a0
+#if 1
+	move	%sp@+,%sr
 #endif
-9:
-	moveml	%sp@+,%a0/%a1
+	movel	%sp@+,%a0
 	rts
+#endif /* CONFIG_MAC */
 
+#if defined(CONSOLE)
 /*
- * Output string pointed to by a0 to serial port.
- * a0 trashed.
+ *	For continuity, see the data alignment
+ *	to which this structure is tied.
  */
-Lserial_puts:
-	movel	%d7,%sp@-
-1:	moveb	%a0@+,%d7
-	jeq	2f
-	jbsr	Lserial_putc
-	jra	1b
-2:	movel	%sp@+,%d7
+#define Lconsole_struct_cur_column	0
+#define Lconsole_struct_cur_row		4
+#define Lconsole_struct_num_columns	8
+#define Lconsole_struct_num_rows	12
+#define Lconsole_struct_left_edge	16
+#define Lconsole_struct_penguin_putc	20
+
+.Lconsole_init:
+	/*
+	 *	Some of the register usage that follows
+	 *		a0 = pointer to boot_info
+	 *		a1 = pointer to screen
+	 *		a2 = pointer to Lconsole_globals
+	 *		d3 = pixel width of screen
+	 *		d4 = pixel height of screen
+	 *		(d3,d4) ~= (x,y) of a point just below
+	 *			and to the right of the screen
+	 *			NOT on the screen!
+	 *		d5 = number of bytes per scan line
+	 *		d6 = number of bytes on the entire screen
+	 */
+	moveml	%a0-%a4/%d0-%d7,%sp@-
+
+	lea	%pc@(SYMBOL_NAME(.Lconsole_globals)),%a2
+	lea	%pc@(.Lmac_videobase),%a0
+	movel	%a0@,%a1
+	lea	%pc@(.Lmac_rowbytes),%a0
+	movel	%a0@,%d5
+	lea	%pc@(.Lmac_dimensions),%a0
+	movel	%a0@,%d3	/* -> low byte */
+	movel	%d3,%d4
+	swap	%d4		/* -> high byte */
+	andl	#0xffff,%d3	/* d3 = screen width in pixels */
+	andl	#0xffff,%d4	/* d4 = screen height in pixels */
+
+	movel	%d5,%d6
+	subl	#20,%d6
+	mulul	%d4,%d6		/* scan line bytes x num scan lines */
+	divul	#8,%d6		/* we'll clear 8 bytes at a time */
+	subq	#1,%d6
+
+console_clear_loop:
+	movel	#0xffffffff,%a1@+	/* Mac_black */
+	movel	#0xffffffff,%a1@+	/* Mac_black */
+	dbra	%d6,console_clear_loop
+
+	/* Calculate font size */
+
+#if   defined(FONT_8x8)
+	lea	%pc@(SYMBOL_NAME(font_vga_8x8)), %a0
+#elif defined(FONT_8x16)
+	lea	%pc@(SYMBOL_NAME(font_vga_8x16)),%a0
+#elif defined(FONT_6x11)
+	lea	%pc@(SYMBOL_NAME(font_vga_6x11)),%a0
+#else	/*   (FONT_8x8) default */
+	lea	%pc@(SYMBOL_NAME(font_vga_8x8)), %a0
+#endif
+
+	/*
+	 *	At this point we make a shift in register usage
+	 *	a1 = address of Lconsole_font pointer
+	 */
+	lea	%pc@(SYMBOL_NAME(.Lconsole_font)),%a1
+	movel	%a0,%a1@	/* store pointer to struct fbcon_font_desc in Lconsole_font */
+
+	/*
+	 *	Calculate global maxs
+	 *	Note - we can use either an
+	 *	8 x 16 or 8 x 8 character font
+	 *	6 x 11 also supported
+	 */
+		/* ASSERT: a0 = contents of Lconsole_font */
+	movel	%d3,%d0			/* screen width in pixels */
+	divul	%a0@(FBCON_FONT_DESC_width),%d0		/* d0 = max num chars per row */
+
+	movel	%d4,%d1			 /* screen height in pixels */
+	divul	%a0@(FBCON_FONT_DESC_height),%d1	 /* d1 = max num rows */
+
+	movel	%d0,%a2@(Lconsole_struct_num_columns)
+	movel	%d1,%a2@(Lconsole_struct_num_rows)
+
+	/*
+	 *	Clear the current row and column
+	 */
+	clrl	%a2@(Lconsole_struct_cur_column)
+	clrl	%a2@(Lconsole_struct_cur_row)
+	clrl	%a2@(Lconsole_struct_left_edge)
+
+	/*
+	 * Initialization is complete
+	 */
+	moveml	%sp@+,%a0-%a4/%d0-%d7
+	rts
+
+.Lconsole_put_stats:
+	/*
+	 *	Some of the register usage that follows
+	 *		a0 = pointer to boot_info
+	 *		d7 = value of boot_info fields
+	 */
+	moveml	%a0/%d7,%sp@-
+
+	putr()
+	puts("MacLinux")
+	putr()
+	putr()
+
+#if defined(SERIAL_DEBUG)
+	puts(" vidaddr:")
+	lea	%pc@(.Lmac_videobase),%a0
+	movel	%a0@,%d7			/* video addr. */
+	jbsr	.Lserial_putnum			/* This redirects to console */
+	putr()
+
+	puts("  _stext:")
+	lea	%pc@(SYMBOL_NAME(_stext)),%a0
+	movel	%a0,%d7		/* get start addr. */
+	jbsr	.Lserial_putnum
+	putr()
+
+	puts("bootinfo:")
+	lea	%pc@(SYMBOL_NAME(_end)),%a0
+	movel	%a0, %d7	/* write start addr. */
+	jbsr	.Lserial_putnum
+	putr()
+
+	puts("     kpt:")
+	lea	%pc@(SYMBOL_NAME(kpt)),%a0
+	movel	%a0,%d7		/* get start addr. */
+	jbsr	.Lserial_putnum
+	putr()
+
+	puts("    *kpt:")
+	lea	%pc@(SYMBOL_NAME(kpt)),%a0
+	movel	%a0@,%d7	/* get start addr. */
+	jbsr	.Lserial_putnum
+	putr()
+
+	puts("cpuid:")
+	lea	%pc@(SYMBOL_NAME(.Lcputype)),%a0
+	movel	%a0@,%d7
+	jbsr	.Lserial_putnum
+	putr()
+
+#  if defined(MMU_PRINT)
+	jbsr	mmu_print_machine_cpu_types
+#  endif /* MMU_PRINT */
+#endif /* SERIAL_DEBUG */
+
+	moveml	%sp@+,%a0/%d7
+	rts
+
+#ifdef CONSOLE_PENGUIN
+.Lconsole_put_penguin:
+	/*
+	 *	Get 'that_penguin' onto the screen in the upper right corner
+	 *	penguin is 64 x 74 pixels, align against right edge of screen
+	 */
+	moveml	%a0-%a1/%d0-%d7,%sp@-
+
+	lea	%pc@(.Lmac_dimensions),%a0
+	movel	%a0@,%d0
+	andil	#0xffff,%d0
+	subil	#64,%d0		/* snug up against the right edge */
+	clrl	%d1		/* start at the top */
+	movel	#73,%d7
+	lea	%pc@(SYMBOL_NAME(that_penguin)),%a1
+console_penguin_row:
+	movel	#31,%d6
+console_penguin_pixel_pair:
+	moveb	%a1@,%d2
+	lsrb	#4,%d2
+	jbsr	console_plot_pixel
+	addq	#1,%d0
+	moveb	%a1@+,%d2
+	jbsr	console_plot_pixel
+	addq	#1,%d0
+	dbra	%d6,console_penguin_pixel_pair
+
+	subil	#64,%d0
+	addq	#1,%d1
+	dbra	%d7,console_penguin_row
+
+	moveml	%sp@+,%a0-%a1/%d0-%d7
+	rts
+#endif
+
+console_scroll:
+	moveml	%a0-%a4/%d0-%d7,%sp@-
+
+	/*
+	 * Calculate source and destination addresses
+	 *	output	a1 = dest
+	 *		a2 = source
+	 */
+	lea	%pc@(.Lmac_videobase),%a0
+	movel	%a0@,%a1
+	movel	%a1,%a2
+	lea	%pc@(.Lmac_rowbytes),%a0
+	movel	%a0@,%d5
+	movel	%pc@(SYMBOL_NAME(.Lconsole_font)),%a0
+	mulul	%a0@(FBCON_FONT_DESC_height),%d5	/* account for # scan lines per character */
+	addal	%d5,%a2
+
+	/*
+	 * Get dimensions
+	 */
+	lea	%pc@(.Lmac_dimensions),%a0
+	movel	%a0@,%d3
+	movel	%d3,%d4
+	swap	%d4
+	andl	#0xffff,%d3	/* d3 = screen width in pixels */
+	andl	#0xffff,%d4	/* d4 = screen height in pixels */
+
+	/*
+	 * Calculate number of bytes to move
+	 */
+	lea	%pc@(.Lmac_rowbytes),%a0
+	movel	%a0@,%d6
+	movel	%pc@(SYMBOL_NAME(.Lconsole_font)),%a0
+	subl	%a0@(FBCON_FONT_DESC_height),%d4	/* we're not scrolling the top row! */
+	mulul	%d4,%d6		/* scan line bytes x num scan lines */
+	divul	#32,%d6		/* we'll move 8 longs at a time */
+	subq	#1,%d6
+
+console_scroll_loop:
+	movel	%a2@+,%a1@+
+	movel	%a2@+,%a1@+
+	movel	%a2@+,%a1@+
+	movel	%a2@+,%a1@+
+	movel	%a2@+,%a1@+
+	movel	%a2@+,%a1@+
+	movel	%a2@+,%a1@+
+	movel	%a2@+,%a1@+
+	dbra	%d6,console_scroll_loop
+
+	lea	%pc@(.Lmac_rowbytes),%a0
+	movel	%a0@,%d6
+	movel	%pc@(SYMBOL_NAME(.Lconsole_font)),%a0
+	mulul	%a0@(FBCON_FONT_DESC_height),%d6	/* scan line bytes x font height */
+	divul	#32,%d6			/* we'll move 8 words at a time */
+	subq	#1,%d6
+
+	moveq	#-1,%d0
+console_scroll_clear_loop:
+	movel	%d0,%a1@+
+	movel	%d0,%a1@+
+	movel	%d0,%a1@+
+	movel	%d0,%a1@+
+	movel	%d0,%a1@+
+	movel	%d0,%a1@+
+	movel	%d0,%a1@+
+	movel	%d0,%a1@+
+	dbra	%d6,console_scroll_clear_loop
+
+	moveml	%sp@+,%a0-%a4/%d0-%d7
 	rts
 
+
+
+.Lconsole_putc:
 /*
- * Output number in d7 in hex notation on serial port.
+ * Output character in d7 on console.
  */
+	moveml	%a0/%a1/%d0-%d7,%sp@-
 
-Lserial_putnum:
-	moveml	%d0-%d2/%d7,%sp@-
-	movel	%d7,%d1
-	moveq	#4,%d0
-	moveq	#7,%d2
-L1:	roll	%d0,%d1
-	moveb	%d1,%d7
-	andb	#0x0f,%d7
-	cmpb	#0x0a,%d7
-	jcc	1f
-	addb	#'0',%d7
-	jra	2f
-1:	addb	#'A'-10,%d7
-2:	jbsr	Lserial_putc
-	dbra	%d2,L1
-	moveq	#32,%d7
-	jbsr	Lserial_putc
-	moveml	%sp@+,%d0-%d2/%d7
+	lea	%pc@(.Lconsole_globals),%a0
+
+	cmpib	#10,%d7
+	jne	console_not_lf
+	movel	%a0@(Lconsole_struct_cur_row),%d0
+	addil	#1,%d0
+	movel	%d0,%a0@(Lconsole_struct_cur_row)
+	movel	%a0@(Lconsole_struct_num_rows),%d1
+	cmpl	%d1,%d0
+	jcs	1f
+	subil	#1,%d0
+	movel	%d0,%a0@(Lconsole_struct_cur_row)
+	jbsr	console_scroll
+1:
+	jra	console_exit
+
+console_not_lf:
+	cmpib	#13,%d7
+	jne	console_not_cr
+	clrl	%a0@(Lconsole_struct_cur_column)
+	jra	console_exit
+
+console_not_cr:
+	cmpib	#1,%d7
+	jne	console_not_home
+	clrl	%a0@(Lconsole_struct_cur_row)
+	clrl	%a0@(Lconsole_struct_cur_column)
+	jra	console_exit
+
+/*
+ *	At this point we know that the %d7 character is going to be
+ *	rendered on the screen.  Register usage is -
+ *		a0 = pointer to console globals
+ *		a1 = font data
+ *		d0 = cursor column
+ *		d1 = cursor row to draw the character
+ *		d7 = character number
+ */
+console_not_home:
+	movel	%a0@(Lconsole_struct_cur_column),%d0
+	addil	#1,%a0@(.Lconsole_struct_cur_column)
+	movel	%a0@(Lconsole_struct_num_columns),%d1
+	cmpl	%d1,%d0
+	jcs	1f
+	movel	%d7,%sp@-
+	putr()		/* recursion is OK! */
+	movel	%sp@+,%d7
+1:
+	movel	%a0@(Lconsole_struct_cur_row),%d1
+
+	/*
+	 *	At this point we make a shift in register usage
+	 *	a0 = address of pointer to font data (fbcon_font_desc)
+	 */
+	movel	%pc@(SYMBOL_NAME(.Lconsole_font)),%a0
+	movel	%a0@(FBCON_FONT_DESC_data),%a1	/* Load fbcon_font_desc.data into a1 */
+	andl	#0x000000ff,%d7
+		/* ASSERT: a0 = contents of Lconsole_font */
+	mulul	%a0@(FBCON_FONT_DESC_height),%d7	/* d7 = index into font data */
+	addl	%d7,%a1			/* a1 = points to char image */
+
+	/*
+	 *	At this point we make a shift in register usage
+	 *	d0 = pixel coordinate, x
+	 *	d1 = pixel coordinate, y
+	 *	d2 = (bit 0) 1/0 for white/black (!) pixel on screen
+	 *	d3 = font scan line data (8 pixels)
+	 *	d6 = count down for the font's pixel width (8)
+	 *	d7 = count down for the font's pixel count in height
+	 */
+		/* ASSERT: a0 = contents of Lconsole_font */
+	mulul	%a0@(FBCON_FONT_DESC_width),%d0
+	mulul	%a0@(FBCON_FONT_DESC_height),%d1
+	movel	%a0@(FBCON_FONT_DESC_height),%d7	/* Load fbcon_font_desc.height into d7 */
+	subq	#1,%d7
+console_read_char_scanline:
+	moveb	%a1@+,%d3
+
+		/* ASSERT: a0 = contents of Lconsole_font */
+	movel	%a0@(FBCON_FONT_DESC_width),%d6	/* Load fbcon_font_desc.width into d6 */
+	subql	#1,%d6
+
+console_do_font_scanline:
+	lslb	#1,%d3
+	scsb	%d2		/* convert 1 bit into a byte */
+	jbsr	console_plot_pixel
+	addq	#1,%d0
+	dbra	%d6,console_do_font_scanline
+
+		/* ASSERT: a0 = contents of Lconsole_font */
+	subl	%a0@(FBCON_FONT_DESC_width),%d0
+	addq	#1,%d1
+	dbra	%d7,console_read_char_scanline
+
+console_exit:
+	moveml	%sp@+,%a0/%a1/%d0-%d7
+	rts
+
+console_plot_pixel:
+	/*
+	 *	Input:
+	 *		d0 = x coordinate
+	 *		d1 = y coordinate
+	 *		d2 = (bit 0) 1/0 for white/black (!)
+	 *	All registers are preserved
+	 */
+	moveml	%a0-%a1/%d0-%d4,%sp@-
+
+	lea	%pc@(.Lmac_videobase),%a0
+	movel	%a0@,%a1
+	lea	%pc@(.Lmac_videodepth),%a0
+	movel	%a0@,%d3
+	lea	%pc@(.Lmac_rowbytes),%a0
+	mulul	%a0@,%d1
+
+	/*
+	 *	Register usage:
+	 *		d0 = x coord becomes byte offset into frame buffer
+	 *		d1 = y coord
+	 *		d2 = black or white (0/1)
+	 *		d3 = video depth
+	 *		d4 = temp of x (d0) for many bit depths
+	 *		d5 = unused
+	 *		d6 = unused
+	 *		d7 = unused
+	 */
+test_1bit:
+	cmpb	#1,%d3
+	jbne	test_2bit
+	movel	%d0,%d4		/* we need the low order 3 bits! */
+	divul	#8,%d0
+	addal	%d0,%a1
+	addal	%d1,%a1
+	andb	#7,%d4
+	eorb	#7,%d4		/* reverse the x-coordinate w/ screen-bit # */
+	andb	#1,%d2
+	jbne	white_1
+	bsetb	%d4,%a1@
+	jbra	console_plot_pixel_exit
+white_1:
+	bclrb	%d4,%a1@
+	jbra	console_plot_pixel_exit
+
+test_2bit:
+	cmpb	#2,%d3
+	jbne	test_4bit
+	movel	%d0,%d4		/* we need the low order 2 bits! */
+	divul	#4,%d0
+	addal	%d0,%a1
+	addal	%d1,%a1
+	andb	#3,%d4
+	eorb	#3,%d4		/* reverse the x-coordinate w/ screen-bit # */
+	lsll	#1,%d4		/* ! */
+	andb	#1,%d2
+	jbne	white_2
+	bsetb	%d4,%a1@
+	addq	#1,%d4
+	bsetb	%d4,%a1@
+	jbra	console_plot_pixel_exit
+white_2:
+	bclrb	%d4,%a1@
+	addq	#1,%d4
+	bclrb	%d4,%a1@
+	jbra	console_plot_pixel_exit
+
+test_4bit:
+	cmpb	#4,%d3
+	jbne	test_8bit
+	movel	%d0,%d4		/* we need the low order bit! */
+	divul	#2,%d0
+	addal	%d0,%a1
+	addal	%d1,%a1
+	andb	#1,%d4
+	eorb	#1,%d4
+	lsll	#2,%d4		/* ! */
+	andb	#1,%d2
+	jbne	white_4
+	bsetb	%d4,%a1@
+	addq	#1,%d4
+	bsetb	%d4,%a1@
+	addq	#1,%d4
+	bsetb	%d4,%a1@
+	addq	#1,%d4
+	bsetb	%d4,%a1@
+	jbra	console_plot_pixel_exit
+white_4:
+	bclrb	%d4,%a1@
+	addq	#1,%d4
+	bclrb	%d4,%a1@
+	addq	#1,%d4
+	bclrb	%d4,%a1@
+	addq	#1,%d4
+	bclrb	%d4,%a1@
+	jbra	console_plot_pixel_exit
+
+test_8bit:
+	cmpb	#8,%d3
+	jbne	test_16bit
+	addal	%d0,%a1
+	addal	%d1,%a1
+	andb	#1,%d2
+	jbne	white_8
+	moveb	#0xff,%a1@
+	jbra	console_plot_pixel_exit
+white_8:
+	clrb	%a1@
+	jbra	console_plot_pixel_exit
+
+test_16bit:
+	cmpb	#16,%d3
+	jbne	console_plot_pixel_exit
+	addal	%d0,%a1
+	addal	%d0,%a1
+	addal	%d1,%a1
+	andb	#1,%d2
+	jbne	white_16
+	clrw	%a1@
+	jbra	console_plot_pixel_exit
+white_16:
+	movew	#0x0fff,%a1@
+	jbra	console_plot_pixel_exit
+
+console_plot_pixel_exit:
+	moveml	%sp@+,%a0-%a1/%d0-%d4
 	rts
+#endif /* CONSOLE */
 
 #if 0
-Lshowtest:
+/*
+ * This is some old code lying around.  I don't believe
+ * it's used or important anymore.  My guess is it contributed
+ * to getting to this point, but it's done for now.
+ * It was still in the 2.1.77 head.S, so it's still here.
+ * (And still not used!)
+ */
+.Lshowtest:
 	moveml	%a0/%d7,%sp@-
-	putc('A')
-	putc('=')
+	puts("A=")
 	putn(%a1)
 
-	ptestr	#5,%a1@,#7,%a0
+	.long	0xf0119f15		| ptestr	#5,%a1@,#7,%a0
 
-	putc('D')
-	putc('A')
-	putc('=')
+	puts("DA=")
 	putn(%a0)
 
-	putc('D')
-	putc('=')
+	puts("D=")
 	putn(%a0@)
 
-	putc('S')
-	putc('=')
-	lea	%pc@(Lmmu),%a0
-	pmove	%psr,%a0@
+	puts("S=")
+	lea	%pc@(.Lmmu),%a0
+	.long	0xf0106200		| pmove		%psr,%a0@
 	clrl	%d7
 	movew	%a0@,%d7
-	jbsr	Lserial_putnum
+	jbsr	.Lserial_putnum
 
 	putr()
 	moveml	%sp@+,%a0/%d7
 	rts
+#endif	/* 0 */
+
+__INITDATA
+	.align	4
+
+#if defined(CONFIG_ATARI) || defined(CONFIG_AMIGA)
+.Lcustom:
+.Liobase:
+	.long 0
+#endif
+
+#ifdef CONFIG_MAC
+.Lconsole_video_virtual:
+	.long	0
+#endif	/* CONFIG_MAC */
+
+#if defined(CONSOLE)
+.Lconsole_globals:
+	.long	0		/* cursor column */
+	.long	0		/* cursor row */
+	.long	0		/* max num columns */
+	.long	0		/* max num rows */
+	.long	0		/* left edge */
+	.long	0		/* mac putc */
+.Lconsole_font:
+	.long	0		/* pointer to console font (struct fbcon_font_desc) */
+#endif /* CONSOLE */
+
+#if defined(MMU_PRINT)
+.Lmmu_print_data:
+	.long	0		/* valid flag */
+	.long	0		/* start logical */
+	.long	0		/* next logical */
+	.long	0		/* start physical */
+	.long	0		/* next physical */
+#endif /* MMU_PRINT */
+
+.Lcputype:
+	.long	0
+.Lmmu_cached_pointer_tables:
+	.long	0
+.Lmmu_num_pointer_tables:
+	.long	0
+.Lphys_kernel_start:
+	.long	0
+.Lkernel_end:
+	.long	0
+.Lmemory_start:
+	.long	0
+.Lkernel_pgdir_ptr:
+	.long	0
+.Ltemp_mmap_mem:
+	.long	0
+
+
+#if defined (CONFIG_BVME6000)
+BVME_SCC_CTRL_A	= 0xffb0000b
+BVME_SCC_DATA_A	= 0xffb0000f
+#endif
+
+#if 0
+#if defined(CONFIG_ATARI)
+SYMBOL_NAME_LABEL(atari_mch_type)
+	.long	0
+#endif
+#endif
+
+#if defined(CONFIG_MAC)
+SYMBOL_NAME_LABEL(.Lmac_booter_data)
+	.long	0
+SYMBOL_NAME_LABEL(.Lmac_videobase)
+	.long	0
+SYMBOL_NAME_LABEL(.Lmac_videodepth)
+	.long	0
+SYMBOL_NAME_LABEL(.Lmac_dimensions)
+	.long	0
+SYMBOL_NAME_LABEL(.Lmac_rowbytes)
+	.long	0
+#ifdef MAC_SERIAL_DEBUG
+SYMBOL_NAME_LABEL(.Lmac_sccbase)
+	.long	0
+#endif /* MAC_SERIAL_DEBUG */
 #endif
+
+__FINIT
 	.data
-	.even
-Lcustom:
-Liobase:
-	.long 0
-Lmmu:	.quad 0
-SYMBOL_NAME_LABEL(kpt)
-	.long 0
+	.align	4
+
 SYMBOL_NAME_LABEL(availmem)
-	.long 0
+	.long	0
 SYMBOL_NAME_LABEL(m68k_pgtable_cachemode)
-	.long 0
-#ifdef CONFIG_060_WRITETHROUGH
+	.long	0
 SYMBOL_NAME_LABEL(m68k_supervisor_cachemode)
-	.long 0
-#endif
+	.long	0
 #if defined(CONFIG_MVME16x)
 SYMBOL_NAME_LABEL(mvme_bdid_ptr)
-	.long 0
+	.long	0
 #endif
Index: linux-2.1/arch/m68k/kernel/ints.c
diff -u linux-2.1/arch/m68k/kernel/ints.c:1.1.1.1.6.2 linux-2.1/arch/m68k/kernel/ints.c:1.1.1.1.6.2.2.2
--- linux-2.1/arch/m68k/kernel/ints.c:1.1.1.1.6.2	Sat Dec 19 18:51:23 1998
+++ linux-2.1/arch/m68k/kernel/ints.c	Sun Dec 20 19:20:12 1998
@@ -23,10 +23,13 @@
  *           If you want to replace a default handler you should know what
  *           you're doing, since it might handle different other irq sources
  *           which must be served                               /Roman Zippel
+ * 20/12/98: Major update, support for realtime interrupts and manages now
+ *           user vector interrupts too.                        /Roman Zippel
  */
 
 #include <linux/types.h>
 #include <linux/sched.h>
+#include <linux/malloc.h>
 #include <linux/kernel_stat.h>
 #include <linux/errno.h>
 #include <linux/init.h>
@@ -38,24 +41,42 @@
 #include <asm/page.h>
 #include <asm/machdep.h>
 
-/* table for system interrupt handlers */
-static irq_handler_t irq_list[SYS_IRQS];
+#include <config/advanced.h>
+#ifdef CONFIG_ADVANCED
+#include <config/rt/interrupt.h>
+#endif
 
-static const char *default_names[SYS_IRQS] = {
-	"spurious int", "int1 handler", "int2 handler", "int3 handler",
-	"int4 handler", "int5 handler", "int6 handler", "int7 handler"
-};
-
 /* The number of spurious interrupts */
 volatile unsigned int num_spurious;
 
-#define NUM_IRQ_NODES 100
+/* static irq nodes used during bootup */
+#define NUM_IRQ_NODES	16
 static irq_node_t nodes[NUM_IRQ_NODES];
 
-unsigned int local_irq_count[NR_CPUS];
+#ifdef NEED_AUTO_IRQ
+/* table for auto vector interrupt handlers */
+irq_node_t *autoirq_list[AUTO_IRQ_NR];
+#ifdef CONFIG_RT_INTERRUPT
+irq_node_t *autoirq_softlist[AUTO_IRQ_NR];
+#endif
+#endif
+
+#ifdef NEED_USER_IRQ
+/* table for user vector interrupt handlers */
+irq_node_t *userirq_list[USER_IRQ_NR];
+#ifdef CONFIG_RT_INTERRUPT
+irq_node_t *userirq_softlist[USER_IRQ_NR];
+#endif
+#endif
 
+unsigned int local_irq_count[NR_CPUS];
 unsigned int local_bh_count[NR_CPUS];
+unsigned int soft_irq_count;
+#ifdef CONFIG_RT_INTERRUPT
+unsigned int rt_irqrequest;
+#endif
 
+#ifndef NO_MACH_DEFS
 static void dummy_enable_irq(unsigned int irq);
 static void dummy_disable_irq(unsigned int irq);
 static int dummy_request_irq(unsigned int irq,
@@ -66,9 +87,11 @@
 void (*enable_irq) (unsigned int) = dummy_enable_irq;
 void (*disable_irq) (unsigned int) = dummy_disable_irq;
 
+void (*mach_init_IRQ) (void) __initdata;
 int (*mach_request_irq) (unsigned int, void (*)(int, void *, struct pt_regs *),
                       unsigned long, const char *, void *) = dummy_request_irq;
 void (*mach_free_irq) (unsigned int, void *) = dummy_free_irq;
+#endif
 
 /*
  * void init_IRQ(void)
@@ -81,37 +104,128 @@
  * the IRQ handling routines.
  */
 
-__initfunc(void init_IRQ(void))
+void __init init_IRQ(void)
 {
 	int i;
 
-	for (i = 0; i < SYS_IRQS; i++) {
-		if (mach_default_handler)
-			irq_list[i].handler = (*mach_default_handler)[i];
-		irq_list[i].flags   = IRQ_FLG_STD;
-		irq_list[i].dev_id  = NULL;
-		irq_list[i].devname = default_names[i];
-	}
+#ifdef NEED_AUTO_IRQ
+	for (i = 0; i < AUTO_IRQ_NR; i++)
+		autoirq_list[i] = NULL;
+#endif
+
+#ifdef NEED_USER_IRQ
+	for (i = 0; i < USER_IRQ_NR; i++)
+		userirq_list[i] = NULL;
+#endif
 
 	for (i = 0; i < NUM_IRQ_NODES; i++)
 		nodes[i].handler = NULL;
 
-	mach_init_IRQ ();
+	mach_init_IRQ();
 }
 
 irq_node_t *new_irq_node(void)
 {
 	irq_node_t *node;
-	short i;
+	int i;
 
-	for (node = nodes, i = NUM_IRQ_NODES-1; i >= 0; node++, i--)
+	for (node = nodes, i = 0; i < NUM_IRQ_NODES; node++, i--)
 		if (!node->handler)
-			return node;
+			break;
+
+	if (!node)
+		node = kmalloc(sizeof(irq_node_t), GFP_KERNEL);
+
+	if (node) {
+		node->handler = NULL;
+		node->flags = 0;
+	}
+
+	return node;
+}
+
+void free_irq_node(irq_node_t *node)
+{
+	if (node >= &nodes[0] || node < &nodes[NUM_IRQ_NODES])
+		node->handler = NULL;
+	else
+		kfree(node);
+}
+
+static irq_node_t **get_irqlist(unsigned int irq, unsigned long flags)
+{
+	irq_node_t **list = NULL;
 
-	printk ("new_irq_node: out of nodes\n");
-	return NULL;
+#ifdef NEED_AUTO_IRQ
+	if (irq > VEC_SPUR && irq <= VEC_INT7) {
+#ifdef CONFIG_RT_INTERRUPT
+		if (!(flags & IRQ_FLG_REALTIME))
+			list = &autoirq_softlist[irq - VEC_SPUR];
+		else
+#endif
+			list = &autoirq_list[irq - VEC_SPUR];
+	}
+#endif
+
+#ifdef NEED_USER_IRQ
+	if (irq >= VEC_USER && irq <= VEC_USER + USER_IRQ_NR) {
+#ifdef CONFIG_RT_INTERRUPT
+		if (!(flags & IRQ_FLG_REALTIME))
+			list = &userirq_softlist[irq - VEC_USER];
+		else
+#endif
+			list = &userirq_list[irq - VEC_USER];
+	}
+#endif
+
+	return list;
 }
 
+static irq_node_t **find_irqlist(unsigned int irq, void *dev_id)
+{
+	irq_node_t **list = NULL;
+#ifdef CONFIG_RT_INTERRUPT
+	irq_node_t **softlist = NULL;
+#endif
+
+#ifdef NEED_AUTO_IRQ
+	if (irq > VEC_SPUR && irq <= VEC_INT7) {
+		list = &autoirq_list[irq - VEC_SPUR];
+#ifdef CONFIG_RT_INTERRUPT
+		softlist = &autoirq_softlist[irq - VEC_SPUR];
+#endif
+	}
+#endif
+
+#ifdef NEED_USER_IRQ
+	if (irq >= VEC_USER && irq <= VEC_USER + USER_IRQ_NR) {
+		list = &userirq_list[irq - VEC_USER];
+#ifdef CONFIG_RT_INTERRUPT
+		softlist = &userirq_softlist[irq - VEC_USER];
+#endif
+	}
+#endif
+
+	while (list) {
+#ifdef CONFIG_RT_INTERRUPT
+		if (!*list) {
+			if (!(list = softlist))
+				break;
+			softlist = NULL;
+		}
+#endif
+		if (!*list)
+			return NULL;
+
+		if ((*list)->dev_id == dev_id)
+			break;
+
+		list = &(*list)->next;
+	}
+
+	return list;
+}
+
 /*
  * We will keep these functions until I have convinced Linus to move
  * the declaration of them from include/linux/sched.h to
@@ -133,46 +247,130 @@
                     void (*handler)(int, void *, struct pt_regs *), 
                     unsigned long flags, const char *devname, void *dev_id)
 {
-	if (irq < IRQ1 || irq > IRQ7) {
-		printk("%s: Incorrect IRQ %d from %s\n",
-		       __FUNCTION__, irq, devname);
-		return -ENXIO;
-	}
+	irq_node_t **list;
+	irq_node_t *node;
 
-	if (!(irq_list[irq].flags & IRQ_FLG_STD)) {
-		if (irq_list[irq].flags & IRQ_FLG_LOCK) {
-			printk("%s: IRQ %d from %s is not replaceable\n",
-			       __FUNCTION__, irq, irq_list[irq].devname);
+	list = find_irqlist(irq, dev_id);
+	if (list) {
+		if (!(flags & IRQ_FLG_REPLACE)) {
+			printk("%s: %s can't replace IRQ %x from %s\n",
+			       __FUNCTION__, devname, irq, (*list)->devname);
+			return -EBUSY;
+		}
+		if ((*list)->flags & IRQ_FLG_LOCK) {
+			printk("%s: IRQ %x from %s is not replaceable\n",
+			       __FUNCTION__, irq, (*list)->devname);
 			return -EBUSY;
 		}
+
+		node = *list;
+		*list = NULL;
+
+		list = get_irqlist(irq, flags);
+	} else {
+		list = get_irqlist(irq, flags);
+		if (!list) {
+			printk("%s: Incorrect IRQ %x from %s\n",
+			       __FUNCTION__, irq, devname);
+			return -ENXIO;
+		}
+
+		if (*list) {
+			printk("%s: IRQ %x is busy\n", __FUNCTION__, irq);
+			return -EBUSY;
+		}
+
+		node = new_irq_node();
+		if (!node)
+			return -ENOMEM;
+	}
+
+	node->handler = handler;
+	node->flags   = flags;
+	node->dev_id  = dev_id;
+	node->devname = devname;
+	node->next    = NULL;
+	*list = node;
+
+	return 0;
+}
+
+int sys_request_listirq(unsigned int irq, 
+                        void (*handler)(int, void *, struct pt_regs *), 
+                        unsigned long flags, const char *devname, void *dev_id)
+{
+	irq_node_t **list;
+	irq_node_t *node;
+
+
+	list = find_irqlist(irq, dev_id);
+	if (list) {
 		if (!(flags & IRQ_FLG_REPLACE)) {
-			printk("%s: %s can't replace IRQ %d from %s\n",
-			       __FUNCTION__, devname, irq, irq_list[irq].devname);
+			printk("%s: %s can't replace IRQ %x from %s\n",
+			       __FUNCTION__, devname, irq, (*list)->devname);
+			return -EBUSY;
+		}
+		if ((*list)->flags & IRQ_FLG_LOCK) {
+			printk("%s: IRQ %x from %s is not replaceable\n",
+			       __FUNCTION__, irq, (*list)->devname);
 			return -EBUSY;
 		}
+
+		node = *list;
+		*list = node->next;
+
+		list = get_irqlist(irq, flags);
+	} else {
+		list = get_irqlist(irq, flags);
+		if (!list) {
+			printk("%s: Incorrect IRQ %x from %s\n",
+			       __FUNCTION__, irq, devname);
+			return -ENXIO;
+		}
+
+		node = new_irq_node();
+		if (!node)
+			return -ENOMEM;
 	}
-	irq_list[irq].handler = handler;
-	irq_list[irq].flags   = flags;
-	irq_list[irq].dev_id  = dev_id;
-	irq_list[irq].devname = devname;
+
+	node->handler = handler;
+	node->flags   = flags;
+	node->dev_id  = dev_id;
+	node->devname = devname;
+
+	if (node->flags & IRQ_FLG_FAST) {
+		node->flags &= ~IRQ_FLG_SLOW;
+		while (*list && (*list)->flags & IRQ_FLG_FAST)
+			list = &(*list)->next;
+	} else if (node->flags & IRQ_FLG_SLOW) {
+		while (*list)
+			list = &(*list)->next;
+	} else {
+		while (*list && !((*list)->flags & IRQ_FLG_SLOW))
+			list = &(*list)->next;
+	}
+
+	node->next = (*list) ? (*list)->next : NULL;
+	*list = node;
+
 	return 0;
 }
 
 void sys_free_irq(unsigned int irq, void *dev_id)
 {
-	if (irq < IRQ1 || irq > IRQ7) {
-		printk("%s: Incorrect IRQ %d\n", __FUNCTION__, irq);
+	irq_node_t **list;
+	irq_node_t *node;
+
+	list = find_irqlist(irq, dev_id);
+	if (!list) {
+		printk("%s: No handler with id 0x%p found for IRQ %x\n",
+		       __FUNCTION__, dev_id, irq);
 		return;
 	}
 
-	if (irq_list[irq].dev_id != dev_id)
-		printk("%s: Removing probably wrong IRQ %d from %s\n",
-		       __FUNCTION__, irq, irq_list[irq].devname);
-
-	irq_list[irq].handler = (*mach_default_handler)[irq];
-	irq_list[irq].flags   = IRQ_FLG_STD;
-	irq_list[irq].dev_id  = NULL;
-	irq_list[irq].devname = default_names[irq];
+	node = *list;
+	*list = node->next;
+	free_irq_node(node);
 }
 
 /*
@@ -188,6 +386,7 @@
 	return 0;
 }
 
+#ifndef NO_MACH_DEFS
 static void dummy_enable_irq(unsigned int irq)
 {
 	printk("calling uninitialized enable_irq()\n");
@@ -210,39 +409,85 @@
 {
 	printk("calling uninitialized disable_irq()\n");
 }
+#endif
 
-asmlinkage void process_int(unsigned long vec, struct pt_regs *fp)
-{
-	if (vec >= VEC_INT1 && vec <= VEC_INT7 && !MACH_IS_BVME6000) {
-		vec -= VEC_SPUR;
-		kstat.irqs[0][vec]++;
-		irq_list[vec].handler(vec, irq_list[vec].dev_id, fp);
-	} else {
-		if (mach_process_int)
-			mach_process_int(vec, fp);
-		else
-			panic("Can't process interrupt vector %ld\n", vec);
-		return;
-	}
-}
-
 int get_irq_list(char *buf)
 {
-	int i, len = 0;
-
+	irq_node_t **list;
+	irq_node_t **softlist;
+	int i, len;
+
+	len = sprintf(buf, "auto %2x: %10u     spurious int\n",
+	              0, num_spurious);
+	
+#ifdef NEED_AUTO_IRQ
 	/* autovector interrupts */
-	if (mach_default_handler) {
-		for (i = 0; i < SYS_IRQS; i++) {
-			len += sprintf(buf+len, "auto %2d: %10u ", i,
-			               i ? kstat.irqs[0][i] : num_spurious);
-			if (irq_list[i].flags & IRQ_FLG_LOCK)
-				len += sprintf(buf+len, "L ");
-			else
-				len += sprintf(buf+len, "  ");
-			len += sprintf(buf+len, "%s\n", irq_list[i].devname);
+	for (i = 1; i < AUTO_IRQ_NR; i++) {
+		list = &autoirq_list[i];
+		softlist = &autoirq_softlist[i];
+		if (!*list && !*softlist)
+			continue;
+		len += sprintf(buf+len, "auto %2x: %10u ",
+		               i, kstat.irqs[0][i]);
+		if (!*list) {
+			list = softlist;
+			softlist = NULL;
+		}
+		while (1) {
+			len += sprintf(buf+len, "%c%c%c %s\n",
+			               (*list)->flags & IRQ_FLG_REALTIME ? 'R' : ' ',
+				       (*list)->flags & IRQ_FLG_LOCK ? 'L' : ' ',
+				       (*list)->flags & IRQ_FLG_FAST ? 'F' :
+				       ((*list)->flags & IRQ_FLG_SLOW ? 'S' : ' '),
+				       (*list)->devname);
+			list = &(*list)->next;
+			if (!*list) {
+				if (!(list = softlist))
+					break;
+				softlist = NULL;
+			}
+			if (!*list)
+				break;
+			len += sprintf(buf+len, "                    ");
 		}
 	}
+#endif
+
+#ifdef NEED_USER_IRQ
+	/* uservector interrupts */
+	for (i = 0; i < USER_IRQ_NR; i++) {
+		list = &userirq_list[i];
+		softlist = &userirq_softlist[i];
+		if (!*list && !*softlist)
+			continue;
+		len += sprintf(buf+len, "user %2x: %10u ",
+		               i, kstat.irqs[0][AUTO_IRQ_NR+i]);
+		if (!*list) {
+			list = softlist;
+			softlist = NULL;
+		}
+		while (1) {
+			len += sprintf(buf+len, "%c%c%c %s\n",
+			               (*list)->flags & IRQ_FLG_REALTIME ? 'R' : ' ',
+				       (*list)->flags & IRQ_FLG_LOCK ? 'L' : ' ',
+				       (*list)->flags & IRQ_FLG_FAST ? 'F' :
+				       ((*list)->flags & IRQ_FLG_SLOW ? 'S' : ' '),
+				       (*list)->devname);
+			list = &(*list)->next;
+			if (!*list) {
+				if (!(list = softlist))
+					break;
+				softlist = NULL;
+			}
+			if (!*list)
+				break;
+			len += sprintf(buf+len, "                    ");
+		}
+	}
+#endif
+
+	if (mach_get_irq_list)
+		len += mach_get_irq_list(buf+len);
 
-	len += mach_get_irq_list(buf+len);
 	return len;
 }
Index: linux-2.1/arch/m68k/kernel/m68k_defs.c
diff -u linux-2.1/arch/m68k/kernel/m68k_defs.c:1.1.1.1.6.3 linux-2.1/arch/m68k/kernel/m68k_defs.c:1.1.1.1.6.3.2.1
--- linux-2.1/arch/m68k/kernel/m68k_defs.c:1.1.1.1.6.3	Sat Dec 19 18:51:24 1998
+++ linux-2.1/arch/m68k/kernel/m68k_defs.c	Sat Dec 19 21:28:20 1998
@@ -10,14 +10,59 @@
 
 #include <linux/stddef.h>
 #include <linux/sched.h>
+#include <linux/kernel_stat.h>
+#include <asm/irq.h>
+#include <asm/amigahw.h>
+#include <config/amiga.h>
 
 #define DEFINE(sym, val) \
 	asm volatile("\n#define " #sym " %c0" : : "i" (val))
 
 int main(void)
 {
-	DEFINE(TS_TSS, offsetof(struct task_struct, tss));
-	DEFINE(TS_ESP0, offsetof(struct task_struct, tss.esp0));
-	DEFINE(TS_FPU, offsetof(struct task_struct, tss.fp));
+	/* offsets into the task struct */
+	DEFINE(TASK_STATE, offsetof(struct task_struct, state));
+	DEFINE(TASK_FLAGS, offsetof(struct task_struct, flags));
+	DEFINE(TASK_SIGPENDING, offsetof(struct task_struct, sigpending));
+	DEFINE(TASK_NEEDRESCHED, offsetof(struct task_struct, need_resched));
+	DEFINE(TASK_TSS, offsetof(struct task_struct, tss));
+	DEFINE(TASK_MM, offsetof(struct task_struct, mm));
+	/* offsets into the thread struct */
+	DEFINE(TSS_KSP, offsetof(struct thread_struct, ksp));
+	DEFINE(TSS_USP, offsetof(struct thread_struct, usp));
+	DEFINE(TSS_SR, offsetof(struct thread_struct, sr));
+	DEFINE(TSS_FS, offsetof(struct thread_struct, fs));
+	DEFINE(TSS_CRP, offsetof(struct thread_struct, crp));
+	DEFINE(TSS_ESP0, offsetof(struct thread_struct, esp0));
+	DEFINE(TSS_FPREG, offsetof(struct thread_struct, fp));
+	DEFINE(TSS_FPCNTL, offsetof(struct thread_struct, fpcntl));
+	DEFINE(TSS_FPSTATE, offsetof(struct thread_struct, fpstate));
+	/* offsets into the pt_regs */
+	DEFINE(PT_D0, offsetof(struct pt_regs, d0));
+	DEFINE(PT_ORIG_D0, offsetof(struct pt_regs, orig_d0));
+	DEFINE(PT_SR, offsetof(struct pt_regs, sr));
+	/* bitfields are a bit difficult */
+	DEFINE(PT_VECTOR, offsetof(struct pt_regs, pc) + 4);
+	/* offsets into the irq_handler struct */
+	DEFINE(IRQ_HANDLER, offsetof(struct irq_node, handler));
+	DEFINE(IRQ_DEVID, offsetof(struct irq_node, dev_id));
+	DEFINE(IRQ_NEXT, offsetof(struct irq_node, next));
+	/* offsets into the kernel_stat struct */
+	DEFINE(STAT_IRQ, offsetof(struct kernel_stat, irqs));
+#ifdef CONFIG_AMIGA
+	/* offsets into the custom struct */
+	DEFINE(CUSTOMBASE, &custom);
+	DEFINE(C_INTENAR, offsetof(struct CUSTOM, intenar));
+	DEFINE(C_INTREQR, offsetof(struct CUSTOM, intreqr));
+	DEFINE(C_INTENA, offsetof(struct CUSTOM, intena));
+	DEFINE(C_INTREQ, offsetof(struct CUSTOM, intreq));
+	DEFINE(C_SERDATR, offsetof(struct CUSTOM, serdatr));
+	DEFINE(C_SERDAT, offsetof(struct CUSTOM, serdat));
+	DEFINE(C_SERPER, offsetof(struct CUSTOM, serper));
+	DEFINE(CIAABASE, &ciaa);
+	DEFINE(CIABBASE, &ciab);
+	DEFINE(C_PRA, offsetof(struct CIA, pra));
+	DEFINE(ZTWOBASE, zTwoBase);
+#endif /* CONFIG_AMIGA */
 	return 0;
 }
Index: linux-2.1/arch/m68k/kernel/m68k_defs.h
diff -u linux-2.1/arch/m68k/kernel/m68k_defs.h:1.1.1.4.4.2 linux-2.1/arch/m68k/kernel/m68k_defs.h:removed
--- linux-2.1/arch/m68k/kernel/m68k_defs.h:1.1.1.4.4.2	Sat Dec 19 18:51:25 1998
+++ linux-2.1/arch/m68k/kernel/m68k_defs.h	Sun Dec 20 19:20:51 1998
@@ -1,8 +0,0 @@
-/*
- * WARNING! This file is automatically generated - DO NOT EDIT!
- */
-
-#define TS_MAGICKEY	0x5a5a5a5a
-#define TS_TSS 478
-#define TS_ESP0 498
-#define TS_FPU 502
Index: linux-2.1/arch/m68k/kernel/m68k_ksyms.c
diff -u linux-2.1/arch/m68k/kernel/m68k_ksyms.c:1.1.1.3.6.3 linux-2.1/arch/m68k/kernel/m68k_ksyms.c:1.1.1.3.6.3.2.1
--- linux-2.1/arch/m68k/kernel/m68k_ksyms.c:1.1.1.3.6.3	Sat Dec 19 18:51:26 1998
+++ linux-2.1/arch/m68k/kernel/m68k_ksyms.c	Sat Dec 19 21:28:21 1998
@@ -7,7 +7,6 @@
 #include <linux/elfcore.h>
 #include <linux/in6.h>
 #include <linux/interrupt.h>
-#include <linux/config.h>
 
 #include <asm/setup.h>
 #include <asm/machdep.h>
@@ -18,6 +17,12 @@
 #include <asm/hardirq.h>
 #include <asm/softirq.h>
 
+#include <config/advanced.h>
+#ifdef CONFIG_ADVANCED
+#include <config/single/memory/chunk.h>
+#include <config/rt/interrupt.h>
+#endif
+
 asmlinkage long long __ashrdi3 (long long, int);
 extern char m68k_debug_device[];
 
@@ -50,6 +55,9 @@
 EXPORT_SYMBOL(enable_irq);
 EXPORT_SYMBOL(disable_irq);
 EXPORT_SYMBOL(kernel_set_cachemode);
+#ifdef CONFIG_RT_INTERRUPT
+EXPORT_SYMBOL(soft_irq_count);
+#endif
 
 /* Networking helper routines. */
 EXPORT_SYMBOL(csum_partial_copy);
Index: linux-2.1/arch/m68k/kernel/process.c
diff -u linux-2.1/arch/m68k/kernel/process.c:1.1.1.5.6.2 linux-2.1/arch/m68k/kernel/process.c:1.1.1.5.6.2.2.1
--- linux-2.1/arch/m68k/kernel/process.c:1.1.1.5.6.2	Sat Dec 19 18:51:27 1998
+++ linux-2.1/arch/m68k/kernel/process.c	Sat Dec 19 21:28:22 1998
@@ -120,9 +120,10 @@
 	unsigned long zero = 0;
 	set_fs(USER_DS);
 	current->tss.fs = __USER_DS;
-	asm volatile (".chip 68k/68881\n\t"
-		      "frestore %0@\n\t"
-		      ".chip 68k" : : "a" (&zero));
+	if (!FPU_IS_EMU)
+		asm volatile (".chip 68k/68881\n\t"
+			      "frestore %0@\n\t"
+			      ".chip 68k" : : "a" (&zero));
 }
 
 /*
@@ -178,17 +179,19 @@
 	 */
 	p->tss.fs = get_fs().seg;
 
-	/* Copy the current fpu state */
-	asm volatile ("fsave %0" : : "m" (p->tss.fpstate[0]) : "memory");
+	if (!FPU_IS_EMU) {
+		/* Copy the current fpu state */
+		asm volatile ("fsave %0" : : "m" (p->tss.fpstate[0]) : "memory");
+
+		if (!CPU_IS_060 ? p->tss.fpstate[0] : p->tss.fpstate[2])
+		  asm volatile ("fmovemx %/fp0-%/fp7,%0\n\t"
+				"fmoveml %/fpiar/%/fpcr/%/fpsr,%1"
+				: : "m" (p->tss.fp[0]), "m" (p->tss.fpcntl[0])
+				: "memory");
+		/* Restore the state in case the fpu was busy */
+		asm volatile ("frestore %0" : : "m" (p->tss.fpstate[0]));
+	}
 
-	if (!CPU_IS_060 ? p->tss.fpstate[0] : p->tss.fpstate[2])
-	  asm volatile ("fmovemx %/fp0-%/fp7,%0\n\t"
-			"fmoveml %/fpiar/%/fpcr/%/fpsr,%1"
-			: : "m" (p->tss.fp[0]), "m" (p->tss.fpcntl[0])
-			: "memory");
-	/* Restore the state in case the fpu was busy */
-	asm volatile ("frestore %0" : : "m" (p->tss.fpstate[0]));
-
 	return 0;
 }
 
@@ -197,6 +200,9 @@
 int dump_fpu (struct pt_regs *regs, struct user_m68kfp_struct *fpu)
 {
   char fpustate[216];
+
+  if (FPU_IS_EMU)
+     return 1;
 
   /* First dump the fpu context to avoid protocol violation.  */
   asm volatile ("fsave %0" :: "m" (fpustate[0]) : "memory");
Index: linux-2.1/arch/m68k/kernel/setup.c
diff -u linux-2.1/arch/m68k/kernel/setup.c:1.1.1.3.6.2 linux-2.1/arch/m68k/kernel/setup.c:1.1.1.3.6.2.2.1
--- linux-2.1/arch/m68k/kernel/setup.c:1.1.1.3.6.2	Sat Dec 19 18:51:28 1998
+++ linux-2.1/arch/m68k/kernel/setup.c	Sat Dec 19 21:28:23 1998
@@ -57,16 +57,13 @@
 
 char m68k_debug_device[6] = "";
 
+#ifndef NO_MACH_DEFS
 void (*mach_sched_init) (void (*handler)(int, void *, struct pt_regs *)) __initdata;
 /* machine dependent keyboard functions */
 int (*mach_keyb_init) (void) __initdata;
 int (*mach_kbdrate) (struct kbd_repeat *) = NULL;
+#endif
 void (*mach_kbd_leds) (unsigned int) = NULL;
-/* machine dependent "kbd-reset" setup function */
-void (*kbd_reset_setup) (char *, int) __initdata = NULL;
-/* machine dependent irq functions */
-void (*mach_init_IRQ) (void) __initdata;
-void (*(*mach_default_handler)[]) (int, void *, struct pt_regs *) = NULL;
 void (*mach_get_model) (char *model) = NULL;
 int (*mach_get_hardware_list) (char *buffer) = NULL;
 int (*mach_get_irq_list) (char *) = NULL;
@@ -111,7 +108,7 @@
 #define MASK_256K 0xfffc0000
 
 
-__initfunc(static void m68k_parse_bootinfo(const struct bi_record *record))
+static void __init m68k_parse_bootinfo(const struct bi_record *record)
 {
     while (record->tag != BI_LAST) {
 	int unknown = 0;
@@ -168,8 +165,8 @@
 #endif
 }
 
-__initfunc(void setup_arch(char **cmdline_p, unsigned long * memory_start_p,
-			   unsigned long * memory_end_p))
+void __init setup_arch(char **cmdline_p, unsigned long * memory_start_p,
+		       unsigned long * memory_end_p)
 {
 	extern int _etext, _edata, _end;
 	int i;
@@ -220,6 +217,17 @@
 		i = 1;
 	    }
 #endif
+#ifdef CONFIG_AMIGA
+	    if (!strncmp( p, "timer=", 6 )) {
+		extern int amiga_cia_timer;
+
+		if (!strncmp( p+6, "ciaa", 4))
+		    amiga_cia_timer = 0;
+		else if (!strncmp( p+6, "ciab", 4))
+		    amiga_cia_timer = 1;
+		i = 1;
+	    }
+#endif
 
 	    if (i) {
 		/* option processed, delete it */
@@ -385,7 +393,7 @@
 }
 
 #if defined(CONFIG_AMIGA_FLOPPY) || defined(CONFIG_ATARI_FLOPPY)
-__initfunc(void floppy_setup(char *str, int *ints))
+void __init floppy_setup(char *str, int *ints)
 {
 	if (mach_floppy_setup)
 		mach_floppy_setup (str, ints);
@@ -398,9 +406,9 @@
 }
 #endif
 
-__initfunc(unsigned long arch_kbd_init(void))
+/* for "kbd-reset" cmdline param */
+void __init kbd_reset_setup(char *str, int *ints)
 {
-	return mach_keyb_init();
 }
 
 void arch_gettod(int *year, int *mon, int *day, int *hour,
Index: linux-2.1/arch/m68k/kernel/signal.c
diff -u linux-2.1/arch/m68k/kernel/signal.c:1.1.1.3.6.2 linux-2.1/arch/m68k/kernel/signal.c:1.1.1.3.6.2.2.1
--- linux-2.1/arch/m68k/kernel/signal.c:1.1.1.3.6.2	Sat Dec 19 18:51:29 1998
+++ linux-2.1/arch/m68k/kernel/signal.c	Sat Dec 19 21:28:24 1998
@@ -187,6 +187,20 @@
 {
 	int err = 1;
 
+	if (FPU_IS_EMU) {
+		/* restore state */
+		current->tss.fpcntl[0] = sc->sc_fpcntl[0];
+		current->tss.fpcntl[1] = sc->sc_fpcntl[1];
+		current->tss.fpcntl[2] = sc->sc_fpcntl[2];
+		current->tss.fp[0] = sc->sc_fpregs[0];
+		current->tss.fp[1] = sc->sc_fpregs[1];
+		current->tss.fp[2] = sc->sc_fpregs[2];
+		current->tss.fp[3] = sc->sc_fpregs[3];
+		current->tss.fp[4] = sc->sc_fpregs[4];
+		current->tss.fp[5] = sc->sc_fpregs[5];
+		return 0;
+	}
+
 	if (CPU_IS_060 ? sc->sc_fpstate[2] : sc->sc_fpstate[0]) {
 	    /* Verify the frame format.  */
 	    if (!CPU_IS_060 && (sc->sc_fpstate[0] != fpu_version))
@@ -239,6 +253,18 @@
 	fpregset_t fpregs;
 	int err = 1;
 
+	if (FPU_IS_EMU) {
+		/* restore fpu control register */
+		if (__copy_from_user(current->tss.fpcntl,
+				&uc->uc_mcontext.fpregs.f_pcr, 12))
+			goto out;
+		/* restore all other fpu register */
+		if (__copy_from_user(current->tss.fp,
+				uc->uc_mcontext.fpregs.f_fpregs, 96))
+			goto out;
+		return 0;
+	}
+
 	if (__get_user(*(long *)fpstate, (long *)&uc->uc_fpstate))
 		goto out;
 	if (CPU_IS_060 ? fpstate[2] : fpstate[0]) {
@@ -536,6 +562,20 @@
 
 static inline void save_fpu_state(struct sigcontext *sc, struct pt_regs *regs)
 {
+	if (FPU_IS_EMU) {
+		/* save state */
+		sc->sc_fpcntl[0] = current->tss.fpcntl[0];
+		sc->sc_fpcntl[1] = current->tss.fpcntl[1];
+		sc->sc_fpcntl[2] = current->tss.fpcntl[2];
+		sc->sc_fpregs[0] = current->tss.fp[0];
+		sc->sc_fpregs[1] = current->tss.fp[1];
+		sc->sc_fpregs[2] = current->tss.fp[2];
+		sc->sc_fpregs[3] = current->tss.fp[3];
+		sc->sc_fpregs[4] = current->tss.fp[4];
+		sc->sc_fpregs[5] = current->tss.fp[5];
+		return;
+	}
+
 	__asm__ volatile (".chip 68k/68881\n\t"
 			  "fsave %0\n\t"
 			  ".chip 68k"
@@ -566,6 +606,16 @@
 	unsigned char fpstate[FPCONTEXT_SIZE];
 	int context_size = CPU_IS_060 ? 8 : 0;
 	int err = 0;
+
+	if (FPU_IS_EMU) {
+		/* save fpu control register */
+		err |= copy_to_user(&uc->uc_mcontext.fpregs.f_pcr,
+				current->tss.fpcntl, 12);
+		/* save all other fpu register */
+		err |= copy_to_user(uc->uc_mcontext.fpregs.f_fpregs,
+				current->tss.fp, 96);
+		return err;
+	}
 
 	__asm__ volatile (".chip 68k/68881\n\t"
 			  "fsave %0\n\t"
Index: linux-2.1/arch/m68k/kernel/traps.c
diff -u linux-2.1/arch/m68k/kernel/traps.c:1.1.1.2.6.2 linux-2.1/arch/m68k/kernel/traps.c:1.1.1.2.6.2.2.1
--- linux-2.1/arch/m68k/kernel/traps.c:1.1.1.2.6.2	Sat Dec 19 18:51:30 1998
+++ linux-2.1/arch/m68k/kernel/traps.c	Sat Dec 19 21:28:25 1998
@@ -37,6 +37,7 @@
 #include <asm/pgtable.h>
 #include <asm/machdep.h>
 #include <asm/siginfo.h>
+#include <asm/irq.h>
 #ifdef CONFIG_KGDB
 #include <asm/kgdb.h>
 #endif
@@ -52,19 +53,14 @@
 	0, 0, buserr, trap, trap, trap, trap, trap,
 	trap, trap, trap, trap, trap, trap, trap, trap,
 	trap, trap, trap, trap, trap, trap, trap, trap,
-	inthandler, inthandler, inthandler, inthandler,
-	inthandler, inthandler, inthandler, inthandler,
+	bad_interrupt, bad_interrupt, bad_interrupt, bad_interrupt,
+	bad_interrupt, bad_interrupt, bad_interrupt, bad_interrupt,
 	/* TRAP #0-15 */
 	system_call, trap, trap, trap, trap, trap, trap, trap,
 	trap, trap, trap, trap, trap, trap, trap, trap,
 	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 };
 
-/* nmi handler for the Amiga */
-asm(".text\n"
-    __ALIGN_STR "\n"
-    SYMBOL_NAME_STR(nmihandler) ": rte");
-
 __initfunc(void base_trap_init(void))
 {
 	/* setup the exception vector table */
@@ -131,18 +127,7 @@
 			vectors[i] = trap;
 
 	for (i = 64; i < 256; i++)
-		vectors[i] = inthandler;
-
-        /* if running on an amiga, make the NMI interrupt do nothing */
-	if (MACH_IS_AMIGA) {
-		vectors[VEC_INT7] = nmihandler;
-	}
-}
-
-void set_evector(int vecnum, void (*handler)(void))
-{
-	if (vecnum >= 0 && vecnum <= 256)
-		vectors[vecnum] = handler;
+		vectors[i] = bad_interrupt;
 }
 
 
@@ -695,7 +680,7 @@
 	enter_kgdb( &fp->ptregs );
 #else
 	unsigned long *stack, *endstack, addr, module_start, module_end;
-	extern char _start, _etext;
+	extern char _stext, _etext;
 	int i;
 
 	addr = (unsigned long)&fp->un;
@@ -778,7 +763,7 @@
 		 * down the cause of the crash will be able to figure
 		 * out the call path that was taken.
 		 */
-		if (((addr >= (unsigned long) &_start) &&
+		if (((addr >= (unsigned long) &_stext) &&
 		     (addr <= (unsigned long) &_etext)) ||
 		    ((addr >= module_start) && (addr <= module_end))) {
 			if (i % 4 == 0)
Index: linux-2.1/arch/m68k/mac/config.c
diff -u linux-2.1/arch/m68k/mac/config.c:1.1.1.4.6.3 linux-2.1/arch/m68k/mac/config.c:1.1.1.4.6.3.2.1
--- linux-2.1/arch/m68k/mac/config.c:1.1.1.4.6.3	Sat Dec 19 18:51:31 1998
+++ linux-2.1/arch/m68k/mac/config.c	Sat Dec 19 21:28:26 1998
@@ -65,7 +65,6 @@
 extern int mac_keyb_init(void);
 extern int mac_kbdrate(struct kbd_repeat *k);
 extern void mac_kbd_leds(unsigned int leds);
-extern void mac_kbd_reset_setup(char*, int);
 
 /* Mac specific irq functions */
 extern void mac_init_IRQ (void);
@@ -307,7 +306,6 @@
     mach_keyb_init       = mac_keyb_init;
     mach_kbdrate         = mac_kbdrate;
     mach_kbd_leds        = mac_kbd_leds;
-    kbd_reset_setup      = mac_kbd_reset_setup;
     mach_init_IRQ        = mac_init_IRQ;
     mach_request_irq     = mac_request_irq;
     mach_free_irq        = mac_free_irq;
Index: linux-2.1/arch/m68k/mac/mackeyb.c
diff -u linux-2.1/arch/m68k/mac/mackeyb.c:1.1.1.5.6.3 linux-2.1/arch/m68k/mac/mackeyb.c:1.1.1.5.6.3.2.2
--- linux-2.1/arch/m68k/mac/mackeyb.c:1.1.1.5.6.3	Sat Dec 19 18:51:34 1998
+++ linux-2.1/arch/m68k/mac/mackeyb.c	Sun Dec 20 01:29:15 1998
@@ -50,6 +50,8 @@
 #include <linux/kbd_kern.h>
 #include <linux/kbd_ll.h>
 
+#include <config/adbmouse.h>
+
 static void kbd_repeat(unsigned long);
 static struct timer_list repeat_timer = { NULL, NULL, 0, 0, kbd_repeat };
 static int last_keycode;
@@ -758,9 +760,4 @@
 	printk("keyboard init done\n");
 
 	return 0;
-}
-
-/* for "kbd-reset" cmdline param */
-__initfunc(void mac_kbd_reset_setup(char *str, int *ints))
-{
 }
Index: linux-2.1/arch/m68k/mm/init.c
diff -u linux-2.1/arch/m68k/mm/init.c:1.1.1.4.6.2 linux-2.1/arch/m68k/mm/init.c:1.1.1.4.6.2.2.2
--- linux-2.1/arch/m68k/mm/init.c:1.1.1.4.6.2	Sat Dec 19 18:51:38 1998
+++ linux-2.1/arch/m68k/mm/init.c	Sun Dec 20 01:29:16 1998
@@ -28,6 +28,8 @@
 #include <asm/atari_stram.h>
 #endif
 
+#define DEBUG
+
 extern void die_if_kernel(char *,struct pt_regs *,long);
 extern void init_kpointer_table(void);
 extern void show_net_buffers(void);
@@ -133,6 +135,7 @@
 	else
 		ptablep = (pte_t *)__get_free_page(GFP_KERNEL);
 
+	clear_page((unsigned long)ptablep);
 	flush_page_to_ram((unsigned long) ptablep);
 	flush_tlb_kernel_page((unsigned long) ptablep);
 	nocache_page ((unsigned long)ptablep);
@@ -140,168 +143,98 @@
 	return ptablep;
 }
 
-__initfunc(static unsigned long
-map_chunk (unsigned long addr, unsigned long size, unsigned long *memavailp))
+static unsigned long __init
+map_chunk (unsigned long addr, long size, unsigned long *memavailp)
 {
-#define ONEMEG	(1024*1024)
-#define L3TREESIZE (256*1024)
-
-	static unsigned long mem_mapped = 0;
+#define PTRTREESIZE (256*1024)
+#define ROOTTREESIZE (32*1024*1024)
 	static unsigned long virtaddr = 0;
-	static pte_t *ktablep = NULL;
-	unsigned long *kpointerp;
 	unsigned long physaddr;
-	extern pte_t *kpt;
-	int pindex;   /* index into pointer table */
-	pgd_t *page_dir = pgd_offset_k (virtaddr);
-
-	if (!pgd_present (*page_dir)) {
-		/* we need a new pointer table */
-		kpointerp = (unsigned long *) get_kpointer_table ();
-		pgd_set (page_dir, (pmd_t *) kpointerp);
-		memset (kpointerp, 0, PTRS_PER_PMD * sizeof (pmd_t));
-	}
-	else
-		kpointerp = (unsigned long *) pgd_page (*page_dir);
+	pgd_t *pgd_dir;
+	pmd_t *pmd_dir;
+	pte_t *pte_dir;
 
-	/*
-	 * pindex is the offset into the pointer table for the
-	 * descriptors for the current virtual address being mapped.
-	 */
-	pindex = (virtaddr >> 18) & 0x7f;
+	physaddr = addr | m68k_supervisor_cachemode |
+		_PAGE_PRESENT | _PAGE_ACCESSED;
+	if (CPU_IS_040_OR_060)
+		physaddr |= _PAGE_GLOBAL040;
 
+	while (size > 0) {
 #ifdef DEBUG
-	printk ("mm=%ld, kernel_pg_dir=%p, kpointerp=%p, pindex=%d\n",
-		mem_mapped, kernel_pg_dir, kpointerp, pindex);
+		if (!(virtaddr & (PTRTREESIZE-1)))
+			printk ("\npa=%#lx va=%#lx ", physaddr, virtaddr);
 #endif
-
-	/*
-	 * if this is running on an '040, we already allocated a page
-	 * table for the first 4M.  The address is stored in kpt by
-	 * arch/head.S
-	 *
-	 */
-	if (CPU_IS_040_OR_060 && mem_mapped == 0)
-		ktablep = kpt;
-
-	for (physaddr = addr;
-	     physaddr < addr + size;
-	     mem_mapped += L3TREESIZE, virtaddr += L3TREESIZE) {
-
+		pgd_dir = pgd_offset_k(virtaddr);
+		if (!virtaddr && CPU_IS_020_OR_030) {
+			if (!(virtaddr & (ROOTTREESIZE-1)) &&
+			    size >= ROOTTREESIZE) {
 #ifdef DEBUG
-		printk ("pa=%#lx va=%#lx ", physaddr, virtaddr);
+				printk ("[very early term]");
 #endif
-
-		if (pindex > 127 && mem_mapped >= 32*ONEMEG) {
-			/* we need a new pointer table every 32M */
+				pgd_val(*pgd_dir) = physaddr;
+				size -= ROOTTREESIZE;
+				virtaddr += ROOTTREESIZE;
+				physaddr += ROOTTREESIZE;
+				continue;
+			}
+		}
+		if (!pgd_present(*pgd_dir)) {
 #ifdef DEBUG
 			printk ("[new pointer]");
 #endif
-
-			kpointerp = (unsigned long *)get_kpointer_table ();
-			pgd_set(pgd_offset_k(virtaddr), (pmd_t *)kpointerp);
-			pindex = 0;
-		}
+			pmd_dir = get_kpointer_table(memavailp);
+			pgd_set(pgd_dir, pmd_dir);
+		} else
+			pmd_dir = pmd_offset(pgd_dir, virtaddr);
 
-		if (CPU_IS_040_OR_060) {
-			int i;
-			unsigned long ktable;
-
-			/* Don't map the first 4 MB again. The pagetables
-			 * for this range have already been initialized
-			 * in boot/head.S. Otherwise the pages used for
-			 * tables would be reinitialized to copyback mode.
-			 */
-
-			if (mem_mapped < 4 * ONEMEG)
-			{
-#ifdef DEBUG
-				printk ("Already initialized\n");
-#endif
-				physaddr += L3TREESIZE;
-				pindex++;
-				continue;
-			}
+		if (CPU_IS_020_OR_030) {
+			if (virtaddr) {
 #ifdef DEBUG
-			printk ("[setup table]");
+				printk ("[early term]");
 #endif
-
-			/*
-			 * 68040, use page tables pointed to by the
-			 * kernel pointer table.
-			 */
-
-			if ((pindex & 15) == 0) {
-				/* Need new page table every 4M on the '040 */
+				pmd_dir->pmd[(virtaddr/PTRTREESIZE)&-16] = physaddr;
+				physaddr += PTRTREESIZE;
+			} else {
+				int i;
 #ifdef DEBUG
-				printk ("[new table]");
+				printk ("[zero map]");
 #endif
-				ktablep = kernel_page_table (memavailp);
-			}
-
-			ktable = virt_to_phys(ktablep);
-
-			/*
-			 * initialize section of the page table mapping
-			 * this 256K portion.
-			 */
-			for (i = 0; i < 64; i++) {
-				pte_val(ktablep[i]) = physaddr | _PAGE_PRESENT
-				  | m68k_supervisor_cachemode | _PAGE_GLOBAL040
-					| _PAGE_ACCESSED;
+				pte_dir = (pte_t *)get_kpointer_table(memavailp);
+				pmd_dir->pmd[0] = virt_to_phys(pte_dir) |
+					_PAGE_TABLE | _PAGE_ACCESSED;
+				pte_val(*pte_dir++) = 0;
 				physaddr += PAGE_SIZE;
+				for (i = 1; i < 64; physaddr += PAGE_SIZE, i++)
+					pte_val(*pte_dir++) = physaddr;
 			}
-			ktablep += 64;
-
-			/*
-			 * make the kernel pointer table point to the
-			 * kernel page table.  Each entries point to a
-			 * 64 entry section of the page table.
-			 */
-
-			kpointerp[pindex++] = ktable | _PAGE_TABLE | _PAGE_ACCESSED;
+			size -= PTRTREESIZE;
+			virtaddr += PTRTREESIZE;
 		} else {
-			/*
-			 * 68030, use early termination page descriptors.
-			 * Each one points to 64 pages (256K).
-			 */
-#ifdef DEBUG
-			printk ("[early term] ");
-#endif
-			if (virtaddr == 0UL) {
-				/* map the first 256K using a 64 entry
-				 * 3rd level page table.
-				 * UNMAP the first entry to trap
-				 * zero page (NULL pointer) references
-				 */
-				int i;
-				unsigned long *tbl;
-				
-				tbl = (unsigned long *)get_kpointer_table();
-
-				kpointerp[pindex++] = virt_to_phys(tbl) | _PAGE_TABLE |_PAGE_ACCESSED;
-
-				for (i = 0; i < 64; i++, physaddr += PAGE_SIZE)
-					tbl[i] = physaddr | _PAGE_PRESENT | _PAGE_ACCESSED;
-				
-				/* unmap the zero page */
-				tbl[0] = 0;
-			} else {
-				/* not the first 256K */
-				kpointerp[pindex++] = physaddr | _PAGE_PRESENT | _PAGE_ACCESSED;
+			if (!pmd_present(*pmd_dir)) {
 #ifdef DEBUG
-				printk ("%lx=%lx ", virt_to_phys(&kpointerp[pindex-1]),
-					kpointerp[pindex-1]);
+				printk ("[new table]");
 #endif
-				physaddr += 64 * PAGE_SIZE;
+				pte_dir = kernel_page_table(memavailp);
+				pmd_set(pmd_dir, pte_dir);
 			}
+			pte_dir = pte_offset(pmd_dir, virtaddr);
+
+			if (virtaddr) {
+				if (!pte_present(*pte_dir))
+					pte_val(*pte_dir) = physaddr;
+			} else
+				pte_val(*pte_dir) = 0;
+			size -= PAGE_SIZE;
+			virtaddr += PAGE_SIZE;
+			physaddr += PAGE_SIZE;
 		}
+
+	}
 #ifdef DEBUG
-		printk ("\n");
+	printk("\n");
 #endif
-	}
 
-	return mem_mapped;
+	return virtaddr;
 }
 
 extern unsigned long free_area_init(unsigned long, unsigned long);
@@ -317,17 +250,17 @@
  * paging_init() continues the virtual memory environment setup which
  * was begun by the code in arch/head.S.
  */
-__initfunc(unsigned long paging_init(unsigned long start_mem,
-				     unsigned long end_mem))
+unsigned long __init paging_init(unsigned long start_mem,
+				 unsigned long end_mem)
 {
 	int chunk;
 	unsigned long mem_avail = 0;
 
 #ifdef DEBUG
 	{
-		extern pte_t *kpt;
-		printk ("start of paging_init (%p, %p, %lx, %lx, %lx)\n",
-			kernel_pg_dir, kpt, availmem, start_mem, end_mem);
+		extern unsigned long availmem;
+		printk ("start of paging_init (%p, %lx, %lx, %lx)\n",
+			kernel_pg_dir, availmem, start_mem, end_mem);
 	}
 #endif
 
@@ -385,18 +318,6 @@
 	start_mem += PAGE_SIZE;
 	memset((void *)empty_zero_page, 0, PAGE_SIZE);
 
-#if 0
-	/* 
-	 * allocate the "swapper" page directory and
-	 * record in task 0 (swapper) tss 
-	 */
-	swapper_pg_dir = (pgd_t *)get_kpointer_table();
-
-	init_mm.pgd = swapper_pg_dir;
-#endif
-
-	memset (swapper_pg_dir, 0, sizeof(pgd_t)*PTRS_PER_PGD);
-
 	/* setup CPU root pointer for swapper task */
 	task[0]->tss.crp[0] = 0x80000000 | _PAGE_TABLE;
 	task[0]->tss.crp[1] = virt_to_phys (swapper_pg_dir);
@@ -434,7 +355,7 @@
 	return PAGE_ALIGN(free_area_init (start_mem, end_mem));
 }
 
-__initfunc(void mem_init(unsigned long start_mem, unsigned long end_mem))
+void __init mem_init(unsigned long start_mem, unsigned long end_mem)
 {
 	int codepages = 0;
 	int datapages = 0;
Index: linux-2.1/arch/m68k/mm/memory.c
diff -u linux-2.1/arch/m68k/mm/memory.c:1.1.1.6.6.2 linux-2.1/arch/m68k/mm/memory.c:1.1.1.6.6.2.2.3
--- linux-2.1/arch/m68k/mm/memory.c:1.1.1.6.6.2	Sat Dec 19 18:51:39 1998
+++ linux-2.1/arch/m68k/mm/memory.c	Sun Dec 20 16:11:46 1998
@@ -10,6 +10,7 @@
 #include <linux/string.h>
 #include <linux/types.h>
 #include <linux/malloc.h>
+#include <linux/init.h>
 
 #include <asm/setup.h>
 #include <asm/segment.h>
@@ -178,28 +179,52 @@
 
 /* maximum pages used for kpointer tables */
 #define KPTR_PAGES      4
-/* # of reserved slots */
-#define RESERVED_KPTR	4
-extern pmd_tablepage kernel_pmd_table; /* reserved in head.S */
 
 static struct kpointer_pages {
         pmd_tablepage *page[KPTR_PAGES];
         u_char alloced[KPTR_PAGES];
 } kptr_pages;
 
-void init_kpointer_table(void) {
-	short i = KPTR_PAGES-1;
+static void __init alloc_kpointer_table(unsigned long dir)
+{
+	pmd_tablepage *page = (pmd_tablepage *)(dir & PAGE_MASK);
+	int mask = 0x80 >> ((dir & ~PAGE_MASK) / sizeof(pmd_table));
+	int i;
+
+	for (i = 0; i < KPTR_PAGES; i++) {
+		if (page == kptr_pages.page[i]) {
+			kptr_pages.alloced[i] |= mask;
+			return;
+		}
+	}
+
+	for (i = 0; i < KPTR_PAGES; i++) {
+		if (!kptr_pages.page[i]) {
+			kptr_pages.page[i] = page;
+			kptr_pages.alloced[i] = mask;
+			return;
+		}
+	}
+}
+
+void __init init_kpointer_table(void)
+{
+	int i;
 
-	/* first page is reserved in head.S */
-	kptr_pages.page[i] = &kernel_pmd_table;
-	kptr_pages.alloced[i] = ~(0xff>>RESERVED_KPTR);
-	for (i--; i>=0; i--) {
-		kptr_pages.page[i] = NULL;
-		kptr_pages.alloced[i] = 0;
+	alloc_kpointer_table((unsigned long)kernel_pg_dir);
+
+	for (i = 0; i < PTRS_PER_PGD; i++) {
+		if (!pgd_val(kernel_pg_dir[i]))
+			continue;
+		alloc_kpointer_table(phys_to_virt(pgd_val(kernel_pg_dir[i])));
 	}
+
+	for (i = 0; i < KPTR_PAGES; i++)
+		printk("kpointer: %p, %02x\n", kptr_pages.page[i],
+		       kptr_pages.alloced[i]);
 }
 
-pmd_t *get_kpointer_table (void)
+pmd_t *get_kpointer_table(unsigned long *memavailp)
 {
 	/* For pointer tables for the kernel virtual address space,
 	 * use the page that is reserved in head.S that can hold up to
@@ -220,23 +245,31 @@
 	long nr, offset = -8;
 	short i;
 
-	for (i=KPTR_PAGES-1; i>=0; i--) {
+	for (i = 0; i < KPTR_PAGES; i++) {
 		asm volatile("bfffo %1{%2,#8},%0"
 			: "=d" (nr)
 			: "d" ((u_char)~kptr_pages.alloced[i]), "d" (offset));
 		if (nr)
 			break;
 	}
-	if (i < 0) {
+	if (i >= KPTR_PAGES) {
 		printk("No space for kernel pointer table!\n");
 		return NULL;
 	}
 	if (!(page = kptr_pages.page[i])) {
-		if (!(page = (pmd_tablepage *)get_free_page(GFP_KERNEL))) {
+		if (memavailp) {
+			page = (pmd_tablepage *)*memavailp;
+			*memavailp += PAGE_SIZE;
+		} else
+			page = (pmd_tablepage *)__get_free_page(GFP_KERNEL);
+
+		if (!page) {
 			printk("No space for kernel pointer table!\n");
 			return NULL;
 		}
-		flush_tlb_kernel_page((unsigned long) page);
+		clear_page((unsigned long)page);
+		flush_page_to_ram((unsigned long)page);
+		flush_tlb_kernel_page((unsigned long)page);
 		nocache_page((u_long)(kptr_pages.page[i] = page));
 	}
 	asm volatile("bfset %0@{%1,#1}"
@@ -244,6 +277,7 @@
 		: "a" (&kptr_pages.alloced[i]), "d" (nr-offset));
 	table = &(*page)[nr-offset];
 	memset(table, 0, sizeof(pmd_table));
+	printk("kpointer: %p\n", table);
 	return ((pmd_t *)table);
 }
 
@@ -254,12 +288,12 @@
 	long nr;
 	short i;
 
-	for (i=KPTR_PAGES-1; i>=0; i--) {
+	for (i = 0; i < KPTR_PAGES; i++) {
 		if (kptr_pages.page[i] == page)
 			break;
 	}
 	nr = ((u_long)table - (u_long)page) / sizeof(pmd_table);
-	if (!table || i < 0 || (i == KPTR_PAGES-1 && nr < RESERVED_KPTR)) {
+	if (!table || i >= KPTR_PAGES) {
 		printk("Attempt to free invalid kernel pointer table: %p\n", table);
 		return;
 	}
Index: linux-2.1/drivers/block/ide.c
diff -u linux-2.1/drivers/block/ide.c:1.1.1.10.4.3 linux-2.1/drivers/block/ide.c:1.1.1.10.4.3.2.1
--- linux-2.1/drivers/block/ide.c:1.1.1.10.4.3	Sat Dec 19 18:51:41 1998
+++ linux-2.1/drivers/block/ide.c	Sat Dec 19 21:28:41 1998
@@ -1392,7 +1392,9 @@
 	ide_drive_t *drive;
 	ide_handler_t *handler;
 
+#ifdef __i386__
 	__cli();	/* local CPU only */
+#endif
 	spin_lock_irqsave(&hwgroup->spinlock, flags);
 	hwif = hwgroup->hwif;
 	if (!ide_ack_intr(hwif)) {
@@ -2749,7 +2751,7 @@
 		enable_irq(ide_hwifs[0].irq);
 		ide_release_lock(&ide_lock);
 	}
-#endif /* __mc68000__ || CONFIG_APUS*/
+#endif /* __mc68000__ || CONFIG_APUS */
 #endif /* CONFIG_BLK_DEV_IDE */
 
 #ifdef CONFIG_PROC_FS
Index: linux-2.1/drivers/block/z2ram.c
diff -u linux-2.1/drivers/block/z2ram.c:1.1.1.2.6.1 linux-2.1/drivers/block/z2ram.c:1.1.1.2.6.1.2.1
--- linux-2.1/drivers/block/z2ram.c:1.1.1.2.6.1	Fri Dec 18 23:13:58 1998
+++ linux-2.1/drivers/block/z2ram.c	Sun Dec 20 01:29:21 1998
@@ -39,10 +39,8 @@
 #include <asm/setup.h>
 #include <asm/bitops.h>
 #include <asm/amigahw.h>
-#ifdef CONFIG_APUS
 #include <asm/pgtable.h>
 #include <asm/io.h>
-#endif
 #include <linux/zorro.h>
 
 
Index: linux-2.1/drivers/char/amiga_ser.c
diff -u linux-2.1/drivers/char/amiga_ser.c:1.1.4.3 linux-2.1/drivers/char/amiga_ser.c:1.1.4.3.2.3
--- linux-2.1/drivers/char/amiga_ser.c:1.1.4.3	Sat Dec 19 18:51:43 1998
+++ linux-2.1/drivers/char/amiga_ser.c	Sun Dec 20 18:14:37 1998
@@ -43,6 +43,8 @@
 #include <asm/irq.h>
 #include <asm/atomic.h>
 
+#include <config/kgdb.h>
+
 /* some serial hardware definitions */
 #define SDR_OVRUN   (1<<15)
 #define SDR_RBF     (1<<14)
@@ -95,7 +97,7 @@
 };
 
 /* Standard speeds table */
-static int baud_table[17] = {
+static int baud_table[18] = {
     /* B0     */ 0,
     /* B50    */ 50,
     /* B75    */ 75,
@@ -112,7 +114,8 @@
     /* B9600  */ 9600,
     /* B19200 */ 19200,
     /* B38400 */ 38400,
-    /* B57600 */ 57600
+    /* B57600 */ 57600,
+    /* B115200*/ 115200
 };
 	
 static __inline__ void ser_DTRoff(void)
@@ -185,7 +188,7 @@
 
     /* set ISRs, and then disable the rx interrupts */
     request_irq(IRQ_AMIGA_TBE, ser_tx_int, 0, "serial TX", info);
-    request_irq(IRQ_AMIGA_RBF, ser_rx_int, 0, "serial RX", info);
+    request_irq(IRQ_AMIGA_RBF, ser_rx_int, IRQ_FLG_REALTIME, "serial RX", info);
 
     amiga_info = info;
 
@@ -363,8 +366,8 @@
 	    }
     }
     if (!div){
-	/* Maximum  speed is 57600 :-( */
-	if (baud > 16) baud = 16;
+	/* Maximum  speed is 115200 :-| */
+	if (baud > 17) baud = 17;
 	realbaud = baud_table[baud];
 	if (realbaud)
 	    div = (amiga_colorclock+realbaud/2)/realbaud;
Index: linux-2.1/drivers/char/amikeyb.c
diff -u linux-2.1/drivers/char/amikeyb.c:1.1.1.2.6.2 linux-2.1/drivers/char/amikeyb.c:1.1.1.2.6.2.2.1
--- linux-2.1/drivers/char/amikeyb.c:1.1.1.2.6.2	Sat Dec 19 18:51:44 1998
+++ linux-2.1/drivers/char/amikeyb.c	Sat Dec 19 21:28:43 1998
@@ -341,8 +341,3 @@
     
     return( 0 );
 }
-
-/* for "kbd-reset" cmdline param */
-__initfunc(void amiga_kbd_reset_setup(char *str, int *ints))
-{
-}
Index: linux-2.1/drivers/char/tty_io.c
diff -u linux-2.1/drivers/char/tty_io.c:1.1.1.13.2.3 linux-2.1/drivers/char/tty_io.c:1.1.1.13.2.3.2.1
--- linux-2.1/drivers/char/tty_io.c:1.1.1.13.2.3	Sat Dec 19 18:51:46 1998
+++ linux-2.1/drivers/char/tty_io.c	Sat Dec 19 21:28:45 1998
@@ -1843,33 +1843,21 @@
 static void flush_to_ldisc(void *private_)
 {
 	struct tty_struct *tty = (struct tty_struct *) private_;
-	unsigned char	*cp;
-	char		*fp;
-	int		count;
-	unsigned long flags;
-
-	if (tty->flip.buf_num) {
-		cp = tty->flip.char_buf + TTY_FLIPBUF_SIZE;
-		fp = tty->flip.flag_buf + TTY_FLIPBUF_SIZE;
-		tty->flip.buf_num = 0;
-
-		save_flags(flags); cli();
-		tty->flip.char_buf_ptr = tty->flip.char_buf;
-		tty->flip.flag_buf_ptr = tty->flip.flag_buf;
-	} else {
-		cp = tty->flip.char_buf;
-		fp = tty->flip.flag_buf;
-		tty->flip.buf_num = 1;
-
-		save_flags(flags); cli();
-		tty->flip.char_buf_ptr = tty->flip.char_buf + TTY_FLIPBUF_SIZE;
-		tty->flip.flag_buf_ptr = tty->flip.flag_buf + TTY_FLIPBUF_SIZE;
+	int newcount, count = tty->flip.count;
+	int pop = tty->flip.pop;
+
+	newcount = count;
+	if (pop + count > TTY_FLIPBUF_SIZE) {
+		newcount = TTY_FLIPBUF_SIZE - pop;
+		tty->ldisc.receive_buf(tty, &tty->flip.char_buf[pop],
+				&tty->flip.flag_buf[pop], newcount);
+		newcount = count - newcount;
+		pop = 0;
 	}
-	count = tty->flip.count;
-	tty->flip.count = 0;
-	restore_flags(flags);
-	
-	tty->ldisc.receive_buf(tty, cp, fp, count);
+	tty->ldisc.receive_buf(tty, &tty->flip.char_buf[pop], 
+			       &tty->flip.flag_buf[pop], newcount);
+	tty->flip.pop = (pop + newcount) & (TTY_FLIPBUF_SIZE - 1);
+	atomic_sub(count, (atomic_t *)&tty->flip.count);
 }
 
 /*
@@ -1925,8 +1913,9 @@
 	tty->magic = TTY_MAGIC;
 	tty->ldisc = ldiscs[N_TTY];
 	tty->pgrp = -1;
-	tty->flip.char_buf_ptr = tty->flip.char_buf;
-	tty->flip.flag_buf_ptr = tty->flip.flag_buf;
+	tty->flip.count = 0;
+	tty->flip.push = 0;
+	tty->flip.pop = 0;
 	tty->flip.tqueue.routine = flush_to_ldisc;
 	tty->flip.tqueue.data = tty;
 	tty->flip.pty_sem = MUTEX;
Index: linux-2.1/drivers/video/amifb.c
diff -u linux-2.1/drivers/video/amifb.c:1.1.1.5.6.2 linux-2.1/drivers/video/amifb.c:1.1.1.5.6.2.2.2
--- linux-2.1/drivers/video/amifb.c:1.1.1.5.6.2	Sat Dec 19 18:51:48 1998
+++ linux-2.1/drivers/video/amifb.c	Sun Dec 20 16:11:50 1998
@@ -599,8 +599,8 @@
 
 #define arraysize(x)	(sizeof(x)/sizeof(*(x)))
 
-#define VBlankOn()	custom.intena = IF_SETCLR|IF_COPER
-#define VBlankOff()	custom.intena = IF_COPER
+#define VBlankOn()	custom.intena = IF_SETCLR|IF_COPPER
+#define VBlankOff()	custom.intena = IF_COPPER
 
 
 	/*
@@ -1204,6 +1204,7 @@
 static void do_install_cmap(int con, struct fb_info *info);
 static int flash_cursor(void);
 static void amifb_interrupt(int irq, void *dev_id, struct pt_regs *fp);
+static void amifb_dummyinterrupt(int irq, void *dev_id, struct pt_regs *fp);
 static void get_video_mode(const char *name);
 static void check_default_mode(void);
 static u_long chipalloc(u_long size);
@@ -1894,13 +1895,17 @@
 
 	check_default_mode();
 
-	if (request_irq(IRQ_AMIGA_AUTO_3, amifb_interrupt, IRQ_FLG_LOCK,
-	                "fb vertb handler", NULL))
-		panic("Couldn't add vblank interrupt\n");
-	ami_intena_vals[IRQ_AMIGA_VERTB] = IF_COPER;
+	disable_irq(IRQ_AMIGA_VERTB);
+	ami_intena_vals[IRQ_AMIGA_VERTB] = IF_COPPER;
 	ami_intena_vals[IRQ_AMIGA_COPPER] = 0;
-	custom.intena = IF_VERTB;
-	custom.intena = IF_SETCLR | IF_COPER;
+	/* this keeps the copper int allocated and sets realtime int flags */
+	request_irq(IRQ_AMIGA_COPPER, amifb_dummyinterrupt, IRQ_FLG_LOCK |
+	            IRQ_FLG_REALTIME, "fb dummy handler", NULL);
+
+	if (request_irq(IRQ_AMIGA_AUTO_3, amifb_interrupt, IRQ_FLG_REPLACE |
+	                IRQ_FLG_LOCK | IRQ_FLG_REALTIME, "fb vertb handler", NULL))
+		panic("Couldn't add vblank interrupt\n");
+	enable_irq(IRQ_AMIGA_VERTB);
 
 	amifb_set_var(&amifb_default, -1, &fb_info);
 
@@ -1983,8 +1988,11 @@
 
 static void amifb_interrupt(int irq, void *dev_id, struct pt_regs *fp)
 {
+#ifdef CONFIG_APUS
 	u_short ints = custom.intreqr & custom.intenar;
-	static struct irq_server server = {0, 0};
+#else
+	int ints = irq;
+#endif
 	unsigned long flags;
 
 	if (ints & IF_BLIT) {
@@ -1992,8 +2000,8 @@
 		amiga_do_irq(IRQ_AMIGA_BLIT, fp);
 	}
 
-	if (ints & IF_COPER) {
-		custom.intreq = IF_COPER;
+	if (ints & IF_COPPER) {
+		custom.intreq = IF_COPPER;
 		if (do_vmode_pan || do_vmode_full)
 			ami_update_display();
 
@@ -2013,11 +2021,11 @@
 				ami_set_sprite();
 		}
 
-		save_flags(flags);
-		cli();
+		__save_flags(flags);
+		__cli();
 		if (get_vbpos() < down2(currentpar.diwstrt_v - 6))
 			custom.copjmp2 = 0;
-		restore_flags(flags);
+		__restore_flags(flags);
 
 		if (do_blank) {
 			ami_do_blank();
@@ -2028,7 +2036,10 @@
 			ami_reinit_copper();
 			do_vmode_full = 0;
 		}
-		amiga_do_irq_list(IRQ_AMIGA_VERTB, fp, &server);
+		amiga_do_irq_list(IRQ_AMIGA_VERTB, fp);
+#ifdef CONFIG_RT_INTERRUPT
+		rt_irqrequest |= (amiga_slowintmask & IF_VERTB);
+#endif
 	}
 
 	if (ints & IF_VERTB) {
@@ -2038,6 +2049,14 @@
 }
 
 	/*
+	 * Dummy int
+	 */
+
+static void amifb_dummyinterrupt(int irq, void *dev_id, struct pt_regs *fp)
+{
+}
+
+	/*
 	 * Get a Video Mode
 	 */
 
@@ -3322,7 +3341,7 @@
 		(cop++)->l = CMOVE2(loww(p), sprpt[i]);
 	}
 
-	(cop++)->l = CMOVE(IF_SETCLR | IF_COPER, intreq);
+	(cop++)->l = CMOVE(IF_SETCLR | IF_COPPER, intreq);
 	copdisplay.wait = cop;
 	(cop++)->l = CEND;
 	(cop++)->l = CMOVE(0, copjmp2);
Index: linux-2.1/drivers/video/fbcon-iplan2p2.c
diff -u linux-2.1/drivers/video/fbcon-iplan2p2.c:1.1.1.7.6.2 linux-2.1/drivers/video/fbcon-iplan2p2.c:1.1.1.7.6.2.2.2
--- linux-2.1/drivers/video/fbcon-iplan2p2.c:1.1.1.7.6.2	Sat Dec 19 18:51:55 1998
+++ linux-2.1/drivers/video/fbcon-iplan2p2.c	Sun Dec 20 01:29:26 1998
@@ -10,7 +10,6 @@
  *  more details.
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/tty.h>
 #include <linux/console.h>
@@ -18,6 +17,7 @@
 #include <linux/fb.h>
 
 #include <asm/byteorder.h>
+#include <asm/setup.h>
 
 #include <video/fbcon.h>
 #include <video/fbcon-iplan2p2.h>
@@ -43,7 +43,7 @@
 /* Perform the m68k movepw operation.  */
 static inline void movepw(u8 *d, u16 val)
 {
-#if defined __mc68000__ && !defined CONFIG_OPTIMIZE_060
+#if defined __mc68000__ && !defined CPU_M68060_ONLY
     asm volatile ("movepw %1,%0@(0)" : : "a" (d), "d" (val));
 #else
     d[0] = (val >> 16) & 0xff;
Index: linux-2.1/drivers/video/fbcon-iplan2p4.c
diff -u linux-2.1/drivers/video/fbcon-iplan2p4.c:1.1.1.7.6.2 linux-2.1/drivers/video/fbcon-iplan2p4.c:1.1.1.7.6.2.2.2
--- linux-2.1/drivers/video/fbcon-iplan2p4.c:1.1.1.7.6.2	Sat Dec 19 18:51:56 1998
+++ linux-2.1/drivers/video/fbcon-iplan2p4.c	Sun Dec 20 01:29:27 1998
@@ -10,7 +10,6 @@
  *  more details.
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/tty.h>
 #include <linux/console.h>
@@ -18,6 +17,7 @@
 #include <linux/fb.h>
 
 #include <asm/byteorder.h>
+#include <asm/setup.h>
 
 #include <video/fbcon.h>
 #include <video/fbcon-iplan2p4.h>
@@ -35,7 +35,7 @@
 /* Perform the m68k movepl operation.  */
 static inline void movepl(u8 *d, u32 val)
 {
-#if defined __mc68000__ && !defined CONFIG_OPTIMIZE_060
+#if defined __mc68000__ && !defined CPU_M68060_ONLY
     asm volatile ("movepl %1,%0@(0)" : : "a" (d), "d" (val));
 #else
     d[0] = (val >> 24) & 0xff;
Index: linux-2.1/drivers/video/fbcon-iplan2p8.c
diff -u linux-2.1/drivers/video/fbcon-iplan2p8.c:1.1.1.7.6.2 linux-2.1/drivers/video/fbcon-iplan2p8.c:1.1.1.7.6.2.2.2
--- linux-2.1/drivers/video/fbcon-iplan2p8.c:1.1.1.7.6.2	Sat Dec 19 18:51:57 1998
+++ linux-2.1/drivers/video/fbcon-iplan2p8.c	Sun Dec 20 01:29:28 1998
@@ -10,7 +10,6 @@
  *  more details.
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/tty.h>
 #include <linux/console.h>
@@ -18,6 +17,7 @@
 #include <linux/fb.h>
 
 #include <asm/byteorder.h>
+#include <asm/setup.h>
 
 #include <video/fbcon.h>
 #include <video/fbcon-iplan2p8.h>
@@ -40,7 +40,7 @@
 /* Perform the m68k movepl operation extended to 64 bits.  */
 static inline void movepl2(u8 *d, u32 val1, u32 val2)
 {
-#if defined __mc68000__ && !defined CONFIG_OPTIMIZE_060
+#if defined __mc68000__ && !defined CPU_M68060_ONLY
     asm volatile ("movepl %1,%0@(0); movepl %2,%0@(8)"
 		  : : "a" (d), "d" (val1), "d" (val2));
 #else
Index: linux-2.1/fs/msdos/namei.c
diff -u linux-2.1/fs/msdos/namei.c:1.1.1.6.2.1 linux-2.1/fs/msdos/namei.c:1.1.1.6.2.1.2.1
--- linux-2.1/fs/msdos/namei.c:1.1.1.6.2.1	Fri Dec 18 23:15:23 1998
+++ linux-2.1/fs/msdos/namei.c	Sun Dec 20 01:29:31 1998
@@ -6,7 +6,6 @@
  */
 
 #define __NO_VERSION__
-#include <linux/config.h>
 #include <linux/module.h>
 
 #include <linux/sched.h>
Index: linux-2.1/include/asm-i386/atomic_new.h
diff -u /dev/null linux-2.1/include/asm-i386/atomic_new.h:1.1.6.1
--- /dev/null	Sun Dec 20 19:21:44 1998
+++ linux-2.1/include/asm-i386/atomic_new.h	Sun Dec 20 01:54:05 1998
@@ -0,0 +1,94 @@
+#ifndef _ASM_I386_ATOMIC_H
+#define _ASM_I386_ATOMIC_H
+
+#ifdef __SMP__
+#define __LOCK
+#endif
+
+#if 0
+
+#define atomic_define	unsigned long __atomic_flags
+#define atomic_enter()	asm volatile ("cli": : :"memory")
+#define atomic_leave()	asm volatile ("sti": : :"memory")
+
+#else
+
+#define __has_atomic_instr
+
+#define __atomic_init( ptr, old ) ({ old = *(ptr); })
+
+#define __atomic_reserve( ptr, old )
+
+#define __atomic_update( ptr, old, new ) ({			\
+	unsigned char res;					\
+	asm volatile (__LOCK "cmpxchg %3,%1; sete %0"		\
+		: "=q" (res),  "=m" (*(ptr)), "=&a" (old)	\
+		: "r" (new), "1" (*(ptr)), "2" (old) );		\
+	res;							\
+})
+
+#define atomic_do_exchange( ptr, old, new ) ({			\
+	old = *(ptr);						\
+	asm volatile ("1:" : "=&a" (old) : "0" (old) );		\
+	asm volatile (__LOCK "cmpxchg %2,%0; jne 1b"		\
+		: "=m" (*(ptr)), "=&a" (old)			\
+		: "r" (new), "0" (*(ptr)), "1" (old) );		\
+})
+
+#define atomic_inserthead( ptr, old, new ) ({			\
+	typeof(*(ptr)) __val = *(ptr);				\
+	asm volatile ("1:" : "=&r" (__val) : "0" (__val) );	\
+	old = __val;						\
+	asm volatile (__LOCK "cmpxchg %2,%0; jne 1b"		\
+		: "=m" (*(ptr)), "=&a" (__val)			\
+		: "r" (new), "0" (*(ptr)), "1" (__val) );	\
+})
+
+#endif
+
+#define atomic_do_exchange_const( ptr, old, new ) ({		\
+	asm volatile (__LOCK "xchg %1,%0"			\
+		: "=m" (*(ptr)), "=r" (old)			\
+		: "0" (*(ptr)), "1" (new) );			\
+})
+
+#define atomic_inc( ptr ) ({					\
+	asm volatile (__LOCK "incl %0"				\
+		: "=m" (*(ptr)) : "0" (*(ptr)) );		\
+})
+
+#define atomic_dec( ptr ) ({					\
+	asm volatile (__LOCK "decl %0"				\
+		: "=m" (*(ptr)) : "0" (*(ptr)) );		\
+})
+
+#define atomic_dec_test( ptr ) ({				\
+	unsigned char __res;					\
+								\
+	asm volatile (__LOCK "decl %0; sete %1"			\
+		: "=m" (*(ptr)), "=qm" (__res)			\
+		: "1" (*(ptr)) );				\
+	__res != 0;						\
+})
+
+#define atomic_add( ptr, val ) ({				\
+	asm volatile (__LOCK "addl %1,%0"			\
+		: "=m" (*(ptr)) : "ir" (val), "0" (*(ptr)) );	\
+})
+
+#define atomic_sub( ptr, val ) ({				\
+	asm volatile (__LOCK "subl %1,%0"			\
+		: "=m" (*(ptr)) : "ir" (val), "0" (*(ptr)) );	\
+})
+
+#define atomic_setmask( ptr, mask ) ({				\
+	asm volatile (__LOCK "orl %1,%0"			\
+		: "=m" (*(ptr)) : "ir" (val), "0" (*(ptr)) );	\
+})
+
+#define atomic_clrmask( ptr, mask ) ({				\
+	asm volatile (__LOCK "andl %1,%0"			\
+		: "=m" (*(ptr)) : "ir" (~(val)), "0" (*(ptr)) );\
+})
+
+#endif /* _ASM_I386_ATOMIC_H */
Index: linux-2.1/include/asm-m68k/amigadep.h
diff -u /dev/null linux-2.1/include/asm-m68k/amigadep.h:1.1.6.1
--- /dev/null	Sun Dec 20 19:21:46 1998
+++ linux-2.1/include/asm-m68k/amigadep.h	Sun Dec 20 02:01:10 1998
@@ -0,0 +1,52 @@
+#ifndef _M68K_AMIGADEP_H
+#define _M68K_AMIGADEP_H
+
+#include "asm/setup.h"
+
+#ifdef MACH_AMIGA_ONLY
+
+#define NO_MACH_DEFS
+
+#define mach_sched_init		amiga_sched_init
+#define mach_keyb_init		amiga_keyb_init
+#define mach_kbdrate		amiga_kbdrate
+#define mach_init_IRQ		amiga_init_IRQ
+#define mach_request_irq	amiga_request_irq
+#define mach_free_irq		amiga_free_irq
+#define mach_do_irqrequest	amiga_do_irqrequest
+#define enable_irq		amiga_enable_irq
+#define disable_irq		amiga_disable_irq
+
+#endif
+
+extern void amiga_sched_init(void (*handler)(int, void *, struct pt_regs *));
+/* amiga specific keyboard functions */
+extern int amiga_keyb_init(void);
+extern int amiga_kbdrate (struct kbd_repeat *);
+/* amiga specific irq functions */
+extern void amiga_init_IRQ (void);
+extern void (*amiga_default_handler[]) (int, void *, struct pt_regs *);
+extern int amiga_request_irq (unsigned int irq,
+                              void (*handler)(int, void *, struct pt_regs *),
+                              unsigned long flags, const char *devname,
+                              void *dev_id);
+extern void amiga_free_irq (unsigned int irq, void *dev_id);
+extern void amiga_do_irqrequest (void);
+extern void amiga_enable_irq (unsigned int);
+extern void amiga_disable_irq (unsigned int);
+extern void amiga_get_model(char *model);
+extern int amiga_get_hardware_list(char *buffer);
+extern int amiga_get_irq_list (char *);
+/* amiga specific timer functions */
+extern unsigned long amiga_gettimeoffset (void);
+extern void a3000_gettod (int *, int *, int *, int *, int *, int *);
+extern void a2000_gettod (int *, int *, int *, int *, int *, int *);
+extern int amiga_hwclk (int, struct hwclk_time *);
+extern int amiga_set_clock_mmss (unsigned long);
+extern void amiga_mksound( unsigned int count, unsigned int ticks );
+extern void amiga_floppy_setup(char *, int *);
+extern void amiga_reset (void);
+extern void amiga_init_sound(void);
+extern void amiga_heartbeat(int on);
+
+#endif /* _M68K_AMIGADEP_H */
Index: linux-2.1/include/asm-m68k/amigaints.h
diff -u linux-2.1/include/asm-m68k/amigaints.h:1.1.1.1.6.2 linux-2.1/include/asm-m68k/amigaints.h:1.1.1.1.6.2.2.1
--- linux-2.1/include/asm-m68k/amigaints.h:1.1.1.1.6.2	Sat Dec 19 18:52:01 1998
+++ linux-2.1/include/asm-m68k/amigaints.h	Sat Dec 19 21:28:55 1998
@@ -13,6 +13,13 @@
 #ifndef _ASMm68k_AMIGAINTS_H_
 #define _ASMm68k_AMIGAINTS_H_
 
+#include <linux/kernel_stat.h>
+#include <asm/irq.h>
+#include <config/advanced.h>
+#ifdef CONFIG_ADVANCED
+#include <config/rt/interrupt.h>
+#endif
+
 /*
 ** Amiga Interrupt sources.
 **
@@ -22,35 +29,21 @@
 #define AMI_STD_IRQS        (14)
 #define CIA_IRQS            (5)
 #define AMI_IRQS            (32) /* AUTO_IRQS+AMI_STD_IRQS+2*CIA_IRQS */
-
-/* vertical blanking interrupt */
-#define IRQ_AMIGA_VERTB     0
-
-/* copper interrupt */
-#define IRQ_AMIGA_COPPER    1
 
-/* Audio interrupts */
-#define IRQ_AMIGA_AUD0	    2
-#define IRQ_AMIGA_AUD1	    3
-#define IRQ_AMIGA_AUD2	    4
-#define IRQ_AMIGA_AUD3	    5
-
-/* Blitter done interrupt */
+/* Amiga standard interrupt sources */
+#define IRQ_AMIGA_TBE	    0
+#define IRQ_AMIGA_DSKBLK    1
+#define IRQ_AMIGA_SOFT      2
+#define IRQ_AMIGA_PORTS	    3
+#define IRQ_AMIGA_COPPER    4
+#define IRQ_AMIGA_VERTB     5
 #define IRQ_AMIGA_BLIT	    6
-
-/* floppy disk interrupts */
-#define IRQ_AMIGA_DSKSYN    7
-#define IRQ_AMIGA_DSKBLK    8
-
-/* builtin serial port interrupts */
-#define IRQ_AMIGA_RBF	    9
-#define IRQ_AMIGA_TBE	    10
-
-/* software interrupts */
-#define IRQ_AMIGA_SOFT      11
-
-/* interrupts from external hardware */
-#define IRQ_AMIGA_PORTS	    12
+#define IRQ_AMIGA_AUD0	    7
+#define IRQ_AMIGA_AUD1	    8
+#define IRQ_AMIGA_AUD2	    9
+#define IRQ_AMIGA_AUD3	    10
+#define IRQ_AMIGA_RBF	    11
+#define IRQ_AMIGA_DSKSYN    12
 #define IRQ_AMIGA_EXTER	    13
 
 /* CIA interrupt sources */
@@ -100,21 +93,56 @@
 #define IF_AUD0     0x0080	/* audio channel 0 done interrupt */
 #define IF_BLIT     0x0040	/* blitter done interrupt */
 #define IF_VERTB    0x0020	/* vertical blanking interrupt */
-#define IF_COPER    0x0010	/* copper interrupt */
+#define IF_COPPER   0x0010	/* copper interrupt */
 #define IF_PORTS    0x0008	/* external level 2 and CIA A interrupt */
 #define IF_SOFT     0x0004	/* software initiated interrupt */
 #define IF_DSKBLK   0x0002	/* diskblock DMA finished */
 #define IF_TBE	    0x0001	/* serial transmit buffer empty interrupt */
 
-struct irq_server {
-	unsigned short count, reentrance;
-};
+extern irq_node_t *ami_irq_list[AMI_STD_IRQS];
+#ifdef CONFIG_RT_INTERRUPT
+extern unsigned short amiga_slowintmask, amiga_rtintmask;
+#endif
+
+extern void amiga_inthandler(void);
+extern void nmi_handler(void);
+
+extern inline void amiga_do_irq(int irq, struct pt_regs *fp)
+{
+	kstat.irqs[0][AUTO_IRQ_NR + irq]++;
+	userirq_list[irq]->handler(irq, userirq_list[irq]->dev_id, fp);
+}
+
+extern inline void amiga_do_softirq(int irq, struct pt_regs *fp)
+{
+	kstat.irqs[0][AUTO_IRQ_NR + irq]++;
+	userirq_softlist[irq]->handler(irq, userirq_softlist[irq]->dev_id, fp);
+}
+
+extern inline void amiga_do_irq_list(int irq, struct pt_regs *fp)
+{
+	irq_node_t *node;
+
+	kstat.irqs[0][AUTO_IRQ_NR + irq]++;
+	/* serve handlers */
+	for (node = userirq_list[irq]; node; node = node->next)
+		node->handler(irq, node->dev_id, fp);
+}
+
+extern inline void amiga_do_softirq_list(int irq, struct pt_regs *fp)
+{
+	irq_node_t *node;
+
+	/* serve handlers */
+	for (node = userirq_softlist[irq]; node; node = node->next)
+		node->handler(irq, node->dev_id, fp);
+}
 
-extern void amiga_do_irq(int irq, struct pt_regs *fp);
-extern void amiga_do_irq_list(int irq, struct pt_regs *fp, struct irq_server *server);
+/*
+ * CIA specific definitions
+ */
 
 /* CIA interrupt control register bits */
-
 #define CIA_ICR_TA	0x01
 #define CIA_ICR_TB	0x02
 #define CIA_ICR_ALRM	0x04
Index: linux-2.1/include/asm-m68k/atomic_new.h
diff -u /dev/null linux-2.1/include/asm-m68k/atomic_new.h:1.1.6.1
--- /dev/null	Sun Dec 20 19:21:48 1998
+++ linux-2.1/include/asm-m68k/atomic_new.h	Sun Dec 20 01:54:07 1998
@@ -0,0 +1,195 @@
+#ifndef _ASM_M68K_ATOMIC_H
+#define _ASM_M68K_ATOMIC_H
+
+#include <config/advanced.h>
+#ifdef CONFIG_ADVANCED
+#include <config/rmw/insns.h>
+#endif
+
+#ifndef CONFIG_RMW_INSNS
+
+#include <asm/system.h>
+
+#define __has_bit_instr
+
+#define atomic_define   unsigned long __atomic_flags
+#define atomic_enter()  save_and_cli( __atomic_flags )
+#define atomic_leave()  restore_flags( __atomic_flags )
+
+#else /* CONFIG_RMW_INSNS */
+
+#define __has_atomic_instr
+
+#define __atomic_init( ptr , data )	((data) = *(ptr))
+
+#define __atomic_reserve( ptr, data )
+
+#define __atomic_update( ptr, data, new ) ({			\
+	card8 res;						\
+								\
+	asm volatile ( "cas.l %3,%4,%5; seq %0"			\
+		: "=d" (res), "=&d" (data), "=m" (*(ptr))	\
+		: "1" (data), "d" (new), "2" (*(ptr)));		\
+	res;							\
+})
+
+#define atomic_do_exchange( ptr, old, new ) ({			\
+	old = *(ptr);						\
+	asm volatile ("1:" : "=&d" (old) : "0" (old) );		\
+	asm volatile ("cas.l %2,%3,%4; jne 1b"			\
+		: "=&d" (old), "=m" (*(ptr))			\
+		: "0" (old), "d" (new), "1" (*(ptr)));		\
+})
+
+#define atomic_do_exchange_const( ptr, old, new ) ({		\
+	asm volatile ("1: cas.l %2,%3,%4; jne 1b"		\
+		: "=&d" (old), "=m" (*(ptr))			\
+		: "0" (*(ptr)), "d" (new), "1" (*(ptr)));	\
+})
+
+#define atomic_inserthead( ptr, old, new ) ({			\
+	typeof(*(ptr)) __val = *(ptr);				\
+								\
+	asm volatile ( "1:" : "=&d" (__val) : "0" (__val) );	\
+	old = __val;						\
+	asm volatile ( "cas.l %2,%3,%4; jne 1b"			\
+		: "=&d" (__val), "=m" (*(ptr))			\
+		: "0" (__val), "d" (new), "1" (*(ptr)) );	\
+})
+
+#endif /* CONFIG_RMW_INSNS */
+
+/* so fare we donīt have SMP systems... */
+
+#ifndef __SMP__
+
+#if 0 /* for now */
+#define atomic_inc( ptr ) ({					\
+	asm volatile ("addq.l #1,%0"				\
+		: "=m" (*(ptr)): "0" (*(ptr)));			\
+})
+
+#define atomic_dec( ptr ) ({					\
+	asm volatile ("subq.l #1,%0"				\
+		: "=m" (*(ptr)): "0" (*(ptr)));			\
+})
+
+#define atomic_dec_test( ptr ) ({				\
+	unsigned char res;					\
+								\
+	asm volatile ( "subq.l #1,%1; seq %0"			\
+		: "=d" (res), "=m" (*(ptr)) : "0" (*(ptr)) );	\
+	res != 0;						\
+})
+
+
+#define atomic_add( ptr, val ) ({				\
+	asm volatile ( "add.l %1,%0": "=m" (*(ptr))		\
+		: "d" (val), "0" (*(ptr)) );			\
+})
+
+#define atomic_sub( ptr, val ) ({				\
+	asm volatile ( "sub.l %1,%0": "=m" (*(ptr))		\
+		: "d" (val), "0" (*(ptr)) );			\
+})
+#endif
+
+#define atomic_do_setmask( ptr, mask ) ({			\
+	asm volatile ( "or.l %1,%0": "=m" (*(ptr))		\
+		: "d" (mask), "0" (*(ptr)) );			\
+})
+
+#define atomic_do_clrmask( ptr, mask ) ({			\
+	asm volatile ( "and.l %1,%0": "=m" (*(ptr))		\
+		: "d" (~(mask)), "0" (*(ptr)) );		\
+})
+
+#define atomic_do_chgmask( ptr, mask ) ({			\
+	asm volatile ( "xor.l %1,%0": "=m" (*(ptr))		\
+		: "d" (mask), "0" (*(ptr)) );			\
+})
+
+#define atomic_do_setbit( ptr, bit ) ({				\
+	unsigned char *__ptr;					\
+								\
+	__ptr = (unsigned char *)(ptr) + (3 - (bit >> 3));	\
+	asm volatile ( "bset %1,%0": "=m" (*(__ptr))		\
+		: "id" (bit & 7), "0" (*(__ptr)) );		\
+})
+
+#define atomic_do_clrbit( ptr, bit ) ({				\
+	unsigned char *__ptr;					\
+								\
+	__ptr = (unsigned char *)(ptr) + (3 - (bit >> 3));	\
+	asm volatile ( "bclr %1,%0": "=m" (*(__ptr))		\
+		: "id" (bit & 7), "0" (*(__ptr)) );		\
+})
+
+#define atomic_do_chgbit( ptr, bit ) ({				\
+	unsigned char *__ptr;					\
+								\
+	__ptr = (unsigned char *)(ptr) + (3 - (bit >> 3));	\
+	asm volatile ( "bchg %1,%0": "=m" (*(__ptr))		\
+		: "id" (bit & 7), "0" (*(__ptr)) );		\
+})
+
+#define atomic_do_test_setmask( ptr, mask ) ({			\
+	unsigned char __res;					\
+								\
+	asm volatile ( "or.l %2,%1; sne %0"			\
+		: "=r" (__res), "=m" (*(ptr))			\
+		: "id" (mask), "1" (*(ptr)) );			\
+	__res;							\
+})
+
+#define atomic_do_test_clrmask( ptr, mask ) ({			\
+	unsigned char __res;					\
+								\
+	asm volatile ( "and.l %2,%1; sne %0"			\
+		: "=r" (__res), "=m" (*(ptr))			\
+		: "id" (~(mask)), "1" (*(ptr)) );		\
+	__res;							\
+})
+
+#define atomic_do_test_chgmask( ptr, mask ) ({			\
+	unsigned char __res;					\
+								\
+	asm volatile ( "xor.l %2,%1; sne %0"			\
+		: "=r" (__res), "=m" (*(ptr))			\
+		: "id" (mask), "1" (*(ptr)) );			\
+	__res;							\
+})
+
+#define atomic_do_test_setbit( ptr, bit ) ({			\
+	unsigned char *__ptr, __res;				\
+								\
+	__ptr = (unsigned char *)(ptr) + (3 - (bit >> 3));	\
+	asm volatile ( "bset %2,%1; sne %0"			\
+		: "=r" (__res), "=m" (*(__ptr))			\
+		: "id" (bit & 7), "1" (*(__ptr)) );		\
+	__res;							\
+})
+
+#define atomic_do_test_clrbit( ptr, bit ) ({			\
+	unsigned char *__ptr, __res;				\
+								\
+	__ptr = (unsigned char *)(ptr) + (3 - (bit >> 3));	\
+	asm volatile ( "bclr %2,%1; sne %0"			\
+		: "=r" (__res), "=m" (*(__ptr))			\
+		: "id" (bit & 7), "1" (*(__ptr)) );		\
+	__res;							\
+})
+
+#define atomic_do_test_chgbit( ptr, bit ) ({			\
+	unsigned char *__ptr, __res;				\
+								\
+	__ptr = (unsigned char *)(ptr) + (3 - (bit >> 3));	\
+	asm volatile ( "bchg %2,%1; sne %0"			\
+		: "=r" (__res), "=m" (*(__ptr))			\
+		: "id" (bit & 7), "1" (*(__ptr)) );		\
+	__res;							\
+})
+
+#endif /* __SMP__ */
+
+#endif /* _ASM_M68K_ATOMIC_H */
Index: linux-2.1/include/asm-m68k/entry.h
diff -u linux-2.1/include/asm-m68k/entry.h:1.1.1.2.6.2 linux-2.1/include/asm-m68k/entry.h:1.1.1.2.6.2.2.1
--- linux-2.1/include/asm-m68k/entry.h:1.1.1.2.6.2	Sat Dec 19 18:52:03 1998
+++ linux-2.1/include/asm-m68k/entry.h	Sat Dec 19 21:28:58 1998
@@ -1,7 +1,11 @@
 #ifndef __M68K_ENTRY_H
 #define __M68K_ENTRY_H
 
-#include <linux/config.h>
+#include <config/atari.h>
+#ifdef CONFIG_ATARI
+#include <config/hades.h>
+#endif
+#include <config/kgdb.h>
 #include <asm/setup.h>
 #ifdef CONFIG_KGDB
 #include <asm/kgdb.h>
@@ -37,25 +41,8 @@
 
 #define curptr a2
 
-/*
- * these are offsets into the task-struct
- */
-LTASK_STATE	 =  0
-LTASK_FLAGS	 =  4
-LTASK_SIGPENDING =  8
-LTASK_ADDRLIMIT	 = 12
-LTASK_EXECDOMAIN = 16
-LTASK_NEEDRESCHED = 20
-
-LTSS_KSP	= 0
-LTSS_USP	= 4
-LTSS_SR		= 8
-LTSS_FS		= 10
-LTSS_CRP	= 12
-LTSS_FPCTXT	= 24
-
 /* the following macro is used when enabling interrupts */
-#if defined(CONFIG_ATARI_ONLY) && !defined(CONFIG_HADES)
+#if defined(MACH_ATARI_ONLY) && !defined(CONFIG_HADES)
 	/* block out HSYNC on the atari */
 #define ALLOWINT 0xfbff
 #define	MAX_NOINT_IPL	3
@@ -65,22 +52,20 @@
 #define	MAX_NOINT_IPL	0
 #endif /* machine compilation types */ 
 
-LPT_OFF_D0	  = 0x20
-LPT_OFF_ORIG_D0	  = 0x24
-LPT_OFF_SR	  = 0x2C
-LPT_OFF_FORMATVEC = 0x32
-
 LFLUSH_I_AND_D = 0x00000808
-LENOSYS = 38
 LSIGTRAP = 5
 
-LPF_TRACESYS_OFF = 3
-LPF_TRACESYS_BIT = 5
-LPF_PTRACED_OFF = 3
-LPF_PTRACED_BIT = 4
-LPF_DTRACE_OFF = 1
-LPF_DTRACE_BIT = 5
-
+/* process bits for task_struct.flags */
+PF_TRACESYS_OFF = 3
+PF_TRACESYS_BIT = 5
+PF_PTRACED_OFF = 3
+PF_PTRACED_BIT = 4
+PF_DTRACE_OFF = 1
+PF_DTRACE_BIT = 5
+
+#define SAVE_ALL_INT save_all_int
+#define SAVE_ALL_SYS save_all_sys
+#define RESTORE_ALL restore_all
 /*
  * This defines the normal kernel pt-regs layout.
  *
@@ -92,56 +77,68 @@
  * a -1 in the orig_d0 field signifies
  * that the stack frame is NOT for syscall
  */
-#define SAVE_ALL_INT				\
-	clrl	%sp@-;		/* stk_adj */	\
-	pea	-1:w;		/* orig d0 */	\
-	movel	%d0,%sp@-;	/* d0 */	\
+.macro	save_all_int
+	clrl	%sp@-		| stk_adj
+	pea	-1:w		| orig d0
+	movel	%d0,%sp@-	| d0
 	moveml	%d1-%d5/%a0-%a1/%curptr,%sp@-
+.endm
 
-#define SAVE_ALL_SYS				\
-	clrl	%sp@-;		/* stk_adj */	\
-	movel	%d0,%sp@-;	/* orig d0 */	\
-	movel	%d0,%sp@-;	/* d0 */	\
-	moveml  %d1-%d5/%a0-%a1/%curptr,%sp@-
+.macro	save_all_sys
+	clrl	%sp@-		| stk_adj
+	movel	%d0,%sp@-	| orig d0
+	movel	%d0,%sp@-	| d0
+	moveml	%d1-%d5/%a0-%a1/%curptr,%sp@-
+.endm
 #else
 /* Need to save the "missing" registers for kgdb...
  */
-#define SAVE_ALL_INT					\
-	clrl	%sp@-;		/* stk_adj */		\
-	pea	-1:w;		/* orig d0 */		\
-	movel	%d0,%sp@-;	/* d0 */		\
-	moveml	%d1-%d5/%a0-%a1/%curptr,%sp@-;		\
-	moveml	%d6-%d7,kgdb_registers+GDBOFFA_D6;	\
+.macro	save_all_int
+	clrl	%sp@-		| stk_adj
+	pea	-1:w		| orig d0
+	movel	%d0,%sp@-	| d0
+	moveml	%d1-%d5/%a0-%a1/%curptr,%sp@-
+	moveml	%d6-%d7,kgdb_registers+GDBOFFA_D6
 	moveml	%a3-%a6,kgdb_registers+GDBOFFA_A3
+.endm
 
-#define SAVE_ALL_SYS					\
-	clrl	%sp@-;		/* stk_adj */		\
-	movel	%d0,%sp@-;	/* orig d0 */		\
-	movel	%d0,%sp@-;	/* d0 */		\
-	moveml	%d1-%d5/%a0-%a1/%curptr,%sp@-;		\
-	moveml	%d6-%d7,kgdb_registers+GDBOFFA_D6;	\
+.macro	save_all_sys
+	clrl	%sp@-		| stk_adj
+	movel	%d0,%sp@-	| orig d0
+	movel	%d0,%sp@-	| d0
+	moveml	%d1-%d5/%a0-%a1/%curptr,%sp@-
+	moveml	%d6-%d7,kgdb_registers+GDBOFFA_D6
 	moveml	%a3-%a6,kgdb_registers+GDBOFFA_A3
+.endm
 #endif
 
-#define RESTORE_ALL			\
-	moveml	%sp@+,%a0-%a1/%curptr/%d1-%d5;	\
-	movel	%sp@+,%d0;		\
-	addql	#4,%sp;	 /* orig d0 */	\
-	addl	%sp@+,%sp; /* stk adj */	\
+.macro	restore_all
+	moveml	%sp@+,%a0-%a1/%curptr/%d1-%d5
+	movel	%sp@+,%d0
+	addql	#4,%sp		| orig d0
+	addl	%sp@+,%sp	| stk adj
 	rte
+.endm
 
 #define SWITCH_STACK_SIZE (6*4+4)	/* includes return address */
+
+#define SAVE_SWITCH_STACK save_switch_stack
+#define RESTORE_SWITCH_STACK restore_switch_stack
+#define GET_CURRENT(tmp) get_current tmp
 
-#define SAVE_SWITCH_STACK \
+.macro	save_switch_stack
 	moveml	%a3-%a6/%d6-%d7,%sp@-
+.endm
 
-#define RESTORE_SWITCH_STACK \
+.macro	restore_switch_stack
 	moveml	%sp@+,%a3-%a6/%d6-%d7
+.endm
 
-#define GET_CURRENT(tmp) \
-	movel	%sp,tmp; \
-	andw	&-8192,tmp; \
-	movel	tmp,%curptr;
+.macro	get_current reg=%d0
+	movel	%sp,\reg
+	andw	#-8192,\reg
+	movel	\reg,%curptr
+.endm
 
 #else /* C source */
 
Index: linux-2.1/include/asm-m68k/fpu.h
diff -u linux-2.1/include/asm-m68k/fpu.h:1.1.1.1.6.2 linux-2.1/include/asm-m68k/fpu.h:1.1.1.1.6.2.2.1
--- linux-2.1/include/asm-m68k/fpu.h:1.1.1.1.6.2	Sat Dec 19 18:52:06 1998
+++ linux-2.1/include/asm-m68k/fpu.h	Sat Dec 19 21:28:59 1998
@@ -1,7 +1,10 @@
 #ifndef __M68K_FPU_H
 #define __M68K_FPU_H
 
-#include <linux/config.h>
+#include <config/m68020.h>
+#include <config/m68030.h>
+#include <config/m68040.h>
+#include <config/m68060.h>
 
 /*
  * MAX floating point unit state size (FSAVE/FRESTORE)
Index: linux-2.1/include/asm-m68k/ide.h
diff -u linux-2.1/include/asm-m68k/ide.h:1.1.1.2.6.2 linux-2.1/include/asm-m68k/ide.h:1.1.1.2.6.2.2.1
--- linux-2.1/include/asm-m68k/ide.h:1.1.1.2.6.2	Sat Dec 19 18:52:07 1998
+++ linux-2.1/include/asm-m68k/ide.h	Sat Dec 19 21:29:00 1998
@@ -31,7 +31,9 @@
 
 #ifdef __KERNEL__
 
-#include <linux/config.h>
+#include <config/amiga.h>
+#include <config/atari.h>
+#include <config/mac.h>
 
 #include <asm/setup.h>
 #include <asm/io.h>
@@ -449,7 +451,7 @@
  * an interrupt, and in that case it does nothing. Hope that is reasonable and
  * works. (Roman)
  */
-#ifdef CONFIG_ATARI_ONLY
+#ifdef MACH_ATARI_ONLY
 #define	ide__sti()					\
     do {						\
 	if (!in_interrupt()) __sti();			\
Index: linux-2.1/include/asm-m68k/init.h
diff -u linux-2.1/include/asm-m68k/init.h:1.1.1.1.6.2 linux-2.1/include/asm-m68k/init.h:1.1.1.1.6.2.2.1
--- linux-2.1/include/asm-m68k/init.h:1.1.1.1.6.2	Sat Dec 19 18:52:08 1998
+++ linux-2.1/include/asm-m68k/init.h	Sat Dec 19 21:29:01 1998
@@ -1,7 +1,7 @@
 #ifndef _M68K_INIT_H
 #define _M68K_INIT_H
 
-#include <linux/config.h>
+#include <config/kgdb.h>
 
 #ifndef CONFIG_KGDB
 
Index: linux-2.1/include/asm-m68k/io.h
diff -u linux-2.1/include/asm-m68k/io.h:1.1.1.2.6.2 linux-2.1/include/asm-m68k/io.h:1.1.1.2.6.2.2.1
--- linux-2.1/include/asm-m68k/io.h:1.1.1.2.6.2	Sat Dec 19 18:52:09 1998
+++ linux-2.1/include/asm-m68k/io.h	Sat Dec 19 21:29:02 1998
@@ -3,7 +3,7 @@
 
 #ifdef __KERNEL__
 
-#include <linux/config.h>
+#include <config/atari.h>
 
 #ifdef CONFIG_ATARI
 #include <asm/atarihw.h>
Index: linux-2.1/include/asm-m68k/irq.h
diff -u linux-2.1/include/asm-m68k/irq.h:1.1.1.1.6.2 linux-2.1/include/asm-m68k/irq.h:1.1.1.1.6.2.2.1
--- linux-2.1/include/asm-m68k/irq.h:1.1.1.1.6.2	Sat Dec 19 18:52:10 1998
+++ linux-2.1/include/asm-m68k/irq.h	Sat Dec 19 21:29:03 1998
@@ -1,49 +1,56 @@
 #ifndef _M68K_IRQ_H_
 #define _M68K_IRQ_H_
 
-#include <linux/config.h>
+#ifndef __ASSEMBLY__
+#include <asm/machdep.h>
+#endif
+#include <config/amiga.h>
+#include <config/atari.h>
 
 /*
- * # of m68k interrupts
+ * # of auto and user vector m68k interrupts. This number is used for kstat, so
+ * the first 8 are always the autovector interrupts, the rest is machine
+ * specific. It can be either the # of used vector interrupts or the # of other
+ * interrupt sources. The highest value wins if compiled for several machines.
  */
 
-#define SYS_IRQS 8
+#define AUTO_IRQ_NR 8
 
-/*
- * This should be the same as the max(NUM_X_SOURCES) for all the
- * different m68k hosts compiled into the kernel.
- * Currently the Atari has 72 and the Amiga 24, but if both are
- * supported in the kernel it is better to make room for 72.
- */
 #if defined(CONFIG_ATARI)
-#define NR_IRQS (72+SYS_IRQS)
+#define USER_IRQ_NR 72
+#elif defined(CONFIG_AMIGA)
+#define USER_IRQ_NR 24
 #else
-#define NR_IRQS (24+SYS_IRQS)
+#define USER_IRQ_NR 0
 #endif
 
 /*
- * Interrupt source definitions
- * General interrupt sources are the level 1-7.
- * Adding an interrupt service routine for one of these sources
- * results in the addition of that routine to a chain of routines.
- * Each one is called in succession.  Each individual interrupt
- * service routine should determine if the device associated with
- * that routine requires service.
+ * This should be the same as the max(NUM_X_SOURCES) for all the
+ * different m68k hosts compiled into the kernel.
  */
 
-#define IRQ1		(1)	/* level 1 interrupt */
-#define IRQ2		(2)	/* level 2 interrupt */
-#define IRQ3		(3)	/* level 3 interrupt */
-#define IRQ4		(4)	/* level 4 interrupt */
-#define IRQ5		(5)	/* level 5 interrupt */
-#define IRQ6		(6)	/* level 6 interrupt */
-#define IRQ7		(7)	/* level 7 interrupt (non-maskable) */
+#define NR_IRQS (AUTO_IRQ_NR+USER_IRQ_NR)
 
 /*
- * "Generic" interrupt sources
+ * This defines the compiled in interrupt support
  */
+
+#define NEED_AUTO_IRQ
+#if 0
+#define NEED_AUTO_IRQ_STD_HANDLER
+#define NEED_AUTO_IRQ_STD_LISTHANDLER
+#endif
+
+#define NEED_USER_IRQ
+#if 0
+#define NEED_USER_IRQ_STD_HANDLER
+#define NEED_USER_IRQ_STD_LISTHANDLER
+#endif
+
+#define NEED_SINGLE_IRQ
+#define NEED_LIST_IRQ
 
-#define IRQ_SCHED_TIMER	(8)    /* interrupt source for scheduling timer */
+#ifndef __ASSEMBLY__
 
 static __inline__ int irq_cannonicalize(int irq)
 {
@@ -67,13 +74,10 @@
  *                                                      01/11/97 - Jes
  */
 
+#ifndef NO_MACH_DEFS
 extern void (*enable_irq)(unsigned int);
 extern void (*disable_irq)(unsigned int);
-
-extern int sys_request_irq(unsigned int, 
-	void (*)(int, void *, struct pt_regs *), 
-	unsigned long, const char *, void *);
-extern void sys_free_irq(unsigned int, void *);
+#endif
 
 /*
  * various flags for request_irq()
@@ -82,6 +86,7 @@
 #define IRQ_FLG_REPLACE	(0x0002)	/* replace existing handler	*/
 #define IRQ_FLG_FAST	(0x0004)
 #define IRQ_FLG_SLOW	(0x0008)
+#define IRQ_FLG_REALTIME (0x0010)
 #define IRQ_FLG_STD	(0x8000)	/* internally used		*/
 
 /*
@@ -96,22 +101,26 @@
 	struct irq_node *next;
 } irq_node_t;
 
-/*
- * This structure has only 4 elements for speed reasons
- */
-typedef struct irq_handler {
-	void		(*handler)(int, void *, struct pt_regs *);
-	unsigned long	flags;
-	void		*dev_id;
-	const char	*devname;
-} irq_handler_t;
+extern int sys_request_irq(unsigned int, void (*)(int, void *, struct pt_regs *), 
+                           unsigned long, const char *, void *);
+extern int sys_request_listirq(unsigned int, void (*)(int, void *, struct pt_regs *), 
+                               unsigned long, const char *, void *);
+extern void sys_free_irq(unsigned int, void *);
+
+extern irq_node_t *autoirq_list[];
+extern irq_node_t *autoirq_softlist[];
+extern irq_node_t *userirq_list[];
+extern irq_node_t *userirq_softlist[];
 
 /* count of spurious interrupts */
 extern volatile unsigned int num_spurious;
+extern void bad_interrupt(void);
 
 /*
  * This function returns a new irq_node_t
  */
 extern irq_node_t *new_irq_node(void);
+extern void free_irq_node(irq_node_t *);
+#endif
 
 #endif /* _M68K_IRQ_H_ */
Index: linux-2.1/include/asm-m68k/keyboard.h
diff -u linux-2.1/include/asm-m68k/keyboard.h:1.1.1.2.6.2 linux-2.1/include/asm-m68k/keyboard.h:1.1.1.2.6.2.2.1
--- linux-2.1/include/asm-m68k/keyboard.h:1.1.1.2.6.2	Sat Dec 19 18:52:11 1998
+++ linux-2.1/include/asm-m68k/keyboard.h	Sat Dec 19 21:29:04 1998
@@ -8,10 +8,11 @@
  *  This file contains the m68k architecture specific keyboard definitions
  */
 
-#include <linux/config.h> /* CONFIG_MAGIC_SYSRQ */
 #ifndef __M68K_KEYBOARD_H
 #define __M68K_KEYBOARD_H
 
+#include <config/magic/sysrq.h>
+
 #ifdef __KERNEL__
 
 #include <asm/machdep.h>
@@ -52,9 +53,9 @@
 
 #ifdef CONFIG_MAGIC_SYSRQ
 #define kbd_is_sysrq(keycode)	((keycode) == mach_sysrq_key && \
-								 (up_flag || \
-								  (shift_state & mach_sysrq_shift_mask) == \
-								  mach_sysrq_shift_state))
+				 (up_flag || \
+				  (shift_state & mach_sysrq_shift_mask) == \
+				  mach_sysrq_shift_state))
 #define kbd_sysrq_xlate			mach_sysrq_xlate
 #endif
 
Index: linux-2.1/include/asm-m68k/linux_logo.h
diff -u linux-2.1/include/asm-m68k/linux_logo.h:1.1.1.4.6.2 linux-2.1/include/asm-m68k/linux_logo.h:1.1.1.4.6.2.2.1
--- linux-2.1/include/asm-m68k/linux_logo.h:1.1.1.4.6.2	Sat Dec 19 18:52:12 1998
+++ linux-2.1/include/asm-m68k/linux_logo.h	Sat Dec 19 21:29:20 1998
@@ -18,9 +18,9 @@
  * but should contain %s to display the version
  */
  
-#include <linux/config.h>
 #include <linux/init.h>
 #include <linux/version.h>
+#include <config/mac.h>
 
 #define linux_logo_banner "Linux/m68k version " UTS_RELEASE
 
Index: linux-2.1/include/asm-m68k/machdep.h
diff -u linux-2.1/include/asm-m68k/machdep.h:1.1.1.3.6.2 linux-2.1/include/asm-m68k/machdep.h:1.1.1.3.6.2.2.1
--- linux-2.1/include/asm-m68k/machdep.h:1.1.1.3.6.2	Sat Dec 19 18:52:13 1998
+++ linux-2.1/include/asm-m68k/machdep.h	Sat Dec 19 21:29:21 1998
@@ -8,22 +8,26 @@
 struct gendisk;
 struct buffer_head;
 
+#include <asm/amigadep.h>
+
+#ifndef NO_MACH_DEFS
 extern void (*mach_sched_init) (void (*handler)(int, void *, struct pt_regs *));
 /* machine dependent keyboard functions */
 extern int (*mach_keyb_init) (void);
 extern int (*mach_kbdrate) (struct kbd_repeat *);
+#endif
 extern void (*mach_kbd_leds) (unsigned int);
-extern void (*kbd_reset_setup) (char *, int);
+extern void (*mach_get_model) (char *model);
+extern int (*mach_get_hardware_list) (char *buffer);
+#ifndef NO_MACH_DEFS
 /* machine dependent irq functions */
 extern void (*mach_init_IRQ) (void);
-extern void (*(*mach_default_handler)[]) (int, void *, struct pt_regs *);
 extern int (*mach_request_irq) (unsigned int irq, void (*handler)(int, void *, struct pt_regs *),
                                 unsigned long flags, const char *devname, void *dev_id);
 extern void (*mach_free_irq) (unsigned int irq, void *dev_id);
-extern void (*mach_get_model) (char *model);
-extern int (*mach_get_hardware_list) (char *buffer);
+extern void (*mach_do_irqrequest) (void);
+#endif
 extern int (*mach_get_irq_list) (char *buf);
-extern void (*mach_process_int) (int irq, struct pt_regs *fp);
 /* machine dependent timer functions */
 extern unsigned long (*mach_gettimeoffset)(void);
 extern void (*mach_gettod)(int *year, int *mon, int *day, int *hour,
@@ -31,8 +35,6 @@
 extern int (*mach_hwclk)(int, struct hwclk_time*);
 extern int (*mach_set_clock_mmss)(unsigned long);
 extern void (*mach_reset)( void );
-extern unsigned long (*mach_hd_init) (unsigned long, unsigned long);
-extern void (*mach_hd_setup)(char *, int *);
 extern long mach_max_dma_address;
 extern void (*mach_floppy_setup)(char *, int *);
 extern void (*mach_floppy_eject)(void);
Index: linux-2.1/include/asm-m68k/page.h
diff -u linux-2.1/include/asm-m68k/page.h:1.1.1.1.6.2 linux-2.1/include/asm-m68k/page.h:1.1.1.1.6.2.2.1
--- linux-2.1/include/asm-m68k/page.h:1.1.1.1.6.2	Sat Dec 19 18:52:14 1998
+++ linux-2.1/include/asm-m68k/page.h	Sat Dec 19 21:29:22 1998
@@ -8,7 +8,7 @@
 
 #ifdef __KERNEL__
 
-#include<linux/config.h>
+#include <asm/setup.h>
 
 #define STRICT_MM_TYPECHECKS
 
@@ -18,7 +18,7 @@
 /*
  * We don't need to check for alignment etc.
  */
-#if defined(CONFIG_OPTIMIZE_040) || defined(CONFIG_OPTIMIZE_060)
+#ifdef CPU_M68040_OR_M68060_ONLY
 static inline void copy_page(unsigned long to, unsigned long from)
 {
   unsigned long tmp;
Index: linux-2.1/include/asm-m68k/pgtable.h
diff -u linux-2.1/include/asm-m68k/pgtable.h:1.1.1.5.4.3 linux-2.1/include/asm-m68k/pgtable.h:1.1.1.5.4.3.2.2
--- linux-2.1/include/asm-m68k/pgtable.h:1.1.1.5.4.3	Sat Dec 19 18:52:15 1998
+++ linux-2.1/include/asm-m68k/pgtable.h	Sun Dec 20 01:29:33 1998
@@ -1,8 +1,17 @@
 #ifndef _M68K_PGTABLE_H
 #define _M68K_PGTABLE_H
 
-#include <linux/config.h>
 #include <asm/setup.h>
+#include <config/advanced.h>
+#include <config/vme.h>
+#include <config/m68060.h>
+#ifdef CONFIG_ADVANCED
+#include <config/single/memory/chunk.h>
+#endif
+#if (defined(CONFIG_VME) && defined(CONFIG_M68060)) || \
+    (!defined(CONFIG_VME) && defined(CONFIG_M68060) && defined(CONFIG_ADVANCED))
+#include <config/060/writethrough.h>
+#endif
 
 #ifndef __ASSEMBLY__
 #include <asm/processor.h>
@@ -442,16 +451,6 @@
 		pmdp->pmd[i] = _PAGE_TABLE | _PAGE_ACCESSED | (unsigned long)ptep;
 }
 
-/* early termination version of the above */
-extern inline void pmd_set_et(pmd_t * pmdp, pte_t * ptep)
-{
-	int i;
-
-	ptep = (pte_t *) virt_to_phys(ptep);
-	for (i = 0; i < 16; i++, ptep += PTRS_PER_PTE/16)
-		pmdp->pmd[i] = _PAGE_PRESENT | _PAGE_ACCESSED | (unsigned long)ptep;
-}
-
 extern inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
 { pgd_val(*pgdp) = _PAGE_TABLE | _PAGE_ACCESSED | virt_to_phys(pmdp); }
 
@@ -547,7 +546,7 @@
 	return mm->pgd + (address >> PGDIR_SHIFT);
 }
 
-extern pgd_t swapper_pg_dir[128];
+#define swapper_pg_dir kernel_pg_dir
 extern pgd_t kernel_pg_dir[128];
 
 extern inline pgd_t * pgd_offset_k(unsigned long address)
@@ -625,7 +624,7 @@
 
 extern pmd_t *get_pointer_table(void);
 extern int free_pointer_table(pmd_t *);
-extern pmd_t *get_kpointer_table(void);
+extern pmd_t *get_kpointer_table(unsigned long *memavailp);
 extern void free_kpointer_table(pmd_t *);
 
 extern __inline__ pte_t *get_pte_fast(void)
@@ -761,7 +760,7 @@
 {
 	address = (address >> PMD_SHIFT) & (PTRS_PER_PMD - 1);
 	if (pgd_none(*pgd)) {
-		pmd_t *page = get_kpointer_table();
+		pmd_t *page = get_kpointer_table(NULL);
 		if (pgd_none(*pgd)) {
 			if (page) {
 				pgd_set(pgd, page);
Index: linux-2.1/include/asm-m68k/semaphore.h
diff -u linux-2.1/include/asm-m68k/semaphore.h:1.1.1.1.6.3 linux-2.1/include/asm-m68k/semaphore.h:1.1.1.1.6.3.2.1
--- linux-2.1/include/asm-m68k/semaphore.h:1.1.1.1.6.3	Sat Dec 19 18:52:16 1998
+++ linux-2.1/include/asm-m68k/semaphore.h	Sat Dec 19 21:29:24 1998
@@ -1,10 +1,13 @@
 #ifndef _M68K_SEMAPHORE_H
 #define _M68K_SEMAPHORE_H
 
-#include <linux/config.h>
 #include <linux/linkage.h>
 #include <asm/system.h>
 #include <asm/atomic.h>
+#include <config/advanced.h>
+#ifdef CONFIG_ADVANCED
+#include <config/rmw/insns.h>
+#endif
 
 /*
  * SMP- and interrupt-safe semaphores..
Index: linux-2.1/include/asm-m68k/serial.h
diff -u linux-2.1/include/asm-m68k/serial.h:1.1.1.2.6.2 linux-2.1/include/asm-m68k/serial.h:1.1.1.2.6.2.2.2
--- linux-2.1/include/asm-m68k/serial.h:1.1.1.2.6.2	Sat Dec 19 18:52:17 1998
+++ linux-2.1/include/asm-m68k/serial.h	Sun Dec 20 16:11:54 1998
@@ -195,7 +195,7 @@
 #include <linux/termios.h>
 #include <linux/tqueue.h>
 
-#include <linux/config.h>	/* for Mac SCC extensions */
+#include <config/mac.h>
 
 #ifdef CONFIG_MAC
 #define NUM_ZSREGS    16
@@ -332,10 +332,12 @@
 					    int ch, int err )
 {
 	struct tty_struct *tty = info->tty;
-	
-	if (tty->flip.count >= TTY_FLIPBUF_SIZE)
+	int push = tty->flip.push;
+	int count = tty->flip.count;
+
+	if (count++ >= TTY_FLIPBUF_SIZE)
 		return;
-	tty->flip.count++;
+	tty->flip.count = count;
 	switch(err) {
 	case TTY_BREAK:
 		info->icount.brk++;
@@ -352,8 +354,9 @@
 		info->icount.frame++;
 		break;
 	}
-	*tty->flip.flag_buf_ptr++ = err;
-	*tty->flip.char_buf_ptr++ = ch;
+	tty->flip.flag_buf[push] = err;
+	tty->flip.char_buf[push] = ch;
+	tty->flip.push = (push + 1) & (TTY_FLIPBUF_SIZE - 1);
 	info->icount.rx++;
 	tty_flip_buffer_push(tty);
 }
Index: linux-2.1/include/asm-m68k/setup.h
diff -u linux-2.1/include/asm-m68k/setup.h:1.1.1.2.6.2 linux-2.1/include/asm-m68k/setup.h:1.1.1.2.6.2.2.1
--- linux-2.1/include/asm-m68k/setup.h:1.1.1.2.6.2	Sat Dec 19 18:52:18 1998
+++ linux-2.1/include/asm-m68k/setup.h	Sat Dec 19 21:29:26 1998
@@ -23,8 +23,30 @@
 #ifndef _M68K_SETUP_H
 #define _M68K_SETUP_H
 
-#include <linux/config.h>
-
+#include <config/amiga.h>
+#include <config/apollo.h>
+#include <config/atari.h>
+#include <config/hp300.h>
+#include <config/mac.h>
+#include <config/sun3.h>
+#include <config/vme.h>
+#ifdef CONFIG_VME
+#include <config/bvme6000.h>
+#include <config/mvme16x.h>
+#endif
+
+#include <config/m68020.h>
+#include <config/m68030.h>
+#include <config/m68040.h>
+#include <config/m68060.h>
+
+#include <config/experimental.h>
+#ifdef CONFIG_EXPERIMENTAL
+#include <config/math/emu.h>
+#ifdef CONFIG_MATH_EMU
+#include <config/math/emu/only.h>
+#endif
+#endif
 
     /*
      *  Linux/m68k Architectures
@@ -52,7 +74,7 @@
 	|| defined(CONFIG_MVME16x) || defined(CONFIG_BVME6000) || defined(CONFIG_HP300)
 #  define MACH_IS_AMIGA (m68k_machtype == MACH_AMIGA)
 #else
-#  define CONFIG_AMIGA_ONLY
+#  define MACH_AMIGA_ONLY
 #  define MACH_IS_AMIGA (1)
 #  define MACH_TYPE (MACH_AMIGA)
 #endif
@@ -63,7 +85,7 @@
 	|| defined(CONFIG_MVME16x) || defined(CONFIG_BVME6000) || defined(CONFIG_HP300)
 #  define MACH_IS_ATARI (m68k_machtype == MACH_ATARI)
 #else
-#  define CONFIG_ATARI_ONLY
+#  define MACH_ATARI_ONLY
 #  define MACH_IS_ATARI (1)
 #  define MACH_TYPE (MACH_ATARI)
 #endif
@@ -74,7 +96,7 @@
 	|| defined(CONFIG_HP300) || defined(CONFIG_MVME16x) || defined(CONFIG_BVME6000)
 #  define MACH_IS_MAC (m68k_machtype == MACH_MAC)
 #else
-#  define CONFIG_MAC_ONLY
+#  define MACH_MAC_ONLY
 #  define MACH_IS_MAC (1)
 #  define MACH_TYPE (MACH_MAC)
 #endif
@@ -91,7 +113,7 @@
 	|| defined(CONFIG_MVME16x) || defined(CONFIG_BVME6000) || defined(CONFIG_HP300)
 #  define MACH_IS_APOLLO (m68k_machtype == MACH_APOLLO)
 #else
-#  define CONFIG_APOLLO_ONLY
+#  define MACH_APOLLO_ONLY
 #  define MACH_IS_APOLLO (1)
 #  define MACH_TYPE (MACH_APOLLO)
 #endif
@@ -102,7 +124,7 @@
 	|| defined(CONFIG_APOLLO) || defined(CONFIG_BVME6000) || defined(CONFIG_HP300)
 #  define MACH_IS_MVME16x (m68k_machtype == MACH_MVME16x)
 #else
-#  define CONFIG_MVME16x_ONLY
+#  define MACH_MVME16x_ONLY
 #  define MACH_IS_MVME16x (1)
 #  define MACH_TYPE (MACH_MVME16x)
 #endif
@@ -113,7 +135,7 @@
 	|| defined(CONFIG_APOLLO) || defined(CONFIG_MVME16x) || defined(CONFIG_HP300)
 #  define MACH_IS_BVME6000 (m68k_machtype == MACH_BVME6000)
 #else
-#  define CONFIG_BVME6000_ONLY
+#  define MACH_BVME6000_ONLY
 #  define MACH_IS_BVME6000 (1)
 #  define MACH_TYPE (MACH_BVME6000)
 #endif
@@ -124,7 +146,7 @@
 	|| defined(CONFIG_APOLLO) || defined(CONFIG_MVME16x) || defined(CONFIG_BVME6000)
 #  define MAC_IS_HP300 (m68k_machtype == MACH_HP300)
 #else
-#  define CONFIG_HP300_ONLY
+#  define MACH_HP300_ONLY
 #  define MACH_IS_HP300 (1)
 #  define MACH_TYPE (MACH_HP300)
 #endif
@@ -259,6 +281,17 @@
 #endif
 
 #define CPU_TYPE (m68k_cputype)
+
+#ifdef CONFIG_MATH_EMU
+#  ifdef CONFIG_MATH_EMU_ONLY
+#    define FPU_IS_EMU (1)
+#  else
+#    define FPU_IS_EMU (m68k_fputype)
+#  endif
+#else
+#  define FPU_IS_EMU (0)
+#endif
+
 
     /*
      *  Miscellaneous
Index: linux-2.1/include/asm-m68k/system.h
diff -u linux-2.1/include/asm-m68k/system.h:1.1.1.1.6.2 linux-2.1/include/asm-m68k/system.h:1.1.1.1.6.2.2.1
--- linux-2.1/include/asm-m68k/system.h:1.1.1.1.6.2	Sat Dec 19 18:52:19 1998
+++ linux-2.1/include/asm-m68k/system.h	Sat Dec 19 21:29:27 1998
@@ -1,9 +1,18 @@
 #ifndef _M68K_SYSTEM_H
 #define _M68K_SYSTEM_H
 
-#include <linux/config.h> /* get configuration macros */
 #include <linux/linkage.h>
 #include <asm/segment.h>
+#include <asm/setup.h>
+#include <config/atari.h>
+#ifdef CONFIG_ATARI
+#include <config/hades.h>
+#endif
+#include <config/advanced.h>
+#ifdef CONFIG_ADVANCED
+#include <config/rt/interrupt.h>
+#include <config/rmw/insns.h>
+#endif
 
 extern inline unsigned long rdusp(void) {
   	unsigned long usp;
@@ -46,11 +55,8 @@
 #define switch_to(prev,next) { \
   register void *_prev __asm__ ("a0") = (prev); \
   register void *_next __asm__ ("a1") = (next); \
-  register int _tssoff __asm__ ("d1") = (int)&((struct task_struct *)0)->tss; \
-  register char _shared __asm__ ("d2") = ((prev)->mm == (next)->mm); \
-  __asm__ __volatile__("jbsr " SYMBOL_NAME_STR(resume) "\n\t" \
-		       : : "a" (_prev), "a" (_next), "d" (_tssoff), \
-		           "d" (_shared) \
+  __asm__ __volatile__("jbsr " SYMBOL_NAME_STR(resume) \
+		       : : "a" (_prev), "a" (_next) \
 		       : "d0", "d1", "d2", "d3", "d4", "d5", "a0", "a1"); \
 }
 
@@ -60,7 +66,7 @@
 struct __xchg_dummy { unsigned long a[100]; };
 #define __xg(x) ((volatile struct __xchg_dummy *)(x))
 
-#if defined(CONFIG_ATARI) && !defined(CONFIG_AMIGA) && !defined(CONFIG_MAC) && !defined(CONFIG_HADES) && !defined(CONFIG_VME) && !defined(CONFIG_APOLLO)
+#if defined(MACH_ATARI_ONLY) && !defined(CONFIG_HADES)
 /* block out HSYNC on the atari */
 #define __sti() __asm__ __volatile__ ("andiw #0xfbff,%/sr": : : "memory")
 #else /* portable version */
@@ -76,19 +82,81 @@
 #define __restore_flags(x) \
 __asm__ __volatile__("movew %0,%/sr": /* no outputs */ :"d" (x) : "memory")
 
+#ifdef CONFIG_RT_INTERRUPT
+
+#include <linux/stddef.h>
+#include <asm/ptrace.h>
+#include <linux/linkage.h>
+#include <linux/smp.h>
+#include <linux/interrupt.h>
+#include <asm/machdep.h>
+#include <asm/atomic.h>
+
+extern void do_rt_request(void);
+extern unsigned int rt_irqrequest;
+extern unsigned int soft_irq_count;
+
+#ifndef __DOREQUEST
+#ifdef mach_do_irqrequest
+#define __DOREALREQUEST(label) SYMBOL_NAME_STR(label)
+#define __DOREQUEST __DOREALREQUEST(mach_do_irqrequest)
+#else
+#define __DOREQUEST "@("SYMBOL_NAME_STR(mach_do_irqrequest)")@(0)"
+#endif
+#endif
+
+#define cli() ({				\
+	if (soft_irq_count == ~0)		\
+		soft_irq_count = 0;		\
+})
+#define sti() ({				\
+	if (!in_interrupt())			\
+		asm volatile (			\
+		  "	subql	#1,%0\n"	\
+		  "	jcs	1f\n"		\
+		  "	jbsr	"__DOREQUEST"\n"\
+		  "1:"				\
+		  : "=m" (soft_irq_count)	\
+		  : "0" (soft_irq_count)	\
+		  : "d0", "d1", "a0", "a1",	\
+		    "cc", "memory");		\
+	__sti();				\
+})
+#define save_flags(x) ({ (x) = soft_irq_count; })
+#define restore_flags(x) ({			\
+	if ((x) == ~0 && soft_irq_count != ~0)	\
+		asm volatile (			\
+		  "	subql	#1,%0\n"	\
+		  "	jcs	1f\n"		\
+		  "	jbsr	"__DOREQUEST"\n"\
+		  "1:"				\
+		  : "=m" (soft_irq_count)	\
+		  : "0" (soft_irq_count)	\
+		  : "d0", "d1", "a0", "a1",	\
+		    "cc", "memory");		\
+})
+#define save_and_cli(x) ({			\
+	save_flags(x);				\
+	cli();					\
+})
+
+#else
+
 #define cli() __cli()
 #define sti() __sti()
 #define save_flags(x) __save_flags(x)
 #define restore_flags(x) __restore_flags(x)
 #define save_and_cli(flags)   do { save_flags(flags); cli(); } while(0)
 
+#endif
+
 #ifndef CONFIG_RMW_INSNS
 static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
 {
   unsigned long tmp, flags;
 
-  save_flags(flags);
-  cli();
+  __save_flags(flags);
+  __cli();
 
   switch (size) {
   case 1:
@@ -110,7 +178,7 @@
     : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
     break;
   }
-  restore_flags(flags);
+  __restore_flags(flags);
   return tmp;
 }
 #else
Index: linux-2.1/include/asm-m68k/traps.h
diff -u linux-2.1/include/asm-m68k/traps.h:1.1.1.1.6.2 linux-2.1/include/asm-m68k/traps.h:1.1.1.1.6.2.2.1
--- linux-2.1/include/asm-m68k/traps.h:1.1.1.1.6.2	Sat Dec 19 18:52:20 1998
+++ linux-2.1/include/asm-m68k/traps.h	Sat Dec 19 21:29:28 1998
@@ -11,10 +11,14 @@
 #ifndef _M68K_TRAPS_H
 #define _M68K_TRAPS_H
 
+#ifndef __ASSEMBLY__
+
 typedef void (*e_vector)(void);
 
 extern e_vector vectors[];
 
+#endif
+
 #define VEC_BUSERR  (2)
 #define VEC_ADDRERR (3)
 #define VEC_ILLEGAL (4)
@@ -63,9 +67,12 @@
 #define VEC_FPUNSUP (55)
 #define	VEC_UNIMPEA (60)
 #define	VEC_UNIMPII (61)
+#define VEC_USER    (64)
 
 #define VECOFF(vec) ((vec)<<2)
 
+#ifndef __ASSEMBLY__
+
 /* Status register bits */
 #define PS_T  (0x8000)
 #define PS_S  (0x2000)
@@ -237,5 +244,7 @@
 	    } fmtb;
     } un;
 };
+
+#endif /* __ASSEMBLY__ */
 
 #endif /* _M68K_TRAPS_H */
Index: linux-2.1/include/asm-m68k/virtconvert.h
diff -u linux-2.1/include/asm-m68k/virtconvert.h:1.1.1.1.6.2 linux-2.1/include/asm-m68k/virtconvert.h:1.1.1.1.6.2.2.1
--- linux-2.1/include/asm-m68k/virtconvert.h:1.1.1.1.6.2	Sat Dec 19 18:52:21 1998
+++ linux-2.1/include/asm-m68k/virtconvert.h	Sat Dec 19 21:29:29 1998
@@ -7,8 +7,16 @@
 
 #ifdef __KERNEL__
 
-#include <linux/config.h>
 #include <asm/setup.h>
+#include <config/amiga.h>
+#include <config/atari.h>
+#ifdef CONFIG_ATARI
+#include <config/hades.h>
+#endif
+#include <config/advanced.h>
+#ifdef CONFIG_ADVANCED
+#include <config/single/memory/chunk.h>
+#endif
 
 #ifdef CONFIG_AMIGA
 #include <asm/amigahw.h>
Index: linux-2.1/include/asm-ppc/atomic_new.h
diff -u /dev/null linux-2.1/include/asm-ppc/atomic_new.h:1.1.6.1
--- /dev/null	Sun Dec 20 19:22:09 1998
+++ linux-2.1/include/asm-ppc/atomic_new.h	Sun Dec 20 01:54:09 1998
@@ -0,0 +1,42 @@
+#ifndef _ASM_PPC_ATOMIC_H
+#define _ASM_PPC_ATOMIC_H
+
+#define __has_atomic_instr
+
+#ifdef __SMP__
+#define __SYNC	"sync; "
+#endif 
+
+#define __atomic_init( ptr, old )
+
+#define __atomic_reserve( ptr, old ) ({				\
+	asm volatile ( "lwarx %0,0,%1"				\
+		: "=r" (old) : "m" (*(ptr)) );			\
+})
+
+#define __atomic_update( ptr, old, new ) ({			\
+	unsigned int __res;					\
+	asm volatile ( __SYNC "stwcx. %2,0,%1; mfcr %0"		\
+		: "=r" (__res), "=m" (*(ptr))			\
+		: "r" (new) : "cc" );				\
+	__res & 0x20000000;					\
+})
+
+#define atomic_exchange( ptr, old, new ) ({			\
+	asm volatile ( "1: lwarx %0,0,%1"			\
+		: "=r" (old) : "m" (*(ptr)) );			\
+	asm volatile ( __SYNC "stwcx. %1,0,%0; bne- 1b"		\
+		: "=m" (*(ptr)) : "r" ((new)) : "cc" );		\
+})
+
+#define atomic_inserthead( ptr, old, new ) ({			\
+	typeof(*(ptr)) __val;					\
+								\
+	asm volatile ( "1: lwarx %0,0,%1"			\
+		: "=r" (__val) : "m" (*(ptr)) );		\
+	(old) = __val;						\
+	asm volatile ( __SYNC "stwcx. %1,0,%0; bne- 1b"		\
+		: "=m" (*(ptr)) : "r" ((new)) : "cc" );		\
+})
+
+#endif /* _ASM_PPC_ATOMIC_H */
Index: linux-2.1/include/linux/atomic.h
diff -u /dev/null linux-2.1/include/linux/atomic.h:1.1.6.1
--- /dev/null	Sun Dec 20 19:22:13 1998
+++ linux-2.1/include/linux/atomic.h	Sun Dec 20 01:54:11 1998
@@ -0,0 +1,403 @@
+/*
+ * linux/include/linux/atomic.h
+ *
+ * Copyright (C) 1998, Roman Zippel
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file COPYING in the main directory of this archive
+ * for more details.
+ *
+ * For a more detailed documentation about this, see ....
+ */
+
+#ifndef _LINUX_ATOMIC_H
+#define _LINUX_ATOMIC_H
+
+#ifdef __KERNEL__
+
+#include <asm/atomic_new.h>
+
+#ifdef __has_atomic_instr
+
+/* atomic instructions are available, so no need for special synchronization */
+
+#define atomic_define
+#define atomic_enter()
+#define atomic_leave()
+
+#define __atomic_exchange( ptr, old, new ) atomic_exchange( ptr, old, new )
+#define __atomic_inserthead( ptr, old, new ) atomic_inserthead( ptr, old, new )
+#define __atomic_inc( ptr ) atomic_inc( ptr )
+#define __atomic_dec( ptr ) atomic_dec( ptr )
+#define __atomic_dec_test( ptr ) atomic_dec_test( ptr )
+#define __atomic_add( ptr, val ) atomic_add( ptr, val )
+#define __atomic_sub( ptr, val ) atomic_sub( ptr, val )
+#define __atomic_setmask( ptr, val ) atomic_setmask( ptr, val )
+#define __atomic_clrmask( ptr, val ) atomic_clrmask( ptr, val )
+#define __atomic_chgmask( ptr, val ) atomic_chgmask( ptr, val )
+#define __atomic_test_setmask( ptr, val ) atomic_test_setmask( ptr, val )
+#define __atomic_test_clrmask( ptr, val ) atomic_test_clrmask( ptr, val )
+#define __atomic_test_chgmask( ptr, val ) atomic_test_chgmask( ptr, val )
+
+#else
+
+/* special synchronization is needed, that is done by atomic_enter() and
+ * atomic_leave(), between them we can let the compiler do the work
+ */
+
+#define __atomic_init( ptr, old )		({ (old) = *(ptr); })
+#define __atomic_reserve( ptr, old )
+#define __atomic_update( ptr, old, new )	({ *(ptr) = (new); 1; })
+
+#define __atomic_exchange( ptr, old, new )		\
+	({ (old) = *(ptr); *(ptr) = (new); void; })
+#define __atomic_inserthead( ptr, old, new ) ({		\
+	({ (old) = *(ptr); *(ptr) = (new); void; })
+#define __atomic_inc( ptr )		( (void)(*(ptr)++) )
+#define __atomic_dec( ptr )		( (void)(*(ptr)--) )
+#define __atomic_dec_test( ptr )	( --*(ptr) )
+#define __atomic_add( ptr, val )	( (void)(*(ptr) += (val)) )
+#define __atomic_sub( ptr, val )	( (void)(*(ptr) -= (val)) )
+#define __atomic_setmask( ptr, mask )	( (void)(*(ptr) |= (mask)) )
+#define __atomic_clrmask( ptr, mask )	( (void)(*(ptr) &= ~(mask)) )
+#define __atomic_chgmask( ptr, mask )	( (void)(*(ptr) ^= (mask)) )
+
+/* for the following macros, the C version is ugly, see if there is a more
+ * effeciently version available.
+ */
+
+#ifdef __has_bit_instr
+
+#define __atomic_test_setmask( ptr, mask ) atomic_test_setmask( ptr, mask )
+#define __atomic_test_clrmask( ptr, mask ) atomic_test_clrmask( ptr, mask )
+#define __atomic_test_chgmask( ptr, mask ) atomic_test_chgmask( ptr, mask )
+
+#else
+
+#define __atomic_test_setmask( ptr, mask ) ({			\
+	typeof(*(ptr)) __oldval = *(ptr);			\
+								\
+	*(ptr) |= (mask);					\
+	__oldval & (mask);					\
+})
+
+#define __atomic_test_clrmask( ptr, val ) ({			\
+	typeof(*(ptr)) __oldval = *(ptr);			\
+								\
+	*(ptr) &= ~(val);					\
+	__oldval & (mask);					\
+})
+
+#define __atomic_test_chgmask( ptr, val ) ({			\
+	typeof(*(ptr)) __oldval = *(ptr);			\
+								\
+	*(ptr) ^= (mask);					\
+	__oldval & (mask);					\
+})
+
+#endif
+
+#endif
+
+/* atomically exchange a memory value and return the old value, if <new> is
+ * constant, a more effecient macro might be available.
+ */
+
+#ifndef atomic_do_exchange
+#define atomic_do_exchange( ptr, old, new ) ({			\
+	atomic_define;						\
+								\
+	atomic_enter();						\
+	__atomic_init( ptr, old );				\
+	do {							\
+		__atomic_reserve( ptr, old );			\
+	} while ( !__atomic_update(ptr, old, (new)) );		\
+	atomic_leave();						\
+})
+#endif
+
+#ifndef atomic_do_exchange_const
+#define atomic_do_exchange_const( ptr, old, new ) atomic_do_exchange( ptr, old, new )
+#endif
+
+#ifndef atomic_exchange
+#define atomic_exchange( ptr, old, new ) ({			\
+	if ( __builtin_constant_p(new) )			\
+		atomic_do_exchange_const( ptr, old, new );	\
+	else							\
+		atomic_do_exchange( ptr, old, new );		\
+})
+#endif
+
+#ifndef atomic_inserthead
+#define atomic_inserthead( ptr, old, new ) ({			\
+	typeof(*(ptr)) __val;					\
+	atomic_define;						\
+								\
+	atomic_enter();						\
+	__atomic_init( ptr, __val );				\
+	do {							\
+		__atomic_reserve( ptr, __val );			\
+		old = __val;					\
+	} while ( !__atomic_update(ptr, __val, (new)) );	\
+	atomic_leave();						\
+})
+#endif
+
+#if 0 /* for now */
+/* atomically increment the value */
+#ifndef atomic_inc
+#define atomic_inc( ptr ) ({					\
+	typeof(*(ptr)) __val;					\
+								\
+	atomic_exchange( ptr, __val, __val + 1 );		\
+})
+#endif
+
+/* atomically decrement the value */
+#ifndef atomic_dec
+#define atomic_dec( ptr ) ({					\
+	typeof(*(ptr)) __val;					\
+								\
+	atomic_exchange( ptr, __val, __val - 1 );		\
+})
+#endif
+
+/* atomically decrement the value and test the result */
+#ifndef atomic_dec_test
+#define atomic_dec_test( ptr ) ({				\
+	typeof(*(ptr)) __val;					\
+								\
+	atomic_exchange( ptr, __val, __val - 1 );		\
+	__val != 1;						\
+})
+#endif
+
+/* atomically add a value */
+#ifndef atomic_add
+#define atomic_add( ptr, val ) ({				\
+	typeof(*(ptr)) __val;					\
+								\
+	atomic_exchange( ptr, __val, __val + (val) );		\
+})
+#endif
+
+/* atomically subtract a value */
+#ifndef atomic_sub
+#define atomic_sub( ptr, val ) ({				\
+	typeof(*(ptr)) __val;					\
+								\
+	atomic_exchange( ptr, __val, __val - (val) );		\
+})
+#endif
+#endif
+
+#define __getbitnr( mask ) ({					\
+	int __bit = -1;						\
+								\
+	if ( __builtin_constant_p(mask) ) {			\
+		switch ( mask ) {				\
+		case 1 <<  0: __bit =  0; break;		\
+		case 1 <<  1: __bit =  1; break;		\
+		case 1 <<  2: __bit =  2; break;		\
+		case 1 <<  3: __bit =  3; break;		\
+		case 1 <<  4: __bit =  4; break;		\
+		case 1 <<  5: __bit =  5; break;		\
+		case 1 <<  6: __bit =  6; break;		\
+		case 1 <<  7: __bit =  7; break;		\
+		case 1 <<  8: __bit =  8; break;		\
+		case 1 <<  9: __bit =  9; break;		\
+		case 1 << 10: __bit = 10; break;		\
+		case 1 << 11: __bit = 11; break;		\
+		case 1 << 12: __bit = 12; break;		\
+		case 1 << 13: __bit = 13; break;		\
+		case 1 << 14: __bit = 14; break;		\
+		case 1 << 15: __bit = 15; break;		\
+		case 1 << 16: __bit = 16; break;		\
+		case 1 << 17: __bit = 17; break;		\
+		case 1 << 18: __bit = 18; break;		\
+		case 1 << 19: __bit = 19; break;		\
+		case 1 << 20: __bit = 20; break;		\
+		case 1 << 21: __bit = 21; break;		\
+		case 1 << 22: __bit = 22; break;		\
+		case 1 << 23: __bit = 23; break;		\
+		case 1 << 24: __bit = 24; break;		\
+		case 1 << 25: __bit = 25; break;		\
+		case 1 << 26: __bit = 26; break;		\
+		case 1 << 27: __bit = 27; break;		\
+		case 1 << 28: __bit = 28; break;		\
+		case 1 << 29: __bit = 29; break;		\
+		case 1 << 30: __bit = 30; break;		\
+		case 1 << 31: __bit = 31; break;		\
+		}						\
+	}							\
+	__bit;							\
+})
+
+#define __getmask( bit ) ( 1 << (bit) )
+
+/* atomically set a mask, if the mask has only a single bit set, try a bit
+ * operation if available
+ */
+
+#ifndef atomic_do_setmask
+#define atomic_do_setmask( ptr, mask ) ({			\
+	typeof(*(ptr)) __val;					\
+								\
+	atomic_exchange( ptr, __val, __val | (mask) );		\
+})
+#endif
+
+#ifndef atomic_do_setbit
+#define atomic_do_setbit( ptr, bit ) atomic_do_setmask( ptr, __getmask(bit) );
+#endif
+
+#ifndef atomic_setmask
+#define atomic_setmask( ptr, mask ) ({				\
+	int __bit = __getbitnr( mask );				\
+								\
+	if ( bit < 0 )						\
+		atomic_do_setmask( ptr, mask );			\
+	else							\
+		atomic_do_setbit( ptr, __bit );			\
+})
+#endif
+
+/* atomically clear a mask, if the mask has only a single bit set, try a bit
+ * operation if available
+ */
+
+#ifndef atomic_do_clrmask
+#define atomic_do_clrmask( ptr, mask ) ({			\
+	typeof(*(ptr)) __val;					\
+								\
+	atomic_exchange( ptr, __val, __val & ~(mask) );		\
+})
+#endif
+
+#ifndef atomic_do_clrbit
+#define atomic_do_clrbit( ptr, bit ) atomic_do_clrmask( ptr, __getmask(bit) );
+#endif
+
+#ifndef atomic_clrmask
+#define atomic_clrmask( ptr, mask ) ({				\
+	int __bit = __getbitnr( mask );				\
+								\
+	if ( bit < 0 )						\
+		atomic_do_clrmask( ptr, mask );			\
+	else							\
+		atomic_do_clrbit( ptr, __bit );			\
+})
+#endif
+
+/* atomically change a mask, if the mask has only a single bit set, try a bit
+ * operation if available
+ */
+
+#ifndef atomic_do_chgmask
+#define atomic_do_chgmask( ptr, mask ) ({			\
+	typeof(*(ptr)) __val;					\
+								\
+	atomic_exchange( ptr, __val, __val ^ (mask) );		\
+})
+#endif
+
+#ifndef atomic_do_chgbit
+#define atomic_do_chgbit( ptr, bit ) atomic_do_chgmask( ptr, __getmask(bit) );
+#endif
+
+#ifndef atomic_chgmask
+#define atomic_chgmask( ptr, mask ) ({				\
+	int __bit = __getbitnr( mask );				\
+								\
+	if ( bit < 0 )						\
+		atomic_do_chgmask( ptr, mask );			\
+	else							\
+		atomic_do_chgbit( ptr, __bit );			\
+})
+#endif
+
+/* atomically set a mask and test it against the old value */
+
+#ifndef atomic_do_test_setmask
+#define atomic_do_test_setmask( ptr, mask ) ({			\
+	typeof(*(ptr)) __oldval;				\
+								\
+	atomic_exchange( ptr, __oldval, __oldval | (mask) );	\
+	__oldval & (mask);					\
+})
+#endif
+
+#ifndef atomic_do_test_setbit
+#define atomic_do_test_setbit( ptr, bit ) atomic_do_test_setmask( ptr, __getmask(bit) );
+#endif
+
+#ifndef atomic_test_setmask
+#define atomic_test_setmask( ptr, mask ) ({			\
+	int __res, __bit = __getbitnr( mask );			\
+								\
+	if ( __bit < 0 )					\
+		__res = atomic_do_test_setmask( ptr, mask );	\
+	else							\
+		__res = atomic_do_test_setbit( ptr, __bit );	\
+	__res;							\
+})
+#endif
+
+/* atomically clear a mask and test it against the old value */
+
+#ifndef atomic_do_test_clrmask
+#define atomic_do_test_clrmask( ptr, mask ) ({			\
+	typeof(*(ptr)) __val;					\
+								\
+	atomic_exchange( ptr, __val, __val & ~(mask) );		\
+	__val & (mask);						\
+})
+#endif
+
+#ifndef atomic_do_test_clrbit
+#define atomic_do_test_clrbit( ptr, bit ) atomic_do_test_clrmask( ptr, __getmask(bit) );
+#endif
+
+#ifndef atomic_test_clrmask
+#define atomic_test_clrmask( ptr, mask ) ({			\
+	int __res, __bit = __getbitnr( mask );			\
+								\
+	if ( __bit < 0 )					\
+		__res = atomic_do_test_clrmask( ptr, mask );	\
+	else							\
+		__res = atomic_do_test_clrbit( ptr, __bit );	\
+	__res;							\
+})
+#endif
+
+/* atomically change a mask and test it against the old value */
+
+#ifndef atomic_do_test_chgmask
+#define atomic_do_test_chgmask( ptr, mask ) ({			\
+	typeof(*(ptr)) __val;					\
+								\
+	atomic_exchange( ptr, __val, __val ^ (mask) );		\
+	__val & (mask);						\
+})
+#endif
+
+#ifndef atomic_do_test_chgbit
+#define atomic_do_test_chgbit( ptr, bit ) atomic_do_test_chgmask( ptr, __getmask(bit) );
+#endif
+
+#ifndef atomic_test_chgmask
+#define atomic_test_chgmask( ptr, mask ) ({			\
+	int __res, __bit = __getbitnr( mask );			\
+								\
+	if ( __bit < 0 )					\
+		__res = atomic_do_test_chgmask( ptr, mask );	\
+	else							\
+		__res = atomic_do_test_chgbit( ptr, __bit );	\
+	__res;							\
+})
+#endif
+
+#endif /* __KERNEL__ */
+
+#endif /* _LINUX_ATOMIC_H */
Index: linux-2.1/include/linux/tqueue.h
diff -u linux-2.1/include/linux/tqueue.h:1.1.1.2.6.2 linux-2.1/include/linux/tqueue.h:1.1.1.2.6.2.2.1
--- linux-2.1/include/linux/tqueue.h:1.1.1.2.6.2	Sat Dec 19 18:52:28 1998
+++ linux-2.1/include/linux/tqueue.h	Sat Dec 19 21:29:35 1998
@@ -13,9 +13,9 @@
 #ifndef _LINUX_TQUEUE_H
 #define _LINUX_TQUEUE_H
 
+#include <linux/atomic.h>
 #include <asm/bitops.h>
 #include <asm/system.h>
-#include <asm/spinlock.h>
 
 /*
  * New proposed "bottom half" handlers:
@@ -75,21 +75,18 @@
  * interrupt.
  */
 
-extern spinlock_t tqueue_lock;
-
 /*
  * queue_task
  */
 extern __inline__ void queue_task(struct tq_struct *bh_pointer,
 			   task_queue *bh_list)
 {
-	if (!test_and_set_bit(0,&bh_pointer->sync)) {
-		unsigned long flags;
-		spin_lock_irqsave(&tqueue_lock, flags);
-		bh_pointer->next = *bh_list;
-		*bh_list = bh_pointer;
-		spin_unlock_irqrestore(&tqueue_lock, flags);
-	}
+	atomic_define;
+
+	atomic_enter();
+	if (!__atomic_test_setmask(&bh_pointer->sync, 1))
+		__atomic_inserthead(bh_list, bh_pointer->next, bh_pointer);
+	atomic_leave();
 }
 
 /*
@@ -98,13 +95,9 @@
 extern __inline__ void run_task_queue(task_queue *list)
 {
 	if (*list) {
-		unsigned long flags;
 		struct tq_struct *p;
 
-		spin_lock_irqsave(&tqueue_lock, flags);
-		p = *list;
-		*list = NULL;
-		spin_unlock_irqrestore(&tqueue_lock, flags);
+		atomic_exchange(list, p, NULL);
 		
 		while (p) {
 			void *arg;
Index: linux-2.1/include/linux/tty.h
diff -u linux-2.1/include/linux/tty.h:1.1.1.5.6.2 linux-2.1/include/linux/tty.h:1.1.1.5.6.2.2.1
--- linux-2.1/include/linux/tty.h:1.1.1.5.6.2	Sat Dec 19 18:52:29 1998
+++ linux-2.1/include/linux/tty.h	Sat Dec 19 21:29:36 1998
@@ -130,17 +130,16 @@
  * located in the tty structure, and is used as a high speed interface
  * between the tty driver and the tty line discipline.
  */
-#define TTY_FLIPBUF_SIZE 512
+#define TTY_FLIPBUF_SIZE 1024
 
 struct tty_flip_buffer {
 	struct tq_struct tqueue;
 	struct semaphore pty_sem;
-	char		*char_buf_ptr;
-	unsigned char	*flag_buf_ptr;
 	int		count;
-	int		buf_num;
-	unsigned char	char_buf[2*TTY_FLIPBUF_SIZE];
-	char		flag_buf[2*TTY_FLIPBUF_SIZE];
+	int		push;
+	int		pop;
+	unsigned char	char_buf[TTY_FLIPBUF_SIZE];
+	char		flag_buf[TTY_FLIPBUF_SIZE];
 	unsigned char	slop[4]; /* N.B. bug overwrites buffer by 1 */
 };
 /*
Index: linux-2.1/include/linux/tty_flip.h
diff -u linux-2.1/include/linux/tty_flip.h:1.1.1.1.6.2 linux-2.1/include/linux/tty_flip.h:1.1.1.1.6.2.2.1
--- linux-2.1/include/linux/tty_flip.h:1.1.1.1.6.2	Sat Dec 19 18:52:30 1998
+++ linux-2.1/include/linux/tty_flip.h	Sat Dec 19 21:29:37 1998
@@ -12,8 +12,9 @@
 {
 	if (tty->flip.count < TTY_FLIPBUF_SIZE) {
 		tty->flip.count++;
-		*tty->flip.flag_buf_ptr++ = flag;
-		*tty->flip.char_buf_ptr++ = ch;
+		tty->flip.flag_buf[tty->flip.push] = flag;
+		tty->flip.char_buf[tty->flip.push] = ch;
+		tty->flip.push = (tty->flip.push + 1) & (TTY_FLIPBUF_SIZE - 1);
 	}
 }
 
Index: linux-2.1/kernel/ksyms.c
diff -u linux-2.1/kernel/ksyms.c:1.1.1.10.4.3 linux-2.1/kernel/ksyms.c:1.1.1.10.4.3.2.1
--- linux-2.1/kernel/ksyms.c:1.1.1.10.4.3	Sat Dec 19 18:52:31 1998
+++ linux-2.1/kernel/ksyms.c	Sat Dec 19 21:29:40 1998
@@ -270,7 +270,6 @@
 
 #ifdef __SMP__
 /* Various random spinlocks we want to export */
-EXPORT_SYMBOL(tqueue_lock);
 EXPORT_SYMBOL(waitqueue_lock);
 #endif
 
Index: linux-2.1/kernel/sched.c
diff -u linux-2.1/kernel/sched.c:1.1.1.13.6.2 linux-2.1/kernel/sched.c:1.1.1.13.6.2.2.1
--- linux-2.1/kernel/sched.c:1.1.1.13.6.2	Sat Dec 19 18:52:32 1998
+++ linux-2.1/kernel/sched.c	Sat Dec 19 21:29:41 1998
@@ -868,8 +868,6 @@
 	}
 }
 
-spinlock_t tqueue_lock;
-
 void tqueue_bh(void)
 {
 	run_task_queue(&tq_timer);

