2.2.0-final
[davej-history.git] / arch / m68k / kernel / head.S
blob482c15f5084181432e7ddfa2d669f1d7c93af47b
1 /* -*- mode: asm -*-
2 **
3 ** head.S -- This file contains the initial boot code for the
4 **           Linux/68k kernel.
5 **
6 ** Copyright 1993 by Hamish Macdonald
7 **
8 ** 68040 fixes by Michael Rausch
9 ** 68060 fixes by Roman Hodek
10 ** MMU cleanup by Randy Thelen
11 ** Final MMU cleanup by Roman Zippel
13 ** Atari support by Andreas Schwab, using ideas of Robert de Vries
14 ** and Bjoern Brauel
15 ** VME Support by Richard Hirst
17 ** 94/11/14 Andreas Schwab: put kernel at PAGESIZE
18 ** 94/11/18 Andreas Schwab: remove identity mapping of STRAM for Atari
19 ** ++ Bjoern & Roman: ATARI-68040 support for the Medusa
20 ** 95/11/18 Richard Hirst: Added MVME166 support
21 ** 96/04/26 Guenther Kelleter: fixed identity mapping for Falcon with
22 **                            Magnum- and FX-alternate ram
23 ** 98/04/25 Phil Blundell: added HP300 support
24 ** 1998/08/30 David Kilzer: Added support for fbcon_font_desc structures
25 **            for linux-2.1.115
27 ** This file is subject to the terms and conditions of the GNU General Public
28 ** License. See the file README.legal in the main directory of this archive
29 ** for more details.
34  * Linux startup code.
35  *
36  * At this point, the boot loader has:
37  * Disabled interrupts
38  * Disabled caches
39  * Put us in supervisor state.
40  *
41  * The kernel setup code takes the following steps:
42  * .  Raise interrupt level
43  * .  Set up initial kernel memory mapping.
44  *    .  This sets up a mapping of the 4M of memory the kernel is located in.
45  *    .  It also does a mapping of any initial machine specific areas.
46  * .  Enable the MMU
47  * .  Enable cache memories
48  * .  Jump to kernel startup
49  *
50  * Much of the file restructuring was to accomplish:
51  * 1) Remove register dependency through-out the file.
52  * 2) Increase use of subroutines to perform functions
53  * 3) Increase readability of the code
54  *
55  * Of course, readability is a subjective issue, so it will never be
56  * argued that that goal was accomplished.  It was merely a goal.
57  * A key way to help make code more readable is to give good
58  * documentation.  So, the first thing you will find is exaustive
59  * write-ups on the structure of the file, and the features of the
60  * functional subroutines.
61  *
62  * General Structure:
63  * ------------------
64  *      Without a doubt the single largest chunk of head.S is spent
65  * mapping the kernel and I/O physical space into the logical range
66  * for the kernel.
67  *      There are new subroutines and data structures to make MMU
68  * support cleaner and easier to understand.
69  *      First, you will find a routine call "mmu_map" which maps
70  * a logical to a physical region for some length given a cache
71  * type on behalf of the caller.  This routine makes writing the
72  * actual per-machine specific code very simple.
73  *      A central part of the code, but not a subroutine in itself,
74  * is the mmu_init code which is broken down into mapping the kernel
75  * (the same for all machines) and mapping machine-specific I/O
76  * regions.
77  *      Also, there will be a description of engaging the MMU and
78  * caches.
79  *      You will notice that there is a chunk of code which
80  * can emit the entire MMU mapping of the machine.  This is present
81  * only in debug modes and can be very helpful.
82  *      Further, there is a new console driver in head.S that is
83  * also only engaged in debug mode.  Currently, it's only supported
84  * on the Macintosh class of machines.  However, it is hoped that
85  * others will plug-in support for specific machines.
86  *
87  * ######################################################################
88  *
89  * mmu_map
90  * -------
91  *      mmu_map was written for two key reasons.  First, it was clear
92  * that it was very difficult to read the previous code for mapping
93  * regions of memory.  Second, the Macintosh required such extensive
94  * memory allocations that it didn't make sense to propogate the
95  * existing code any further.
96  *      mmu_map requires some parameters:
97  *
98  *      mmu_map (logical, physical, length, cache_type)
99  *
100  *      While this essentially describes the function in the abstract, you'll
101  * find more indepth description of other parameters at the implementation site.
102  * 
103  * mmu_get_root_table_entry
104  * ------------------------
105  * mmu_get_ptr_table_entry
106  * -----------------------
107  * mmu_get_page_table_entry
108  * ------------------------
109  * 
110  *      These routines are used by other mmu routines to get a pointer into
111  * a table, if necessary a new table is allocated. These routines are working
112  * basically like pmd_alloc() and pte_alloc() in <asm/pgtable.h>. The root
113  * table needs of course only to be allocated once in mmu_get_root_table_entry,
114  * so that here also some mmu specific initialization is done. The second page
115  * at the start of the kernel (the first page is unmapped later) is used for
116  * the kernel_pg_dir. It must be at a position known at link time (as it's used
117  * to initialize the init task struct) and since it needs special cache
118  * settings, it's the easiest to use this page, the rest of the page is used
119  * for further pointer tables.
120  * mmu_get_page_table_entry allocates always a whole page for page tables, this
121  * means 1024 pages and so 4MB of memory can be mapped. It doesn't make sense
122  * to manage page tables in smaller pieces as nearly all mappings have that
123  * size.
125  * ######################################################################
128  * ######################################################################
130  * mmu_engage
131  * ----------
132  *      Thanks to a small helping routine enabling the mmu got quiet simple
133  * and there is only one way left. mmu_engage makes a complete a new mapping
134  * that only includes the absolute necessary to be able to jump to the final
135  * postion and to restore the original mapping.
136  * As this code doesn't need a transparent translation register anymore this
137  * means all registers are free to be used by machines that needs them for
138  * other purposes.
140  * ######################################################################
142  * mmu_print
143  * ---------
144  *      This algorithm will print out the page tables of the system as
145  * appropriate for an 030 or an 040.  This is useful for debugging purposes
146  * and as such is enclosed in #ifdef MMU_PRINT/#endif clauses.
148  * ######################################################################
150  * console_init
151  * ------------
152  *      The console is also able to be turned off.  The console in head.S
153  * is specifically for debugging and can be very useful.  It is surrounded by
154  * #ifdef CONSOLE/#endif clauses so it doesn't have to ship in known-good
155  * kernels.  It's basic algorithm is to determine the size of the screen
156  * (in height/width and bit depth) and then use that information for
157  * displaying an 8x8 font or an 8x16 (widthxheight).  I prefer the 8x8 for
158  * debugging so I can see more good data.  But it was trivial to add support
159  * for both fonts, so I included it.
160  *      Also, the algorithm for plotting pixels is abstracted so that in
161  * theory other platforms could add support for different kinds of frame
162  * buffers.  This could be very useful.
164  * console_put_penguin
165  * -------------------
166  *      An important part of any Linux bring up is the penguin and there's
167  * nothing like getting the Penguin on the screen!  This algorithm will work
168  * on any machine for which there is a console_plot_pixel.
170  * console_scroll
171  * --------------
172  *      My hope is that the scroll algorithm does the right thing on the
173  * various platforms, but it wouldn't be hard to add the test conditions
174  * and new code if it doesn't.
176  * console_putc
177  * -------------
179  * ######################################################################
181  *      Register usage has greatly simplified within head.S. Every subroutine
182  * saves and restores all registers that it modifies (except it returns a
183  * value in there of course). So the only register that needs to be initialized
184  * is the stack pointer.
185  * All other init code and data is now placed in the init section, so it will
186  * be automatically freed at the end of the kernel initialization.
188  * ######################################################################
190  * options
191  * -------
192  *      There are many options availble in a build of this file.  I've
193  * taken the time to describe them here to save you the time of searching
194  * for them and trying to understand what they mean.
196  * CONFIG_xxx:  These are the obvious machine configuration defines created
197  * during configuration.  These are defined in include/linux/autoconf.h.
199  * CONSOLE:     There is support for head.S console in this file.  This
200  * console can talk to a Mac frame buffer, but could easily be extrapolated
201  * to extend it to support other platforms.
203  * TEST_MMU:    This is a test harness for running on any given machine but
204  * getting an MMU dump for another class of machine.  The classes of machines
205  * that can be tested are any of the makes (Atari, Amiga, Mac, VME, etc.)
206  * and any of the models (030, 040, 060, etc.).
208  *      NOTE:   TEST_MMU is NOT permanent!  It is scheduled to be removed
209  *              When head.S boots on Atari, Amiga, Macintosh, and VME
210  *              machines.  At that point the underlying logic will be
211  *              believed to be solid enough to be trusted, and TEST_MMU
212  *              can be dropped.  Do note that that will clean up the
213  *              head.S code significantly as large blocks of #if/#else
214  *              clauses can be removed.
216  * MMU_NOCACHE_KERNEL:  On the Macintosh platform there was an inquiry into
217  * determing why devices don't appear to work.  A test case was to remove
218  * the cacheability of the kernel bits.
220  * MMU_PRINT:   There is a routine built into head.S that can display the
221  * MMU data structures.  It outputs its result through the serial_putc
222  * interface.  So where ever that winds up driving data, that's where the
223  * mmu struct will appear.  On the Macintosh that's typically the console.
225  * SERIAL_DEBUG:        There are a series of putc() macro statements
226  * scattered through out the code to give progress of status to the
227  * person sitting at the console.  This constant determines whether those
228  * are used.
230  * DEBUG:       This is the standard DEBUG flag that can be set for building
231  *              the kernel.  It has the effect adding additional tests into
232  *              the code.
234  * FONT_6x11:
235  * FONT_8x8:
236  * FONT_8x16:
237  *              In theory these could be determined at run time or handed
238  *              over by the booter.  But, let's be real, it's a fine hard
239  *              coded value.  (But, you will notice the code is run-time
240  *              flexible!)  A pointer to the font's struct fbcon_font_desc
241  *              is kept locally in Lconsole_font.  It is used to determine
242  *              font size information dynamically.
244  * Atari constants:
245  * USE_PRINTER: Use the printer port for serial debug.
246  * USE_SCC_B:   Use the SCC port A (Serial2) for serial debug.
247  * USE_SCC_A:   Use the SCC port B (Modem2) for serial debug.
248  * USE_MFP:     Use the ST-MFP port (Modem1) for serial debug.
250  * Macintosh constants:
251  * MAC_SERIAL_DEBUG:    Turns on serial debug output for the Macintosh.
252  * MAC_USE_SCC_A:       Use the SCC port A (modem) for serial debug.
253  * MAC_USE_SCC_B:       Use the SCC port B (printer) for serial debug (default).
254  */
256 #include <linux/config.h>
257 #include <linux/linkage.h>
258 #include <linux/init.h>
259 #include <asm/bootinfo.h>
260 #include <asm/setup.h>
261 #include <asm/pgtable.h>
262 #include "m68k_defs.h"
264 #ifdef CONFIG_MAC
266 #include <asm/machw.h>
269  * Macintosh console support
270  */
272 #define CONSOLE
275  * Macintosh serial debug support; outputs boot info to the printer
276  *   and/or modem serial ports
277  */
278 #undef MAC_SERIAL_DEBUG
281  * Macintosh serial debug port selection; define one or both;
282  *   requires MAC_SERIAL_DEBUG to be defined
283  */
284 #define MAC_USE_SCC_A           /* Macintosh modem serial port */
285 #define MAC_USE_SCC_B           /* Macintosh printer serial port */
287 #endif  /* CONFIG_MAC */
289 #undef MMU_PRINT
290 #undef MMU_NOCACHE_KERNEL
291 #define SERIAL_DEBUG
292 #undef DEBUG
295  * For the head.S console, there are three supported fonts, 6x11, 8x16 and 8x8.
296  * The 8x8 font is harder to read but fits more on the screen.
297  */
298 #define FONT_8x8        /* default */
299 /* #define FONT_8x16 */ /* 2nd choice */
300 /* #define FONT_6x11 */ /* 3rd choice */
302 .globl SYMBOL_NAME(kernel_pg_dir)
303 .globl SYMBOL_NAME(availmem)
304 .globl SYMBOL_NAME(m68k_pgtable_cachemode)
305 .globl SYMBOL_NAME(m68k_supervisor_cachemode)
307 CPUTYPE_040     = 1     /* indicates an 040 */
308 CPUTYPE_060     = 2     /* indicates an 060 */
309 CPUTYPE_0460    = 3     /* if either above are set, this is set */
310 CPUTYPE_020     = 4     /* indicates an 020 */
312 /* Translation control register */
313 TC_ENABLE = 0x8000
314 TC_PAGE8K = 0x4000
315 TC_PAGE4K = 0x0000
317 /* Transparent translation registers */
318 TTR_ENABLE      = 0x8000        /* enable transparent translation */
319 TTR_ANYMODE     = 0x4000        /* user and kernel mode access */
320 TTR_KERNELMODE  = 0x2000        /* only kernel mode access */
321 TTR_USERMODE    = 0x0000        /* only user mode access */
322 TTR_CI          = 0x0400        /* inhibit cache */
323 TTR_RW          = 0x0200        /* read/write mode */
324 TTR_RWM         = 0x0100        /* read/write mask */
325 TTR_FCB2        = 0x0040        /* function code base bit 2 */
326 TTR_FCB1        = 0x0020        /* function code base bit 1 */
327 TTR_FCB0        = 0x0010        /* function code base bit 0 */
328 TTR_FCM2        = 0x0004        /* function code mask bit 2 */
329 TTR_FCM1        = 0x0002        /* function code mask bit 1 */
330 TTR_FCM0        = 0x0001        /* function code mask bit 0 */
332 /* Cache Control registers */
333 CC6_ENABLE_D    = 0x80000000    /* enable data cache (680[46]0) */
334 CC6_FREEZE_D    = 0x40000000    /* freeze data cache (68060) */
335 CC6_ENABLE_SB   = 0x20000000    /* enable store buffer (68060) */
336 CC6_PUSH_DPI    = 0x10000000    /* disable CPUSH invalidation (68060) */
337 CC6_HALF_D      = 0x08000000    /* half-cache mode for data cache (68060) */
338 CC6_ENABLE_B    = 0x00800000    /* enable branch cache (68060) */
339 CC6_CLRA_B      = 0x00400000    /* clear all entries in branch cache (68060) */
340 CC6_CLRU_B      = 0x00200000    /* clear user entries in branch cache (68060) */
341 CC6_ENABLE_I    = 0x00008000    /* enable instruction cache (680[46]0) */
342 CC6_FREEZE_I    = 0x00004000    /* freeze instruction cache (68060) */
343 CC6_HALF_I      = 0x00002000    /* half-cache mode for instruction cache (68060) */
344 CC3_ALLOC_WRITE = 0x00002000    /* write allocate mode(68030) */
345 CC3_ENABLE_DB   = 0x00001000    /* enable data burst (68030) */
346 CC3_CLR_D       = 0x00000800    /* clear data cache (68030) */
347 CC3_CLRE_D      = 0x00000400    /* clear entry in data cache (68030) */
348 CC3_FREEZE_D    = 0x00000200    /* freeze data cache (68030) */
349 CC3_ENABLE_D    = 0x00000100    /* enable data cache (68030) */
350 CC3_ENABLE_IB   = 0x00000010    /* enable instruction burst (68030) */
351 CC3_CLR_I       = 0x00000008    /* clear instruction cache (68030) */
352 CC3_CLRE_I      = 0x00000004    /* clear entry in instruction cache (68030) */
353 CC3_FREEZE_I    = 0x00000002    /* freeze instruction cache (68030) */
354 CC3_ENABLE_I    = 0x00000001    /* enable instruction cache (68030) */
356 /* Miscellaneous definitions */
357 PAGESIZE        = 4096
358 PAGESHIFT       = 12
360 ROOT_TABLE_SIZE = 128
361 PTR_TABLE_SIZE  = 128
362 PAGE_TABLE_SIZE = 64
363 ROOT_INDEX_SHIFT = 25
364 PTR_INDEX_SHIFT  = 18
365 PAGE_INDEX_SHIFT = 12
367 #ifdef DEBUG
368 /* When debugging use readable names for labels */
369 #ifdef __STDC__
370 #define L(name) .head.S.##name
371 #else
372 #define L(name) .head.S./**/name
373 #endif
374 #else
375 #ifdef __STDC__
376 #define L(name) .L##name
377 #else
378 #define L(name) .L/**/name
379 #endif
380 #endif
382 /* Several macros to make the writing of subroutines easier:
383  * - func_start marks the beginning of the routine which setups the frame
384  *   register and saves the registers, it also defines another macro
385  *   to automatically restore the registers again.
386  * - func_return marks the end of the routine and simply calls the prepared
387  *   macro to restore registers and jump back to the caller.
388  * - func_define generates another macro to automatically put arguments
389  *   onto the stack call the subroutine and cleanup the stack again.
390  */
392 /* Within subroutines these macros can be used to access the arguments
393  * on the stack. With STACK some allocated memory on the stack can be
394  * accessed and ARG0 points to the return address (used by mmu_engage).
395  */
396 #define STACK   %a6@(stackstart)
397 #define ARG0    %a6@(4)
398 #define ARG1    %a6@(8)
399 #define ARG2    %a6@(12)
400 #define ARG3    %a6@(16)
401 #define ARG4    %a6@(20)
403 .macro  func_start      name,saveregs,stack=0
404 L(\name):
405         linkw   %a6,#-\stack
406         moveml  \saveregs,%sp@-
407 .set    stackstart,-\stack      
409 .macro  func_return_\name
410         moveml  %sp@+,\saveregs
411         unlk    %a6
412         rts
413 .endm
414 .endm
416 .macro  func_return     name
417         func_return_\name
418 .endm
420 .macro  func_call       name
421         jbsr    L(\name)
422 .endm
424 .macro  move_stack      nr,arg1,arg2,arg3,arg4
425 .if     \nr
426         move_stack      "(\nr-1)",\arg2,\arg3,\arg4
427         movel   \arg1,%sp@-
428 .endif
429 .endm
431 .macro  func_define     name,nr=0
432 .macro  \name   arg1,arg2,arg3,arg4
433         move_stack      \nr,\arg1,\arg2,\arg3,\arg4
434         func_call       \name
435 .if     \nr
436         lea     %sp@(\nr*4),%sp
437 .endif
438 .endm
439 .endm
441 func_define     mmu_map,4
442 func_define     mmu_map_tt,4
443 func_define     mmu_fixup_page_mmu_cache,1
444 func_define     mmu_temp_map,2
445 func_define     mmu_engage
446 func_define     mmu_get_root_table_entry,1
447 func_define     mmu_get_ptr_table_entry,2
448 func_define     mmu_get_page_table_entry,2
449 func_define     mmu_print
450 func_define     get_new_page
451 #ifdef CONFIG_HP300
452 func_define     set_leds
453 #endif
455 .macro  mmu_map_eq      arg1,arg2,arg3
456         mmu_map \arg1,\arg1,\arg2,\arg3
457 .endm
459 .macro  get_bi_record   record
460         pea     \record
461         func_call       get_bi_record
462         addql   #4,%sp
463 .endm
465 func_define     serial_putc,1
466 func_define     console_putc,1
468 .macro  putc    ch
469 #if defined(CONSOLE) || defined(SERIAL_DEBUG)
470         pea     \ch
471 #endif
472 #ifdef CONSOLE
473         func_call       console_putc
474 #endif
475 #ifdef SERIAL_DEBUG
476         func_call       serial_putc
477 #endif
478 #if defined(CONSOLE) || defined(SERIAL_DEBUG)
479         addql   #4,%sp
480 #endif
481 .endm
483 .macro  dputc   ch
484 #ifdef DEBUG
485         putc    \ch
486 #endif
487 .endm
489 func_define     putn,1
491 .macro  dputn   nr
492 #ifdef DEBUG
493         putn    \nr
494 #endif
495 .endm
497 .macro  puts            string
498 #if defined(CONSOLE) || defined(SERIAL_DEBUG)
499         __INITDATA
500 .Lstr\@:
501         .string "\string"
502         __FINIT
503         pea     %pc@(.Lstr\@)
504         func_call       puts
505         addql   #4,%sp
506 #endif
507 .endm
509 .macro  dputs   string
510 #ifdef DEBUG
511         puts    "\string"
512 #endif
513 .endm
516 #define is_not_amiga(lab) cmpl &MACH_AMIGA,%pc@(m68k_machtype); jne lab
517 #define is_not_atari(lab) cmpl &MACH_ATARI,%pc@(m68k_machtype); jne lab
518 #define is_not_mac(lab) cmpl &MACH_MAC,%pc@(m68k_machtype); jne lab
519 #define is_not_mvme16x(lab) cmpl &MACH_MVME16x,%pc@(m68k_machtype); jne lab
520 #define is_not_bvme6000(lab) cmpl &MACH_BVME6000,%pc@(m68k_machtype); jne lab
521 #define is_not_hp300(lab) cmpl &MACH_HP300,%pc@(m68k_machtype); jne lab
523 #define is_040_or_060(lab)      btst &CPUTYPE_0460,%pc@(L(cputype)+3); jne lab
524 #define is_not_040_or_060(lab)  btst &CPUTYPE_0460,%pc@(L(cputype)+3); jeq lab
525 #define is_040(lab)             btst &CPUTYPE_040,%pc@(L(cputype)+3); jne lab
526 #define is_060(lab)             btst &CPUTYPE_060,%pc@(L(cputype)+3); jne lab
527 #define is_not_060(lab)         btst &CPUTYPE_060,%pc@(L(cputype)+3); jeq lab
528 #define is_020(lab)             btst &CPUTYPE_020,%pc@(L(cputype)+3); jne lab
529 #define is_not_020(lab)         btst &CPUTYPE_020,%pc@(L(cputype)+3); jeq lab
531 /* On the HP300 we use the on-board LEDs for debug output before
532    the console is running.  Writing a 1 bit turns the corresponding LED
533    _off_ - on the 340 bit 7 is towards the back panel of the machine.  */
534 .macro  leds    mask
535 #ifdef CONFIG_HP300
536         is_not_hp300(.Lled\@)
537         pea     \mask
538         func_call       set_leds
539         addql   #4,%sp
540 .Lled\@:
541 #endif
542 .endm
544 .text
545 ENTRY(_stext)
547  * Version numbers of the bootinfo interface
548  * The area from _stext to _start will later be used as kernel pointer table
549  */
550         bras    1f      /* Jump over bootinfo version numbers */
552         .long   BOOTINFOV_MAGIC
553         .long   MACH_AMIGA, AMIGA_BOOTI_VERSION
554         .long   MACH_ATARI, ATARI_BOOTI_VERSION
555         .long   MACH_MVME16x, MVME16x_BOOTI_VERSION
556         .long   MACH_BVME6000, BVME6000_BOOTI_VERSION
557         .long   MACH_MAC, MAC_BOOTI_VERSION
558         .long   0
559 1:      jra     SYMBOL_NAME(__start)
561 .equ    SYMBOL_NAME(kernel_pg_dir),SYMBOL_NAME(_stext)
563 .equ    .,SYMBOL_NAME(_stext)+PAGESIZE
565 ENTRY(_start)
566         jra     SYMBOL_NAME(__start)
567 __INIT
568 ENTRY(__start)
571  * Setup initial stack pointer
572  */
573         lea     %pc@(SYMBOL_NAME(_stext)),%sp
576  * Record the CPU and machine type.
577  */
579         get_bi_record   BI_MACHTYPE
580         lea     %pc@(SYMBOL_NAME(m68k_machtype)),%a1
581         movel   %a0@,%a1@
583         get_bi_record   BI_FPUTYPE
584         lea     %pc@(SYMBOL_NAME(m68k_fputype)),%a1
585         movel   %a0@,%a1@
587         get_bi_record   BI_MMUTYPE
588         lea     %pc@(SYMBOL_NAME(m68k_mmutype)),%a1
589         movel   %a0@,%a1@
591         get_bi_record   BI_CPUTYPE
592         lea     %pc@(SYMBOL_NAME(m68k_cputype)),%a1
593         movel   %a0@,%a1@
595 #ifdef CONFIG_MAC
597  * For Macintosh, we need to determine the display parameters early (at least
598  * while debugging it).
599  */
601         is_not_mac(L(test_notmac))
603         get_bi_record   BI_MAC_VADDR
604         lea     %pc@(L(mac_videobase)),%a1
605         movel   %a0@,%a1@
607         get_bi_record   BI_MAC_VDEPTH
608         lea     %pc@(L(mac_videodepth)),%a1
609         movel   %a0@,%a1@
611         get_bi_record   BI_MAC_VDIM
612         lea     %pc@(L(mac_dimensions)),%a1
613         movel   %a0@,%a1@
615         get_bi_record   BI_MAC_VROW
616         lea     %pc@(L(mac_rowbytes)),%a1
617         movel   %a0@,%a1@
619 #ifdef MAC_SERIAL_DEBUG
620         get_bi_record   BI_MAC_SCCBASE
621         lea     %pc@(L(mac_sccbase)),%a1
622         movel   %a0@,%a1@
623 #endif /* MAC_SERIAL_DEBUG */
625 #if 0
626         /*
627          * Clear the screen
628          */
629         lea     %pc@(L(mac_videobase)),%a0
630         movel   %a0@,%a1
631         lea     %pc@(L(mac_dimensions)),%a0
632         movel   %a0@,%d1
633         swap    %d1             /* #rows is high bytes */
634         andl    #0xFFFF,%d1     /* rows */
635         subl    #10,%d1
636         lea     %pc@(L(mac_rowbytes)),%a0
637 loopy2:
638         movel   %a0@,%d0
639         subql   #1,%d0
640 loopx2:
641         moveb   #0x55, %a1@+
642         dbra    %d0,loopx2
643         dbra    %d1,loopy2
644 #endif
646 L(test_notmac):
647 #endif /* CONFIG_MAC */
651  * There are ultimately two pieces of information we want for all kinds of
652  * processors CpuType and CacheBits.  The CPUTYPE was passed in from booter
653  * and is converted here from a booter type definition to a separate bit
654  * number which allows for the standard is_0x0 macro tests.
655  */
656         movel   %pc@(SYMBOL_NAME(m68k_cputype)),%d0
657         /*
658          * Assume it's an 030
659          */
660         clrl    %d1
662         /*
663          * Test the BootInfo cputype for 060
664          */
665         btst    #CPUB_68060,%d0
666         jeq     1f
667         bset    #CPUTYPE_060,%d1
668         bset    #CPUTYPE_0460,%d1
669         jra     3f
671         /*
672          * Test the BootInfo cputype for 040
673          */
674         btst    #CPUB_68040,%d0
675         jeq     2f
676         bset    #CPUTYPE_040,%d1
677         bset    #CPUTYPE_0460,%d1
678         jra     3f
680         /*
681          * Test the BootInfo cputype for 020
682          */
683         btst    #CPUB_68020,%d0
684         jeq     3f
685         bset    #CPUTYPE_020,%d1
686         jra     3f
688         /*
689          * Record the cpu type
690          */
691         lea     %pc@(L(cputype)),%a0
692         movel   %d1,%a0@
694         /*
695          * NOTE:
696          *
697          * Now the macros are valid:
698          *      is_040_or_060
699          *      is_not_040_or_060
700          *      is_040
701          *      is_060
702          *      is_not_060
703          */
705         /*
706          * Determine the cache mode for pages holding MMU tables
707          * and for supervisor mode, unused for '020 and '030
708          */
709         clrl    %d0
710         clrl    %d1
712         is_not_040_or_060(L(save_cachetype))
714         /*
715          * '040 or '060
716          * d1 := cacheable write-through
717          * NOTE: The 68040 manual strongly recommends non-cached for MMU tables,
718          * but we have been using write-through since at least 2.0.29 so I
719          * guess it is OK.
720          */
721 #ifdef CONFIG_060_WRITETHROUGH
722         /*
723          * If this is a 68060 board using drivers with cache coherency
724          * problems, then supervisor memory accesses need to be write-through
725          * also; otherwise, we want copyback.
726          */
728         is_not_060(1f)
729         movel   #_PAGE_CACHE040W,%d0
730         jra     L(save_cachetype)
731 #endif /* CONFIG_060_WRITETHROUGH */
733         movew   #_PAGE_CACHE040,%d0
735         movel   #_PAGE_CACHE040W,%d1
737 L(save_cachetype):
738         /* Save cache mode for supervisor mode and page tables
739          */
740         lea     %pc@(SYMBOL_NAME(m68k_supervisor_cachemode)),%a0
741         movel   %d0,%a0@
742         lea     %pc@(SYMBOL_NAME(m68k_pgtable_cachemode)),%a0
743         movel   %d1,%a0@
746  * raise interrupt level
747  */
748         movew   #0x2700,%sr
751    If running on an Atari, determine the I/O base of the
752    serial port and test if we are running on a Medusa or Hades.
753    This test is necessary here, because on the Hades the serial
754    port is only accessible in the high I/O memory area.
756    The test whether it is a Medusa is done by writing to the byte at
757    phys. 0x0. This should result in a bus error on all other machines.
759    ...should, but doesn't. The Afterburner040 for the Falcon has the
760    same behaviour (0x0..0x7 are no ROM shadow). So we have to do
761    another test to distinguish Medusa and AB040. This is a
762    read attempt for 0x00ff82fe phys. that should bus error on a Falcon
763    (+AB040), but is in the range where the Medusa always asserts DTACK.
765    The test for the Hades is done by reading address 0xb0000000. This
766    should give a bus error on the Medusa.
767  */
769 #ifdef CONFIG_ATARI
770         is_not_atari(L(notypetest))
772         /* get special machine type (Medusa/Hades/AB40) */
773         moveq   #0,%d3 /* default if tag doesn't exist */
774         get_bi_record   BI_ATARI_MCH_TYPE
775         tstl    %d0
776         jbmi    1f
777         movel   %a0@,%d3
778         lea     %pc@(SYMBOL_NAME(atari_mch_type)),%a0
779         movel   %d3,%a0@
781         /* On the Hades, the iobase must be set up before opening the
782          * serial port. There are no I/O regs at 0x00ffxxxx at all. */
783         moveq   #0,%d0
784         cmpl    #ATARI_MACH_HADES,%d3
785         jbne    1f
786         movel   #0xff000000,%d0         /* Hades I/O base addr: 0xff000000 */
787 1:      lea     %pc@(L(iobase)),%a0
788         movel   %d0,%a0@
790 L(notypetest):
791 #endif
794  * Initialize serial port
795  */
796         jbsr    L(serial_init)
799  * Initialize console
800  */
801 #ifdef CONFIG_MAC
802         is_not_mac(L(nocon))
803 #ifdef CONSOLE
804         jbsr    L(console_init)
805 #ifdef CONSOLE_PENGUIN
806         jbsr    L(console_put_penguin)
807 #endif  /* CONSOLE_PENGUIN */
808         jbsr    L(console_put_stats)
809 #endif  /* CONSOLE */
810 L(nocon):
811 #endif  /* CONFIG_MAC */
814         putc    '\n'
815         putc    'A'
816         dputn   %pc@(L(cputype))
817         dputn   %pc@(SYMBOL_NAME(m68k_supervisor_cachemode))
818         dputn   %pc@(SYMBOL_NAME(m68k_pgtable_cachemode))
819         dputc   '\n'
822  * Save physical start address of kernel
823  */
824         lea     %pc@(L(phys_kernel_start)),%a0
825         lea     %pc@(SYMBOL_NAME(_stext)),%a1
826         subl    #SYMBOL_NAME(_stext),%a1
827         movel   %a1,%a0@
829         putc    'B'
831         leds    0x4
834  *      mmu_init
836  *      This block of code does what's necessary to map in the various kinds
837  *      of machines for execution of Linux.
838  *      First map the first 4 MB of kernel code & data
839  */
841         mmu_map #0,%pc@(L(phys_kernel_start)),#4*1024*1024,\
842                 %pc@(SYMBOL_NAME(m68k_supervisor_cachemode))
844         putc    'C'
846 #ifdef CONFIG_AMIGA
848 L(mmu_init_amiga):
850         is_not_amiga(L(mmu_init_not_amiga))
852  * mmu_init_amiga
853  */
855         putc    'D'
857         is_not_040_or_060(1f)
859         /*
860          * 040: Map the 16Meg range physical 0x0 upto logical 0x8000.0000
861          */
862         mmu_map #0x80000000,#0,#0x01000000,#_PAGE_NOCACHE_S
864         jbra    L(mmu_init_done)
867         /*
868          * 030: Map the 32Meg range physical 0x0 upto logical 0x8000.0000
869          */
870         mmu_map #0x80000000,#0,#0x02000000,#_PAGE_NOCACHE030
872         jbra    L(mmu_init_done)
874 L(mmu_init_not_amiga):
875 #endif
877 #ifdef CONFIG_ATARI
879 L(mmu_init_atari):
881         is_not_atari(L(mmu_init_not_atari))
883         putc    'E'
885 /* On the Atari, we map the I/O region (phys. 0x00ffxxxx) by mapping
886    the last 16 MB of virtual address space to the first 16 MB (i.e.
887    0xffxxxxxx -> 0x00xxxxxx). For this, an additional pointer table is
888    needed. I/O ranges are marked non-cachable.
890    For the Medusa it is better to map the I/O region transparently
891    (i.e. 0xffxxxxxx -> 0xffxxxxxx), because some I/O registers are
892    accessible only in the high area.
894    On the Hades all I/O registers are only accessible in the high
895    area.
898         /* I/O base addr for non-Medusa, non-Hades: 0x00000000 */
899         moveq   #0,%d0
900         movel   %pc@(SYMBOL_NAME(atari_mch_type)),%d3
901         cmpl    #ATARI_MACH_MEDUSA,%d3
902         jbeq    2f
903         cmpl    #ATARI_MACH_HADES,%d3
904         jbne    1f
905 2:      movel   #0xff000000,%d0 /* Medusa/Hades base addr: 0xff000000 */
906 1:      movel   %d0,%d3
908         is_040_or_060(L(spata68040))
910         /* Map everything non-cacheable, though not all parts really
911          * need to disable caches (crucial only for 0xff8000..0xffffff
912          * (standard I/O) and 0xf00000..0xf3ffff (IDE)). The remainder
913          * isn't really used, except for sometimes peeking into the
914          * ROMs (mirror at phys. 0x0), so caching isn't necessary for
915          * this. */
916         mmu_map #0xff000000,%d3,#0x01000000,#_PAGE_NOCACHE030
918         jbra    L(mmu_init_done)
920 L(spata68040):
922         mmu_map #0xff000000,%d3,#0x01000000,#_PAGE_NOCACHE_S
924         jbra    L(mmu_init_done)
926 L(mmu_init_not_atari):
927 #endif
929 #ifdef CONFIG_HP300
930         is_not_hp300(L(nothp300))
932 /* On the HP300, we map the ROM, INTIO and DIO regions (phys. 0x00xxxxxx)
933    by mapping 32MB from 0xf0xxxxxx -> 0x00xxxxxx) using an 030 early
934    termination page descriptor.  The ROM mapping is needed because the LEDs
935    are mapped there too.  */
937         mmu_map #0xf0000000,#0,#0x02000000,#_PAGE_NOCACHE030
939 L(nothp300):
941 #endif
943 #ifdef CONFIG_MVME16x
945         is_not_mvme16x(L(not16x))
947         /* Get pointer to board ID data */
948         movel   %d2,%sp@-
949         trap    #15
950         .word   0x70            /* trap 0x70 - .BRD_ID */
951         movel   %sp@+,%d2
952         lea     %pc@(SYMBOL_NAME(mvme_bdid_ptr)),%a0
953         movel   %d2,%a0@
955         /*
956          * On MVME16x we have already created kernel page tables for
957          * 4MB of RAM at address 0, so now need to do a transparent
958          * mapping of the top of memory space.  Make it 0.5GByte for now.
959          * Supervisor only access, so transparent mapping doesn't
960          * clash with User code virtual address space.
961          * this covers IO devices, PROM and SRAM.  The PROM and SRAM
962          * mapping is needed to allow 167Bug to run.
963          * IO is in the range 0xfff00000 to 0xfffeffff.
964          * PROM is 0xff800000->0xffbfffff and SRAM is
965          * 0xffe00000->0xffe1ffff.
966          */
968         mmu_map_tt      1,#0xe0000000,#0x20000000,#_PAGE_NOCACHE_S
970         jbra    L(mmu_init_done)
972 L(not16x):
973 #endif  /* CONFIG_MVME162 | CONFIG_MVME167 */
975 #ifdef CONFIG_BVME6000
977         is_not_bvme6000(L(not6000))
979         /*
980          * On BVME6000 we have already created kernel page tables for
981          * 4MB of RAM at address 0, so now need to do a transparent
982          * mapping of the top of memory space.  Make it 0.5GByte for now,
983          * so we can access on-board i/o areas.
984          * Supervisor only access, so transparent mapping doesn't
985          * clash with User code virtual address space.
986          */
988         mmu_map_tt      1,#0xe0000000,#0x20000000,#_PAGE_NOCACHE_S
990         jbra    L(mmu_init_done)
992 L(not6000):
993 #endif /* CONFIG_BVME6000 */
996  * mmu_init_mac
998  * The Macintosh mappings are less clear.
1000  * Even as of this writing, it is unclear how the
1001  * Macintosh mappings will be done.  However, as
1002  * the first author of this code I'm proposing the
1003  * following model:
1005  * Map the kernel (that's already done),
1006  * Map the I/O (on most machines that's the
1007  * 0x5000.0000 ... 0x5200.0000 range,
1008  * Map the video frame buffer using as few pages
1009  * as absolutely (this requirement mostly stems from
1010  * the fact that when the frame buffer is at
1011  * 0x0000.0000 then we know there is valid RAM just
1012  * above the screen that we don't want to waste!).
1014  * By the way, if the frame buffer is at 0x0000.0000
1015  * then the Macintosh is known as an RBV based Mac.
1017  * By the way 2, the code currently maps in a bunch of
1018  * regions.  But I'd like to cut that out.  (And move most
1019  * of the mappings up into the kernel proper ... or only
1020  * map what's necessary.)
1021  */
1023 #ifdef CONFIG_MAC
1025 L(mmu_init_mac):
1027         is_not_mac(L(mmu_init_not_mac))
1029         putc    'F'
1031         lea     %pc@(L(mac_videobase)),%a0
1032         lea     %pc@(L(console_video_virtual)),%a1
1033         movel   %a0@,%a1@
1035         is_not_040_or_060(1f)
1037         moveq   #_PAGE_NOCACHE_S,%d3
1038         jbra    2f
1040         moveq   #_PAGE_NOCACHE030,%d3
1042         /*
1043          * Mac Note: screen address of logical 0xF000.0000 -> <screen physical>
1044          *           we simply map the 4MB that contains the videomem
1045          */
1047         movel   #VIDEOMEMMASK,%d0
1048         andl    L(mac_videobase),%d0
1050         mmu_map         #VIDEOMEMBASE,%d0,#VIDEOMEMSIZE,%d3
1051         mmu_map_eq      #0x40800000,#0x02000000,%d3     /* rom ? */
1052         mmu_map_eq      #0x50000000,#0x02000000,%d3
1053         mmu_map_eq      #0x60000000,#0x00400000,%d3
1054         mmu_map_eq      #0x9c000000,#0x00400000,%d3
1055         mmu_map_tt      1,#0xf8000000,#0x08000000,%d3
1057         jbra    L(mmu_init_done)
1059 L(mmu_init_not_mac):
1060 #endif
1062 L(mmu_init_done):
1064         putc    'G'
1065         leds    0x8
1068  * mmu_fixup
1070  * On the 040 class machines, all pages that are used for the
1071  * mmu have to be fixed up. According to Motorola, pages holding mmu
1072  * tables should be non-cacheable on a '040 and write-through on a
1073  * '060. But analysis of the reasons for this, and practical
1074  * experience, showed that write-through also works on a '040.
1076  * Allocated memory so far goes from kernel_end to memory_start that
1077  * is used for all kind of tables, for that the cache attributes
1078  * are now fixed.
1079  */
1080 L(mmu_fixup):
1082         is_not_040_or_060(L(mmu_fixup_done))
1084 #ifdef MMU_NOCACHE_KERNEL
1085         jbra    L(mmu_fixup_done)
1086 #endif
1088         /* first fix the page at the start of the kernel, that
1089          * contains also kernel_pg_dir.
1090          */
1091         movel   %pc@(L(phys_kernel_start)),%d0
1092         lea     %pc@(SYMBOL_NAME(_stext)),%a0
1093         subl    %d0,%a0
1094         mmu_fixup_page_mmu_cache        %a0
1096         movel   %pc@(L(kernel_end)),%a0
1097         subl    %d0,%a0
1098         movel   %pc@(L(memory_start)),%a1
1099         subl    %d0,%a1
1100         bra     2f
1102         mmu_fixup_page_mmu_cache        %a0
1103         addw    #PAGESIZE,%a0
1105         cmpl    %a0,%a1
1106         jgt     1b
1108 L(mmu_fixup_done):
1110 #ifdef MMU_PRINT
1111         mmu_print
1112 #endif
1115  * mmu_engage
1117  * This chunk of code performs the gruesome task of engaging the MMU.
1118  * The reason its gruesome is because when the MMU becomes engaged it
1119  * maps logical addresses to physical addresses.  The Program Counter
1120  * register is then passed through the MMU before the next instruction
1121  * is fetched (the instruction following the engage MMU instruction).
1122  * This may mean one of two things:
1123  * 1. The Program Counter falls within the logical address space of
1124  *    the kernel of which there are two sub-possibilities:
1125  *    A. The PC maps to the correct instruction (logical PC == physical
1126  *       code location), or
1127  *    B. The PC does not map through and the processor will read some
1128  *       data (or instruction) which is not the logically next instr.
1129  *    As you can imagine, A is good and B is bad.
1130  * Alternatively,
1131  * 2. The Program Counter does not map through the MMU.  The processor
1132  *    will take a Bus Error.
1133  * Clearly, 2 is bad.
1134  * It doesn't take a wiz kid to figure you want 1.A.
1135  * This code creates that possibility.
1136  * There are two possible 1.A. states (we now ignore the other above states):
1137  * A. The kernel is located at physical memory addressed the same as
1138  *    the logical memory for the kernel, i.e., 0x01000.
1139  * B. The kernel is located some where else.  e.g., 0x0400.0000
1141  *    Under some conditions the Macintosh can look like A or B.
1142  * [A friend and I once noted that Apple hardware engineers should be
1143  * wacked twice each day: once when they show up at work (as in, Whack!,
1144  * "This is for the screwy hardware we know you're going to design today."),
1145  * and also at the end of the day (as in, Whack! "I don't know what
1146  * you designed today, but I'm sure it wasn't good."). -- rst]
1148  * This code works on the following premise:
1149  * If the kernel start (%d5) is within the first 16 Meg of RAM,
1150  * then create a mapping for the kernel at logical 0x8000.0000 to
1151  * the physical location of the pc.  And, create a transparent
1152  * translation register for the first 16 Meg.  Then, after the MMU
1153  * is engaged, the PC can be moved up into the 0x8000.0000 range
1154  * and then the transparent translation can be turned off and then
1155  * the PC can jump to the correct logical location and it will be
1156  * home (finally).  This is essentially the code that the Amiga used
1157  * to use.  Now, it's generalized for all processors.  Which means
1158  * that a fresh (but temporary) mapping has to be created.  The mapping
1159  * is made in page 0 (an as of yet unused location -- except for the
1160  * stack!).  This temporary mapping will only require 1 pointer table
1161  * and a single page table (it can map 256K).
1163  * OK, alternatively, imagine that the Program Counter is not within
1164  * the first 16 Meg.  Then, just use Transparent Translation registers
1165  * to do the right thing.
1167  * Last, if _start is already at 0x01000, then there's nothing special
1168  * to do (in other words, in a degenerate case of the first case above,
1169  * do nothing).
1171  * Let's do it.
1174  */
1176         putc    'H'
1178         mmu_engage
1180 #ifdef CONFIG_AMIGA
1181         is_not_amiga(1f)
1182         /* fixup the Amiga custom register location before printing */
1183         clrl    L(custom)
1185 #endif
1187 #ifdef CONFIG_ATARI
1188         is_not_atari(1f)
1189         /* fixup the Atari iobase register location before printing */
1190         movel   #0xff000000,L(iobase)
1192 #endif
1194 #ifdef CONFIG_MAC
1195         is_not_mac(1f)
1196         movel   #~VIDEOMEMMASK,%d0
1197         andl    L(mac_videobase),%d0
1198         addl    #VIDEOMEMBASE,%d0
1199         movel   %d0,L(mac_videobase)
1201 #endif
1203 #ifdef CONFIG_HP300
1204         is_not_hp300(1f)
1205         /*
1206          * Fix up the custom register to point to the new location of the LEDs.
1207          */
1208         movel   #0xf0000000,L(custom)
1210         /*
1211          * Energise the FPU and caches.
1212          */
1213         movel   #0x60,0xf05f400c
1215 #endif
1218  * Fixup the addresses for the kernel pointer table and availmem.
1219  * Convert them from physical addresses to virtual addresses.
1220  */
1222         putc    'I'
1223         leds    0x10
1225         /* do the same conversion on the first available memory
1226          * address (in a6).
1227          */
1228         movel   L(memory_start),%d0
1229         movel   %d0,SYMBOL_NAME(availmem)
1232  * Enable caches
1233  */
1235         is_not_040_or_060(L(cache_not_680460))
1237 L(cache680460):
1238         .chip   68040
1239         nop
1240         cpusha  %bc
1241         nop
1243         is_060(L(cache68060))
1245         movel   #CC6_ENABLE_D+CC6_ENABLE_I,%d0
1246         /* MMU stuff works in copyback mode now, so enable the cache */
1247         movec   %d0,%cacr
1248         jra     L(cache_done)
1250 L(cache68060):
1251         movel   #CC6_ENABLE_D+CC6_ENABLE_I+CC6_ENABLE_SB+CC6_PUSH_DPI+CC6_ENABLE_B+CC6_CLRA_B,%d0
1252         /* MMU stuff works in copyback mode now, so enable the cache */
1253         movec   %d0,%cacr
1254         /* enable superscalar dispatch in PCR */
1255         moveq   #1,%d0
1256         .chip   68060
1257         movec   %d0,%pcr
1259         jbra    L(cache_done)
1260 L(cache_not_680460):
1261 L(cache68030):
1262         .chip   68030
1263         movel   #CC3_ENABLE_DB+CC3_CLR_D+CC3_ENABLE_D+CC3_ENABLE_IB+CC3_CLR_I+CC3_ENABLE_I,%d0
1264         movec   %d0,%cacr
1266         jra     L(cache_done)
1267         .chip   68k
1268 L(cache_done):
1270         putc    'J'
1273  * Setup initial stack pointer
1274  */
1275         lea     SYMBOL_NAME(init_task_union),%a2
1276         lea     0x2000(%a2),%sp
1278 /* jump to the kernel start */
1279         putc    '\n'
1280         leds    0x55
1282         subl    %a6,%a6         /* clear a6 for gdb */
1283         jbsr    SYMBOL_NAME(start_kernel)
1286  * Find a tag record in the bootinfo structure
1287  * The bootinfo structure is located right after the kernel bss
1288  * Returns: d0: size (-1 if not found)
1289  *          a0: data pointer (end-of-records if not found)
1290  */
1291 func_start      get_bi_record,%d1
1293         movel   ARG1,%d0
1294         lea     %pc@(SYMBOL_NAME(_end)),%a0
1295 1:      tstw    %a0@(BIR_TAG)
1296         jeq     3f
1297         cmpw    %a0@(BIR_TAG),%d0
1298         jeq     2f
1299         addw    %a0@(BIR_SIZE),%a0
1300         jra     1b
1301 2:      moveq   #0,%d0
1302         movew   %a0@(BIR_SIZE),%d0
1303         lea     %a0@(BIR_DATA),%a0
1304         jra     4f
1305 3:      moveq   #-1,%d0
1306         lea     %a0@(BIR_SIZE),%a0
1308 func_return     get_bi_record
1312  *      MMU Initialization Begins Here
1314  *      The structure of the MMU tables on the 68k machines
1315  *      is thus:
1316  *      Root Table
1317  *              Logical addresses are translated through
1318  *      a hierarchical translation mechanism where the high-order
1319  *      seven bits of the logical address (LA) are used as an
1320  *      index into the "root table."  Each entry in the root
1321  *      table has a bit which specifies if it's a valid pointer to a
1322  *      pointer table.  Each entry defines a 32KMeg range of memory.
1323  *      If an entry is invalid then that logical range of 32M is
1324  *      invalid and references to that range of memory (when the MMU
1325  *      is enabled) will fault.  If the entry is valid, then it does
1326  *      one of two things.  On 040/060 class machines, it points to
1327  *      a pointer table which then describes more finely the memory
1328  *      within that 32M range.  On 020/030 class machines, a technique
1329  *      called "early terminating descriptors" are used.  This technique
1330  *      allows an entire 32Meg to be described by a single entry in the
1331  *      root table.  Thus, this entry in the root table, contains the
1332  *      physical address of the memory or I/O at the logical address
1333  *      which the entry represents and it also contains the necessary
1334  *      cache bits for this region.
1336  *      Pointer Tables
1337  *              Per the Root Table, there will be one or more
1338  *      pointer tables.  Each pointer table defines a 32M range.
1339  *      Not all of the 32M range need be defined.  Again, the next
1340  *      seven bits of the logical address are used an index into
1341  *      the pointer table to point to page tables (if the pointer
1342  *      is valid).  There will undoubtedly be more than one
1343  *      pointer table for the kernel because each pointer table
1344  *      defines a range of only 32M.  Valid pointer table entries
1345  *      point to page tables, or are early terminating entries
1346  *      themselves.
1348  *      Page Tables
1349  *              Per the Pointer Tables, each page table entry points
1350  *      to the physical page in memory that supports the logical
1351  *      address that translates to the particular index.
1353  *      In short, the Logical Address gets translated as follows:
1354  *              bits 31..26 - index into the Root Table
1355  *              bits 25..18 - index into the Pointer Table
1356  *              bits 17..12 - index into the Page Table
1357  *              bits 11..0  - offset into a particular 4K page
1359  *      The algorithms which follows do one thing: they abstract
1360  *      the MMU hardware.  For example, there are three kinds of
1361  *      cache settings that are relevant.  Either, memory is
1362  *      being mapped in which case it is either Kernel Code (or
1363  *      the RamDisk) or it is MMU data.  On the 030, the MMU data
1364  *      option also describes the kernel.  Or, I/O is being mapped
1365  *      in which case it has its own kind of cache bits.  There
1366  *      are constants which abstract these notions from the code that
1367  *      actually makes the call to map some range of memory.
1371  */
1373 #ifdef MMU_PRINT
1375  *      mmu_print
1377  *      This algorithm will print out the current MMU mappings.
1379  *      Input:
1380  *              %a5 points to the root table.  Everything else is calculated
1381  *                      from this.
1382  */
1384 #define mmu_next_valid          0
1385 #define mmu_start_logical       4
1386 #define mmu_next_logical        8
1387 #define mmu_start_physical      12
1388 #define mmu_next_physical       16
1390 #define MMU_PRINT_INVALID               -1
1391 #define MMU_PRINT_VALID                 1
1392 #define MMU_PRINT_UNINITED              0
1394 #define putZc(z,n)              jbne 1f; putc z; jbra 2f; 1: putc n; 2:
1396 func_start      mmu_print,%a0-%a6/%d0-%d7
1398         movel   %pc@(L(kernel_pgdir_ptr)),%a5
1399         lea     %pc@(L(mmu_print_data)),%a0
1400         movel   #MMU_PRINT_UNINITED,%a0@(mmu_next_valid)
1402         is_not_040_or_060(mmu_030_print)
1404 mmu_040_print:
1405         puts    "\nMMU040\n"
1406         puts    "rp:"
1407         putn    %a5
1408         putc    '\n'
1409 #if 0
1410         /*
1411          * The following #if/#endif block is a tight algorithm for dumping the 040
1412          * MMU Map in gory detail.  It really isn't that practical unless the
1413          * MMU Map algorithm appears to go awry and you need to debug it at the
1414          * entry per entry level.
1415          */
1416         movel   #ROOT_TABLE_SIZE,%d5
1417 #if 0
1418         movel   %a5@+,%d7               | Burn an entry to skip the kernel mappings,
1419         subql   #1,%d5                  | they (might) work
1420 #endif
1421 1:      tstl    %d5
1422         jbeq    mmu_print_done
1423         subq    #1,%d5
1424         movel   %a5@+,%d7
1425         btst    #1,%d7
1426         jbeq    1b
1428 2:      putn    %d7
1429         andil   #0xFFFFFE00,%d7
1430         movel   %d7,%a4
1431         movel   #PTR_TABLE_SIZE,%d4
1432         putc    ' '
1433 3:      tstl    %d4
1434         jbeq    11f
1435         subq    #1,%d4
1436         movel   %a4@+,%d7
1437         btst    #1,%d7
1438         jbeq    3b
1440 4:      putn    %d7
1441         andil   #0xFFFFFF00,%d7
1442         movel   %d7,%a3
1443         movel   #PAGE_TABLE_SIZE,%d3
1444 5:      movel   #8,%d2
1445 6:      tstl    %d3
1446         jbeq    31f
1447         subq    #1,%d3
1448         movel   %a3@+,%d6
1449         btst    #0,%d6
1450         jbeq    6b
1451 7:      tstl    %d2
1452         jbeq    8f
1453         subq    #1,%d2
1454         putc    ' '
1455         jbra    91f
1456 8:      putc    '\n'
1457         movel   #8+1+8+1+1,%d2
1458 9:      putc    ' '
1459         dbra    %d2,9b
1460         movel   #7,%d2
1461 91:     putn    %d6
1462         jbra    6b
1464 31:     putc    '\n'
1465         movel   #8+1,%d2
1466 32:     putc    ' '
1467         dbra    %d2,32b
1468         jbra    3b
1470 11:     putc    '\n'
1471         jbra    1b
1472 #endif /* MMU 040 Dumping code that's gory and detailed */
1474         lea     %pc@(SYMBOL_NAME(kernel_pg_dir)),%a5
1475         movel   %a5,%a0                 /* a0 has the address of the root table ptr */
1476         movel   #0x00000000,%a4         /* logical address */
1477         moveql  #0,%d0
1479         /* Increment the logical address and preserve in d5 */
1480         movel   %a4,%d5
1481         addil   #PAGESIZE<<13,%d5
1482         movel   %a0@+,%d6
1483         btst    #1,%d6
1484         jbne    41f
1485         jbsr    mmu_print_tuple_invalidate
1486         jbra    48f
1488         movel   #0,%d1
1489         andil   #0xfffffe00,%d6
1490         movel   %d6,%a1
1492         movel   %a4,%d5
1493         addil   #PAGESIZE<<6,%d5
1494         movel   %a1@+,%d6
1495         btst    #1,%d6
1496         jbne    43f
1497         jbsr    mmu_print_tuple_invalidate
1498         jbra    47f
1500         movel   #0,%d2
1501         andil   #0xffffff00,%d6
1502         movel   %d6,%a2
1504         movel   %a4,%d5
1505         addil   #PAGESIZE,%d5
1506         movel   %a2@+,%d6
1507         btst    #0,%d6
1508         jbne    45f
1509         jbsr    mmu_print_tuple_invalidate
1510         jbra    46f
1512         moveml  %d0-%d1,%sp@-
1513         movel   %a4,%d0
1514         movel   %d6,%d1
1515         andil   #0xfffff4e0,%d1
1516         lea     %pc@(mmu_040_print_flags),%a6
1517         jbsr    mmu_print_tuple
1518         moveml  %sp@+,%d0-%d1
1520         movel   %d5,%a4
1521         addq    #1,%d2
1522         cmpib   #64,%d2
1523         jbne    44b
1525         movel   %d5,%a4
1526         addq    #1,%d1
1527         cmpib   #128,%d1
1528         jbne    42b
1530         movel   %d5,%a4                 /* move to the next logical address */
1531         addq    #1,%d0
1532         cmpib   #128,%d0
1533         jbne    40b
1535         .chip   68040
1536         movec   %dtt1,%d0
1537         movel   %d0,%d1
1538         andiw   #0x8000,%d1             /* is it valid ? */
1539         jbeq    1f                      /* No, bail out */
1541         movel   %d0,%d1
1542         andil   #0xff000000,%d1         /* Get the address */
1543         putn    %d1
1544         puts    "=="
1545         putn    %d1
1547         movel   %d0,%d6
1548         jbsr    mmu_040_print_flags_tt
1550         movec   %dtt0,%d0
1551         movel   %d0,%d1
1552         andiw   #0x8000,%d1             /* is it valid ? */
1553         jbeq    1f                      /* No, bail out */
1555         movel   %d0,%d1
1556         andil   #0xff000000,%d1         /* Get the address */
1557         putn    %d1
1558         puts    "=="
1559         putn    %d1
1561         movel   %d0,%d6
1562         jbsr    mmu_040_print_flags_tt
1564         .chip   68k
1566         jbra    mmu_print_done
1568 mmu_040_print_flags:
1569         btstl   #10,%d6
1570         putZc(' ','G')  /* global bit */
1571         btstl   #7,%d6
1572         putZc(' ','S')  /* supervisor bit */
1573 mmu_040_print_flags_tt:
1574         btstl   #6,%d6
1575         jbne    3f
1576         putc    'C'
1577         btstl   #5,%d6
1578         putZc('w','c')  /* write through or copy-back */
1579         jbra    4f
1581         putc    'N'
1582         btstl   #5,%d6
1583         putZc('s',' ')  /* serialized non-cacheable, or non-cacheable */
1585         rts
1587 mmu_030_print_flags:
1588         btstl   #6,%d6
1589         putZc('C','I')  /* write through or copy-back */
1590         rts
1592 mmu_030_print:
1593         puts    "\nMMU030\n"
1594         puts    "\nrp:"
1595         putn    %a5
1596         putc    '\n'
1597         movel   %a5,%d0
1598         andil   #0xfffffff0,%d0
1599         movel   %d0,%a0
1600         movel   #0x00000000,%a4         /* logical address */
1601         movel   #0,%d0
1603         movel   %a4,%d5
1604         addil   #PAGESIZE<<13,%d5
1605         movel   %a0@+,%d6
1606         btst    #1,%d6                  /* is it a ptr? */
1607         jbne    31f                     /* yes */
1608         btst    #0,%d6                  /* is it early terminating? */
1609         jbeq    1f                      /* no */
1610         jbsr    mmu_030_print_helper
1611         jbra    38f
1613         jbsr    mmu_print_tuple_invalidate
1614         jbra    38f
1616         movel   #0,%d1
1617         andil   #0xfffffff0,%d6
1618         movel   %d6,%a1
1620         movel   %a4,%d5
1621         addil   #PAGESIZE<<6,%d5
1622         movel   %a1@+,%d6
1623         btst    #1,%d6
1624         jbne    33f
1625         btst    #0,%d6
1626         jbeq    1f                      /* no */
1627         jbsr    mmu_030_print_helper
1628         jbra    37f
1630         jbsr    mmu_print_tuple_invalidate
1631         jbra    37f
1633         movel   #0,%d2
1634         andil   #0xfffffff0,%d6
1635         movel   %d6,%a2
1637         movel   %a4,%d5
1638         addil   #PAGESIZE,%d5
1639         movel   %a2@+,%d6
1640         btst    #0,%d6
1641         jbne    35f
1642         jbsr    mmu_print_tuple_invalidate
1643         jbra    36f
1645         jbsr    mmu_030_print_helper
1647         movel   %d5,%a4
1648         addq    #1,%d2
1649         cmpib   #64,%d2
1650         jbne    34b
1652         movel   %d5,%a4
1653         addq    #1,%d1
1654         cmpib   #128,%d1
1655         jbne    32b
1657         movel   %d5,%a4                 /* move to the next logical address */
1658         addq    #1,%d0
1659         cmpib   #128,%d0
1660         jbne    30b
1662 mmu_print_done:
1663         puts    "\n\n"
1665 func_return     mmu_print
1668 mmu_030_print_helper:
1669         moveml  %d0-%d1,%sp@-
1670         movel   %a4,%d0
1671         movel   %d6,%d1
1672         lea     %pc@(mmu_030_print_flags),%a6
1673         jbsr    mmu_print_tuple
1674         moveml  %sp@+,%d0-%d1
1675         rts
1677 mmu_print_tuple_invalidate:
1678         moveml  %a0/%d7,%sp@-
1680         lea     %pc@(L(mmu_print_data)),%a0
1681         tstl    %a0@(mmu_next_valid)
1682         jbmi    mmu_print_tuple_invalidate_exit
1684         movel   #MMU_PRINT_INVALID,%a0@(mmu_next_valid)
1686         putn    %a4
1688         puts    "##\n"
1690 mmu_print_tuple_invalidate_exit:
1691         moveml  %sp@+,%a0/%d7
1692         rts
1695 mmu_print_tuple:
1696         moveml  %d0-%d7/%a0,%sp@-
1698         lea     %pc@(L(mmu_print_data)),%a0
1700         tstl    %a0@(mmu_next_valid)
1701         jble    mmu_print_tuple_print
1703         cmpl    %a0@(mmu_next_physical),%d1
1704         jbeq    mmu_print_tuple_increment
1706 mmu_print_tuple_print:
1707         putn    %d0
1708         puts    "->"
1709         putn    %d1
1711         movel   %d1,%d6
1712         jbsr    %a6@
1714 mmu_print_tuple_record:
1715         movel   #MMU_PRINT_VALID,%a0@(mmu_next_valid)
1717         movel   %d1,%a0@(mmu_next_physical)
1719 mmu_print_tuple_increment:
1720         movel   %d5,%d7
1721         subl    %a4,%d7
1722         addl    %d7,%a0@(mmu_next_physical)
1724 mmu_print_tuple_exit:
1725         moveml  %sp@+,%d0-%d7/%a0
1726         rts
1728 mmu_print_machine_cpu_types:
1729         puts    "machine: "
1731         is_not_amiga(1f)
1732         puts    "amiga"
1733         jbra    9f
1735         is_not_atari(2f)
1736         puts    "atari"
1737         jbra    9f
1739         is_not_mac(3f)
1740         puts    "macintosh"
1741         jbra    9f
1742 3:      puts    "unknown"
1743 9:      putc    '\n'
1745         puts    "cputype: 0"
1746         is_not_060(1f)
1747         putc    '6'
1748         jbra    9f
1750         is_not_040_or_060(2f)
1751         putc    '4'
1752         jbra    9f
1753 2:      putc    '3'
1754 9:      putc    '0'
1755         putc    '\n'
1757         rts
1758 #endif /* MMU_PRINT */
1761  * mmu_map_tt
1763  * This is a specific function which works on all 680x0 machines.
1764  * On 030, 040 & 060 it will attempt to use Transparent Translation
1765  * registers (tt1).
1766  * On 020 it will call the standard mmu_map which will use early
1767  * terminating descriptors.
1768  */
1769 func_start      mmu_map_tt,%d0/%d1/%a0,4
1771         dputs   "mmu_map_tt:"
1772         dputn   ARG1
1773         dputn   ARG2
1774         dputn   ARG3
1775         dputn   ARG4
1776         dputc   '\n'
1778         is_020(L(do_map))
1780         /* Extract the highest bit set
1781          */
1782         bfffo   ARG3{#0,#32},%d1
1783         cmpw    #8,%d0
1784         jcc     L(do_map)
1786         /* And get the mask
1787          */
1788         moveq   #-1,%d0
1789         lsrl    %d1,%d0
1790         lsrl    #1,%d0
1792         /* Mask the address
1793          */
1794         movel   %d0,%d1
1795         notl    %d1
1796         andl    ARG2,%d1
1798         /* Generate the upper 16bit of the tt register
1799          */
1800         lsrl    #8,%d0
1801         orl     %d0,%d1
1802         clrw    %d1
1804         is_040_or_060(L(mmu_map_tt_040))
1806         /* set 030 specific bits (read/write access for supervisor mode
1807          * (highest function code set, lower two bits masked))
1808          */
1809         orw     #TTR_ENABLE+TTR_RWM+TTR_FCB2+TTR_FCM1+TTR_FCM0,%d1
1810         movel   ARG4,%d0
1811         btst    #6,%d0
1812         jeq     1f
1813         orw     #TTR_CI,%d1
1815 1:      lea     STACK,%a0
1816         dputn   %d1
1817         movel   %d1,%a0@
1818         .chip   68030
1819         tstl    ARG1
1820         jne     1f
1821         pmove   %a0@,%tt0
1822         jra     2f
1823 1:      pmove   %a0@,%tt1
1824 2:      .chip   68k
1825         jra     L(mmu_map_tt_done)
1827         /* set 040 specific bits
1828          */
1829 L(mmu_map_tt_040):
1830         orw     #TTR_ENABLE+TTR_KERNELMODE,%d1
1831         orl     ARG4,%d1
1832         dputn   %d1
1834         .chip   68040
1835         tstl    ARG1
1836         jne     1f
1837         movec   %d1,%itt0
1838         movec   %d1,%dtt0
1839         jra     2f
1840 1:      movec   %d1,%itt1
1841         movec   %d1,%dtt1
1842 2:      .chip   68k
1844         jra     L(mmu_map_tt_done)
1846 L(do_map):
1847         mmu_map_eq      ARG2,ARG3,ARG4
1849 L(mmu_map_tt_done):
1851 func_return     mmu_map_tt
1854  *      mmu_map
1856  *      This routine will map a range of memory using a pointer
1857  *      table and allocating the pages on the fly from the kernel.
1858  *      The pointer table does not have to be already linked into
1859  *      the root table, this routine will do that if necessary.
1861  *      NOTE
1862  *      This routine will assert failure and use the serial_putc
1863  *      routines in the case of a run-time error.  For example,
1864  *      if the address is already mapped.
1866  *      NOTE-2
1867  *      This routine will use early terminating descriptors
1868  *      where possible for the 68020+68851 and 68030 type
1869  *      processors.
1870  */
1871 func_start      mmu_map,%d0-%d4/%a0-%a4
1873         dputs   "\nmmu_map:"
1874         dputn   ARG1
1875         dputn   ARG2
1876         dputn   ARG3
1877         dputn   ARG4
1878         dputc   '\n'
1880         /* Get logical address and round it down to 256KB
1881          */
1882         movel   ARG1,%d0
1883         andl    #-(PAGESIZE*PAGE_TABLE_SIZE),%d0
1884         movel   %d0,%a3
1886         /* Get the end address
1887          */
1888         movel   ARG1,%a4
1889         addl    ARG3,%a4
1890         subql   #1,%a4
1892         /* Get physical address and round it down to 256KB
1893          */
1894         movel   ARG2,%d0
1895         andl    #-(PAGESIZE*PAGE_TABLE_SIZE),%d0
1896         movel   %d0,%a2
1898         /* Add page attributes to the physical address
1899          */
1900         movel   ARG4,%d0
1901         orw     #_PAGE_PRESENT+_PAGE_ACCESSED+_PAGE_DIRTY,%d0
1902         addw    %d0,%a2
1904         dputn   %a2
1905         dputn   %a3
1906         dputn   %a4
1908         is_not_040_or_060(L(mmu_map_030))
1910         addw    #_PAGE_GLOBAL040,%a2
1912  *      MMU 040 & 060 Support
1914  *      The MMU usage for the 040 and 060 is different enough from
1915  *      the 030 and 68851 that there is separate code.  This comment
1916  *      block describes the data structures and algorithms built by
1917  *      this code.
1919  *      The 040 does not support early terminating descriptors, as
1920  *      the 030 does.  Therefore, a third level of table is needed
1921  *      for the 040, and that would be the page table.  In Linux,
1922  *      page tables are allocated directly from the memory above the
1923  *      kernel.
1925  */
1927 L(mmu_map_040):
1928         /* Calculate the offset into the root table
1929          */
1930         movel   %a3,%d0
1931         moveq   #ROOT_INDEX_SHIFT,%d1
1932         lsrl    %d1,%d0
1933         mmu_get_root_table_entry        %d0
1935         /* Calculate the offset into the pointer table
1936          */
1937         movel   %a3,%d0
1938         moveq   #PTR_INDEX_SHIFT,%d1
1939         lsrl    %d1,%d0
1940         andl    #PTR_TABLE_SIZE-1,%d0
1941         mmu_get_ptr_table_entry         %a0,%d0
1943         /* Calculate the offset into the page table
1944          */
1945         movel   %a3,%d0
1946         moveq   #PAGE_INDEX_SHIFT,%d1
1947         lsrl    %d1,%d0
1948         andl    #PAGE_TABLE_SIZE-1,%d0
1949         mmu_get_page_table_entry        %a0,%d0
1951         /* The page table entry must not no be busy
1952          */
1953         tstl    %a0@
1954         jne     L(mmu_map_error)
1956         /* Do the mapping and advance the pointers
1957          */
1958         movel   %a2,%a0@
1960         addw    #PAGESIZE,%a2
1961         addw    #PAGESIZE,%a3
1963         /* Ready with mapping?
1964          */
1965         lea     %a3@(-1),%a0
1966         cmpl    %a0,%a4
1967         jhi     L(mmu_map_040)
1968         jra     L(mmu_map_done)
1970 L(mmu_map_030):
1971         /* Calculate the offset into the root table
1972          */
1973         movel   %a3,%d0
1974         moveq   #ROOT_INDEX_SHIFT,%d1
1975         lsrl    %d1,%d0
1976         mmu_get_root_table_entry        %d0
1978         /* Check if logical address 32MB aligned,
1979          * so we can try to map it once
1980          */
1981         movel   %a3,%d0
1982         andl    #(PTR_TABLE_SIZE*PAGE_TABLE_SIZE*PAGESIZE-1)&(-ROOT_TABLE_SIZE),%d0
1983         jne     1f
1985         /* Is there enough to map for 32MB at once
1986          */
1987         lea     %a3@(PTR_TABLE_SIZE*PAGE_TABLE_SIZE*PAGESIZE-1),%a1
1988         cmpl    %a1,%a4
1989         jcs     1f
1991         addql   #1,%a1
1993         /* The root table entry must not no be busy
1994          */
1995         tstl    %a0@
1996         jne     L(mmu_map_error)
1998         /* Do the mapping and advance the pointers
1999          */
2000         dputs   "early term1"
2001         dputn   %a2
2002         dputn   %a3
2003         dputn   %a1
2004         dputc   '\n'
2005         movel   %a2,%a0@
2007         movel   %a1,%a3
2008         lea     %a2@(PTR_TABLE_SIZE*PAGE_TABLE_SIZE*PAGESIZE),%a2
2009         jra     L(mmu_mapnext_030)
2011         /* Calculate the offset into the pointer table
2012          */
2013         movel   %a3,%d0
2014         moveq   #PTR_INDEX_SHIFT,%d1
2015         lsrl    %d1,%d0
2016         andl    #PTR_TABLE_SIZE-1,%d0
2017         mmu_get_ptr_table_entry         %a0,%d0
2019         /* The pointer table entry must not no be busy
2020          */
2021         tstl    %a0@
2022         jne     L(mmu_map_error)
2024         /* Do the mapping and advance the pointers
2025          */
2026         dputs   "early term2"
2027         dputn   %a2
2028         dputn   %a3
2029         dputc   '\n'
2030         movel   %a2,%a0@
2032         addl    #PAGE_TABLE_SIZE*PAGESIZE,%a2
2033         addl    #PAGE_TABLE_SIZE*PAGESIZE,%a3
2035 L(mmu_mapnext_030):
2036         /* Ready with mapping?
2037          */
2038         lea     %a3@(-1),%a0
2039         cmpl    %a0,%a4
2040         jhi     L(mmu_map_030)
2041         jra     L(mmu_map_done)
2043 L(mmu_map_error):
2045         dputs   "mmu_map error:"
2046         dputn   %a2
2047         dputn   %a3
2048         dputc   '\n'
2050 L(mmu_map_done):
2052 func_return     mmu_map
2055  *      mmu_fixup
2057  *      On the 040 class machines, all pages that are used for the
2058  *      mmu have to be fixed up.
2059  */
2061 func_start      mmu_fixup_page_mmu_cache,%d0/%a0
2063         dputs   "mmu_fixup_page_mmu_cache"
2064         dputn   ARG1
2066         /* Calculate the offset into the root table
2067          */
2068         movel   ARG1,%d0
2069         moveq   #ROOT_INDEX_SHIFT,%d1
2070         lsrl    %d1,%d0
2071         mmu_get_root_table_entry        %d0
2073         /* Calculate the offset into the pointer table
2074          */
2075         movel   ARG1,%d0
2076         moveq   #PTR_INDEX_SHIFT,%d1
2077         lsrl    %d1,%d0
2078         andl    #PTR_TABLE_SIZE-1,%d0
2079         mmu_get_ptr_table_entry         %a0,%d0
2081         /* Calculate the offset into the page table
2082          */
2083         movel   ARG1,%d0
2084         moveq   #PAGE_INDEX_SHIFT,%d1
2085         lsrl    %d1,%d0
2086         andl    #PAGE_TABLE_SIZE-1,%d0
2087         mmu_get_page_table_entry        %a0,%d0
2089         movel   %a0@,%d0
2090         andil   #_CACHEMASK040,%d0
2091         orl     %pc@(SYMBOL_NAME(m68k_pgtable_cachemode)),%d0
2092         movel   %d0,%a0@
2094         dputc   '\n'
2096 func_return     mmu_fixup_page_mmu_cache
2099  *      mmu_temp_map
2101  *      create a temporary mapping to enable the mmu,
2102  *      this we don't need any transparation translation tricks.
2103  */
2105 func_start      mmu_temp_map,%d0/%d1/%a0/%a1
2107         dputs   "mmu_temp_map"
2108         dputn   ARG1
2109         dputn   ARG2
2110         dputc   '\n'
2112         lea     %pc@(L(temp_mmap_mem)),%a1
2114         /* Calculate the offset in the root table
2115          */
2116         movel   ARG2,%d0
2117         moveq   #ROOT_INDEX_SHIFT,%d1
2118         lsrl    %d1,%d0
2119         mmu_get_root_table_entry        %d0
2121         /* Check if the table is temporary allocated, so we have to reuse it
2122          */
2123         movel   %a0@,%d0
2124         cmpl    %pc@(L(memory_start)),%d0
2125         jcc     1f
2127         /* Temporary allocate a ptr table and insert it into the root table
2128          */
2129         movel   %a1@,%d0
2130         addl    #PTR_TABLE_SIZE*4,%a1@
2131         orw     #_PAGE_TABLE+_PAGE_ACCESSED,%d0
2132         movel   %d0,%a0@
2133         dputs   " (new)"
2135         dputn   %d0
2136         /* Mask the root table entry for the ptr table
2137          */
2138         andw    #-ROOT_TABLE_SIZE,%d0
2139         movel   %d0,%a0
2141         /* Calculate the offset into the pointer table
2142          */
2143         movel   ARG2,%d0
2144         moveq   #PTR_INDEX_SHIFT,%d1
2145         lsrl    %d1,%d0
2146         andl    #PTR_TABLE_SIZE-1,%d0
2147         lea     %a0@(%d0*4),%a0
2148         dputn   %a0
2150         /* Check if a temporary page table is already allocated
2151          */
2152         movel   %a0@,%d0
2153         jne     1f
2155         /* Temporary allocate a page table and insert it into the ptr table
2156          */
2157         movel   %a1@,%d0
2158         addl    #PTR_TABLE_SIZE*4,%a1@
2159         orw     #_PAGE_TABLE+_PAGE_ACCESSED,%d0
2160         movel   %d0,%a0@
2161         dputs   " (new)"
2163         dputn   %d0
2164         /* Mask the ptr table entry for the page table
2165          */
2166         andw    #-PTR_TABLE_SIZE,%d0
2167         movel   %d0,%a0
2169         /* Calculate the offset into the page table
2170          */
2171         movel   ARG2,%d0
2172         moveq   #PAGE_INDEX_SHIFT,%d1
2173         lsrl    %d1,%d0
2174         andl    #PAGE_TABLE_SIZE-1,%d0
2175         lea     %a0@(%d0*4),%a0
2176         dputn   %a0
2178         /* Insert the address into the page table
2179          */
2180         movel   ARG1,%d0
2181         andw    #-PAGESIZE,%d0
2182         orw     #_PAGE_PRESENT+_PAGE_ACCESSED+_PAGE_DIRTY,%d0
2183         movel   %d0,%a0@
2184         dputn   %d0
2186         dputc   '\n'
2188 func_return     mmu_temp_map
2190 func_start      mmu_engage,%d0-%d2/%a0-%a3
2192         moveq   #ROOT_TABLE_SIZE-1,%d0
2193         /* Temporarily use a different root table.  */
2194         lea     %pc@(L(kernel_pgdir_ptr)),%a0
2195         movel   %a0@,%a2
2196         movel   %pc@(L(memory_start)),%a1
2197         movel   %a1,%a0@
2198         movel   %a2,%a0
2200         movel   %a0@+,%a1@+
2201         dbra    %d0,1b
2203         lea     %pc@(L(temp_mmap_mem)),%a0
2204         movel   %a1,%a0@
2206         movew   #PAGESIZE-1,%d0
2208         clrl    %a1@+
2209         dbra    %d0,1b
2211         lea     %pc@(1b),%a0
2212         movel   #1b,%a1
2213         /* Skip temp mappings if phys == virt */
2214         cmpl    %a0,%a1
2215         jeq     1f
2217         mmu_temp_map    %a0,%a0
2218         mmu_temp_map    %a0,%a1
2220         addw    #PAGESIZE,%a0
2221         addw    #PAGESIZE,%a1
2222         mmu_temp_map    %a0,%a0
2223         mmu_temp_map    %a0,%a1
2225         movel   %pc@(L(memory_start)),%a3
2226         movel   %pc@(L(phys_kernel_start)),%d2
2228         is_not_040_or_060(L(mmu_engage_030))
2230 L(mmu_engage_040):
2231         .chip   68040
2232         nop
2233         cinva   %bc
2234         nop
2235         pflusha
2236         nop
2237         movec   %a3,%srp
2238         movel   #TC_ENABLE+TC_PAGE4K,%d0
2239         movec   %d0,%tc         /* enable the MMU */
2240         jmp     1f:l
2241 1:      nop
2242         movec   %a2,%srp
2243         nop
2244         cinva   %bc
2245         nop
2246         pflusha
2247         .chip   68k
2248         jra     L(mmu_engage_cleanup)
2250 L(mmu_engage_030_temp):
2251         .space  12
2252 L(mmu_engage_030):
2253         .chip   68030
2254         lea     %pc@(L(mmu_engage_030_temp)),%a0
2255         movel   #0x80000002,%a0@
2256         movel   %a3,%a0@(4)
2257         movel   #0x0808,%d0
2258         movec   %d0,%cacr
2259         pmove   %a0@,%srp
2260         pflusha
2261         /*
2262          * enable,super root enable,4096 byte pages,7 bit root index,
2263          * 7 bit pointer index, 6 bit page table index.
2264          */
2265         movel   #0x82c07760,%a0@(8)
2266         pmove   %a0@(8),%tc     /* enable the MMU */
2267         jmp     1f:l
2268 1:      movel   %a2,%a0@(4)
2269         movel   #0x0808,%d0
2270         movec   %d0,%cacr
2271         pmove   %a0@,%srp
2272         pflusha
2273         .chip   68k
2275 L(mmu_engage_cleanup):
2276         subl    %d2,%a2
2277         movel   %a2,L(kernel_pgdir_ptr)
2278         subl    %d2,%fp
2279         subl    %d2,%sp
2280         subl    %d2,ARG0
2281         subl    %d2,L(memory_start)
2283 func_return     mmu_engage
2285 func_start      mmu_get_root_table_entry,%d0/%a1
2287 #if 0
2288         dputs   "mmu_get_root_table_entry:"
2289         dputn   ARG1
2290         dputs   " ="
2291 #endif
2293         movel   %pc@(L(kernel_pgdir_ptr)),%a0
2294         tstl    %a0
2295         jne     2f
2297         dputs   "\nmmu_init:"
2299         /* Find the start of free memory, get_bi_record does this for us,
2300          * as the bootinfo structure is located directly behind the kernel
2301          * and and we simply search for the last entry.
2302          */
2303         get_bi_record   BI_LAST
2304         addw    #PAGESIZE-1,%a0
2305         movel   %a0,%d0
2306         andw    #-PAGESIZE,%d0
2308         dputn   %d0
2310         lea     %pc@(L(memory_start)),%a0
2311         movel   %d0,%a0@
2312         lea     %pc@(L(kernel_end)),%a0
2313         movel   %d0,%a0@
2315         /* we have to return the first page at _stext since the init code
2316          * in mm/init.c simply expects kernel_pg_dir there, the rest of
2317          * page is used for further ptr tables in get_ptr_table.
2318          */
2319         lea     %pc@(SYMBOL_NAME(_stext)),%a0
2320         lea     %pc@(L(mmu_cached_pointer_tables)),%a1
2321         movel   %a0,%a1@
2322         addl    #ROOT_TABLE_SIZE*4,%a1@
2324         lea     %pc@(L(mmu_num_pointer_tables)),%a1
2325         addql   #1,%a1@
2327         /* clear the page
2328          */
2329         movel   %a0,%a1
2330         movew   #PAGESIZE/4-1,%d0
2332         clrl    %a1@+
2333         dbra    %d0,1b
2335         lea     %pc@(L(kernel_pgdir_ptr)),%a1
2336         movel   %a0,%a1@
2338         dputn   %a0
2339         dputc   '\n'
2341         movel   ARG1,%d0
2342         lea     %a0@(%d0*4),%a0
2344 #if 0
2345         dputn   %a0
2346         dputc   '\n'
2347 #endif
2349 func_return     mmu_get_root_table_entry
2353 func_start      mmu_get_ptr_table_entry,%d0/%a1
2355 #if 0
2356         dputs   "mmu_get_ptr_table_entry:"
2357         dputn   ARG1
2358         dputn   ARG2
2359         dputs   " ="
2360 #endif
2362         movel   ARG1,%a0
2363         movel   %a0@,%d0
2364         jne     2f
2366         /* Keep track of the number of pointer tables we use
2367          */
2368         dputs   "\nmmu_get_new_ptr_table:"
2369         lea     %pc@(L(mmu_num_pointer_tables)),%a0
2370         movel   %a0@,%d0
2371         addql   #1,%a0@
2373         /* See if there is a free pointer table in our cache of pointer tables
2374          */
2375         lea     %pc@(L(mmu_cached_pointer_tables)),%a1
2376         andw    #7,%d0
2377         jne     1f
2379         /* Get a new pointer table page from above the kernel memory
2380          */
2381         get_new_page
2382         movel   %a0,%a1@
2384         /* There is an unused pointer table in our cache... use it
2385          */
2386         movel   %a1@,%d0
2387         addl    #PTR_TABLE_SIZE*4,%a1@
2389         dputn   %d0
2390         dputc   '\n'
2392         /* Insert the new pointer table into the root table
2393          */
2394         movel   ARG1,%a0
2395         orw     #_PAGE_TABLE+_PAGE_ACCESSED,%d0
2396         movel   %d0,%a0@
2398         /* Extract the pointer table entry
2399          */
2400         andw    #-PTR_TABLE_SIZE,%d0
2401         movel   %d0,%a0
2402         movel   ARG2,%d0
2403         lea     %a0@(%d0*4),%a0
2405 #if 0
2406         dputn   %a0
2407         dputc   '\n'
2408 #endif
2410 func_return     mmu_get_ptr_table_entry
2413 func_start      mmu_get_page_table_entry,%d0/%a1
2415 #if 0
2416         dputs   "mmu_get_page_table_entry:"
2417         dputn   ARG1
2418         dputn   ARG2
2419         dputs   " ="
2420 #endif
2422         movel   ARG1,%a0
2423         movel   %a0@,%d0
2424         jne     2f
2426         /* If the page table entry doesn't exist, we allocate a complete new
2427          * page and use it as one continues big page table which can cover
2428          * 4MB of memory, nearly almost all mappings have that alignment.
2429          */
2430         get_new_page
2431         addw    #_PAGE_TABLE+_PAGE_ACCESSED,%a0
2433         /* align pointer table entry for a page of page tables
2434          */
2435         movel   ARG1,%d0
2436         andw    #-(PAGESIZE/PAGE_TABLE_SIZE),%d0
2437         movel   %d0,%a1
2439         /* Insert the page tables into the pointer entries
2440          */
2441         moveq   #PAGESIZE/PAGE_TABLE_SIZE/4-1,%d0
2443         movel   %a0,%a1@+
2444         lea     %a0@(PAGE_TABLE_SIZE*4),%a0
2445         dbra    %d0,1b
2447         /* Now we can get the initialized pointer table entry
2448          */
2449         movel   ARG1,%a0
2450         movel   %a0@,%d0
2452         /* Extract the page table entry
2453          */
2454         andw    #-PAGE_TABLE_SIZE,%d0
2455         movel   %d0,%a0
2456         movel   ARG2,%d0
2457         lea     %a0@(%d0*4),%a0
2459 #if 0
2460         dputn   %a0
2461         dputc   '\n'
2462 #endif
2464 func_return     mmu_get_page_table_entry
2467  *      get_new_page
2469  *      Return a new page from the memory start and clear it.
2470  */
2471 func_start      get_new_page,%d0/%a1
2473         dputs   "\nget_new_page:"
2475         /* allocate the page and adjust memory_start
2476          */
2477         lea     %pc@(L(memory_start)),%a0
2478         movel   %a0@,%a1
2479         addl    #PAGESIZE,%a0@
2481         /* clear the new page
2482          */
2483         movel   %a1,%a0
2484         movew   #PAGESIZE/4-1,%d0
2486         clrl    %a1@+
2487         dbra    %d0,1b
2489         dputn   %a0
2490         dputc   '\n'
2492 func_return     get_new_page
2497  * Debug output support
2498  * Atarians have a choice between the parallel port, the serial port
2499  * from the MFP or a serial port of the SCC
2500  */
2502 #ifdef CONFIG_MAC
2504 L(scc_initable_mac):
2505         .byte   9,12            /* Reset */
2506         .byte   4,0x44          /* x16, 1 stopbit, no parity */
2507         .byte   3,0xc0          /* receiver: 8 bpc */
2508         .byte   5,0xe2          /* transmitter: 8 bpc, assert dtr/rts */
2509         .byte   9,0             /* no interrupts */
2510         .byte   10,0            /* NRZ */
2511         .byte   11,0x50         /* use baud rate generator */
2512         .byte   12,10,13,0      /* 9600 baud */
2513         .byte   14,1            /* Baud rate generator enable */
2514         .byte   3,0xc1          /* enable receiver */
2515         .byte   5,0xea          /* enable transmitter */
2516         .byte   -1
2517         .even
2518 #endif
2520 #ifdef CONFIG_ATARI
2521 /* #define USE_PRINTER */
2522 /* #define USE_SCC_B */
2523 /* #define USE_SCC_A */
2524 #define USE_MFP
2526 #if defined(USE_SCC_A) || defined(USE_SCC_B)
2527 #define USE_SCC
2528 /* Initialisation table for SCC */
2529 L(scc_initable):
2530         .byte   9,12            /* Reset */
2531         .byte   4,0x44          /* x16, 1 stopbit, no parity */
2532         .byte   3,0xc0          /* receiver: 8 bpc */
2533         .byte   5,0xe2          /* transmitter: 8 bpc, assert dtr/rts */
2534         .byte   9,0             /* no interrupts */
2535         .byte   10,0            /* NRZ */
2536         .byte   11,0x50         /* use baud rate generator */
2537         .byte   12,24,13,0      /* 9600 baud */
2538         .byte   14,2,14,3       /* use master clock for BRG, enable */
2539         .byte   3,0xc1          /* enable receiver */
2540         .byte   5,0xea          /* enable transmitter */
2541         .byte   -1
2542         .even
2543 #endif
2545 #ifdef USE_PRINTER
2547 LPSG_SELECT     = 0xff8800
2548 LPSG_READ       = 0xff8800
2549 LPSG_WRITE      = 0xff8802
2550 LPSG_IO_A       = 14
2551 LPSG_IO_B       = 15
2552 LPSG_CONTROL    = 7
2553 LSTMFP_GPIP     = 0xfffa01
2554 LSTMFP_DDR      = 0xfffa05
2555 LSTMFP_IERB     = 0xfffa09
2557 #elif defined(USE_SCC_B)
2559 LSCC_CTRL       = 0xff8c85
2560 LSCC_DATA       = 0xff8c87
2562 #elif defined(USE_SCC_A)
2564 LSCC_CTRL       = 0xff8c81
2565 LSCC_DATA       = 0xff8c83
2567 /* Initialisation table for SCC */
2568 L(scc_initable):
2569         .byte   9,12            /* Reset */
2570         .byte   4,0x44          /* x16, 1 stopbit, no parity */
2571         .byte   3,0xc0          /* receiver: 8 bpc */
2572         .byte   5,0xe2          /* transmitter: 8 bpc, assert dtr/rts */
2573         .byte   9,0             /* no interrupts */
2574         .byte   10,0            /* NRZ */
2575         .byte   11,0x50         /* use baud rate generator */
2576         .byte   12,24,13,0      /* 9600 baud */
2577         .byte   14,2,14,3       /* use master clock for BRG, enable */
2578         .byte   3,0xc1          /* enable receiver */
2579         .byte   5,0xea          /* enable transmitter */
2580         .byte   -1
2581         .even
2583 #elif defined(USE_MFP)
2585 LMFP_UCR     = 0xfffa29
2586 LMFP_TDCDR   = 0xfffa1d
2587 LMFP_TDDR    = 0xfffa25
2588 LMFP_TSR     = 0xfffa2d
2589 LMFP_UDR     = 0xfffa2f
2591 #endif
2592 #endif  /* CONFIG_ATARI */
2595  * Serial port output support.
2596  */
2599  * Initialize serial port hardware for 9600/8/1
2600  */
2601 func_start      serial_init,%d0/%d1/%a0/%a1
2602         /*
2603          *      Some of the register usage that follows
2604          *      CONFIG_AMIGA
2605          *              a0 = pointer to boot info record
2606          *              d0 = boot info offset
2607          *      CONFIG_ATARI
2608          *              a0 = address of SCC
2609          *              a1 = Liobase address/address of scc_initable
2610          *              d0 = init data for serial port
2611          *      CONFIG_MAC
2612          *              a0 = address of SCC
2613          *              a1 = address of scc_initable_mac
2614          *              d0 = init data for serial port
2615          */
2617 #ifdef CONFIG_AMIGA
2618 #define SERIAL_DTR      7
2619 #define SERIAL_CNTRL    CIABBASE+C_PRA
2621         is_not_amiga(1f)
2622         lea     %pc@(L(custom)),%a0
2623         movel   #-ZTWOBASE,%a0@
2624         bclr    #SERIAL_DTR,SERIAL_CNTRL-ZTWOBASE
2625         get_bi_record   BI_AMIGA_SERPER
2626         movew   %a0@,CUSTOMBASE+C_SERPER-ZTWOBASE
2627 |       movew   #61,CUSTOMBASE+C_SERPER-ZTWOBASE
2629 #endif
2630 #ifdef CONFIG_ATARI
2631         is_not_atari(4f)
2632         movel   %pc@(L(iobase)),%a1
2633 #if defined(USE_PRINTER)
2634         bclr    #0,%a1@(LSTMFP_IERB)
2635         bclr    #0,%a1@(LSTMFP_DDR)
2636         moveb   #LPSG_CONTROL,%a1@(LPSG_SELECT)
2637         moveb   #0xff,%a1@(LPSG_WRITE)
2638         moveb   #LPSG_IO_B,%a1@(LPSG_SELECT)
2639         clrb    %a1@(LPSG_WRITE)
2640         moveb   #LPSG_IO_A,%a1@(LPSG_SELECT)
2641         moveb   %a1@(LPSG_READ),%d0
2642         bset    #5,%d0
2643         moveb   %d0,%a1@(LPSG_WRITE)
2644 #elif defined(USE_SCC)
2645         lea     %a1@(LSCC_CTRL),%a0
2646         lea     %pc@(L(scc_initable)),%a1
2647 2:      moveb   %a1@+,%d0
2648         jmi     3f
2649         moveb   %d0,%a0@
2650         moveb   %a1@+,%a0@
2651         jra     2b
2652 3:      clrb    %a0@
2653 #elif defined(USE_MFP)
2654         bclr    #1,%a1@(LMFP_TSR)
2655         moveb   #0x88,%a1@(LMFP_UCR)
2656         andb    #0x70,%a1@(LMFP_TDCDR)
2657         moveb   #2,%a1@(LMFP_TDDR)
2658         orb     #1,%a1@(LMFP_TDCDR)
2659         bset    #1,%a1@(LMFP_TSR)
2660 #endif
2661         jra     L(serial_init_done)
2663 #endif
2664 #ifdef CONFIG_MAC
2665         is_not_mac(L(serial_init_not_mac))
2666 #ifdef MAC_SERIAL_DEBUG
2667 #if !defined(MAC_USE_SCC_A) && !defined(MAC_USE_SCC_B)
2668 #define MAC_USE_SCC_B
2669 #endif
2670 #define mac_scc_cha_b_ctrl_offset       0x0
2671 #define mac_scc_cha_a_ctrl_offset       0x2
2672 #define mac_scc_cha_b_data_offset       0x4
2673 #define mac_scc_cha_a_data_offset       0x6
2675 #ifdef MAC_USE_SCC_A
2676         /* Initialize channel A */
2677         movel   %pc@(L(mac_sccbase)),%a0
2678         lea     %pc@(L(scc_initable_mac)),%a1
2679 5:      moveb   %a1@+,%d0
2680         jmi     6f
2681         moveb   %d0,%a0@(mac_scc_cha_a_ctrl_offset)
2682         moveb   %a1@+,%a0@(mac_scc_cha_a_ctrl_offset)
2683         jra     5b
2685 #endif  /* MAC_USE_SCC_A */
2687 #ifdef MAC_USE_SCC_B
2688         /* Initialize channel B */
2689 #ifndef MAC_USE_SCC_A   /* Load mac_sccbase only if needed */
2690         movel   %pc@(L(mac_sccbase)),%a0
2691 #endif  /* MAC_USE_SCC_A */
2692         lea     %pc@(L(scc_initable_mac)),%a1
2693 7:      moveb   %a1@+,%d0
2694         jmi     8f
2695         moveb   %d0,%a0@(mac_scc_cha_b_ctrl_offset)
2696         moveb   %a1@+,%a0@(mac_scc_cha_b_ctrl_offset)
2697         jra     7b
2699 #endif  /* MAC_USE_SCC_B */
2700 #endif  /* MAC_SERIAL_DEBUG */
2702         jra     L(serial_init_done)
2703 L(serial_init_not_mac):
2704 #endif  /* CONFIG_MAC */
2706 L(serial_init_done):
2707 func_return     serial_init
2710  * Output character on serial port.
2711  */
2712 func_start      serial_putc,%d0/%d1/%a0/%a1
2714         movel   ARG1,%d0
2715         cmpib   #'\n',%d0
2716         jbne    1f
2718         /* A little safe recursion is good for the soul */
2719         serial_putc     #'\r'
2722 #ifdef CONFIG_AMIGA
2723         is_not_amiga(2f)
2724         andw    #0x00ff,%d0
2725         oriw    #0x0100,%d0
2726         movel   %pc@(L(custom)),%a0
2727         movew   %d0,%a0@(CUSTOMBASE+C_SERDAT)
2728 1:      movew   %a0@(CUSTOMBASE+C_SERDATR),%d0
2729         andw    #0x2000,%d0
2730         jeq     1b
2731         jra     L(serial_putc_done)
2733 #endif
2735 #ifdef CONFIG_MAC
2736         is_not_mac(5f)
2738 #ifdef CONSOLE
2739         console_putc    %d0
2740 #endif /* CONSOLE */
2742 #ifdef MAC_SERIAL_DEBUG
2744 #ifdef MAC_USE_SCC_A
2745         movel   %pc@(L(mac_sccbase)),%a1
2746 3:      btst    #2,%a1@(mac_scc_cha_a_ctrl_offset)
2747         jeq     3b
2748         moveb   %d0,%a1@(mac_scc_cha_a_data_offset)
2749 #endif  /* MAC_USE_SCC_A */
2751 #ifdef MAC_USE_SCC_B
2752 #ifndef MAC_USE_SCC_A   /* Load mac_sccbase only if needed */
2753         movel   %pc@(L(mac_sccbase)),%a1
2754 #endif  /* MAC_USE_SCC_A */
2755 4:      btst    #2,%a1@(mac_scc_cha_b_ctrl_offset)
2756         jeq     4b
2757         moveb   %d0,%a1@(mac_scc_cha_b_data_offset)
2758 #endif  /* MAC_USE_SCC_B */
2760 #endif  /* MAC_SERIAL_DEBUG */
2762         jra     L(serial_putc_done)
2764 #endif  /* CONFIG_MAC */
2766 #ifdef CONFIG_ATARI
2767         is_not_atari(4f)
2768         movel   %pc@(L(iobase)),%a1
2769 #if defined(USE_PRINTER)
2770 3:      btst    #0,%a1@(LSTMFP_GPIP)
2771         jne     3b
2772         moveb   #LPSG_IO_B,%a1@(LPSG_SELECT)
2773         moveb   %d0,%a1@(LPSG_WRITE)
2774         moveb   #LPSG_IO_A,%a1@(LPSG_SELECT)
2775         moveb   %a1@(LPSG_READ),%d0
2776         bclr    #5,%d0
2777         moveb   %d0,%a1@(LPSG_WRITE)
2778         nop
2779         nop
2780         bset    #5,%d0
2781         moveb   %d0,%a1@(LPSG_WRITE)
2782 #elif defined(USE_SCC)
2783 3:      btst    #2,%a1@(LSCC_CTRL)
2784         jeq     3b
2785         moveb   %d0,%a1@(LSCC_DATA)
2786 #elif defined(USE_MFP)
2787 3:      btst    #7,%a1@(LMFP_TSR)
2788         jeq     3b
2789         moveb   %d0,%a1@(LMFP_UDR)
2790 #endif
2791         jra     L(serial_putc_done)
2793 #endif  /* CONFIG_ATARI */
2795 #ifdef CONFIG_MVME16x
2796         is_not_mvme16x(2f)
2797         /*
2798          * The VME 16x class has PROM support for serial output
2799          * of some kind;  the TRAP table is still valid.
2800          */
2801         moveml  %d0-%d7/%a2-%a6,%sp@-
2802         moveb   %d0,%sp@-
2803         trap    #15
2804         .word   0x0020  /* TRAP 0x020 */
2805         moveml  %sp@+,%d0-%d7/%a2-%a6
2806         jbra    L(serial_putc_done)
2808 #endif CONFIG_MVME162 | CONFIG_MVME167
2810 #ifdef CONFIG_BVME6000
2811         is_not_bvme6000(2f)
2812         /*
2813          * The BVME6000 machine has a serial port ...
2814          */
2815 1:      btst    #2,BVME_SCC_CTRL_A
2816         jeq     1b
2817         moveb   %d0,BVME_SCC_DATA_A
2818         jbra    L(serial_putc_done)
2820 #endif
2822 L(serial_putc_done):
2823 func_return     serial_putc
2826  * Output a string.
2827  */
2828 func_start      puts,%d0/%a0
2830         movel   ARG1,%a0
2831         jra     2f
2833 #ifdef CONSOLE
2834         console_putc    %d0
2835 #endif 
2836 #ifdef SERIAL_DEBUG
2837         serial_putc     %d0
2838 #endif
2839 2:      moveb   %a0@+,%d0
2840         jne     1b
2842 func_return     puts
2845  * Output number in hex notation.
2846  */
2848 func_start      putn,%d0-%d2
2850         putc    ' '
2852         movel   ARG1,%d0
2853         moveq   #7,%d1
2854 1:      roll    #4,%d0
2855         move    %d0,%d2
2856         andb    #0x0f,%d2
2857         addb    #'0',%d2
2858         cmpb    #'9',%d2
2859         jls     2f
2860         addb    #'A'-('9'+1),%d2
2862 #ifdef CONSOLE
2863         console_putc    %d2
2864 #endif 
2865 #ifdef SERIAL_DEBUG
2866         serial_putc     %d2
2867 #endif
2868         dbra    %d1,1b
2870 func_return     putn
2872 #ifdef CONFIG_MAC
2874  *      mac_serial_print
2876  *      This routine takes its parameters on the stack.  It then
2877  *      turns around and calls the internal routine.  This routine
2878  *      is used until the Linux console driver initializes itself.
2880  *      The calling parameters are:
2881  *              void mac_serial_print(const char *str);
2883  *      This routine does NOT understand variable arguments only
2884  *      simple strings!
2885  */
2886 ENTRY(mac_serial_print)
2887         moveml  %d0/%a0,%sp@-
2888 #if 1
2889         move    %sr,%sp@-
2890         ori     #0x0700,%sr
2891 #endif
2892         movel   %sp@(10),%a0            /* fetch parameter */
2893         jra     2f
2894 1:      serial_putc     %d0
2895 2:      moveb   %a0@+,%d0
2896         jne     1b
2897 #if 1
2898         move    %sp@+,%sr
2899 #endif
2900         moveml  %sp@+,%d0/%a0
2901         rts
2902 #endif /* CONFIG_MAC */
2904 #ifdef CONFIG_HP300
2905 func_start      set_leds,%d0/%a0
2906         movel   ARG1,%d0
2907         movel   %pc@(Lcustom),%a0
2908         moveb   %d0,%a0@(0x1ffff)
2909 func_return     set_leds
2910 #endif
2912 #ifdef CONSOLE
2914  *      For continuity, see the data alignment
2915  *      to which this structure is tied.
2916  */
2917 #define Lconsole_struct_cur_column      0
2918 #define Lconsole_struct_cur_row         4
2919 #define Lconsole_struct_num_columns     8
2920 #define Lconsole_struct_num_rows        12
2921 #define Lconsole_struct_left_edge       16
2922 #define Lconsole_struct_penguin_putc    20
2924 L(console_init):
2925         /*
2926          *      Some of the register usage that follows
2927          *              a0 = pointer to boot_info
2928          *              a1 = pointer to screen
2929          *              a2 = pointer to Lconsole_globals
2930          *              d3 = pixel width of screen
2931          *              d4 = pixel height of screen
2932          *              (d3,d4) ~= (x,y) of a point just below
2933          *                      and to the right of the screen
2934          *                      NOT on the screen!
2935          *              d5 = number of bytes per scan line
2936          *              d6 = number of bytes on the entire screen
2937          */
2938         moveml  %a0-%a4/%d0-%d7,%sp@-
2940         lea     %pc@(L(console_globals)),%a2
2941         lea     %pc@(L(mac_videobase)),%a0
2942         movel   %a0@,%a1
2943         lea     %pc@(L(mac_rowbytes)),%a0
2944         movel   %a0@,%d5
2945         lea     %pc@(L(mac_dimensions)),%a0
2946         movel   %a0@,%d3        /* -> low byte */
2947         movel   %d3,%d4
2948         swap    %d4             /* -> high byte */
2949         andl    #0xffff,%d3     /* d3 = screen width in pixels */
2950         andl    #0xffff,%d4     /* d4 = screen height in pixels */
2952         movel   %d5,%d6
2953         subl    #20,%d6
2954         mulul   %d4,%d6         /* scan line bytes x num scan lines */
2955         divul   #8,%d6          /* we'll clear 8 bytes at a time */
2956         subq    #1,%d6
2958 console_clear_loop:
2959         movel   #0xffffffff,%a1@+       /* Mac_black */
2960         movel   #0xffffffff,%a1@+       /* Mac_black */
2961         dbra    %d6,console_clear_loop
2963         /* Calculate font size */
2965 #if   defined(FONT_8x8)
2966         lea     %pc@(SYMBOL_NAME(font_vga_8x8)), %a0
2967 #elif defined(FONT_8x16)
2968         lea     %pc@(SYMBOL_NAME(font_vga_8x16)),%a0
2969 #elif defined(FONT_6x11)
2970         lea     %pc@(SYMBOL_NAME(font_vga_6x11)),%a0
2971 #else   /*   (FONT_8x8) default */
2972         lea     %pc@(SYMBOL_NAME(font_vga_8x8)), %a0
2973 #endif
2975         /*
2976          *      At this point we make a shift in register usage
2977          *      a1 = address of Lconsole_font pointer
2978          */
2979         lea     %pc@(L(console_font)),%a1
2980         movel   %a0,%a1@        /* store pointer to struct fbcon_font_desc in Lconsole_font */
2982         /*
2983          *      Calculate global maxs
2984          *      Note - we can use either an
2985          *      8 x 16 or 8 x 8 character font
2986          *      6 x 11 also supported
2987          */
2988                 /* ASSERT: a0 = contents of Lconsole_font */
2989         movel   %d3,%d0                 /* screen width in pixels */
2990         divul   %a0@(FBCON_FONT_DESC_WIDTH),%d0         /* d0 = max num chars per row */
2992         movel   %d4,%d1                  /* screen height in pixels */
2993         divul   %a0@(FBCON_FONT_DESC_HEIGHT),%d1         /* d1 = max num rows */
2995         movel   %d0,%a2@(Lconsole_struct_num_columns)
2996         movel   %d1,%a2@(Lconsole_struct_num_rows)
2998         /*
2999          *      Clear the current row and column
3000          */
3001         clrl    %a2@(Lconsole_struct_cur_column)
3002         clrl    %a2@(Lconsole_struct_cur_row)
3003         clrl    %a2@(Lconsole_struct_left_edge)
3005         /*
3006          * Initialization is complete
3007          */
3008         moveml  %sp@+,%a0-%a4/%d0-%d7
3009         rts
3011 L(console_put_stats):
3012         /*
3013          *      Some of the register usage that follows
3014          *              a0 = pointer to boot_info
3015          *              d7 = value of boot_info fields
3016          */
3017         moveml  %a0/%d7,%sp@-
3019         puts    "\nMacLinux\n\n"
3021 #ifdef SERIAL_DEBUG
3022         puts    " vidaddr:"
3023         putn    %pc@(L(mac_videobase))          /* video addr. */
3025         puts    "\n  _stext:"
3026         lea     %pc@(SYMBOL_NAME(_stext)),%a0
3027         putn    %a0
3029         puts    "\nbootinfo:"
3030         lea     %pc@(SYMBOL_NAME(_end)),%a0
3031         putn    %a0
3033         puts    "\ncpuid:"
3034         putn    %pc@(L(cputype))
3035         putc    '\n'
3037 #  if defined(MMU_PRINT)
3038         jbsr    mmu_print_machine_cpu_types
3039 #  endif /* MMU_PRINT */
3040 #endif /* SERIAL_DEBUG */
3042         moveml  %sp@+,%a0/%d7
3043         rts
3045 #ifdef CONSOLE_PENGUIN
3046 L(console_put_penguin):
3047         /*
3048          *      Get 'that_penguin' onto the screen in the upper right corner
3049          *      penguin is 64 x 74 pixels, align against right edge of screen
3050          */
3051         moveml  %a0-%a1/%d0-%d7,%sp@-
3053         lea     %pc@(L(mac_dimensions)),%a0
3054         movel   %a0@,%d0
3055         andil   #0xffff,%d0
3056         subil   #64,%d0         /* snug up against the right edge */
3057         clrl    %d1             /* start at the top */
3058         movel   #73,%d7
3059         lea     %pc@(SYMBOL_NAME(that_penguin)),%a1
3060 console_penguin_row:
3061         movel   #31,%d6
3062 console_penguin_pixel_pair:
3063         moveb   %a1@,%d2
3064         lsrb    #4,%d2
3065         jbsr    console_plot_pixel
3066         addq    #1,%d0
3067         moveb   %a1@+,%d2
3068         jbsr    console_plot_pixel
3069         addq    #1,%d0
3070         dbra    %d6,console_penguin_pixel_pair
3072         subil   #64,%d0
3073         addq    #1,%d1
3074         dbra    %d7,console_penguin_row
3076         moveml  %sp@+,%a0-%a1/%d0-%d7
3077         rts
3078 #endif
3080 console_scroll:
3081         moveml  %a0-%a4/%d0-%d7,%sp@-
3083         /*
3084          * Calculate source and destination addresses
3085          *      output  a1 = dest
3086          *              a2 = source
3087          */
3088         lea     %pc@(L(mac_videobase)),%a0
3089         movel   %a0@,%a1
3090         movel   %a1,%a2
3091         lea     %pc@(L(mac_rowbytes)),%a0
3092         movel   %a0@,%d5
3093         movel   %pc@(L(console_font)),%a0
3094         mulul   %a0@(FBCON_FONT_DESC_HEIGHT),%d5        /* account for # scan lines per character */
3095         addal   %d5,%a2
3097         /*
3098          * Get dimensions
3099          */
3100         lea     %pc@(L(mac_dimensions)),%a0
3101         movel   %a0@,%d3
3102         movel   %d3,%d4
3103         swap    %d4
3104         andl    #0xffff,%d3     /* d3 = screen width in pixels */
3105         andl    #0xffff,%d4     /* d4 = screen height in pixels */
3107         /*
3108          * Calculate number of bytes to move
3109          */
3110         lea     %pc@(L(mac_rowbytes)),%a0
3111         movel   %a0@,%d6
3112         movel   %pc@(L(console_font)),%a0
3113         subl    %a0@(FBCON_FONT_DESC_HEIGHT),%d4        /* we're not scrolling the top row! */
3114         mulul   %d4,%d6         /* scan line bytes x num scan lines */
3115         divul   #32,%d6         /* we'll move 8 longs at a time */
3116         subq    #1,%d6
3118 console_scroll_loop:
3119         movel   %a2@+,%a1@+
3120         movel   %a2@+,%a1@+
3121         movel   %a2@+,%a1@+
3122         movel   %a2@+,%a1@+
3123         movel   %a2@+,%a1@+
3124         movel   %a2@+,%a1@+
3125         movel   %a2@+,%a1@+
3126         movel   %a2@+,%a1@+
3127         dbra    %d6,console_scroll_loop
3129         lea     %pc@(L(mac_rowbytes)),%a0
3130         movel   %a0@,%d6
3131         movel   %pc@(L(console_font)),%a0
3132         mulul   %a0@(FBCON_FONT_DESC_HEIGHT),%d6        /* scan line bytes x font height */
3133         divul   #32,%d6                 /* we'll move 8 words at a time */
3134         subq    #1,%d6
3136         moveq   #-1,%d0
3137 console_scroll_clear_loop:
3138         movel   %d0,%a1@+
3139         movel   %d0,%a1@+
3140         movel   %d0,%a1@+
3141         movel   %d0,%a1@+
3142         movel   %d0,%a1@+
3143         movel   %d0,%a1@+
3144         movel   %d0,%a1@+
3145         movel   %d0,%a1@+
3146         dbra    %d6,console_scroll_clear_loop
3148         moveml  %sp@+,%a0-%a4/%d0-%d7
3149         rts
3152 func_start      console_putc,%a0/%a1/%d0-%d7
3154         is_not_mac(console_exit)
3156         /* Output character in d7 on console.
3157          */
3158         movel   ARG1,%d7
3159         cmpib   #'\n',%d7
3160         jbne    1f
3162         /* A little safe recursion is good for the soul */
3163         console_putc    #'\r'
3165         lea     %pc@(L(console_globals)),%a0
3167         cmpib   #10,%d7
3168         jne     console_not_lf
3169         movel   %a0@(Lconsole_struct_cur_row),%d0
3170         addil   #1,%d0
3171         movel   %d0,%a0@(Lconsole_struct_cur_row)
3172         movel   %a0@(Lconsole_struct_num_rows),%d1
3173         cmpl    %d1,%d0
3174         jcs     1f
3175         subil   #1,%d0
3176         movel   %d0,%a0@(Lconsole_struct_cur_row)
3177         jbsr    console_scroll
3179         jra     console_exit
3181 console_not_lf:
3182         cmpib   #13,%d7
3183         jne     console_not_cr
3184         clrl    %a0@(Lconsole_struct_cur_column)
3185         jra     console_exit
3187 console_not_cr:
3188         cmpib   #1,%d7
3189         jne     console_not_home
3190         clrl    %a0@(Lconsole_struct_cur_row)
3191         clrl    %a0@(Lconsole_struct_cur_column)
3192         jra     console_exit
3195  *      At this point we know that the %d7 character is going to be
3196  *      rendered on the screen.  Register usage is -
3197  *              a0 = pointer to console globals
3198  *              a1 = font data
3199  *              d0 = cursor column
3200  *              d1 = cursor row to draw the character
3201  *              d7 = character number
3202  */
3203 console_not_home:
3204         movel   %a0@(Lconsole_struct_cur_column),%d0
3205         addil   #1,%a0@(Lconsole_struct_cur_column)
3206         movel   %a0@(Lconsole_struct_num_columns),%d1
3207         cmpl    %d1,%d0
3208         jcs     1f
3209         putc    '\n'    /* recursion is OK! */
3211         movel   %a0@(Lconsole_struct_cur_row),%d1
3213         /*
3214          *      At this point we make a shift in register usage
3215          *      a0 = address of pointer to font data (fbcon_font_desc)
3216          */
3217         movel   %pc@(L(console_font)),%a0
3218         movel   %a0@(FBCON_FONT_DESC_DATA),%a1  /* Load fbcon_font_desc.data into a1 */
3219         andl    #0x000000ff,%d7
3220                 /* ASSERT: a0 = contents of Lconsole_font */
3221         mulul   %a0@(FBCON_FONT_DESC_HEIGHT),%d7        /* d7 = index into font data */
3222         addl    %d7,%a1                 /* a1 = points to char image */
3224         /*
3225          *      At this point we make a shift in register usage
3226          *      d0 = pixel coordinate, x
3227          *      d1 = pixel coordinate, y
3228          *      d2 = (bit 0) 1/0 for white/black (!) pixel on screen
3229          *      d3 = font scan line data (8 pixels)
3230          *      d6 = count down for the font's pixel width (8)
3231          *      d7 = count down for the font's pixel count in height
3232          */
3233                 /* ASSERT: a0 = contents of Lconsole_font */
3234         mulul   %a0@(FBCON_FONT_DESC_WIDTH),%d0
3235         mulul   %a0@(FBCON_FONT_DESC_HEIGHT),%d1
3236         movel   %a0@(FBCON_FONT_DESC_HEIGHT),%d7        /* Load fbcon_font_desc.height into d7 */
3237         subq    #1,%d7
3238 console_read_char_scanline:
3239         moveb   %a1@+,%d3
3241                 /* ASSERT: a0 = contents of Lconsole_font */
3242         movel   %a0@(FBCON_FONT_DESC_WIDTH),%d6 /* Load fbcon_font_desc.width into d6 */
3243         subql   #1,%d6
3245 console_do_font_scanline:
3246         lslb    #1,%d3
3247         scsb    %d2             /* convert 1 bit into a byte */
3248         jbsr    console_plot_pixel
3249         addq    #1,%d0
3250         dbra    %d6,console_do_font_scanline
3252                 /* ASSERT: a0 = contents of Lconsole_font */
3253         subl    %a0@(FBCON_FONT_DESC_WIDTH),%d0
3254         addq    #1,%d1
3255         dbra    %d7,console_read_char_scanline
3257 console_exit:
3259 func_return     console_putc
3261 console_plot_pixel:
3262         /*
3263          *      Input:
3264          *              d0 = x coordinate
3265          *              d1 = y coordinate
3266          *              d2 = (bit 0) 1/0 for white/black (!)
3267          *      All registers are preserved
3268          */
3269         moveml  %a0-%a1/%d0-%d4,%sp@-
3271         lea     %pc@(L(mac_videobase)),%a0
3272         movel   %a0@,%a1
3273         lea     %pc@(L(mac_videodepth)),%a0
3274         movel   %a0@,%d3
3275         lea     %pc@(L(mac_rowbytes)),%a0
3276         mulul   %a0@,%d1
3278         /*
3279          *      Register usage:
3280          *              d0 = x coord becomes byte offset into frame buffer
3281          *              d1 = y coord
3282          *              d2 = black or white (0/1)
3283          *              d3 = video depth
3284          *              d4 = temp of x (d0) for many bit depths
3285          *              d5 = unused
3286          *              d6 = unused
3287          *              d7 = unused
3288          */
3289 test_1bit:
3290         cmpb    #1,%d3
3291         jbne    test_2bit
3292         movel   %d0,%d4         /* we need the low order 3 bits! */
3293         divul   #8,%d0
3294         addal   %d0,%a1
3295         addal   %d1,%a1
3296         andb    #7,%d4
3297         eorb    #7,%d4          /* reverse the x-coordinate w/ screen-bit # */
3298         andb    #1,%d2
3299         jbne    white_1
3300         bsetb   %d4,%a1@
3301         jbra    console_plot_pixel_exit
3302 white_1:
3303         bclrb   %d4,%a1@
3304         jbra    console_plot_pixel_exit
3306 test_2bit:
3307         cmpb    #2,%d3
3308         jbne    test_4bit
3309         movel   %d0,%d4         /* we need the low order 2 bits! */
3310         divul   #4,%d0
3311         addal   %d0,%a1
3312         addal   %d1,%a1
3313         andb    #3,%d4
3314         eorb    #3,%d4          /* reverse the x-coordinate w/ screen-bit # */
3315         lsll    #1,%d4          /* ! */
3316         andb    #1,%d2
3317         jbne    white_2
3318         bsetb   %d4,%a1@
3319         addq    #1,%d4
3320         bsetb   %d4,%a1@
3321         jbra    console_plot_pixel_exit
3322 white_2:
3323         bclrb   %d4,%a1@
3324         addq    #1,%d4
3325         bclrb   %d4,%a1@
3326         jbra    console_plot_pixel_exit
3328 test_4bit:
3329         cmpb    #4,%d3
3330         jbne    test_8bit
3331         movel   %d0,%d4         /* we need the low order bit! */
3332         divul   #2,%d0
3333         addal   %d0,%a1
3334         addal   %d1,%a1
3335         andb    #1,%d4
3336         eorb    #1,%d4
3337         lsll    #2,%d4          /* ! */
3338         andb    #1,%d2
3339         jbne    white_4
3340         bsetb   %d4,%a1@
3341         addq    #1,%d4
3342         bsetb   %d4,%a1@
3343         addq    #1,%d4
3344         bsetb   %d4,%a1@
3345         addq    #1,%d4
3346         bsetb   %d4,%a1@
3347         jbra    console_plot_pixel_exit
3348 white_4:
3349         bclrb   %d4,%a1@
3350         addq    #1,%d4
3351         bclrb   %d4,%a1@
3352         addq    #1,%d4
3353         bclrb   %d4,%a1@
3354         addq    #1,%d4
3355         bclrb   %d4,%a1@
3356         jbra    console_plot_pixel_exit
3358 test_8bit:
3359         cmpb    #8,%d3
3360         jbne    test_16bit
3361         addal   %d0,%a1
3362         addal   %d1,%a1
3363         andb    #1,%d2
3364         jbne    white_8
3365         moveb   #0xff,%a1@
3366         jbra    console_plot_pixel_exit
3367 white_8:
3368         clrb    %a1@
3369         jbra    console_plot_pixel_exit
3371 test_16bit:
3372         cmpb    #16,%d3
3373         jbne    console_plot_pixel_exit
3374         addal   %d0,%a1
3375         addal   %d0,%a1
3376         addal   %d1,%a1
3377         andb    #1,%d2
3378         jbne    white_16
3379         clrw    %a1@
3380         jbra    console_plot_pixel_exit
3381 white_16:
3382         movew   #0x0fff,%a1@
3383         jbra    console_plot_pixel_exit
3385 console_plot_pixel_exit:
3386         moveml  %sp@+,%a0-%a1/%d0-%d4
3387         rts
3388 #endif /* CONSOLE */
3390 #if 0
3392  * This is some old code lying around.  I don't believe
3393  * it's used or important anymore.  My guess is it contributed
3394  * to getting to this point, but it's done for now.
3395  * It was still in the 2.1.77 head.S, so it's still here.
3396  * (And still not used!)
3397  */
3398 L(showtest):
3399         moveml  %a0/%d7,%sp@-
3400         puts    "A="
3401         putn    %a1
3403         .long   0xf0119f15              | ptestr        #5,%a1@,#7,%a0
3405         puts    "DA="
3406         putn    %a0
3408         puts    "D="
3409         putn    %a0@
3411         puts    "S="
3412         lea     %pc@(L(mmu)),%a0
3413         .long   0xf0106200              | pmove         %psr,%a0@
3414         clrl    %d7
3415         movew   %a0@,%d7
3416         putn    %d7
3418         putc    '\n'
3419         moveml  %sp@+,%a0/%d7
3420         rts
3421 #endif  /* 0 */
3423 __INITDATA
3424         .align  4
3426 #if defined(CONFIG_ATARI) || defined(CONFIG_AMIGA) || defined(CONFIG_HP300)
3427 L(custom):
3428 L(iobase):
3429         .long 0
3430 #endif
3432 #ifdef CONFIG_MAC
3433 L(console_video_virtual):
3434         .long   0
3435 #endif  /* CONFIG_MAC */
3437 #if defined(CONSOLE)
3438 L(console_globals):
3439         .long   0               /* cursor column */
3440         .long   0               /* cursor row */
3441         .long   0               /* max num columns */
3442         .long   0               /* max num rows */
3443         .long   0               /* left edge */
3444         .long   0               /* mac putc */
3445 L(console_font):
3446         .long   0               /* pointer to console font (struct fbcon_font_desc) */
3447 #endif /* CONSOLE */
3449 #if defined(MMU_PRINT)
3450 L(mmu_print_data):
3451         .long   0               /* valid flag */
3452         .long   0               /* start logical */
3453         .long   0               /* next logical */
3454         .long   0               /* start physical */
3455         .long   0               /* next physical */
3456 #endif /* MMU_PRINT */
3458 L(cputype):
3459         .long   0
3460 L(mmu_cached_pointer_tables):
3461         .long   0
3462 L(mmu_num_pointer_tables):
3463         .long   0
3464 L(phys_kernel_start):
3465         .long   0
3466 L(kernel_end):
3467         .long   0
3468 L(memory_start):
3469         .long   0
3470 L(kernel_pgdir_ptr):
3471         .long   0
3472 L(temp_mmap_mem):
3473         .long   0
3476 #if defined (CONFIG_BVME6000)
3477 BVME_SCC_CTRL_A = 0xffb0000b
3478 BVME_SCC_DATA_A = 0xffb0000f
3479 #endif
3481 #if defined(CONFIG_MAC)
3482 L(mac_booter_data):
3483         .long   0
3484 L(mac_videobase):
3485         .long   0
3486 L(mac_videodepth):
3487         .long   0
3488 L(mac_dimensions):
3489         .long   0
3490 L(mac_rowbytes):
3491         .long   0
3492 #ifdef MAC_SERIAL_DEBUG
3493 L(mac_sccbase):
3494         .long   0
3495 #endif /* MAC_SERIAL_DEBUG */
3496 #endif
3498 __FINIT
3499         .data
3500         .align  4
3502 SYMBOL_NAME_LABEL(availmem)
3503         .long   0
3504 SYMBOL_NAME_LABEL(m68k_pgtable_cachemode)
3505         .long   0
3506 SYMBOL_NAME_LABEL(m68k_supervisor_cachemode)
3507         .long   0
3508 #if defined(CONFIG_MVME16x)
3509 SYMBOL_NAME_LABEL(mvme_bdid_ptr)
3510         .long   0
3511 #endif