1 /* $NetBSD: hpc_machdep.c,v 1.69 2003/07/15 00:25:09 lukem Exp $ */ 2 3 /* 4 * Copyright (c) 1994-1998 Mark Brinicombe. 5 * Copyright (c) 1994 Brini. 6 * All rights reserved. 7 * 8 * This code is derived from software written for Brini by Mark Brinicombe 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by Brini. 21 * 4. The name of the company nor the name of the author may be used to 22 * endorse or promote products derived from this software without specific 23 * prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED 26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 28 * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 29 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 30 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * SUCH DAMAGE. 36 * 37 * RiscBSD kernel project 38 * 39 * machdep.c 40 * 41 * Machine dependant functions for kernel setup 42 * 43 * This file needs a lot of work. 44 * 45 * Created : 17/09/94 46 */ 47 /* 48 * hpc_machdep.c 49 */ 50 51 #include <sys/cdefs.h> 52 __KERNEL_RCSID(0, "$NetBSD: hpc_machdep.c,v 1.69 2003/07/15 00:25:09 lukem Exp $"); 53 54 #include "opt_ddb.h" 55 #include "opt_pmap_debug.h" 56 #include "fs_nfs.h" 57 58 #include <sys/param.h> 59 #include <sys/systm.h> 60 #include <sys/kernel.h> 61 #include <sys/reboot.h> 62 #include <sys/proc.h> 63 #include <sys/msgbuf.h> 64 #include <sys/exec.h> 65 #include <sys/ksyms.h> 66 67 #include <dev/cons.h> 68 69 #include "ksyms.h" 70 71 #if NKSYMS || defined(DDB) || defined(LKM) 72 #include <machine/db_machdep.h> 73 #include <ddb/db_sym.h> 74 #include <ddb/db_extern.h> 75 #ifndef DB_ELFSIZE 76 #error Must define DB_ELFSIZE! 77 #endif 78 #define ELFSIZE DB_ELFSIZE 79 #include <sys/exec_elf.h> 80 #endif 81 82 #include <uvm/uvm.h> 83 84 #include <machine/signal.h> 85 #include <machine/frame.h> 86 #include <machine/bootconfig.h> 87 #include <machine/cpu.h> 88 #include <machine/io.h> 89 #include <machine/intr.h> 90 #include <arm/arm32/katelib.h> 91 #include <machine/bootinfo.h> 92 #include <arm/cpuconf.h> 93 #include <arm/undefined.h> 94 #include <machine/rtc.h> 95 #include <machine/platid.h> 96 97 #include <arm/sa11x0/sa11x0_reg.h> 98 99 #include <dev/hpc/bicons.h> 100 101 #include "opt_ipkdb.h" 102 103 /* XXX for consinit related hacks */ 104 #include <sys/conf.h> 105 106 #ifdef NFS 107 #include <sys/mount.h> 108 #include <nfs/rpcv2.h> 109 #include <nfs/nfsproto.h> 110 #include <nfs/nfs.h> 111 #include <nfs/nfsmount.h> 112 #endif 113 114 /* Kernel text starts 256K in from the bottom of the kernel address space. */ 115 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00040000) 116 #define KERNEL_VM_BASE (KERNEL_BASE + 0x00c00000) 117 #define KERNEL_VM_SIZE 0x05000000 118 119 /* 120 * Address to call from cpu_reset() to reset the machine. 121 * This is machine architecture dependant as it varies depending 122 * on where the ROM appears when you turn the MMU off. 123 */ 124 125 u_int cpu_reset_address = 0; 126 127 /* Define various stack sizes in pages */ 128 #define IRQ_STACK_SIZE 1 129 #define ABT_STACK_SIZE 1 130 #ifdef IPKDB 131 #define UND_STACK_SIZE 2 132 #else 133 #define UND_STACK_SIZE 1 134 #endif 135 136 BootConfig bootconfig; /* Boot config storage */ 137 struct bootinfo *bootinfo, bootinfo_storage; 138 static char booted_kernel_storage[80]; 139 char *booted_kernel = booted_kernel_storage; 140 141 paddr_t physical_start; 142 paddr_t physical_freestart; 143 paddr_t physical_freeend; 144 paddr_t physical_end; 145 int physmem = 0; 146 147 #ifndef PMAP_STATIC_L1S 148 int max_processes = 64; /* Default number */ 149 #endif /* !PMAP_STATIC_L1S */ 150 151 152 /* Physical and virtual addresses for some global pages */ 153 pv_addr_t systempage; 154 pv_addr_t irqstack; 155 pv_addr_t undstack; 156 pv_addr_t abtstack; 157 pv_addr_t kernelstack; 158 159 char *boot_args = NULL; 160 char boot_file[16]; 161 162 vaddr_t msgbufphys; 163 164 extern u_int data_abort_handler_address; 165 extern u_int prefetch_abort_handler_address; 166 extern u_int undefined_handler_address; 167 extern int end; 168 169 #ifdef PMAP_DEBUG 170 extern int pmap_debug_level; 171 #endif /* PMAP_DEBUG */ 172 173 #define KERNEL_PT_VMEM 0 /* Page table for mapping video memory */ 174 #define KERNEL_PT_SYS 1 /* Page table for mapping proc0 zero page */ 175 #define KERNEL_PT_KERNEL 2 /* Page table for mapping kernel */ 176 #define KERNEL_PT_IO 3 /* Page table for mapping IO */ 177 #define KERNEL_PT_VMDATA 4 /* Page tables for mapping kernel VM */ 178 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */ 179 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM) 180 181 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS]; 182 183 struct user *proc0paddr; 184 185 #define CPU_SA110_CACHE_CLEAN_SIZE (0x4000 * 2) 186 extern unsigned int sa1_cache_clean_addr; 187 extern unsigned int sa1_cache_clean_size; 188 static vaddr_t sa1_cc_base; 189 190 /* Non-buffered non-cachable memory needed to enter idle mode */ 191 extern vaddr_t sa11x0_idle_mem; 192 193 /* Prototypes */ 194 195 void physcon_display_base __P((u_int addr)); 196 void consinit __P((void)); 197 198 void data_abort_handler __P((trapframe_t *frame)); 199 void prefetch_abort_handler __P((trapframe_t *frame)); 200 void undefinedinstruction_bounce __P((trapframe_t *frame)); 201 202 u_int cpu_get_control __P((void)); 203 204 void rpc_sa110_cc_setup(void); 205 206 #ifdef DEBUG_BEFOREMMU 207 static void fakecninit(); 208 #endif 209 210 #ifdef BOOT_DUMP 211 void dumppages(char *, int); 212 #endif 213 214 u_int initarm(int, char **, struct bootinfo *); 215 extern int db_trapper(u_int, u_int, trapframe_t *, int); 216 extern void dump_spl_masks __P((void)); 217 extern void dumpsys __P((void)); 218 219 /* 220 * void cpu_reboot(int howto, char *bootstr) 221 * 222 * Reboots the system 223 * 224 * Deal with any syncing, unmounting, dumping and shutdown hooks, 225 * then reset the CPU. 226 */ 227 228 void 229 cpu_reboot(howto, bootstr) 230 int howto; 231 char *bootstr; 232 { 233 /* 234 * If we are still cold then hit the air brakes 235 * and crash to earth fast 236 */ 237 if (cold) { 238 doshutdownhooks(); 239 printf("Halted while still in the ICE age.\n"); 240 printf("The operating system has halted.\n"); 241 printf("Please press any key to reboot.\n\n"); 242 cngetc(); 243 printf("rebooting...\n"); 244 cpu_reset(); 245 /*NOTREACHED*/ 246 } 247 248 /* Disable console buffering */ 249 cnpollc(1); 250 251 /* 252 * If RB_NOSYNC was not specified sync the discs. 253 * Note: Unless cold is set to 1 here, syslogd will die during the unmount. 254 * It looks like syslogd is getting woken up only to find that it cannot 255 * page part of the binary in as the filesystem has been unmounted. 256 */ 257 if (!(howto & RB_NOSYNC)) 258 bootsync(); 259 260 /* Say NO to interrupts */ 261 splhigh(); 262 263 /* Do a dump if requested. */ 264 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) 265 dumpsys(); 266 267 268 /* Run any shutdown hooks */ 269 doshutdownhooks(); 270 271 /* Make sure IRQ's are disabled */ 272 IRQdisable; 273 274 if (howto & RB_HALT) { 275 printf("The operating system has halted.\n"); 276 printf("Please press any key to reboot.\n\n"); 277 cngetc(); 278 } 279 280 printf("rebooting...\n"); 281 cpu_reset(); 282 /*NOTREACHED*/ 283 } 284 285 /* 286 * 287 * Initial entry point on startup. This gets called before main() is 288 * entered. 289 * It should be responsible for setting up everything that must be 290 * in place when main is called. 291 * This includes 292 * Taking a copy of the boot configuration structure. 293 * Initialising the physical console so characters can be printed. 294 * Setting up page tables for the kernel 295 */ 296 297 u_int 298 initarm(argc, argv, bi) 299 int argc; 300 char **argv; 301 struct bootinfo *bi; 302 { 303 int loop; 304 u_int kerneldatasize, symbolsize; 305 u_int l1pagetable; 306 vaddr_t freemempos; 307 pv_addr_t kernel_l1pt; 308 vsize_t pt_size; 309 #if NKSYMS || defined(DDB) || defined(LKM) 310 Elf_Shdr *sh; 311 #endif 312 313 /* 314 * Heads up ... Setup the CPU / MMU / TLB functions 315 */ 316 set_cpufuncs(); 317 318 #ifdef DEBUG_BEFOREMMU 319 /* 320 * At this point, we cannot call real consinit(). 321 * Just call a faked up version of consinit(), which does the thing 322 * with MMU disabled. 323 */ 324 fakecninit(); 325 #endif 326 327 /* 328 * XXX for now, overwrite bootconfig to hardcoded values. 329 * XXX kill bootconfig and directly call uvm_physload 330 */ 331 bootconfig.dram[0].address = 0xc0000000; 332 bootconfig.dram[0].pages = 8192; 333 bootconfig.dramblocks = 1; 334 kerneldatasize = (u_int32_t)&end - (u_int32_t)KERNEL_TEXT_BASE; 335 336 symbolsize = 0; 337 #if NKSYMS || defined(DDB) || defined(LKM) 338 if (! memcmp(&end, "\177ELF", 4)) { 339 sh = (Elf_Shdr *)((char *)&end + ((Elf_Ehdr *)&end)->e_shoff); 340 loop = ((Elf_Ehdr *)&end)->e_shnum; 341 for(; loop; loop--, sh++) 342 if (sh->sh_offset > 0 && 343 (sh->sh_offset + sh->sh_size) > symbolsize) 344 symbolsize = sh->sh_offset + sh->sh_size; 345 } 346 #endif 347 348 printf("kernsize=0x%x\n", kerneldatasize); 349 kerneldatasize += symbolsize; 350 kerneldatasize = ((kerneldatasize - 1) & ~(PAGE_SIZE * 4 - 1)) + 351 PAGE_SIZE * 8; 352 353 /* parse kernel args */ 354 boot_file[0] = '\0'; 355 strncpy(booted_kernel_storage, *argv, sizeof(booted_kernel_storage)); 356 for(argc--, argv++; argc; argc--, argv++) 357 switch(**argv) { 358 case 'a': 359 boothowto |= RB_ASKNAME; 360 break; 361 case 's': 362 boothowto |= RB_SINGLE; 363 break; 364 case 'b': 365 /* boot device: -b=sd0 etc. */ 366 #ifdef NFS 367 if (strcmp(*argv + 2, "nfs") == 0) 368 mountroot = nfs_mountroot; 369 else 370 strncpy(boot_file, *argv + 2, 371 sizeof(boot_file)); 372 #else /* NFS */ 373 strncpy(boot_file, *argv + 2, sizeof(boot_file)); 374 #endif /* NFS */ 375 break; 376 default: 377 break; 378 } 379 380 /* copy bootinfo into known kernel space */ 381 bootinfo_storage = *bi; 382 bootinfo = &bootinfo_storage; 383 384 #ifdef BOOTINFO_FB_WIDTH 385 bootinfo->fb_line_bytes = BOOTINFO_FB_LINE_BYTES; 386 bootinfo->fb_width = BOOTINFO_FB_WIDTH; 387 bootinfo->fb_height = BOOTINFO_FB_HEIGHT; 388 bootinfo->fb_type = BOOTINFO_FB_TYPE; 389 #endif 390 391 /* 392 * hpcboot has loaded me with MMU disabled. 393 * So create kernel page tables and enable MMU 394 */ 395 396 /* 397 * Set up the variables that define the availablilty of physcial 398 * memory 399 */ 400 physical_start = bootconfig.dram[0].address; 401 physical_freestart = physical_start 402 + (KERNEL_TEXT_BASE - KERNEL_BASE) + kerneldatasize; 403 physical_end = bootconfig.dram[bootconfig.dramblocks - 1].address 404 + bootconfig.dram[bootconfig.dramblocks - 1].pages * PAGE_SIZE; 405 physical_freeend = physical_end; 406 407 for (loop = 0; loop < bootconfig.dramblocks; ++loop) 408 physmem += bootconfig.dram[loop].pages; 409 410 /* XXX handle UMA framebuffer memory */ 411 412 /* Use the first 256kB to allocate things */ 413 freemempos = KERNEL_BASE; 414 memset((void *)KERNEL_BASE, 0, KERNEL_TEXT_BASE - KERNEL_BASE); 415 416 /* 417 * Right We have the bottom meg of memory mapped to 0x00000000 418 * so was can get at it. The kernel will ocupy the start of it. 419 * After the kernel/args we allocate some of the fixed page tables 420 * we need to get the system going. 421 * We allocate one page directory and 8 page tables and store the 422 * physical addresses in the kernel_pt_table array. 423 * Must remember that neither the page L1 or L2 page tables are the 424 * same size as a page ! 425 * 426 * Ok the next bit of physical allocate may look complex but it is 427 * simple really. I have done it like this so that no memory gets 428 * wasted during the allocate of various pages and tables that are 429 * all different sizes. 430 * The start address will be page aligned. 431 * We allocate the kernel page directory on the first free 16KB 432 * boundry we find. 433 * We allocate the kernel page tables on the first 1KB boundry we find. 434 * We allocate 9 PT's. This means that in the process we 435 * KNOW that we will encounter at least 1 16KB boundry. 436 * 437 * Eventually if the top end of the memory gets used for process L1 438 * page tables the kernel L1 page table may be moved up there. 439 */ 440 441 #ifdef VERBOSE_INIT_ARM 442 printf("Allocating page tables\n"); 443 #endif 444 445 /* Define a macro to simplify memory allocation */ 446 #define valloc_pages(var, np) \ 447 (var).pv_pa = (var).pv_va = freemempos; \ 448 freemempos += (np) * PAGE_SIZE; 449 #define alloc_pages(var, np) \ 450 (var) = freemempos; \ 451 freemempos += (np) * PAGE_SIZE; 452 453 454 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE); 455 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) { 456 alloc_pages(kernel_pt_table[loop].pv_pa, 457 L2_TABLE_SIZE / PAGE_SIZE); 458 kernel_pt_table[loop].pv_va = kernel_pt_table[loop].pv_pa; 459 } 460 461 /* 462 * Allocate a page for the system page mapped to V0x00000000 463 * This page will just contain the system vectors and can be 464 * shared by all processes. 465 */ 466 valloc_pages(systempage, 1); 467 468 pt_size = round_page(freemempos) - KERNEL_BASE; 469 470 /* Allocate stacks for all modes */ 471 valloc_pages(irqstack, IRQ_STACK_SIZE); 472 valloc_pages(abtstack, ABT_STACK_SIZE); 473 valloc_pages(undstack, UND_STACK_SIZE); 474 valloc_pages(kernelstack, UPAGES); 475 476 #ifdef VERBOSE_INIT_ARM 477 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa, 478 irqstack.pv_va); 479 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa, 480 abtstack.pv_va); 481 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa, 482 undstack.pv_va); 483 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa, 484 kernelstack.pv_va); 485 #endif 486 487 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE); 488 489 /* 490 * XXX Actually, we only need virtual space and don't need 491 * XXX physical memory for sa110_cc_base and sa11x0_idle_mem. 492 */ 493 /* 494 * XXX totally stuffed hack to work round problems introduced 495 * in recent versions of the pmap code. Due to the calls used there 496 * we cannot allocate virtual memory during bootstrap. 497 */ 498 for(;;) { 499 alloc_pages(sa1_cc_base, 1); 500 if (! (sa1_cc_base & (CPU_SA110_CACHE_CLEAN_SIZE - 1))) 501 break; 502 } 503 { 504 vaddr_t dummy; 505 alloc_pages(dummy, CPU_SA110_CACHE_CLEAN_SIZE / PAGE_SIZE - 1); 506 } 507 sa1_cache_clean_addr = sa1_cc_base; 508 sa1_cache_clean_size = CPU_SA110_CACHE_CLEAN_SIZE / 2; 509 510 alloc_pages(sa11x0_idle_mem, 1); 511 512 /* 513 * Ok we have allocated physical pages for the primary kernel 514 * page tables 515 */ 516 517 #ifdef VERBOSE_INIT_ARM 518 printf("Creating L1 page table\n"); 519 #endif 520 521 /* 522 * Now we start consturction of the L1 page table 523 * We start by mapping the L2 page tables into the L1. 524 * This means that we can replace L1 mappings later on if necessary 525 */ 526 l1pagetable = kernel_l1pt.pv_pa; 527 528 /* Map the L2 pages tables in the L1 page table */ 529 pmap_link_l2pt(l1pagetable, 0x00000000, 530 &kernel_pt_table[KERNEL_PT_SYS]); 531 pmap_link_l2pt(l1pagetable, KERNEL_BASE, 532 &kernel_pt_table[KERNEL_PT_KERNEL]); 533 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; ++loop) 534 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000, 535 &kernel_pt_table[KERNEL_PT_VMDATA + loop]); 536 537 /* update the top of the kernel VM */ 538 pmap_curmaxkvaddr = 539 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000); 540 #define SAIPIO_BASE 0xd0000000 /* XXX XXX */ 541 pmap_link_l2pt(l1pagetable, SAIPIO_BASE, 542 &kernel_pt_table[KERNEL_PT_IO]); 543 544 545 #ifdef VERBOSE_INIT_ARM 546 printf("Mapping kernel\n"); 547 #endif 548 549 /* Now we fill in the L2 pagetable for the kernel code/data */ 550 551 /* 552 * XXX there is no ELF header to find RO region. 553 * XXX What should we do? 554 */ 555 #if 0 556 if (N_GETMAGIC(kernexec[0]) == ZMAGIC) { 557 logical = pmap_map_chunk(l1pagetable, KERNEL_TEXT_BASE, 558 physical_start, kernexec->a_text, 559 VM_PROT_READ, PTE_CACHE); 560 logical += pmap_map_chunk(l1pagetable, 561 KERNEL_TEXT_BASE + logical, physical_start + logical, 562 kerneldatasize - kernexec->a_text, 563 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 564 } else 565 #endif 566 pmap_map_chunk(l1pagetable, KERNEL_TEXT_BASE, 567 KERNEL_TEXT_BASE, kerneldatasize, 568 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 569 570 #ifdef VERBOSE_INIT_ARM 571 printf("Constructing L2 page tables\n"); 572 #endif 573 574 /* Map the stack pages */ 575 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa, 576 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 577 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa, 578 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 579 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa, 580 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 581 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa, 582 UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 583 584 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa, 585 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE); 586 587 /* Map page tables */ 588 pmap_map_chunk(l1pagetable, KERNEL_BASE, KERNEL_BASE, pt_size, 589 VM_PROT_READ | VM_PROT_WRITE, PTE_PAGETABLE); 590 591 /* Map a page for entering idle mode */ 592 pmap_map_entry(l1pagetable, sa11x0_idle_mem, sa11x0_idle_mem, 593 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE); 594 595 /* Map the vector page. */ 596 pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa, 597 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 598 599 /* Map any I/O modules here, as we don't have real bus_space_map() */ 600 printf("mapping IO..."); 601 pmap_map_entry(l1pagetable, SACOM3_BASE, SACOM3_HW_BASE, 602 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE); 603 604 pmap_map_chunk(l1pagetable, sa1_cache_clean_addr, 0xe0000000, 605 CPU_SA110_CACHE_CLEAN_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 606 /* 607 * Now we have the real page tables in place so we can switch to them. 608 * Once this is done we will be running with the REAL kernel page 609 * tables. 610 */ 611 612 printf("done.\n"); 613 614 /* 615 * Pages were allocated during the secondary bootstrap for the 616 * stacks for different CPU modes. 617 * We must now set the r13 registers in the different CPU modes to 618 * point to these stacks. 619 * Since the ARM stacks use STMFD etc. we must set r13 to the top end 620 * of the stack memory. 621 */ 622 printf("init subsystems: stacks "); 623 624 set_stackptr(PSR_IRQ32_MODE, 625 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE); 626 set_stackptr(PSR_ABT32_MODE, 627 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE); 628 set_stackptr(PSR_UND32_MODE, 629 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE); 630 #ifdef PMAP_DEBUG 631 if (pmap_debug_level >= 0) 632 printf("kstack V%08lx P%08lx\n", kernelstack.pv_va, 633 kernelstack.pv_pa); 634 #endif /* PMAP_DEBUG */ 635 636 /* 637 * Well we should set a data abort handler. 638 * Once things get going this will change as we will need a proper 639 * handler. Until then we will use a handler that just panics but 640 * tells us why. 641 * Initialisation of the vectors will just panic on a data abort. 642 * This just fills in a slighly better one. 643 */ 644 printf("vectors "); 645 data_abort_handler_address = (u_int)data_abort_handler; 646 prefetch_abort_handler_address = (u_int)prefetch_abort_handler; 647 undefined_handler_address = (u_int)undefinedinstruction_bounce; 648 printf("%08x %08x %08x\n", data_abort_handler_address, 649 prefetch_abort_handler_address, undefined_handler_address); 650 651 /* Initialise the undefined instruction handlers */ 652 printf("undefined "); 653 undefined_init(); 654 655 /* Set the page table address. */ 656 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT); 657 setttb(kernel_l1pt.pv_pa); 658 cpu_tlb_flushID(); 659 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)); 660 661 /* 662 * Moved from cpu_startup() as data_abort_handler() references 663 * this during uvm init 664 */ 665 proc0paddr = (struct user *)kernelstack.pv_va; 666 lwp0.l_addr = proc0paddr; 667 668 #ifdef BOOT_DUMP 669 dumppages((char *)0xc0000000, 16 * PAGE_SIZE); 670 dumppages((char *)0xb0100000, 64); /* XXX */ 671 #endif 672 /* Enable MMU, I-cache, D-cache, write buffer. */ 673 cpufunc_control(0x337f, 0x107d); 674 675 arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL); 676 677 consinit(); 678 679 #ifdef VERBOSE_INIT_ARM 680 printf("freemempos=%08lx\n", freemempos); 681 printf("MMU enabled. control=%08x\n", cpu_get_control()); 682 #endif 683 684 /* Load memory into UVM. */ 685 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */ 686 for (loop = 0; loop < bootconfig.dramblocks; loop++) { 687 paddr_t start = (paddr_t)bootconfig.dram[loop].address; 688 paddr_t end = start + (bootconfig.dram[loop].pages * PAGE_SIZE); 689 690 if (start < physical_freestart) 691 start = physical_freestart; 692 if (end > physical_freeend) 693 end = physical_freeend; 694 695 uvm_page_physload(atop(start), atop(end), 696 atop(start), atop(end), VM_FREELIST_DEFAULT); 697 } 698 699 /* Boot strap pmap telling it where the kernel page table is */ 700 pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, KERNEL_VM_BASE, 701 KERNEL_VM_BASE + KERNEL_VM_SIZE); 702 703 if (cputype == CPU_ID_SA110) 704 rpc_sa110_cc_setup(); 705 706 #ifdef IPKDB 707 /* Initialise ipkdb */ 708 ipkdb_init(); 709 if (boothowto & RB_KDB) 710 ipkdb_connect(0); 711 #endif /* NIPKDB */ 712 713 #ifdef BOOT_DUMP 714 dumppages((char *)kernel_l1pt.pv_va, 16); 715 dumppages((char *)PTE_BASE, 16); 716 #endif 717 718 #ifdef DDB 719 db_machine_init(); 720 #endif 721 #if NKSYMS || defined(DDB) || defined(LKM) 722 ksyms_init(symbolsize, ((int *)&end), ((char *)&end) + symbolsize); 723 #endif 724 725 printf("kernsize=0x%x", kerneldatasize); 726 printf(" (including 0x%x symbols)\n", symbolsize); 727 728 #ifdef DDB 729 if (boothowto & RB_KDB) 730 Debugger(); 731 #endif /* DDB */ 732 733 if (bootinfo->magic == BOOTINFO_MAGIC) { 734 platid.dw.dw0 = bootinfo->platid_cpu; 735 platid.dw.dw1 = bootinfo->platid_machine; 736 } 737 738 /* We return the new stack pointer address */ 739 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP); 740 } 741 742 void 743 consinit(void) 744 { 745 static int consinit_called = 0; 746 747 if (consinit_called != 0) 748 return; 749 750 consinit_called = 1; 751 if (bootinfo->bi_cnuse == BI_CNUSE_SERIAL) 752 cninit(); 753 else { 754 /* 755 * Nothing to do here. Console initialization is done at 756 * autoconf device attach time. 757 */ 758 } 759 } 760 761 #ifdef DEBUG_BEFOREMMU 762 cons_decl(sacom); 763 void 764 fakecninit() 765 { 766 static struct consdev fakecntab = cons_init(sacom); 767 cn_tab = &fakecntab; 768 769 (*cn_tab->cn_init)(0); 770 cn_tab->cn_pri = CN_REMOTE; 771 } 772 #endif 773 774 775 /* 776 * For optimal cache cleaning we need two 16K banks of 777 * virtual address space that NOTHING else will access 778 * and then we alternate the cache cleaning between the 779 * two banks. 780 * The cache cleaning code requires requires 2 banks aligned 781 * on total size boundry so the banks can be alternated by 782 * eorring the size bit (assumes the bank size is a power of 2) 783 */ 784 void 785 rpc_sa110_cc_setup(void) 786 { 787 int loop; 788 paddr_t kaddr; 789 pt_entry_t *pte; 790 791 (void) pmap_extract(pmap_kernel(), KERNEL_TEXT_BASE, &kaddr); 792 for (loop = 0; loop < CPU_SA110_CACHE_CLEAN_SIZE; loop += PAGE_SIZE) { 793 pte = vtopte(sa1_cc_base + loop); 794 *pte = L2_S_PROTO | kaddr | 795 L2_S_PROT(PTE_KERNEL, VM_PROT_READ) | pte_l2_s_cache_mode; 796 PTE_SYNC(pte); 797 } 798 sa1_cache_clean_addr = sa1_cc_base; 799 sa1_cache_clean_size = CPU_SA110_CACHE_CLEAN_SIZE / 2; 800 } 801 802 #ifdef BOOT_DUMP 803 void dumppages(char *start, int nbytes) 804 { 805 char *p = start; 806 char *p1; 807 int i; 808 809 for(i = nbytes; i > 0; i -= 16, p += 16) { 810 for(p1 = p + 15; p != p1; p1--) { 811 if (*p1) 812 break; 813 } 814 if (! *p1) 815 continue; 816 printf("%08x %02x %02x %02x %02x %02x %02x %02x %02x" 817 " %02x %02x %02x %02x %02x %02x %02x %02x\n", 818 (unsigned int)p, 819 p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], 820 p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]); 821 } 822 } 823 #endif 824 825 /* End of machdep.c */ 826