1 /* $NetBSD: atari_init.c,v 1.48 2000/03/28 23:57:25 simonb Exp $ */ 2 3 /* 4 * Copyright (c) 1995 Leo Weppelman 5 * Copyright (c) 1994 Michael L. Hitch 6 * Copyright (c) 1993 Markus Wild 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed by Markus Wild. 20 * 4. The name of the author may not be used to endorse or promote products 21 * derived from this software without specific prior written permission 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 */ 34 35 #include "opt_ddb.h" 36 37 #include <sys/param.h> 38 #include <sys/systm.h> 39 #include <sys/proc.h> 40 #include <vm/vm.h> 41 #include <sys/user.h> 42 #include <sys/ioctl.h> 43 #include <sys/select.h> 44 #include <sys/tty.h> 45 #include <sys/proc.h> 46 #include <sys/buf.h> 47 #include <sys/msgbuf.h> 48 #include <sys/mbuf.h> 49 #include <sys/extent.h> 50 #include <sys/protosw.h> 51 #include <sys/domain.h> 52 #include <sys/dkbad.h> 53 #include <sys/reboot.h> 54 #include <sys/exec.h> 55 #include <sys/core.h> 56 #include <sys/kcore.h> 57 #include <vm/pmap.h> 58 59 #include <machine/vmparam.h> 60 #include <machine/pte.h> 61 #include <machine/cpu.h> 62 #include <machine/iomap.h> 63 #include <machine/mfp.h> 64 #include <machine/scu.h> 65 #include <machine/acia.h> 66 #include <machine/kcore.h> 67 68 #include <m68k/cpu.h> 69 #include <m68k/cacheops.h> 70 71 #include <atari/atari/intr.h> 72 #include <atari/atari/stalloc.h> 73 #include <atari/dev/ym2149reg.h> 74 75 #include "pci.h" 76 77 void start_c __P((int, u_int, u_int, u_int, char *)); 78 static void atari_hwinit __P((void)); 79 static void cpu_init_kcorehdr __P((u_long)); 80 static void initcpu __P((void)); 81 static void mmu030_setup __P((st_entry_t *, u_int, pt_entry_t *, u_int, 82 pt_entry_t *, u_int, u_int)); 83 static void map_io_areas __P((pt_entry_t *, u_int, u_int)); 84 static void set_machtype __P((void)); 85 86 #if defined(M68040) || defined(M68060) 87 static void mmu040_setup __P((st_entry_t *, u_int, pt_entry_t *, u_int, 88 pt_entry_t *, u_int, u_int)); 89 #endif 90 91 /* 92 * Extent maps to manage all memory space, including I/O ranges. Allocate 93 * storage for 8 regions in each, initially. Later, iomem_malloc_safe 94 * will indicate that it's safe to use malloc() to dynamically allocate 95 * region descriptors. 96 * This means that the fixed static storage is only used for registrating 97 * the found memory regions and the bus-mapping of the console. 98 * 99 * The extent maps are not static! They are used for bus address space 100 * allocation. 101 */ 102 static long iomem_ex_storage[EXTENT_FIXED_STORAGE_SIZE(8) / sizeof(long)]; 103 struct extent *iomem_ex; 104 int iomem_malloc_safe; 105 106 /* 107 * All info needed to generate a panic dump. All fields are setup by 108 * start_c(). 109 * XXX: Should sheck usage of phys_segs. There is some unwanted overlap 110 * here.... Also, the name is badly choosen. Phys_segs contains the 111 * segment descriptions _after_ reservations are made. 112 * XXX: 'lowram' is obsoleted by the new panicdump format 113 */ 114 static cpu_kcore_hdr_t cpu_kcore_hdr; 115 116 extern u_int lowram; 117 extern u_int Sysptsize, Sysseg_pa, proc0paddr; 118 extern pt_entry_t *Sysptmap; 119 extern st_entry_t *Sysseg; 120 u_int *Sysmap; 121 int machineid, mmutype, cputype, astpending; 122 char *vmmap; 123 pv_entry_t pv_table; 124 #if defined(M68040) || defined(M68060) 125 extern int protostfree; 126 #endif 127 128 extern char *esym; 129 extern struct pcb *curpcb; 130 131 /* 132 * This is the virtual address of physical page 0. Used by 'do_boot()'. 133 */ 134 vaddr_t page_zero; 135 136 /* 137 * Crude support for allocation in ST-ram. Currently only used to allocate 138 * video ram. 139 * The physical address is also returned because the video init needs it to 140 * setup the controller at the time the vm-system is not yet operational so 141 * 'kvtop()' cannot be used. 142 */ 143 #ifndef ST_POOL_SIZE 144 #define ST_POOL_SIZE 40 /* XXX: enough? */ 145 #endif 146 147 u_long st_pool_size = ST_POOL_SIZE * NBPG; /* Patchable */ 148 u_long st_pool_virt, st_pool_phys; 149 150 /* 151 * Are we relocating the kernel to TT-Ram if possible? It is faster, but 152 * it is also reported not to work on all TT's. So the default is NO. 153 */ 154 #ifndef RELOC_KERNEL 155 #define RELOC_KERNEL 0 156 #endif 157 int reloc_kernel = RELOC_KERNEL; /* Patchable */ 158 159 /* 160 * this is the C-level entry function, it's called from locore.s. 161 * Preconditions: 162 * Interrupts are disabled 163 * PA == VA, we don't have to relocate addresses before enabling 164 * the MMU 165 * Exec is no longer available (because we're loaded all over 166 * low memory, no ExecBase is available anymore) 167 * 168 * It's purpose is: 169 * Do the things that are done in locore.s in the hp300 version, 170 * this includes allocation of kernel maps and enabling the MMU. 171 * 172 * Some of the code in here is `stolen' from Amiga MACH, and was 173 * written by Bryan Ford and Niklas Hallqvist. 174 * 175 * Very crude 68040 support by Michael L. Hitch. 176 */ 177 178 void 179 start_c(id, ttphystart, ttphysize, stphysize, esym_addr) 180 int id; /* Machine id */ 181 u_int ttphystart, ttphysize; /* Start address and size of TT-ram */ 182 u_int stphysize; /* Size of ST-ram */ 183 char *esym_addr; /* Address of kernel '_esym' symbol */ 184 { 185 extern char end[]; 186 extern void etext __P((void)); 187 extern u_long protorp[2]; 188 u_int pstart; /* Next available physical address*/ 189 u_int vstart; /* Next available virtual address */ 190 u_int avail; 191 pt_entry_t *pt; 192 u_int ptsize, ptextra; 193 u_int tc, i; 194 u_int *pg; 195 u_int pg_proto; 196 u_int end_loaded; 197 u_long kbase; 198 u_int kstsize; 199 200 boot_segs[0].start = 0; 201 boot_segs[0].end = stphysize; 202 boot_segs[1].start = ttphystart; 203 boot_segs[1].end = ttphystart + ttphysize; 204 boot_segs[2].start = boot_segs[2].end = 0; /* End of segments! */ 205 206 /* 207 * The following is a hack. We do not know how much ST memory we 208 * really need until after configuration has finished. At this 209 * time I have no idea how to grab ST memory at that time. 210 * The round_page() call is ment to correct errors made by 211 * binpatching! 212 */ 213 st_pool_size = m68k_round_page(st_pool_size); 214 st_pool_phys = stphysize - st_pool_size; 215 stphysize = st_pool_phys; 216 217 machineid = id; 218 esym = esym_addr; 219 220 /* 221 * the kernel ends at end() or esym. 222 */ 223 if(esym == NULL) 224 end_loaded = (u_int)end; 225 else end_loaded = (u_int)esym; 226 227 /* 228 * If we have enough fast-memory to put the kernel in and the 229 * RELOC_KERNEL option is set, do it! 230 */ 231 if((reloc_kernel != 0) && (ttphysize >= end_loaded)) 232 kbase = ttphystart; 233 else kbase = 0; 234 235 /* 236 * update these as soon as possible! 237 */ 238 PAGE_SIZE = NBPG; 239 PAGE_MASK = NBPG-1; 240 PAGE_SHIFT = PG_SHIFT; 241 242 /* 243 * Determine the type of machine we are running on. This needs 244 * to be done early (and before initcpu())! 245 */ 246 set_machtype(); 247 248 /* 249 * Initialize cpu specific stuff 250 */ 251 initcpu(); 252 253 /* 254 * We run the kernel from ST memory at the moment. 255 * The kernel segment table is put just behind the loaded image. 256 * pstart: start of usable ST memory 257 * avail : size of ST memory available. 258 */ 259 pstart = (u_int)end_loaded; 260 pstart = m68k_round_page(pstart); 261 avail = stphysize - pstart; 262 263 /* 264 * Calculate the number of pages needed for Sysseg. 265 * For the 68030, we need 256 descriptors (segment-table-entries). 266 * This easily fits into one page. 267 * For the 68040, both the level-1 and level-2 descriptors are 268 * stored into Sysseg. We currently handle a maximum sum of MAXKL2SIZE 269 * level-1 & level-2 tables. 270 */ 271 #if defined(M68040) || defined(M68060) 272 if (mmutype == MMU_68040) 273 kstsize = MAXKL2SIZE / (NPTEPG/SG4_LEV2SIZE); 274 else 275 #endif 276 kstsize = 1; 277 /* 278 * allocate the kernel segment table 279 */ 280 Sysseg = (st_entry_t *)pstart; 281 Sysseg_pa = (u_int)Sysseg + kbase; 282 pstart += kstsize * NBPG; 283 avail -= kstsize * NBPG; 284 285 /* 286 * Determine the number of pte's we need for extra's like 287 * ST I/O map's. 288 */ 289 ptextra = btoc(STIO_SIZE); 290 291 /* 292 * If present, add pci areas 293 */ 294 if (machineid & ATARI_HADES) 295 ptextra += btoc(PCI_CONF_SIZE + PCI_IO_SIZE + PCI_VGA_SIZE); 296 ptextra += btoc(BOOTM_VA_POOL); 297 298 /* 299 * The 'pt' (the initial kernel pagetable) has to map the kernel and 300 * the I/O areas. The various I/O areas are mapped (virtually) at 301 * the top of the address space mapped by 'pt' (ie. just below Sysmap). 302 */ 303 pt = (pt_entry_t *)pstart; 304 ptsize = (Sysptsize + howmany(ptextra, NPTEPG)) << PGSHIFT; 305 pstart += ptsize; 306 avail -= ptsize; 307 308 /* 309 * allocate kernel page table map 310 */ 311 Sysptmap = (pt_entry_t *)pstart; 312 pstart += NBPG; 313 avail -= NBPG; 314 315 /* 316 * Set Sysmap; mapped after page table pages. Because I too (LWP) 317 * didn't understand the reason for this, I borrowed the following 318 * (sligthly modified) comment from mac68k/locore.s: 319 * LAK: There seems to be some confusion here about the next line, 320 * so I'll explain. The kernel needs some way of dynamically modifying 321 * the page tables for its own virtual memory. What it does is that it 322 * has a page table map. This page table map is mapped right after the 323 * kernel itself (in our implementation; in HP's it was after the I/O 324 * space). Therefore, the first three (or so) entries in the segment 325 * table point to the first three pages of the page tables (which 326 * point to the kernel) and the next entry in the segment table points 327 * to the page table map (this is done later). Therefore, the value 328 * of the pointer "Sysmap" will be something like 16M*3 = 48M. When 329 * the kernel addresses this pointer (e.g., Sysmap[0]), it will get 330 * the first longword of the first page map (== pt[0]). Since the 331 * page map mirrors the segment table, addressing any index of Sysmap 332 * will give you a PTE of the page maps which map the kernel. 333 */ 334 Sysmap = (u_int *)(ptsize << (SEGSHIFT - PGSHIFT)); 335 336 /* 337 * Initialize segment tables 338 */ 339 #if defined(M68040) || defined(M68060) 340 if (mmutype == MMU_68040) 341 mmu040_setup(Sysseg, kstsize, pt, ptsize, Sysptmap, 1, kbase); 342 else 343 #endif /* defined(M68040) || defined(M68060) */ 344 mmu030_setup(Sysseg, kstsize, pt, ptsize, Sysptmap, 1, kbase); 345 346 /* 347 * initialize kernel page table page(s). 348 * Assume load at VA 0. 349 * - Text pages are RO 350 * - Page zero is invalid 351 */ 352 pg_proto = (0 + kbase) | PG_RO | PG_V; 353 pg = pt; 354 *pg++ = PG_NV; pg_proto += NBPG; 355 for(i = NBPG; i < (u_int)etext; i += NBPG, pg_proto += NBPG) 356 *pg++ = pg_proto; 357 358 /* 359 * data, bss and dynamic tables are read/write 360 */ 361 pg_proto = (pg_proto & PG_FRAME) | PG_RW | PG_V; 362 363 #if defined(M68040) || defined(M68060) 364 /* 365 * Map the kernel segment table cache invalidated for 366 * these machines (for the 68040 not strictly necessary, but 367 * recommended by Motorola; for the 68060 mandatory) 368 */ 369 if (mmutype == MMU_68040) { 370 for (; i < (u_int)Sysseg; i += NBPG, pg_proto += NBPG) 371 *pg++ = pg_proto; 372 pg_proto = (pg_proto & ~PG_CCB) | PG_CI; 373 for (; i < (u_int)&Sysseg[kstsize * NPTEPG]; i += NBPG, 374 pg_proto += NBPG) 375 *pg++ = pg_proto; 376 pg_proto = (pg_proto & ~PG_CI) | PG_CCB; 377 } 378 #endif /* defined(M68040) || defined(M68060) */ 379 380 /* 381 * go till end of data allocated so far 382 * plus proc0 u-area (to be allocated) 383 */ 384 for(; i < pstart + USPACE; i += NBPG, pg_proto += NBPG) 385 *pg++ = pg_proto; 386 387 /* 388 * invalidate remainder of kernel PT 389 */ 390 while(pg < &pt[ptsize/sizeof(pt_entry_t)]) 391 *pg++ = PG_NV; 392 393 /* 394 * Map various I/O areas 395 */ 396 map_io_areas(pt, ptsize, ptextra); 397 398 /* 399 * Save KVA of proc0 user-area and allocate it 400 */ 401 proc0paddr = pstart; 402 pstart += USPACE; 403 avail -= USPACE; 404 405 /* 406 * At this point, virtual and physical allocation starts to divert. 407 */ 408 vstart = pstart; 409 410 /* 411 * Map the allocated space in ST-ram now. In the contig-case, there 412 * is no need to make a distinction between virtual and physical 413 * adresses. But I make it anyway to be prepared. 414 * Physcal space is already reserved! 415 */ 416 st_pool_virt = vstart; 417 pg = &pt[vstart / NBPG]; 418 pg_proto = st_pool_phys | PG_RW | PG_CI | PG_V; 419 vstart += st_pool_size; 420 while(pg_proto < (st_pool_phys + st_pool_size)) { 421 *pg++ = pg_proto; 422 pg_proto += NBPG; 423 } 424 425 /* 426 * Map physical page_zero and page-zero+1 (First ST-ram page). We need 427 * to reference it in the reboot code. Two pages are mapped, because 428 * we must make sure 'doboot()' is contained in it (see the tricky 429 * copying there....). 430 */ 431 page_zero = vstart; 432 pg = &pt[vstart / NBPG]; 433 *pg++ = PG_RW | PG_CI | PG_V; 434 vstart += NBPG; 435 *pg = PG_RW | PG_CI | PG_V | NBPG; 436 vstart += NBPG; 437 438 lowram = 0 >> PGSHIFT; /* XXX */ 439 440 /* 441 * Fill in usable segments. The page indexes will be initialized 442 * later when all reservations are made. 443 */ 444 usable_segs[0].start = 0; 445 usable_segs[0].end = stphysize; 446 usable_segs[1].start = ttphystart; 447 usable_segs[1].end = ttphystart + ttphysize; 448 usable_segs[2].start = usable_segs[2].end = 0; /* End of segments! */ 449 450 if(kbase) { 451 /* 452 * First page of ST-ram is unusable, reserve the space 453 * for the kernel in the TT-ram segment. 454 * Note: Because physical page-zero is partially mapped to ROM 455 * by hardware, it is unusable. 456 */ 457 usable_segs[0].start = NBPG; 458 usable_segs[1].start += pstart; 459 } 460 else usable_segs[0].start += pstart; 461 462 /* 463 * As all segment sizes are now valid, calculate page indexes and 464 * available physical memory. 465 */ 466 usable_segs[0].first_page = 0; 467 for (i = 1; usable_segs[i].start; i++) { 468 usable_segs[i].first_page = usable_segs[i-1].first_page; 469 usable_segs[i].first_page += 470 (usable_segs[i-1].end - usable_segs[i-1].start) / NBPG; 471 } 472 for (i = 0, physmem = 0; usable_segs[i].start; i++) 473 physmem += usable_segs[i].end - usable_segs[i].start; 474 physmem >>= PGSHIFT; 475 476 /* 477 * get the pmap module in sync with reality. 478 */ 479 pmap_bootstrap(vstart, stio_addr, ptextra); 480 481 /* 482 * Prepare to enable the MMU. 483 * Setup and load SRP nolimit, share global, 4 byte PTE's 484 */ 485 protorp[0] = 0x80000202; 486 protorp[1] = (u_int)Sysseg + kbase; /* + segtable address */ 487 Sysseg_pa = (u_int)Sysseg + kbase; 488 489 cpu_init_kcorehdr(kbase); 490 491 /* 492 * copy over the kernel (and all now initialized variables) 493 * to fastram. DONT use bcopy(), this beast is much larger 494 * than 128k ! 495 */ 496 if(kbase) { 497 register u_long *lp, *le, *fp; 498 499 lp = (u_long *)0; 500 le = (u_long *)pstart; 501 fp = (u_long *)kbase; 502 while(lp < le) 503 *fp++ = *lp++; 504 } 505 #if defined(M68040) || defined(M68060) 506 if (mmutype == MMU_68040) { 507 /* 508 * movel Sysseg_pa,a0; 509 * movec a0,SRP; 510 * pflusha; 511 * movel #$0xc000,d0; 512 * movec d0,TC 513 */ 514 if (cputype == CPU_68060) { 515 /* XXX: Need the branch cache be cleared? */ 516 asm volatile (".word 0x4e7a,0x0002;" 517 "orl #0x400000,d0;" 518 ".word 0x4e7b,0x0002" : : : "d0"); 519 } 520 asm volatile ("movel %0,a0;" 521 ".word 0x4e7b,0x8807" : : "a" (Sysseg_pa) : "a0"); 522 asm volatile (".word 0xf518" : : ); 523 asm volatile ("movel #0xc000,d0;" 524 ".word 0x4e7b,0x0003" : : : "d0" ); 525 } else 526 #endif 527 { 528 asm volatile ("pmove %0@,srp" : : "a" (&protorp[0])); 529 /* 530 * setup and load TC register. 531 * enable_cpr, enable_srp, pagesize=8k, 532 * A = 8 bits, B = 11 bits 533 */ 534 tc = 0x82d08b00; 535 asm volatile ("pmove %0@,tc" : : "a" (&tc)); 536 } 537 538 /* Is this to fool the optimizer?? */ 539 i = *(int *)proc0paddr; 540 *(volatile int *)proc0paddr = i; 541 542 /* 543 * Initialize the "u-area" pages. 544 * Must initialize p_addr before autoconfig or the 545 * fault handler will get a NULL reference. 546 */ 547 bzero((u_char *)proc0paddr, USPACE); 548 proc0.p_addr = (struct user *)proc0paddr; 549 curproc = &proc0; 550 curpcb = &((struct user *)proc0paddr)->u_pcb; 551 552 /* 553 * Get the hardware into a defined state 554 */ 555 atari_hwinit(); 556 557 /* 558 * Initialize stmem allocator 559 */ 560 init_stmem(); 561 562 /* 563 * Initialize the I/O mem extent map. 564 * Note: we don't have to check the return value since 565 * creation of a fixed extent map will never fail (since 566 * descriptor storage has already been allocated). 567 * 568 * N.B. The iomem extent manages _all_ physical addresses 569 * on the machine. When the amount of RAM is found, all 570 * extents of RAM are allocated from the map. 571 */ 572 iomem_ex = extent_create("iomem", 0x0, 0xffffffff, M_DEVBUF, 573 (caddr_t)iomem_ex_storage, sizeof(iomem_ex_storage), 574 EX_NOCOALESCE|EX_NOWAIT); 575 576 /* 577 * Allocate the physical RAM from the extent map 578 */ 579 for (i = 0; boot_segs[i].end != 0; i++) { 580 if (extent_alloc_region(iomem_ex, boot_segs[i].start, 581 boot_segs[i].end - boot_segs[i].start, EX_NOWAIT)) { 582 /* XXX: Ahum, should not happen ;-) */ 583 printf("Warning: Cannot allocate boot memory from" 584 " extent map!?\n"); 585 } 586 } 587 588 /* 589 * Initialize interrupt mapping. 590 */ 591 intr_init(); 592 } 593 594 /* 595 * Try to figure out on what type of machine we are running 596 * Note: This module runs *before* the io-mapping is setup! 597 */ 598 static void 599 set_machtype() 600 { 601 stio_addr = 0xff8000; /* XXX: For TT & Falcon only */ 602 if(badbaddr((caddr_t)&MFP2->mf_gpip, sizeof(char))) { 603 /* 604 * Watch out! We can also have a Hades with < 16Mb 605 * RAM here... 606 */ 607 if(!badbaddr((caddr_t)&MFP->mf_gpip, sizeof(char))) { 608 machineid |= ATARI_FALCON; 609 return; 610 } 611 } 612 if(!badbaddr((caddr_t)(PCI_CONFB_PHYS + PCI_CONFM_PHYS), sizeof(char))) 613 machineid |= ATARI_HADES; 614 else machineid |= ATARI_TT; 615 } 616 617 static void 618 atari_hwinit() 619 { 620 /* 621 * Initialize the sound chip 622 */ 623 ym2149_init(); 624 625 /* 626 * Make sure that the midi acia will not generate an interrupt 627 * unless something attaches to it. We cannot do this for the 628 * keyboard acia because this breaks the '-d' option of the 629 * booter... 630 */ 631 MDI->ac_cs = 0; 632 633 /* 634 * Initialize both MFP chips (if both present!) to generate 635 * auto-vectored interrupts with EOI. The active-edge registers are 636 * set up. The interrupt enable registers are set to disable all 637 * interrupts. 638 */ 639 MFP->mf_iera = MFP->mf_ierb = 0; 640 MFP->mf_imra = MFP->mf_imrb = 0; 641 MFP->mf_aer = MFP->mf_ddr = 0; 642 MFP->mf_vr = 0x40; 643 if(machineid & (ATARI_TT|ATARI_HADES)) { 644 MFP2->mf_iera = MFP2->mf_ierb = 0; 645 MFP2->mf_imra = MFP2->mf_imrb = 0; 646 MFP2->mf_aer = 0x80; 647 MFP2->mf_vr = 0x50; 648 } 649 if(machineid & ATARI_TT) { 650 /* 651 * Initialize the SCU, to enable interrupts on the SCC (ipl5), 652 * MFP (ipl6) and softints (ipl1). 653 */ 654 SCU->sys_mask = SCU_SYS_SOFT; 655 SCU->vme_mask = SCU_MFP | SCU_SCC; 656 #ifdef DDB 657 /* 658 * This allows people with the correct hardware modification 659 * to drop into the debugger from an NMI. 660 */ 661 SCU->sys_mask |= SCU_IRQ7; 662 #endif 663 } 664 665 #if NPCI > 0 666 if(machineid & ATARI_HADES) { 667 /* 668 * Configure PCI-bus 669 */ 670 init_pci_bus(); 671 } 672 #endif 673 674 } 675 676 /* 677 * Do the dull work of mapping the various I/O areas. They MUST be Cache 678 * inhibited! 679 * All I/O areas are virtually mapped at the end of the pt-table. 680 */ 681 static void 682 map_io_areas(pt, ptsize, ptextra) 683 pt_entry_t *pt; 684 u_int ptsize; /* Size of 'pt' in bytes */ 685 u_int ptextra; /* #of additional I/O pte's */ 686 { 687 extern void bootm_init __P((vaddr_t, pt_entry_t *, u_long)); 688 vaddr_t ioaddr; 689 pt_entry_t *pg, *epg; 690 pt_entry_t pg_proto; 691 u_long mask; 692 693 ioaddr = ((ptsize / sizeof(pt_entry_t)) - ptextra) * NBPG; 694 695 /* 696 * Map ST-IO area 697 */ 698 stio_addr = ioaddr; 699 ioaddr += STIO_SIZE; 700 pg = &pt[stio_addr / NBPG]; 701 epg = &pg[btoc(STIO_SIZE)]; 702 pg_proto = STIO_PHYS | PG_RW | PG_CI | PG_V; 703 while(pg < epg) { 704 *pg++ = pg_proto; 705 pg_proto += NBPG; 706 } 707 708 /* 709 * Map PCI areas 710 */ 711 if (machineid & ATARI_HADES) { 712 713 pci_conf_addr = ioaddr; 714 ioaddr += PCI_CONF_SIZE; 715 pg = &pt[pci_conf_addr / NBPG]; 716 epg = &pg[btoc(PCI_CONF_SIZE)]; 717 mask = PCI_CONFM_PHYS; 718 pg_proto = PCI_CONFB_PHYS | PG_RW | PG_CI | PG_V; 719 for(; pg < epg; mask <<= 1) 720 *pg++ = pg_proto | mask; 721 722 pci_io_addr = ioaddr; 723 ioaddr += PCI_IO_SIZE; 724 epg = &pg[btoc(PCI_IO_SIZE)]; 725 pg_proto = PCI_IO_PHYS | PG_RW | PG_CI | PG_V; 726 while(pg < epg) { 727 *pg++ = pg_proto; 728 pg_proto += NBPG; 729 } 730 731 pci_mem_addr = ioaddr; 732 ioaddr += PCI_VGA_SIZE; 733 epg = &pg[btoc(PCI_VGA_SIZE)]; 734 pg_proto = PCI_VGA_PHYS | PG_RW | PG_CI | PG_V; 735 while(pg < epg) { 736 *pg++ = pg_proto; 737 pg_proto += NBPG; 738 } 739 } 740 741 bootm_init(ioaddr, pg, BOOTM_VA_POOL); 742 /* 743 * ioaddr += BOOTM_VA_POOL; 744 * pg = &pg[btoc(BOOTM_VA_POOL)]; 745 */ 746 } 747 748 /* 749 * Used by dumpconf() to get the size of the machine-dependent panic-dump 750 * header in disk blocks. 751 */ 752 int 753 cpu_dumpsize() 754 { 755 int size; 756 757 size = ALIGN(sizeof(kcore_seg_t)) + ALIGN(sizeof(cpu_kcore_hdr_t)); 758 return (btodb(roundup(size, dbtob(1)))); 759 } 760 761 /* 762 * Called by dumpsys() to dump the machine-dependent header. 763 * XXX: Assumes that it will all fit in one diskblock. 764 */ 765 int 766 cpu_dump(dump, p_blkno) 767 int (*dump) __P((dev_t, daddr_t, caddr_t, size_t)); 768 daddr_t *p_blkno; 769 { 770 int buf[dbtob(1)/sizeof(int)]; 771 int error; 772 kcore_seg_t *kseg_p; 773 cpu_kcore_hdr_t *chdr_p; 774 775 kseg_p = (kcore_seg_t *)buf; 776 chdr_p = (cpu_kcore_hdr_t *)&buf[ALIGN(sizeof(*kseg_p)) / sizeof(int)]; 777 778 /* 779 * Generate a segment header 780 */ 781 CORE_SETMAGIC(*kseg_p, KCORE_MAGIC, MID_MACHINE, CORE_CPU); 782 kseg_p->c_size = dbtob(1) - ALIGN(sizeof(*kseg_p)); 783 784 /* 785 * Add the md header 786 */ 787 *chdr_p = cpu_kcore_hdr; 788 error = dump(dumpdev, *p_blkno, (caddr_t)buf, dbtob(1)); 789 *p_blkno += 1; 790 return (error); 791 } 792 793 #if (M68K_NPHYS_RAM_SEGS < NMEM_SEGS) 794 #error "Configuration error: M68K_NPHYS_RAM_SEGS < NMEM_SEGS" 795 #endif 796 /* 797 * Initialize the cpu_kcore_header. 798 */ 799 static void 800 cpu_init_kcorehdr(kbase) 801 u_long kbase; 802 { 803 cpu_kcore_hdr_t *h = &cpu_kcore_hdr; 804 struct m68k_kcore_hdr *m = &h->un._m68k; 805 extern char end[]; 806 int i; 807 808 bzero(&cpu_kcore_hdr, sizeof(cpu_kcore_hdr)); 809 810 /* 811 * Initialize the `dispatcher' portion of the header. 812 */ 813 strcpy(h->name, machine); 814 h->page_size = NBPG; 815 h->kernbase = KERNBASE; 816 817 /* 818 * Fill in information about our MMU configuration. 819 */ 820 m->mmutype = mmutype; 821 m->sg_v = SG_V; 822 m->sg_frame = SG_FRAME; 823 m->sg_ishift = SG_ISHIFT; 824 m->sg_pmask = SG_PMASK; 825 m->sg40_shift1 = SG4_SHIFT1; 826 m->sg40_mask2 = SG4_MASK2; 827 m->sg40_shift2 = SG4_SHIFT2; 828 m->sg40_mask3 = SG4_MASK3; 829 m->sg40_shift3 = SG4_SHIFT3; 830 m->sg40_addr1 = SG4_ADDR1; 831 m->sg40_addr2 = SG4_ADDR2; 832 m->pg_v = PG_V; 833 m->pg_frame = PG_FRAME; 834 835 /* 836 * Initialize pointer to kernel segment table. 837 */ 838 m->sysseg_pa = (u_int)Sysseg + kbase; 839 840 /* 841 * Initialize relocation value such that: 842 * 843 * pa = (va - KERNBASE) + reloc 844 */ 845 m->reloc = kbase; 846 847 /* 848 * Define the end of the relocatable range. 849 */ 850 m->relocend = (u_int32_t)end; 851 852 for (i = 0; i < NMEM_SEGS; i++) { 853 m->ram_segs[i].start = boot_segs[i].start; 854 m->ram_segs[i].size = boot_segs[i].end - 855 boot_segs[i].start; 856 } 857 } 858 859 void 860 mmu030_setup(sysseg, kstsize, pt, ptsize, sysptmap, sysptsize, kbase) 861 st_entry_t *sysseg; /* System segment table */ 862 u_int kstsize; /* size of 'sysseg' in pages */ 863 pt_entry_t *pt; /* Kernel page table */ 864 u_int ptsize; /* size of 'pt' in bytes */ 865 pt_entry_t *sysptmap; /* System page table */ 866 u_int sysptsize; /* size of 'sysptmap' in pages */ 867 u_int kbase; 868 { 869 st_entry_t sg_proto, *sg; 870 pt_entry_t pg_proto, *pg, *epg; 871 872 sg_proto = ((u_int)pt + kbase) | SG_RW | SG_V; 873 pg_proto = ((u_int)pt + kbase) | PG_RW | PG_CI | PG_V; 874 875 /* 876 * Map the page table pages in both the HW segment table 877 * and the software Sysptmap. Note that Sysptmap is also 878 * considered a PT page, hence the +sysptsize. 879 */ 880 sg = sysseg; 881 pg = sysptmap; 882 epg = &pg[(ptsize >> PGSHIFT) + sysptsize]; 883 while(pg < epg) { 884 *sg++ = sg_proto; 885 *pg++ = pg_proto; 886 sg_proto += NBPG; 887 pg_proto += NBPG; 888 } 889 890 /* 891 * invalidate the remainder of the tables 892 */ 893 epg = &sysptmap[sysptsize * NPTEPG]; 894 while(pg < epg) { 895 *sg++ = SG_NV; 896 *pg++ = PG_NV; 897 } 898 } 899 900 #if defined(M68040) || defined(M68060) 901 void 902 mmu040_setup(sysseg, kstsize, pt, ptsize, sysptmap, sysptsize, kbase) 903 st_entry_t *sysseg; /* System segment table */ 904 u_int kstsize; /* size of 'sysseg' in pages */ 905 pt_entry_t *pt; /* Kernel page table */ 906 u_int ptsize; /* size of 'pt' in bytes */ 907 pt_entry_t *sysptmap; /* System page table */ 908 u_int sysptsize; /* size of 'sysptmap' in pages */ 909 u_int kbase; 910 { 911 int i; 912 st_entry_t sg_proto, *sg, *esg; 913 pt_entry_t pg_proto; 914 915 /* 916 * First invalidate the entire "segment table" pages 917 * (levels 1 and 2 have the same "invalid" values). 918 */ 919 sg = sysseg; 920 esg = &sg[kstsize * NPTEPG]; 921 while (sg < esg) 922 *sg++ = SG_NV; 923 924 /* 925 * Initialize level 2 descriptors (which immediately 926 * follow the level 1 table). These should map 'pt' + 'sysptmap'. 927 * We need: 928 * NPTEPG / SG4_LEV3SIZE 929 * level 2 descriptors to map each of the nptpages + 1 930 * pages of PTEs. Note that we set the "used" bit 931 * now to save the HW the expense of doing it. 932 */ 933 i = ((ptsize >> PGSHIFT) + sysptsize) * (NPTEPG / SG4_LEV3SIZE); 934 sg = &sysseg[SG4_LEV1SIZE]; 935 esg = &sg[i]; 936 sg_proto = ((u_int)pt + kbase) | SG_U | SG_RW | SG_V; 937 while (sg < esg) { 938 *sg++ = sg_proto; 939 sg_proto += (SG4_LEV3SIZE * sizeof (st_entry_t)); 940 } 941 942 /* 943 * Initialize level 1 descriptors. We need: 944 * roundup(num, SG4_LEV2SIZE) / SG4_LEVEL2SIZE 945 * level 1 descriptors to map the 'num' level 2's. 946 */ 947 i = roundup(i, SG4_LEV2SIZE) / SG4_LEV2SIZE; 948 protostfree = (-1 << (i + 1)) /* & ~(-1 << MAXKL2SIZE) */; 949 sg = sysseg; 950 esg = &sg[i]; 951 sg_proto = ((u_int)&sg[SG4_LEV1SIZE] + kbase) | SG_U | SG_RW |SG_V; 952 while (sg < esg) { 953 *sg++ = sg_proto; 954 sg_proto += (SG4_LEV2SIZE * sizeof(st_entry_t)); 955 } 956 957 /* 958 * Initialize sysptmap 959 */ 960 sg = sysptmap; 961 esg = &sg[(ptsize >> PGSHIFT) + sysptsize]; 962 pg_proto = ((u_int)pt + kbase) | PG_RW | PG_CI | PG_V; 963 while (sg < esg) { 964 *sg++ = pg_proto; 965 pg_proto += NBPG; 966 } 967 /* 968 * Invalidate rest of Sysptmap page 969 */ 970 esg = &sysptmap[sysptsize * NPTEPG]; 971 while (sg < esg) 972 *sg++ = SG_NV; 973 } 974 #endif /* M68040 */ 975 976 #if defined(M68060) 977 int m68060_pcr_init = 0x21; /* make this patchable */ 978 #endif 979 980 static void 981 initcpu() 982 { 983 typedef void trapfun __P((void)); 984 985 switch (cputype) { 986 987 #if defined(M68060) 988 case CPU_68060: 989 { 990 extern trapfun *vectab[256]; 991 extern trapfun buserr60, addrerr4060, fpfault; 992 #if defined(M060SP) 993 extern u_int8_t FP_CALL_TOP[], I_CALL_TOP[]; 994 #else 995 extern trapfun illinst; 996 #endif 997 998 asm volatile ("movl %0,d0; .word 0x4e7b,0x0808" : : 999 "d"(m68060_pcr_init):"d0" ); 1000 1001 /* bus/addrerr vectors */ 1002 vectab[2] = buserr60; 1003 vectab[3] = addrerr4060; 1004 1005 #if defined(M060SP) 1006 /* integer support */ 1007 vectab[61] = (trapfun *)&I_CALL_TOP[128 + 0x00]; 1008 1009 /* floating point support */ 1010 /* 1011 * XXX maybe we really should run-time check for the 1012 * stack frame format here: 1013 */ 1014 vectab[11] = (trapfun *)&FP_CALL_TOP[128 + 0x30]; 1015 1016 vectab[55] = (trapfun *)&FP_CALL_TOP[128 + 0x38]; 1017 vectab[60] = (trapfun *)&FP_CALL_TOP[128 + 0x40]; 1018 1019 vectab[54] = (trapfun *)&FP_CALL_TOP[128 + 0x00]; 1020 vectab[52] = (trapfun *)&FP_CALL_TOP[128 + 0x08]; 1021 vectab[53] = (trapfun *)&FP_CALL_TOP[128 + 0x10]; 1022 vectab[51] = (trapfun *)&FP_CALL_TOP[128 + 0x18]; 1023 vectab[50] = (trapfun *)&FP_CALL_TOP[128 + 0x20]; 1024 vectab[49] = (trapfun *)&FP_CALL_TOP[128 + 0x28]; 1025 #else 1026 vectab[61] = illinst; 1027 #endif 1028 vectab[48] = fpfault; 1029 } 1030 break; 1031 #endif /* defined(M68060) */ 1032 #if defined(M68040) 1033 case CPU_68040: 1034 { 1035 extern trapfun *vectab[256]; 1036 extern trapfun buserr40, addrerr4060; 1037 1038 /* bus/addrerr vectors */ 1039 vectab[2] = buserr40; 1040 vectab[3] = addrerr4060; 1041 } 1042 break; 1043 #endif /* defined(M68040) */ 1044 #if defined(M68030) || defined(M68020) 1045 case CPU_68030: 1046 case CPU_68020: 1047 { 1048 extern trapfun *vectab[256]; 1049 extern trapfun buserr2030, addrerr2030; 1050 1051 /* bus/addrerr vectors */ 1052 vectab[2] = buserr2030; 1053 vectab[3] = addrerr2030; 1054 } 1055 break; 1056 #endif /* defined(M68030) || defined(M68020) */ 1057 } 1058 1059 DCIS(); 1060 } 1061 1062 #ifdef DEBUG 1063 void dump_segtable __P((u_int *)); 1064 void dump_pagetable __P((u_int *, u_int, u_int)); 1065 u_int vmtophys __P((u_int *, u_int)); 1066 1067 void 1068 dump_segtable(stp) 1069 u_int *stp; 1070 { 1071 u_int *s, *es; 1072 int shift, i; 1073 1074 s = stp; 1075 { 1076 es = s + (ATARI_STSIZE >> 2); 1077 shift = SG_ISHIFT; 1078 } 1079 1080 /* 1081 * XXX need changes for 68040 1082 */ 1083 for (i = 0; s < es; s++, i++) 1084 if (*s & SG_V) 1085 printf("$%08x: $%08x\t", i << shift, *s & SG_FRAME); 1086 printf("\n"); 1087 } 1088 1089 void 1090 dump_pagetable(ptp, i, n) 1091 u_int *ptp, i, n; 1092 { 1093 u_int *p, *ep; 1094 1095 p = ptp + i; 1096 ep = p + n; 1097 for (; p < ep; p++, i++) 1098 if (*p & PG_V) 1099 printf("$%08x -> $%08x\t", i, *p & PG_FRAME); 1100 printf("\n"); 1101 } 1102 1103 u_int 1104 vmtophys(ste, vm) 1105 u_int *ste, vm; 1106 { 1107 ste = (u_int *) (*(ste + (vm >> SEGSHIFT)) & SG_FRAME); 1108 ste += (vm & SG_PMASK) >> PGSHIFT; 1109 return((*ste & -NBPG) | (vm & (NBPG - 1))); 1110 } 1111 1112 #endif 1113