diff -rubBwN linux-270897/.config linux-2.0.29/.config
--- linux-270897/.config        Wed Dec 31 16:00:00 1969
+++ linux-2.0.29/.config        Sun Sep 21 23:37:45 1997
@@ -0,0 +1,90 @@
+#
+# Automatically generated by make menuconfig: don't edit
+#
+
+#
+# Code maturity level options
+#
+CONFIG_EXPERIMENTAL=y
+
+#
+# Loadable module support
+#
+# CONFIG_MODULES is not set
+
+#
+# Platform dependant setup
+#
+# CONFIG_AMIGA is not set
+# CONFIG_ATARI is not set
+CONFIG_MAC=y
+CONFIG_M68020=y
+CONFIG_M68030=y
+CONFIG_M68040=y
+CONFIG_ADVANCED_CPU=y
+# CONFIG_RMW_INSNS is not set
+
+#
+# General setup
+#
+# CONFIG_NET is not set
+# CONFIG_SYSVIPC is not set
+# CONFIG_BINFMT_AOUT is not set
+CONFIG_BINFMT_ELF=y
+CONFIG_KERNEL_ELF=y
+
+#
+# Floppy, IDE, and other block devices
+#
+# CONFIG_BLK_DEV_FD is not set
+# CONFIG_BLK_DEV_IDE is not set
+# CONFIG_BLK_DEV_LOOP is not set
+# CONFIG_BLK_DEV_MD is not set
+# CONFIG_BLK_DEV_RAM is not set
+
+#
+# SCSI support
+#
+# CONFIG_SCSI is not set
+
+#
+# Filesystems
+#
+# CONFIG_QUOTA is not set
+# CONFIG_LOCK_MANDATORY is not set
+# CONFIG_MINIX_FS is not set
+# CONFIG_EXT_FS is not set
+CONFIG_EXT2_FS=y
+# CONFIG_XIA_FS is not set
+# CONFIG_FAT_FS is not set
+# CONFIG_MSDOS_FS is not set
+# CONFIG_VFAT_FS is not set
+# CONFIG_UMSDOS_FS is not set
+# CONFIG_MSDOS_PARTITION is not set
+# CONFIG_PROC_FS is not set
+# CONFIG_NCP_FS is not set
+# CONFIG_ISO9660_FS is not set
+# CONFIG_HPFS_FS is not set
+# CONFIG_SYSV_FS is not set
+# CONFIG_AFFS_FS is not set
+# CONFIG_HFS_FS is not set
+# CONFIG_UFS_FS is not set
+
+#
+# Character devices
+#
+# CONFIG_PRINTER is not set
+CONFIG_MAC_SCC=y
+# CONFIG_USERIAL is not set
+# CONFIG_WATCHDOG is not set
+# CONFIG_UMISC is not set
+
+#
+# Sound support
+#
+# CONFIG_SOUND is not set
+
+#
+# Kernel hacking
+#
+# CONFIG_PROFILE is not set
diff -rubBwN linux-270897/Makefile linux-2.0.29/Makefile
--- linux-270897/Makefile       Fri Sep 12 21:21:37 1997
+++ linux-2.0.29/Makefile       Sun Sep 21 01:32:04 1997
@@ -33,7 +33,7 @@

AS     =$(CROSS_COMPILE)as
LD     =$(CROSS_COMPILE)ld
-CC     =$(CROSS_COMPILE)gcc -D__KERNEL__ -I$(HPATH)
+CC     =$(CROSS_COMPILE)gcc -DDEBUG -D__KERNEL__ -I$(HPATH)
CPP    =$(CC) -E
AR     =$(CROSS_COMPILE)ar
NM     =$(CROSS_COMPILE)nm
diff -rubBwN linux-270897/arch/m68k/kernel/console.c linux-2.0.29/arch/m68k/kernel/console.c
--- linux-270897/arch/m68k/kernel/console.c     Fri Sep 12 21:21:37 1997
+++ linux-2.0.29/arch/m68k/kernel/console.c     Sun Sep 21 20:43:56 1997
@@ -2188,6 +2188,7 @@
 */
unsigned long con_init(unsigned long kmem_start)
{
+#if 0
       char *display_desc = "????";
       unsigned int currcons = 0;
       extern int serial_debug;
@@ -2272,6 +2273,8 @@
               MIN_NR_CONSOLES, (MIN_NR_CONSOLES == 1) ? "" : "s", MAX_NR_CONSOLES);

       init_bh(CONSOLE_BH, console_bh);
+#endif
+
       return kmem_start;
}

diff -rubBwN linux-270897/arch/m68k/kernel/head.S linux-2.0.29/arch/m68k/kernel/head.S
--- linux-270897/arch/m68k/kernel/head.S        Fri Sep 12 21:21:37 1997
+++ linux-2.0.29/arch/m68k/kernel/head.S        Mon Sep 22 00:15:11 1997
@@ -7,6 +7,7 @@
**
** 68040 fixes by Michael Rausch
** 68060 fixes by Roman Hodek
+** MMU cleanup by Randy Thelen
**
** Atari support by Andreas Schwab, using ideas of Robert de Vries
** and Bjoern Brauel
@@ -90,6 +91,10 @@
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 */
+
/* Translation control register */
TC_ENABLE = 0x8000
TC_PAGE8K = 0x4000
@@ -148,9 +153,17 @@
TABLENR_16MB   = 64    /* same for 16 MB */

#define putc(ch) moveq &ch,%d7; jbsr Lserial_putc
-#define putr() putc(13); putc(10)
+#define put2c(ch1,ch2)                 putc(ch1); putc(ch2)
+#define put3c(ch1,ch2,ch3)             put2c(ch1,ch2); putc(ch3)
+#define put4c(ch1,ch2,ch3,ch4)         put3c(ch1,ch2,ch3); putc(ch4)
+#define put5c(ch1,ch2,ch3,ch4,ch5)     put4c(ch1,ch2,ch3,ch4); putc(ch5)
+#define put6c(ch1,ch2,ch3,ch4,ch5,ch6) put5c(ch1,ch2,ch3,ch4,ch5); putc(ch6)
+#define putr()                         put2c(13,10)
#define putn(nr) movel nr,%d7; jbsr Lserial_putnum

+#define FONT_HEIGHT    8
+
+#if 0
#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_mac(lab) moveq &MACH_MAC,%d7; cmpl %d4,%d7; jne lab
@@ -159,13 +172,27 @@
#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
+#else
+#define is_not_amiga(lab) cmpl &MACH_AMIGA,%pc@(Lmachinetype); jne lab
+#define is_not_atari(lab) cmpl &MACH_ATARI,%pc@(Lmachinetype); jne lab
+#define is_not_mac(lab) cmpl &MACH_MAC,%pc@(Lmachinetype); jne lab

-#define CONFIG_MAC
+#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
+#endif

+/*
+ * misc defines for test hacks
+ */
+#define CONFIG_MAC
/*#define CONFIG_MAC_ONLY*/
#define FPU

-#undef  MACSERIAL
+#define MACSERIAL
+#define SERIAL_DEBUG

ENTRY(_stext)
/*
@@ -212,6 +239,7 @@

/*
 * Copy bootinfo from position after BSS to final resting place
+ * (regardless if it makes sense; i.e. for the NetBSD booter)
 */
       lea     %pc@(SYMBOL_NAME(_end)),%a0
       lea     %pc@(SYMBOL_NAME(boot_info)),%a1
@@ -220,18 +248,6 @@
1:     moveb   %a0@+,%a1@+
       dbra    %d1,1b

-#ifdef CONFIG_MAC
-/*
- *     first, save register d0 and d4 if configured for Mac - it contains lots
- *     of important things we'd need to guess on otherwise!
- *     d0: used by Penguin booter
- *     d4: used by NetBSD booter (cpuid, meminfo and stuff)
- */
-       movel   %d4,SYMBOL_NAME(mac_booter_data)
-       movel   %d0,SYMBOL_NAME(peng_booter_data)
-
-#endif
-
/*
 * This code is used by all machines, so please don't mess with it :-)
 * Record the CPU and machine type (we need it for all Linux booters! Most
@@ -244,253 +260,56 @@
       movel   %a0@(BI_machtype),%d4
       movel   %a0@(BI_cputype),%d0

-#ifdef CONFIG_MAC
-/*
- * Mac hack: now that the bootinfo has been set up, do the Mac stuff if Mac
- *
- * Complicated: with the NetBSD booter, the bootinfo we just copied in does
- * not contain anything sensible. With all other booters, it actually does
- * define the machine type (or should; don't know how the Mac bootstrap
- * behaves...)
- * So what happens is: if the bootinfo states this machine is neither Atari
- * nor Amiga (or anything else well-behaved, for that matter), it is assumed
- * it must be a Mac (as this code only appears in the Mac source, presently).
- * The problem 'Penguin or NetBSD' is resolved by testing a magic number we
- * need to restore to d0. For Penguin, machine info now is read from the
- * bootinfo, for NetBSD it is read from (restored) d4 and the other
- * registers, see head of this file for register usage.
- * Here's a question: Why not use the bootinfo data for recognizing 'this
- * box is a Mac'?? NetBSD never should set that flag ...
- *
- * Somebody should actually clean this up before sending patches to Jes ...
- */
-
-       /* roundabout, but necessary when invoked by MacBSD */
-       is_not_atari(Ltest_maybe_mac)
-       jra     Ltest_notmac    /* is Atari -> skip */
-
-Ltest_maybe_mac:
-       is_not_amiga(Ltest_is_mac)
-       jra     Ltest_notmac    /* is Amiga -> skip */
-
-Ltest_is_mac:                  /* not Amiga, not Atari: must be Mac! */
-
-       /* restore d0 */
-       movel   SYMBOL_NAME(peng_booter_data),%d0
-       movel   SYMBOL_NAME(mac_booter_data),%d4
-
-       /* test for Penguin booter */
-       movel   %d0,%d1
-       andl    #0xffffff00,%d1
-       cmpl    #0x50656e00,%d1
-       jeq     Ltest_penguin
-
-
-       /* okay, so it's the MacBSD booter, not Penguin */
-       /*
-        *      NetBSD hack:
-        *      restore register d4 :-)
+       /* Record the machinetype and cputype where they can be used by macros!
        */
-#if 0
-       movel   SYMBOL_NAME(mac_booter_data),%d4
-#endif
-       /*
-        * zero bootinfo - who knows what we copied above ...
-        */
-       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
-       movel   %pc@(SYMBOL_NAME(bisize)),%d0
-       subql   #1,%d0
-1:     moveb   #0,%a0@+
-       dbra    %d0,1b
+       lea     %pc@(Lmachinetype),%a0
+       movel   %d4,%a0@

-/*
-        *      Save the boot info
+       /* Test the BootInfo cputype for 060
        */
-       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
-       movel   #MACH_MAC,%a0@(BI_machtype)
-       movel   %sp@+, %d0
-       movel   %d0, %a0@(BI_args)
-       movel   %d4, %a0@(BI_cpuid)
-       /*
-        *      See if it is an 030 - just for now
-        */
-       movel   #0x200, %d6
-       movec   %d6, %cacr
-       movec   %cacr, %d6
-       tstl    %d6
-       jeq     cpu_nocacr
-       /*
-        *      An 030
-        */
-#ifdef FPU
-       movel   #34,%d0 /* 68030+68881 - guessing FPU */
-#else
-       movel   #2, %d0 /* 68030 alone */
-#endif
-       bra     cpu_typed
-
-       /*
-        *      020,040 or 060 that is the question ?
-        */
-cpu_nocacr:
-       bset    #31, %d6        /* Set DCache Enable */
-       movec   %d6, %cacr
-       movec   %cacr, %d6
-       btst    #31, %d6        /* Did it set ? */
-       jeq     cpu_nodce
-
-       /*
-        *      Ok we have DCE but not CACR that makes us an 040
-        *      or 060. My manual doesn't go up to the 060 and I've
-        *      yet to meet a Macintrash with one !
-        *      Note: 040 mode doesnt work yet on the Mac as I use early
-        *      termination descriptors.
-        */
-       movel   #132, %d0       /* 68040 - built in FPU */
-       bra     cpu_typed
-
-       /*
-        *      no dce no cacr, 68010 or 68020. We don't support 010
-        *      anyway..
-        */
-cpu_nodce:
-#ifdef FPU
-       movel   #33, %d0        /* 68020+68881 */
-#else
-       movel   #1, %d0
-#endif
-cpu_typed:
-       movel   %d0, %a0@(BI_cputype)
-       movel   %a4, %a0@(BI_dimensions)
-       movel   %d5, %a0@(BI_videoaddr)
-       movel   %a3, %a0@(BI_videorow)
-       movel   %a2, %a0@(BI_videodepth)
-       lea     %pc@(SYMBOL_NAME(_stext):w),%sp
-       movel   #0, %a0@(BI_memory+MI_addr)
-       lsrl    #7, %d4
-       andl    #31, %d4
-       movel   #20, %d0
-       lsll    %d0, %d4
-       movel   %d4, %a0@(BI_memory+MI_size)
-
-       /*
-        * end of MacBSD hackery
-        * d0 clobbered
-        * d4, d6 clobbered
-        */
-Ltest_penguin:
-
-#if 0
-       jbsr Lserial_init
+       clrl    %d6
+       btst    #CPUB_68060,%d0
+       jeq     1f

-       putr()
-       putc('L')
-       putc('i')
-       putc('n')
-       putc('u')
-       putc('x')
-       putc('.')
-       putr()
-#endif
+       bset    &CPUTYPE_060,%d6
+       bset    &CPUTYPE_0460,%d6
+       jra     2f

-       /*
-        *      Yes this isnt the clean way to do it. I need to revise
-        *      my 68k asm.
+1:     /* Test the BootInfo cputype for 040
 */
-       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
-       movel   %a0@(BI_videoaddr), %a1
-       movel   %a0@(BI_dimensions), %d1
-       andl    #0xFFFF,%d1     /* rows */
-loopy:
-       movel   %a0@(BI_videorow), %d0
-loopx:
-       moveb   #0x55, %a1@+
-       dbra    %d0,loopx
-       dbra    %d1,loopy
+       btst    #CPUB_68040,%d0
+       jeq     1f

-       /*
-        * check how far we got ...
+       bset    &CPUTYPE_040,%d6
+       bset    &CPUTYPE_0460,%d6
+       jra     2f
+1:     /* Assume it's an 020 & 030
+        * 020/030 no difference in Lcputype
        */
-       movel   %a0@(BI_videoaddr),%a1
-       movel   %a0@(BI_videorow),%d0
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0         /* that's 5 rows + 1 byte! dbra weirdness :-) */
-       addl    #8,%d0
-loopw:
-       moveb   #0x00, %a1@+
-       dbra    %d0,loopw       /* white + 9 bytes */
-
-       movel   %a0@(BI_videoaddr), %a1@+       /* video addr. */
-       moveb   #0xFF, %a1@+
-       moveb   #0x00, %a1@+    /* b/w */
-#if 0  /* don't clobber videoaddr!! */
-       movel   %a1, %a0@(BI_videoaddr) /* save screen pointer */
-#endif
-       lea     %pc@(SYMBOL_NAME(_stext):w),%a0
-       movel   %a0,%d0         /* get start addr. */
-
-       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
-#if 0  /* a1 preserved */
-       movel   %a0@(BI_videoaddr), %a1 /* restore screen pointer */
-#endif
-       movel   %d0, %a1@+      /* write start addr. */
-
-       moveb   #0xFF, %a1@+
-       moveb   #0x00, %a1@+    /* b/w */
-
-Ltest_notmac:
-
+2:
/*
- * Re-record the CPU and machine type (we just clobbered d0 and d4 :=( if
- * booting with NetBSD ...).
+        * Determine the cache bits for 040 & 060 CPU's
 */
-       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
-       movel   %a0@(BI_machtype),%d4
-       movel   %a0@(BI_cputype),%d0
+       lea     %pc@(Lcputype),%a0
+       movel   %d6,%a0@

-/*
- * end of Mac-specific hacks
- */
-#endif
+       is_not_040_or_060(1f)
+       /* '040 or '060: d6 := cacheable write-through */
+       movel   #_PAGE_CACHE040W,%d6
+       jbra    2f

-       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 */
+1:     /* '020 or '030: d6 := cache bits unused */
       moveq   #0,%d6

-2:     lea     %pc@(SYMBOL_NAME(m68k_pgtable_cachemode)),%a0
-       moveq   #0,%d0
-       movew   %d6,%d0
-       movel   %d0,%a0@                /* save cache mode for page tables */
-
-#ifdef DEBUG_MAC
-       is_not_mac(2f)
-       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
-       movel   %a0@(BI_videorow),%d0   /* rowbytes */
-       andl    #0xFFFF,%d0             /* bytes per rows */
-       movel   %a0@(BI_videoaddr),%a0  /* videoaddr */
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0                 /* 5 rows */
-       addl    #7,%d0
-1:
-       moveb   #0xFF,%a0@+             /* black + 8 bytes */
-       dbra    %d0,1b
2:
-#endif
+       lea     %pc@(SYMBOL_NAME(m68k_pgtable_cachemode)),%a0
+       movel   %d6,%a0@                /* save cache mode for page tables */

/*
+        *      I don't see reference to FROM_PL9 anywhere else in
+        *      source tree.  Is this used?
+        */
+/*
 * raise interrupt level with MASTER bit set, copy isp to msp (if not 68060)
 */
#ifdef FROM_PL9
@@ -503,54 +322,16 @@
       movew   #0x2700,%sr
#endif

-#ifdef DEBUG_MAC
-       is_not_mac(2f)
-       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
-       movel   %a0@(BI_videorow),%d0   /* rowbytes */
-       andl    #0xFFFF,%d0             /* bytes per rows */
-       movel   %a0@(BI_videoaddr),%a0  /* videoaddr */
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0                 /* 5 rows */
-       addl    #6,%d0
-1:
-       moveb   #0x00,%a0@+             /* white + 7 bytes */
-       dbra    %d0,1b
-2:
-#endif
-
-#ifndef CONFIG_MAC
/*
 * Initialize serial port
 */
       jbsr Lserial_init

+#ifdef SERIAL_DEBUG
       putr()
       putc('A')
#endif

-#ifdef DEBUG_MAC
-       is_not_mac(2f)
-       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
-       movel   %a0@(BI_videorow),%d0   /* rowbytes */
-       andl    #0xFFFF,%d0             /* bytes per rows */
-       movel   %a0@(BI_videoaddr),%a0  /* videoaddr */
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0                 /* 5 rows */
-       addl    #5,%d0
-1:
-       moveb   #0xFF,%a0@+             /* black + 6 bytes */
-       dbra    %d0,1b
-2:
-       /* at this point, the bar should be black,
-        * with a white-black-white pattern appended
-        * -> SE/30 gets that far :-)
-        */
-#endif
-
/*
 * Get address at end of kernel code/data/bss and
 * mask off at a page boundary.
@@ -560,25 +341,12 @@
       movel   %a0,%d0
       andl    #-PAGESIZE,%d0
       movel   %d0,%a6
+/*
+ * %a6 now contains the address to the
+ * next free block beyond the kernel
+ */

-#ifdef DEBUG_MAC
-       is_not_mac(2f)
-       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
-       movel   %a0@(BI_videorow),%d0   /* rowbytes */
-       andl    #0xFFFF,%d0             /* bytes per rows */
-       movel   %a0@(BI_videoaddr),%a0  /* videoaddr */
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0                 /* 5 rows */
-       addl    #4,%d0
-1:
-       moveb   #0x00,%a0@+             /* white + 5 bytes */
-       dbra    %d0,1b
-2:
-#endif
-
-#ifndef CONFIG_MAC
+#ifdef SERIAL_DEBUG
       putc('B')
#endif

@@ -589,50 +357,6 @@
       lea     %pc@(SYMBOL_NAME(_stext)-PAGESIZE:w),%a0
       movel   %a0,%d5

-#ifdef DEBUG_MAC
-       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
-       movel   %a0@(BI_videorow),%d0   /* rowbytes */
-       andl    #0xFFFF,%d0             /* bytes per rows */
-       movel   %a0@(BI_videoaddr),%a0  /* videoaddr */
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0                 /* 7 rows */
-
-       movel   %d5,%a0@(%d0)
-
-       movel   #0,%d5
-
-       /* just testing if we arrived here ...  pattern interrupted if not! */
-       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
-       movel   %a0@(BI_videorow),%d0   /* rowbytes */
-       andl    #0xFFFF,%d0             /* bytes per rows */
-       movel   %a0@(BI_videoaddr),%a0  /* videoaddr */
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0                 /* 5 rows */
-       addl    #3,%d0
-1:
-       moveb   #0xFF,%a0@+             /* black + 4 bytes */
-       dbra    %d0,1b
-
-       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
-       movel   %a0@(BI_videorow),%d0   /* rowbytes */
-       andl    #0xFFFF,%d0             /* bytes per rows */
-       movel   %a0@(BI_videoaddr),%a0  /* videoaddr */
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0                 /* 5 rows */
-       addl    #2,%d0
-1:
-       moveb   #0x00,%a0@+             /* white + 3 bytes */
-       dbra    %d0,1b
-#endif
-
       jra Lsave_start_done

Lsave_start_notmac:
@@ -646,1048 +370,967 @@
       movel   %d5,%a0@
#endif

+       jbsr    mmu_init
+
+       lea     3f,%a1
+       lea     %pc@(SYMBOL_NAME(_stext)-PAGESIZE:w),%a0
+       movel   %a0,%d0
+       jbra    1f
+1:     nop
+       .word   0xf518          /* pflusha */
+       .long   0x4e7bd807      /* movec %a5,%srp */
+       .long   0x4e7bd806      /* movec %a5,%urp */
+       movel   #TC_ENABLE+TC_PAGE4K,%d0
/*
- * initialize the kernel root table.
+        * this value is also ok for the 68060, we don`t use the cache
+        * mode/protection defaults
 */
-       lea     %pc@(SYMBOL_NAME(kernel_pg_dir):w),%a5
-       movel   %a5,%a0
-       moveq   #ROOT_TABLE_SIZE-1,%d1
-1:     clrl    %a0@+
-       dbra    %d1,1b
-
+       .long   0x4e7b0003      /* movec %d0,%tc (enable the MMU) */
+       jmp     %a1@
+3:
       /*
-        * Initialize root table descriptor pointing to the kernel pointer
-        * table.
+ * Fixup the addresses for the kernel pointer table and availmem.
+ * Convert them from physical addresses to virtual addresses.
        */
-       lea     %pc@(Lavail_pmd_table:w),%a4
-       moveq   #_PAGE_TABLE,%d0
-       addl    %a4,%d0
-       movel   %d0,%a5@

-#ifdef DEBUG_MAC
-       is_not_mac(2f)
-       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
-       movel   %a0@(BI_videorow),%d0   /* rowbytes */
-       andl    #0xFFFF,%d0             /* bytes per rows */
-       movel   %a0@(BI_videoaddr),%a0  /* videoaddr */
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0                 /* 5 rows */
-       addl    #1,%d0
-1:
-       moveb   #0xFF,%a0@+             /* black + 2 bytes */
-       dbra    %d0,1b
-2:
+#ifdef SERIAL_DEBUG
+       putc('M')
#endif

-#if 0
-       putc('C')
-#endif
-
-/*
- * 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).
+       /* d5 contains physaddr of kernel start
        */
-       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
-       addql   #_PAGE_TABLE,%a1        /* descriptor type */
-       movel   #PAGE_TABLE_SIZE<<2,%d2 /* increment */
+       subl    %d5,SYMBOL_NAME(kpt)

-2:     movel   %a1,%a0@+
-       addl    %d2,%a1
-       dbra    %d1,2b
+       /* do the same conversion on the first available memory
+        * address (in a6).
+        */
+       subl    %d5,%a6
+       movel   %a6,SYMBOL_NAME(availmem) /* first available memory address */

-#ifdef DEBUG_MAC
-       is_not_mac(2f)
-       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
-       movel   %a0@(BI_videorow),%d0   /* rowbytes */
-       andl    #0xFFFF,%d0             /* bytes per rows */
-       movel   %a0@(BI_videoaddr),%a0  /* videoaddr */
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0                 /* 5 rows */
-1:
-       moveb   #0x00,%a0@+             /* white + 1 byte */
-       dbra    %d0,1b
-2:
+#ifdef SERIAL_DEBUG
+       putc('N')
#endif

#if 0
-       putc('D')
+       putr()
+       lea     SYMBOL_NAME(kernel_pmd_table),%a0
+       moveq   #63,%d0
+1:     moveq   #7,%d1
+       putn(%a0)
+       putc(':')
+       putc(' ')
+2:     putn(%a0@+)
+       dbra    %d1,2b
+       putr()
+       dbra    %d0,1b
+       putr()
+       movel   SYMBOL_NAME(kpt),%a0
+       moveq   #63,%d0
+1:     moveq   #7,%d1
+       putn(%a0)
+       putc(':')
+       putc(' ')
+2:     putn(%a0@+)
+       dbra    %d1,2b
+       putr()
+       dbra    %d0,1b
#endif
+/*
+ * Enable caches
+ */

/*
- * 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.
+       ** Will work only if virtual == physical
 */
-       is_not_040_or_060(Lnot040)
+       is_040_or_060(Lcache680460)

-#if 0
-       putc('F')
-#endif
+       movel   #CC3_ENABLE_DB+CC3_CLR_D+CC3_ENABLE_D+CC3_ENABLE_IB+CC3_CLR_I+CC3_ENABLE_I,%d0
+       movec   %d0,%cacr

-       movel   %a3,%a0
-       movel   %d5,%a1
-       addw    #_PAGE_GLOBAL040+_PAGE_CACHE040+_PAGE_PRESENT,%a1
-       movew   #(PAGE_TABLE_SIZE*TABLENR_4MB)-1,%d1
-       movel   #PAGESIZE,%d2
-1:     movel   %a1,%a0@+
-       addl    %d2,%a1
-       dbra    %d1,1b
+       jra     1f

-       /*
-        * 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@
-
-       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.
-        */
+Lcache680460:
+       .word   0xf4f8          /* cpusha %bc */

-       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
-       movel   %a0@(BI_videorow),%d0   /* rowbytes */
-       andl    #0xFFFF,%d0             /* bytes per rows */
-       movel   %a0@(BI_videoaddr),%a0  /* videoaddr */
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0                 /* 5 rows */
-1:
-       moveb   #0xF0,%a0@+             /* b/w+1 : this is missing on SE/30 */
-       dbra    %d0,1b
+       is_060(Lcache68060)

-Lnot040:
-/*
- * Do any machine specific page table initializations.
- */
-#ifdef CONFIG_AMIGA
-       is_not_amiga(Lnotami)
+       movel   #CC6_ENABLE_D+CC6_ENABLE_I,%d0
+       /* MMU stuff works in copyback mode now, so enable the cache */
+       movec   %d0,%cacr
+       jra     1f
+
+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
+       .long   0x4e7b0808      /* movec d0,pcr */
+1:

/*
- * 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.
+ * Setup initial stack pointer
 */
+       lea     SYMBOL_NAME(init_user_stack)+PAGESIZE,%sp

-#if 0
-       putc('H')
+/* jump to the kernel start */
+#ifdef SERIAL_DEBUG
+       putr()
#endif

-       is_040_or_060(Lspami68040)
+       jbsr    SYMBOL_NAME(start_kernel)

       /*
-        * 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.
+ * switch off mmu and exit
        */

-#if 0
-       putc('I')
-#endif
-
-       moveq   #_PAGE_NOCACHE030+_PAGE_PRESENT,%d0
-       orl     #0x80000000, %d0
-       movel   %d0,%a5@(0x40<<2)
-
-       jra     Lmapphys
+#ifdef HACKER_KERNEL
+ENTRY(kernel_exit)
+       lea     2f:w,%a0
+       movel   %pc@(Lkernel_start),%a0
+       lea     %a0@(2f:w),%a1
+       movel   %a1,%d0
+       andl    #0xff000000,%d0
+       jne     1f
+       jmp     %a0@(1f+0x80000000)
+1:     orw     #TTR_ENABLE+TTR_KERNELMODE+_PAGE_NOCACHE_S,%d0
+       .long   0x4e7b0004      /* movec %d0,%itt0 */
+       jmp     %a1@
+2:     moveq   #0,%d0
+       .long   0x4e7b0003      /* movec %d0,%tc (disable the MMU) */
+       .word   0xf518          /* pflusha */
+       .long   0x4e7b0004      /* movec %d0,%itt0 */
+       movec   %d0,%cacr
+       .word   0xf4f8          /* cpusha %bc */

-Lspami68040:
+       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
+       jmp     %a0@(BI_amiga_exit_func:w)@(0:w)
+#endif

       /*
-        * 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).
-        */
+ *     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 is either 0x0000.0000 or a valid pointer to a
+ *     pointer table.  Each entry defines a 32Meg range of memory.
+ *     If an entry is 0x00 then that logical range of 32M is
+ *     invalid and references to that range of memory (when the MMU
+ *     is enabled) will fault.
+ *
+ *     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 not 0x0).  There will undoubtedly be more than one
+ *     pointer table for the kernel because each pointer table
+ *     defines a range of only 256K.
+ *
+ *     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
+ */
+#define        MMU_CACHE_KERNEL_CODE           0
+#define MMU_CACHE_MMU_DATA             1
+#define MMU_CACHE_IO_DATA              2
+
+mmu_init_map_kernel_low:
+       lea     %pc@(SYMBOL_NAME(Lavail_pmd_table)),%a4
+       jbsr    mmu_clear_pointer_table

-       /* clear the amiga pointer table */
-       lea     %a4@(PTR_TABLE_SIZE<<2),%a4
-       moveq   #PTR_TABLE_SIZE-1,%d1
-1:     clrl    %a0@+
-       dbra    %d1,1b
+       /* Map the 4Meg range beginning at the kernel's phys start
+        */
+       movel   %d5,%a1
+       movel   %d5,%a0
+       movel   #4*1024*1024,%d0
+       movel   #MMU_CACHE_MMU_DATA,%d1
+       jbsr    mmu_map
+       jbra    2f

-       /* allocate 4 pages for 64 page tables */
-       movel   %a6,%a3
-       addw    #4*PAGESIZE,%a6
+1:
+       movel   %d5,%a1
+       movel   %d5,%a0
+       movel   #PAGESIZE,%d0
+       movel   #MMU_CACHE_KERNEL_CODE,%d1

-       /* initialize the pointer table */
-       movel   %a4,%a0
-       movel   %a3,%a1
-       addql   #_PAGE_TABLE,%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
+       moveq   #0,%d0
+       movel   %d0,%a4
+       movel   %d0,%a3
+2:
+       rts

-       /* ensure that the root table points to the pointer table */
-       movel   %a4,%a0
-       addql   #_PAGE_TABLE,%a0
-       movel   %a0,%a5@(0x40<<2)
-
-       /*
-        * initialize the page tables
-        * descriptor bits include noncachable/serialized and global bits.
-        */
-       movel   %a3,%a0
-       movew   #_PAGE_GLOBAL040+_PAGE_NOCACHE_S+_PAGE_PRESENT,%a1
-       movel   #PAGESIZE,%d2
-       movew   #(PAGE_TABLE_SIZE*TABLENR_16MB)-1,%d1
+mmu_init:
+       moveml  %d0-%d7/%a0-%a4,%sp@-

-1:     movel   %a1,%a0@+
-       addl    %d2,%a1
-       dbra    %d1,1b
+/*
+ * initialize the kernel root table.
+ */
+       lea     %pc@(SYMBOL_NAME(kernel_pg_dir)),%a5
+       jbsr    mmu_clear_root_table

+       jbsr    mmu_init_map_kernel_low
       /*
-        * 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
+ *     jbsr    mmu_init_map_kerenl_high
+ */

-       jra     Lmapphys
+#if defined(CONFIG_AMIGA)
+mmu_init_amiga:
+       is_not_amiga(mmu_init_not_amiga)

-Lnotami:
+       /* There is nothing else to do on this platform!
+        *              Yet!
+        */
+mmu_init_not_amiga:
#endif

-#ifdef CONFIG_MAC
-       is_not_mac(Lnotmac)
+#if defined(CONFIG_ATARI)
+mmu_init_atari:
+       is_not_atari(mmu_init_not_atari)

-/*
- * Setup a mapping of the 0xFC range for 32M of physical address space
- * at virtual address 0xFC000000, using early termination page descriptors
- * for the 68030, and proper page tables for the 680[46]0.  Set this area
- * as non-cacheable. (040/060 one still wrong XXX)
+       /* There is nothing else to do on this platform!
+        *              Yet!
 */
-
-#if 0
-       putc('H')
+mmu_init_not_atari:
#endif

-       is_040_or_060(Lspmac68040)
+#if defined(CONFIG_MAC)
+mmu_init_mac:
+       is_not_mac(mmu_init_not_mac)

-#ifdef DEBUG_MAC
-       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
-       movel   %a0@(BI_videorow),%d0   /* rowbytes */
-       andl    #0xFFFF,%d0             /* bytes per rows */
-       movel   %a0@(BI_videoaddr),%a0  /* videoaddr */
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0                 /* 5 rows */
-       subl    #1, %d0
-1:
-       moveb   #0xFF,%a0@+             /* black - 0 bytes : ok */
-       dbra    %d0,1b
-#endif
+       moveq   #0,%d0
+       movel   %d0,%a4
+       movel   %d0,%a3

-       /*
-        * for the 68030, just setup a translation to map in the
-        * 32M of physical address space at virtual address 0x80000000
-         * using an early termination page descriptor.
-        */
+       movel   #0x50000000,%a1
+       movel   #0x02000000,%d0
+       movel   #MMU_CACHE_IO_DATA,%d1
+       movel   %a1,%a0
+       jbsr    mmu_map
+
+       movel   #0x60000000,%a1
+       movel   %a1,%a0
+       movel   #0x00400000,%d0
+       movel   #MMU_CACHE_IO_DATA,%d1
+       jbsr    mmu_map
+
+       movel   #0xF8000000,%a1
+1:
+       movel   %a1,%a0
+       movel   #0x00400000,%d0
+       movel   #MMU_CACHE_IO_DATA,%d1
+       jbsr    mmu_map
+       addl    #0x01000000,%a1
+       cmpl    #0,%a1
+       jbne    1b

-#if 0
-       putc('I')
+mmu_init_not_mac:
#endif

-       /*
-        *      Nubus space
-        */
+       moveml  %sp@+,%d0-%d7/%a0-%a4
+       rts

-       moveq   #_PAGE_NOCACHE030+_PAGE_PRESENT,%d0
-       orl     #0xF8000000,%d0
-       movel   %d0,%a5@(0x7C<<2)
-       moveq   #_PAGE_NOCACHE030+_PAGE_PRESENT,%d0
-       orl     #0xFA000000,%d0
-       movel   %d0,%a5@(0x7D<<2)
-       moveq   #_PAGE_NOCACHE030+_PAGE_PRESENT,%d0
-       orl     #0xFC000000,%d0
-       movel   %d0,%a5@(0x7E<<2)
-       moveq   #_PAGE_NOCACHE030+_PAGE_PRESENT,%d0
-       orl     #0xFE000000,%d0
-       movel   %d0,%a5@(0x7F<<2)
+#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

-       /*
-        *      IO space identity at 0x50-> for now
-        */
+#define MMU_PRINT_INVALID              -1
+#define MMU_PRINT_VALID                        1
+#define MMU_PRINT_UNINITED             0

-       moveq   #_PAGE_NOCACHE030+_PAGE_PRESENT,%d0
-       orl     #0x50000000,%d0
-       movel   %d0,%a5@(0x28<<2)
+#define        putZc(z,n)              jbne 1f; putc(z); jbra 2f ; 1: putc(n); 2:

-       /*
-        *      MAC onboard video
-        */
+mmu_print:
+       moveml  %a0-%a6/%d0-%d7,%sp@-

-       moveq   #_PAGE_NOCACHE030+_PAGE_PRESENT,%d0
-       orl     #0x60000000,%d0
-       movel   %d0,%a5@(0x30<<2)
-
-       /*
-        *      Classic Video (9Fxxxxxx) (0x9E000000-0x9FFFFFFF -> 0x60000000?)
-        */
+       is_040_or_060(mmu_040_print)
+       jbra    mmu_030_print

-       moveq   #_PAGE_NOCACHE030+_PAGE_PRESENT,%d0
-       orl     #0x60000000,%d0
-       movel   %d0,%a5@(0x4F<<2)
+mmu_040_print:
+       putr()
+       put3c('r','p',':')
+       movel   %a5,%d7
+       jbsr    Lserial_putnum
+       putr()
+       put3c('t','c',':')
+       movel   %d5,%d7
+       jbsr    Lserial_putnum
+       putr()
+       putr()
+       put3c('M','M','U')
+       put3c('0','4','0')
+       putr()
+       movel   %a5,%d0
+       andil   #0xfffffe00,%d0
+       movel   %d0,%a0
+       movel   #0x00000000,%a4         /* logical address */
+       movel   #0,%d0
+40:
+       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
+
+       jbra    mmu_print_done
+
+mmu_040_print_flags:
+       btstl   #10,%d6
+       putZc(' ','G')  /* global bit */
+       btstl   #7,%d6
+       putZc(' ','S')  /* supervisor bit */
+       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

-#if 1
-       /*
-        *      MAC RAM identity at 0x00000000 - required for SE/30 and IIcx
-        *      syntax: physbase | _PAGE_NOCACHE030 | _PAGE_PRESENT
-        *      -> tbl[virtual >> 18]
-        */
+mmu_030_print_flags:
+       btstl   #6,%d6
+       putZc('C','I')  /* write through or copy-back */
+       rts

-       moveq   #_PAGE_NOCACHE030+_PAGE_PRESENT,%d0
-       orl     #0x00000000,%d0
-       movel   %d0,%a5@(0x00<<2)
-#endif
+mmu_030_print:
+       putr()
+       put3c('r','p',':')
+       movel   %a5,%d7
+       jbsr    Lserial_putnum
+       putr()
+       put3c('t','c',':')
+       movel   %d5,%d7
+       jbsr    Lserial_putnum
+       putr()
+       putr()
+       put3c('M','M','U')
+       put3c('0','3','0')
+       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:
+       lea     %pc@(Lmmu_print_data),%a0
+       movel   #MMU_PRINT_UNINITED,%a0@(mmu_next_valid)
+
+       cmpil   #0,%d5
+       beq     3f
+       put6c('a','4','!','=','0','!')
+       movel   %d5,%d7
+       jsr     Lserial_putnum
+       putr()
+3:
+       putr()
+       putr()

-#if 0
-       /*
-        *      MAC RAM  0x80000000 -> 0x00000000 - doesn't help :-(
-        */
+       moveml  %sp@+,%a0-%a6/%d0-%d7
+       rts

-       moveq   #_PAGE_NOCACHE030+_PAGE_PRESENT,%d0
-       orl     #0x00000000,%d0
-       movel   %d0,%a5@(0x40<<2)
-#endif
+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

-#ifdef DEBUG_MAC
-       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
-       movel   %a0@(BI_videorow),%d0   /* rowbytes */
-       andl    #0xFFFF,%d0             /* bytes per rows */
-       movel   %a0@(BI_videoaddr),%a0  /* videoaddr */
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0                 /* 5 rows */
-       subl    #2, %d0
-1:
-       moveb   #0x00,%a0@+             /* white - 1 bytes : ok! */
-       dbra    %d0,1b
-#endif
+mmu_print_tuple_invalidate:
+       moveml  %a0/%d7,%sp@-

-       jra     Lmapphys
+       lea     %pc@(Lmmu_print_data),%a0
+       tstl    %a0@(mmu_next_valid)
+       jbmi    mmu_print_tuple_invalidate_exit

-Lspmac68040:
+       movel   #MMU_PRINT_INVALID,%a0@(mmu_next_valid)

-#ifdef DEBUG_MAC
-       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
-       movel   %a0@(BI_videorow),%d0   /* rowbytes */
-       andl    #0xFFFF,%d0             /* bytes per rows */
-       movel   %a0@(BI_videoaddr),%a0  /* videoaddr */
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0                 /* 5 rows */
-       subl    #2, %d0
-1:
-       moveb   #0xF0,%a0@+             /* black/white - 1 bytes ?? weird */
-       dbra    %d0,1b
-#endif
-       /*
-        * 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).
-        */
+       movel   %a4,%d7
+       jbsr    Lserial_putnum

-       /* clear the mac pointer table */
-       lea     %a4@(PTR_TABLE_SIZE<<2),%a4
-       moveq   #PTR_TABLE_SIZE-1,%d1
-1:     clrl    %a0@+
-       dbra    %d1,1b
+       put2c('#','#')
+       putr()

-       /* allocate 4 pages for 64 page tables */
-       movel   %a6,%a3
-       addw    #4*PAGESIZE,%a6
+mmu_print_tuple_invalidate_exit:
+       moveml  %sp@+,%a0/%d7
+       rts

-       /* initialize the pointer table */
-       movel   %a4,%a0
-       movel   %a3,%a1
-       addql   #_PAGE_TABLE,%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
+mmu_print_tuple:
+       moveml  %d0-%d7/%a0,%sp@-

-       /* ensure that the root table points to the pointer table */
-       movel   %a4,%a0
-       addql   #_PAGE_TABLE,%a0
-       movel   %a0,%a5@(0x40<<2)
-
-       /*
-        * initialize the page tables
-        * descriptor bits include noncachable/serialized and global bits.
-        */
-       movel   %a3,%a0
-       movew   #_PAGE_GLOBAL040+_PAGE_NOCACHE_S+_PAGE_PRESENT,%a1
-       movel   #PAGESIZE,%d2
-       movew   #(PAGE_TABLE_SIZE*TABLENR_16MB)-1,%d1
+       lea     %pc@(Lmmu_print_data),%a0

-1:     movel   %a1,%a0@+
-       addl    %d2,%a1
-       dbra    %d1,1b
+       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

-       /*
-        * 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
-
-       jra     Lmapphys
-
-Lnotmac:
-#endif
+mmu_print_tuple_print:
+       movel   %d0,%d7
+       jbsr    Lserial_putnum

-#ifdef CONFIG_ATARI
-       is_not_atari(Lnotatari)
+       put2c('-','>')

-       move.w  #PAGESIZE,%sp
+       movel   %d1,%d7
+       jbsr    Lserial_putnum

-/* 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.
-   0xffxxxxxx -> 0x00xxxxxx). For this, an additional pointer table is
-   needed. I/O ranges are marked non-cachable.
-
-   For the Medusa it is better to map the I/O region transparently
-   (i.e. 0xffxxxxxx -> 0xffxxxxxx), because some I/O registers are
-   accessible only in the high area. The test whether it is a Medusa
-   is done by writing to the byte at phys. 0x0. This should result
-   in a bus error on all other machines.
-
-   ...should, but doesn't. The Afterburner040 for the Falcon has the
-   same behaviour (0x0..0x7 are no ROM shadow). So we have to do
-   another test to distinguish Medusa and AB040. This is a
-   read attempt for 0x00ff82fe phys. that should bus error on a Falcon
-   (+AB040), but is in the range where the Medusa always asserts DTACK.
-*/
-
-       moveq   #0,%d3                  /* base addr for others: 0x00000000 */
-       movec   %d3,%vbr
-       lea     %pc@(Ltest_berr),%a0
-       movel   %a0,0x8
-       movel   %sp,%a0
-       moveb   0x0,%d1
-       clrb    0x0
-       nop
-       moveb   %d1,0x0
-       nop
-       tstb    0x00ff82fe
-       nop
-       movel   #0xff000000,%d3         /* Medusa base addr: 0xff000000 */
-Ltest_berr:
-       movel   %a0,%sp
-       lea     %pc@(SYMBOL_NAME(is_medusa)),%a0
-       movel   %d3,%a0@
-
-       /* Let the root table point to the new pointer table */
-       lea     %a4@(PTR_TABLE_SIZE<<2),%a4
-       movel   %a4,%a0
-       addl    #_PAGE_TABLE,%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
-       addl    #_PAGE_PRESENT,%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)
+       movel   %d1,%d6
+       jbsr    %a6@
+       putr()

-       jra     Lmapphys
+mmu_print_tuple_record:
+       movel   #MMU_PRINT_VALID,%a0@(mmu_next_valid)

-Lspata68040:
-       /* allocate 4 page tables */
-       movel   %a6,%a3
-       addw    #4*PAGESIZE,%a6
+       movel   %d1,%a0@(mmu_next_physical)

-       /* Initialize the upper half of the pointer table (a0 is still valid) */
-       movel   %a3,%a1
-       addql   #_PAGE_TABLE,%a1
-       movel   #PAGE_TABLE_SIZE<<2,%d2
-       moveq   #TABLENR_16MB-1,%d1
-1:     movel   %a1,%a0@+
-       addl    %d2,%a1
-       dbra    %d1,1b
+mmu_print_tuple_increment:
+       movel   %d5,%d7
+       subl    %a4,%d7
+       addl    %d7,%a0@(mmu_next_physical)

-       /* Initialize the page tables as noncacheable/serialized! */
-       movel   %a3,%a0
-       movel   %d3,%a1
-       addw    #_PAGE_GLOBAL040+_PAGE_NOCACHE_S+_PAGE_PRESENT,%a1
-       movel   #PAGESIZE,%d2
-       movew   #(PAGE_TABLE_SIZE*TABLENR_16MB)-1,%d1
-1:     movel   %a1,%a0@+
-       addl    %d2,%a1
-       dbra    %d1,1b
+mmu_print_tuple_exit:
+       moveml  %sp@+,%d0-%d7/%a0
+       rts

-       /*
-        * 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
+mmu_print_machine_cpu_types:
+       put4c('m','a','c','h')
+       put5c('i','n','e',':',' ')
+       is_not_amiga(1f)
+       put5c('a','m','i','g','a')
+       jbra    9f
+1:     is_not_atari(2f)
+       put5c('a','t','a','r','i')
+       jbra    9f
+2:     is_not_mac(3f)
+       put5c('m','a','c','i','n')
+       put5c('t','r','a','s','h')
+       jbra    9f
+3:     put5c('u','n','k','n','o')
+       put2c('w','n')
+9:     putr()
+
+       put4c('c','p','u','t')
+       put5c('y','p','e',':',' ')
+       putc('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()

-Lnotatari:
-#endif
+       rts

/*
- * Setup a transparent mapping of the physical memory we are executing in.
+ *     mmu_clear_root_table
+ *
+ *     %a5 = pointer to the root table
+ *
+ *     This routine will clear out the kernel root table
+ *
+ *     The root table points to 128 pointer tables.  Because the
+ *     root table describes 32 bits of logical memory, (and there
+ *     are 7 bits of indexing in the root table) there is 25 bits
+ *     of logical address space described by each entry in the
+ *     root table.  2^25 is 32Meg, another way to look at that is
+ *     4Gig / 128 = 32Meg.  Any entry which does not have bit 1 set
+ *     is not a valid entry.  In that case, a reference into that
+ *     memory range will cause a memory exception (bus error).
+ *
+ *     The pointer tables each have 128 entries.  Each entry
+ *     describes 1/128th of 32Meg, or 256K.  Again, any entry
+ *     with bit 1 cleared is not a valid entry.
 *
- * 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.
 */
-Lmapphys:
+mmu_clear_root_table:
+       movel   %d0,%sp@-

-#if 0
-       putc('J')
-#endif
-
-#ifdef CONFIG_AMIGA
-       is_not_amiga(Lmapphysnotamiga)
+       moveq   #ROOT_TABLE_SIZE-1,%d0
+1:     clrl    %a5@(%d0*4)
+       dbra    %d0,1b

-/*
- * 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.
- */
+       movel   %sp@+,%d0
+       rts

/*
- * Setup Supervisor Root Pointer register to point to page directory,
- * setup translation register contents and enable translation.
+ *     mmu_clear_pointer_table
+ *
+ *     %a4 = pointer to a pointer table
+ *
+ *     This routine will clear out a pointer table.
+ *     It does NOT link the pointer table into the root table
+ *     (that linkage is done by mapping memory!)
 */
+mmu_clear_pointer_table:
+       movel   %d0,%sp@-

-#if 0
-       putc('K')
-#endif
-
-       movew   #PAGESIZE,%sp
-
-       /* fixup the Amiga custom register location before printing */
-       lea     %pc@(Lcustom),%a0
-       movel   #0x80000000,%a0@
-
-       is_040_or_060(Lamimmu68040)
-
-       moveq   #ROOT_INDEX_SHIFT,%d2
-       movel   %d5,%d0
-       lsrl    %d2,%d0
-       movel   %d0,%d1
-       lsll    %d2,%d1
-       addql   #_PAGE_PRESENT,%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)
-       .long   0xf0134800      /* pmove %a3@,%srp */
-       .long   0xf0134c00      /* pmove %a3@,%crp */
-       .long   0xf0002400      /* pflusha */
-       /*
-        * enable,super root enable,4096 byte pages,7 bit root index,
-        * 7 bit pointer index, 6 bit page table index.
-        */
-       movel   #0x82c07760,%a3@
-       .long   0xf0134000      /* pmove %a3@,%tc (enable the MMU) */
-       tstl    %d0
-       jne     1f
-       jmp     %pc@(2f+0x80000000)
-1:     jmp     2f:w
-2:     movel   %d2,%a5@(%d0:w)
-       .long   0xf0002400      /* pflusha */
-       jmp     LdoneMMUenable:w
+       moveq   #PTR_TABLE_SIZE-1,%d0
+1:     clrl    %a4@(%d0*4)
+       dbra    %d0,1b

-Lamimmu68040:
+       movel   %sp@+,%d0
+       rts

-       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
-       .long   0x4e7b0004      /* movec %d0,%itt0 */
-       .long   0x4e7bd806      /* movec %a5,%urp */
-       .long   0x4e7bd807      /* movec %a5,%srp */
-       .word   0xf518          /* pflusha */
-       movel   #TC_ENABLE+TC_PAGE4K,%d0
       /*
-        * this value is also ok for the 68060, we don`t use the cache
-        * mode/protection defaults
+ *     mmu_clear_page_table
+ *
+ *     %a3 = pointer to a page table
+ *
+ *     This routine will clear out a pointer table.
+ *     It does NOT link the page table into the pointer table
+ *     (that linkage is done by mapping memory!)
        */
-       .long   0x4e7b0003      /* movec %d0,%tc (enable the MMU) */
-       jmp     %a0@
-2:     moveq   #0,%d0
-       .long   0x4e7b0004      /* movec %d0,%itt0 */
-       jmp     LdoneMMUenable:w
+mmu_clear_page_table:
+       movel   %d0,%sp@-

-Lmapphysnotamiga:
-#endif
+       moveq   #PAGE_TABLE_SIZE-1,%d0
+1:     clrl    %a3@(%d0*4)
+       dbra    %d0,1b

-#ifdef CONFIG_ATARI
-       is_not_atari(Lmapphysnotatari)
+       movel   %sp@+,%d0
+       rts

/*
- * 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_map
+ *
+ *     %a6 = address of free memory above kernel (page aligned)
+ *     %a5 = pointer to the root table
+ *     %a4 = pointer to a pointer table
+ *     %a1 = physical address of mapping
+ *     %a0 = logical address to map
+ *     %d1 = memory type
+ *     %d0 = length of the mapping
+ *
+ *     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 Lserial_putc
+ *     routines in the case of a run-time error.  For example,
+ *     if the address to be mapped requires two pointer tables
+ *     this routine will fail and the boot process will terminate.
+ *     A higher level routine would have to be written to call
+ *     this routine multiple times (with different parameters
+ *     if a single mapping might straddle multiple pointer tables.
+ *
+ *     NOTE-2
+ *     This routine will use early terminating descriptors
+ *     where possible for the 68020+68851 and 68030 type
+ *     processors.
+ *
+ *     Memory Type
+ *     0 = Cacheable (common)
+ *     1 = Non-cacheable (serialized)
+ *     2 = Global, cacheable
+ *     3 = Global, non-cacheable
 */
+mmu_map:
+       moveml  %d0-%d7/%a0-%a5,%sp@-

-#if 0
-       putc('L')
-#endif
+       /* Calculate the offset in the root table
+        */
+       movel   %a0,%d5
+       andil   #0xFE000000,%d5
+       roll    #7,%d5

-       /* fixup the  Atari iobase register location before printing */
-       lea     %pc@(Liobase),%a0
-       movel   #0xff000000,%a0@
+       /* Calculate the offset in the pointer table
+        */
+       movel   %a0,%d4
+       andil   #0x01fC0000,%d4
+       lsrl    #2,%d4
+       swap    %d4

-       is_040_or_060(Latarimmu68040)
+       /* Calculate the offset in the page table (used on 040's + 060's)
+        */
+       movel   %a0,%d3
+       andil   #0x0002F000,%d3
+       lsll    #4,%d3
+       swap    %d3

-       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@
-       .long   0xf0130800      /* 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
-       addql   #_PAGE_PRESENT,%d1
-       movel   %a1@,%d2
-       movel   %d1,%a1@
-       lea     5f:w,%a0
-       /* no limit, 4byte descriptors */
-3:     movel   #0x80000002,%a3@
-       movel   %a5,%a3@(4)
-       .long   0xf0134800      /* pmove %a3@,%srp */
-       .long   0xf0134c00      /* pmove %a3@,%crp */
-       .long   0xf0002400      /* pflusha */
-       /*
-        * enable,super root enable,4096 byte pages,7 bit root index,
-        * 7 bit pointer index, 6 bit page table index.
-        */
-       movel   #0x82c07760,%a3@
-       .long   0xf0134000      /* pmove %a3@,%tc (enable the MMU) */
-       jmp     %a0@
-4:     clrl    %a3@
-       .long   0xf0130800      /* pmove %a3@,%tt0 */
-       jra     LdoneMMUenable
-5:     movel   %d2,%a1@
-       jra     LdoneMMUenable
+       /* Convert address range length into # of pages
+        */
+       divul   #PAGESIZE,%d0

-Latarimmu68040:
-       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
-       .long   0x4e7b0004      /* movec %d0,%itt0 */
-2:     nop
-       .word   0xf518          /* pflusha */
-       .long   0x4e7bd807      /* movec %a5,%srp */
-       .long   0x4e7bd806      /* 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
+        *      The code that follows implements the following rules
+        *      with respect to the pointer table for this memory mapping
+        *      1) If the memory to be mapped lies within an already
+        *         mapped region, there will be a pointer table listed
+        *         in the root table.  This pointer table must be used.
+        *      2) If the caller does not supply a pointer table, a table
+        *         will be allocated from above the kernel.
+        *      3) Else, the caller must have passed the address to memory
+        *         that will be used as the pointer table for this mapping.
        */
-       .long   0x4e7b0003      /* movec %d0,%tc (enable the MMU) */
-       jmp     %a0@
-3:     moveq   #0,%d0
-       .long   0x4e7b0004      /* movec %d0,%itt0 */
-       tstl    %a1
-       jra     LdoneMMUenable
-
-Lmapphysnotatari:
-#endif
+mmu_map_check_root_entry:
+       /* Is another pointer table already mapped into this root entry?
+        */
+       movel   %a5@(%d5*4),%d2
+       jbeq    mmu_map_check_make_new_pointer_table

-#ifdef CONFIG_MAC
-       is_not_mac(Lmapphysnotmac)
+       /* If there is an entry already, we must use it
+        * to preserve existing MMU mapping data!
+        */
+       andil   #0xFFFFFE00,%d2         /* 040 MMU Ptr mask */
+       movel   %d2,%a4
+       jbra    2f

-#ifdef DEBUG_MAC
-       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
-       movel   %a0@(BI_videorow),%d0   /* rowbytes */
-       andl    #0xFFFF,%d0             /* bytes per rows */
-       movel   %a0@(BI_videoaddr),%a0  /* videoaddr */
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0                 /* 5 rows */
-       subl    #3, %d0
+mmu_map_check_make_new_pointer_table:
1:
-       moveb   #0xFF,%a0@+             /* black - 2 bytes : present */
-       dbra    %d0,1b
-#endif
+       /* Should we get a pointer table from memory on behalf of the caller?
+        */
+       cmpl    #0x00000000,%a4
+       jbne    2f

-#if 0
-       putc('L')
-#endif
+       jbsr    mmu_get_pointer_table

-       is_040_or_060(Lmacmmu68040)
+       /* Put the pointer table into the root table
+        */
+2:
+       movel   %a4,%d2
+       oril    #_PAGE_TABLE,%d2
+       movel   %d2,%a5@(%d5*4)
+
+       /* Split up here, 030's have different logic than 040's
+        */
+3:
+/*     is_not_040_or_060(mmu_map_030)
+ */

-       lea     %pc@(Lmmu),%a3
-       movel   %d5,%d0
-       /* We always follow this path as the kernel is at 0x0000 after
-          the MacBoot has finished */
-       /* no transparent translation ?? */
-
-       lea     LdoneMMUenable:w,%a0
-       movel   #0x80000002,%a3@
-       movel   %a5,%a3@(4)
-       .long   0xf0134800      /* pmove %a3@,%srp */
-       .long   0xf0134c00      /* pmove %a3@,%crp */
-       .long   0xf0002400      /* pflusha */
-       /*
-        * enable,super root enable,4096 byte pages,7 bit root index,
-        * 7 bit pointer index, 6 bit page table index.
-        */
-       movel   #0x82c07760,%a3@
-       .long   0xf0134000      /* pmove %a3@,%tc (enable the MMU) */
-       jmp     %a0@
-
-Lmacmmu68040:
-       movel   %d5,%d0
-       lea     LdoneMMUenable:w,%a0
-       jra     2f
-2:     nop
-       .word   0xf518          /* pflusha */
-       .long   0x4e7bd807      /* movec %a5,%srp */
-       .long   0x4e7bd806      /* 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
+ *     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.  Register A6 points to the memory above kernel and
+ *     it is from that pool that page tables are allocated.
+ *
+ *     For each page table that is allocated from above the kernel,
+ *     that page table's address has to be put into the pointer table.
+ *     Then, each page table has to be fully prepared.  Page tables,
+ *     by the way describe a full 256K of memory.  That coincides with
+ *     the fact that a single entry in the pointer table describes
+ *     a 256K of memory because a pointer table entry points to a
+ *     complete page table.  There are 64 entries in the page table,
+ *     and each entry in the page table points to a physical page of
+ *     memory.  Each page is 4K.
+ *
+ *     Also, there is a label "kpt" which holds the pointer to the
+ *     page table that describes the kernel.  This is only true on
+ *     the 040 and 060 cpu's.  This algorithm, because it's general
+ *     and allows the mapping of arbitrary regions of memory, assumes
+ *     that the first memory mapping is the one which maps the kernel.
+ *     So it's that page table that gets stored at kpt.
+ *
+ *     Also, it is an error to attempt to map two regions that
+ *     fall within the same 256K range.  For that to work, this routine
+ *     would need to be modified.
+ *
+ *
+ *
        */
-       .long   0x4e7b0003      /* movec %d0,%tc (enable the MMU) */
-       jmp     %a0@
-3:     moveq   #0,%d0
-       .long   0x4e7b0004      /* movec %d0,%itt0 */
-       tstl    %a1
-       jra     LdoneMMUenable
-
-       /* NOT reached (and if we try to write to screenmem after MMU
-        * enable - what happens??)
+mmu_map_040:
+       /* Turn abstract cache type into 040 cache bits
        */
+       andil   #3,%d1
+       movel   %pc@(Lmmu_040_cache_flags,%d1*4),%d1
+       addw    %d1,%a1

-#ifdef DEBUG_MAC
-       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
-       movel   %a0@(BI_videorow),%d0   /* rowbytes */
-       andl    #0xFFFF,%d0             /* bytes per rows */
-       movel   %a0@(BI_videoaddr),%a0  /* videoaddr */
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0                 /* 5 rows */
-       subl    #4, %d0
-1:
-       moveb   #0xF0,%a0@+             /* white/black - 3 bytes */
-       dbra    %d0,1b
-#endif
+mmu_040_loop:
+       /* See if there is an existing page table pointer to use
+        */
+       movel   %a4@(%d4*4),%a3
+       tstl    %a3
+       jbne    1f

-Lmapphysnotmac:
-#endif
+       jbsr    mmu_get_page_table

-LdoneMMUenable:
+1:
+       /* Now, begin assigning physical pages into the page table
+        */
+mmu_fill_040_pagetable:
+       movel   %a1,%a3@(%d3*4)

-/*
- * Fixup the addresses for the kernel pointer table and availmem.
- * Convert them from physical addresses to virtual addresses.
+       /* Decrement page count
 */
+       subq    #1,%d0
+       jbeq    mmu_map_done

-#ifdef DEBUG_MAC
-       is_not_mac(2f)
-       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
-       movel   %a0@(BI_videorow),%d0   /* rowbytes */
-       andl    #0xFFFF,%d0             /* bytes per rows */
-       movel   %a0@(BI_videoaddr),%a0  /* videoaddr */
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0
-       addl    %d0,%d0                 /* 5 rows */
-       subl    #4, %d0
-1:
-       moveb   #0x00,%a0@+             /* white - 3 bytes : present */
-       dbra    %d0,1b
-2:
-#endif
+       /* Increase mapping addresses
+        */
+       addl    #PAGESIZE,%a1
+       addl    #PAGESIZE,%a0

-/*     putc('M')*/
+       /* Have we exhausted this page table?
+        */
+       addq    #1,%d3
+       cmpil   #PAGE_TABLE_SIZE,%d3
+       jbne    mmu_fill_040_pagetable

-       /*
-        * d5 contains physaddr of kernel start
+       /* Have we exhausted this pointer table?
        */
-       subl    %d5,SYMBOL_NAME(kpt)
+       clrl    %d3
+       addq    #1,%d4
+       cmpil   #PTR_TABLE_SIZE,%d4
+       jbne    mmu_040_loop

-       /*
-        * do the same conversion on the first available memory
-        * address (in a6).
+       /* It's an error to exhaust the pointer table
+        *
+        *      FIXME -- but it's trivial to fix this now
        */
-       subl    %d5,%a6
-       movel   %a6,SYMBOL_NAME(availmem) /* first available memory address */
+       movel   #4,%d0
+       jbra    mmu_err

-/*     putc('N')*/
+mmu_map_done:
+       moveml  %sp@+,%d0-%d7/%a0-%a5
+       rts

-#if 0
-       putr()
-       lea     SYMBOL_NAME(kernel_pmd_table),%a0
-       moveq   #63,%d0
-1:     moveq   #7,%d1
-       putn(%a0)
-       putc(':')
-       putc(' ')
-2:     putn(%a0@+)
-       dbra    %d1,2b
-       putr()
-       dbra    %d0,1b
-       putr()
-       movel   SYMBOL_NAME(kpt),%a0
-       moveq   #639,%d0
-1:     moveq   #7,%d1
-       putn(%a0)
-       putc(':')
-       putc(' ')
-2:     putn(%a0@+)
-       dbra    %d1,2b
-       putr()
-       dbra    %d0,1b
-#endif
-/*
- * Enable caches
- */

-       /*
-       ** Will work only if virtual == physical
-       */
-#ifdef DEBUG_MAC
-       is_not_mac(Lcache_notmac)
-       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
-       movel   %a0@(BI_videorow),%d0   /* rowbytes */
-       andl    #0xFFFF,%d0             /* bytes per rows */
-       movel   %a0@(BI_videoaddr),%a0
-       addl    %d0,%d0
-       addl    %d0,%d0
-1:
-       moveb   #0x33,%a0@+
-       dbra    %d0,1b
-Lcache_notmac:
-#endif
+mmu_err:
+       put3c('E','r','r')

-       is_040_or_060(Lcache680460)
+       movel   %d0,%d7
+       jbsr    Lserial_putnum

-       movel   #CC3_ENABLE_DB+CC3_CLR_D+CC3_ENABLE_D+CC3_ENABLE_IB+CC3_CLR_I+CC3_ENABLE_I,%d0
-       movec   %d0,%cacr
+       jbsr    mmu_print

-#ifdef DEBUG_MAC
-       is_not_mac(Lcache_notmac030)
-       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
-       movel   %a0@(BI_videorow),%d0   /* rowbytes */
-       andl    #0xFFFF,%d0             /* bytes per rows */
-       movel   %a0@(BI_videoaddr),%a0
-       addl    %d0,%d0
-1:
-       moveb   #0xFF,%a0@+
-       dbra    %d0,1b
-Lcache_notmac030:
-#endif
+mmu_fail:
+       jbra    mmu_fail

-       jra     1f

-Lcache680460:
-       .word   0xf4f8          /* cpusha %bc */
+mmu_get_page_table:
+       moveml  %a0-%a2/%d0-%d2,%sp@-

-       is_060(Lcache68060)
+       /* See if there is a page table in our cache of page tables
+        */
+       lea     %pc@(Lmmu_cached_page_tables),%a2
+       movel   %a2@,%d2
+       jbeq    1f

-       movel   #CC6_ENABLE_D+CC6_ENABLE_I,%d0
-       /* MMU stuff works in copyback mode now, so enable the cache */
-       movec   %d0,%cacr
-       jra     1f
+       andil   #0x00000F00,%d2
+       jbeq    1f

-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
-       .long   0x4e7b0808      /* movec d0,pcr */
-1:
+       /* There is an unused page table in our cache... use it
+        */
+       movel   %a2@,%d2
+       movel   %d2,%a3
+       addil   #PAGE_TABLE_SIZE*4,%d2
+       movel   %d2,%a2@
+       jbra    2f
+
+1:     /* Get the page table from above the kernel memory
+        */
+       movel   %a6,%a3
+       addw    #PAGESIZE,%a6   /* allocate page for 16 page tables */
+       movel   %a3,%a2@
+2:
+       jbsr    mmu_clear_page_table
+
+       /* Is this the first page table allocated?
+        */
+       lea     %pc@(SYMBOL_NAME(kpt)),%a2
+       tst     %a2@
+       jbne    1f
+
+       /* Store the page table address at kpt.
+        */
+       movel   %a3,%a2@        /* save adddress of first page table */

-#ifdef DEBUG_MAC
-       is_not_mac(Lstart_notmac)
-       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
-       movel   %a0@(BI_videorow),%d0   /* rowbytes */
-       andl    #0xFFFF,%d0             /* bytes per rows */
-       movel   %a0@(BI_videoaddr),%a0
1:
-       moveb   #0x00,%a0@+
-       dbra    %d0,1b
-Lstart_notmac:
-#endif
+       /* Log this page table (%a3) in the pointer table (%a4)
+        */
+       movel   %a3,%d2
+       orib    #2,%d2  /* enable this pointer table entry */
+       movel   %d2,%a4@(%d4*4)

-/*
- * Setup initial stack pointer
+       moveml  %sp@+,%a0-%a2/%d0-%d2
+       rts
+
+mmu_get_pointer_table:
+       moveml  %a0-%a2/%d0-%d2,%sp@-
+
+       /* See if there is a pointer table in our cache of pointer tables
 */
-       lea     SYMBOL_NAME(init_user_stack)+PAGESIZE,%sp
+       lea     %pc@(Lmmu_cached_pointer_tables),%a2
+       movel   %a2@,%d2
+       jbeq    1f

-/* jump to the kernel start */
-/*     putr()*/
+       andil   #0x00000E00,%d2
+       jbeq    1f

-       jbsr    SYMBOL_NAME(start_kernel)
+       /* There is an unused pointer table in our cache... use it
+        */
+       movel   %a2@,%d2
+       movel   %d2,%a4
+       addil   #PTR_TABLE_SIZE*4,%d2
+       movel   %d2,%a2@
+       jbra    2f

-/*
- * switch off mmu and exit
+1:     /* Get the page table from above the kernel memory
 */
+       movel   %a6,%a4
+       addw    #PAGESIZE,%a6   /* allocate page for 8 ptr tables */
+       movel   %a4,%a2@
+2:
+       jbsr    mmu_clear_pointer_table

-#ifdef HACKER_KERNEL
-ENTRY(kernel_exit)
-       lea     2f:w,%a0
-       movel   %pc@(Lkernel_start),%a0
-       lea     %a0@(2f:w),%a1
-       movel   %a1,%d0
-       andl    #0xff000000,%d0
-       jne     1f
-       jmp     %a0@(1f+0x80000000)
-1:     orw     #TTR_ENABLE+TTR_KERNELMODE+_PAGE_NOCACHE_S,%d0
-       .long   0x4e7b0004      /* movec %d0,%itt0 */
-       jmp     %a1@
-2:     moveq   #0,%d0
-       .long   0x4e7b0003      /* movec %d0,%tc (disable the MMU) */
-       .word   0xf518          /* pflusha */
-       .long   0x4e7b0004      /* movec %d0,%itt0 */
-       movec   %d0,%cacr
-       .word   0xf4f8          /* cpusha %bc */
+       /* Log this pointer table (%a4) in the root table (%a5)
+        */
+       movel   %a4,%d2
+       orib    #2,%d2  /* enable this pointer table entry */
+       movel   %d2,%a5@(%d5*4)
+
+       moveml  %sp@+,%a0-%a2/%d0-%d2
+       rts

-       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
-       jmp     %a0@(BI_amiga_exit_func:w)@(0:w)
-#endif

/*
 * Serial port output support.
@@ -1783,8 +1426,7 @@
       .even
Lserial_init:
#ifdef CONFIG_AMIGA
-       cmpil   #MACH_AMIGA,%d4
-       jne     1f
+       is_not_amiga(1f)
       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
       bclr    #LSERIAL_DTR,LSERIAL_CNTRL
       movew   #LNTSC_PERIOD,LSERPER
@@ -1795,8 +1437,7 @@
1:
#endif
#ifdef CONFIG_ATARI
-       cmpil   #MACH_ATARI,%d4
-       jne     4f
+       is_not_atari(4f)
#ifdef USE_PRINTER
       bclr    #0,LSTMFP_IERB
       bclr    #0,LSTMFP_DDR
@@ -1825,21 +1466,13 @@
       orb     #1,LMFP_TDCDR
       bset    #1,LMFP_TSR
#endif
-#endif
4:
-#ifdef defined(CONFIG_MAC)
-#ifdef MACSERIAL
-       cmpil   #MACH_MAC,%d4
-       jne     3f
-       lea     #50F04000,%a0
-       lea     %pc@(scc_initable_mac:w),%a1
-2:     moveb   %a1@+,%d0
-       jmi     3f
-       moveb   %d0,%a0@
-       moveb   %a1@+,%a0@
-       jra     2b
-3:
-#endif /* MACSERIAL */
+#endif
+#if defined(CONFIG_MAC)
+       is_not_mac(5f)
+       jbsr    Lconsole_init
+       jbra    9f
+5:
#endif
9:
       rts
@@ -1849,10 +1482,16 @@
 * d7 thrashed.
 */
Lserial_putc:
+       cmpib   #'\n',%d7
+       jbne    1f
+
+       putc(13)        /* A little safe recursion is good for the soul */
+       moveb   #'\n',%d7
+1:
       moveml  %a0/%a1,%sp@-
+
#ifdef CONFIG_AMIGA
-       cmpil   #MACH_AMIGA,%d4
-       jne     2f
+       is_not_amiga(2f)
       andw    #0x00ff,%d7
       oriw    #0x0100,%d7
       movel   %pc@(Lcustom),%a1
@@ -1863,23 +1502,16 @@
       jra     9f
2:
#endif
+
#ifdef CONFIG_MAC
-#ifdef MACSERIAL
-       /* check if mac ... */
-       cmpil   #MACH_MAC,%d4
-       jne     4f
-       /* should check if MAC .. - note this base is for a MacII and later ! */
-       lea     0x50F04000,%a1
-3:     btst    #2,%a1@(0)
-       jeq     3b
-       moveb   %d7,%a1@(4)
+       is_not_mac(4f)
+       jbsr    Lconsole_putc
       jra     9f
4:
-#endif /* MACSERIAL */
#endif
+
#ifdef CONFIG_ATARI
-       cmpil   #MACH_ATARI,%d4
-       jne     4f
+       is_not_atari(4f)
       movel   %pc@(Liobase),%a1
#ifdef USE_PRINTER
3:     btst    #0,%a1@(LSTMFP_GPIP)
@@ -1924,8 +1556,6 @@

/*
 * Output number in d7 in hex notation on serial port.
- * d0-d2 trashed.
- * d7 trashed.
 */

Lserial_putnum:
@@ -1948,25 +1578,479 @@
       moveml  %sp@+,%d0-%d2/%d7
       rts

+#if defined(CONFIG_MAC)
+/*
+ *     For continuity, see the data alignment
+ *     to which this structure is strong tied.
+ */
+#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
+
+#define MAC_CONSOLE_SCROLL
+
+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(boot_info)),%a0
+       lea     %pc@(SYMBOL_NAME(Lconsole_globals)),%a2
+       movel   %a0@(BI_videoaddr), %a1
+       movel   %a0@(BI_videorow),%d5
+       movel   %a0@(BI_dimensions), %d3
+       movel   %d3,%d4
+       swap    %d4
+       andl    #0xffff,%d3     /* d3 = screen width in pixels */
+       andl    #0xffff,%d4     /* d4 = screen height in pixels */
+
+       movel   %d5,%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 global maxs
+        *      Note - we can use either an
+        *      8 x 16 or 8 x 8 character font
+        */
+       movel   %d3,%d0         /* screen width in pixels */
+       divul   #8,%d0          /* d0 = max num chars per row */
+
+       movel   %d4,%d1          /* screen height in pixels */
+       divul   #FONT_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 ... now output some
+        * debugging information
+        */
+
+       jbsr    console_put_penguin
+
+Lconsole_put_stats:
+       putr()
+       put3c('M','a','c')
+       put5c('L','i','n','u','x')
+       putr()
+       putr()
+
+#ifdef SERIAL_DEBUG
+       put4c(' ','v','i','d')
+       put5c('a','d','d','r',':');
+       movel   %a0@(BI_videoaddr), %d7         /* video addr. */
+       jbsr    Lserial_putnum                  /* This redirects to console */
+       putr()
+
+       put4c(' ',' ','_','s')
+       put5c('t','e','x','t',':')
+       lea     %pc@(SYMBOL_NAME(_stext)),%a0
+       movel   %a0,%d7         /* get start addr. */
+       jbsr    Lserial_putnum
+       putr()
+
+       put4c('b','o','o','t')
+       put5c('i','n','f','o',':')
+       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
+       movel   %a0, %d7        /* write start addr. */
+       jbsr    Lserial_putnum
+       putr()
+
+       put5c('c','p','u','i','d')
+       putc(':')
+       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
+       movel   %a0@(BI_cputype),%d7
+       jbsr    Lserial_putnum
+       putr()
+
+       jbsr    mmu_print_machine_cpu_types
+#endif
+
+       moveml  %sp@+,%a0-%a4/%d0-%d7
+       rts
+
+console_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@(SYMBOL_NAME(boot_info)),%a0
+       movel   %a0@(SYMBOL_NAME(BI_dimensions)),%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
+
+console_scroll:
+       moveml  %a0-%a4/%d0-%d7,%sp@-
+
+       lea     %pc@(SYMBOL_NAME(boot_info)),%a0
+
+       /*
+        * Calculate source and destination addresses
+        *      output  a1 = dest
+        *              a2 = source
+        */
+       movel   %a0@(BI_videoaddr),%a1
+       movel   %a1,%a2
+       movel   %a0@(BI_videorow),%d5
+       mulul   #FONT_HEIGHT,%d5 /* account for # scan lines per character */
+       addal   %d5,%a2
+
+       /*
+        * Get dimensions
+        */
+       movel   %a0@(BI_dimensions), %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
+        */
+       movel   %a0@(BI_videorow),%d6
+       subil   #FONT_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 bytes 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
+
+       movel   %a0@(BI_videorow),%d6
+       mulul   #FONT_HEIGHT,%d6        /* scan line bytes x font height */
+       divul   #32,%d6         /* we'll move 8 bytes 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
+
+/*
+ *     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@-
+       movel   %sp@(8),%a0             /* fetch parameter */
+       jbsr    Lserial_puts
+       movel   %sp@+,%a0
+       rts
+
+
+Lconsole_putc:
+/*
+ * Output character in d7 on console.
+ */
+       moveml  %a0/%a1/%d0-%d7,%sp@-
+
+       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
+#if defined(MAC_CONSOLE_SCROLL)                /* regular scrolling code */
+       subil   #1,%d0
+       movel   %d0,%a0@(Lconsole_struct_cur_row)
+       jbsr    console_scroll
+#else          /* make-shift scroller, use dual columns on screen */
+       moveq   #10,%d0
+       movel   %d0,%a0@(Lconsole_struct_cur_row)
+       moveq   #52,%d0
+       addl    %d0,%a0@(Lconsole_struct_left_edge)
+#endif
+1:
+       jra     console_exit
+
+console_not_lf:
+       cmpib   #13,%d7
+       jne     console_not_cr
+#if defined(MAC_CONSOLE_SCROLL)
+       clrl    %a0@(Lconsole_struct_cur_column)
+#else
+       movel   %a0@(Lconsole_struct_left_edge),%a0@(Lconsole_struct_cur_column)
+#endif
+       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_cr:
+       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
+
+       movel   #FONT_HEIGHT,%d2
+       cmpil   #16,%d2
+       beq     console_8x16
+console_8x8:
+       lea     %pc@(SYMBOL_NAME(fontdata_8x8)),%a1
+       jbra    console_got_fontaddr
+
+console_8x16:
+       lea     %pc@(SYMBOL_NAME(fontdata_8x16)),%a1
+
+console_got_fontaddr:
+       andl    #0x000000ff,%d7
+       mulul   #FONT_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
+        */
+       mulul   #8,%d0
+       mulul   #FONT_HEIGHT,%d1
+       moveq   #FONT_HEIGHT,%d7
+       subq    #1,%d7
+console_read_char_scanline:
+       moveb   %a1@+,%d3
+
+       movel   #7,%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
+
+       subq    #8,%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@(SYMBOL_NAME(boot_info)),%a0
+       movel   %a0@(BI_videoaddr),%a1
+       movel   %a0@(BI_videodepth),%d3
+       mulul   %a0@(BI_videorow),%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    console_plot_pixel_exit
+       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
+
+console_plot_pixel_exit:
+       moveml  %sp@+,%a0-%a1/%d0-%d4
+       rts
+#endif
+
Lshowtest:
       moveml  %a0/%d7,%sp@-
-       putc('A')
-       putc('=')
+       put2c('A','=')
       putn(%a1)

       .long   0xf0119f15              | ptestr        #5,%a1@,#7,%a0

-       putc('D')
-       putc('A')
-       putc('=')
+       put3c('D','A','=')
       putn(%a0)

-       putc('D')
-       putc('=')
+       put2c('D','=')
       putn(%a0@)

-       putc('S')
-       putc('=')
+       put2c('S','=')
       lea     %pc@(Lmmu),%a0
       .long   0xf0106200              | pmove         %psr,%a0@
       clrl    %d7
@@ -1987,6 +2071,38 @@
Liobase:
       .long 0
Lmmu:  .quad 0
+
+Lmachinetype:
+       .long   0
+Lcputype:
+       .long   0
+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 */
+
+Lmmu_print_data:
+       .long   0               /* valid flag */
+       .long   0               /* start logical */
+       .long   0               /* next logical */
+       .long   0               /* start physical */
+       .long   0               /* next physical */
+
+Lmmu_040_cache_flags:
+       .long   _PAGE_PRESENT+_PAGE_CACHE040
+       .long   _PAGE_PRESENT+_PAGE_CACHE040W
+       .long   _PAGE_PRESENT+_PAGE_GLOBAL040+_PAGE_NOCACHE_S
+       .long   0
+
+Lmmu_cached_page_tables:
+       .long   0
+
+Lmmu_cached_pointer_tables:
+       .long   0
+
SYMBOL_NAME_LABEL(mac_booter_data)
       .long 0
SYMBOL_NAME_LABEL(peng_booter_data)
diff -rubBwN linux-270897/arch/m68k/kernel/process.c linux-2.0.29/arch/m68k/kernel/process.c
--- linux-270897/arch/m68k/kernel/process.c     Fri Sep 12 21:21:37 1997
+++ linux-2.0.29/arch/m68k/kernel/process.c     Mon Sep 22 00:29:15 1997
@@ -134,6 +134,14 @@
        */
       p->tss.fs = get_fs();

+       /*
+        * MS: don't fiddle with the FPU state if no FPU !!
+        * FIXME: need to check if
+        *      a) no FPU present (->bootinfo), _and_
+        *      b) no LINE11 trap installed (emulator needs FPU state)!
+        */
+
+       if (boot_info.cputype & (FPU_68881|FPU_68882|FPU_68040|FPU_68060)) {
       /* Copy the current fpu state */
       asm volatile ("fsave %0" : : "m" (p->tss.fpstate[0]) : "memory");

@@ -146,13 +154,14 @@
       /* Restore the state in case the fpu was busy */
       asm volatile ("frestore %0" : : "m" (p->tss.fpstate[0]));
}
+}

/* Fill in the fpu structure for a core dump.  */

int dump_fpu (struct user_m68kfp_struct *fpu)
{
  char fpustate[216];
-
+  if (boot_info.cputype & (FPU_68881|FPU_68882|FPU_68040|FPU_68060)) {
  /* First dump the fpu context to avoid protocol violation.  */
  asm volatile ("fsave %0" :: "m" (fpustate[0]) : "memory");
  if((!CPU_IS_060 && !fpustate[0]) || (CPU_IS_060 && !fpustate[2]))
@@ -165,6 +174,8 @@
               :: "m" (fpu->fpregs[0])
               : "memory");
  return 1;
+  }
+  return 0;
}

/*
diff -rubBwN linux-270897/arch/m68k/kernel/setup.c linux-2.0.29/arch/m68k/kernel/setup.c
--- linux-270897/arch/m68k/kernel/setup.c       Fri Sep 12 21:21:37 1997
+++ linux-2.0.29/arch/m68k/kernel/setup.c       Sun Sep 21 23:31:41 1997
@@ -91,6 +91,7 @@
extern void register_console(void (*proc)(const char *));
extern void ami_serial_print (const char *str);
extern void ata_serial_print (const char *str);
+extern void mac_serial_print (const char *str);

extern void (*kd_mksound)(unsigned int, unsigned int);

@@ -116,6 +117,9 @@

       if (MACH_IS_ATARI)
               register_console(ata_serial_print);
+
+       if (MACH_IS_MAC)
+               register_console(mac_serial_print);

       if (CPU_IS_040)
               m68k_is040or060 = 4;
diff -rubBwN linux-270897/arch/m68k/kernel/signal.c linux-2.0.29/arch/m68k/kernel/signal.c
--- linux-270897/arch/m68k/kernel/signal.c      Sat Oct  5 06:24:07 1996
+++ linux-2.0.29/arch/m68k/kernel/signal.c      Mon Sep 22 00:29:15 1997
@@ -161,6 +161,8 @@
                             : "m" (*context.sc_fpregs),
                               "m" (*context.sc_fpcntl));
         }
+       /* XXX MS: skip FPU restore if no FPU ! */
+       if (boot_info.cputype & (FPU_68881|FPU_68882|FPU_68040|FPU_68060))
       __asm__ volatile ("frestore %0" : : "m" (*context.sc_fpstate));

       fsize = extra_sizes[regs->format];
@@ -316,6 +318,9 @@
       context.sc_sr         = regs->sr;
       context.sc_pc         = regs->pc;
       context.sc_formatvec  = (regs->format << 12 | regs->vector);
+
+       /* XXX MS: skip FPU dump if no FPU */
+       if (boot_info.cputype & (FPU_68881|FPU_68882|FPU_68040|FPU_68060)) {
       __asm__ volatile ("fsave %0" : : "m" (*context.sc_fpstate) : "memory");
       if ((!CPU_IS_060 && context.sc_fpstate[0]) || (CPU_IS_060 && context.sc_fpstate[2])){
               fpu_version = context.sc_fpstate[0];
@@ -325,6 +330,7 @@
                                 : "m" (*context.sc_fpregs),
                                 "m" (*context.sc_fpcntl)
                                 : "memory");
+         }
       }
       memcpy_tofs (tframe, &context, sizeof(context));

diff -rubBwN linux-270897/arch/m68k/kernel/traps.c linux-2.0.29/arch/m68k/kernel/traps.c
--- linux-270897/arch/m68k/kernel/traps.c       Fri Sep 12 21:21:37 1997
+++ linux-2.0.29/arch/m68k/kernel/traps.c       Mon Sep 22 00:29:15 1997
@@ -671,7 +671,11 @@
   vmalloced.  */
#define MODULE_RANGE (8*1024*1024)

-static void dump_stack(struct frame *fp)
+/*
+ * XXX MS: export dump_stack to Mac debug handles
+ */
+
+/*static*/ void dump_stack(struct frame *fp)
{
       unsigned long *stack, *endstack, addr, module_start, module_end;
       extern char _start, _etext;
diff -rubBwN linux-270897/arch/m68k/mac/config.c linux-2.0.29/arch/m68k/mac/config.c
--- linux-270897/arch/m68k/mac/config.c Fri Sep 12 21:21:38 1997
+++ linux-2.0.29/arch/m68k/mac/config.c Mon Sep 22 00:24:42 1997
@@ -111,46 +111,13 @@

void config_mac(void)
{
-    int xd,yd;
-    int y;
-    unsigned char c=0xF0;
-    unsigned char *bp=(unsigned char *)boot_info.bi_mac.videoaddr;

    if (MACH_IS_ATARI || MACH_IS_AMIGA) {
      printk("ERROR: no Mac, but config_mac() called!! \n");
    }

-    mac_env=(char *)boot_info.bi_mac.args;
-
-    xd=boot_info.bi_mac.dimensions;
-
-    yd=xd>>16;
-    xd&=0xFFFF;
-
-#if 0
-    /* clear screen */
-    for(y=0;y<16;y++)
-    {
-       memset(bp+y*boot_info.bi_mac.videorow,
-               0x00,boot_info.bi_mac.videorow);
-    }
-    memset(bp+y*boot_info.bi_mac.videorow,
-               0xFF,boot_info.bi_mac.videorow);
-
-    *bp=0xFF;
-    bp[boot_info.bi_mac.videorow-1]=0xFF;
-    bp[boot_info.bi_mac.videorow]=0xF0;
-    bp[boot_info.bi_mac.videorow*2-1]=0x0F;
-
-    for(y=17;y<yd;y++)
-    {
-       memset(bp+y*boot_info.bi_mac.videorow,
-               c,boot_info.bi_mac.videorow);
-       c^=0xFF;
-    }
-#endif
-
-    mac_debugging_penguin(5);
+    printk("Welcome to MacLinux!\n");
+    printk("Please visit www.maclinux.org\n");

    mach_sched_init      = mac_sched_init;
    mach_keyb_init       = mac_keyb_init;
@@ -183,8 +150,12 @@
     */

    mac_identify();
+    mac_report_hardware();
+
    /* goes on forever if timers broken */
-    /*mac_mksound(1000,100);*/
+#ifdef MAC_DEBUG_SOUND
+    mac_mksound(1000,10);
+#endif

    /*
     * Check for machine specific fixups.
@@ -273,11 +244,12 @@
       int model = boot_info.bi_mac.id;
       if (!model) {
       /* no bootinfo model id -> NetBSD booter was used! */
-               model=(boot_info.bi_mac.cpuid>>2)&31;   /* breaks for model > 31 */
+               /* XXX FIXME: breaks for model > 31 */
+               model=(boot_info.bi_mac.cpuid>>2)&31;
               printk ("No bootinfo model ID, using cpuid instead (hey, use Penguin!)\n");
       }

-       printk ("Detected Macintosh model: %d ", model);
+       printk ("Detected Macintosh model: %d \n", model);

       while(m->ident != -1)
       {
@@ -288,13 +260,11 @@
       if(m->ident==-1)
       {
               printk("\nUnknown macintosh model %d.\n", model);
-               mac_debugging_long(0, (long) 0x55555555);
-               mac_debugging_long(0, (long) model);
#if 0
               mac_boom(5);
#else
               model = MAC_MODEL_Q800;
-               printk("Hardcoding: Micha's Quadra800, model id %d\n", model);
+               printk("Hardcoding: Quadra800, model id %d\n", model);
               m=&mac_data_table[0];
               while(m->ident != -1)
               {
@@ -312,23 +282,35 @@
       printk (" Video: addr %lx row %lx depth %lx dimensions %lx\n",
               boot_info.bi_mac.videoaddr, boot_info.bi_mac.videorow,
               boot_info.bi_mac.videodepth, boot_info.bi_mac.dimensions);
-       printk (" Args: %ld CPU ID: %lx boottime %lx GMTBias %ld \n",
-               boot_info.bi_mac.args, boot_info.bi_mac.cpuid,
+       printk (" Args: %ld CPU type: %lx boottime %lx GMTBias %ld \n",
+               boot_info.bi_mac.args, boot_info.cputype,
               boot_info.bi_mac.boottime, boot_info.bi_mac.gmtbias);
-       printk (" Booter version: %ld video log.: %lx SCC at %lx \n",
+       printk (" Booter version: %lx video log.: %lx SCC at %lx \n",
               boot_info.bi_mac.bootver, boot_info.bi_mac.videological,
               boot_info.bi_mac.scc);
       printk (" Machine ID: %ld memory size: %lx \n",
               boot_info.bi_mac.id, boot_info.bi_mac.memsize);
-       printk (" Serial : %ld handshake: %lx GPI: %lx \n",
+       printk (" Serial : %lx handshake: %lx GPI: %lx \n",
               boot_info.bi_mac.serialmf, boot_info.bi_mac.serialhsk,
               boot_info.bi_mac.serialgpi);
-       printk (" Printer: %ld handshake: %lx GPI: %lx \n",
+       printk (" Printer: %lx handshake: %lx GPI: %lx \n",
               boot_info.bi_mac.printmf, boot_info.bi_mac.printhsk,
               boot_info.bi_mac.printgpi);
-       printk (" ROMbase: %ld ADBDelay: %lx timebra: %lx \n",
-               boot_info.bi_mac.rombase, boot_info.bi_mac.adbdelay,
-               boot_info.bi_mac.timedbra);
+       printk (" CPUid: %lx ROMbase: %lx ADBDelay: %lx timebra: %lx \n",
+               boot_info.bi_mac.cpuid, boot_info.bi_mac.rombase,
+               boot_info.bi_mac.adbdelay, boot_info.bi_mac.timedbra);
+
+       if (CPU_IS_020)
+         printk("Processor type 020\n");
+
+       if (CPU_IS_030)
+         printk("Processor type 030\n");
+
+       if (CPU_IS_040)
+         printk("Processor type 040\n");
+
+       if (CPU_IS_060)
+         printk("Processor type 060\n");

       /*
        *      Save the pointer
diff -rubBwN linux-270897/arch/m68k/mac/macfb.c linux-2.0.29/arch/m68k/mac/macfb.c
--- linux-270897/arch/m68k/mac/macfb.c  Fri Sep 12 21:21:38 1997
+++ linux-2.0.29/arch/m68k/mac/macfb.c  Sun Sep 21 02:04:55 1997
@@ -306,175 +306,42 @@
/*
 * These two auxiliary debug functions should go away ASAP. Only usage:
 * before the console output is up (after head.S come some other crucial
- * setup routines :-) it permits writing 'data' to the screen as bit patterns
- * (good luck reading those). Helped to figure that the bootinfo contained
+ * setup routines :-) it permits writing data to the screen.
+ * Helped to figure that the bootinfo contained
 * garbage data on the amount and size of memory chunks ...
 */

void mac_debugging_short(int pos, short num)
{
-       unsigned char *pengoffset;
-       unsigned char *pptr;
-       int peng=0, line=0;
-       int i;
-
-       if (MACH_IS_ATARI || MACH_IS_AMIGA) {
-               /* printk("debug: %d !\n", num); */
-               return;
-       }
-
-       if (!pos) {
-               line++;
-               peng = 0;
-       }
-
-       pengoffset=(unsigned char *)(boot_info.bi_mac.videoaddr+
-               (30+line*2)*boot_info.bi_mac.videorow)+80*peng;
-
-       pptr=pengoffset;
-
-       for(i=0;i<8*sizeof(short);i++) /* # of bits */
-       {
-               *pptr++ = (num & ( 1 << (8*sizeof(short)-i-1) ) ? 0xFF : 0x00);
-       }
-
-       peng++;
+        printk("debug- (%d, %d)\n", pos, num);
}

void mac_debugging_long(int pos, long addr)
{
-       unsigned char *pengoffset;
-       unsigned char *pptr;
-       int peng=0, line=0;
-       int i;
-
-       if (MACH_IS_ATARI || MACH_IS_AMIGA) {
-               /* printk("debug: #%ld !\n", addr); */
-               return;
+        printk("debug- (%d, %lX)\n", pos, addr);
       }

-       if (!pos) {
-               line++;
-               peng = 0;
-       }
-
-       pengoffset=(unsigned char *)(boot_info.bi_mac.videoaddr+
-               (30+line*2)*boot_info.bi_mac.videorow)+80*peng;
-
-       pptr=pengoffset;
-
-       for(i=0;i<8*sizeof(long);i++) /* # of bits */
-       {
-               *pptr++ = (addr & ( 1 << (8*sizeof(long)-i-1) ) ? 0xFF : 0x00);
-       }
-
-       peng++;
-}
-
-static char that_penguin[]={
+char that_penguin[]={
#include "that_penguin.h"
};

-/*
- * B/W version of penguin, unfinished - any takers??
- */
-static char bw_penguin[]={
-#include "bw_penguin.h"
-};
-
void mac_debugging_penguin(int peng)
{
-       unsigned char *pengoffset;
-       unsigned char *pptr;
-       unsigned char *pdptr=that_penguin;
-       unsigned char *bwpdptr=bw_penguin;
-       int i;
-
-       if (MACH_IS_ATARI || MACH_IS_AMIGA) {
-               printk("Penguin #%d !\n", peng);
-               return;
-       }
-
-       if (boot_info.bi_mac.videodepth ==1)
-               pengoffset=(unsigned char *)(boot_info.bi_mac.videoaddr+
-                       64*boot_info.bi_mac.videorow)+10*peng;
-       else
-               pengoffset=(unsigned char *)(boot_info.bi_mac.videoaddr+
-                       64*boot_info.bi_mac.videorow)+40*peng;
-
-       pptr=pengoffset;
-
-       for(i=0;i<74;i++)
-       {
-               if (boot_info.bi_mac.videodepth ==1) {
-                       memcpy(pptr,bwpdptr,8);
-                       bwpdptr+=8;
-               } else {
-                       memcpy(pptr,pdptr,32);
-                       pdptr+=32;
-               }
-               pptr+=boot_info.bi_mac.videorow;
-       }
+        printk("Pengiun #%d\n",peng);
}

-static char kaboom_map[]={
-#include "mac.h"
-};
-
-/*
- * B/W version of flaming Mac, unfinished (see above).
- */
-static char bw_kaboom_map[]={
-#include "bw_mac.h"
-};
-
static void mac_boom_boom(void)
{
-       static unsigned char *boomoffset=NULL;
-       unsigned char *pptr;
-       unsigned char *pdptr=kaboom_map;
-       unsigned char *bwpdptr=bw_kaboom_map;
-       int i;
-
-       if(!boomoffset)
-               if (boot_info.bi_mac.videodepth == 1) {
-                       boomoffset=(unsigned char *)(boot_info.bi_mac.videoaddr+
-                               160*boot_info.bi_mac.videorow);
-               } else {
-                       boomoffset=(unsigned char *)(boot_info.bi_mac.videoaddr+
-                               256*boot_info.bi_mac.videorow);
-               }
-       else
-               if (boot_info.bi_mac.videodepth == 1)
-                       boomoffset+=10;
-               else
-                       boomoffset+=32;
-
-       pptr=boomoffset;
-
-       for(i=0;i<74;i++)
-       {
-               if (boot_info.bi_mac.videodepth ==1) {
-                       memcpy(pptr,bwpdptr,8);
-                       bwpdptr+=8;
-               } else {
-                       memcpy(pptr,pdptr,32);
-                       pdptr+=32;
-               }
-               pptr+=boot_info.bi_mac.videorow;
-       }
+        printk("Boom!!  Kapoow!\n");
}

void mac_boom(int booms)
{
       int i;

-       if (MACH_IS_ATARI || MACH_IS_AMIGA) {
               printk("Boom #%d !\n", booms);
-               return;
-       }

-       for(i=0;i<booms;i++)
-               mac_boom_boom();
+       printk("halted");
+
       while(1);
}
diff -rubBwN linux-270897/arch/m68k/mm/init.c linux-2.0.29/arch/m68k/mm/init.c
--- linux-270897/arch/m68k/mm/init.c    Fri Sep 12 21:21:38 1997
+++ linux-2.0.29/arch/m68k/mm/init.c    Mon Sep 22 00:17:28 1997
@@ -131,23 +131,21 @@
       pgd_t *page_dir = pgd_offset_k (virtaddr);

       if (!pgd_present (*page_dir)) {
-               mac_debugging_short(0, 1);
               /* 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
-               mac_debugging_short(0, 2);
+       {
               kpointerp = (unsigned long *) pgd_page (*page_dir);
+       }

       /*
        * pindex is the offset into the pointer table for the
        * descriptors for the current virtual address being mapped.
        */
       pindex = (virtaddr >> 18) & 0x7f;
-       mac_debugging_long(1, (long) kpointerp);
-       mac_debugging_long(1, (long) pindex);

#ifdef DEBUG
       printk ("mm=%ld, kernel_pg_dir=%p, kpointerp=%p, pindex=%d\n",
@@ -166,16 +164,14 @@
       for (physaddr = addr;
            physaddr < addr + size;
            mem_mapped += L3TREESIZE, virtaddr += L3TREESIZE) {
-               mac_debugging_long(1, (long) physaddr);
-
#ifdef DEBUG
-               printk ("pa=%#lx va=%#lx ", physaddr, virtaddr);
+//             printk ("pa=%#lx va=%#lx ", physaddr, virtaddr);
#endif

               if (pindex > 127 && mem_mapped >= 32*ONEMEG) {
                       /* we need a new pointer table every 32M */
#ifdef DEBUG
-                       printk ("[new pointer]");
+//                     printk ("[new pointer]");
#endif

                       kpointerp = (unsigned long *)get_kpointer_table ();
@@ -187,7 +183,6 @@
                       int i;
                       unsigned long ktable;

-                       mac_debugging_short(1, 3);
                       /* 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
@@ -197,14 +192,14 @@
                       if (mem_mapped < 4 * ONEMEG)
                       {
#ifdef DEBUG
-                               printk ("Already initialized\n");
+//                             printk ("Already initialized\n");
#endif
                               physaddr += L3TREESIZE;
                               pindex++;
                               continue;
                       }
#ifdef DEBUG
-                       printk ("[setup table]");
+//                     printk ("[setup table]");
#endif

                       /*
@@ -215,7 +210,7 @@
                       if ((pindex & 15) == 0) {
                               /* Need new page table every 4M on the '040 */
#ifdef DEBUG
-                               printk ("[new table]");
+//                             printk ("[new table]");
#endif
                               ktablep = kernel_page_table (memavailp);
                       }
@@ -242,7 +237,6 @@

                       kpointerp[pindex++] = ktable | _PAGE_TABLE | _PAGE_ACCESSED;
               } else {
-                       mac_debugging_short(1, 4);
                       /*
                        * 68030, use early termination page descriptors.
                        * Each one points to 64 pages (256K).
@@ -259,7 +253,6 @@
                               int i;
                               unsigned long *tbl;

-                               mac_debugging_short(1, 5);
                               tbl = (unsigned long *)get_kpointer_table();

                               kpointerp[pindex++] = VTOP(tbl) | _PAGE_TABLE |_PAGE_ACCESSED;
@@ -270,7 +263,6 @@
                               /* unmap the zero page */
                               tbl[0] = 0;
                       } else {
-                               mac_debugging_short(1, 6);
                               /* not the first 256K */
                               kpointerp[pindex++] = physaddr | _PAGE_PRESENT | _PAGE_ACCESSED;
#ifdef DEBUG
@@ -281,11 +273,10 @@
                       }
               }
#ifdef DEBUG
-               printk ("\n");
+//             printk ("\n");
#endif
       }

-       mac_debugging_long(0, (long) mem_mapped);
       return mem_mapped;
}

@@ -331,10 +322,15 @@
        * address space.  It may allocate some memory for page
        * tables and thus modify availmem.
        */
+#ifdef DEBUG
+       printk("Printing out boot_info mappings\n");
+#endif

       for (chunk = 0; chunk < boot_info.num_memory; chunk++) {
-               mac_debugging_long(0, boot_info.memory[chunk].addr);
-               mac_debugging_long(1, boot_info.memory[chunk].size);
+#ifdef DEBUG
+               printk("Memory range begins :%lX\n",boot_info.memory[chunk].addr);
+               printk("Memory range size   :%lX\n",boot_info.memory[chunk].size);
+#endif
               mem_avail = map_chunk (boot_info.memory[chunk].addr,
                                      boot_info.memory[chunk].size,
                                      &availmem);
@@ -350,8 +347,6 @@
        * "availmem" is setup by the code in head.S.
        */
       start_mem = availmem;
-       mac_debugging_long(0, start_mem);
-       mac_debugging_long(1, end_mem);

#ifdef DEBUG
       printk ("start_mem is %#lx\nvirtual_end is %#lx\n",
diff -rubBwN linux-270897/drivers/block/genhd.c linux-2.0.29/drivers/block/genhd.c
--- linux-270897/drivers/block/genhd.c  Fri Sep 12 21:21:38 1997
+++ linux-2.0.29/drivers/block/genhd.c  Mon Sep 22 00:29:15 1997
@@ -981,12 +981,12 @@
       if(amiga_partition(hd, dev, first_sector))
               return;
#endif
-#ifdef CONFIG_ATARI_PARTITION
-       if(atari_partition(hd, dev, first_sector))
-               return;
-#endif
#ifdef CONFIG_MAC_PARTITION
       if (mac_partition(hd, dev, first_sector))
+               return;
+#endif
+#ifdef CONFIG_ATARI_PARTITION
+       if(atari_partition(hd, dev, first_sector))
               return;
#endif
       printk(" unknown partition table\n");
diff -rubBwN linux-270897/drivers/char/m68kserial.c linux-2.0.29/drivers/char/m68kserial.c
--- linux-270897/drivers/char/m68kserial.c      Fri Sep 12 21:21:39 1997
+++ linux-2.0.29/drivers/char/m68kserial.c      Mon Sep 22 00:29:15 1997
@@ -1369,6 +1369,10 @@
 * available (atleast for the Amiga), and should cause no harm to the
 * old drivers.                         - Jes Sorensen ([email protected])
 *
+ *
+ * Macintosh
+ *   Macintosh serial port                             || 64   | ttyS0
+ *   Macintosh printer port                            || 65   | ttyS1
 */

/*
@@ -1532,7 +1536,9 @@

            case MACH_MAC:
#ifdef CONFIG_MAC_SCC
+#if 1
           mac_SCC_init();
+#endif
#endif
           break;

diff -rubBwN linux-270897/drivers/char/mac_SCC.c linux-2.0.29/drivers/char/mac_SCC.c
--- linux-270897/drivers/char/mac_SCC.c Fri Sep 12 21:21:39 1997
+++ linux-2.0.29/drivers/char/mac_SCC.c Mon Sep 22 00:29:15 1997
@@ -20,7 +20,7 @@
 * variety of chips, and the rs_* serial routines need to be shared.
 *
 * I've tried to make consistent use of the async_struct info populated in the
- * midlevel code, and introduced a async_private struct to hold the Macintosh
+ * midlevel code, and introduced an async_private struct to hold the Macintosh
 * SCC internals (this was added to the async_struct for the PowerMac driver).
 * Exception: the console and kgdb hooks still use the zs_soft[] data, and this
 * is still filled in by the probe_sccs() routine, which provides some data
@@ -480,13 +480,18 @@
        */
#define CHAN_IRQMASK (CHBRxIP | CHBTxIP | CHBEXT)

+       printk("mac_SCC: interrupt; channel: %lx \n", info->private->zs_channel);
+
       if (info->private->zs_chan_a == info->private->zs_channel)
               shift = 3;      /* Channel A */
       else
               shift = 0;      /* Channel B */

       for (;;) {
-               zs_intreg = read_zsreg(info->private->zs_chan_a, 3) >> shift;
+               zs_intreg = read_zsreg(info->private->zs_chan_a, 3);
+               printk("mac_SCC: status %x shift %d shifted %x \n",
+               zs_intreg, shift, zs_intreg >> shift);
+               zs_intreg = zs_intreg >> shift;
               if ((zs_intreg & CHAN_IRQMASK) == 0)
                       break;

@@ -627,6 +632,8 @@

       /* BUT: startup part needs to be done here! */

+       printk("mac_SCC: init, info %lx \n", info);
+
       /*
        * Clear the receive FIFO.
        */
@@ -675,8 +682,10 @@
static void SCC_init_port( struct async_struct *info, int type, int channel )
{
       static int got_autovector = 0;
-       info->sw = &SCC_switch;

+       printk("mac_SCC: init_port, info %x \n", info);
+
+       info->sw = &SCC_switch;
       info->private = &zs_soft_private[channel];
       info->private->zs_channel = &zs_channels[channel];
       info->irq = IRQ_SCC;
@@ -695,6 +704,7 @@

       /* If console serial line, then enable interrupts. */
       if (info->private->is_cons) {
+               printk("mac_SCC: console line %lx; enabling interrupt!\n", info);
               write_zsreg(info->private->zs_channel, R1,
                           (EXT_INT_ENAB | INT_ALL_Rx | TxINT_ENAB));
               write_zsreg(info->private->zs_channel, R9, (NV | MIE));
@@ -706,9 +716,10 @@
        * now want to receive the 'control-c' character from the
        * client attached to us asynchronously.
        */
-       if (info->private->kgdb_channel)
+       if (info->private->kgdb_channel) {
+               printk("mac_SCC: kgdb line %lx; enabling interrupt!\n", info);
               kgdb_chaninit(info, 1, info->private->zs_baud);
-
+       }
#if 0  /* FIXME : This is all set in m68kserial.c !! */
       info->magic = SERIAL_MAGIC;
       info->port = (int) info->private->zs_channel->control; /* set above */
@@ -729,6 +740,8 @@
       info->normal_termios = serial_driver.init_termios;
       info->open_wait = 0;
       info->close_wait = 0;
+#endif
+       /* but report settings here ... */
       printk("tty%02d at 0x%08x (irq = %d)", info->line,
                      info->port, info->irq);
#ifdef CONFIG_MAC
@@ -737,7 +750,6 @@
       printk(" is a Z8530 SCC\n");
#endif

-#endif
}

/*
diff -rubBwN linux-270897/drivers/net/daynaport.c linux-2.0.29/drivers/net/daynaport.c
--- linux-270897/drivers/net/daynaport.c        Fri Sep 12 21:21:39 1997
+++ linux-2.0.29/drivers/net/daynaport.c        Mon Sep 22 00:29:15 1997
@@ -162,6 +163,9 @@
       if(dev==NULL)
               return -ENOMEM;

+       /*
+        *      Dayna specific init
+        */
       if(id==NS8390_DAYNA)
       {
               dev->base_addr=(int)(nubus_slot_addr(slot)+DAYNA_8390_BASE);
@@ -365,7 +369,7 @@
                       ei_status.get_8390_hdr = &dayna_get_8390_hdr;
                       ei_status.reg_offset = fwrd4_offsets;
                       break;
-               case NS8390_APPLE:      /*Asante/Farallon */
+               case NS8390_APPLE:      /* Apple/Asante/Farallon */
               case NS8390_FARALLON:
               case NS8390_ASANTE:
                       /*      16 bit card, register map is reversed */
diff -rubBwN linux-270897/drivers/scsi/mac_scsi.c linux-2.0.29/drivers/scsi/mac_scsi.c
--- linux-270897/drivers/scsi/mac_scsi.c        Fri Sep 12 21:21:40 1997
+++ linux-2.0.29/drivers/scsi/mac_scsi.c        Mon Sep 22 00:29:15 1997
@@ -29,7 +29,7 @@
#define NDEBUG_TAGS    0x1000000
#define NDEBUG_MERGING 0x2000000

-#define NDEBUG (NDEBUG_NO_WRITE )
+#define NDEBUG (0)

#define AUTOSENSE
/* MSch: Tested the pseudo-DMA code on Atari for the Mac68k port ... */
@@ -348,9 +348,9 @@
#if 0
       /* To be sure the int is not masked */
       mac_enable_irq( IRQ_MAC_SCSI );
+#endif
       /* Clear the IRQ */
       via_scsi_clear();
-#endif
}


diff -rubBwN linux-270897/include/asm-m68k/macints.h linux-2.0.29/include/asm-m68k/macints.h
--- linux-270897/include/asm-m68k/macints.h     Fri Sep 12 21:21:42 1997
+++ linux-2.0.29/include/asm-m68k/macints.h     Mon Sep 22 00:29:15 1997
@@ -71,13 +71,17 @@
#define IRQ_AUTO_7        (IRQ_MACHSPEC | 7)

/* VIA1 interrupts */
-#define IRQ_VIA1_0       (IRQ_MACHSPEC | 8)
-#define IRQ_VIA1_1        (IRQ_MACHSPEC | 9)
-#define IRQ_VIA1_2       (IRQ_MACHSPEC | 10)
+#define IRQ_VIA1_0       (IRQ_MACHSPEC | 8)    /* one second int. */
+#define IRQ_VIA1_1        (IRQ_MACHSPEC | 9)   /* VBlank int. */
+#define IRQ_VIA1_2       (IRQ_MACHSPEC | 10)   /* ADB SR shifts complete */
#define IRQ_MAC_ADB      IRQ_VIA1_2
-#define IRQ_VIA1_3       (IRQ_MACHSPEC | 11)
-#define IRQ_VIA1_4        (IRQ_MACHSPEC | 12)
+#define IRQ_MAC_ADB_SR   IRQ_VIA1_2
+#define IRQ_VIA1_3       (IRQ_MACHSPEC | 11)   /* ADB SR CB2 ?? */
+#define IRQ_MAC_ADB_SD   IRQ_VIA1_3
+#define IRQ_VIA1_4        (IRQ_MACHSPEC | 12)  /* ADB SR ext. clock pulse */
+#define IRQ_MAC_ADB_CL   IRQ_VIA1_4
#define IRQ_VIA1_5       (IRQ_MACHSPEC | 13)
+#define IRQ_MAC_TIMER_2          IRQ_VIA1_5
#define IRQ_VIA1_6       (IRQ_MACHSPEC | 14)
#define IRQ_MAC_TIMER_1          IRQ_VIA1_6
#define IRQ_VIA1_7        (IRQ_MACHSPEC | 15)
diff -rubBwN linux-270897/include/asm-m68k/serial.h linux-2.0.29/include/asm-m68k/serial.h
--- linux-270897/include/asm-m68k/serial.h      Fri Sep 12 21:21:42 1997
+++ linux-2.0.29/include/asm-m68k/serial.h      Mon Sep 22 00:29:15 1997
@@ -10,6 +10,7 @@
#ifndef _M68K_SERIAL_H
#define _M68K_SERIAL_H

+#include <linux/config.h>      /* for Mac SCC extensions */

/* m68k serial port types are numbered from 100 to avoid interference
 * with the PC types (1..4)
diff -rubBwN linux-270897/include/asm-m68k/setup.h linux-2.0.29/include/asm-m68k/setup.h
--- linux-270897/include/asm-m68k/setup.h       Fri Sep 12 21:21:42 1997
+++ linux-2.0.29/include/asm-m68k/setup.h       Sun Sep 21 03:56:35 1997
@@ -215,10 +215,10 @@
       unsigned long printmf;
       unsigned long printhsk;
       unsigned long printgpi;
+       unsigned long cpuid;
       unsigned long rombase;
       unsigned long adbdelay;
       unsigned long timedbra;
-       unsigned long cpuid;
       struct {
               /* video hardware */
               /* sound hardware */
@@ -247,7 +247,7 @@
#define BI_videodepth  BI_videorow+4
#define BI_dimensions  BI_videodepth+4
#define BI_args                BI_dimensions+4
-#define BI_cpuid       BI_args+68
+#define BI_cpuid       BI_args+56
#endif

#define NUM_MEMINFO  4
diff -rubBwN linux-270897/init/main.c linux-2.0.29/init/main.c
--- linux-270897/init/main.c    Fri Sep 12 21:21:42 1997
+++ linux-2.0.29/init/main.c    Sun Sep 21 23:32:53 1997
@@ -798,11 +798,6 @@
       extern struct consw fb_con;
       extern u_long fbcon_startup(u_long, char **);

-       if(fb_con.con_startup!=fbcon_startup)
-               mac_boom(1);
-
-       mac_debugging_penguin(0);
-
/*
 *     This little check will move.
 */
@@ -820,14 +815,26 @@
 * enable them
 */
       setup_arch(&command_line, &memory_start, &memory_end);
-       mac_debugging_penguin(1);
+       printk("Setup_arch complete\n");
+
       memory_start = paging_init(memory_start,memory_end);
-       mac_debugging_penguin(2);
+       printk("Memory_start complete\n");
+
       trap_init();
+       printk("Trap_init complete\n");
+
       init_IRQ();
+       printk("Init_IRQ complete\n");
+
       sched_init();
+       printk("Sched_init complete\n");
+
       time_init();
+       printk("Time_init complete\n");
+
       parse_options(command_line);
+       printk("Parse_options complete\n");
+
#ifdef CONFIG_MODULES
       init_modules();
#endif