int _bus_dmamap_load_vaddr(bus_dma_tag_t t, bus_dmamap_t map, void *buf, bus_size_t size, pmap_t pmap) { vaddr_t vaddr; paddr_t paddr; vaddr_t next, end; int error; vaddr = (vaddr_t)buf; end = vaddr + size; if (pmap == pmap_kernel() && vaddr >= SH3_P1SEG_BASE && end <= SH3_P2SEG_END) paddr = SH3_P1SEG_TO_PHYS(vaddr); else { for (next = (vaddr + PAGE_SIZE) & ~PAGE_MASK; next < end; next += PAGE_SIZE) { pmap_extract(pmap, vaddr, &paddr); error = _bus_dmamap_load_paddr(t, map, paddr, vaddr, next - vaddr); if (error != 0) return (error); vaddr = next; } pmap_extract(pmap, vaddr, &paddr); size = end - vaddr; } return (_bus_dmamap_load_paddr(t, map, paddr, vaddr, size)); }
/* * Dump the machine-dependent dump header. */ u_int cpu_dump(int (*dump)(dev_t, daddr_t, caddr_t, size_t), daddr_t *blknop) { extern cpu_kcore_hdr_t cpu_kcore_hdr; char buf[dbtob(1)]; cpu_kcore_hdr_t *h; kcore_seg_t *kseg; int rc; #ifdef DIAGNOSTIC if (cpu_dumpsize() > btodb(sizeof buf)) { printf("buffer too small in cpu_dump, "); return (EINVAL); /* "aborted" */ } #endif bzero(buf, sizeof buf); kseg = (kcore_seg_t *)buf; h = (cpu_kcore_hdr_t *)(buf + ALIGN(sizeof(kcore_seg_t))); /* Create the segment header */ CORE_SETMAGIC(*kseg, KCORE_MAGIC, MID_MACHINE, CORE_CPU); kseg->c_size = dbtob(1) - ALIGN(sizeof(kcore_seg_t)); bcopy(&cpu_kcore_hdr, h, sizeof(*h)); /* We can now fill kptp in the header... */ h->kcore_kptp = SH3_P1SEG_TO_PHYS((vaddr_t)pmap_kernel()->pm_ptp); rc = (*dump)(dumpdev, *blknop, buf, sizeof buf); *blknop += btodb(sizeof buf); return (rc); }
__dead void landisk_startup(int howto, char *_esym) { u_int32_t ramsize; /* Start to determine heap area */ esym = _esym; kernend = (vaddr_t)round_page((vaddr_t)esym); boothowto = howto; ramsize = getramsize(); /* Initialize CPU ops. */ sh_cpu_init(CPU_ARCH_SH4, CPU_PRODUCT_7751R); /* Initialize early console */ consinit(); /* Load memory to UVM */ if (ramsize == 0 || ramsize > 512 * 1024 * 1024) ramsize = IOM_RAM_SIZE; physmem = atop(ramsize); kernend = atop(round_page(SH3_P1SEG_TO_PHYS(kernend))); uvm_page_physload(atop(IOM_RAM_BEGIN), atop(IOM_RAM_BEGIN + ramsize), kernend, atop(IOM_RAM_BEGIN + ramsize), 0); cpu_init_kcore_hdr(); /* need to be done before pmap_bootstrap */ /* Initialize proc0 u-area */ sh_proc0_init(); /* Initialize pmap and start to address translation */ pmap_bootstrap(); #if defined(DDB) db_machine_init(); ddb_init(); if (boothowto & RB_KDB) { Debugger(); } #endif /* Jump to main */ __asm volatile( "jmp @%0\n\t" " mov %1, sp" :: "r" (main), "r" (proc0.p_md.md_pcb->pcb_sf.sf_r7_bank)); /* NOTREACHED */ for (;;) ; }
void dreamcast_startup() { extern char edata[], end[]; paddr_t kernend; /* Clear bss */ memset(edata, 0, end - edata); /* Initialize CPU ops. */ sh_cpu_init(CPU_ARCH_SH4, CPU_PRODUCT_7750); /* Console */ consinit(); /* Load memory to UVM */ physmem = atop(IOM_RAM_SIZE); kernend = atop(round_page(SH3_P1SEG_TO_PHYS(end))); uvm_page_physload( kernend, atop(IOM_RAM_BEGIN + IOM_RAM_SIZE), kernend, atop(IOM_RAM_BEGIN + IOM_RAM_SIZE), VM_FREELIST_DEFAULT); /* Initialize proc0 u-area */ sh_proc0_init(); /* Initialize pmap and start to address translation */ pmap_bootstrap(); /* Debugger. */ #ifdef DDB ddb_init(0, NULL, NULL); #endif #if defined(KGDB) && (NSCIF > 0) if (scif_kgdb_init() == 0) { kgdb_debug_init = 1; kgdb_connect(1); } #endif /* KGDB && NSCIF > 0 */ /* Jump to main */ __asm__ __volatile__( "jmp @%0;" "mov %1, sp" :: "r"(main),"r"(proc0.p_md.md_pcb->pcb_sf.sf_r7_bank)); /* NOTREACHED */ while (1) ; }
/*ARGSUSED*/ int mmrw(dev_t dev, struct uio *uio, int flags) { struct iovec *iov; vaddr_t v, o; int c; int error = 0; while (uio->uio_resid > 0 && !error) { iov = uio->uio_iov; if (iov->iov_len == 0) { uio->uio_iov++; uio->uio_iovcnt--; if (uio->uio_iovcnt < 0) panic("mmrw"); continue; } v = uio->uio_offset; switch (minor(dev)) { kmemphys: case DEV_MEM: /* Physical address */ if (__mm_mem_addr(v)) { o = v & PGOFSET; c = min(uio->uio_resid, (int)(PAGE_SIZE - o)); error = uiomove((void *)SH3_PHYS_TO_P1SEG(v), c, uio); } else { return (EFAULT); } break; case DEV_KMEM: /* P0 */ if (v < SH3_P1SEG_BASE) return (EFAULT); /* P1 */ if (v < SH3_P2SEG_BASE) { v = SH3_P1SEG_TO_PHYS(v); goto kmemphys; } /* P2 */ if (v < SH3_P3SEG_BASE) return (EFAULT); /* P3 */ c = min(iov->iov_len, MAXPHYS); if (!uvm_kernacc((void *)v, c, uio->uio_rw == UIO_READ ? B_READ : B_WRITE)) return (EFAULT); error = uiomove((void *)v, c, uio); break; case DEV_NULL: if (uio->uio_rw == UIO_WRITE) uio->uio_resid = 0; return (0); case DEV_ZERO: if (uio->uio_rw == UIO_WRITE) { uio->uio_resid = 0; return (0); } if (zeropage == NULL) { zeropage = malloc(PAGE_SIZE, M_TEMP, M_WAITOK); memset(zeropage, 0, PAGE_SIZE); } c = min(iov->iov_len, PAGE_SIZE); error = uiomove(zeropage, c, uio); break; default: return (ENXIO); } } return (error); }
void machine_startup(int argc, char *argv[], struct bootinfo *bi) { extern char edata[], end[]; vaddr_t kernend; size_t symbolsize; int i; char *p; /* * this routines stack is never polluted since stack pointer * is lower than kernel text segment, and at exiting, stack pointer * is changed to proc0. */ struct kloader_bootinfo kbi; /* Symbol table size */ symbolsize = 0; if (memcmp(&end, ELFMAG, SELFMAG) == 0) { Elf_Ehdr *eh = (void *)end; Elf_Shdr *sh = (void *)(end + eh->e_shoff); for(i = 0; i < eh->e_shnum; i++, sh++) if (sh->sh_offset > 0 && (sh->sh_offset + sh->sh_size) > symbolsize) symbolsize = sh->sh_offset + sh->sh_size; } /* Clear BSS */ memset(edata, 0, end - edata); /* Setup bootinfo */ bootinfo = &kbi.bootinfo; memcpy(bootinfo, bi, sizeof(struct bootinfo)); if (bootinfo->magic == BOOTINFO_MAGIC) { platid.dw.dw0 = bootinfo->platid_cpu; platid.dw.dw1 = bootinfo->platid_machine; } /* CPU initialize */ if (platid_match(&platid, &platid_mask_CPU_SH_3)) sh_cpu_init(CPU_ARCH_SH3, CPU_PRODUCT_7709A); else if (platid_match(&platid, &platid_mask_CPU_SH_4)) sh_cpu_init(CPU_ARCH_SH4, CPU_PRODUCT_7750); /* Start to determine heap area */ kernend = (vaddr_t)sh3_round_page(end + symbolsize); /* Setup bootstrap options */ makebootdev("wd0"); /* default boot device */ boothowto = 0; for (i = 1; i < argc; i++) { /* skip 1st arg (kernel name). */ char *cp = argv[i]; switch (*cp) { case 'b': /* boot device: -b=sd0 etc. */ p = cp + 2; #ifdef NFS if (strcmp(p, "nfs") == 0) mountroot = nfs_mountroot; else makebootdev(p); #else /* NFS */ makebootdev(p); #endif /* NFS */ break; default: BOOT_FLAG(*cp, boothowto); break; } } #ifdef MFS /* * Check to see if a mini-root was loaded into memory. It resides * at the start of the next page just after the end of BSS. */ if (boothowto & RB_MINIROOT) { size_t fssz; fssz = sh3_round_page(mfs_initminiroot((void *)kernend)); #ifdef MEMORY_DISK_DYNAMIC md_root_setconf((caddr_t)kernend, fssz); #endif kernend += fssz; } #endif /* MFS */ /* Console */ consinit(); #ifdef HPC_DEBUG_LCD dbg_lcd_test(); #endif /* copy boot parameter for kloader */ kloader_bootinfo_set(&kbi, argc, argv, bi, TRUE); /* Find memory cluster. and load to UVM */ physmem = mem_cluster_init(SH3_P1SEG_TO_PHYS(kernend)); _DPRINTF("total memory = %dMbyte\n", (int)(sh3_ptob(physmem) >> 20)); mem_cluster_load(); /* Initialize proc0 u-area */ sh_proc0_init(); /* Initialize pmap and start to address translation */ pmap_bootstrap(); /* Debugger. */ #ifdef DDB if (symbolsize) { ddb_init(symbolsize, &end, end + symbolsize); _DPRINTF("symbol size = %d byte\n", symbolsize); } if (boothowto & RB_KDB) Debugger(); #endif /* DDB */ #ifdef KGDB if (boothowto & RB_KDB) { if (kgdb_dev == NODEV) { printf("no kgdb console.\n"); } else { kgdb_debug_init = 1; kgdb_connect(1); } } #endif /* KGDB */ /* Jump to main */ __asm__ __volatile__( "jmp @%0;" "mov %1, sp" :: "r"(main),"r"(proc0.p_md.md_pcb->pcb_sf.sf_r7_bank)); /* NOTREACHED */ while (1) ; }