OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [rc203soc/] [sw/] [uClinux/] [arch/] [m68k/] [kernel/] [head.S] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1623 jcastillo
/* -*- 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
**
11
** Atari support by Andreas Schwab, using ideas of Robert de Vries
12
** and Bjoern Brauel
13
**
14
** 94/11/14 Andreas Schwab: put kernel at PAGESIZE
15
** 94/11/18 Andreas Schwab: remove identity mapping of STRAM for Atari
16
** ++ Bjoern & Roman: ATARI-68040 support for the Medusa
17
** 96/04/26 G|nther Kelleter: fixed identity mapping for Falcon with
18
**                            Magnum- and FX-alternate ram
19
**
20
** This file is subject to the terms and conditions of the GNU General Public
21
** License. See the file README.legal in the main directory of this archive
22
** for more details.
23
**
24
*/
25
 
26
/*
27
 * Linux startup code.
28
 *
29
 * At this point, the boot loader has:
30
 * Disabled interrupts
31
 * Disabled caches
32
 * Put us in supervisor state.
33
 *
34
 * The kernel setup code takes the following steps:
35
 *   Raise interrupt level
36
 *   Set up initial kernel memory mapping.
37
 *      This sets up a mapping of the 4M of memory the kernel
38
 *      is located in.  It also does a mapping of any initial
39
 *      machine specific areas.
40
 * Note that the kernel is located at virtual address 0x1000 == _start
41
 *   Enable cache memories
42
 *   Jump to kernel startup
43
 *
44
 * Register d6 contains the CPU flags and d4 the machine type
45
 * from the boot_info information for most of this file.
46
 * The upper word of d6 contains a bit for '040 or '060, since these two
47
 * are quite similar for initial mm setup. Another bit in d6 allows
48
 * distinction of the '060. The lower word of d6 contains the cache mode
49
 * that should be applied to pages containing descriptors. This mode is
50
 * non-cached/non-serialized for the '040 and cacheable/write-through for
51
 * the '060.
52
 *
53
 * General register usage:
54
 *   a6 - start of unused memory
55
 *        new pages can be allocated from here
56
 *   a5 - mmu root table
57
 *   a4 - mmu pointer table
58
 *   a3 - mmu page tables
59
 *   a2 - points to the page table entry for a6
60
 *        cache status can be changed (used for '0[46]0)
61
 *        you must increase a2 if alloc a new page
62
 *   d7 - used for debug output and some macros
63
 *   d6 - cpu type and cache mode
64
 *   d5 - physical start address of kernel
65
 *   d4 - machine type
66
 */
67
 
68
#include 
69
#include 
70
#include 
71
#include 
72
#include 
73
 
74
.globl SYMBOL_NAME(kernel_pg_dir), SYMBOL_NAME(kpt)
75
.globl SYMBOL_NAME(availmem), SYMBOL_NAME(is_medusa)
76
.globl SYMBOL_NAME(m68k_pgtable_cachemode)
77
.globl SYMBOL_NAME(kernel_pmd_table), SYMBOL_NAME(swapper_pg_dir)
78
 
79
D6B_0460 = 16           /* indicates 680[46]0 in d6 */
80
D6B_060  = 17           /* indicates 68060 in d6 */
81
D6F_040  = 1<
82
D6F_060  = (1<
83
 
84
/* Translation control register */
85
TC_ENABLE = 0x8000
86
TC_PAGE8K = 0x4000
87
TC_PAGE4K = 0x0000
88
 
89
/* Transparent translation registers */
90
TTR_ENABLE      = 0x8000        /* enable transparent translation */
91
TTR_ANYMODE     = 0x4000        /* user and kernel mode access */
92
TTR_KERNELMODE  = 0x2000        /* only kernel mode access */
93
TTR_USERMODE    = 0x0000        /* only user mode access */
94
TTR_CI          = 0x0400        /* inhibit cache */
95
TTR_RW          = 0x0200        /* read/write mode */
96
TTR_RWM         = 0x0100        /* read/write mask */
97
TTR_FCB2        = 0x0040        /* function code base bit 2 */
98
TTR_FCB1        = 0x0020        /* function code base bit 1 */
99
TTR_FCB0        = 0x0010        /* function code base bit 0 */
100
TTR_FCM2        = 0x0004        /* function code mask bit 2 */
101
TTR_FCM1        = 0x0002        /* function code mask bit 1 */
102
TTR_FCM0        = 0x0001        /* function code mask bit 0 */
103
 
104
/* Cache Control registers */
105
CC6_ENABLE_D    = 0x80000000    /* enable data cache (680[46]0) */
106
CC6_FREEZE_D    = 0x40000000    /* freeze data cache (68060) */
107
CC6_ENABLE_SB   = 0x20000000    /* enable store buffer (68060) */
108
CC6_PUSH_DPI    = 0x10000000    /* disable CPUSH invalidation (68060) */
109
CC6_HALF_D      = 0x08000000    /* half-cache mode for data cache (68060) */
110
CC6_ENABLE_B    = 0x00800000    /* enable branch cache (68060) */
111
CC6_CLRA_B      = 0x00400000    /* clear all entries in branch cache (68060) */
112
CC6_CLRU_B      = 0x00200000    /* clear user entries in branch cache (68060) */
113
CC6_ENABLE_I    = 0x00008000    /* enable instruction cache (680[46]0) */
114
CC6_FREEZE_I    = 0x00004000    /* freeze instruction cache (68060) */
115
CC6_HALF_I      = 0x00002000    /* half-cache mode for instruction cache (68060) */
116
CC3_ALLOC_WRITE = 0x00002000    /* write allocate mode(68030) */
117
CC3_ENABLE_DB   = 0x00001000    /* enable data burst (68030) */
118
CC3_CLR_D       = 0x00000800    /* clear data cache (68030) */
119
CC3_CLRE_D      = 0x00000400    /* clear entry in data cache (68030) */
120
CC3_FREEZE_D    = 0x00000200    /* freeze data cache (68030) */
121
CC3_ENABLE_D    = 0x00000100    /* enable data cache (68030) */
122
CC3_ENABLE_IB   = 0x00000010    /* enable instruction burst (68030) */
123
CC3_CLR_I       = 0x00000008    /* clear instruction cache (68030) */
124
CC3_CLRE_I      = 0x00000004    /* clear entry in instruction cache (68030) */
125
CC3_FREEZE_I    = 0x00000002    /* freeze instruction cache (68030) */
126
CC3_ENABLE_I    = 0x00000001    /* enable instruction cache (68030) */
127
 
128
/* Miscellaneous definitions */
129
PAGESIZE        = 4096
130
 
131
ROOT_TABLE_SIZE = 128
132
PTR_TABLE_SIZE  = 128
133
PAGE_TABLE_SIZE = 64
134
ROOT_INDEX_SHIFT = 25
135
PTR_INDEX_SHIFT  = 18
136
PAGE_INDEX_SHIFT = 12
137
 
138
TABLENR_4MB     = 16    /* # of page tables needed to page 4 MB */
139
TABLENR_16MB    = 64    /* same for 16 MB */
140
 
141
#define putc(ch) moveq &ch,%d7; jbsr Lserial_putc
142
#define putr() putc(13); putc(10)
143
#define putn(nr) movel nr,%d7; jbsr Lserial_putnum
144
 
145
#define is_not_amiga(lab) moveq &MACH_AMIGA,%d7; cmpl %d4,%d7; jne lab
146
#define is_not_atari(lab) moveq &MACH_ATARI,%d7; cmpl %d4,%d7; jne lab
147
 
148
#define is_040_or_060(lab) btst &D6B_0460,%d6; jne lab
149
#define is_not_040_or_060(lab) btst &D6B_0460,%d6; jeq lab
150
#define is_060(lab) btst &D6B_060,%d6; jne lab
151
#define is_not_060(lab) btst &D6B_060,%d6; jeq lab
152
 
153
.text
154
ENTRY(_stext)
155
/*
156
 * Version numbers of the bootinfo interface
157
 * The area from _stext to _start will later be used as kernel pointer table
158
 */
159
        bras    1f      /* Jump over bootinfo version numbers */
160
 
161
        .long   BOOTINFOV_MAGIC
162
        .long   MACH_AMIGA, AMIGA_BOOTI_VERSION
163
        .long   MACH_ATARI, ATARI_BOOTI_VERSION
164
        .long   0
165
1:      jra     SYMBOL_NAME(_start)
166
 
167
.equ    SYMBOL_NAME(kernel_pmd_table),SYMBOL_NAME(_stext)
168
.equ    SYMBOL_NAME(kernel_pg_dir),SYMBOL_NAME(kernel_pmd_table)
169
.equ    SYMBOL_NAME(swapper_pg_dir),SYMBOL_NAME(kernel_pg_dir)+(ROOT_TABLE_SIZE<<2)
170
.equ    Lavail_pmd_table,SYMBOL_NAME(swapper_pg_dir)+(ROOT_TABLE_SIZE<<2)
171
 
172
.equ    .,SYMBOL_NAME(_stext)+PAGESIZE
173
 
174
ENTRY(_start)
175
 
176
/*
177
 * Setup initial stack pointer
178
 */
179
        lea     %pc@(SYMBOL_NAME(_stext):w),%sp
180
 
181
/*
182
 * Copy bootinfo from position after BSS to final resting place
183
 */
184
        lea     %pc@(SYMBOL_NAME(_end)),%a0
185
        lea     %pc@(SYMBOL_NAME(boot_info)),%a1
186
        movel   %pc@(SYMBOL_NAME(bisize)),%d0
187
        subql   #1,%d0
188
1:      moveb   %a0@+,%a1@+
189
        dbra    %d0,1b
190
 
191
/*
192
 * Record the CPU and machine type.
193
 */
194
        lea     %pc@(SYMBOL_NAME(boot_info)),%a0
195
        movel   %a0@(BI_machtype),%d4
196
        movel   %a0@(BI_cputype),%d0
197
 
198
        btst    #CPUB_68060,%d0
199
        jeq     1f
200
        /* '060: d6 := BIT0460|BIT060, cache mode 0x60 (no-cache/non-ser) */
201
        movel   #D6F_060+_PAGE_NOCACHE,%d6
202
        jra     2f
203
1:      btst    #CPUB_68040,%d0
204
        jeq     1f
205
        /* '040: d6 := BIT0460, cache mode 0x00 (write-through) */
206
        movel   #D6F_040+_PAGE_CACHE040W,%d6
207
        jra     2f
208
1:      /* '020 or '030: d6 := no CPU bit, cache mode unused */
209
        moveq   #0,%d6
210
 
211
2:      lea     %pc@(SYMBOL_NAME(m68k_pgtable_cachemode)),%a0
212
        moveq   #0,%d0
213
        movew   %d6,%d0
214
        movel   %d0,%a0@                /* save cache mode for page tables */
215
 
216
/*
217
 * raise interrupt level with MASTER bit set, copy isp to msp (if not 68060)
218
 */
219
#ifdef FROM_PL9
220
        movew   #0x3700,%sr
221
        is_060(1f)
222
        movec   %isp,%d0
223
        movel   %d0,%sp
224
1:
225
#else
226
        movew   #0x2700,%sr
227
#endif
228
 
229
/*
230
 * Initialize serial port
231
 */
232
        jbsr Lserial_init
233
 
234
        putr()
235
        putc('A')
236
 
237
/*
238
 * Get address at end of kernel code/data/bss and
239
 * mask off at a page boundary.
240
 */
241
        lea     %pc@(SYMBOL_NAME(_end)),%a0
242
        addw    #PAGESIZE-1,%a0
243
        movel   %a0,%d0
244
        andl    #-PAGESIZE,%d0
245
        movel   %d0,%a6
246
 
247
        putc('B')
248
 
249
/*
250
 * Save physical start address of kernel
251
 */
252
        lea     %pc@(SYMBOL_NAME(_stext)-PAGESIZE:w),%a0
253
        movel   %a0,%d5
254
#ifdef HACKER_KERNEL
255
        lea     %pc@(Lkernel_start),%a0
256
        movel   %d5,%a0@
257
#endif
258
 
259
/*
260
 * initialize the kernel root table.
261
 */
262
        lea     %pc@(SYMBOL_NAME(kernel_pg_dir):w),%a5
263
        movel   %a5,%a0
264
        moveq   #ROOT_TABLE_SIZE-1,%d1
265
1:      clrl    %a0@+
266
        dbra    %d1,1b
267
 
268
        /*
269
         * Initialize root table descriptor pointing to the kernel pointer
270
         * table.
271
         */
272
        lea     %pc@(Lavail_pmd_table:w),%a4
273
        moveq   #_PAGE_TABLE,%d0
274
        addl    %a4,%d0
275
        movel   %d0,%a5@
276
 
277
        putc('C')
278
 
279
/*
280
 * Initialize the pointer tables referred to above.  They either point
281
 * to page tables in the case of the 680[46]0 or contain early
282
 * termination page descriptors in the case of the 68851 or 68030.
283
 *
284
 * Each pointer table entry points to a 64 entry page table.  16 of these
285
 * page tables are grouped to form a single 1024 entry page table which
286
 * fits in a single 4096 byte page.
287
 *
288
 * Some register usages:
289
 *    a0 -> pointer table descriptor address
290
 *    a1 -> pointer table descriptor
291
 *    d1 -> counter
292
 *    d2 -> pointer table descriptor increment (varies according to CPU)
293
 */
294
 
295
        /* clear the kernel pointer table */
296
        movel   %a4,%a0
297
        moveq   #PTR_TABLE_SIZE-1,%d1
298
1:      clrl    %a0@+
299
        dbra    %d1,1b
300
 
301
        movel   %a4,%a0
302
        moveq   #15,%d1
303
 
304
        /*
305
         * base value of pointer table descriptor is either
306
         * the address of the first page table (680[46]0)
307
         * or the base address of physical memory (68030).
308
         */
309
        is_040_or_060(1f)
310
 
311
        /* 680[23]0 */
312
        movel   %d5,%a1                         /* base address */
313
        addql   #_PAGE_PRESENT,%a1              /* descriptor type */
314
        movel   #PAGE_TABLE_SIZE*PAGESIZE,%d2   /* increment */
315
        jra     2f
316
 
317
1:      /* 680[46]0 */
318
        movel   %a6,%a3                 /* base address */
319
        addw    #PAGESIZE,%a6           /* allocate page for 16 page tables */
320
        lea     %pc@(SYMBOL_NAME(kpt)),%a1
321
        movel   %a3,%a1@                /* save address of page table */
322
        movel   %a3,%a1
323
        addql   #_PAGE_TABLE,%a1        /* descriptor type */
324
        movel   #PAGE_TABLE_SIZE<<2,%d2 /* increment */
325
 
326
2:      movel   %a1,%a0@+
327
        addl    %d2,%a1
328
        dbra    %d1,2b
329
 
330
        putc('D')
331
 
332
/*
333
 * If we are running on a 680[46]0, we have a kernel page table and
334
 * must initialize it.  Make the entries point to the first
335
 * 4M of physical memory (the memory we are residing in).
336
 * Set the cache mode bits to Cacheable, Copyback.  Set the Global bits
337
 * in the descriptors also.
338
 */
339
        is_not_040_or_060(Lnot040)
340
 
341
        putc('F')
342
 
343
        movel   %a3,%a0
344
        movel   %d5,%a1
345
        addw    #_PAGE_GLOBAL040+_PAGE_CACHE040+_PAGE_PRESENT,%a1
346
        movew   #(PAGE_TABLE_SIZE*TABLENR_4MB)-1,%d1
347
        movel   #PAGESIZE,%d2
348
1:      movel   %a1,%a0@+
349
        addl    %d2,%a1
350
        dbra    %d1,1b
351
 
352
        /*
353
         * on the 68040, pages used to hold mmu tables should
354
         * be initialized as noncachable; the '060 allows write-through.
355
         * Do this for the root table page (which also contains
356
         * all pointer tables utilized thus far) and the
357
         * kernel page table.
358
         */
359
        movel   %a5,%d0
360
        subl    %d5,%d0
361
        moveq   #PAGE_INDEX_SHIFT,%d2
362
        lsrl    %d2,%d0
363
        lea     %a3@(%d0:l:4),%a2
364
        movel   %a2@,%d1
365
        andw    #_CACHEMASK040,%d1
366
        orw     %d6,%d1
367
        movel   %d1,%a2@
368
 
369
        movel   %a3,%d0
370
        subl    %d5,%d0
371
        lsrl    %d2,%d0
372
        lea     %a3@(%d0:l:4),%a2
373
        movel   %a2@,%d1
374
        andw    #_CACHEMASK040,%d1
375
        orw     %d6,%d1
376
        movel   %d1,%a2@+
377
        /*
378
         * %a2 points now to the page table entry for available pages at %a6,
379
         * hence caching modes for new pages can easily set unless increasing
380
         * of %a2 are forgotten.
381
         */
382
Lnot040:
383
/*
384
 * Do any machine specific page table initializations.
385
 */
386
#ifdef CONFIG_AMIGA
387
        is_not_amiga(Lnotami)
388
 
389
/*
390
 * Setup a mapping of the first 16M of physical address space at virtual
391
 * address 0x80000000, using early termination page descriptors for the
392
 * 68030, and proper page tables for the 680[46]0.  Set this area as
393
 * non-cacheable.
394
 */
395
 
396
        putc('H')
397
 
398
        is_040_or_060(Lspami68040)
399
 
400
        /*
401
         * for the 68030, just setup a translation to map in the first
402
         * 32M of physical address space at virtual address 0x80000000
403
         * using an early termination page descriptor.
404
         */
405
 
406
        putc('I')
407
 
408
        moveq   #_PAGE_NOCACHE030+_PAGE_PRESENT,%d0
409
        movel   %d0,%a5@(0x40<<2)
410
 
411
        jra     Lmapphys
412
 
413
Lspami68040:
414
 
415
        /*
416
         * for the 680[46]0, use another pointer table, and allocate 4 more
417
         * page tables.  Initialize the pointer table to point to the
418
         * page tables.  Then initialize the page tables to point to
419
         * the first 16M of memory, with no caching (noncachable/serialized).
420
         */
421
 
422
        /* clear the amiga pointer table */
423
        lea     %a4@(PTR_TABLE_SIZE<<2),%a4
424
        moveq   #PTR_TABLE_SIZE-1,%d1
425
1:      clrl    %a0@+
426
        dbra    %d1,1b
427
 
428
        /* allocate 4 pages for 64 page tables */
429
        movel   %a6,%a3
430
        addw    #4*PAGESIZE,%a6
431
 
432
        /* initialize the pointer table */
433
        movel   %a4,%a0
434
        movel   %a3,%a1
435
        addql   #_PAGE_TABLE,%a1        /* base descriptor */
436
        movel   #PAGE_TABLE_SIZE<<2,%d2 /* increment */
437
        moveq   #TABLENR_16MB-1,%d1
438
 
439
1:      movel   %a1,%a0@+
440
        addl    %d2,%a1
441
        dbra    %d1,1b
442
 
443
        /* ensure that the root table points to the pointer table */
444
        movel   %a4,%a0
445
        addql   #_PAGE_TABLE,%a0
446
        movel   %a0,%a5@(0x40<<2)
447
 
448
        /*
449
         * initialize the page tables
450
         * descriptor bits include noncachable/serialized and global bits.
451
         */
452
        movel   %a3,%a0
453
        movew   #_PAGE_GLOBAL040+_PAGE_NOCACHE_S+_PAGE_PRESENT,%a1
454
        movel   #PAGESIZE,%d2
455
        movew   #(PAGE_TABLE_SIZE*TABLENR_16MB)-1,%d1
456
 
457
1:      movel   %a1,%a0@+
458
        addl    %d2,%a1
459
        dbra    %d1,1b
460
 
461
        /*
462
         * Finally, since we just allocated 4 page tables, make sure that
463
         * the virtual mapping of the 4 page tables indicates
464
         * noncachable/serialized.
465
         */
466
        moveq   #3,%d0
467
1:      movel   %a2@,%d1        /* a2 already points to root table offset */
468
        andw    #_CACHEMASK040,%d1
469
        orw     %d6,%d1
470
        movel   %d1,%a2@+
471
        dbra    %d0,1b
472
 
473
        jra     Lmapphys
474
 
475
Lnotami:
476
#endif
477
 
478
#ifdef CONFIG_ATARI
479
        is_not_atari(Lnotatari)
480
 
481
        move.w  #PAGESIZE,%sp
482
 
483
/* On the Atari, we map the I/O region (phys. 0x00ffxxxx) by mapping
484
   the last 16 MB of virtual address space to the first 16 MB (i.e.
485
   0xffxxxxxx -> 0x00xxxxxx). For this, an additional pointer table is
486
   needed. I/O ranges are marked non-cachable.
487
 
488
   For the Medusa it is better to map the I/O region transparently
489
   (i.e. 0xffxxxxxx -> 0xffxxxxxx), because some I/O registers are
490
   accessible only in the high area. The test whether it is a Medusa
491
   is done by writing to the byte at phys. 0x0. This should result
492
   in a bus error on all other machines.
493
 
494
   ...should, but doesn't. The Afterburner040 for the Falcon has the
495
   same behaviour (0x0..0x7 are no ROM shadow). So we have to do
496
   another test to distinguish Medusa and AB040. This is a
497
   read attempt for 0x00ff82fe phys. that should bus error on a Falcon
498
   (+AB040), but is in the range where the Medusa always asserts DTACK.
499
*/
500
 
501
        moveq   #0,%d3                  /* base addr for others: 0x00000000 */
502
        movec   %d3,%vbr
503
        lea     %pc@(Ltest_berr),%a0
504
        movel   %a0,0x8
505
        movel   %sp,%a0
506
        moveb   0x0,%d1
507
        clrb    0x0
508
        nop
509
        moveb   %d1,0x0
510
        nop
511
        tstb    0x00ff82fe
512
        nop
513
        movel   #0xff000000,%d3         /* Medusa base addr: 0xff000000 */
514
Ltest_berr:
515
        movel   %a0,%sp
516
        lea     %pc@(SYMBOL_NAME(is_medusa)),%a0
517
        movel   %d3,%a0@
518
 
519
        /* Let the root table point to the new pointer table */
520
        lea     %a4@(PTR_TABLE_SIZE<<2),%a4
521
        movel   %a4,%a0
522
        addl    #_PAGE_TABLE,%a0
523
        movel   %a0,%a5@(0x7f<<2)       /* 0xFE000000 - 0xFFFFFFFF */
524
 
525
        /* clear lower half of the pointer table (0xfexxxxxx) */
526
        movel   %a4,%a0
527
        movel   #(PTR_TABLE_SIZE/2)-1,%d2
528
1:      clrl    %a0@+
529
        dbra    %d2,1b
530
 
531
        is_040_or_060(Lspata68040)
532
 
533
/* Mapping of the last 16M of virtual address space to the first 16M
534
   for efficient addressing of hardware registers */
535
        movel   #PAGE_TABLE_SIZE*PAGESIZE,%d1
536
        movel   #(PTR_TABLE_SIZE/2)-1,%d2
537
        movel   %d3,%d0
538
        addl    #_PAGE_PRESENT,%d0
539
1:      movel   %d0,%a0@+
540
        addl    %d1,%d0
541
        dbra    %d2,1b
542
        moveq   #_PAGE_NOCACHE030,%d0   /* make non-cachable */
543
        addl    %d0,%a4@(0x7f<<2)       /* 0xFFFC0000-0xFFFFFFFF (I/O space) */
544
/* GK: 0xFFF00000-0xFFF3FFFF (IDE-bus) has to be non-cachable too */
545
        addl    %d0,%a4@(0x7c<<2)
546
 
547
        jra     Lmapphys
548
 
549
Lspata68040:
550
        /* allocate 4 page tables */
551
        movel   %a6,%a3
552
        addw    #4*PAGESIZE,%a6
553
 
554
        /* Initialize the upper half of the pointer table (a0 is still valid) */
555
        movel   %a3,%a1
556
        addql   #_PAGE_TABLE,%a1
557
        movel   #PAGE_TABLE_SIZE<<2,%d2
558
        moveq   #TABLENR_16MB-1,%d1
559
1:      movel   %a1,%a0@+
560
        addl    %d2,%a1
561
        dbra    %d1,1b
562
 
563
        /* Initialize the page tables as noncacheable/serialized! */
564
        movel   %a3,%a0
565
        movel   %d3,%a1
566
        addw    #_PAGE_GLOBAL040+_PAGE_NOCACHE_S+_PAGE_PRESENT,%a1
567
        movel   #PAGESIZE,%d2
568
        movew   #(PAGE_TABLE_SIZE*TABLENR_16MB)-1,%d1
569
1:      movel   %a1,%a0@+
570
        addl    %d2,%a1
571
        dbra    %d1,1b
572
 
573
        /*
574
         * Finally, since we just allocated 4 page tables, make sure that
575
         * the virtual mapping of the 4 page tables indicates
576
         * noncachable or write-through.
577
         */
578
        moveq   #3,%d0
579
1:      movel   %a2@,%d1        /* a2 already points to root table offset */
580
        andw    #_CACHEMASK040,%d1
581
        orw     %d6,%d1
582
        movel   %d1,%a2@+
583
        dbra    %d0,1b
584
 
585
Lnotatari:
586
#endif
587
 
588
/*
589
 * Setup a transparent mapping of the physical memory we are executing in.
590
 *
591
 * Only do this if the physical memory is not in the first 16M Meg, or not on
592
 * an Amiga since the first 16M is already identity mapped on the Amiga.
593
 */
594
Lmapphys:
595
        putc('J')
596
 
597
#ifdef CONFIG_AMIGA
598
        is_not_amiga(Lmapphysnotamiga)
599
 
600
/*
601
 * The virtual address of the start of the kernel is 0x1000. We transparently
602
 * translate the memory where we running in and can enable then the MMU. Hence
603
 * we have now two locations of the kernel in memory and can jump to the final
604
 * place. Except if the physical location is in the first 16MB, translation
605
 * will overlap later virtual location, but as we already mapped the first
606
 * 16MB to 0x80000000, we can jump there after translation and MMU is enabled
607
 * and then we can switch off translation and go to the final place.
608
 * When MMU is enabled, stack pointer and Lcustom will become again valid and
609
 * points to the unused first page.
610
 */
611
 
612
/*
613
 * Setup Supervisor Root Pointer register to point to page directory,
614
 * setup translation register contents and enable translation.
615
 */
616
        putc('K')
617
 
618
        movew   #PAGESIZE,%sp
619
 
620
        /* fixup the Amiga custom register location before printing */
621
        lea     %pc@(Lcustom),%a0
622
        movel   #0x80000000,%a0@
623
 
624
        is_040_or_060(Lamimmu68040)
625
 
626
        lea     2f:w,%a0
627
        movel   %d5,%d0
628
        andl    #0xff000000,%d0
629
        jne     1f
630
        lea     %pc@(2f+0x80000000),%a0
631
1:      orw     #TTR_ENABLE+TTR_CI+TTR_RWM+TTR_FCB2+TTR_FCM1+TTR_FCM0,%d0
632
        lea     %pc@(Lmmu),%a3
633
        movel   %d0,%a3@
634
        .long   0xf0130800      /* pmove %a3@,%tt0 */
635
        /* no limit, 4byte descriptors */
636
        movel   #0x80000002,%a3@
637
        movel   %a5,%a3@(4)
638
        .long   0xf0134800      /* pmove %a3@,%srp */
639
        .long   0xf0134c00      /* pmove %a3@,%crp */
640
        .long   0xf0002400      /* pflusha */
641
        /*
642
         * enable,super root enable,4096 byte pages,7 bit root index,
643
         * 7 bit pointer index, 6 bit page table index.
644
         */
645
        movel   #0x82c07760,%a3@
646
        .long   0xf0134000      /* pmove %a3@,%tc (enable the MMU) */
647
        jmp     %a0@
648
2:      clrl    %a3@
649
        .long   0xf0130800      /* pmove %a3@,%tt0 */
650
        jmp     LdoneMMUenable:w
651
 
652
Lamimmu68040:
653
 
654
        lea     2f:w,%a0
655
        movel   %d5,%d0
656
        andl    #0xff000000,%d0
657
        jne     1f
658
        lea     %pc@(2f+0x80000000),%a0
659
1:      orw     #TTR_ENABLE+TTR_KERNELMODE+_PAGE_NOCACHE_S,%d0
660
        .long   0x4e7b0004      /* movec %d0,%itt0 */
661
        .long   0x4e7bd806      /* movec %a5,%urp */
662
        .long   0x4e7bd807      /* movec %a5,%srp */
663
        .word   0xf518          /* pflusha */
664
        movel   #TC_ENABLE+TC_PAGE4K,%d0
665
        /*
666
         * this value is also ok for the 68060, we don`t use the cache
667
         * mode/protection defaults
668
         */
669
        .long   0x4e7b0003      /* movec %d0,%tc (enable the MMU) */
670
        jmp     %a0@
671
2:      moveq   #0,%d0
672
        .long   0x4e7b0004      /* movec %d0,%itt0 */
673
        jmp     LdoneMMUenable:w
674
 
675
Lmapphysnotamiga:
676
#endif
677
 
678
#ifdef CONFIG_ATARI
679
        is_not_atari(Lmapphysnotatari)
680
 
681
/*
682
 * If the kernel physical address is different from its virtual address, we
683
 * will temporarily set up an identity mapping of the 16MB chunk with
684
 * transparent translation where the kernel is executing.
685
 */
686
        putc('L')
687
 
688
        /* fixup the  Atari iobase register location before printing */
689
        lea     %pc@(Liobase),%a0
690
        movel   #0xff000000,%a0@
691
 
692
        is_040_or_060(Latarimmu68040)
693
 
694
        lea     %pc@(Lmmu),%a3
695
        movel   %d5,%d0
696
        jne     1f
697
        lea     LdoneMMUenable:w,%a0
698
        jra     3f
699
1:      lea     4f:w,%a0
700
        andl    #0xff000000,%d0 /* logical address base */
701
        jeq     2f
702
        orw     #TTR_ENABLE+TTR_CI+TTR_RWM+TTR_FCB2+TTR_FCM1+TTR_FCM0,%d0
703
        movel   %d0,%a3@
704
        .long   0xf0130800      /* pmove %a3@,%tt0 */
705
        jra     3f
706
        /* tt0 doesn't work if physical and virtual address of kernel is in
707
         * the same 16M area (Falcon with Magnum/FX, kernel in alternate ram)
708
         * Transparent translation through kernel pointer table
709
         * Requires that this code until after MMU enabling lies in
710
         * the 256K page around %d5
711
         */
712
2:      movel   %a4@,%d1
713
        andw    #0xfff0,%d1
714
        movel   %d1,%a1
715
        movel   %d5,%d1
716
        moveq   #PTR_INDEX_SHIFT,%d0
717
        lsrl    %d0,%d1
718
        lea     %a1@(%d1:l:4),%a1
719
        movel   %d5,%d1
720
        addql   #_PAGE_PRESENT,%d1
721
        movel   %a1@,%d2
722
        movel   %d1,%a1@
723
        lea     5f:w,%a0
724
        /* no limit, 4byte descriptors */
725
3:      movel   #0x80000002,%a3@
726
        movel   %a5,%a3@(4)
727
        .long   0xf0134800      /* pmove %a3@,%srp */
728
        .long   0xf0134c00      /* pmove %a3@,%crp */
729
        .long   0xf0002400      /* pflusha */
730
        /*
731
         * enable,super root enable,4096 byte pages,7 bit root index,
732
         * 7 bit pointer index, 6 bit page table index.
733
         */
734
        movel   #0x82c07760,%a3@
735
        .long   0xf0134000      /* pmove %a3@,%tc (enable the MMU) */
736
        jmp     %a0@
737
4:      clrl    %a3@
738
        .long   0xf0130800      /* pmove %a3@,%tt0 */
739
        jra     LdoneMMUenable
740
5:      movel   %d2,%a1@
741
        jra     LdoneMMUenable
742
 
743
Latarimmu68040:
744
        movel   %d5,%d0
745
        jne     1f
746
        lea     LdoneMMUenable:w,%a0
747
        jra     2f
748
1:      lea     3f:w,%a0
749
        andl    #0xff000000,%d0 /* logical address base */
750
        orw     #TTR_ENABLE+TTR_KERNELMODE+_PAGE_NOCACHE_S,%d0
751
        .long   0x4e7b0004      /* movec %d0,%itt0 */
752
2:      .word   0xf518          /* pflusha */
753
        .long   0x4e7bd807      /* movec %a5,%srp */
754
        .long   0x4e7bd806      /* movec %a5,%urp */
755
        movel   #TC_ENABLE+TC_PAGE4K,%d0
756
        /*
757
         * this value is also ok for the 68060, we don`t use the cache
758
         * mode/protection defaults
759
         */
760
        .long   0x4e7b0003      /* movec %d0,%tc (enable the MMU) */
761
        jmp     %a0@
762
3:      moveq   #0,%d0
763
        .long   0x4e7b0004      /* movec %d0,%itt0 */
764
        tstl    %a1
765
        jra     LdoneMMUenable
766
 
767
Lmapphysnotatari:
768
#endif
769
 
770
LdoneMMUenable:
771
 
772
/*
773
 * Fixup the addresses for the kernel pointer table and availmem.
774
 * Convert them from physical addresses to virtual addresses.
775
 */
776
 
777
        putc('M')
778
 
779
        /*
780
         * d5 contains physaddr of kernel start
781
         */
782
        subl    %d5,SYMBOL_NAME(kpt)
783
 
784
        /*
785
         * do the same conversion on the first available memory
786
         * address (in a6).
787
         */
788
        subl    %d5,%a6
789
        movel   %a6,SYMBOL_NAME(availmem) /* first available memory address */
790
 
791
        putc('N')
792
 
793
#if 0
794
        putr()
795
        lea     SYMBOL_NAME(kernel_pmd_table),%a0
796
        moveq   #63,%d0
797
1:      moveq   #7,%d1
798
        putn(%a0)
799
        putc(':')
800
        putc(' ')
801
2:      putn(%a0@+)
802
        dbra    %d1,2b
803
        putr()
804
        dbra    %d0,1b
805
        putr()
806
        movel   SYMBOL_NAME(kpt),%a0
807
        moveq   #639,%d0
808
1:      moveq   #7,%d1
809
        putn(%a0)
810
        putc(':')
811
        putc(' ')
812
2:      putn(%a0@+)
813
        dbra    %d1,2b
814
        putr()
815
        dbra    %d0,1b
816
#endif
817
/*
818
 * Enable caches
819
 */
820
        is_040_or_060(Lcache680460)
821
 
822
        movel   #CC3_ENABLE_DB+CC3_CLR_D+CC3_ENABLE_D+CC3_ENABLE_IB+CC3_CLR_I+CC3_ENABLE_I,%d0
823
        movec   %d0,%cacr
824
        jra     1f
825
 
826
Lcache680460:
827
        .word   0xf4f8          /* cpusha %bc */
828
 
829
        is_060(Lcache68060)
830
 
831
        movel   #CC6_ENABLE_D+CC6_ENABLE_I,%d0
832
        /* MMU stuff works in copyback mode now, so enable the cache */
833
        movec   %d0,%cacr
834
        jra     1f
835
 
836
Lcache68060:
837
        movel   #CC6_ENABLE_D+CC6_ENABLE_I+CC6_ENABLE_SB+CC6_PUSH_DPI+CC6_ENABLE_B+CC6_CLRA_B,%d0
838
        /* MMU stuff works in copyback mode now, so enable the cache */
839
        movec   %d0,%cacr
840
        /* enable superscalar dispatch in PCR */
841
        moveq   #1,%d0
842
        .long   0x4e7b0808      /* movec d0,pcr */
843
1:
844
 
845
/*
846
 * Setup initial stack pointer
847
 */
848
        lea     SYMBOL_NAME(init_user_stack)+PAGESIZE,%sp
849
 
850
/* jump to the kernel start */
851
        putr()
852
 
853
        jbsr    SYMBOL_NAME(start_kernel)
854
 
855
/*
856
 * switch off mmu and exit
857
 */
858
 
859
#ifdef HACKER_KERNEL
860
ENTRY(kernel_exit)
861
        lea     2f:w,%a0
862
        movel   %pc@(Lkernel_start),%a0
863
        lea     %a0@(2f:w),%a1
864
        movel   %a1,%d0
865
        andl    #0xff000000,%d0
866
        jne     1f
867
        jmp     %a0@(1f+0x80000000)
868
1:      orw     #TTR_ENABLE+TTR_KERNELMODE+_PAGE_NOCACHE_S,%d0
869
        .long   0x4e7b0004      /* movec %d0,%itt0 */
870
        jmp     %a1@
871
2:      moveq   #0,%d0
872
        .long   0x4e7b0003      /* movec %d0,%tc (disable the MMU) */
873
        .word   0xf518          /* pflusha */
874
        .long   0x4e7b0004      /* movec %d0,%itt0 */
875
        movec   %d0,%cacr
876
        .word   0xf4f8          /* cpusha %bc */
877
 
878
        lea     %pc@(SYMBOL_NAME(boot_info)),%a0
879
        jmp     %a0@(BI_amiga_exit_func:w)@(0:w)
880
#endif
881
 
882
/*
883
 * Serial port output support.
884
 */
885
LSERPER      = 0xdff032
886
LSERDAT      = 0xdff030
887
LSERDATR     = 0xdff018
888
LNTSC_PERIOD = 371
889
LPAL_PERIOD  = 368
890
LNTSC_ECLOCK = 7159090
891
LSERIAL_CNTRL = 0xbfd000
892
LSERIAL_DTR   = 7
893
 
894
/*
895
 * Debug output support
896
 * Atarians have a choice between the parallel port, the serial port
897
 * from the MFP or a serial port of the SCC
898
 */
899
 
900
#ifdef CONFIG_ATARI
901
/* #define USE_PRINTER */
902
/* #define USE_SCC */
903
#define USE_MFP
904
 
905
#ifdef USE_PRINTER
906
 
907
LPSG_SELECT     = 0xff8800
908
LPSG_READ       = 0xff8800
909
LPSG_WRITE      = 0xff8802
910
LPSG_IO_A       = 14
911
LPSG_IO_B       = 15
912
LPSG_CONTROL    = 7
913
LSTMFP_GPIP     = 0xfffa01
914
LSTMFP_DDR      = 0xfffa05
915
LSTMFP_IERB     = 0xfffa09
916
 
917
#elif defined(USE_SCC)
918
 
919
LSCC_CTRL_B     = 0xff8c85
920
LSCC_DATA_B     = 0xff8c87
921
 
922
/* Initialisation table for SCC */
923
scc_initable:
924
        .byte   9,12            /* Reset */
925
        .byte   4,0x44          /* x16, 1 stopbit, no parity */
926
        .byte   3,0xc0          /* receiver: 8 bpc */
927
        .byte   5,0xe2          /* transmitter: 8 bpc, assert dtr/rts */
928
        .byte   9,0             /* no interrupts */
929
        .byte   10,0            /* NRZ */
930
        .byte   11,0x50         /* use baud rate generator */
931
        .byte   12,24,13,0      /* 9600 baud */
932
        .byte   14,2,14,3       /* use master clock for BRG, enable */
933
        .byte   3,0xc1          /* enable receiver */
934
        .byte   5,0xea          /* enable transmitter */
935
        .byte   -1
936
        .even
937
 
938
#elif defined(USE_MFP)
939
 
940
LMFP_UCR     = 0xfffa29
941
LMFP_TDCDR   = 0xfffa1d
942
LMFP_TDDR    = 0xfffa25
943
LMFP_TSR     = 0xfffa2d
944
LMFP_UDR     = 0xfffa2f
945
 
946
#endif
947
#endif
948
 
949
/*
950
 * Initialize serial port hardware for 9600/8/1
951
 * a0 thrashed
952
 * Atari d0 trashed (a1 in case of SCC)
953
 */
954
        .even
955
Lserial_init:
956
#ifdef CONFIG_AMIGA
957
        cmpil   #MACH_AMIGA,%d4
958
        jne     1f
959
        lea     %pc@(SYMBOL_NAME(boot_info)),%a0
960
        bclr    #LSERIAL_DTR,LSERIAL_CNTRL
961
        movew   #LNTSC_PERIOD,LSERPER
962
        cmpl    #LNTSC_ECLOCK,%a0@(BI_amiga_eclock)
963
        jeq     9f
964
        movew   #LPAL_PERIOD,LSERPER
965
        jra     9f
966
1:
967
#endif
968
#ifdef CONFIG_ATARI
969
        cmpil   #MACH_ATARI,%d4
970
        jne     4f
971
#ifdef USE_PRINTER
972
        bclr    #0,LSTMFP_IERB
973
        bclr    #0,LSTMFP_DDR
974
        moveb   #LPSG_CONTROL,LPSG_SELECT
975
        moveb   #0xff,LPSG_WRITE
976
        moveb   #LPSG_IO_B,LPSG_SELECT
977
        clrb    LPSG_WRITE
978
        moveb   #LPSG_IO_A,LPSG_SELECT
979
        moveb   LPSG_READ,%d0
980
        bset    #5,%d0
981
        moveb   %d0,LPSG_WRITE
982
#elif defined(USE_SCC)
983
        lea     LSCC_CTRL_B,%a0
984
        lea     %pc@(scc_initable:w),%a1
985
2:      moveb   %a1@+,%d0
986
        jmi     3f
987
        moveb   %d0,%a0@
988
        moveb   %a1@+,%a0@
989
        jra     2b
990
3:      clrb    %a0@
991
#elif defined(USE_MFP)
992
        bclr    #1,LMFP_TSR
993
        moveb   #0x88,LMFP_UCR
994
        andb    #0x70,LMFP_TDCDR
995
        moveb   #2,LMFP_TDDR
996
        orb     #1,LMFP_TDCDR
997
        bset    #1,LMFP_TSR
998
#endif
999
4:
1000
#endif
1001
9:
1002
        rts
1003
 
1004
/*
1005
 * Output character in d7 on serial port.
1006
 * d7 thrashed.
1007
 */
1008
Lserial_putc:
1009
        moveml  %a0/%a1,%sp@-
1010
#ifdef CONFIG_AMIGA
1011
        cmpil   #MACH_AMIGA,%d4
1012
        jne     2f
1013
        andw    #0x00ff,%d7
1014
        oriw    #0x0100,%d7
1015
        movel   %pc@(Lcustom),%a1
1016
        movew   %d7,%a1@(LSERDAT)
1017
1:      movew   %a1@(LSERDATR),%d7
1018
        andw    #0x2000,%d7
1019
        jeq     1b
1020
        jra     9f
1021
2:
1022
#endif
1023
#ifdef CONFIG_ATARI
1024
        cmpil   #MACH_ATARI,%d4
1025
        jne     4f
1026
        movel   %pc@(Liobase),%a1
1027
#ifdef USE_PRINTER
1028
3:      btst    #0,%a1@(LSTMFP_GPIP)
1029
        jne     3b
1030
        moveb   #LPSG_IO_B,%a1@(LPSG_SELECT)
1031
        moveb   %d7,%a1@(LPSG_WRITE)
1032
        moveb   #LPSG_IO_A,%a1@(LPSG_SELECT)
1033
        moveb   %a1@(LPSG_READ),%d7
1034
        bclr    #5,%d7
1035
        moveb   %d7,%a1@(LPSG_WRITE)
1036
        nop
1037
        nop
1038
        bset    #5,%d7
1039
        moveb   %d7,%a1@(LPSG_WRITE)
1040
#elif defined(USE_SCC)
1041
3:      btst    #2,%a1@(LSCC_CTRL_B)
1042
        jeq     3b
1043
        moveb   %d7,%a1@(LSCC_DATA_B)
1044
#elif defined(USE_MFP)
1045
3:      btst    #7,%a1@(LMFP_TSR)
1046
        jeq     3b
1047
        moveb   %d7,%a1@(LMFP_UDR)
1048
#endif
1049
4:
1050
#endif
1051
9:
1052
        moveml  %sp@+,%a0/%a1
1053
        rts
1054
 
1055
/*
1056
 * Output string pointed to by a0 to serial port.
1057
 * a0 trashed.
1058
 */
1059
Lserial_puts:
1060
        movel   %d7,%sp@-
1061
1:      moveb   %a0@+,%d7
1062
        jeq     2f
1063
        jbsr    Lserial_putc
1064
        jra     1b
1065
2:      movel   %sp@+,%d7
1066
        rts
1067
 
1068
/*
1069
 * Output number in d7 in hex notation on serial port.
1070
 * d0-d2 trashed.
1071
 * d7 trashed.
1072
 */
1073
 
1074
Lserial_putnum:
1075
        moveml  %d0-%d2/%d7,%sp@-
1076
        movel   %d7,%d1
1077
        moveq   #4,%d0
1078
        moveq   #7,%d2
1079
L1:     roll    %d0,%d1
1080
        moveb   %d1,%d7
1081
        andb    #0x0f,%d7
1082
        cmpb    #0x0a,%d7
1083
        jcc     1f
1084
        addb    #'0',%d7
1085
        jra     2f
1086
1:      addb    #'A'-10,%d7
1087
2:      jbsr    Lserial_putc
1088
        dbra    %d2,L1
1089
        moveq   #32,%d7
1090
        jbsr    Lserial_putc
1091
        moveml  %sp@+,%d0-%d2/%d7
1092
        rts
1093
 
1094
Lshowtest:
1095
        moveml  %a0/%d7,%sp@-
1096
        putc('A')
1097
        putc('=')
1098
        putn(%a1)
1099
 
1100
        ptestr  #5,%a1@,#7,%a0
1101
 
1102
        putc('D')
1103
        putc('A')
1104
        putc('=')
1105
        putn(%a0)
1106
 
1107
        putc('D')
1108
        putc('=')
1109
        putn(%a0@)
1110
 
1111
        putc('S')
1112
        putc('=')
1113
        lea     %pc@(Lmmu),%a0
1114
        pmove   %psr,%a0@
1115
        clrl    %d7
1116
        movew   %a0@,%d7
1117
        jbsr    Lserial_putnum
1118
 
1119
        putr()
1120
        moveml  %sp@+,%a0/%d7
1121
        rts
1122
 
1123
        .data
1124
        .even
1125
#ifdef HACKER_KERNEL
1126
Lkernel_start:
1127
        .long 0
1128
#endif
1129
Lcustom:
1130
Liobase:
1131
        .long 0
1132
Lmmu:   .quad 0
1133
SYMBOL_NAME_LABEL(kpt)
1134
        .long 0
1135
SYMBOL_NAME_LABEL(availmem)
1136
        .long 0
1137
SYMBOL_NAME_LABEL(is_medusa)
1138
        .long 0
1139
SYMBOL_NAME_LABEL(m68k_pgtable_cachemode)
1140
        .long 0

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.