1 /* $NetBSD: hpc_machdep.c,v 1.82 2006/10/07 13:53:24 peter 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 38 /* 39 * Machine dependent functions for kernel setup. 40 */ 41 42 #include <sys/cdefs.h> 43 __KERNEL_RCSID(0, "$NetBSD: hpc_machdep.c,v 1.82 2006/10/07 13:53:24 peter Exp $"); 44 45 #include "opt_ddb.h" 46 #include "opt_ipkdb.h" 47 #include "opt_pmap_debug.h" 48 #include "fs_nfs.h" 49 #include "ksyms.h" 50 51 #include <sys/param.h> 52 #include <sys/systm.h> 53 #include <sys/kernel.h> 54 #include <sys/reboot.h> 55 #include <sys/proc.h> 56 #include <sys/msgbuf.h> 57 #include <sys/exec.h> 58 #include <sys/ksyms.h> 59 #include <sys/boot_flag.h> 60 #include <sys/conf.h> /* XXX for consinit related hacks */ 61 62 #if NKSYMS || defined(DDB) || defined(LKM) 63 #include <machine/db_machdep.h> 64 #include <ddb/db_sym.h> 65 #include <ddb/db_extern.h> 66 #ifndef DB_ELFSIZE 67 #error Must define DB_ELFSIZE! 68 #endif 69 #define ELFSIZE DB_ELFSIZE 70 #include <sys/exec_elf.h> 71 #endif 72 73 #include <uvm/uvm.h> 74 75 #include <arm/sa11x0/sa11x0_reg.h> 76 #include <arm/cpuconf.h> 77 #include <arm/undefined.h> 78 79 #include <machine/bootconfig.h> 80 #include <machine/bootinfo.h> 81 #include <machine/cpu.h> 82 #include <machine/frame.h> 83 #include <machine/intr.h> 84 #include <machine/io.h> 85 #include <machine/platid.h> 86 #include <machine/rtc.h> 87 #include <machine/signal.h> 88 89 #include <dev/cons.h> 90 #include <dev/hpc/apm/apmvar.h> 91 #include <dev/hpc/bicons.h> 92 93 #ifdef NFS 94 #include <sys/mount.h> 95 #include <nfs/rpcv2.h> 96 #include <nfs/nfsproto.h> 97 #include <nfs/nfs.h> 98 #include <nfs/nfsmount.h> 99 #endif /* NFS */ 100 101 /* Kernel text starts 256K in from the bottom of the kernel address space. */ 102 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00040000) 103 #define KERNEL_VM_BASE (KERNEL_BASE + 0x00C00000) 104 #define KERNEL_VM_SIZE 0x05000000 105 106 /* 107 * Address to call from cpu_reset() to reset the machine. 108 * This is machine architecture dependent as it varies depending 109 * on where the ROM appears when you turn the MMU off. 110 */ 111 u_int cpu_reset_address = 0; 112 113 /* Define various stack sizes in pages */ 114 #define IRQ_STACK_SIZE 1 115 #define ABT_STACK_SIZE 1 116 #ifdef IPKDB 117 #define UND_STACK_SIZE 2 118 #else 119 #define UND_STACK_SIZE 1 120 #endif 121 122 BootConfig bootconfig; /* Boot config storage */ 123 struct bootinfo *bootinfo, bootinfo_storage; 124 static char booted_kernel_storage[80]; 125 char *booted_kernel = booted_kernel_storage; 126 127 paddr_t physical_start; 128 paddr_t physical_freestart; 129 paddr_t physical_freeend; 130 paddr_t physical_end; 131 int physmem = 0; 132 133 #ifndef PMAP_STATIC_L1S 134 int max_processes = 64; /* Default number */ 135 #endif /* !PMAP_STATIC_L1S */ 136 137 138 /* Physical and virtual addresses for some global pages */ 139 pv_addr_t systempage; 140 pv_addr_t irqstack; 141 pv_addr_t undstack; 142 pv_addr_t abtstack; 143 pv_addr_t kernelstack; 144 145 char *boot_args = NULL; 146 char boot_file[16]; 147 148 vaddr_t msgbufphys; 149 150 extern u_int data_abort_handler_address; 151 extern u_int prefetch_abort_handler_address; 152 extern u_int undefined_handler_address; 153 extern int end; 154 155 #ifdef PMAP_DEBUG 156 extern int pmap_debug_level; 157 #endif /* PMAP_DEBUG */ 158 159 #define KERNEL_PT_VMEM 0 /* Page table for mapping video memory */ 160 #define KERNEL_PT_SYS 1 /* Page table for mapping proc0 zero page */ 161 #define KERNEL_PT_KERNEL 2 /* Page table for mapping kernel */ 162 #define KERNEL_PT_IO 3 /* Page table for mapping IO */ 163 #define KERNEL_PT_VMDATA 4 /* Page tables for mapping kernel VM */ 164 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */ 165 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM) 166 167 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS]; 168 169 struct user *proc0paddr; 170 171 #define CPU_SA110_CACHE_CLEAN_SIZE (0x4000 * 2) 172 extern unsigned int sa1_cache_clean_addr; 173 extern unsigned int sa1_cache_clean_size; 174 static vaddr_t sa1_cc_base; 175 176 /* Mode dependent sleep function holder */ 177 void (*__sleep_func)(void *); 178 void *__sleep_ctx; 179 180 /* Non-buffered non-cacheable memory needed to enter idle mode */ 181 extern vaddr_t sa11x0_idle_mem; 182 183 /* Prototypes */ 184 void data_abort_handler(trapframe_t *); 185 void prefetch_abort_handler(trapframe_t *); 186 void undefinedinstruction_bounce(trapframe_t *); 187 void dumpsys(void); 188 u_int cpu_get_control(void); 189 190 u_int initarm(int, char **, struct bootinfo *); 191 192 #ifdef DEBUG_BEFOREMMU 193 static void fakecninit(void); 194 #endif 195 196 #ifdef BOOT_DUMP 197 static void dumppages(char *, int); 198 #endif 199 200 /* 201 * Reboots the system. 202 * 203 * Deal with any syncing, unmounting, dumping and shutdown hooks, 204 * then reset the CPU. 205 */ 206 void 207 cpu_reboot(int howto, char *bootstr) 208 { 209 /* 210 * If we are still cold then hit the air brakes 211 * and crash to earth fast. 212 */ 213 if (cold) { 214 doshutdownhooks(); 215 printf("Halted while still in the ICE age.\n"); 216 printf("The operating system has halted.\n"); 217 printf("Please press any key to reboot.\n\n"); 218 cngetc(); 219 printf("rebooting...\n"); 220 cpu_reset(); 221 /* NOTREACHED */ 222 } 223 224 /* Reset the sleep function. */ 225 __sleep_func = NULL; 226 __sleep_ctx = NULL; 227 228 /* Disable console buffering. */ 229 cnpollc(1); 230 231 /* 232 * If RB_NOSYNC was not specified sync the discs. 233 * Note: Unless cold is set to 1 here, syslogd will die during 234 * the unmount. It looks like syslogd is getting woken up only 235 * to find that it cannot page part of the binary in as the 236 * file system has been unmounted. 237 */ 238 if (!(howto & RB_NOSYNC)) 239 bootsync(); 240 241 /* Say NO to interrupts. */ 242 (void)splhigh(); 243 244 /* Do a dump if requested. */ 245 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) 246 dumpsys(); 247 248 /* Run any shutdown hooks. */ 249 doshutdownhooks(); 250 251 /* Make sure IRQs are disabled. */ 252 IRQdisable; 253 254 if (howto & RB_HALT) { 255 printf("The operating system has halted.\n"); 256 printf("Please press any key to reboot.\n\n"); 257 cngetc(); 258 } 259 260 printf("rebooting...\n"); 261 cpu_reset(); 262 /* NOTREACHED */ 263 } 264 265 /* Number of DRAM pages which are installed */ 266 /* Units are 4K pages, so 8192 is 32 MB of memory */ 267 #ifndef DRAM_PAGES 268 #define DRAM_PAGES 8192 269 #endif 270 271 /* 272 * Static device mappings. These peripheral registers are mapped at 273 * fixed virtual addresses very early in initarm() so that we can use 274 * them while booting the kernel and stay at the same address 275 * throughout whole kernel's life time. 276 */ 277 static const struct pmap_devmap sa11x0_devmap[] = { 278 /* Physical/virtual address for UART #3. */ 279 { 280 SACOM3_VBASE, 281 SACOM3_BASE, 282 0x24, 283 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE 284 }, 285 { 0, 0, 0, 0, 0 } 286 }; 287 288 /* 289 * Initial entry point on startup. This gets called before main() is 290 * entered. 291 * It should be responsible for setting up everything that must be 292 * in place when main is called. 293 * This includes: 294 * Taking a copy of the boot configuration structure. 295 * Initializing the physical console so characters can be printed. 296 * Setting up page tables for the kernel. 297 */ 298 u_int 299 initarm(int argc, char **argv, struct bootinfo *bi) 300 { 301 u_int kerneldatasize, symbolsize; 302 u_int l1pagetable; 303 vaddr_t freemempos; 304 pv_addr_t kernel_l1pt; 305 vsize_t pt_size; 306 int loop, i; 307 #if NKSYMS || defined(DDB) || defined(LKM) 308 Elf_Shdr *sh; 309 #endif 310 311 __sleep_func = NULL; 312 __sleep_ctx = NULL; 313 314 /* 315 * Heads up ... Setup the CPU / MMU / TLB functions. 316 */ 317 set_cpufuncs(); 318 319 #ifdef DEBUG_BEFOREMMU 320 /* 321 * At this point, we cannot call real consinit(). 322 * Just call a faked up version of consinit(), which does the thing 323 * with MMU disabled. 324 */ 325 fakecninit(); 326 #endif 327 328 /* 329 * XXX for now, overwrite bootconfig to hardcoded values. 330 * XXX kill bootconfig and directly call uvm_physload 331 */ 332 bootconfig.dram[0].address = 0xc0000000; 333 bootconfig.dram[0].pages = DRAM_PAGES; 334 bootconfig.dramblocks = 1; 335 kerneldatasize = (uint32_t)&end - (uint32_t)KERNEL_TEXT_BASE; 336 337 symbolsize = 0; 338 #if NKSYMS || defined(DDB) || defined(LKM) 339 if (!memcmp(&end, "\177ELF", 4)) { 340 sh = (Elf_Shdr *)((char *)&end + ((Elf_Ehdr *)&end)->e_shoff); 341 loop = ((Elf_Ehdr *)&end)->e_shnum; 342 for (; loop; loop--, sh++) 343 if (sh->sh_offset > 0 && 344 (sh->sh_offset + sh->sh_size) > symbolsize) 345 symbolsize = sh->sh_offset + sh->sh_size; 346 } 347 #endif 348 349 printf("kernsize=0x%x\n", kerneldatasize); 350 kerneldatasize += symbolsize; 351 kerneldatasize = ((kerneldatasize - 1) & ~(PAGE_SIZE * 4 - 1)) + 352 PAGE_SIZE * 8; 353 354 /* parse kernel args */ 355 boothowto = 0; 356 boot_file[0] = '\0'; 357 strncpy(booted_kernel_storage, argv[0], sizeof(booted_kernel_storage)); 358 for (i = 1; i < argc; i++) { 359 char *cp = argv[i]; 360 361 switch (*cp) { 362 case 'b': 363 /* boot device: -b=sd0 etc. */ 364 cp = cp + 2; 365 #ifdef NFS 366 if (strcmp(cp, "nfs") == 0) 367 mountroot = nfs_mountroot; 368 else 369 strncpy(boot_file, cp, sizeof(boot_file)); 370 #else /* !NFS */ 371 strncpy(boot_file, cp, sizeof(boot_file)); 372 #endif /* !NFS */ 373 break; 374 default: 375 BOOT_FLAG(*cp, boothowto); 376 break; 377 } 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 availability 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 occupy 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 * boundary we find. 433 * We allocate the kernel page tables on the first 1KB boundary 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 boundary. 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 construction 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 #ifdef VERBOSE_INIT_ARM 545 printf("Mapping kernel\n"); 546 #endif 547 548 /* Now we fill in the L2 pagetable for the kernel code/data */ 549 550 /* 551 * XXX there is no ELF header to find RO region. 552 * XXX What should we do? 553 */ 554 #if 0 555 if (N_GETMAGIC(kernexec[0]) == ZMAGIC) { 556 logical = pmap_map_chunk(l1pagetable, KERNEL_TEXT_BASE, 557 physical_start, kernexec->a_text, 558 VM_PROT_READ, PTE_CACHE); 559 logical += pmap_map_chunk(l1pagetable, 560 KERNEL_TEXT_BASE + logical, physical_start + logical, 561 kerneldatasize - kernexec->a_text, 562 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 563 } else 564 #endif 565 pmap_map_chunk(l1pagetable, KERNEL_TEXT_BASE, 566 KERNEL_TEXT_BASE, kerneldatasize, 567 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 568 569 #ifdef VERBOSE_INIT_ARM 570 printf("Constructing L2 page tables\n"); 571 #endif 572 573 /* Map the stack pages */ 574 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa, 575 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 576 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa, 577 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 578 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa, 579 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 580 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa, 581 UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 582 583 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa, 584 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE); 585 586 /* Map page tables */ 587 pmap_map_chunk(l1pagetable, KERNEL_BASE, KERNEL_BASE, pt_size, 588 VM_PROT_READ | VM_PROT_WRITE, PTE_PAGETABLE); 589 590 /* Map a page for entering idle mode */ 591 pmap_map_entry(l1pagetable, sa11x0_idle_mem, sa11x0_idle_mem, 592 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE); 593 594 /* Map the vector page. */ 595 pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa, 596 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 597 598 /* Map the statically mapped devices. */ 599 pmap_devmap_bootstrap(l1pagetable, sa11x0_devmap); 600 601 pmap_map_chunk(l1pagetable, sa1_cache_clean_addr, 0xe0000000, 602 CPU_SA110_CACHE_CLEAN_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 603 /* 604 * Now we have the real page tables in place so we can switch to them. 605 * Once this is done we will be running with the REAL kernel page 606 * tables. 607 */ 608 609 printf("done.\n"); 610 611 /* 612 * Pages were allocated during the secondary bootstrap for the 613 * stacks for different CPU modes. 614 * We must now set the r13 registers in the different CPU modes to 615 * point to these stacks. 616 * Since the ARM stacks use STMFD etc. we must set r13 to the top end 617 * of the stack memory. 618 */ 619 printf("init subsystems: stacks "); 620 621 set_stackptr(PSR_IRQ32_MODE, 622 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE); 623 set_stackptr(PSR_ABT32_MODE, 624 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE); 625 set_stackptr(PSR_UND32_MODE, 626 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE); 627 #ifdef PMAP_DEBUG 628 if (pmap_debug_level >= 0) 629 printf("kstack V%08lx P%08lx\n", kernelstack.pv_va, 630 kernelstack.pv_pa); 631 #endif /* PMAP_DEBUG */ 632 633 /* 634 * Well we should set a data abort handler. 635 * Once things get going this will change as we will need a proper 636 * handler. Until then we will use a handler that just panics but 637 * tells us why. 638 * Initialization of the vectors will just panic on a data abort. 639 * This just fills in a slightly better one. 640 */ 641 printf("vectors "); 642 data_abort_handler_address = (u_int)data_abort_handler; 643 prefetch_abort_handler_address = (u_int)prefetch_abort_handler; 644 undefined_handler_address = (u_int)undefinedinstruction_bounce; 645 printf("%08x %08x %08x\n", data_abort_handler_address, 646 prefetch_abort_handler_address, undefined_handler_address); 647 648 /* Initialize the undefined instruction handlers */ 649 printf("undefined "); 650 undefined_init(); 651 652 /* Set the page table address. */ 653 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT); 654 setttb(kernel_l1pt.pv_pa); 655 cpu_tlb_flushID(); 656 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)); 657 658 /* 659 * Moved from cpu_startup() as data_abort_handler() references 660 * this during uvm init. 661 */ 662 proc0paddr = (struct user *)kernelstack.pv_va; 663 lwp0.l_addr = proc0paddr; 664 665 #ifdef BOOT_DUMP 666 dumppages((char *)0xc0000000, 16 * PAGE_SIZE); 667 dumppages((char *)0xb0100000, 64); /* XXX */ 668 #endif 669 /* Enable MMU, I-cache, D-cache, write buffer. */ 670 cpufunc_control(0x337f, 0x107d); 671 672 arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL); 673 674 consinit(); 675 676 #ifdef VERBOSE_INIT_ARM 677 printf("freemempos=%08lx\n", freemempos); 678 printf("MMU enabled. control=%08x\n", cpu_get_control()); 679 #endif 680 681 /* Load memory into UVM. */ 682 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */ 683 for (loop = 0; loop < bootconfig.dramblocks; loop++) { 684 paddr_t dblk_start = (paddr_t)bootconfig.dram[loop].address; 685 paddr_t dblk_end = dblk_start 686 + (bootconfig.dram[loop].pages * PAGE_SIZE); 687 688 if (dblk_start < physical_freestart) 689 dblk_start = physical_freestart; 690 if (dblk_end > physical_freeend) 691 dblk_end = physical_freeend; 692 693 uvm_page_physload(atop(dblk_start), atop(dblk_end), 694 atop(dblk_start), atop(dblk_end), VM_FREELIST_DEFAULT); 695 } 696 697 /* Boot strap pmap telling it where the kernel page table is */ 698 pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, KERNEL_VM_BASE, 699 KERNEL_VM_BASE + KERNEL_VM_SIZE); 700 701 #ifdef IPKDB 702 /* Initialize ipkdb */ 703 ipkdb_init(); 704 if (boothowto & RB_KDB) 705 ipkdb_connect(0); 706 #endif /* IPKDB */ 707 708 #ifdef BOOT_DUMP 709 dumppages((char *)kernel_l1pt.pv_va, 16); 710 #endif 711 712 #ifdef DDB 713 db_machine_init(); 714 #endif 715 #if NKSYMS || defined(DDB) || defined(LKM) 716 ksyms_init(symbolsize, ((int *)&end), ((char *)&end) + symbolsize); 717 #endif 718 719 printf("kernsize=0x%x", kerneldatasize); 720 printf(" (including 0x%x symbols)\n", symbolsize); 721 722 #ifdef DDB 723 if (boothowto & RB_KDB) 724 Debugger(); 725 #endif /* DDB */ 726 727 if (bootinfo->magic == BOOTINFO_MAGIC) { 728 platid.dw.dw0 = bootinfo->platid_cpu; 729 platid.dw.dw1 = bootinfo->platid_machine; 730 } 731 732 /* We return the new stack pointer address */ 733 return (kernelstack.pv_va + USPACE_SVC_STACK_TOP); 734 } 735 736 void 737 machine_sleep(void) 738 { 739 740 if (__sleep_func != NULL) 741 __sleep_func(__sleep_ctx); 742 } 743 744 void 745 machine_standby(void) 746 { 747 748 } 749 750 void 751 consinit(void) 752 { 753 static int consinit_called = 0; 754 755 if (consinit_called != 0) 756 return; 757 758 consinit_called = 1; 759 if (bootinfo->bi_cnuse == BI_CNUSE_SERIAL) 760 cninit(); 761 else { 762 /* 763 * Nothing to do here. Console initialization is done at 764 * autoconf device attach time. 765 */ 766 } 767 } 768 769 #ifdef DEBUG_BEFOREMMU 770 cons_decl(sacom); 771 772 static void 773 fakecninit(void) 774 { 775 static struct consdev fakecntab = cons_init(sacom); 776 cn_tab = &fakecntab; 777 778 (*cn_tab->cn_init)(0); 779 cn_tab->cn_pri = CN_REMOTE; 780 } 781 #endif 782 783 #ifdef BOOT_DUMP 784 static void 785 dumppages(char *start, int nbytes) 786 { 787 char *p = start; 788 char *p1; 789 int i; 790 791 for (i = nbytes; i > 0; i -= 16, p += 16) { 792 for (p1 = p + 15; p != p1; p1--) { 793 if (*p1) 794 break; 795 } 796 if (!*p1) 797 continue; 798 printf("%08x %02x %02x %02x %02x %02x %02x %02x %02x" 799 " %02x %02x %02x %02x %02x %02x %02x %02x\n", 800 (unsigned int)p, 801 p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], 802 p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]); 803 } 804 } 805 #endif 806