3 ** head.S -- This file contains the initial boot code for the
6 ** Copyright 1993 by Hamish Macdonald
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
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 font_desc structures
26 ** 1999/02/11 Richard Zidlicky: added Q40 support (initial version 99/01/01)
27 ** 2004/05/13 Kars de Jong: Finalised HP300 support
29 ** This file is subject to the terms and conditions of the GNU General Public
30 ** License. See the file README.legal in the main directory of this archive
38 * At this point, the boot loader has:
41 * Put us in supervisor state.
43 * The kernel setup code takes the following steps:
44 * . Raise interrupt level
45 * . Set up initial kernel memory mapping.
46 * . This sets up a mapping of the 4M of memory the kernel is located in.
47 * . It also does a mapping of any initial machine specific areas.
49 * . Enable cache memories
50 * . Jump to kernel startup
52 * Much of the file restructuring was to accomplish:
53 * 1) Remove register dependency through-out the file.
54 * 2) Increase use of subroutines to perform functions
55 * 3) Increase readability of the code
57 * Of course, readability is a subjective issue, so it will never be
58 * argued that that goal was accomplished. It was merely a goal.
59 * A key way to help make code more readable is to give good
60 * documentation. So, the first thing you will find is exhaustive
61 * write-ups on the structure of the file, and the features of the
62 * functional subroutines.
66 * Without a doubt the single largest chunk of head.S is spent
67 * mapping the kernel and I/O physical space into the logical range
69 * There are new subroutines and data structures to make MMU
70 * support cleaner and easier to understand.
71 * First, you will find a routine call "mmu_map" which maps
72 * a logical to a physical region for some length given a cache
73 * type on behalf of the caller. This routine makes writing the
74 * actual per-machine specific code very simple.
75 * A central part of the code, but not a subroutine in itself,
76 * is the mmu_init code which is broken down into mapping the kernel
77 * (the same for all machines) and mapping machine-specific I/O
79 * Also, there will be a description of engaging the MMU and
81 * You will notice that there is a chunk of code which
82 * can emit the entire MMU mapping of the machine. This is present
83 * only in debug modes and can be very helpful.
84 * Further, there is a new console driver in head.S that is
85 * also only engaged in debug mode. Currently, it's only supported
86 * on the Macintosh class of machines. However, it is hoped that
87 * others will plug-in support for specific machines.
89 * ######################################################################
93 * mmu_map was written for two key reasons. First, it was clear
94 * that it was very difficult to read the previous code for mapping
95 * regions of memory. Second, the Macintosh required such extensive
96 * memory allocations that it didn't make sense to propagate the
97 * existing code any further.
98 * mmu_map requires some parameters:
100 * mmu_map (logical, physical, length, cache_type)
102 * While this essentially describes the function in the abstract, you'll
103 * find more indepth description of other parameters at the implementation site.
105 * mmu_get_root_table_entry
106 * ------------------------
107 * mmu_get_ptr_table_entry
108 * -----------------------
109 * mmu_get_page_table_entry
110 * ------------------------
112 * These routines are used by other mmu routines to get a pointer into
113 * a table, if necessary a new table is allocated. These routines are working
114 * basically like pmd_alloc() and pte_alloc() in <asm/pgtable.h>. The root
115 * table needs of course only to be allocated once in mmu_get_root_table_entry,
116 * so that here also some mmu specific initialization is done. The second page
117 * at the start of the kernel (the first page is unmapped later) is used for
118 * the kernel_pg_dir. It must be at a position known at link time (as it's used
119 * to initialize the init task struct) and since it needs special cache
120 * settings, it's the easiest to use this page, the rest of the page is used
121 * for further pointer tables.
122 * mmu_get_page_table_entry allocates always a whole page for page tables, this
123 * means 1024 pages and so 4MB of memory can be mapped. It doesn't make sense
124 * to manage page tables in smaller pieces as nearly all mappings have that
127 * ######################################################################
130 * ######################################################################
134 * Thanks to a small helping routine enabling the mmu got quite simple
135 * and there is only one way left. mmu_engage makes a complete a new mapping
136 * that only includes the absolute necessary to be able to jump to the final
137 * position and to restore the original mapping.
138 * As this code doesn't need a transparent translation register anymore this
139 * means all registers are free to be used by machines that needs them for
142 * ######################################################################
146 * This algorithm will print out the page tables of the system as
147 * appropriate for an 030 or an 040. This is useful for debugging purposes
148 * and as such is enclosed in #ifdef MMU_PRINT/#endif clauses.
150 * ######################################################################
154 * The console is also able to be turned off. The console in head.S
155 * is specifically for debugging and can be very useful. It is surrounded by
156 * #ifdef / #endif clauses so it doesn't have to ship in known-good
157 * kernels. It's basic algorithm is to determine the size of the screen
158 * (in height/width and bit depth) and then use that information for
159 * displaying an 8x8 font or an 8x16 (widthxheight). I prefer the 8x8 for
160 * debugging so I can see more good data. But it was trivial to add support
161 * for both fonts, so I included it.
162 * Also, the algorithm for plotting pixels is abstracted so that in
163 * theory other platforms could add support for different kinds of frame
164 * buffers. This could be very useful.
166 * console_put_penguin
167 * -------------------
168 * An important part of any Linux bring up is the penguin and there's
169 * nothing like getting the Penguin on the screen! This algorithm will work
170 * on any machine for which there is a console_plot_pixel.
174 * My hope is that the scroll algorithm does the right thing on the
175 * various platforms, but it wouldn't be hard to add the test conditions
176 * and new code if it doesn't.
181 * ######################################################################
183 * Register usage has greatly simplified within head.S. Every subroutine
184 * saves and restores all registers that it modifies (except it returns a
185 * value in there of course). So the only register that needs to be initialized
186 * is the stack pointer.
187 * All other init code and data is now placed in the init section, so it will
188 * be automatically freed at the end of the kernel initialization.
190 * ######################################################################
194 * There are many options available in a build of this file. I've
195 * taken the time to describe them here to save you the time of searching
196 * for them and trying to understand what they mean.
198 * CONFIG_xxx: These are the obvious machine configuration defines created
199 * during configuration. These are defined in autoconf.h.
201 * CONSOLE_DEBUG: Only supports a Mac frame buffer but could easily be
202 * extended to support other platforms.
204 * TEST_MMU: This is a test harness for running on any given machine but
205 * getting an MMU dump for another class of machine. The classes of machines
206 * that can be tested are any of the makes (Atari, Amiga, Mac, VME, etc.)
207 * and any of the models (030, 040, 060, etc.).
209 * NOTE: TEST_MMU is NOT permanent! It is scheduled to be removed
210 * When head.S boots on Atari, Amiga, Macintosh, and VME
211 * machines. At that point the underlying logic will be
212 * believed to be solid enough to be trusted, and TEST_MMU
213 * can be dropped. Do note that that will clean up the
214 * head.S code significantly as large blocks of #if/#else
215 * clauses can be removed.
217 * MMU_NOCACHE_KERNEL: On the Macintosh platform there was an inquiry into
218 * determing why devices don't appear to work. A test case was to remove
219 * the cacheability of the kernel bits.
221 * MMU_PRINT: There is a routine built into head.S that can display the
222 * MMU data structures. It outputs its result through the serial_putc
223 * interface. So where ever that winds up driving data, that's where the
224 * mmu struct will appear.
226 * SERIAL_DEBUG: There are a series of putc() macro statements
227 * scattered through out the code to give progress of status to the
228 * person sitting at the console. This constant determines whether those
231 * DEBUG: This is the standard DEBUG flag that can be set for building
232 * the kernel. It has the effect adding additional tests into
238 * In theory these could be determined at run time or handed
239 * over by the booter. But, let's be real, it's a fine hard
240 * coded value. (But, you will notice the code is run-time
241 * flexible!) A pointer to the font's struct font_desc
242 * is kept locally in Lconsole_font. It is used to determine
243 * font size information dynamically.
246 * USE_PRINTER: Use the printer port for serial debug.
247 * USE_SCC_B: Use the SCC port A (Serial2) for serial debug.
248 * USE_SCC_A: Use the SCC port B (Modem2) for serial debug.
249 * USE_MFP: Use the ST-MFP port (Modem1) for serial debug.
251 * Macintosh constants:
252 * MAC_USE_SCC_A: Use SCC port A (modem) for serial debug.
253 * MAC_USE_SCC_B: Use SCC port B (printer) for serial debug.
256 #include <linux/linkage.h>
257 #include <linux/init.h>
258 #include <linux/pgtable.h>
259 #include <asm/bootinfo.h>
260 #include <asm/bootinfo-amiga.h>
261 #include <asm/bootinfo-atari.h>
262 #include <asm/bootinfo-hp300.h>
263 #include <asm/bootinfo-mac.h>
264 #include <asm/bootinfo-q40.h>
265 #include <asm/bootinfo-vme.h>
266 #include <asm/setup.h>
267 #include <asm/entry.h>
268 #include <asm/page.h>
269 #include <asm/asm-offsets.h>
271 # include <asm/machw.h>
274 #ifdef CONFIG_EARLY_PRINTK
275 # define SERIAL_DEBUG
276 # if defined(CONFIG_MAC) && defined(CONFIG_FONT_SUPPORT)
277 # define CONSOLE_DEBUG
282 #undef MMU_NOCACHE_KERNEL
286 * For the head.S console, there are three supported fonts, 6x11, 8x16 and 8x8.
287 * The 8x8 font is harder to read but fits more on the screen.
289 #define FONT_8x8 /* default */
290 /* #define FONT_8x16 */ /* 2nd choice */
291 /* #define FONT_6x11 */ /* 3rd choice */
295 .globl m68k_init_mapped_size
296 .globl m68k_pgtable_cachemode
297 .globl m68k_supervisor_cachemode
298 #ifdef CONFIG_MVME16x
305 CPUTYPE_040 = 1 /* indicates an 040 */
306 CPUTYPE_060 = 2 /* indicates an 060 */
307 CPUTYPE_0460 = 3 /* if either above are set, this is set */
308 CPUTYPE_020 = 4 /* indicates an 020 */
310 /* Translation control register */
315 /* Transparent translation registers */
316 TTR_ENABLE = 0x8000 /* enable transparent translation */
317 TTR_ANYMODE = 0x4000 /* user and kernel mode access */
318 TTR_KERNELMODE = 0x2000 /* only kernel mode access */
319 TTR_USERMODE = 0x0000 /* only user mode access */
320 TTR_CI = 0x0400 /* inhibit cache */
321 TTR_RW = 0x0200 /* read/write mode */
322 TTR_RWM = 0x0100 /* read/write mask */
323 TTR_FCB2 = 0x0040 /* function code base bit 2 */
324 TTR_FCB1 = 0x0020 /* function code base bit 1 */
325 TTR_FCB0 = 0x0010 /* function code base bit 0 */
326 TTR_FCM2 = 0x0004 /* function code mask bit 2 */
327 TTR_FCM1 = 0x0002 /* function code mask bit 1 */
328 TTR_FCM0 = 0x0001 /* function code mask bit 0 */
330 /* Cache Control registers */
331 CC6_ENABLE_D = 0x80000000 /* enable data cache (680[46]0) */
332 CC6_FREEZE_D = 0x40000000 /* freeze data cache (68060) */
333 CC6_ENABLE_SB = 0x20000000 /* enable store buffer (68060) */
334 CC6_PUSH_DPI = 0x10000000 /* disable CPUSH invalidation (68060) */
335 CC6_HALF_D = 0x08000000 /* half-cache mode for data cache (68060) */
336 CC6_ENABLE_B = 0x00800000 /* enable branch cache (68060) */
337 CC6_CLRA_B = 0x00400000 /* clear all entries in branch cache (68060) */
338 CC6_CLRU_B = 0x00200000 /* clear user entries in branch cache (68060) */
339 CC6_ENABLE_I = 0x00008000 /* enable instruction cache (680[46]0) */
340 CC6_FREEZE_I = 0x00004000 /* freeze instruction cache (68060) */
341 CC6_HALF_I = 0x00002000 /* half-cache mode for instruction cache (68060) */
342 CC3_ALLOC_WRITE = 0x00002000 /* write allocate mode(68030) */
343 CC3_ENABLE_DB = 0x00001000 /* enable data burst (68030) */
344 CC3_CLR_D = 0x00000800 /* clear data cache (68030) */
345 CC3_CLRE_D = 0x00000400 /* clear entry in data cache (68030) */
346 CC3_FREEZE_D = 0x00000200 /* freeze data cache (68030) */
347 CC3_ENABLE_D = 0x00000100 /* enable data cache (68030) */
348 CC3_ENABLE_IB = 0x00000010 /* enable instruction burst (68030) */
349 CC3_CLR_I = 0x00000008 /* clear instruction cache (68030) */
350 CC3_CLRE_I = 0x00000004 /* clear entry in instruction cache (68030) */
351 CC3_FREEZE_I = 0x00000002 /* freeze instruction cache (68030) */
352 CC3_ENABLE_I = 0x00000001 /* enable instruction cache (68030) */
354 /* Miscellaneous definitions */
358 ROOT_TABLE_SIZE = 128
361 ROOT_INDEX_SHIFT = 25
363 PAGE_INDEX_SHIFT = 12
366 /* When debugging use readable names for labels */
368 #define L(name) .head.S.##name
370 #define L(name) .head.S./**/name
374 #define L(name) .L##name
376 #define L(name) .L/**/name
380 /* The __INITDATA stuff is a no-op when ftrace or kgdb are turned on */
382 #define __INITDATA .data
383 #define __FINIT .previous
386 /* Several macros to make the writing of subroutines easier:
387 * - func_start marks the beginning of the routine which setups the frame
388 * register and saves the registers, it also defines another macro
389 * to automatically restore the registers again.
390 * - func_return marks the end of the routine and simply calls the prepared
391 * macro to restore registers and jump back to the caller.
392 * - func_define generates another macro to automatically put arguments
393 * onto the stack call the subroutine and cleanup the stack again.
396 /* Within subroutines these macros can be used to access the arguments
397 * on the stack. With STACK some allocated memory on the stack can be
398 * accessed and ARG0 points to the return address (used by mmu_engage).
400 #define STACK %a6@(stackstart)
403 #define ARG2 %a6@(12)
404 #define ARG3 %a6@(16)
405 #define ARG4 %a6@(20)
407 .macro func_start name,saveregs,stack=0
410 moveml \saveregs,%sp@-
411 .set stackstart,-\stack
413 .macro func_return_\name
414 moveml %sp@+,\saveregs
420 .macro func_return name
424 .macro func_call name
428 .macro move_stack nr,arg1,arg2,arg3,arg4
430 move_stack "(\nr-1)",\arg2,\arg3,\arg4
435 .macro func_define name,nr=0
436 .macro \name arg1,arg2,arg3,arg4
437 move_stack \nr,\arg1,\arg2,\arg3,\arg4
445 func_define mmu_map,4
446 func_define mmu_map_tt,4
447 func_define mmu_fixup_page_mmu_cache,1
448 func_define mmu_temp_map,2
449 func_define mmu_engage
450 func_define mmu_get_root_table_entry,1
451 func_define mmu_get_ptr_table_entry,2
452 func_define mmu_get_page_table_entry,2
453 func_define mmu_print
454 func_define get_new_page
455 #if defined(CONFIG_HP300) || defined(CONFIG_APOLLO)
459 .macro mmu_map_eq arg1,arg2,arg3
460 mmu_map \arg1,\arg1,\arg2,\arg3
463 .macro get_bi_record record
465 func_call get_bi_record
469 func_define serial_putc,1
470 func_define console_putc,1
472 func_define console_init
473 func_define console_put_penguin
474 func_define console_plot_pixel,3
475 func_define console_scroll
478 #if defined(CONSOLE_DEBUG) || defined(SERIAL_DEBUG)
482 func_call console_putc
485 func_call serial_putc
487 #if defined(CONSOLE_DEBUG) || defined(SERIAL_DEBUG)
507 #if defined(CONSOLE_DEBUG) || defined(SERIAL_DEBUG)
524 #define is_not_amiga(lab) cmpl &MACH_AMIGA,%pc@(m68k_machtype); jne lab
525 #define is_not_atari(lab) cmpl &MACH_ATARI,%pc@(m68k_machtype); jne lab
526 #define is_not_mac(lab) cmpl &MACH_MAC,%pc@(m68k_machtype); jne lab
527 #define is_not_mvme147(lab) cmpl &MACH_MVME147,%pc@(m68k_machtype); jne lab
528 #define is_not_mvme16x(lab) cmpl &MACH_MVME16x,%pc@(m68k_machtype); jne lab
529 #define is_not_bvme6000(lab) cmpl &MACH_BVME6000,%pc@(m68k_machtype); jne lab
530 #define is_mvme147(lab) cmpl &MACH_MVME147,%pc@(m68k_machtype); jeq lab
531 #define is_mvme16x(lab) cmpl &MACH_MVME16x,%pc@(m68k_machtype); jeq lab
532 #define is_bvme6000(lab) cmpl &MACH_BVME6000,%pc@(m68k_machtype); jeq lab
533 #define is_not_hp300(lab) cmpl &MACH_HP300,%pc@(m68k_machtype); jne lab
534 #define is_not_apollo(lab) cmpl &MACH_APOLLO,%pc@(m68k_machtype); jne lab
535 #define is_not_q40(lab) cmpl &MACH_Q40,%pc@(m68k_machtype); jne lab
536 #define is_not_sun3x(lab) cmpl &MACH_SUN3X,%pc@(m68k_machtype); jne lab
538 #define hasnt_leds(lab) cmpl &MACH_HP300,%pc@(m68k_machtype); \
540 cmpl &MACH_APOLLO,%pc@(m68k_machtype); \
544 #define is_040_or_060(lab) btst &CPUTYPE_0460,%pc@(L(cputype)+3); jne lab
545 #define is_not_040_or_060(lab) btst &CPUTYPE_0460,%pc@(L(cputype)+3); jeq lab
546 #define is_040(lab) btst &CPUTYPE_040,%pc@(L(cputype)+3); jne lab
547 #define is_060(lab) btst &CPUTYPE_060,%pc@(L(cputype)+3); jne lab
548 #define is_not_060(lab) btst &CPUTYPE_060,%pc@(L(cputype)+3); jeq lab
549 #define is_020(lab) btst &CPUTYPE_020,%pc@(L(cputype)+3); jne lab
550 #define is_not_020(lab) btst &CPUTYPE_020,%pc@(L(cputype)+3); jeq lab
552 /* On the HP300 we use the on-board LEDs for debug output before
553 the console is running. Writing a 1 bit turns the corresponding LED
554 _off_ - on the 340 bit 7 is towards the back panel of the machine. */
556 #if defined(CONFIG_HP300) || defined(CONFIG_APOLLO)
568 * Version numbers of the bootinfo interface
569 * The area from _stext to _start will later be used as kernel pointer table
571 bras 1f /* Jump over bootinfo version numbers */
573 .long BOOTINFOV_MAGIC
574 .long MACH_AMIGA, AMIGA_BOOTI_VERSION
575 .long MACH_ATARI, ATARI_BOOTI_VERSION
576 .long MACH_MVME147, MVME147_BOOTI_VERSION
577 .long MACH_MVME16x, MVME16x_BOOTI_VERSION
578 .long MACH_BVME6000, BVME6000_BOOTI_VERSION
579 .long MACH_MAC, MAC_BOOTI_VERSION
580 .long MACH_Q40, Q40_BOOTI_VERSION
581 .long MACH_HP300, HP300_BOOTI_VERSION
585 .equ kernel_pg_dir,_stext
587 .equ .,_stext+PAGESIZE
594 * Setup initial stack pointer
599 * Record the CPU and machine type.
601 get_bi_record BI_MACHTYPE
602 lea %pc@(m68k_machtype),%a1
605 get_bi_record BI_FPUTYPE
606 lea %pc@(m68k_fputype),%a1
609 get_bi_record BI_MMUTYPE
610 lea %pc@(m68k_mmutype),%a1
613 get_bi_record BI_CPUTYPE
614 lea %pc@(m68k_cputype),%a1
621 * For Macintosh, we need to determine the display parameters early (at least
622 * while debugging it).
625 is_not_mac(L(test_notmac))
627 get_bi_record BI_MAC_VADDR
628 lea %pc@(L(mac_videobase)),%a1
631 get_bi_record BI_MAC_VDEPTH
632 lea %pc@(L(mac_videodepth)),%a1
635 get_bi_record BI_MAC_VDIM
636 lea %pc@(L(mac_dimensions)),%a1
639 get_bi_record BI_MAC_VROW
640 lea %pc@(L(mac_rowbytes)),%a1
643 get_bi_record BI_MAC_SCCBASE
644 lea %pc@(L(mac_sccbase)),%a1
648 #endif /* CONFIG_MAC */
652 * There are ultimately two pieces of information we want for all kinds of
653 * processors CpuType and CacheBits. The CPUTYPE was passed in from booter
654 * and is converted here from a booter type definition to a separate bit
655 * number which allows for the standard is_0x0 macro tests.
657 movel %pc@(m68k_cputype),%d0
664 * Test the BootInfo cputype for 060
668 bset #CPUTYPE_060,%d1
669 bset #CPUTYPE_0460,%d1
673 * Test the BootInfo cputype for 040
677 bset #CPUTYPE_040,%d1
678 bset #CPUTYPE_0460,%d1
682 * Test the BootInfo cputype for 020
686 bset #CPUTYPE_020,%d1
690 * Record the cpu type
692 lea %pc@(L(cputype)),%a0
698 * Now the macros are valid:
707 * Determine the cache mode for pages holding MMU tables
708 * and for supervisor mode, unused for '020 and '030
713 is_not_040_or_060(L(save_cachetype))
717 * d1 := cacheable write-through
718 * NOTE: The 68040 manual strongly recommends non-cached for MMU tables,
719 * but we have been using write-through since at least 2.0.29 so I
722 #ifdef CONFIG_060_WRITETHROUGH
724 * If this is a 68060 board using drivers with cache coherency
725 * problems, then supervisor memory accesses need to be write-through
726 * also; otherwise, we want copyback.
730 movel #_PAGE_CACHE040W,%d0
731 jra L(save_cachetype)
732 #endif /* CONFIG_060_WRITETHROUGH */
734 movew #_PAGE_CACHE040,%d0
736 movel #_PAGE_CACHE040W,%d1
739 /* Save cache mode for supervisor mode and page tables
741 lea %pc@(m68k_supervisor_cachemode),%a0
743 lea %pc@(m68k_pgtable_cachemode),%a0
747 * raise interrupt level
752 If running on an Atari, determine the I/O base of the
753 serial port and test if we are running on a Medusa or Hades.
754 This test is necessary here, because on the Hades the serial
755 port is only accessible in the high I/O memory area.
757 The test whether it is a Medusa is done by writing to the byte at
758 phys. 0x0. This should result in a bus error on all other machines.
760 ...should, but doesn't. The Afterburner040 for the Falcon has the
761 same behaviour (0x0..0x7 are no ROM shadow). So we have to do
762 another test to distinguish Medusa and AB040. This is a
763 read attempt for 0x00ff82fe phys. that should bus error on a Falcon
764 (+AB040), but is in the range where the Medusa always asserts DTACK.
766 The test for the Hades is done by reading address 0xb0000000. This
767 should give a bus error on the Medusa.
771 is_not_atari(L(notypetest))
773 /* get special machine type (Medusa/Hades/AB40) */
774 moveq #0,%d3 /* default if tag doesn't exist */
775 get_bi_record BI_ATARI_MCH_TYPE
779 lea %pc@(atari_mch_type),%a0
782 /* On the Hades, the iobase must be set up before opening the
783 * serial port. There are no I/O regs at 0x00ffxxxx at all. */
785 cmpl #ATARI_MACH_HADES,%d3
787 movel #0xff000000,%d0 /* Hades I/O base addr: 0xff000000 */
788 1: lea %pc@(L(iobase)),%a0
795 is_mvme147(L(getvmetype))
796 is_bvme6000(L(getvmetype))
797 is_not_mvme16x(L(gvtdone))
799 /* See if the loader has specified the BI_VME_TYPE tag. Recent
800 * versions of VMELILO and TFTPLILO do this. We have to do this
801 * early so we know how to handle console output. If the tag
802 * doesn't exist then we use the Bug for output on MVME16x.
805 get_bi_record BI_VME_TYPE
809 lea %pc@(vme_brdtype),%a0
812 #ifdef CONFIG_MVME16x
813 is_not_mvme16x(L(gvtdone))
815 /* Need to get the BRD_ID info to differentiate between 162, 167,
816 * etc. This is available as a BI_VME_BRDINFO tag with later
817 * versions of VMELILO and TFTPLILO, otherwise we call the Bug.
819 get_bi_record BI_VME_BRDINFO
823 /* Get pointer to board ID data from Bug */
826 .word 0x70 /* trap 0x70 - .BRD_ID */
829 lea %pc@(mvme_bdid),%a1
830 /* Structure is 32 bytes long */
846 is_not_hp300(L(nothp))
848 /* Get the address of the UART for serial debugging */
849 get_bi_record BI_HP300_UART_ADDR
853 lea %pc@(L(uartbase)),%a0
855 get_bi_record BI_HP300_UART_SCODE
859 lea %pc@(L(uart_scode)),%a0
866 * Initialize serial port
875 # ifdef CONSOLE_DEBUG
879 # endif /* CONFIG_LOGO */
880 # endif /* CONSOLE_DEBUG */
882 #endif /* CONFIG_MAC */
888 dputn %pc@(L(cputype))
889 dputn %pc@(m68k_supervisor_cachemode)
890 dputn %pc@(m68k_pgtable_cachemode)
894 * Save physical start address of kernel
896 lea %pc@(L(phys_kernel_start)),%a0
899 addl #PAGE_OFFSET,%a1
909 * This block of code does what's necessary to map in the various kinds
910 * of machines for execution of Linux.
911 * First map the first 4, 8, or 16 MB of kernel code & data
914 get_bi_record BI_MEMCHUNK
916 movel #16*1024*1024,%d1
924 lea %pc@(m68k_init_mapped_size),%a0
926 mmu_map #PAGE_OFFSET,%pc@(L(phys_kernel_start)),%d1,\
927 %pc@(m68k_supervisor_cachemode)
935 is_not_amiga(L(mmu_init_not_amiga))
942 is_not_040_or_060(1f)
945 * 040: Map the 16Meg range physical 0x0 up to logical 0x8000.0000
947 mmu_map #0x80000000,#0,#0x01000000,#_PAGE_NOCACHE_S
949 * Map the Zorro III I/O space with transparent translation
950 * for frame buffer memory etc.
952 mmu_map_tt #1,#0x40000000,#0x20000000,#_PAGE_NOCACHE_S
954 jbra L(mmu_init_done)
958 * 030: Map the 32Meg range physical 0x0 up to logical 0x8000.0000
960 mmu_map #0x80000000,#0,#0x02000000,#_PAGE_NOCACHE030
961 mmu_map_tt #1,#0x40000000,#0x20000000,#_PAGE_NOCACHE030
963 jbra L(mmu_init_done)
965 L(mmu_init_not_amiga):
972 is_not_atari(L(mmu_init_not_atari))
976 /* On the Atari, we map the I/O region (phys. 0x00ffxxxx) by mapping
977 the last 16 MB of virtual address space to the first 16 MB (i.e.
978 0xffxxxxxx -> 0x00xxxxxx). For this, an additional pointer table is
979 needed. I/O ranges are marked non-cachable.
981 For the Medusa it is better to map the I/O region transparently
982 (i.e. 0xffxxxxxx -> 0xffxxxxxx), because some I/O registers are
983 accessible only in the high area.
985 On the Hades all I/O registers are only accessible in the high
989 /* I/O base addr for non-Medusa, non-Hades: 0x00000000 */
991 movel %pc@(atari_mch_type),%d3
992 cmpl #ATARI_MACH_MEDUSA,%d3
994 cmpl #ATARI_MACH_HADES,%d3
996 2: movel #0xff000000,%d0 /* Medusa/Hades base addr: 0xff000000 */
999 is_040_or_060(L(spata68040))
1001 /* Map everything non-cacheable, though not all parts really
1002 * need to disable caches (crucial only for 0xff8000..0xffffff
1003 * (standard I/O) and 0xf00000..0xf3ffff (IDE)). The remainder
1004 * isn't really used, except for sometimes peeking into the
1005 * ROMs (mirror at phys. 0x0), so caching isn't necessary for
1007 mmu_map #0xff000000,%d3,#0x01000000,#_PAGE_NOCACHE030
1009 jbra L(mmu_init_done)
1013 mmu_map #0xff000000,%d3,#0x01000000,#_PAGE_NOCACHE_S
1015 jbra L(mmu_init_done)
1017 L(mmu_init_not_atari):
1021 is_not_q40(L(notq40))
1023 * add transparent mapping for 0xff00 0000 - 0xffff ffff
1024 * non-cached serialized etc..
1025 * this includes master chip, DAC, RTC and ISA ports
1026 * 0xfe000000-0xfeffffff is for screen and ROM
1031 mmu_map_tt #0,#0xfe000000,#0x01000000,#_PAGE_CACHE040W
1032 mmu_map_tt #1,#0xff000000,#0x01000000,#_PAGE_NOCACHE_S
1034 jbra L(mmu_init_done)
1040 is_not_hp300(L(nothp300))
1042 /* On the HP300, we map the ROM, INTIO and DIO regions (phys. 0x00xxxxxx)
1043 * by mapping 32MB (on 020/030) or 16 MB (on 040) from 0xf0xxxxxx -> 0x00xxxxxx).
1044 * The ROM mapping is needed because the LEDs are mapped there too.
1050 * 030: Map the 32Meg range physical 0x0 up to logical 0xf000.0000
1052 mmu_map #0xf0000000,#0,#0x02000000,#_PAGE_NOCACHE030
1054 jbra L(mmu_init_done)
1058 * 040: Map the 16Meg range physical 0x0 up to logical 0xf000.0000
1060 mmu_map #0xf0000000,#0,#0x01000000,#_PAGE_NOCACHE_S
1062 jbra L(mmu_init_done)
1065 #endif /* CONFIG_HP300 */
1067 #ifdef CONFIG_MVME147
1069 is_not_mvme147(L(not147))
1072 * On MVME147 we have already created kernel page tables for
1073 * 4MB of RAM at address 0, so now need to do a transparent
1074 * mapping of the top of memory space. Make it 0.5GByte for now,
1075 * so we can access on-board i/o areas.
1078 mmu_map_tt #1,#0xe0000000,#0x20000000,#_PAGE_NOCACHE030
1080 jbra L(mmu_init_done)
1083 #endif /* CONFIG_MVME147 */
1085 #ifdef CONFIG_MVME16x
1087 is_not_mvme16x(L(not16x))
1090 * On MVME16x we have already created kernel page tables for
1091 * 4MB of RAM at address 0, so now need to do a transparent
1092 * mapping of the top of memory space. Make it 0.5GByte for now.
1093 * Supervisor only access, so transparent mapping doesn't
1094 * clash with User code virtual address space.
1095 * this covers IO devices, PROM and SRAM. The PROM and SRAM
1096 * mapping is needed to allow 167Bug to run.
1097 * IO is in the range 0xfff00000 to 0xfffeffff.
1098 * PROM is 0xff800000->0xffbfffff and SRAM is
1099 * 0xffe00000->0xffe1ffff.
1102 mmu_map_tt #1,#0xe0000000,#0x20000000,#_PAGE_NOCACHE_S
1104 jbra L(mmu_init_done)
1107 #endif /* CONFIG_MVME162 | CONFIG_MVME167 */
1109 #ifdef CONFIG_BVME6000
1111 is_not_bvme6000(L(not6000))
1114 * On BVME6000 we have already created kernel page tables for
1115 * 4MB of RAM at address 0, so now need to do a transparent
1116 * mapping of the top of memory space. Make it 0.5GByte for now,
1117 * so we can access on-board i/o areas.
1118 * Supervisor only access, so transparent mapping doesn't
1119 * clash with User code virtual address space.
1122 mmu_map_tt #1,#0xe0000000,#0x20000000,#_PAGE_NOCACHE_S
1124 jbra L(mmu_init_done)
1127 #endif /* CONFIG_BVME6000 */
1132 * The Macintosh mappings are less clear.
1134 * Even as of this writing, it is unclear how the
1135 * Macintosh mappings will be done. However, as
1136 * the first author of this code I'm proposing the
1139 * Map the kernel (that's already done),
1140 * Map the I/O (on most machines that's the
1141 * 0x5000.0000 ... 0x5300.0000 range,
1142 * Map the video frame buffer using as few pages
1143 * as absolutely (this requirement mostly stems from
1144 * the fact that when the frame buffer is at
1145 * 0x0000.0000 then we know there is valid RAM just
1146 * above the screen that we don't want to waste!).
1148 * By the way, if the frame buffer is at 0x0000.0000
1149 * then the Macintosh is known as an RBV based Mac.
1151 * By the way 2, the code currently maps in a bunch of
1152 * regions. But I'd like to cut that out. (And move most
1153 * of the mappings up into the kernel proper ... or only
1154 * map what's necessary.)
1161 is_not_mac(L(mmu_init_not_mac))
1165 is_not_040_or_060(1f)
1167 moveq #_PAGE_NOCACHE_S,%d3
1170 moveq #_PAGE_NOCACHE030,%d3
1173 * Mac Note: screen address of logical 0xF000.0000 -> <screen physical>
1174 * we simply map the 4MB that contains the videomem
1177 movel #VIDEOMEMMASK,%d0
1178 andl %pc@(L(mac_videobase)),%d0
1180 mmu_map #VIDEOMEMBASE,%d0,#VIDEOMEMSIZE,%d3
1181 /* ROM from 4000 0000 to 4200 0000 (only for mac_reset()) */
1182 mmu_map_eq #0x40000000,#0x02000000,%d3
1183 /* IO devices (incl. serial port) from 5000 0000 to 5300 0000 */
1184 mmu_map_eq #0x50000000,#0x03000000,%d3
1185 /* Nubus slot space (video at 0xF0000000, rom at 0xF0F80000) */
1186 mmu_map_tt #1,#0xf8000000,#0x08000000,%d3
1188 jbra L(mmu_init_done)
1190 L(mmu_init_not_mac):
1194 is_not_sun3x(L(notsun3x))
1196 /* oh, the pain.. We're gonna want the prom code after
1197 * starting the MMU, so we copy the mappings, translating
1198 * from 8k -> 4k pages as we go.
1201 /* copy maps from 0xfee00000 to 0xff000000 */
1202 movel #0xfee00000, %d0
1203 moveq #ROOT_INDEX_SHIFT, %d1
1205 mmu_get_root_table_entry %d0
1207 movel #0xfee00000, %d0
1208 moveq #PTR_INDEX_SHIFT, %d1
1210 andl #PTR_TABLE_SIZE-1, %d0
1211 mmu_get_ptr_table_entry %a0,%d0
1213 movel #0xfee00000, %d0
1214 moveq #PAGE_INDEX_SHIFT, %d1
1216 andl #PAGE_TABLE_SIZE-1, %d0
1217 mmu_get_page_table_entry %a0,%d0
1219 /* this is where the prom page table lives */
1220 movel 0xfefe00d4, %a1
1223 movel #((0x200000 >> 13)-1), %d1
1233 /* setup tt1 for I/O */
1234 mmu_map_tt #1,#0x40000000,#0x40000000,#_PAGE_NOCACHE_S
1235 jbra L(mmu_init_done)
1240 #ifdef CONFIG_APOLLO
1241 is_not_apollo(L(notapollo))
1244 mmu_map #0x80000000,#0,#0x02000000,#_PAGE_NOCACHE030
1247 jbra L(mmu_init_done)
1258 * On the 040 class machines, all pages that are used for the
1259 * mmu have to be fixed up. According to Motorola, pages holding mmu
1260 * tables should be non-cacheable on a '040 and write-through on a
1261 * '060. But analysis of the reasons for this, and practical
1262 * experience, showed that write-through also works on a '040.
1264 * Allocated memory so far goes from kernel_end to memory_start that
1265 * is used for all kind of tables, for that the cache attributes
1270 is_not_040_or_060(L(mmu_fixup_done))
1272 #ifdef MMU_NOCACHE_KERNEL
1273 jbra L(mmu_fixup_done)
1276 /* first fix the page at the start of the kernel, that
1277 * contains also kernel_pg_dir.
1279 movel %pc@(L(phys_kernel_start)),%d0
1280 subl #PAGE_OFFSET,%d0
1281 lea %pc@(_stext),%a0
1283 mmu_fixup_page_mmu_cache %a0
1285 movel %pc@(L(kernel_end)),%a0
1287 movel %pc@(L(memory_start)),%a1
1291 mmu_fixup_page_mmu_cache %a0
1306 * This chunk of code performs the gruesome task of engaging the MMU.
1307 * The reason it's gruesome is because when the MMU becomes engaged it
1308 * maps logical addresses to physical addresses. The Program Counter
1309 * register is then passed through the MMU before the next instruction
1310 * is fetched (the instruction following the engage MMU instruction).
1311 * This may mean one of two things:
1312 * 1. The Program Counter falls within the logical address space of
1313 * the kernel of which there are two sub-possibilities:
1314 * A. The PC maps to the correct instruction (logical PC == physical
1315 * code location), or
1316 * B. The PC does not map through and the processor will read some
1317 * data (or instruction) which is not the logically next instr.
1318 * As you can imagine, A is good and B is bad.
1320 * 2. The Program Counter does not map through the MMU. The processor
1321 * will take a Bus Error.
1322 * Clearly, 2 is bad.
1323 * It doesn't take a wiz kid to figure you want 1.A.
1324 * This code creates that possibility.
1325 * There are two possible 1.A. states (we now ignore the other above states):
1326 * A. The kernel is located at physical memory addressed the same as
1327 * the logical memory for the kernel, i.e., 0x01000.
1328 * B. The kernel is located some where else. e.g., 0x0400.0000
1330 * Under some conditions the Macintosh can look like A or B.
1331 * [A friend and I once noted that Apple hardware engineers should be
1332 * wacked twice each day: once when they show up at work (as in, Whack!,
1333 * "This is for the screwy hardware we know you're going to design today."),
1334 * and also at the end of the day (as in, Whack! "I don't know what
1335 * you designed today, but I'm sure it wasn't good."). -- rst]
1337 * This code works on the following premise:
1338 * If the kernel start (%d5) is within the first 16 Meg of RAM,
1339 * then create a mapping for the kernel at logical 0x8000.0000 to
1340 * the physical location of the pc. And, create a transparent
1341 * translation register for the first 16 Meg. Then, after the MMU
1342 * is engaged, the PC can be moved up into the 0x8000.0000 range
1343 * and then the transparent translation can be turned off and then
1344 * the PC can jump to the correct logical location and it will be
1345 * home (finally). This is essentially the code that the Amiga used
1346 * to use. Now, it's generalized for all processors. Which means
1347 * that a fresh (but temporary) mapping has to be created. The mapping
1348 * is made in page 0 (an as of yet unused location -- except for the
1349 * stack!). This temporary mapping will only require 1 pointer table
1350 * and a single page table (it can map 256K).
1352 * OK, alternatively, imagine that the Program Counter is not within
1353 * the first 16 Meg. Then, just use Transparent Translation registers
1354 * to do the right thing.
1356 * Last, if _start is already at 0x01000, then there's nothing special
1357 * to do (in other words, in a degenerate case of the first case above,
1370 * After this point no new memory is allocated and
1371 * the start of available memory is stored in availmem.
1372 * (The bootmem allocator requires now the physical address.)
1375 movel L(memory_start),availmem
1379 /* fixup the Amiga custom register location before printing */
1386 /* fixup the Atari iobase register location before printing */
1387 movel #0xff000000,L(iobase)
1393 movel #~VIDEOMEMMASK,%d0
1394 andl L(mac_videobase),%d0
1395 addl #VIDEOMEMBASE,%d0
1396 movel %d0,L(mac_videobase)
1397 #ifdef CONSOLE_DEBUG
1398 movel %pc@(L(phys_kernel_start)),%d0
1399 subl #PAGE_OFFSET,%d0
1400 subl %d0,L(console_font)
1401 subl %d0,L(console_font_data)
1403 orl #0x50000000,L(mac_sccbase)
1410 * Fix up the iobase register to point to the new location of the LEDs.
1412 movel #0xf0000000,L(iobase)
1415 * Energise the FPU and caches.
1418 movel #0x60,0xf05f400c
1422 * 040: slightly different, apparently.
1424 1: movew #0,0xf05f400e
1425 movew #0x64,0xf05f400e
1433 oriw #0x4000,0x61000000
1437 #ifdef CONFIG_APOLLO
1441 * Fix up the iobase before printing
1443 movel #0x80000000,L(iobase)
1454 is_not_040_or_060(L(cache_not_680460))
1462 is_060(L(cache68060))
1464 movel #CC6_ENABLE_D+CC6_ENABLE_I,%d0
1465 /* MMU stuff works in copyback mode now, so enable the cache */
1470 movel #CC6_ENABLE_D+CC6_ENABLE_I+CC6_ENABLE_SB+CC6_PUSH_DPI+CC6_ENABLE_B+CC6_CLRA_B,%d0
1471 /* MMU stuff works in copyback mode now, so enable the cache */
1473 /* enable superscalar dispatch in PCR */
1479 L(cache_not_680460):
1482 movel #CC3_ENABLE_DB+CC3_CLR_D+CC3_ENABLE_D+CC3_ENABLE_IB+CC3_CLR_I+CC3_ENABLE_I,%d0
1492 * Setup initial stack pointer
1494 lea init_task,%curptr
1495 lea init_thread_union+THREAD_SIZE,%sp
1499 subl %a6,%a6 /* clear a6 for gdb */
1502 * The new 64bit printf support requires an early exception initialization.
1506 /* jump to the kernel start */
1514 * Find a tag record in the bootinfo structure
1515 * The bootinfo structure is located right after the kernel
1516 * Returns: d0: size (-1 if not found)
1517 * a0: data pointer (end-of-records if not found)
1519 func_start get_bi_record,%d1
1523 1: tstw %a0@(BIR_TAG)
1525 cmpw %a0@(BIR_TAG),%d0
1527 addw %a0@(BIR_SIZE),%a0
1530 movew %a0@(BIR_SIZE),%d0
1531 lea %a0@(BIR_DATA),%a0
1534 lea %a0@(BIR_SIZE),%a0
1536 func_return get_bi_record
1540 * MMU Initialization Begins Here
1542 * The structure of the MMU tables on the 68k machines
1545 * Logical addresses are translated through
1546 * a hierarchical translation mechanism where the high-order
1547 * seven bits of the logical address (LA) are used as an
1548 * index into the "root table." Each entry in the root
1549 * table has a bit which specifies if it's a valid pointer to a
1550 * pointer table. Each entry defines a 32Meg range of memory.
1551 * If an entry is invalid then that logical range of 32M is
1552 * invalid and references to that range of memory (when the MMU
1553 * is enabled) will fault. If the entry is valid, then it does
1554 * one of two things. On 040/060 class machines, it points to
1555 * a pointer table which then describes more finely the memory
1556 * within that 32M range. On 020/030 class machines, a technique
1557 * called "early terminating descriptors" are used. This technique
1558 * allows an entire 32Meg to be described by a single entry in the
1559 * root table. Thus, this entry in the root table, contains the
1560 * physical address of the memory or I/O at the logical address
1561 * which the entry represents and it also contains the necessary
1562 * cache bits for this region.
1565 * Per the Root Table, there will be one or more
1566 * pointer tables. Each pointer table defines a 32M range.
1567 * Not all of the 32M range need be defined. Again, the next
1568 * seven bits of the logical address are used an index into
1569 * the pointer table to point to page tables (if the pointer
1570 * is valid). There will undoubtedly be more than one
1571 * pointer table for the kernel because each pointer table
1572 * defines a range of only 32M. Valid pointer table entries
1573 * point to page tables, or are early terminating entries
1577 * Per the Pointer Tables, each page table entry points
1578 * to the physical page in memory that supports the logical
1579 * address that translates to the particular index.
1581 * In short, the Logical Address gets translated as follows:
1582 * bits 31..26 - index into the Root Table
1583 * bits 25..18 - index into the Pointer Table
1584 * bits 17..12 - index into the Page Table
1585 * bits 11..0 - offset into a particular 4K page
1587 * The algorithms which follow do one thing: they abstract
1588 * the MMU hardware. For example, there are three kinds of
1589 * cache settings that are relevant. Either, memory is
1590 * being mapped in which case it is either Kernel Code (or
1591 * the RamDisk) or it is MMU data. On the 030, the MMU data
1592 * option also describes the kernel. Or, I/O is being mapped
1593 * in which case it has its own kind of cache bits. There
1594 * are constants which abstract these notions from the code that
1595 * actually makes the call to map some range of memory.
1605 * This algorithm will print out the current MMU mappings.
1608 * %a5 points to the root table. Everything else is calculated
1612 #define mmu_next_valid 0
1613 #define mmu_start_logical 4
1614 #define mmu_next_logical 8
1615 #define mmu_start_physical 12
1616 #define mmu_next_physical 16
1618 #define MMU_PRINT_INVALID -1
1619 #define MMU_PRINT_VALID 1
1620 #define MMU_PRINT_UNINITED 0
1622 #define putZc(z,n) jbne 1f; putc z; jbra 2f; 1: putc n; 2:
1624 func_start mmu_print,%a0-%a6/%d0-%d7
1626 movel %pc@(L(kernel_pgdir_ptr)),%a5
1627 lea %pc@(L(mmu_print_data)),%a0
1628 movel #MMU_PRINT_UNINITED,%a0@(mmu_next_valid)
1630 is_not_040_or_060(mmu_030_print)
1639 * The following #if/#endif block is a tight algorithm for dumping the 040
1640 * MMU Map in gory detail. It really isn't that practical unless the
1641 * MMU Map algorithm appears to go awry and you need to debug it at the
1642 * entry per entry level.
1644 movel #ROOT_TABLE_SIZE,%d5
1646 movel %a5@+,%d7 | Burn an entry to skip the kernel mappings,
1647 subql #1,%d5 | they (might) work
1657 andil #0xFFFFFE00,%d7
1659 movel #PTR_TABLE_SIZE,%d4
1669 andil #0xFFFFFF00,%d7
1671 movel #PAGE_TABLE_SIZE,%d3
1685 movel #8+1+8+1+1,%d2
1700 #endif /* MMU 040 Dumping code that's gory and detailed */
1702 lea %pc@(kernel_pg_dir),%a5
1703 movel %a5,%a0 /* a0 has the address of the root table ptr */
1704 movel #0x00000000,%a4 /* logical address */
1707 /* Increment the logical address and preserve in d5 */
1709 addil #PAGESIZE<<13,%d5
1713 jbsr mmu_print_tuple_invalidate
1717 andil #0xfffffe00,%d6
1721 addil #PAGESIZE<<6,%d5
1725 jbsr mmu_print_tuple_invalidate
1729 andil #0xffffff00,%d6
1737 jbsr mmu_print_tuple_invalidate
1740 moveml %d0-%d1,%sp@-
1743 andil #0xfffff4e0,%d1
1744 lea %pc@(mmu_040_print_flags),%a6
1745 jbsr mmu_print_tuple
1746 moveml %sp@+,%d0-%d1
1758 movel %d5,%a4 /* move to the next logical address */
1766 andiw #0x8000,%d1 /* is it valid ? */
1767 jbeq 1f /* No, bail out */
1770 andil #0xff000000,%d1 /* Get the address */
1776 jbsr mmu_040_print_flags_tt
1780 andiw #0x8000,%d1 /* is it valid ? */
1781 jbeq 1f /* No, bail out */
1784 andil #0xff000000,%d1 /* Get the address */
1790 jbsr mmu_040_print_flags_tt
1796 mmu_040_print_flags:
1798 putZc(' ','G') /* global bit */
1800 putZc(' ','S') /* supervisor bit */
1801 mmu_040_print_flags_tt:
1806 putZc('w','c') /* write through or copy-back */
1811 putZc('s',' ') /* serialized non-cacheable, or non-cacheable */
1815 mmu_030_print_flags:
1817 putZc('C','I') /* write through or copy-back */
1826 andil #0xfffffff0,%d0
1828 movel #0x00000000,%a4 /* logical address */
1832 addil #PAGESIZE<<13,%d5
1834 btst #1,%d6 /* is it a table ptr? */
1836 btst #0,%d6 /* is it early terminating? */
1838 jbsr mmu_030_print_helper
1841 jbsr mmu_print_tuple_invalidate
1845 andil #0xfffffff0,%d6
1849 addil #PAGESIZE<<6,%d5
1851 btst #1,%d6 /* is it a table ptr? */
1853 btst #0,%d6 /* is it a page descriptor? */
1855 jbsr mmu_030_print_helper
1858 jbsr mmu_print_tuple_invalidate
1862 andil #0xfffffff0,%d6
1870 jbsr mmu_print_tuple_invalidate
1873 jbsr mmu_030_print_helper
1885 movel %d5,%a4 /* move to the next logical address */
1893 func_return mmu_print
1896 mmu_030_print_helper:
1897 moveml %d0-%d1,%sp@-
1900 lea %pc@(mmu_030_print_flags),%a6
1901 jbsr mmu_print_tuple
1902 moveml %sp@+,%d0-%d1
1905 mmu_print_tuple_invalidate:
1906 moveml %a0/%d7,%sp@-
1908 lea %pc@(L(mmu_print_data)),%a0
1909 tstl %a0@(mmu_next_valid)
1910 jbmi mmu_print_tuple_invalidate_exit
1912 movel #MMU_PRINT_INVALID,%a0@(mmu_next_valid)
1918 mmu_print_tuple_invalidate_exit:
1919 moveml %sp@+,%a0/%d7
1924 moveml %d0-%d7/%a0,%sp@-
1926 lea %pc@(L(mmu_print_data)),%a0
1928 tstl %a0@(mmu_next_valid)
1929 jble mmu_print_tuple_print
1931 cmpl %a0@(mmu_next_physical),%d1
1932 jbeq mmu_print_tuple_increment
1934 mmu_print_tuple_print:
1942 mmu_print_tuple_record:
1943 movel #MMU_PRINT_VALID,%a0@(mmu_next_valid)
1945 movel %d1,%a0@(mmu_next_physical)
1947 mmu_print_tuple_increment:
1950 addl %d7,%a0@(mmu_next_physical)
1952 mmu_print_tuple_exit:
1953 moveml %sp@+,%d0-%d7/%a0
1956 mmu_print_machine_cpu_types:
1978 is_not_040_or_060(2f)
1986 #endif /* MMU_PRINT */
1991 * This is a specific function which works on all 680x0 machines.
1992 * On 030, 040 & 060 it will attempt to use Transparent Translation
1994 * On 020 it will call the standard mmu_map which will use early
1995 * terminating descriptors.
1997 func_start mmu_map_tt,%d0/%d1/%a0,4
2008 /* Extract the highest bit set
2010 bfffo ARG3{#0,#32},%d1
2026 /* Generate the upper 16bit of the tt register
2032 is_040_or_060(L(mmu_map_tt_040))
2034 /* set 030 specific bits (read/write access for supervisor mode
2035 * (highest function code set, lower two bits masked))
2037 orw #TTR_ENABLE+TTR_RWM+TTR_FCB2+TTR_FCM1+TTR_FCM0,%d1
2053 jra L(mmu_map_tt_done)
2055 /* set 040 specific bits
2058 orw #TTR_ENABLE+TTR_KERNELMODE,%d1
2072 jra L(mmu_map_tt_done)
2075 mmu_map_eq ARG2,ARG3,ARG4
2079 func_return mmu_map_tt
2084 * This routine will map a range of memory using a pointer
2085 * table and allocate the pages on the fly from the kernel.
2086 * The pointer table does not have to be already linked into
2087 * the root table, this routine will do that if necessary.
2090 * This routine will assert failure and use the serial_putc
2091 * routines in the case of a run-time error. For example,
2092 * if the address is already mapped.
2095 * This routine will use early terminating descriptors
2096 * where possible for the 68020+68851 and 68030 type
2099 func_start mmu_map,%d0-%d4/%a0-%a4
2108 /* Get logical address and round it down to 256KB
2111 andl #-(PAGESIZE*PAGE_TABLE_SIZE),%d0
2114 /* Get the end address
2120 /* Get physical address and round it down to 256KB
2123 andl #-(PAGESIZE*PAGE_TABLE_SIZE),%d0
2126 /* Add page attributes to the physical address
2129 orw #_PAGE_PRESENT+_PAGE_ACCESSED+_PAGE_DIRTY,%d0
2136 is_not_040_or_060(L(mmu_map_030))
2138 addw #_PAGE_GLOBAL040,%a2
2140 * MMU 040 & 060 Support
2142 * The MMU usage for the 040 and 060 is different enough from
2143 * the 030 and 68851 that there is separate code. This comment
2144 * block describes the data structures and algorithms built by
2147 * The 040 does not support early terminating descriptors, as
2148 * the 030 does. Therefore, a third level of table is needed
2149 * for the 040, and that would be the page table. In Linux,
2150 * page tables are allocated directly from the memory above the
2156 /* Calculate the offset into the root table
2159 moveq #ROOT_INDEX_SHIFT,%d1
2161 mmu_get_root_table_entry %d0
2163 /* Calculate the offset into the pointer table
2166 moveq #PTR_INDEX_SHIFT,%d1
2168 andl #PTR_TABLE_SIZE-1,%d0
2169 mmu_get_ptr_table_entry %a0,%d0
2171 /* Calculate the offset into the page table
2174 moveq #PAGE_INDEX_SHIFT,%d1
2176 andl #PAGE_TABLE_SIZE-1,%d0
2177 mmu_get_page_table_entry %a0,%d0
2179 /* The page table entry must not no be busy
2182 jne L(mmu_map_error)
2184 /* Do the mapping and advance the pointers
2191 /* Ready with mapping?
2199 /* Calculate the offset into the root table
2202 moveq #ROOT_INDEX_SHIFT,%d1
2204 mmu_get_root_table_entry %d0
2206 /* Check if logical address 32MB aligned,
2207 * so we can try to map it once
2210 andl #(PTR_TABLE_SIZE*PAGE_TABLE_SIZE*PAGESIZE-1)&(-ROOT_TABLE_SIZE),%d0
2213 /* Is there enough to map for 32MB at once
2215 lea %a3@(PTR_TABLE_SIZE*PAGE_TABLE_SIZE*PAGESIZE-1),%a1
2221 /* The root table entry must not no be busy
2224 jne L(mmu_map_error)
2226 /* Do the mapping and advance the pointers
2236 lea %a2@(PTR_TABLE_SIZE*PAGE_TABLE_SIZE*PAGESIZE),%a2
2237 jra L(mmu_mapnext_030)
2239 /* Calculate the offset into the pointer table
2242 moveq #PTR_INDEX_SHIFT,%d1
2244 andl #PTR_TABLE_SIZE-1,%d0
2245 mmu_get_ptr_table_entry %a0,%d0
2247 /* The pointer table entry must not no be busy
2250 jne L(mmu_map_error)
2252 /* Do the mapping and advance the pointers
2260 addl #PAGE_TABLE_SIZE*PAGESIZE,%a2
2261 addl #PAGE_TABLE_SIZE*PAGESIZE,%a3
2264 /* Ready with mapping?
2273 dputs "mmu_map error:"
2285 * On the 040 class machines, all pages that are used for the
2286 * mmu have to be fixed up.
2289 func_start mmu_fixup_page_mmu_cache,%d0/%a0
2291 dputs "mmu_fixup_page_mmu_cache"
2294 /* Calculate the offset into the root table
2297 moveq #ROOT_INDEX_SHIFT,%d1
2299 mmu_get_root_table_entry %d0
2301 /* Calculate the offset into the pointer table
2304 moveq #PTR_INDEX_SHIFT,%d1
2306 andl #PTR_TABLE_SIZE-1,%d0
2307 mmu_get_ptr_table_entry %a0,%d0
2309 /* Calculate the offset into the page table
2312 moveq #PAGE_INDEX_SHIFT,%d1
2314 andl #PAGE_TABLE_SIZE-1,%d0
2315 mmu_get_page_table_entry %a0,%d0
2318 andil #_CACHEMASK040,%d0
2319 orl %pc@(m68k_pgtable_cachemode),%d0
2324 func_return mmu_fixup_page_mmu_cache
2329 * create a temporary mapping to enable the mmu,
2330 * this we don't need any transparation translation tricks.
2333 func_start mmu_temp_map,%d0/%d1/%a0/%a1
2335 dputs "mmu_temp_map"
2340 lea %pc@(L(temp_mmap_mem)),%a1
2342 /* Calculate the offset in the root table
2345 moveq #ROOT_INDEX_SHIFT,%d1
2347 mmu_get_root_table_entry %d0
2349 /* Check if the table is temporary allocated, so we have to reuse it
2352 cmpl %pc@(L(memory_start)),%d0
2355 /* Temporary allocate a ptr table and insert it into the root table
2358 addl #PTR_TABLE_SIZE*4,%a1@
2359 orw #_PAGE_TABLE+_PAGE_ACCESSED,%d0
2364 /* Mask the root table entry for the ptr table
2366 andw #-ROOT_TABLE_SIZE,%d0
2369 /* Calculate the offset into the pointer table
2372 moveq #PTR_INDEX_SHIFT,%d1
2374 andl #PTR_TABLE_SIZE-1,%d0
2378 /* Check if a temporary page table is already allocated
2383 /* Temporary allocate a page table and insert it into the ptr table
2386 /* The 512 should be PAGE_TABLE_SIZE*4, but that violates the
2387 alignment restriction for pointer tables on the '0[46]0. */
2389 orw #_PAGE_TABLE+_PAGE_ACCESSED,%d0
2394 /* Mask the ptr table entry for the page table
2396 andw #-PTR_TABLE_SIZE,%d0
2399 /* Calculate the offset into the page table
2402 moveq #PAGE_INDEX_SHIFT,%d1
2404 andl #PAGE_TABLE_SIZE-1,%d0
2408 /* Insert the address into the page table
2412 orw #_PAGE_PRESENT+_PAGE_ACCESSED+_PAGE_DIRTY,%d0
2418 func_return mmu_temp_map
2420 func_start mmu_engage,%d0-%d2/%a0-%a3
2422 moveq #ROOT_TABLE_SIZE-1,%d0
2423 /* Temporarily use a different root table. */
2424 lea %pc@(L(kernel_pgdir_ptr)),%a0
2426 movel %pc@(L(memory_start)),%a1
2433 lea %pc@(L(temp_mmap_mem)),%a0
2436 movew #PAGESIZE-1,%d0
2443 /* Skip temp mappings if phys == virt */
2447 mmu_temp_map %a0,%a0
2448 mmu_temp_map %a0,%a1
2452 mmu_temp_map %a0,%a0
2453 mmu_temp_map %a0,%a1
2455 movel %pc@(L(memory_start)),%a3
2456 movel %pc@(L(phys_kernel_start)),%d2
2458 is_not_040_or_060(L(mmu_engage_030))
2468 movel #TC_ENABLE+TC_PAGE4K,%d0
2469 movec %d0,%tc /* enable the MMU */
2478 jra L(mmu_engage_cleanup)
2480 L(mmu_engage_030_temp):
2484 lea %pc@(L(mmu_engage_030_temp)),%a0
2485 movel #0x80000002,%a0@
2492 * enable,super root enable,4096 byte pages,7 bit root index,
2493 * 7 bit pointer index, 6 bit page table index.
2495 movel #0x82c07760,%a0@(8)
2496 pmove %a0@(8),%tc /* enable the MMU */
2498 1: movel %a2,%a0@(4)
2505 L(mmu_engage_cleanup):
2506 subl #PAGE_OFFSET,%d2
2508 movel %a2,L(kernel_pgdir_ptr)
2513 func_return mmu_engage
2515 func_start mmu_get_root_table_entry,%d0/%a1
2518 dputs "mmu_get_root_table_entry:"
2523 movel %pc@(L(kernel_pgdir_ptr)),%a0
2529 /* Find the start of free memory, get_bi_record does this for us,
2530 * as the bootinfo structure is located directly behind the kernel
2531 * we simply search for the last entry.
2533 get_bi_record BI_LAST
2534 addw #PAGESIZE-1,%a0
2540 lea %pc@(L(memory_start)),%a0
2542 lea %pc@(L(kernel_end)),%a0
2545 /* we have to return the first page at _stext since the init code
2546 * in mm/init.c simply expects kernel_pg_dir there, the rest of
2547 * page is used for further ptr tables in get_ptr_table.
2549 lea %pc@(_stext),%a0
2550 lea %pc@(L(mmu_cached_pointer_tables)),%a1
2552 addl #ROOT_TABLE_SIZE*4,%a1@
2554 lea %pc@(L(mmu_num_pointer_tables)),%a1
2560 movew #PAGESIZE/4-1,%d0
2565 lea %pc@(L(kernel_pgdir_ptr)),%a1
2579 func_return mmu_get_root_table_entry
2583 func_start mmu_get_ptr_table_entry,%d0/%a1
2586 dputs "mmu_get_ptr_table_entry:"
2596 /* Keep track of the number of pointer tables we use
2598 dputs "\nmmu_get_new_ptr_table:"
2599 lea %pc@(L(mmu_num_pointer_tables)),%a0
2603 /* See if there is a free pointer table in our cache of pointer tables
2605 lea %pc@(L(mmu_cached_pointer_tables)),%a1
2609 /* Get a new pointer table page from above the kernel memory
2614 /* There is an unused pointer table in our cache... use it
2617 addl #PTR_TABLE_SIZE*4,%a1@
2622 /* Insert the new pointer table into the root table
2625 orw #_PAGE_TABLE+_PAGE_ACCESSED,%d0
2628 /* Extract the pointer table entry
2630 andw #-PTR_TABLE_SIZE,%d0
2640 func_return mmu_get_ptr_table_entry
2643 func_start mmu_get_page_table_entry,%d0/%a1
2646 dputs "mmu_get_page_table_entry:"
2656 /* If the page table entry doesn't exist, we allocate a complete new
2657 * page and use it as one continuous big page table which can cover
2658 * 4MB of memory, nearly almost all mappings have that alignment.
2661 addw #_PAGE_TABLE+_PAGE_ACCESSED,%a0
2663 /* align pointer table entry for a page of page tables
2666 andw #-(PAGESIZE/PAGE_TABLE_SIZE),%d0
2669 /* Insert the page tables into the pointer entries
2671 moveq #PAGESIZE/PAGE_TABLE_SIZE/4-1,%d0
2674 lea %a0@(PAGE_TABLE_SIZE*4),%a0
2677 /* Now we can get the initialized pointer table entry
2682 /* Extract the page table entry
2684 andw #-PAGE_TABLE_SIZE,%d0
2694 func_return mmu_get_page_table_entry
2699 * Return a new page from the memory start and clear it.
2701 func_start get_new_page,%d0/%a1
2703 dputs "\nget_new_page:"
2705 /* allocate the page and adjust memory_start
2707 lea %pc@(L(memory_start)),%a0
2711 /* clear the new page
2714 movew #PAGESIZE/4-1,%d0
2722 func_return get_new_page
2727 * Debug output support
2728 * Atarians have a choice between the parallel port, the serial port
2729 * from the MFP or a serial port of the SCC
2733 /* You may define either or both of these. */
2734 #define MAC_USE_SCC_A /* Modem port */
2735 #define MAC_USE_SCC_B /* Printer port */
2737 #if defined(MAC_USE_SCC_A) || defined(MAC_USE_SCC_B)
2738 /* Initialisation table for SCC with 3.6864 MHz PCLK */
2739 L(scc_initable_mac):
2740 .byte 4,0x44 /* x16, 1 stopbit, no parity */
2741 .byte 3,0xc0 /* receiver: 8 bpc */
2742 .byte 5,0xe2 /* transmitter: 8 bpc, assert dtr/rts */
2743 .byte 10,0 /* NRZ */
2744 .byte 11,0x50 /* use baud rate generator */
2745 .byte 12,1,13,0 /* 38400 baud */
2746 .byte 14,1 /* Baud rate generator enable */
2747 .byte 3,0xc1 /* enable receiver */
2748 .byte 5,0xea /* enable transmitter */
2752 #endif /* CONFIG_MAC */
2755 /* #define USE_PRINTER */
2756 /* #define USE_SCC_B */
2757 /* #define USE_SCC_A */
2760 #if defined(USE_SCC_A) || defined(USE_SCC_B)
2761 /* Initialisation table for SCC with 7.9872 MHz PCLK */
2762 /* PCLK == 8.0539 gives baud == 9680.1 */
2763 L(scc_initable_atari):
2764 .byte 4,0x44 /* x16, 1 stopbit, no parity */
2765 .byte 3,0xc0 /* receiver: 8 bpc */
2766 .byte 5,0xe2 /* transmitter: 8 bpc, assert dtr/rts */
2767 .byte 10,0 /* NRZ */
2768 .byte 11,0x50 /* use baud rate generator */
2769 .byte 12,24,13,0 /* 9600 baud */
2770 .byte 14,2,14,3 /* use master clock for BRG, enable */
2771 .byte 3,0xc1 /* enable receiver */
2772 .byte 5,0xea /* enable transmitter */
2779 LPSG_SELECT = 0xff8800
2780 LPSG_READ = 0xff8800
2781 LPSG_WRITE = 0xff8802
2785 LSTMFP_GPIP = 0xfffa01
2786 LSTMFP_DDR = 0xfffa05
2787 LSTMFP_IERB = 0xfffa09
2789 #elif defined(USE_SCC_B)
2791 LSCC_CTRL = 0xff8c85
2792 LSCC_DATA = 0xff8c87
2794 #elif defined(USE_SCC_A)
2796 LSCC_CTRL = 0xff8c81
2797 LSCC_DATA = 0xff8c83
2799 #elif defined(USE_MFP)
2802 LMFP_TDCDR = 0xfffa1d
2803 LMFP_TDDR = 0xfffa25
2808 #endif /* CONFIG_ATARI */
2811 * Serial port output support.
2815 * Initialize serial port hardware
2817 func_start serial_init,%d0/%d1/%a0/%a1
2819 * Some of the register usage that follows
2821 * a0 = pointer to boot info record
2822 * d0 = boot info offset
2824 * a0 = address of SCC
2825 * a1 = Liobase address/address of scc_initable_atari
2826 * d0 = init data for serial port
2828 * a0 = address of SCC
2829 * a1 = address of scc_initable_mac
2830 * d0 = init data for serial port
2834 #define SERIAL_DTR 7
2835 #define SERIAL_CNTRL CIABBASE+C_PRA
2838 lea %pc@(L(custom)),%a0
2839 movel #-ZTWOBASE,%a0@
2840 bclr #SERIAL_DTR,SERIAL_CNTRL-ZTWOBASE
2841 get_bi_record BI_AMIGA_SERPER
2842 movew %a0@,CUSTOMBASE+C_SERPER-ZTWOBASE
2843 | movew #61,CUSTOMBASE+C_SERPER-ZTWOBASE
2849 movel %pc@(L(iobase)),%a1
2850 #if defined(USE_PRINTER)
2851 bclr #0,%a1@(LSTMFP_IERB)
2852 bclr #0,%a1@(LSTMFP_DDR)
2853 moveb #LPSG_CONTROL,%a1@(LPSG_SELECT)
2854 moveb #0xff,%a1@(LPSG_WRITE)
2855 moveb #LPSG_IO_B,%a1@(LPSG_SELECT)
2856 clrb %a1@(LPSG_WRITE)
2857 moveb #LPSG_IO_A,%a1@(LPSG_SELECT)
2858 moveb %a1@(LPSG_READ),%d0
2860 moveb %d0,%a1@(LPSG_WRITE)
2861 #elif defined(USE_SCC_A) || defined(USE_SCC_B)
2862 lea %a1@(LSCC_CTRL),%a0
2863 /* Reset SCC register pointer */
2865 /* Reset SCC device: write register pointer then register value */
2868 /* Wait for 5 PCLK cycles, which is about 63 CPU cycles */
2869 /* 5 / 7.9872 MHz = approx. 0.63 us = 63 / 100 MHz */
2874 /* Initialize channel */
2875 lea %pc@(L(scc_initable_atari)),%a1
2882 #elif defined(USE_MFP)
2883 bclr #1,%a1@(LMFP_TSR)
2884 moveb #0x88,%a1@(LMFP_UCR)
2885 andb #0x70,%a1@(LMFP_TDCDR)
2886 moveb #2,%a1@(LMFP_TDDR)
2887 orb #1,%a1@(LMFP_TDCDR)
2888 bset #1,%a1@(LMFP_TSR)
2890 jra L(serial_init_done)
2895 is_not_mac(L(serial_init_not_mac))
2896 #if defined(MAC_USE_SCC_A) || defined(MAC_USE_SCC_B)
2897 #define mac_scc_cha_b_ctrl_offset 0x0
2898 #define mac_scc_cha_a_ctrl_offset 0x2
2899 #define mac_scc_cha_b_data_offset 0x4
2900 #define mac_scc_cha_a_data_offset 0x6
2901 movel %pc@(L(mac_sccbase)),%a0
2902 /* Reset SCC register pointer */
2903 moveb %a0@(mac_scc_cha_a_ctrl_offset),%d0
2904 /* Reset SCC device: write register pointer then register value */
2905 moveb #9,%a0@(mac_scc_cha_a_ctrl_offset)
2906 moveb #0xc0,%a0@(mac_scc_cha_a_ctrl_offset)
2907 /* Wait for 5 PCLK cycles, which is about 68 CPU cycles */
2908 /* 5 / 3.6864 MHz = approx. 1.36 us = 68 / 50 MHz */
2914 #ifdef MAC_USE_SCC_A
2915 /* Initialize channel A */
2916 lea %pc@(L(scc_initable_mac)),%a1
2919 moveb %d0,%a0@(mac_scc_cha_a_ctrl_offset)
2920 moveb %a1@+,%a0@(mac_scc_cha_a_ctrl_offset)
2923 #endif /* MAC_USE_SCC_A */
2924 #ifdef MAC_USE_SCC_B
2925 /* Initialize channel B */
2926 lea %pc@(L(scc_initable_mac)),%a1
2929 moveb %d0,%a0@(mac_scc_cha_b_ctrl_offset)
2930 moveb %a1@+,%a0@(mac_scc_cha_b_ctrl_offset)
2933 #endif /* MAC_USE_SCC_B */
2934 jra L(serial_init_done)
2935 L(serial_init_not_mac):
2936 #endif /* CONFIG_MAC */
2940 /* debug output goes into SRAM, so we don't do it unless requested
2941 - check for '%LX$' signature in SRAM */
2942 lea %pc@(q40_mem_cptr),%a1
2943 move.l #0xff020010,%a1@ /* must be inited - also used by debug=mem */
2944 move.l #0xff020000,%a1
2957 lea %pc@(L(q40_do_debug)),%a1
2959 /*nodbg: q40_do_debug is 0 by default*/
2963 #ifdef CONFIG_MVME16x
2964 is_not_mvme16x(L(serial_init_not_mvme16x))
2965 moveb #0x10,M167_PCSCCMICR
2966 moveb #0x10,M167_PCSCCTICR
2967 moveb #0x10,M167_PCSCCRICR
2968 jra L(serial_init_done)
2969 L(serial_init_not_mvme16x):
2972 #ifdef CONFIG_APOLLO
2973 /* We count on the PROM initializing SIO1 */
2977 /* We count on the boot loader initialising the UART */
2980 L(serial_init_done):
2981 func_return serial_init
2984 * Output character on serial port.
2986 func_start serial_putc,%d0/%d1/%a0/%a1
2992 /* A little safe recursion is good for the soul */
3000 movel %pc@(L(custom)),%a0
3001 movew %d0,%a0@(CUSTOMBASE+C_SERDAT)
3002 1: movew %a0@(CUSTOMBASE+C_SERDATR),%d0
3005 jra L(serial_putc_done)
3011 #if defined(MAC_USE_SCC_A) || defined(MAC_USE_SCC_B)
3012 movel %pc@(L(mac_sccbase)),%a1
3014 #ifdef MAC_USE_SCC_A
3015 3: btst #2,%a1@(mac_scc_cha_a_ctrl_offset)
3017 moveb %d0,%a1@(mac_scc_cha_a_data_offset)
3018 #endif /* MAC_USE_SCC_A */
3019 #ifdef MAC_USE_SCC_B
3020 4: btst #2,%a1@(mac_scc_cha_b_ctrl_offset)
3022 moveb %d0,%a1@(mac_scc_cha_b_data_offset)
3023 #endif /* MAC_USE_SCC_B */
3024 jra L(serial_putc_done)
3026 #endif /* CONFIG_MAC */
3030 movel %pc@(L(iobase)),%a1
3031 #if defined(USE_PRINTER)
3032 3: btst #0,%a1@(LSTMFP_GPIP)
3034 moveb #LPSG_IO_B,%a1@(LPSG_SELECT)
3035 moveb %d0,%a1@(LPSG_WRITE)
3036 moveb #LPSG_IO_A,%a1@(LPSG_SELECT)
3037 moveb %a1@(LPSG_READ),%d0
3039 moveb %d0,%a1@(LPSG_WRITE)
3043 moveb %d0,%a1@(LPSG_WRITE)
3044 #elif defined(USE_SCC_A) || defined(USE_SCC_B)
3045 3: btst #2,%a1@(LSCC_CTRL)
3047 moveb %d0,%a1@(LSCC_DATA)
3048 #elif defined(USE_MFP)
3049 3: btst #7,%a1@(LMFP_TSR)
3051 moveb %d0,%a1@(LMFP_UDR)
3053 jra L(serial_putc_done)
3055 #endif /* CONFIG_ATARI */
3057 #ifdef CONFIG_MVME147
3059 1: btst #2,M147_SCC_CTRL_A
3061 moveb %d0,M147_SCC_DATA_A
3062 jbra L(serial_putc_done)
3066 #ifdef CONFIG_MVME16x
3069 * If the loader gave us a board type then we can use that to
3070 * select an appropriate output routine; otherwise we just use
3071 * the Bug code. If we have to use the Bug that means the Bug
3072 * workspace has to be valid, which means the Bug has to use
3073 * the SRAM, which is non-standard.
3075 moveml %d0-%d7/%a2-%a6,%sp@-
3076 movel vme_brdtype,%d1
3077 jeq 1f | No tag - use the Bug
3078 cmpi #VME_TYPE_MVME162,%d1
3080 cmpi #VME_TYPE_MVME172,%d1
3082 /* 162/172; it's an SCC */
3083 6: btst #2,M162_SCC_CTRL_A
3088 moveb #8,M162_SCC_CTRL_A
3092 moveb %d0,M162_SCC_CTRL_A
3095 /* 166/167/177; it's a CD2401 */
3097 moveb M167_CYIER,%d2
3098 moveb #0x02,M167_CYIER
3100 btst #5,M167_PCSCCTICR
3102 moveb M167_PCTPIACKR,%d1
3103 moveb M167_CYLICR,%d1
3105 moveb #0x08,M167_CYTEOIR
3108 moveb %d0,M167_CYTDR
3109 moveb #0,M167_CYTEOIR
3110 moveb %d2,M167_CYIER
3115 .word 0x0020 /* TRAP 0x020 */
3117 moveml %sp@+,%d0-%d7/%a2-%a6
3118 jbra L(serial_putc_done)
3120 #endif /* CONFIG_MVME16x */
3122 #ifdef CONFIG_BVME6000
3125 * The BVME6000 machine has a serial port ...
3127 1: btst #2,BVME_SCC_CTRL_A
3129 moveb %d0,BVME_SCC_DATA_A
3130 jbra L(serial_putc_done)
3137 movel 0xFEFE0018,%a1
3140 jbra L(serial_putc_done)
3146 tst.l %pc@(L(q40_do_debug)) /* only debug if requested */
3148 lea %pc@(q40_mem_cptr),%a1
3153 jbra L(serial_putc_done)
3157 #ifdef CONFIG_APOLLO
3159 movl %pc@(L(iobase)),%a1
3160 moveb %d0,%a1@(LTHRB0)
3161 1: moveb %a1@(LSRB0),%d0
3164 jbra L(serial_putc_done)
3170 movl %pc@(L(iobase)),%a1
3171 addl %pc@(L(uartbase)),%a1
3172 movel %pc@(L(uart_scode)),%d1 /* Check the scode */
3173 jmi 3f /* Unset? Exit */
3174 cmpi #256,%d1 /* APCI scode? */
3176 1: moveb %a1@(DCALSR),%d1 /* Output to DCA */
3179 moveb %d0,%a1@(DCADATA)
3180 jbra L(serial_putc_done)
3181 2: moveb %a1@(APCILSR),%d1 /* Output to APCI */
3184 moveb %d0,%a1@(APCIDATA)
3185 jbra L(serial_putc_done)
3189 L(serial_putc_done):
3190 func_return serial_putc
3195 func_start puts,%d0/%a0
3200 #ifdef CONSOLE_DEBUG
3212 * Output number in hex notation.
3215 func_start putn,%d0-%d2
3227 addb #'A'-('9'+1),%d2
3229 #ifdef CONSOLE_DEBUG
3239 #ifdef CONFIG_EARLY_PRINTK
3241 * This routine takes its parameters on the stack. It then
3242 * turns around and calls the internal routines. This routine
3243 * is used by the boot console.
3245 * The calling parameters are:
3246 * void debug_cons_nputs(const char *str, unsigned length)
3248 * This routine does NOT understand variable arguments only
3251 ENTRY(debug_cons_nputs)
3252 moveml %d0/%d1/%a0,%sp@-
3255 movel %sp@(18),%a0 /* fetch parameter */
3256 movel %sp@(22),%d1 /* fetch parameter */
3259 #ifdef CONSOLE_DEBUG
3271 moveml %sp@+,%d0/%d1/%a0
3273 #endif /* CONFIG_EARLY_PRINTK */
3275 #if defined(CONFIG_HP300) || defined(CONFIG_APOLLO)
3276 func_start set_leds,%d0/%a0
3280 movel %pc@(L(iobase)),%a0
3281 moveb %d0,%a0@(0x1ffff)
3285 #ifdef CONFIG_APOLLO
3286 movel %pc@(L(iobase)),%a0
3289 moveb %d0,%a0@(LCPUCTRL)
3292 func_return set_leds
3295 #ifdef CONSOLE_DEBUG
3297 * For continuity, see the data alignment
3298 * to which this structure is tied.
3300 #define Lconsole_struct_cur_column 0
3301 #define Lconsole_struct_cur_row 4
3302 #define Lconsole_struct_num_columns 8
3303 #define Lconsole_struct_num_rows 12
3304 #define Lconsole_struct_left_edge 16
3306 func_start console_init,%a0-%a4/%d0-%d7
3308 * Some of the register usage that follows
3309 * a0 = pointer to boot_info
3310 * a1 = pointer to screen
3311 * a2 = pointer to console_globals
3312 * d3 = pixel width of screen
3313 * d4 = pixel height of screen
3314 * (d3,d4) ~= (x,y) of a point just below
3315 * and to the right of the screen
3316 * NOT on the screen!
3317 * d5 = number of bytes per scan line
3318 * d6 = number of bytes on the entire screen
3321 lea %pc@(L(console_globals)),%a2
3322 movel %pc@(L(mac_videobase)),%a1
3323 movel %pc@(L(mac_rowbytes)),%d5
3324 movel %pc@(L(mac_dimensions)),%d3 /* -> low byte */
3326 swap %d4 /* -> high byte */
3327 andl #0xffff,%d3 /* d3 = screen width in pixels */
3328 andl #0xffff,%d4 /* d4 = screen height in pixels */
3332 mulul %d4,%d6 /* scan line bytes x num scan lines */
3333 divul #8,%d6 /* we'll clear 8 bytes at a time */
3334 moveq #-1,%d0 /* Mac_black */
3337 L(console_clear_loop):
3340 dbra %d6,L(console_clear_loop)
3342 /* Calculate font size */
3344 #if defined(FONT_8x8) && defined(CONFIG_FONT_8x8)
3345 lea %pc@(font_vga_8x8),%a0
3346 #elif defined(FONT_8x16) && defined(CONFIG_FONT_8x16)
3347 lea %pc@(font_vga_8x16),%a0
3348 #elif defined(FONT_6x11) && defined(CONFIG_FONT_6x11)
3349 lea %pc@(font_vga_6x11),%a0
3350 #elif defined(CONFIG_FONT_8x8) /* default */
3351 lea %pc@(font_vga_8x8),%a0
3352 #else /* no compiled-in font */
3357 * At this point we make a shift in register usage
3358 * a1 = address of console_font pointer
3360 lea %pc@(L(console_font)),%a1
3361 movel %a0,%a1@ /* store pointer to struct fbcon_font_desc in console_font */
3364 lea %pc@(L(console_font_data)),%a4
3365 movel %a0@(FONT_DESC_DATA),%d0
3366 subl #L(console_font),%a1
3371 * Calculate global maxs
3372 * Note - we can use either an
3373 * 8 x 16 or 8 x 8 character font
3374 * 6 x 11 also supported
3376 /* ASSERT: a0 = contents of Lconsole_font */
3377 movel %d3,%d0 /* screen width in pixels */
3378 divul %a0@(FONT_DESC_WIDTH),%d0 /* d0 = max num chars per row */
3380 movel %d4,%d1 /* screen height in pixels */
3381 divul %a0@(FONT_DESC_HEIGHT),%d1 /* d1 = max num rows */
3383 movel %d0,%a2@(Lconsole_struct_num_columns)
3384 movel %d1,%a2@(Lconsole_struct_num_rows)
3387 * Clear the current row and column
3389 clrl %a2@(Lconsole_struct_cur_column)
3390 clrl %a2@(Lconsole_struct_cur_row)
3391 clrl %a2@(Lconsole_struct_left_edge)
3394 * Initialization is complete
3397 func_return console_init
3400 func_start console_put_penguin,%a0-%a1/%d0-%d7
3402 * Get 'that_penguin' onto the screen in the upper right corner
3403 * penguin is 64 x 74 pixels, align against right edge of screen
3405 lea %pc@(L(mac_dimensions)),%a0
3408 subil #64,%d0 /* snug up against the right edge */
3409 clrl %d1 /* start at the top */
3411 lea %pc@(L(that_penguin)),%a1
3412 L(console_penguin_row):
3414 L(console_penguin_pixel_pair):
3417 console_plot_pixel %d0,%d1,%d2
3420 console_plot_pixel %d0,%d1,%d2
3422 dbra %d6,L(console_penguin_pixel_pair)
3426 dbra %d7,L(console_penguin_row)
3428 func_return console_put_penguin
3430 /* include penguin bitmap */
3432 #include "../mac/mac_penguin.S"
3436 * Calculate source and destination addresses
3441 func_start console_scroll,%a0-%a4/%d0-%d7
3442 lea %pc@(L(mac_videobase)),%a0
3445 lea %pc@(L(mac_rowbytes)),%a0
3447 movel %pc@(L(console_font)),%a0
3450 mulul %a0@(FONT_DESC_HEIGHT),%d5 /* account for # scan lines per character */
3456 lea %pc@(L(mac_dimensions)),%a0
3460 andl #0xffff,%d3 /* d3 = screen width in pixels */
3461 andl #0xffff,%d4 /* d4 = screen height in pixels */
3464 * Calculate number of bytes to move
3466 lea %pc@(L(mac_rowbytes)),%a0
3468 movel %pc@(L(console_font)),%a0
3469 subl %a0@(FONT_DESC_HEIGHT),%d4 /* we're not scrolling the top row! */
3470 mulul %d4,%d6 /* scan line bytes x num scan lines */
3471 divul #32,%d6 /* we'll move 8 longs at a time */
3474 L(console_scroll_loop):
3483 dbra %d6,L(console_scroll_loop)
3485 lea %pc@(L(mac_rowbytes)),%a0
3487 movel %pc@(L(console_font)),%a0
3488 mulul %a0@(FONT_DESC_HEIGHT),%d6 /* scan line bytes x font height */
3489 divul #32,%d6 /* we'll move 8 words at a time */
3493 L(console_scroll_clear_loop):
3502 dbra %d6,L(console_scroll_clear_loop)
3505 func_return console_scroll
3508 func_start console_putc,%a0/%a1/%d0-%d7
3510 is_not_mac(L(console_exit))
3511 tstl %pc@(L(console_font))
3514 /* Output character in d7 on console.
3520 /* A little safe recursion is good for the soul */
3523 lea %pc@(L(console_globals)),%a0
3526 jne L(console_not_lf)
3527 movel %a0@(Lconsole_struct_cur_row),%d0
3529 movel %d0,%a0@(Lconsole_struct_cur_row)
3530 movel %a0@(Lconsole_struct_num_rows),%d1
3534 movel %d0,%a0@(Lconsole_struct_cur_row)
3541 jne L(console_not_cr)
3542 clrl %a0@(Lconsole_struct_cur_column)
3547 jne L(console_not_home)
3548 clrl %a0@(Lconsole_struct_cur_row)
3549 clrl %a0@(Lconsole_struct_cur_column)
3553 * At this point we know that the %d7 character is going to be
3554 * rendered on the screen. Register usage is -
3555 * a0 = pointer to console globals
3557 * d0 = cursor column
3558 * d1 = cursor row to draw the character
3559 * d7 = character number
3561 L(console_not_home):
3562 movel %a0@(Lconsole_struct_cur_column),%d0
3563 addql #1,%a0@(Lconsole_struct_cur_column)
3564 movel %a0@(Lconsole_struct_num_columns),%d1
3567 console_putc #'\n' /* recursion is OK! */
3569 movel %a0@(Lconsole_struct_cur_row),%d1
3572 * At this point we make a shift in register usage
3573 * a0 = address of pointer to font data (fbcon_font_desc)
3575 movel %pc@(L(console_font)),%a0
3576 movel %pc@(L(console_font_data)),%a1 /* Load fbcon_font_desc.data into a1 */
3577 andl #0x000000ff,%d7
3578 /* ASSERT: a0 = contents of Lconsole_font */
3579 mulul %a0@(FONT_DESC_HEIGHT),%d7 /* d7 = index into font data */
3580 addl %d7,%a1 /* a1 = points to char image */
3583 * At this point we make a shift in register usage
3584 * d0 = pixel coordinate, x
3585 * d1 = pixel coordinate, y
3586 * d2 = (bit 0) 1/0 for white/black (!) pixel on screen
3587 * d3 = font scan line data (8 pixels)
3588 * d6 = count down for the font's pixel width (8)
3589 * d7 = count down for the font's pixel count in height
3591 /* ASSERT: a0 = contents of Lconsole_font */
3592 mulul %a0@(FONT_DESC_WIDTH),%d0
3593 mulul %a0@(FONT_DESC_HEIGHT),%d1
3594 movel %a0@(FONT_DESC_HEIGHT),%d7 /* Load fbcon_font_desc.height into d7 */
3596 L(console_read_char_scanline):
3599 /* ASSERT: a0 = contents of Lconsole_font */
3600 movel %a0@(FONT_DESC_WIDTH),%d6 /* Load fbcon_font_desc.width into d6 */
3603 L(console_do_font_scanline):
3605 scsb %d2 /* convert 1 bit into a byte */
3606 console_plot_pixel %d0,%d1,%d2
3608 dbra %d6,L(console_do_font_scanline)
3610 /* ASSERT: a0 = contents of Lconsole_font */
3611 subl %a0@(FONT_DESC_WIDTH),%d0
3613 dbra %d7,L(console_read_char_scanline)
3616 func_return console_putc
3622 * d2 = (bit 0) 1/0 for white/black (!)
3623 * All registers are preserved
3625 func_start console_plot_pixel,%a0-%a1/%d0-%d4
3627 movel %pc@(L(mac_videobase)),%a1
3628 movel %pc@(L(mac_videodepth)),%d3
3631 mulul %pc@(L(mac_rowbytes)),%d1
3636 * d0 = x coord becomes byte offset into frame buffer
3638 * d2 = black or white (0/1)
3640 * d4 = temp of x (d0) for many bit depths
3645 movel %d0,%d4 /* we need the low order 3 bits! */
3650 eorb #7,%d4 /* reverse the x-coordinate w/ screen-bit # */
3654 jbra L(console_plot_pixel_exit)
3657 jbra L(console_plot_pixel_exit)
3662 movel %d0,%d4 /* we need the low order 2 bits! */
3667 eorb #3,%d4 /* reverse the x-coordinate w/ screen-bit # */
3674 jbra L(console_plot_pixel_exit)
3679 jbra L(console_plot_pixel_exit)
3684 movel %d0,%d4 /* we need the low order bit! */
3700 jbra L(console_plot_pixel_exit)
3709 jbra L(console_plot_pixel_exit)
3719 jbra L(console_plot_pixel_exit)
3722 jbra L(console_plot_pixel_exit)
3726 jbne L(console_plot_pixel_exit)
3733 jbra L(console_plot_pixel_exit)
3736 jbra L(console_plot_pixel_exit)
3738 L(console_plot_pixel_exit):
3739 func_return console_plot_pixel
3740 #endif /* CONSOLE_DEBUG */
3746 m68k_init_mapped_size:
3749 #if defined(CONFIG_ATARI) || defined(CONFIG_AMIGA) || \
3750 defined(CONFIG_HP300) || defined(CONFIG_APOLLO)
3756 #ifdef CONSOLE_DEBUG
3758 .long 0 /* cursor column */
3759 .long 0 /* cursor row */
3760 .long 0 /* max num columns */
3761 .long 0 /* max num rows */
3762 .long 0 /* left edge */
3764 .long 0 /* pointer to console font (struct font_desc) */
3765 L(console_font_data):
3766 .long 0 /* pointer to console font data */
3767 #endif /* CONSOLE_DEBUG */
3769 #if defined(MMU_PRINT)
3771 .long 0 /* valid flag */
3772 .long 0 /* start logical */
3773 .long 0 /* next logical */
3774 .long 0 /* start physical */
3775 .long 0 /* next physical */
3776 #endif /* MMU_PRINT */
3780 L(mmu_cached_pointer_tables):
3782 L(mmu_num_pointer_tables):
3784 L(phys_kernel_start):
3790 L(kernel_pgdir_ptr):
3795 #if defined (CONFIG_MVME147)
3796 M147_SCC_CTRL_A = 0xfffe3002
3797 M147_SCC_DATA_A = 0xfffe3003
3800 #if defined (CONFIG_MVME16x)
3801 M162_SCC_CTRL_A = 0xfff45005
3802 M167_CYCAR = 0xfff450ee
3803 M167_CYIER = 0xfff45011
3804 M167_CYLICR = 0xfff45026
3805 M167_CYTEOIR = 0xfff45085
3806 M167_CYTDR = 0xfff450f8
3807 M167_PCSCCMICR = 0xfff4201d
3808 M167_PCSCCTICR = 0xfff4201e
3809 M167_PCSCCRICR = 0xfff4201f
3810 M167_PCTPIACKR = 0xfff42025
3813 #if defined (CONFIG_BVME6000)
3814 BVME_SCC_CTRL_A = 0xffb0000b
3815 BVME_SCC_DATA_A = 0xffb0000f
3818 #if defined(CONFIG_MAC)
3829 #endif /* CONFIG_MAC */
3831 #if defined (CONFIG_APOLLO)
3837 #if defined(CONFIG_HP300)
3854 m68k_pgtable_cachemode:
3856 m68k_supervisor_cachemode:
3858 #if defined(CONFIG_MVME16x)
3860 .long 0,0,0,0,0,0,0,0
3862 #if defined(CONFIG_Q40)