1 /* $NetBSD: hpc_machdep.c,v 1.5 2001/03/09 12:13:15 toshii 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 "opt_cputypes.h" 52 #include "opt_ddb.h" 53 #include "opt_pmap_debug.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 63 #include <dev/cons.h> 64 65 #include <machine/db_machdep.h> 66 #include <ddb/db_sym.h> 67 #include <ddb/db_extern.h> 68 69 #include <uvm/uvm.h> 70 71 #include <machine/signal.h> 72 #include <machine/frame.h> 73 #include <machine/bootconfig.h> 74 #include <machine/cpu.h> 75 #include <machine/io.h> 76 #include <machine/irqhandler.h> 77 #include <machine/katelib.h> 78 #include <machine/pte.h> 79 #include <machine/bootinfo.h> 80 #include <machine/undefined.h> 81 #include <machine/rtc.h> 82 #include <hpcarm/sa11x0/sa11x0_reg.h> 83 84 #include <dev/hpc/bicons.h> 85 86 #include "opt_ipkdb.h" 87 88 /* XXX for consinit related hacks */ 89 #include <sys/conf.h> 90 91 /* 92 * Address to call from cpu_reset() to reset the machine. 93 * This is machine architecture dependant as it varies depending 94 * on where the ROM appears when you turn the MMU off. 95 */ 96 97 u_int cpu_reset_address = 0; 98 99 /* Define various stack sizes in pages */ 100 #define IRQ_STACK_SIZE 1 101 #define ABT_STACK_SIZE 1 102 #ifdef IPKDB 103 #define UND_STACK_SIZE 2 104 #else 105 #define UND_STACK_SIZE 1 106 #endif 107 108 BootConfig bootconfig; /* Boot config storage */ 109 struct bootinfo *bootinfo, bootinfo_storage; 110 111 vm_offset_t physical_start; 112 vm_offset_t physical_freestart; 113 vm_offset_t physical_freeend; 114 vm_offset_t physical_end; 115 u_int free_pages; 116 int physmem = 0; 117 118 #define biconscnpollc nullcnpollc 119 cons_decl(bicons); 120 static struct consdev bicons = cons_init(bicons); 121 122 #ifndef PMAP_STATIC_L1S 123 int max_processes = 64; /* Default number */ 124 #endif /* !PMAP_STATIC_L1S */ 125 126 127 /* Physical and virtual addresses for some global pages */ 128 pv_addr_t systempage; 129 pv_addr_t irqstack; 130 pv_addr_t undstack; 131 pv_addr_t abtstack; 132 pv_addr_t kernelstack; 133 134 char *boot_args = NULL; 135 char *boot_file = NULL; 136 137 vm_offset_t msgbufphys; 138 139 extern u_int data_abort_handler_address; 140 extern u_int prefetch_abort_handler_address; 141 extern u_int undefined_handler_address; 142 extern int end; 143 144 #ifdef PMAP_DEBUG 145 extern int pmap_debug_level; 146 #endif /* PMAP_DEBUG */ 147 148 #define KERNEL_PT_VMEM 0 /* Page table for mapping video memory */ 149 #define KERNEL_PT_SYS 1 /* Page table for mapping proc0 zero page */ 150 #define KERNEL_PT_KERNEL 2 /* Page table for mapping kernel */ 151 #define KERNEL_PT_IO 3 /* Page table for mapping IO */ 152 #define KERNEL_PT_VMDATA 4 /* Page tables for mapping kernel VM */ 153 #define KERNEL_PT_VMDATA_NUM (KERNEL_VM_SIZE >> (PDSHIFT + 2)) 154 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM) 155 156 pt_entry_t kernel_pt_table[NUM_KERNEL_PTS]; 157 158 struct user *proc0paddr; 159 160 #ifdef CPU_SA110 161 #define CPU_SA110_CACHE_CLEAN_SIZE (0x4000 * 2) 162 extern unsigned int sa110_cache_clean_addr; 163 extern unsigned int sa110_cache_clean_size; 164 static vaddr_t sa110_cc_base; 165 #endif /* CPU_SA110 */ 166 167 /* virtual address for framebuffer */ 168 /* XXX temporary hack until we have bus_space_map */ 169 #define FRAMEBUF_BASE 0xd0100000 170 171 /* Prototypes */ 172 173 void physcon_display_base __P((u_int addr)); 174 extern void consinit __P((void)); 175 176 void map_section __P((vm_offset_t pt, vm_offset_t va, vm_offset_t pa, 177 int cacheable)); 178 void map_pagetable __P((vm_offset_t pt, vm_offset_t va, vm_offset_t pa)); 179 void map_entry __P((vm_offset_t pt, vm_offset_t va, vm_offset_t pa)); 180 void map_entry_nc __P((vm_offset_t pt, vm_offset_t va, vm_offset_t pa)); 181 void map_entry_ro __P((vm_offset_t pt, vm_offset_t va, vm_offset_t pa)); 182 vm_size_t map_chunk __P((vm_offset_t pd, vm_offset_t pt, vm_offset_t va, 183 vm_offset_t pa, vm_size_t size, u_int acc, 184 u_int flg)); 185 186 void data_abort_handler __P((trapframe_t *frame)); 187 void prefetch_abort_handler __P((trapframe_t *frame)); 188 void undefinedinstruction_bounce __P((trapframe_t *frame)); 189 void zero_page_readonly __P((void)); 190 void zero_page_readwrite __P((void)); 191 192 u_int cpu_get_control __P((void)); 193 194 void rpc_sa110_cc_setup(void); 195 196 #ifdef DEBUG_BEFOREMMU 197 static void fakecninit(); 198 #endif 199 200 #ifdef BOOT_DUMP 201 void dumppages(char *, int); 202 #endif 203 204 extern int db_trapper(); 205 206 extern void dump_spl_masks __P((void)); 207 extern pt_entry_t *pmap_pte __P((pmap_t pmap, vm_offset_t va)); 208 extern void db_machine_init __P((void)); 209 extern void parse_mi_bootargs __P((char *args)); 210 211 extern void dumpsys __P((void)); 212 213 /* 214 * void cpu_reboot(int howto, char *bootstr) 215 * 216 * Reboots the system 217 * 218 * Deal with any syncing, unmounting, dumping and shutdown hooks, 219 * then reset the CPU. 220 */ 221 222 void 223 cpu_reboot(howto, bootstr) 224 int howto; 225 char *bootstr; 226 { 227 /* 228 * If we are still cold then hit the air brakes 229 * and crash to earth fast 230 */ 231 if (cold) { 232 doshutdownhooks(); 233 printf("Halted while still in the ICE age.\n"); 234 printf("The operating system has halted.\n"); 235 printf("Please press any key to reboot.\n\n"); 236 cngetc(); 237 printf("rebooting...\n"); 238 cpu_reset(); 239 /*NOTREACHED*/ 240 } 241 242 /* Disable console buffering */ 243 cnpollc(1); 244 245 /* 246 * If RB_NOSYNC was not specified sync the discs. 247 * Note: Unless cold is set to 1 here, syslogd will die during the unmount. 248 * It looks like syslogd is getting woken up only to find that it cannot 249 * page part of the binary in as the filesystem has been unmounted. 250 */ 251 if (!(howto & RB_NOSYNC)) 252 bootsync(); 253 254 /* Say NO to interrupts */ 255 splhigh(); 256 257 /* Do a dump if requested. */ 258 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) 259 dumpsys(); 260 261 262 /* Run any shutdown hooks */ 263 doshutdownhooks(); 264 265 /* Make sure IRQ's are disabled */ 266 IRQdisable; 267 268 if (howto & RB_HALT) { 269 printf("The operating system has halted.\n"); 270 printf("Please press any key to reboot.\n\n"); 271 cngetc(); 272 } 273 274 printf("rebooting...\n"); 275 cpu_reset(); 276 /*NOTREACHED*/ 277 } 278 279 /* 280 * 281 * Initial entry point on startup. This gets called before main() is 282 * entered. 283 * It should be responcible for setting up everything that must be 284 * in place when main is called. 285 * This includes 286 * Taking a copy of the boot configuration structure. 287 * Initialising the physical console so characters can be printed. 288 * Setting up page tables for the kernel 289 */ 290 291 u_int 292 initarm(bi) 293 struct bootinfo *bi; 294 { 295 int loop; 296 u_int kerneldatasize; 297 u_int l1pagetable; 298 u_int l2pagetable; 299 u_int stackptr; 300 vm_offset_t freemempos; 301 extern char page0[], page0_end[]; 302 pv_addr_t kernel_l1pt; 303 pv_addr_t kernel_ptpt; 304 305 /* 306 * Heads up ... Setup the CPU / MMU / TLB functions 307 */ 308 set_cpufuncs(); 309 310 /* Put the processer in SVC mode */ 311 __asm("mov r0, sp; mov r1, ip; mrs r2, cpsr_all;"); 312 /* PSR_MODE, PSR_SVC32_MODE" */ 313 __asm("bic r2, r2, #31; orr r2, r2, #19;"); 314 __asm("msr cpsr_all, r2; mov sp, r0; mov ip, r1;"); 315 316 #ifdef DEBUG_BEFOREMMU 317 /* 318 * At this point, we cannot call real consinit(). 319 * Just call a faked up version of consinit(), which does the thing 320 * with MMU disabled. 321 */ 322 fakecninit(); 323 #endif 324 325 /* 326 * XXX for now, overwrite bootconfig to hardcoded values. 327 * XXX kill bootconfig and directly call uvm_physload 328 */ 329 bootconfig.dram[0].address = 0xc0000000; 330 bootconfig.dram[0].pages = 8192; 331 bootconfig.dramblocks = 1; 332 kerneldatasize = (u_int32_t)&end - (u_int32_t)KERNEL_TEXT_BASE; 333 /* XXX round up kernel size. shouldn't be necessary. not confirmed. */ 334 kerneldatasize = ((kerneldatasize - 1) & ~(NBPG * 4 - 1)) 335 + NBPG * 4 + NBPG * 64; 336 printf("kernsize=0x%x\n", kerneldatasize); 337 338 /* copy bootinfo into known kernel space */ 339 bootinfo_storage = *(struct bootinfo *)bi; 340 bootinfo = &bootinfo_storage; 341 342 bootinfo->fb_addr = (void *)FRAMEBUF_BASE; 343 344 #ifdef BOOTINFO_FB_WIDTH 345 bootinfo->fb_line_bytes = BOOTINFO_FB_LINE_BYTES; 346 bootinfo->fb_width = BOOTINFO_FB_WIDTH; 347 bootinfo->fb_height = BOOTINFO_FB_HEIGHT; 348 bootinfo->fb_type = BOOTINFO_FB_TYPE; 349 #endif 350 351 /* 352 * hpcboot has loaded me with MMU disabled. 353 * So create kernel page tables and enable MMU 354 */ 355 356 /* 357 * Set up the variables that define the availablilty of physcial 358 * memory 359 */ 360 physical_start = bootconfig.dram[0].address; 361 physical_freestart = physical_start 362 + (KERNEL_TEXT_BASE - KERNEL_SPACE_START) + kerneldatasize; 363 physical_end = bootconfig.dram[bootconfig.dramblocks - 1].address 364 + bootconfig.dram[bootconfig.dramblocks - 1].pages * NBPG; 365 physical_freeend = physical_end; 366 /* free_pages = bootconfig.drampages;*/ 367 368 for (loop = 0; loop < bootconfig.dramblocks; ++loop) 369 physmem += bootconfig.dram[loop].pages; 370 371 /* XXX handle UMA framebuffer memory */ 372 373 /* Use the first 1MB to allocate things */ 374 freemempos = 0xc0000000; 375 memset((void *)0xc0000000, 0, 0x80000); 376 377 /* 378 * Right We have the bottom meg of memory mapped to 0x00000000 379 * so was can get at it. The kernel will ocupy the start of it. 380 * After the kernel/args we allocate some of the fixed page tables 381 * we need to get the system going. 382 * We allocate one page directory and 8 page tables and store the 383 * physical addresses in the kernel_pt_table array. 384 * Must remember that neither the page L1 or L2 page tables are the 385 * same size as a page ! 386 * 387 * Ok the next bit of physical allocate may look complex but it is 388 * simple really. I have done it like this so that no memory gets 389 * wasted during the allocate of various pages and tables that are 390 * all different sizes. 391 * The start address will be page aligned. 392 * We allocate the kernel page directory on the first free 16KB 393 * boundry we find. 394 * We allocate the kernel page tables on the first 1KB boundry we find. 395 * We allocate 9 PT's. This means that in the process we 396 * KNOW that we will encounter at least 1 16KB boundry. 397 * 398 * Eventually if the top end of the memory gets used for process L1 399 * page tables the kernel L1 page table may be moved up there. 400 */ 401 402 #ifdef VERBOSE_INIT_ARM 403 printf("Allocating page tables\n"); 404 #endif 405 406 /* Define a macro to simplify memory allocation */ 407 #define valloc_pages(var, np) \ 408 (var).pv_pa = (var).pv_va = freemempos; \ 409 freemempos += np * NBPG; 410 #define alloc_pages(var, np) \ 411 (var) = freemempos; \ 412 freemempos += np * NBPG; 413 414 415 valloc_pages(kernel_l1pt, PD_SIZE / NBPG); 416 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) { 417 alloc_pages(kernel_pt_table[loop], PT_SIZE / NBPG); 418 } 419 420 /* 421 * Allocate a page for the system page mapped to V0x00000000 422 * This page will just contain the system vectors and can be 423 * shared by all processes. 424 */ 425 valloc_pages(systempage, 1); 426 427 /* Allocate a page for the page table to map kernel page tables*/ 428 valloc_pages(kernel_ptpt, PT_SIZE / NBPG); 429 430 /* Allocate stacks for all modes */ 431 valloc_pages(irqstack, IRQ_STACK_SIZE); 432 valloc_pages(abtstack, ABT_STACK_SIZE); 433 valloc_pages(undstack, UND_STACK_SIZE); 434 valloc_pages(kernelstack, UPAGES); 435 436 #ifdef VERBOSE_INIT_ARM 437 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa, irqstack.pv_va); 438 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa, abtstack.pv_va); 439 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa, undstack.pv_va); 440 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa, kernelstack.pv_va); 441 #endif 442 443 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / NBPG); 444 445 #ifdef CPU_SA110 446 /* 447 * XXX totally stuffed hack to work round problems introduced 448 * in recent versions of the pmap code. Due to the calls used there 449 * we cannot allocate virtual memory during bootstrap. 450 */ 451 for(;;) { 452 alloc_pages(sa110_cc_base, 1); 453 if (! (sa110_cc_base & (CPU_SA110_CACHE_CLEAN_SIZE - 1))) 454 break; 455 } 456 { 457 vaddr_t dummy; 458 alloc_pages(dummy, CPU_SA110_CACHE_CLEAN_SIZE / NBPG - 1); 459 } 460 sa110_cache_clean_addr = sa110_cc_base; 461 sa110_cache_clean_size = CPU_SA110_CACHE_CLEAN_SIZE / 2; 462 #endif /* CPU_SA110 */ 463 464 /* 465 * Ok we have allocated physical pages for the primary kernel 466 * page tables 467 */ 468 469 #ifdef VERBOSE_INIT_ARM 470 printf("Creating L1 page table\n"); 471 #endif 472 473 /* 474 * Now we start consturction of the L1 page table 475 * We start by mapping the L2 page tables into the L1. 476 * This means that we can replace L1 mappings later on if necessary 477 */ 478 l1pagetable = kernel_l1pt.pv_pa; 479 480 /* Map the L2 pages tables in the L1 page table */ 481 map_pagetable(l1pagetable, 0x00000000, 482 kernel_pt_table[KERNEL_PT_SYS]); 483 map_pagetable(l1pagetable, KERNEL_SPACE_START, 484 kernel_pt_table[KERNEL_PT_KERNEL]); 485 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; ++loop) 486 map_pagetable(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000, 487 kernel_pt_table[KERNEL_PT_VMDATA + loop]); 488 map_pagetable(l1pagetable, PROCESS_PAGE_TBLS_BASE, 489 kernel_ptpt.pv_pa); 490 #define SAIPIO_BASE 0xd0000000 /* XXX XXX */ 491 map_pagetable(l1pagetable, SAIPIO_BASE, 492 kernel_pt_table[KERNEL_PT_IO]); 493 494 495 #ifdef VERBOSE_INIT_ARM 496 printf("Mapping kernel\n"); 497 #endif 498 499 /* Now we fill in the L2 pagetable for the kernel code/data */ 500 l2pagetable = kernel_pt_table[KERNEL_PT_KERNEL]; 501 502 /* 503 * XXX there is no ELF header to find RO region. 504 * XXX What should we do? 505 */ 506 #if 0 507 if (N_GETMAGIC(kernexec[0]) == ZMAGIC) { 508 logical = map_chunk(l1pagetable, l2pagetable, KERNEL_TEXT_BASE, 509 physical_start, kernexec->a_text, 510 AP_KR, PT_CACHEABLE); 511 logical += map_chunk(l1pagetable, l2pagetable, 512 KERNEL_TEXT_BASE + logical, physical_start + logical, 513 kerneldatasize - kernexec->a_text, AP_KRW, PT_CACHEABLE); 514 } else 515 #endif 516 map_chunk(l1pagetable, l2pagetable, KERNEL_TEXT_BASE, 517 KERNEL_TEXT_BASE, kerneldatasize, 518 AP_KRW, PT_CACHEABLE); 519 520 #ifdef VERBOSE_INIT_ARM 521 printf("Constructing L2 page tables\n"); 522 #endif 523 524 /* Map the stack pages */ 525 l2pagetable = kernel_pt_table[KERNEL_PT_KERNEL]; 526 map_chunk(0, l2pagetable, irqstack.pv_va, irqstack.pv_pa, 527 IRQ_STACK_SIZE * NBPG, AP_KRW, PT_CACHEABLE); 528 map_chunk(0, l2pagetable, abtstack.pv_va, abtstack.pv_pa, 529 ABT_STACK_SIZE * NBPG, AP_KRW, PT_CACHEABLE); 530 map_chunk(0, l2pagetable, undstack.pv_va, undstack.pv_pa, 531 UND_STACK_SIZE * NBPG, AP_KRW, PT_CACHEABLE); 532 map_chunk(0, l2pagetable, kernelstack.pv_va, kernelstack.pv_pa, 533 UPAGES * NBPG, AP_KRW, PT_CACHEABLE); 534 map_chunk(0, l2pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa, 535 PD_SIZE, AP_KRW, 0); 536 537 /* Map the page table that maps the kernel pages */ 538 map_entry_nc(l2pagetable, kernel_ptpt.pv_pa, kernel_ptpt.pv_pa); 539 540 /* 541 * Map entries in the page table used to map PTE's 542 * Basically every kernel page table gets mapped here 543 */ 544 /* The -2 is slightly bogus, it should be -log2(sizeof(pt_entry_t)) */ 545 l2pagetable = kernel_ptpt.pv_pa; 546 map_entry_nc(l2pagetable, (0x00000000 >> (PGSHIFT-2)), 547 kernel_pt_table[KERNEL_PT_SYS]); 548 map_entry_nc(l2pagetable, (KERNEL_SPACE_START >> (PGSHIFT-2)), 549 kernel_pt_table[KERNEL_PT_KERNEL]); 550 map_entry_nc(l2pagetable, (KERNEL_BASE >> (PGSHIFT-2)), 551 kernel_pt_table[KERNEL_PT_KERNEL]); 552 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; ++loop) { 553 map_entry_nc(l2pagetable, ((KERNEL_VM_BASE + 554 (loop * 0x00400000)) >> (PGSHIFT-2)), 555 kernel_pt_table[KERNEL_PT_VMDATA + loop]); 556 } 557 map_entry_nc(l2pagetable, (PROCESS_PAGE_TBLS_BASE >> (PGSHIFT-2)), 558 kernel_ptpt.pv_pa); 559 map_entry_nc(l2pagetable, (SAIPIO_BASE >> (PGSHIFT-2)), 560 kernel_pt_table[KERNEL_PT_IO]); 561 562 /* 563 * Map the system page in the kernel page table for the bottom 1Meg 564 * of the virtual memory map. 565 */ 566 l2pagetable = kernel_pt_table[KERNEL_PT_SYS]; 567 map_entry(l2pagetable, 0x0000000, systempage.pv_pa); 568 569 /* Map any I/O modules here, as we don't have real bus_space_map() */ 570 printf("mapping IO..."); 571 l2pagetable = kernel_pt_table[KERNEL_PT_IO]; 572 map_entry_nc(l2pagetable, SACOM3_BASE, SACOM3_HW_BASE); 573 574 #ifdef FRAMEBUF_HW_BASE 575 /* map framebuffer if its address is known */ 576 map_section(l1pagetable, FRAMEBUF_BASE, FRAMEBUF_HW_BASE, 1); 577 #endif 578 579 #ifdef CPU_SA110 580 l2pagetable = kernel_pt_table[KERNEL_PT_KERNEL]; 581 map_chunk(0, l2pagetable, sa110_cache_clean_addr, 582 sa110_cache_clean_addr, CPU_SA110_CACHE_CLEAN_SIZE, 583 AP_KRW, PT_CACHEABLE); 584 #endif 585 /* 586 * Now we have the real page tables in place so we can switch to them. 587 * Once this is done we will be running with the REAL kernel page 588 * tables. 589 */ 590 591 printf("done.\n"); 592 593 /* Right set up the vectors at the bottom of page 0 */ 594 memcpy((char *)systempage.pv_va, page0, page0_end - page0); 595 596 /* 597 * Pages were allocated during the secondary bootstrap for the 598 * stacks for different CPU modes. 599 * We must now set the r13 registers in the different CPU modes to 600 * point to these stacks. 601 * Since the ARM stacks use STMFD etc. we must set r13 to the top end 602 * of the stack memory. 603 */ 604 printf("init subsystems: stacks "); 605 606 set_stackptr(PSR_IRQ32_MODE, irqstack.pv_va + IRQ_STACK_SIZE * NBPG); 607 set_stackptr(PSR_ABT32_MODE, abtstack.pv_va + ABT_STACK_SIZE * NBPG); 608 set_stackptr(PSR_UND32_MODE, undstack.pv_va + UND_STACK_SIZE * NBPG); 609 #ifdef PMAP_DEBUG 610 if (pmap_debug_level >= 0) 611 printf("kstack V%08lx P%08lx\n", kernelstack.pv_va, 612 kernelstack.pv_pa); 613 #endif /* PMAP_DEBUG */ 614 615 /* 616 * Well we should set a data abort handler. 617 * Once things get going this will change as we will need a proper 618 * handler. Until then we will use a handler that just panics but 619 * tells us why. 620 * Initialisation of the vectors will just panic on a data abort. 621 * This just fills in a slighly better one. 622 */ 623 printf("vectors "); 624 data_abort_handler_address = (u_int)data_abort_handler; 625 prefetch_abort_handler_address = (u_int)prefetch_abort_handler; 626 undefined_handler_address = (u_int)undefinedinstruction_bounce; 627 printf("%08x %08x %08x\n", data_abort_handler_address, 628 prefetch_abort_handler_address, undefined_handler_address); 629 630 /* Initialise the undefined instruction handlers */ 631 printf("undefined "); 632 undefined_init(); 633 634 /* Relocate the stack pointer */ 635 stackptr = get_stackptr(PSR_SVC32_MODE); 636 printf("sp: %08x -> ", stackptr); 637 memcpy((char *)(kernelstack.pv_va + NBPG * (UPAGES - 1)), 638 (char *)(stackptr & ~(NBPG - 1)), NBPG); 639 stackptr = kernelstack.pv_va + NBPG * (UPAGES - 1) 640 + (stackptr & (NBPG - 1)); 641 /* set_stackptr(PSR_SVC32_MODE, stackptr);*/ 642 asm("mov sp, %0" : : "r" (stackptr)); 643 printf("%08x\n", stackptr); 644 645 /* Set the page table address. */ 646 setttb(kernel_l1pt.pv_pa); 647 648 /* Disable PID virtual address mapping */ 649 asm("mcr 15, 0, %0, c13, c0, 0" : : "r" (0)); 650 #ifdef BOOT_DUMP 651 dumppages((char *)0xb0100000, 64); /* XXX */ 652 #endif 653 /* Enable MMU, I-cache, D-cache, write buffer. */ 654 cpufunc_control(0x337f, 0x107d); 655 656 #ifndef FRAMEBUF_HW_BASE 657 bootinfo->bi_cnuse = BI_CNUSE_SERIAL; 658 #endif 659 if (bootinfo->bi_cnuse == BI_CNUSE_SERIAL) 660 consinit(); 661 else { 662 /* XXX this isn't useful for normal use, but helps debuging */ 663 biconscninit(&bicons); 664 cn_tab = &bicons; 665 cn_tab->cn_pri = CN_REMOTE; 666 } 667 668 #ifdef VERBOSE_INIT_ARM 669 printf("MMU enabled. control=%08x\n", cpu_get_control()); 670 #endif 671 672 /* Boot strap pmap telling it where the kernel page table is */ 673 pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, kernel_ptpt); 674 675 676 #ifdef CPU_SA110 677 if (cputype == CPU_ID_SA110) 678 rpc_sa110_cc_setup(); 679 #endif /* CPU_SA110 */ 680 681 #ifdef IPKDB 682 /* Initialise ipkdb */ 683 ipkdb_init(); 684 if (boothowto & RB_KDB) 685 ipkdb_connect(0); 686 #endif /* NIPKDB */ 687 688 #ifdef BOOT_DUMP 689 dumppages((char *)kernel_l1pt.pv_va, 16); 690 dumppages((char *)PROCESS_PAGE_TBLS_BASE, 16); 691 #endif 692 693 #ifdef DDB 694 printf("ddb: "); 695 #if 0 696 db_machine_init(); 697 { 698 extern int *esym; 699 700 ddb_init(*(int *)&end, ((int *)&end) + 1, esym); 701 } 702 #else 703 install_coproc_handler(0, db_trapper); 704 #endif 705 706 printf("kernsize=0x%x", kerneldatasize); 707 #if 0 708 printf(" syms=0x%x", symsize); 709 #endif 710 printf(" %d", (u_int32_t)&end - (u_int32_t)KERNEL_TEXT_BASE); 711 printf("\n"); 712 713 if (boothowto & RB_KDB) 714 Debugger(); 715 #endif /* DDB */ 716 717 /* We return the new stack pointer address */ 718 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP); 719 } 720 721 #ifdef DEBUG_BEFOREMMU 722 cons_decl(sacom); 723 void 724 fakecninit() 725 { 726 static struct consdev fakecntab = cons_init(sacom); 727 cn_tab = &fakecntab; 728 729 (*cn_tab->cn_init)(0); 730 cn_tab->cn_pri = CN_REMOTE; 731 } 732 #endif 733 734 #ifdef CPU_SA110 735 736 /* 737 * For optimal cache cleaning we need two 16K banks of 738 * virtual address space that NOTHING else will access 739 * and then we alternate the cache cleaning between the 740 * two banks. 741 * The cache cleaning code requires requires 2 banks aligned 742 * on total size boundry so the banks can be alternated by 743 * eorring the size bit (assumes the bank size is a power of 2) 744 */ 745 void 746 rpc_sa110_cc_setup(void) 747 { 748 int loop; 749 paddr_t kaddr; 750 pt_entry_t *pte; 751 752 (void) pmap_extract(kernel_pmap, KERNEL_TEXT_BASE, &kaddr); 753 for (loop = 0; loop < CPU_SA110_CACHE_CLEAN_SIZE; loop += NBPG) { 754 pte = pmap_pte(kernel_pmap, (sa110_cc_base + loop)); 755 *pte = L2_PTE(kaddr, AP_KR); 756 } 757 sa110_cache_clean_addr = sa110_cc_base; 758 sa110_cache_clean_size = CPU_SA110_CACHE_CLEAN_SIZE / 2; 759 } 760 #endif /* CPU_SA110 */ 761 762 #ifdef BOOT_DUMP 763 void dumppages(char *start, int nbytes) 764 { 765 char *p = start; 766 char *p1; 767 int i; 768 769 for(i = nbytes; i > 0; i -= 16, p += 16) { 770 for(p1 = p + 15; p != p1; p1--) { 771 if (*p1) 772 break; 773 } 774 if (! *p1) 775 continue; 776 printf("%08x %02x %02x %02x %02x %02x %02x %02x %02x" 777 " %02x %02x %02x %02x %02x %02x %02x %02x\n", 778 (unsigned int)p, 779 p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], 780 p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]); 781 } 782 } 783 #endif 784 785 /* End of machdep.c */ 786