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