1*1f87e7b7Sart /* $OpenBSD: machdep.c,v 1.107 2007/04/23 10:07:43 art Exp $ */ 22a2685f2Sart /* $NetBSD: machdep.c,v 1.210 2000/06/01 17:12:38 thorpej Exp $ */ 3aed035abSart 4aed035abSart /*- 5aed035abSart * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc. 6aed035abSart * All rights reserved. 7aed035abSart * 8aed035abSart * This code is derived from software contributed to The NetBSD Foundation 9aed035abSart * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 10aed035abSart * NASA Ames Research Center and by Chris G. Demetriou. 11aed035abSart * 12aed035abSart * Redistribution and use in source and binary forms, with or without 13aed035abSart * modification, are permitted provided that the following conditions 14aed035abSart * are met: 15aed035abSart * 1. Redistributions of source code must retain the above copyright 16aed035abSart * notice, this list of conditions and the following disclaimer. 17aed035abSart * 2. Redistributions in binary form must reproduce the above copyright 18aed035abSart * notice, this list of conditions and the following disclaimer in the 19aed035abSart * documentation and/or other materials provided with the distribution. 20aed035abSart * 3. All advertising materials mentioning features or use of this software 21aed035abSart * must display the following acknowledgement: 22aed035abSart * This product includes software developed by the NetBSD 23aed035abSart * Foundation, Inc. and its contributors. 24aed035abSart * 4. Neither the name of The NetBSD Foundation nor the names of its 25aed035abSart * contributors may be used to endorse or promote products derived 26aed035abSart * from this software without specific prior written permission. 27aed035abSart * 28aed035abSart * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 29aed035abSart * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 30aed035abSart * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 31aed035abSart * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 32aed035abSart * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33aed035abSart * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 34aed035abSart * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 35aed035abSart * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 36aed035abSart * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 37aed035abSart * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38aed035abSart * POSSIBILITY OF SUCH DAMAGE. 39aed035abSart */ 40df930be7Sderaadt 41df930be7Sderaadt /* 42417eba8cSderaadt * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University. 43df930be7Sderaadt * All rights reserved. 44df930be7Sderaadt * 45df930be7Sderaadt * Author: Chris G. Demetriou 46df930be7Sderaadt * 47df930be7Sderaadt * Permission to use, copy, modify and distribute this software and 48df930be7Sderaadt * its documentation is hereby granted, provided that both the copyright 49df930be7Sderaadt * notice and this permission notice appear in all copies of the 50df930be7Sderaadt * software, derivative works or modified versions, and any portions 51df930be7Sderaadt * thereof, and that both notices appear in supporting documentation. 52df930be7Sderaadt * 53df930be7Sderaadt * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 54df930be7Sderaadt * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 55df930be7Sderaadt * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 56df930be7Sderaadt * 57df930be7Sderaadt * Carnegie Mellon requests users of this software to return to 58df930be7Sderaadt * 59df930be7Sderaadt * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 60df930be7Sderaadt * School of Computer Science 61df930be7Sderaadt * Carnegie Mellon University 62df930be7Sderaadt * Pittsburgh PA 15213-3890 63df930be7Sderaadt * 64df930be7Sderaadt * any improvements or extensions that they make and grant Carnegie the 65df930be7Sderaadt * rights to redistribute these changes. 66df930be7Sderaadt */ 67df930be7Sderaadt 68df930be7Sderaadt #include <sys/param.h> 69df930be7Sderaadt #include <sys/systm.h> 70df930be7Sderaadt #include <sys/signalvar.h> 71df930be7Sderaadt #include <sys/kernel.h> 72df930be7Sderaadt #include <sys/proc.h> 732a2685f2Sart #include <sys/sched.h> 74df930be7Sderaadt #include <sys/buf.h> 75df930be7Sderaadt #include <sys/reboot.h> 76417eba8cSderaadt #include <sys/device.h> 77df930be7Sderaadt #include <sys/conf.h> 78df930be7Sderaadt #include <sys/file.h> 79d66eba84Sart #include <sys/timeout.h> 80df930be7Sderaadt #include <sys/malloc.h> 81df930be7Sderaadt #include <sys/mbuf.h> 82df930be7Sderaadt #include <sys/msgbuf.h> 83df930be7Sderaadt #include <sys/ioctl.h> 84df930be7Sderaadt #include <sys/tty.h> 85df930be7Sderaadt #include <sys/user.h> 86df930be7Sderaadt #include <sys/exec.h> 87df930be7Sderaadt #include <sys/exec_ecoff.h> 88489e49f9Smiod #include <uvm/uvm_extern.h> 89df930be7Sderaadt #include <sys/sysctl.h> 9050ce9ee0Sniklas #include <sys/core.h> 9150ce9ee0Sniklas #include <sys/kcore.h> 9250ce9ee0Sniklas #include <machine/kcore.h> 93433075b6Spvalchev #ifndef NO_IEEE 94433075b6Spvalchev #include <machine/fpu.h> 95433075b6Spvalchev #endif 96df930be7Sderaadt #ifdef SYSVMSG 97df930be7Sderaadt #include <sys/msg.h> 98df930be7Sderaadt #endif 99*1f87e7b7Sart #include <sys/timetc.h> 100df930be7Sderaadt 101df930be7Sderaadt #include <sys/mount.h> 102df930be7Sderaadt #include <sys/syscallargs.h> 103df930be7Sderaadt 104df930be7Sderaadt #include <dev/cons.h> 105df930be7Sderaadt 10650ce9ee0Sniklas #include <machine/autoconf.h> 107df930be7Sderaadt #include <machine/cpu.h> 108df930be7Sderaadt #include <machine/reg.h> 109df930be7Sderaadt #include <machine/rpb.h> 110df930be7Sderaadt #include <machine/prom.h> 1113a630e3fSniklas #include <machine/cpuconf.h> 112433075b6Spvalchev #ifndef NO_IEEE 113433075b6Spvalchev #include <machine/ieeefp.h> 114433075b6Spvalchev #endif 115df930be7Sderaadt 11645e5a1a0Sart #include <dev/pci/pcivar.h> 11745e5a1a0Sart 11812f8bbedSniklas #ifdef DDB 11912f8bbedSniklas #include <machine/db_machdep.h> 12012f8bbedSniklas #include <ddb/db_access.h> 12112f8bbedSniklas #include <ddb/db_sym.h> 12212f8bbedSniklas #include <ddb/db_extern.h> 12312f8bbedSniklas #endif 12412f8bbedSniklas 125c4071fd1Smillert int cpu_dump(void); 126c4071fd1Smillert int cpu_dumpsize(void); 127c4071fd1Smillert u_long cpu_dump_mempagecnt(void); 128c4071fd1Smillert void dumpsys(void); 129c4071fd1Smillert caddr_t allocsys(caddr_t); 130c4071fd1Smillert void identifycpu(void); 131c4071fd1Smillert void regdump(struct trapframe *framep); 132c4071fd1Smillert void printregs(struct reg *); 133df930be7Sderaadt 134df930be7Sderaadt /* 135df930be7Sderaadt * Declare these as initialized data so we can patch them. 136df930be7Sderaadt */ 137df930be7Sderaadt #ifdef NBUF 138df930be7Sderaadt int nbuf = NBUF; 139df930be7Sderaadt #else 140df930be7Sderaadt int nbuf = 0; 141df930be7Sderaadt #endif 14260535ec9Smaja 14360535ec9Smaja #ifndef BUFCACHEPERCENT 14460535ec9Smaja #define BUFCACHEPERCENT 10 14560535ec9Smaja #endif 14660535ec9Smaja 147df930be7Sderaadt #ifdef BUFPAGES 148df930be7Sderaadt int bufpages = BUFPAGES; 149df930be7Sderaadt #else 150df930be7Sderaadt int bufpages = 0; 151df930be7Sderaadt #endif 15260535ec9Smaja int bufcachepercent = BUFCACHEPERCENT; 153aed035abSart 154ab8e80c5Sart struct vm_map *exec_map = NULL; 155ab8e80c5Sart struct vm_map *phys_map = NULL; 156aed035abSart 15727626149Smatthieu #ifdef APERTURE 15827626149Smatthieu #ifdef INSECURE 15927626149Smatthieu int allowaperture = 1; 16027626149Smatthieu #else 16127626149Smatthieu int allowaperture = 0; 16227626149Smatthieu #endif 16327626149Smatthieu #endif 16427626149Smatthieu 165df930be7Sderaadt int totalphysmem; /* total amount of physical memory in system */ 16674652a67Sniklas int physmem; /* physical mem used by OpenBSD + some rsvd */ 167df930be7Sderaadt int resvmem; /* amount of memory reserved for PROM */ 168df930be7Sderaadt int unusedmem; /* amount of memory for OS that we don't use */ 169df930be7Sderaadt int unknownmem; /* amount of memory with an unknown use */ 170df930be7Sderaadt 171df930be7Sderaadt int cputype; /* system type, from the RPB */ 1722586fa93Smiod int alpha_cpus; 173df930be7Sderaadt 1742a2685f2Sart int bootdev_debug = 0; /* patchable, or from DDB */ 1752a2685f2Sart 176df930be7Sderaadt /* 177df930be7Sderaadt * XXX We need an address to which we can assign things so that they 178df930be7Sderaadt * won't be optimized away because we didn't use the value. 179df930be7Sderaadt */ 180df930be7Sderaadt u_int32_t no_optimize; 181df930be7Sderaadt 182df930be7Sderaadt /* the following is used externally (sysctl_hw) */ 183aed035abSart char machine[] = MACHINE; /* from <machine/param.h> */ 184417eba8cSderaadt char cpu_model[128]; 185aed035abSart char root_device[17]; 186df930be7Sderaadt 187df930be7Sderaadt struct user *proc0paddr; 188df930be7Sderaadt 189df930be7Sderaadt /* Number of machine cycles per microsecond */ 190df930be7Sderaadt u_int64_t cycles_per_usec; 191df930be7Sderaadt 192aed035abSart struct bootinfo_kernel bootinfo; 193aed035abSart 194aed035abSart /* For built-in TCDS */ 195aed035abSart #if defined(DEC_3000_300) || defined(DEC_3000_500) 196aed035abSart u_int8_t dec_3000_scsiid[2], dec_3000_scsifast[2]; 197aed035abSart #endif 198aed035abSart 199aed035abSart struct platform platform; 200417eba8cSderaadt 201417eba8cSderaadt /* for cpu_sysctl() */ 20250ce9ee0Sniklas int alpha_unaligned_print = 1; /* warn about unaligned accesses */ 20350ce9ee0Sniklas int alpha_unaligned_fix = 1; /* fix up unaligned accesses */ 204881c1eabSart int alpha_unaligned_sigbus = 1; /* SIGBUS on fixed-up accesses */ 205433075b6Spvalchev #ifndef NO_IEEE 206433075b6Spvalchev int alpha_fp_sync_complete = 0; /* fp fixup if sync even without /s */ 207433075b6Spvalchev #endif 20850ce9ee0Sniklas 209b3cee53eSmartin /* used by hw_sysctl */ 210b3cee53eSmartin extern char *hw_serial; 211b3cee53eSmartin 212aed035abSart /* 213aed035abSart * XXX This should be dynamically sized, but we have the chicken-egg problem! 214aed035abSart * XXX it should also be larger than it is, because not all of the mddt 215aed035abSart * XXX clusters end up being used for VM. 216aed035abSart */ 217aed035abSart phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX]; /* low size bits overloaded */ 218aed035abSart int mem_cluster_cnt; 219aed035abSart 2203a630e3fSniklas void 221aed035abSart alpha_init(pfn, ptb, bim, bip, biv) 222df930be7Sderaadt u_long pfn; /* first free PFN number */ 223df930be7Sderaadt u_long ptb; /* PFN of current level 1 page table */ 224aed035abSart u_long bim; /* bootinfo magic */ 225aed035abSart u_long bip; /* bootinfo pointer */ 226aed035abSart u_long biv; /* bootinfo version */ 227df930be7Sderaadt { 228aed035abSart extern char kernel_text[], _end[]; 229df930be7Sderaadt struct mddt *mddtp; 230aed035abSart struct mddt_cluster *memc; 231df930be7Sderaadt int i, mddtweird; 232aed035abSart struct vm_physseg *vps; 233aed035abSart vaddr_t kernstart, kernend; 234aed035abSart paddr_t kernstartpfn, kernendpfn, pfn0, pfn1; 235aed035abSart vsize_t size; 236df930be7Sderaadt char *p; 237aed035abSart caddr_t v; 2382a2685f2Sart const char *bootinfo_msg; 239aed035abSart const struct cpuinit *c; 240aed035abSart extern caddr_t esym; 241aed035abSart struct cpu_info *ci; 242aed035abSart cpuid_t cpu_id; 243df930be7Sderaadt 244aed035abSart /* NO OUTPUT ALLOWED UNTIL FURTHER NOTICE */ 245f3914c62Sniklas 246df930be7Sderaadt /* 247aed035abSart * Turn off interrupts (not mchecks) and floating point. 248df930be7Sderaadt * Make sure the instruction and data streams are consistent. 249df930be7Sderaadt */ 250aed035abSart (void)alpha_pal_swpipl(ALPHA_PSL_IPL_HIGH); 25150ce9ee0Sniklas alpha_pal_wrfen(0); 25250ce9ee0Sniklas ALPHA_TBIA(); 25350ce9ee0Sniklas alpha_pal_imb(); 254df930be7Sderaadt 255c62181b1Sbrad /* Initialize the SCB. */ 256c62181b1Sbrad scb_init(); 257c62181b1Sbrad 258aed035abSart cpu_id = cpu_number(); 259aed035abSart 260aed035abSart #if defined(MULTIPROCESSOR) 261df930be7Sderaadt /* 262aed035abSart * Set our SysValue to the address of our cpu_info structure. 263aed035abSart * Secondary processors do this in their spinup trampoline. 264df930be7Sderaadt */ 265aed035abSart alpha_pal_wrval((u_long)&cpu_info[cpu_id]); 266aed035abSart #endif 267aed035abSart 268aed035abSart ci = curcpu(); 269aed035abSart ci->ci_cpuid = cpu_id; 270aed035abSart 271aed035abSart /* 272aed035abSart * Get critical system information (if possible, from the 273aed035abSart * information provided by the boot program). 274aed035abSart */ 275aed035abSart bootinfo_msg = NULL; 276aed035abSart if (bim == BOOTINFO_MAGIC) { 277aed035abSart if (biv == 0) { /* backward compat */ 278aed035abSart biv = *(u_long *)bip; 279aed035abSart bip += 8; 280aed035abSart } 281aed035abSart switch (biv) { 282aed035abSart case 1: { 283aed035abSart struct bootinfo_v1 *v1p = (struct bootinfo_v1 *)bip; 284aed035abSart 285aed035abSart bootinfo.ssym = v1p->ssym; 286aed035abSart bootinfo.esym = v1p->esym; 287aed035abSart /* hwrpb may not be provided by boot block in v1 */ 288aed035abSart if (v1p->hwrpb != NULL) { 289aed035abSart bootinfo.hwrpb_phys = 290aed035abSart ((struct rpb *)v1p->hwrpb)->rpb_phys; 291aed035abSart bootinfo.hwrpb_size = v1p->hwrpbsize; 292aed035abSart } else { 293aed035abSart bootinfo.hwrpb_phys = 294aed035abSart ((struct rpb *)HWRPB_ADDR)->rpb_phys; 295aed035abSart bootinfo.hwrpb_size = 296aed035abSart ((struct rpb *)HWRPB_ADDR)->rpb_size; 297aed035abSart } 298aed035abSart bcopy(v1p->boot_flags, bootinfo.boot_flags, 299aed035abSart min(sizeof v1p->boot_flags, 300aed035abSart sizeof bootinfo.boot_flags)); 301aed035abSart bcopy(v1p->booted_kernel, bootinfo.booted_kernel, 302aed035abSart min(sizeof v1p->booted_kernel, 303aed035abSart sizeof bootinfo.booted_kernel)); 304aed035abSart /* booted dev not provided in bootinfo */ 305aed035abSart init_prom_interface((struct rpb *) 306aed035abSart ALPHA_PHYS_TO_K0SEG(bootinfo.hwrpb_phys)); 307aed035abSart prom_getenv(PROM_E_BOOTED_DEV, bootinfo.booted_dev, 308aed035abSart sizeof bootinfo.booted_dev); 309aed035abSart break; 310aed035abSart } 311aed035abSart default: 312aed035abSart bootinfo_msg = "unknown bootinfo version"; 313aed035abSart goto nobootinfo; 314aed035abSart } 315aed035abSart } else { 316aed035abSart bootinfo_msg = "boot program did not pass bootinfo"; 317aed035abSart nobootinfo: 318aed035abSart bootinfo.ssym = (u_long)_end; 319aed035abSart bootinfo.esym = (u_long)_end; 320aed035abSart bootinfo.hwrpb_phys = ((struct rpb *)HWRPB_ADDR)->rpb_phys; 321aed035abSart bootinfo.hwrpb_size = ((struct rpb *)HWRPB_ADDR)->rpb_size; 322aed035abSart init_prom_interface((struct rpb *)HWRPB_ADDR); 323aed035abSart prom_getenv(PROM_E_BOOTED_OSFLAGS, bootinfo.boot_flags, 324aed035abSart sizeof bootinfo.boot_flags); 325aed035abSart prom_getenv(PROM_E_BOOTED_FILE, bootinfo.booted_kernel, 326aed035abSart sizeof bootinfo.booted_kernel); 327aed035abSart prom_getenv(PROM_E_BOOTED_DEV, bootinfo.booted_dev, 328aed035abSart sizeof bootinfo.booted_dev); 329aed035abSart } 330aed035abSart 331aed035abSart esym = (caddr_t)bootinfo.esym; 332aed035abSart /* 333aed035abSart * Initialize the kernel's mapping of the RPB. It's needed for 334aed035abSart * lots of things. 335aed035abSart */ 336aed035abSart hwrpb = (struct rpb *)ALPHA_PHYS_TO_K0SEG(bootinfo.hwrpb_phys); 337aed035abSart 338aed035abSart #if defined(DEC_3000_300) || defined(DEC_3000_500) 339aed035abSart if (hwrpb->rpb_type == ST_DEC_3000_300 || 340aed035abSart hwrpb->rpb_type == ST_DEC_3000_500) { 341aed035abSart prom_getenv(PROM_E_SCSIID, dec_3000_scsiid, 342aed035abSart sizeof(dec_3000_scsiid)); 343aed035abSart prom_getenv(PROM_E_SCSIFAST, dec_3000_scsifast, 344aed035abSart sizeof(dec_3000_scsifast)); 345aed035abSart } 346aed035abSart #endif 347df930be7Sderaadt 348df930be7Sderaadt /* 349df930be7Sderaadt * Remember how many cycles there are per microsecond, 350df930be7Sderaadt * so that we can use delay(). Round up, for safety. 351df930be7Sderaadt */ 352df930be7Sderaadt cycles_per_usec = (hwrpb->rpb_cc_freq + 999999) / 1000000; 353df930be7Sderaadt 354df930be7Sderaadt /* 3559e71c994Saaron * Initialize the (temporary) bootstrap console interface, so 356aed035abSart * we can use printf until the VM system starts being setup. 357aed035abSart * The real console is initialized before then. 358df930be7Sderaadt */ 359aed035abSart init_bootstrap_console(); 360aed035abSart 361aed035abSart /* OUTPUT NOW ALLOWED */ 362aed035abSart 363aed035abSart /* delayed from above */ 364aed035abSart if (bootinfo_msg) 365aed035abSart printf("WARNING: %s (0x%lx, 0x%lx, 0x%lx)\n", 366aed035abSart bootinfo_msg, bim, bip, biv); 367aed035abSart 368aed035abSart /* Initialize the trap vectors on the primary processor. */ 369aed035abSart trap_init(); 370df930be7Sderaadt 371df930be7Sderaadt /* 372aed035abSart * Find out what hardware we're on, and do basic initialization. 373df930be7Sderaadt */ 374aed035abSart cputype = hwrpb->rpb_type; 375aed035abSart if (cputype < 0) { 376aed035abSart /* 377aed035abSart * At least some white-box systems have SRM which 378aed035abSart * reports a systype that's the negative of their 379aed035abSart * blue-box counterpart. 380aed035abSart */ 381aed035abSart cputype = -cputype; 382aed035abSart } 383aed035abSart c = platform_lookup(cputype); 384aed035abSart if (c == NULL) { 385aed035abSart platform_not_supported(); 386aed035abSart /* NOTREACHED */ 387aed035abSart } 388aed035abSart (*c->init)(); 389094fa01fSderaadt strlcpy(cpu_model, platform.model, sizeof cpu_model); 39050ce9ee0Sniklas 39150ce9ee0Sniklas /* 3929e71c994Saaron * Initialize the real console, so that the bootstrap console is 393aed035abSart * no longer necessary. 39450ce9ee0Sniklas */ 395aed035abSart (*platform.cons_init)(); 396aed035abSart 397a55851f4Sderaadt #if 0 398aed035abSart /* Paranoid sanity checking */ 399aed035abSart 400aed035abSart assert(hwrpb->rpb_primary_cpu_id == alpha_pal_whami()); 401aed035abSart 402aed035abSart /* 403aed035abSart * On single-CPU systypes, the primary should always be CPU 0, 404aed035abSart * except on Alpha 8200 systems where the CPU id is related 405aed035abSart * to the VID, which is related to the Turbo Laser node id. 406aed035abSart */ 407aed035abSart if (cputype != ST_DEC_21000) 408aed035abSart assert(hwrpb->rpb_primary_cpu_id == 0); 409aed035abSart #endif 410aed035abSart 411aed035abSart /* NO MORE FIRMWARE ACCESS ALLOWED */ 412aed035abSart #ifdef _PMAP_MAY_USE_PROM_CONSOLE 413aed035abSart /* 414aed035abSart * XXX (unless _PMAP_MAY_USE_PROM_CONSOLE is defined and 415aed035abSart * XXX pmap_uses_prom_console() evaluates to non-zero.) 416aed035abSart */ 417aed035abSart #endif 418aed035abSart 419cfcdef40Smiod #ifndef SMALL_KERNEL 420cfcdef40Smiod /* 421cfcdef40Smiod * If we run on a BWX-capable processor, override cpu_switch 422cfcdef40Smiod * with a faster version. 423cfcdef40Smiod * We do this now because the kernel text might be mapped 424cfcdef40Smiod * read-only eventually (although this is not the case at the moment). 425cfcdef40Smiod */ 426cfcdef40Smiod if (alpha_implver() >= ALPHA_IMPLVER_EV5) { 427cfcdef40Smiod if (~alpha_amask(ALPHA_AMASK_BWX) != 0) { 428cfcdef40Smiod extern vaddr_t __bwx_switch0, __bwx_switch1, 429cfcdef40Smiod __bwx_switch2, __bwx_switch3; 430cfcdef40Smiod u_int32_t *dst, *src, *end; 431cfcdef40Smiod 432cfcdef40Smiod src = (u_int32_t *)&__bwx_switch2; 433cfcdef40Smiod end = (u_int32_t *)&__bwx_switch3; 434cfcdef40Smiod dst = (u_int32_t *)&__bwx_switch0; 435cfcdef40Smiod while (src != end) 436cfcdef40Smiod *dst++ = *src++; 437cfcdef40Smiod src = (u_int32_t *)&__bwx_switch1; 438cfcdef40Smiod end = (u_int32_t *)&__bwx_switch2; 439cfcdef40Smiod while (src != end) 440cfcdef40Smiod *dst++ = *src++; 441cfcdef40Smiod } 442cfcdef40Smiod } 443cfcdef40Smiod #endif 444cfcdef40Smiod 445aed035abSart /* 446aed035abSart * find out this system's page size 447aed035abSart */ 44873b9fe7cSart if ((uvmexp.pagesize = hwrpb->rpb_page_size) != 8192) 44973b9fe7cSart panic("page size %d != 8192?!", uvmexp.pagesize); 450aed035abSart 451aed035abSart uvm_setpagesize(); 452aed035abSart 453aed035abSart /* 454aed035abSart * Find the beginning and end of the kernel (and leave a 455aed035abSart * bit of space before the beginning for the bootstrap 456aed035abSart * stack). 457aed035abSart */ 458aed035abSart kernstart = trunc_page((vaddr_t)kernel_text) - 2 * PAGE_SIZE; 459aed035abSart kernend = (vaddr_t)round_page((vaddr_t)bootinfo.esym); 460aed035abSart 461aed035abSart kernstartpfn = atop(ALPHA_K0SEG_TO_PHYS(kernstart)); 462aed035abSart kernendpfn = atop(ALPHA_K0SEG_TO_PHYS(kernend)); 463df930be7Sderaadt 464df930be7Sderaadt /* 465df930be7Sderaadt * Find out how much memory is available, by looking at 466df930be7Sderaadt * the memory cluster descriptors. This also tries to do 467df930be7Sderaadt * its best to detect things things that have never been seen 468df930be7Sderaadt * before... 469df930be7Sderaadt */ 470df930be7Sderaadt mddtp = (struct mddt *)(((caddr_t)hwrpb) + hwrpb->rpb_memdat_off); 471df930be7Sderaadt 472aed035abSart /* MDDT SANITY CHECKING */ 473df930be7Sderaadt mddtweird = 0; 474aed035abSart if (mddtp->mddt_cluster_cnt < 2) { 475df930be7Sderaadt mddtweird = 1; 476aed035abSart printf("WARNING: weird number of mem clusters: %lu\n", 477aed035abSart mddtp->mddt_cluster_cnt); 478df930be7Sderaadt } 479df930be7Sderaadt 480aed035abSart #if 0 481aed035abSart printf("Memory cluster count: %d\n", mddtp->mddt_cluster_cnt); 482aed035abSart #endif 483df930be7Sderaadt 484aed035abSart for (i = 0; i < mddtp->mddt_cluster_cnt; i++) { 485aed035abSart memc = &mddtp->mddt_clusters[i]; 486aed035abSart #if 0 487aed035abSart printf("MEMC %d: pfn 0x%lx cnt 0x%lx usage 0x%lx\n", i, 488aed035abSart memc->mddt_pfn, memc->mddt_pg_cnt, memc->mddt_usage); 489aed035abSart #endif 490aed035abSart totalphysmem += memc->mddt_pg_cnt; 491aed035abSart if (mem_cluster_cnt < VM_PHYSSEG_MAX) { /* XXX */ 492aed035abSart mem_clusters[mem_cluster_cnt].start = 493aed035abSart ptoa(memc->mddt_pfn); 494aed035abSart mem_clusters[mem_cluster_cnt].size = 495aed035abSart ptoa(memc->mddt_pg_cnt); 496aed035abSart if (memc->mddt_usage & MDDT_mbz || 497aed035abSart memc->mddt_usage & MDDT_NONVOLATILE || /* XXX */ 498aed035abSart memc->mddt_usage & MDDT_PALCODE) 499aed035abSart mem_clusters[mem_cluster_cnt].size |= 500aed035abSart VM_PROT_READ; 501aed035abSart else 502aed035abSart mem_clusters[mem_cluster_cnt].size |= 503aed035abSart VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE; 504aed035abSart mem_cluster_cnt++; 505ee2d823aSmiod } /* XXX else print something! */ 506aed035abSart 507aed035abSart if (memc->mddt_usage & MDDT_mbz) { 508aed035abSart mddtweird = 1; 509aed035abSart printf("WARNING: mem cluster %d has weird " 510aed035abSart "usage 0x%lx\n", i, memc->mddt_usage); 511aed035abSart unknownmem += memc->mddt_pg_cnt; 512aed035abSart continue; 513aed035abSart } 514aed035abSart if (memc->mddt_usage & MDDT_NONVOLATILE) { 515aed035abSart /* XXX should handle these... */ 516aed035abSart printf("WARNING: skipping non-volatile mem " 517aed035abSart "cluster %d\n", i); 518aed035abSart unusedmem += memc->mddt_pg_cnt; 519aed035abSart continue; 520aed035abSart } 521aed035abSart if (memc->mddt_usage & MDDT_PALCODE) { 522aed035abSart resvmem += memc->mddt_pg_cnt; 523aed035abSart continue; 524aed035abSart } 525aed035abSart 526aed035abSart /* 527aed035abSart * We have a memory cluster available for system 528aed035abSart * software use. We must determine if this cluster 529aed035abSart * holds the kernel. 530aed035abSart */ 531aed035abSart #ifdef _PMAP_MAY_USE_PROM_CONSOLE 532aed035abSart /* 533aed035abSart * XXX If the kernel uses the PROM console, we only use the 534aed035abSart * XXX memory after the kernel in the first system segment, 535aed035abSart * XXX to avoid clobbering prom mapping, data, etc. 536aed035abSart */ 537aed035abSart if (!pmap_uses_prom_console() || physmem == 0) { 538aed035abSart #endif /* _PMAP_MAY_USE_PROM_CONSOLE */ 539aed035abSart physmem += memc->mddt_pg_cnt; 540aed035abSart pfn0 = memc->mddt_pfn; 541aed035abSart pfn1 = memc->mddt_pfn + memc->mddt_pg_cnt; 542aed035abSart if (pfn0 <= kernstartpfn && kernendpfn <= pfn1) { 543aed035abSart /* 544aed035abSart * Must compute the location of the kernel 545aed035abSart * within the segment. 546aed035abSart */ 547aed035abSart #if 0 548aed035abSart printf("Cluster %d contains kernel\n", i); 549aed035abSart #endif 550aed035abSart #ifdef _PMAP_MAY_USE_PROM_CONSOLE 551aed035abSart if (!pmap_uses_prom_console()) { 552aed035abSart #endif /* _PMAP_MAY_USE_PROM_CONSOLE */ 553aed035abSart if (pfn0 < kernstartpfn) { 554aed035abSart /* 555aed035abSart * There is a chunk before the kernel. 556aed035abSart */ 557aed035abSart #if 0 558aed035abSart printf("Loading chunk before kernel: " 559aed035abSart "0x%lx / 0x%lx\n", pfn0, kernstartpfn); 560aed035abSart #endif 561aed035abSart uvm_page_physload(pfn0, kernstartpfn, 562aed035abSart pfn0, kernstartpfn, VM_FREELIST_DEFAULT); 563aed035abSart } 564aed035abSart #ifdef _PMAP_MAY_USE_PROM_CONSOLE 565aed035abSart } 566aed035abSart #endif /* _PMAP_MAY_USE_PROM_CONSOLE */ 567aed035abSart if (kernendpfn < pfn1) { 568aed035abSart /* 569aed035abSart * There is a chunk after the kernel. 570aed035abSart */ 571aed035abSart #if 0 572aed035abSart printf("Loading chunk after kernel: " 573aed035abSart "0x%lx / 0x%lx\n", kernendpfn, pfn1); 574aed035abSart #endif 575aed035abSart uvm_page_physload(kernendpfn, pfn1, 576aed035abSart kernendpfn, pfn1, VM_FREELIST_DEFAULT); 577aed035abSart } 578aed035abSart } else { 579aed035abSart /* 580aed035abSart * Just load this cluster as one chunk. 581aed035abSart */ 582aed035abSart #if 0 583aed035abSart printf("Loading cluster %d: 0x%lx / 0x%lx\n", i, 584aed035abSart pfn0, pfn1); 585aed035abSart #endif 586aed035abSart uvm_page_physload(pfn0, pfn1, pfn0, pfn1, 587aed035abSart VM_FREELIST_DEFAULT); 588aed035abSart } 589aed035abSart #ifdef _PMAP_MAY_USE_PROM_CONSOLE 590aed035abSart } 591aed035abSart #endif /* _PMAP_MAY_USE_PROM_CONSOLE */ 592aed035abSart } 593aed035abSart 594a37778bcSderaadt #ifdef DEBUG 595aed035abSart /* 596aed035abSart * Dump out the MDDT if it looks odd... 597aed035abSart */ 598df930be7Sderaadt if (mddtweird) { 599df930be7Sderaadt printf("\n"); 600df930be7Sderaadt printf("complete memory cluster information:\n"); 601df930be7Sderaadt for (i = 0; i < mddtp->mddt_cluster_cnt; i++) { 602df930be7Sderaadt printf("mddt %d:\n", i); 603df930be7Sderaadt printf("\tpfn %lx\n", 604df930be7Sderaadt mddtp->mddt_clusters[i].mddt_pfn); 605df930be7Sderaadt printf("\tcnt %lx\n", 606df930be7Sderaadt mddtp->mddt_clusters[i].mddt_pg_cnt); 607df930be7Sderaadt printf("\ttest %lx\n", 608df930be7Sderaadt mddtp->mddt_clusters[i].mddt_pg_test); 609df930be7Sderaadt printf("\tbva %lx\n", 610df930be7Sderaadt mddtp->mddt_clusters[i].mddt_v_bitaddr); 611df930be7Sderaadt printf("\tbpa %lx\n", 612df930be7Sderaadt mddtp->mddt_clusters[i].mddt_p_bitaddr); 613df930be7Sderaadt printf("\tbcksum %lx\n", 614df930be7Sderaadt mddtp->mddt_clusters[i].mddt_bit_cksum); 615df930be7Sderaadt printf("\tusage %lx\n", 616df930be7Sderaadt mddtp->mddt_clusters[i].mddt_usage); 617df930be7Sderaadt } 618df930be7Sderaadt printf("\n"); 619df930be7Sderaadt } 620a37778bcSderaadt #endif 621df930be7Sderaadt 622df930be7Sderaadt if (totalphysmem == 0) 623df930be7Sderaadt panic("can't happen: system seems to have no memory!"); 624df930be7Sderaadt #if 0 625f46637d1Sderaadt printf("totalphysmem = %u\n", totalphysmem); 626f46637d1Sderaadt printf("physmem = %u\n", physmem); 627df930be7Sderaadt printf("resvmem = %d\n", resvmem); 628df930be7Sderaadt printf("unusedmem = %d\n", unusedmem); 629df930be7Sderaadt printf("unknownmem = %d\n", unknownmem); 630df930be7Sderaadt #endif 631df930be7Sderaadt 632df930be7Sderaadt /* 633aed035abSart * Initialize error message buffer (at end of core). 634df930be7Sderaadt */ 635aed035abSart { 636aed035abSart vsize_t sz = (vsize_t)round_page(MSGBUFSIZE); 637aed035abSart vsize_t reqsz = sz; 638df930be7Sderaadt 639aed035abSart vps = &vm_physmem[vm_nphysseg - 1]; 640e1da84e1Salex 641aed035abSart /* shrink so that it'll fit in the last segment */ 642aed035abSart if ((vps->avail_end - vps->avail_start) < atop(sz)) 643aed035abSart sz = ptoa(vps->avail_end - vps->avail_start); 644aed035abSart 645aed035abSart vps->end -= atop(sz); 646aed035abSart vps->avail_end -= atop(sz); 647aed035abSart initmsgbuf((caddr_t) ALPHA_PHYS_TO_K0SEG(ptoa(vps->end)), sz); 648aed035abSart 649aed035abSart /* Remove the last segment if it now has no pages. */ 650aed035abSart if (vps->start == vps->end) 651aed035abSart vm_nphysseg--; 652aed035abSart 653aed035abSart /* warn if the message buffer had to be shrunk */ 654aed035abSart if (sz != reqsz) 655aed035abSart printf("WARNING: %ld bytes not available for msgbuf " 656aed035abSart "in last cluster (%ld used)\n", reqsz, sz); 657aed035abSart 658aed035abSart } 659aed035abSart 660df930be7Sderaadt /* 661df930be7Sderaadt * Init mapping for u page(s) for proc 0 662df930be7Sderaadt */ 663aed035abSart proc0.p_addr = proc0paddr = 664aed035abSart (struct user *)pmap_steal_memory(UPAGES * PAGE_SIZE, NULL, NULL); 665df930be7Sderaadt 666df930be7Sderaadt /* 667aed035abSart * Allocate space for system data structures. These data structures 668aed035abSart * are allocated here instead of cpu_startup() because physical 669aed035abSart * memory is directly addressable. We don't have to map these into 670aed035abSart * virtual address space. 671df930be7Sderaadt */ 672aed035abSart size = (vsize_t)allocsys(NULL); 673aed035abSart v = (caddr_t)pmap_steal_memory(size, NULL, NULL); 674aed035abSart if ((allocsys(v) - v) != size) 675aed035abSart panic("alpha_init: table size inconsistency"); 676df930be7Sderaadt 677df930be7Sderaadt /* 678df930be7Sderaadt * Clear allocated memory. 679df930be7Sderaadt */ 680aed035abSart bzero(v, size); 681df930be7Sderaadt 682df930be7Sderaadt /* 683df930be7Sderaadt * Initialize the virtual memory system, and set the 684df930be7Sderaadt * page table base register in proc 0's PCB. 685df930be7Sderaadt */ 686aed035abSart pmap_bootstrap(ALPHA_PHYS_TO_K0SEG(ptb << PGSHIFT), 687aed035abSart hwrpb->rpb_max_asn, hwrpb->rpb_pcs_cnt); 688df930be7Sderaadt 689df930be7Sderaadt /* 690df930be7Sderaadt * Initialize the rest of proc 0's PCB, and cache its physical 691df930be7Sderaadt * address. 692df930be7Sderaadt */ 693df930be7Sderaadt proc0.p_md.md_pcbpaddr = 694aed035abSart (struct pcb *)ALPHA_K0SEG_TO_PHYS((vaddr_t)&proc0paddr->u_pcb); 695df930be7Sderaadt 696df930be7Sderaadt /* 697df930be7Sderaadt * Set the kernel sp, reserving space for an (empty) trapframe, 698df930be7Sderaadt * and make proc0's trapframe pointer point to it for sanity. 699df930be7Sderaadt */ 70050ce9ee0Sniklas proc0paddr->u_pcb.pcb_hw.apcb_ksp = 701df930be7Sderaadt (u_int64_t)proc0paddr + USPACE - sizeof(struct trapframe); 70274652a67Sniklas proc0.p_md.md_tf = 70374652a67Sniklas (struct trapframe *)proc0paddr->u_pcb.pcb_hw.apcb_ksp; 70450ce9ee0Sniklas 705aed035abSart /* 706aed035abSart * Initialize the primary CPU's idle PCB to proc0's. In a 707aed035abSart * MULTIPROCESSOR configuration, each CPU will later get 708aed035abSart * its own idle PCB when autoconfiguration runs. 709aed035abSart */ 710aed035abSart ci->ci_idle_pcb = &proc0paddr->u_pcb; 711aed035abSart ci->ci_idle_pcb_paddr = (u_long)proc0.p_md.md_pcbpaddr; 712df930be7Sderaadt 713df930be7Sderaadt /* 714df930be7Sderaadt * Look at arguments passed to us and compute boothowto. 715df930be7Sderaadt */ 716417eba8cSderaadt 717df930be7Sderaadt #ifdef KADB 718df930be7Sderaadt boothowto |= RB_KDB; 719df930be7Sderaadt #endif 720aed035abSart for (p = bootinfo.boot_flags; p && *p != '\0'; p++) { 721417eba8cSderaadt /* 722417eba8cSderaadt * Note that we'd really like to differentiate case here, 723417eba8cSderaadt * but the Alpha AXP Architecture Reference Manual 724417eba8cSderaadt * says that we shouldn't. 725417eba8cSderaadt */ 726df930be7Sderaadt switch (*p) { 727371c77f5Smartin case 'a': /* Ignore */ 728417eba8cSderaadt case 'A': 729df930be7Sderaadt break; 730df930be7Sderaadt 73112f8bbedSniklas case 'b': /* Enter DDB as soon as the console is initialised */ 73212f8bbedSniklas case 'B': 73312f8bbedSniklas boothowto |= RB_KDB; 73412f8bbedSniklas break; 73512f8bbedSniklas 73650ce9ee0Sniklas case 'c': /* enter user kernel configuration */ 73750ce9ee0Sniklas case 'C': 73850ce9ee0Sniklas boothowto |= RB_CONFIG; 73950ce9ee0Sniklas break; 74050ce9ee0Sniklas 74150ce9ee0Sniklas #ifdef DEBUG 74250ce9ee0Sniklas case 'd': /* crash dump immediately after autoconfig */ 74350ce9ee0Sniklas case 'D': 74450ce9ee0Sniklas boothowto |= RB_DUMP; 74550ce9ee0Sniklas break; 74650ce9ee0Sniklas #endif 74750ce9ee0Sniklas 74850ce9ee0Sniklas case 'h': /* always halt, never reboot */ 74950ce9ee0Sniklas case 'H': 75050ce9ee0Sniklas boothowto |= RB_HALT; 751df930be7Sderaadt break; 752df930be7Sderaadt 753417eba8cSderaadt #if 0 754417eba8cSderaadt case 'm': /* mini root present in memory */ 755417eba8cSderaadt case 'M': 756417eba8cSderaadt boothowto |= RB_MINIROOT; 757417eba8cSderaadt break; 758417eba8cSderaadt #endif 75950ce9ee0Sniklas 76050ce9ee0Sniklas case 'n': /* askname */ 76150ce9ee0Sniklas case 'N': 76250ce9ee0Sniklas boothowto |= RB_ASKNAME; 76350ce9ee0Sniklas break; 764aed035abSart 765371c77f5Smartin case 's': /* single-user */ 766aed035abSart case 'S': 767aed035abSart boothowto |= RB_SINGLE; 768aed035abSart break; 769aed035abSart 770aed035abSart case '-': 771aed035abSart /* 772aed035abSart * Just ignore this. It's not required, but it's 773aed035abSart * common for it to be passed regardless. 774aed035abSart */ 775aed035abSart break; 776aed035abSart 777aed035abSart default: 778aed035abSart printf("Unrecognized boot flag '%c'.\n", *p); 779aed035abSart break; 780df930be7Sderaadt } 781df930be7Sderaadt } 782df930be7Sderaadt 783aed035abSart 784df930be7Sderaadt /* 785df930be7Sderaadt * Figure out the number of cpus in the box, from RPB fields. 786df930be7Sderaadt * Really. We mean it. 787df930be7Sderaadt */ 7882586fa93Smiod for (alpha_cpus = 0, i = 0; i < hwrpb->rpb_pcs_cnt; i++) { 789df930be7Sderaadt struct pcs *pcsp; 790df930be7Sderaadt 791aed035abSart pcsp = LOCATE_PCS(hwrpb, i); 792df930be7Sderaadt if ((pcsp->pcs_flags & PCS_PP) != 0) 7932586fa93Smiod alpha_cpus++; 794df930be7Sderaadt } 795aed035abSart 796aed035abSart /* 797aed035abSart * Initialize debuggers, and break into them if appropriate. 798aed035abSart */ 799aed035abSart #ifdef DDB 800aed035abSart ddb_init(); 801aed035abSart 802aed035abSart if (boothowto & RB_KDB) 803aed035abSart Debugger(); 804aed035abSart #endif 805aed035abSart #ifdef KGDB 806aed035abSart if (boothowto & RB_KDB) 807aed035abSart kgdb_connect(0); 808aed035abSart #endif 809aed035abSart /* 810aed035abSart * Figure out our clock frequency, from RPB fields. 811aed035abSart */ 812aed035abSart hz = hwrpb->rpb_intr_freq >> 12; 813aed035abSart if (!(60 <= hz && hz <= 10240)) { 814aed035abSart hz = 1024; 815aed035abSart #ifdef DIAGNOSTIC 816aed035abSart printf("WARNING: unbelievable rpb_intr_freq: %ld (%d hz)\n", 817aed035abSart hwrpb->rpb_intr_freq, hz); 818aed035abSart #endif 819aed035abSart } 820aed035abSart } 821aed035abSart 822aed035abSart caddr_t 823aed035abSart allocsys(v) 824aed035abSart caddr_t v; 825aed035abSart { 826aed035abSart /* 827aed035abSart * Allocate space for system data structures. 828aed035abSart * The first available kernel virtual address is in "v". 829aed035abSart * As pages of kernel virtual memory are allocated, "v" is incremented. 830aed035abSart * 831aed035abSart * These data structures are allocated here instead of cpu_startup() 832aed035abSart * because physical memory is directly addressable. We don't have 833aed035abSart * to map these into virtual address space. 834aed035abSart */ 835aed035abSart #define valloc(name, type, num) \ 836aed035abSart (name) = (type *)v; v = (caddr_t)ALIGN((name)+(num)) 837aed035abSart 838aed035abSart #ifdef SYSVMSG 839aed035abSart valloc(msgpool, char, msginfo.msgmax); 840aed035abSart valloc(msgmaps, struct msgmap, msginfo.msgseg); 841aed035abSart valloc(msghdrs, struct msg, msginfo.msgtql); 842aed035abSart valloc(msqids, struct msqid_ds, msginfo.msgmni); 843aed035abSart #endif 844aed035abSart 845aed035abSart /* 846aed035abSart * Determine how many buffers to allocate. 847aed035abSart * We allocate 10% of memory for buffer space. Insure a 848aed035abSart * minimum of 16 buffers. 849aed035abSart */ 850aed035abSart if (bufpages == 0) 85160535ec9Smaja bufpages = (physmem / (100/bufcachepercent)); 852aed035abSart if (nbuf == 0) { 853aed035abSart nbuf = bufpages; 854aed035abSart if (nbuf < 16) 855aed035abSart nbuf = 16; 856aed035abSart } 857aed035abSart valloc(buf, struct buf, nbuf); 858aed035abSart 859aed035abSart #undef valloc 860aed035abSart 861aed035abSart return v; 862df930be7Sderaadt } 863df930be7Sderaadt 864417eba8cSderaadt void 865df930be7Sderaadt consinit() 866df930be7Sderaadt { 867aed035abSart 868aed035abSart /* 869aed035abSart * Everything related to console initialization is done 870aed035abSart * in alpha_init(). 871aed035abSart */ 872aed035abSart #if defined(DIAGNOSTIC) && defined(_PMAP_MAY_USE_PROM_CONSOLE) 873aed035abSart printf("consinit: %susing prom console\n", 874aed035abSart pmap_uses_prom_console() ? "" : "not "); 87512f8bbedSniklas #endif 876df930be7Sderaadt } 877df930be7Sderaadt 878417eba8cSderaadt void 879df930be7Sderaadt cpu_startup() 880df930be7Sderaadt { 881df930be7Sderaadt register unsigned i; 882df930be7Sderaadt int base, residual; 883aed035abSart vaddr_t minaddr, maxaddr; 884aed035abSart vsize_t size; 88550ce9ee0Sniklas #if defined(DEBUG) 886df930be7Sderaadt extern int pmapdebug; 887df930be7Sderaadt int opmapdebug = pmapdebug; 888df930be7Sderaadt 889df930be7Sderaadt pmapdebug = 0; 890df930be7Sderaadt #endif 891df930be7Sderaadt 892df930be7Sderaadt /* 893df930be7Sderaadt * Good {morning,afternoon,evening,night}. 894df930be7Sderaadt */ 895df930be7Sderaadt printf(version); 896df930be7Sderaadt identifycpu(); 897f46637d1Sderaadt printf("total memory = %ld (%ldK)\n", ptoa((u_long)totalphysmem), 898f46637d1Sderaadt ptoa((u_long)totalphysmem) / 1024); 899f46637d1Sderaadt printf("(%ld reserved for PROM, ", ptoa((u_long)resvmem)); 900f46637d1Sderaadt printf("%ld used by OpenBSD)\n", ptoa((u_long)physmem)); 901aed035abSart if (unusedmem) { 9023f4ce3b7Smiod printf("WARNING: unused memory = %ld (%ldK)\n", 903f46637d1Sderaadt ptoa((u_long)unusedmem), ptoa((u_long)unusedmem) / 1024); 904aed035abSart } 905aed035abSart if (unknownmem) { 9063f4ce3b7Smiod printf("WARNING: %ld (%ldK) of memory with unknown purpose\n", 907f46637d1Sderaadt ptoa((u_long)unknownmem), ptoa((u_long)unknownmem) / 1024); 908aed035abSart } 909df930be7Sderaadt 910df930be7Sderaadt /* 911df930be7Sderaadt * Allocate virtual address space for file I/O buffers. 912df930be7Sderaadt * Note they are different than the array of headers, 'buf', 913df930be7Sderaadt * and usually occupy more virtual memory than physical. 914df930be7Sderaadt */ 915df930be7Sderaadt size = MAXBSIZE * nbuf; 916aed035abSart if (uvm_map(kernel_map, (vaddr_t *) &buffers, round_page(size), 917198a4b3fSart NULL, UVM_UNKNOWN_OFFSET, 0, 918aed035abSart UVM_MAPFLAG(UVM_PROT_NONE, UVM_PROT_NONE, UVM_INH_NONE, 919738a5b4dSart UVM_ADV_NORMAL, 0))) 920aed035abSart panic("startup: cannot allocate VM for buffers"); 921df930be7Sderaadt base = bufpages / nbuf; 922df930be7Sderaadt residual = bufpages % nbuf; 923df930be7Sderaadt for (i = 0; i < nbuf; i++) { 924aed035abSart vsize_t curbufsize; 925aed035abSart vaddr_t curbuf; 926aed035abSart struct vm_page *pg; 927df930be7Sderaadt 928df930be7Sderaadt /* 929aed035abSart * Each buffer has MAXBSIZE bytes of VM space allocated. Of 930aed035abSart * that MAXBSIZE space, we allocate and map (base+1) pages 931aed035abSart * for the first "residual" buffers, and then we allocate 932aed035abSart * "base" pages for the rest. 933df930be7Sderaadt */ 934aed035abSart curbuf = (vaddr_t) buffers + (i * MAXBSIZE); 935194dd68bSbrad curbufsize = PAGE_SIZE * ((i < residual) ? (base+1) : base); 936aed035abSart 937aed035abSart while (curbufsize) { 938aed035abSart pg = uvm_pagealloc(NULL, 0, NULL, 0); 939aed035abSart if (pg == NULL) 940aed035abSart panic("cpu_startup: not enough memory for " 941aed035abSart "buffer cache"); 942aed035abSart pmap_kenter_pa(curbuf, VM_PAGE_TO_PHYS(pg), 943aed035abSart VM_PROT_READ|VM_PROT_WRITE); 944aed035abSart curbuf += PAGE_SIZE; 945aed035abSart curbufsize -= PAGE_SIZE; 946aed035abSart } 9470e5798cfSart pmap_update(pmap_kernel()); 948df930be7Sderaadt } 949df930be7Sderaadt /* 950df930be7Sderaadt * Allocate a submap for exec arguments. This map effectively 951df930be7Sderaadt * limits the number of processes exec'ing at any time. 952df930be7Sderaadt */ 9537c10a71dSdrahn minaddr = vm_map_min(kernel_map); 954aed035abSart exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr, 955aed035abSart 16 * NCARGS, VM_MAP_PAGEABLE, FALSE, NULL); 956df930be7Sderaadt 957df930be7Sderaadt /* 958df930be7Sderaadt * Allocate a submap for physio 959df930be7Sderaadt */ 960aed035abSart phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr, 961aed035abSart VM_PHYS_SIZE, 0, FALSE, NULL); 962df930be7Sderaadt 96350ce9ee0Sniklas #if defined(DEBUG) 964df930be7Sderaadt pmapdebug = opmapdebug; 965df930be7Sderaadt #endif 9663f4ce3b7Smiod printf("avail memory = %ld (%ldK)\n", (long)ptoa(uvmexp.free), 9673f4ce3b7Smiod (long)ptoa(uvmexp.free) / 1024); 968aed035abSart #if 0 969aed035abSart { 970aed035abSart extern u_long pmap_pages_stolen; 971aed035abSart 972aed035abSart printf("stolen memory for VM structures = %d\n", pmap_pages_stolen * PAGE_SIZE); 973aed035abSart } 974aed035abSart #endif 9753f4ce3b7Smiod printf("using %ld buffers containing %ld bytes (%ldK) of memory\n", 976194dd68bSbrad (long)nbuf, (long)bufpages * PAGE_SIZE, (long)bufpages * (PAGE_SIZE / 1024)); 977df930be7Sderaadt 978df930be7Sderaadt /* 979df930be7Sderaadt * Set up buffers, so they can be used to read disk labels. 980df930be7Sderaadt */ 981df930be7Sderaadt bufinit(); 982df930be7Sderaadt 983df930be7Sderaadt /* 984df930be7Sderaadt * Configure the system. 985df930be7Sderaadt */ 98641033391Sderaadt if (boothowto & RB_CONFIG) { 98741033391Sderaadt #ifdef BOOT_CONFIG 98841033391Sderaadt user_config(); 98941033391Sderaadt #else 99041033391Sderaadt printf("kernel does not support -c; continuing..\n"); 99141033391Sderaadt #endif 99241033391Sderaadt } 99350ce9ee0Sniklas 99450ce9ee0Sniklas /* 995aed035abSart * Set up the HWPCB so that it's safe to configure secondary 996aed035abSart * CPUs. 99750ce9ee0Sniklas */ 998aed035abSart hwrpb_primary_init(); 999aed035abSart } 1000aed035abSart 1001aed035abSart /* 1002aed035abSart * Retrieve the platform name from the DSR. 1003aed035abSart */ 1004aed035abSart const char * 1005aed035abSart alpha_dsr_sysname() 1006aed035abSart { 1007aed035abSart struct dsrdb *dsr; 1008aed035abSart const char *sysname; 1009aed035abSart 1010aed035abSart /* 1011aed035abSart * DSR does not exist on early HWRPB versions. 1012aed035abSart */ 1013aed035abSart if (hwrpb->rpb_version < HWRPB_DSRDB_MINVERS) 1014aed035abSart return (NULL); 1015aed035abSart 1016aed035abSart dsr = (struct dsrdb *)(((caddr_t)hwrpb) + hwrpb->rpb_dsrdb_off); 1017aed035abSart sysname = (const char *)((caddr_t)dsr + (dsr->dsr_sysname_off + 1018aed035abSart sizeof(u_int64_t))); 1019aed035abSart return (sysname); 1020aed035abSart } 1021aed035abSart 1022aed035abSart /* 1023aed035abSart * Lookup the system specified system variation in the provided table, 1024aed035abSart * returning the model string on match. 1025aed035abSart */ 1026aed035abSart const char * 1027aed035abSart alpha_variation_name(variation, avtp) 1028aed035abSart u_int64_t variation; 1029aed035abSart const struct alpha_variation_table *avtp; 1030aed035abSart { 1031aed035abSart int i; 1032aed035abSart 1033aed035abSart for (i = 0; avtp[i].avt_model != NULL; i++) 1034aed035abSart if (avtp[i].avt_variation == variation) 1035aed035abSart return (avtp[i].avt_model); 1036aed035abSart return (NULL); 1037aed035abSart } 1038aed035abSart 1039aed035abSart /* 1040aed035abSart * Generate a default platform name based for unknown system variations. 1041aed035abSart */ 1042aed035abSart const char * 1043aed035abSart alpha_unknown_sysname() 1044aed035abSart { 1045aed035abSart static char s[128]; /* safe size */ 1046aed035abSart 1047d5eb2d9aSderaadt snprintf(s, sizeof s, "%s family, unknown model variation 0x%lx", 1048aed035abSart platform.family, hwrpb->rpb_variation & SV_ST_MASK); 1049aed035abSart return ((const char *)s); 1050df930be7Sderaadt } 1051df930be7Sderaadt 105250ce9ee0Sniklas void 1053df930be7Sderaadt identifycpu() 1054df930be7Sderaadt { 1055aed035abSart char *s; 1056b3cee53eSmartin int slen; 1057df930be7Sderaadt 1058df930be7Sderaadt /* 1059df930be7Sderaadt * print out CPU identification information. 1060df930be7Sderaadt */ 1061aed035abSart printf("%s", cpu_model); 1062aed035abSart for(s = cpu_model; *s; ++s) 1063aed035abSart if(strncasecmp(s, "MHz", 3) == 0) 1064aed035abSart goto skipMHz; 1065aed035abSart printf(", %ldMHz", hwrpb->rpb_cc_freq / 1000000); 1066aed035abSart skipMHz: 1067b3cee53eSmartin /* fill in hw_serial if a serial number is known */ 1068b3cee53eSmartin slen = strlen(hwrpb->rpb_ssn) + 1; 1069b3cee53eSmartin if (slen > 1) { 1070b3cee53eSmartin hw_serial = malloc(slen, M_SYSCTL, M_NOWAIT); 1071b3cee53eSmartin if (hw_serial) 1072b3cee53eSmartin strlcpy(hw_serial, (char *)hwrpb->rpb_ssn, slen); 1073b3cee53eSmartin } 1074b3cee53eSmartin 1075aed035abSart printf("\n"); 107650ce9ee0Sniklas printf("%ld byte page size, %d processor%s.\n", 10772586fa93Smiod hwrpb->rpb_page_size, alpha_cpus, alpha_cpus == 1 ? "" : "s"); 1078df930be7Sderaadt #if 0 1079b3cee53eSmartin /* this is not particularly useful! */ 1080df930be7Sderaadt printf("variation: 0x%lx, revision 0x%lx\n", 1081df930be7Sderaadt hwrpb->rpb_variation, *(long *)hwrpb->rpb_revision); 1082df930be7Sderaadt #endif 1083df930be7Sderaadt } 1084df930be7Sderaadt 1085df930be7Sderaadt int waittime = -1; 1086df930be7Sderaadt struct pcb dumppcb; 1087df930be7Sderaadt 1088417eba8cSderaadt void 1089aed035abSart boot(howto) 1090df930be7Sderaadt int howto; 1091df930be7Sderaadt { 1092aed035abSart #if defined(MULTIPROCESSOR) 1093aed035abSart #if 0 /* XXX See below. */ 1094aed035abSart u_long cpu_id; 1095aed035abSart #endif 1096aed035abSart #endif 1097aed035abSart 1098aed035abSart #if defined(MULTIPROCESSOR) 1099aed035abSart /* We must be running on the primary CPU. */ 1100aed035abSart if (alpha_pal_whami() != hwrpb->rpb_primary_cpu_id) 1101aed035abSart panic("cpu_reboot: not on primary CPU!"); 1102aed035abSart #endif 1103aed035abSart 1104df930be7Sderaadt /* If system is cold, just halt. */ 1105df930be7Sderaadt if (cold) { 1106c9ad5066Stom /* (Unless the user explicitly asked for reboot.) */ 1107c9ad5066Stom if ((howto & RB_USERREQ) == 0) 1108df930be7Sderaadt howto |= RB_HALT; 1109df930be7Sderaadt goto haltsys; 1110df930be7Sderaadt } 1111df930be7Sderaadt 111250ce9ee0Sniklas /* If "always halt" was specified as a boot flag, obey. */ 111350ce9ee0Sniklas if ((boothowto & RB_HALT) != 0) 111450ce9ee0Sniklas howto |= RB_HALT; 111550ce9ee0Sniklas 1116df930be7Sderaadt boothowto = howto; 1117df930be7Sderaadt if ((howto & RB_NOSYNC) == 0 && waittime < 0) { 1118df930be7Sderaadt waittime = 0; 1119df930be7Sderaadt vfs_shutdown(); 1120df930be7Sderaadt /* 1121df930be7Sderaadt * If we've been adjusting the clock, the todr 11222417125dSmiod * will be out of synch; adjust it now unless 11232417125dSmiod * the system has been sitting in ddb. 1124df930be7Sderaadt */ 11252417125dSmiod if ((howto & RB_TIMEBAD) == 0) { 1126df930be7Sderaadt resettodr(); 11272417125dSmiod } else { 11282417125dSmiod printf("WARNING: not updating battery clock\n"); 11292417125dSmiod } 1130df930be7Sderaadt } 1131df930be7Sderaadt 1132df930be7Sderaadt /* Disable interrupts. */ 1133df930be7Sderaadt splhigh(); 1134df930be7Sderaadt 1135df930be7Sderaadt /* If rebooting and a dump is requested do it. */ 113650ce9ee0Sniklas if (howto & RB_DUMP) 1137df930be7Sderaadt dumpsys(); 1138df930be7Sderaadt 113934fbf6deSderaadt haltsys: 114034fbf6deSderaadt 1141df930be7Sderaadt /* run any shutdown hooks */ 1142df930be7Sderaadt doshutdownhooks(); 1143df930be7Sderaadt 1144aed035abSart #if defined(MULTIPROCESSOR) 1145aed035abSart #if 0 /* XXX doesn't work when called from here?! */ 1146aed035abSart /* Kill off any secondary CPUs. */ 1147aed035abSart for (cpu_id = 0; cpu_id < hwrpb->rpb_pcs_cnt; cpu_id++) { 1148aed035abSart if (cpu_id == hwrpb->rpb_primary_cpu_id || 1149aed035abSart cpu_info[cpu_id].ci_softc == NULL) 1150aed035abSart continue; 1151aed035abSart cpu_halt_secondary(cpu_id); 1152aed035abSart } 1153aed035abSart #endif 1154aed035abSart #endif 1155aed035abSart 1156df930be7Sderaadt #ifdef BOOTKEY 1157df930be7Sderaadt printf("hit any key to %s...\n", howto & RB_HALT ? "halt" : "reboot"); 1158aed035abSart cnpollc(1); /* for proper keyboard command handling */ 1159df930be7Sderaadt cngetc(); 1160aed035abSart cnpollc(0); 1161df930be7Sderaadt printf("\n"); 1162df930be7Sderaadt #endif 1163df930be7Sderaadt 1164aed035abSart /* Finally, powerdown/halt/reboot the system. */ 1165aed035abSart if ((howto & RB_POWERDOWN) == RB_POWERDOWN && 1166aed035abSart platform.powerdown != NULL) { 1167aed035abSart (*platform.powerdown)(); 1168aed035abSart printf("WARNING: powerdown failed!\n"); 1169aed035abSart } 1170df930be7Sderaadt printf("%s\n\n", howto & RB_HALT ? "halted." : "rebooting..."); 1171df930be7Sderaadt prom_halt(howto & RB_HALT); 1172df930be7Sderaadt /*NOTREACHED*/ 1173df930be7Sderaadt } 1174df930be7Sderaadt 1175df930be7Sderaadt /* 1176df930be7Sderaadt * These variables are needed by /sbin/savecore 1177df930be7Sderaadt */ 1178df930be7Sderaadt u_long dumpmag = 0x8fca0101; /* magic number */ 1179df930be7Sderaadt int dumpsize = 0; /* pages */ 1180df930be7Sderaadt long dumplo = 0; /* blocks */ 1181df930be7Sderaadt 1182df930be7Sderaadt /* 118350ce9ee0Sniklas * cpu_dumpsize: calculate size of machine-dependent kernel core dump headers. 118450ce9ee0Sniklas */ 118550ce9ee0Sniklas int 118650ce9ee0Sniklas cpu_dumpsize() 118750ce9ee0Sniklas { 118850ce9ee0Sniklas int size; 118950ce9ee0Sniklas 1190aed035abSart size = ALIGN(sizeof(kcore_seg_t)) + ALIGN(sizeof(cpu_kcore_hdr_t)) + 1191aed035abSart ALIGN(mem_cluster_cnt * sizeof(phys_ram_seg_t)); 119250ce9ee0Sniklas if (roundup(size, dbtob(1)) != dbtob(1)) 119350ce9ee0Sniklas return -1; 119450ce9ee0Sniklas 119550ce9ee0Sniklas return (1); 119650ce9ee0Sniklas } 119750ce9ee0Sniklas 119850ce9ee0Sniklas /* 1199aed035abSart * cpu_dump_mempagecnt: calculate size of RAM (in pages) to be dumped. 1200aed035abSart */ 1201aed035abSart u_long 1202aed035abSart cpu_dump_mempagecnt() 1203aed035abSart { 1204aed035abSart u_long i, n; 1205aed035abSart 1206aed035abSart n = 0; 1207aed035abSart for (i = 0; i < mem_cluster_cnt; i++) 1208aed035abSart n += atop(mem_clusters[i].size); 1209aed035abSart return (n); 1210aed035abSart } 1211aed035abSart 1212aed035abSart /* 121350ce9ee0Sniklas * cpu_dump: dump machine-dependent kernel core dump headers. 121450ce9ee0Sniklas */ 121550ce9ee0Sniklas int 121650ce9ee0Sniklas cpu_dump() 121750ce9ee0Sniklas { 1218c4071fd1Smillert int (*dump)(dev_t, daddr_t, caddr_t, size_t); 1219aed035abSart char buf[dbtob(1)]; 122050ce9ee0Sniklas kcore_seg_t *segp; 122150ce9ee0Sniklas cpu_kcore_hdr_t *cpuhdrp; 1222aed035abSart phys_ram_seg_t *memsegp; 1223aed035abSart int i; 122450ce9ee0Sniklas 122550ce9ee0Sniklas dump = bdevsw[major(dumpdev)].d_dump; 122650ce9ee0Sniklas 1227aed035abSart bzero(buf, sizeof buf); 122850ce9ee0Sniklas segp = (kcore_seg_t *)buf; 1229aed035abSart cpuhdrp = (cpu_kcore_hdr_t *)&buf[ALIGN(sizeof(*segp))]; 1230aed035abSart memsegp = (phys_ram_seg_t *)&buf[ALIGN(sizeof(*segp)) + 1231aed035abSart ALIGN(sizeof(*cpuhdrp))]; 123250ce9ee0Sniklas 123350ce9ee0Sniklas /* 123450ce9ee0Sniklas * Generate a segment header. 123550ce9ee0Sniklas */ 123650ce9ee0Sniklas CORE_SETMAGIC(*segp, KCORE_MAGIC, MID_MACHINE, CORE_CPU); 123750ce9ee0Sniklas segp->c_size = dbtob(1) - ALIGN(sizeof(*segp)); 123850ce9ee0Sniklas 123950ce9ee0Sniklas /* 1240aed035abSart * Add the machine-dependent header info. 124150ce9ee0Sniklas */ 1242aed035abSart cpuhdrp->lev1map_pa = ALPHA_K0SEG_TO_PHYS((vaddr_t)kernel_lev1map); 124350ce9ee0Sniklas cpuhdrp->page_size = PAGE_SIZE; 1244aed035abSart cpuhdrp->nmemsegs = mem_cluster_cnt; 1245aed035abSart 1246aed035abSart /* 1247aed035abSart * Fill in the memory segment descriptors. 1248aed035abSart */ 1249aed035abSart for (i = 0; i < mem_cluster_cnt; i++) { 1250aed035abSart memsegp[i].start = mem_clusters[i].start; 1251aed035abSart memsegp[i].size = mem_clusters[i].size & ~PAGE_MASK; 1252aed035abSart } 125350ce9ee0Sniklas 125450ce9ee0Sniklas return (dump(dumpdev, dumplo, (caddr_t)buf, dbtob(1))); 125550ce9ee0Sniklas } 125650ce9ee0Sniklas 125750ce9ee0Sniklas /* 1258aed035abSart * This is called by main to set dumplo and dumpsize. 1259194dd68bSbrad * Dumps always skip the first PAGE_SIZE of disk space 1260df930be7Sderaadt * in case there might be a disk label stored there. 1261df930be7Sderaadt * If there is extra space, put dump at the end to 1262df930be7Sderaadt * reduce the chance that swapping trashes it. 1263df930be7Sderaadt */ 1264df930be7Sderaadt void 1265df930be7Sderaadt dumpconf() 1266df930be7Sderaadt { 126750ce9ee0Sniklas int nblks, dumpblks; /* size of dump area */ 1268df930be7Sderaadt int maj; 1269df930be7Sderaadt 1270df930be7Sderaadt if (dumpdev == NODEV) 127150ce9ee0Sniklas goto bad; 1272df930be7Sderaadt maj = major(dumpdev); 1273df930be7Sderaadt if (maj < 0 || maj >= nblkdev) 1274df930be7Sderaadt panic("dumpconf: bad dumpdev=0x%x", dumpdev); 1275df930be7Sderaadt if (bdevsw[maj].d_psize == NULL) 127650ce9ee0Sniklas goto bad; 1277df930be7Sderaadt nblks = (*bdevsw[maj].d_psize)(dumpdev); 1278df930be7Sderaadt if (nblks <= ctod(1)) 127950ce9ee0Sniklas goto bad; 128050ce9ee0Sniklas 128150ce9ee0Sniklas dumpblks = cpu_dumpsize(); 128250ce9ee0Sniklas if (dumpblks < 0) 128350ce9ee0Sniklas goto bad; 1284aed035abSart dumpblks += ctod(cpu_dump_mempagecnt()); 128550ce9ee0Sniklas 128650ce9ee0Sniklas /* If dump won't fit (incl. room for possible label), punt. */ 128750ce9ee0Sniklas if (dumpblks > (nblks - ctod(1))) 128850ce9ee0Sniklas goto bad; 128950ce9ee0Sniklas 129050ce9ee0Sniklas /* Put dump at end of partition */ 129150ce9ee0Sniklas dumplo = nblks - dumpblks; 129250ce9ee0Sniklas 129350ce9ee0Sniklas /* dumpsize is in page units, and doesn't include headers. */ 1294aed035abSart dumpsize = cpu_dump_mempagecnt(); 1295df930be7Sderaadt return; 1296df930be7Sderaadt 129750ce9ee0Sniklas bad: 129850ce9ee0Sniklas dumpsize = 0; 129950ce9ee0Sniklas return; 1300df930be7Sderaadt } 1301df930be7Sderaadt 1302df930be7Sderaadt /* 130350ce9ee0Sniklas * Dump the kernel's image to the swap partition. 1304df930be7Sderaadt */ 1305194dd68bSbrad #define BYTES_PER_DUMP PAGE_SIZE 130650ce9ee0Sniklas 1307df930be7Sderaadt void 1308df930be7Sderaadt dumpsys() 1309df930be7Sderaadt { 1310aed035abSart u_long totalbytesleft, bytes, i, n, memcl; 1311aed035abSart u_long maddr; 1312aed035abSart int psize; 131350ce9ee0Sniklas daddr_t blkno; 1314c4071fd1Smillert int (*dump)(dev_t, daddr_t, caddr_t, size_t); 131550ce9ee0Sniklas int error; 1316067cbd75Sderaadt extern int msgbufmapped; 1317df930be7Sderaadt 131850ce9ee0Sniklas /* Save registers. */ 131950ce9ee0Sniklas savectx(&dumppcb); 132050ce9ee0Sniklas 132150ce9ee0Sniklas msgbufmapped = 0; /* don't record dump msgs in msgbuf */ 1322df930be7Sderaadt if (dumpdev == NODEV) 1323df930be7Sderaadt return; 132450ce9ee0Sniklas 132550ce9ee0Sniklas /* 132650ce9ee0Sniklas * For dumps during autoconfiguration, 132750ce9ee0Sniklas * if dump device has already configured... 132850ce9ee0Sniklas */ 1329df930be7Sderaadt if (dumpsize == 0) 133050ce9ee0Sniklas dumpconf(); 133150ce9ee0Sniklas if (dumplo <= 0) { 1332aed035abSart printf("\ndump to dev %u,%u not possible\n", major(dumpdev), 1333aed035abSart minor(dumpdev)); 1334df930be7Sderaadt return; 1335df930be7Sderaadt } 1336aed035abSart printf("\ndumping to dev %u,%u offset %ld\n", major(dumpdev), 1337aed035abSart minor(dumpdev), dumplo); 1338df930be7Sderaadt 133950ce9ee0Sniklas psize = (*bdevsw[major(dumpdev)].d_psize)(dumpdev); 1340df930be7Sderaadt printf("dump "); 134150ce9ee0Sniklas if (psize == -1) { 134250ce9ee0Sniklas printf("area unavailable\n"); 134350ce9ee0Sniklas return; 134450ce9ee0Sniklas } 134550ce9ee0Sniklas 134650ce9ee0Sniklas /* XXX should purge all outstanding keystrokes. */ 134750ce9ee0Sniklas 134850ce9ee0Sniklas if ((error = cpu_dump()) != 0) 134950ce9ee0Sniklas goto err; 135050ce9ee0Sniklas 1351aed035abSart totalbytesleft = ptoa(cpu_dump_mempagecnt()); 135250ce9ee0Sniklas blkno = dumplo + cpu_dumpsize(); 135350ce9ee0Sniklas dump = bdevsw[major(dumpdev)].d_dump; 135450ce9ee0Sniklas error = 0; 1355aed035abSart 1356aed035abSart for (memcl = 0; memcl < mem_cluster_cnt; memcl++) { 1357aed035abSart maddr = mem_clusters[memcl].start; 1358aed035abSart bytes = mem_clusters[memcl].size & ~PAGE_MASK; 1359aed035abSart 1360aed035abSart for (i = 0; i < bytes; i += n, totalbytesleft -= n) { 136150ce9ee0Sniklas 136250ce9ee0Sniklas /* Print out how many MBs we to go. */ 1363aed035abSart if ((totalbytesleft % (1024*1024)) == 0) 1364aed035abSart printf("%ld ", totalbytesleft / (1024 * 1024)); 136550ce9ee0Sniklas 136650ce9ee0Sniklas /* Limit size for next transfer. */ 1367aed035abSart n = bytes - i; 136850ce9ee0Sniklas if (n > BYTES_PER_DUMP) 136950ce9ee0Sniklas n = BYTES_PER_DUMP; 137050ce9ee0Sniklas 137150ce9ee0Sniklas error = (*dump)(dumpdev, blkno, 137250ce9ee0Sniklas (caddr_t)ALPHA_PHYS_TO_K0SEG(maddr), n); 137350ce9ee0Sniklas if (error) 1374aed035abSart goto err; 137550ce9ee0Sniklas maddr += n; 137650ce9ee0Sniklas blkno += btodb(n); /* XXX? */ 137750ce9ee0Sniklas 137850ce9ee0Sniklas /* XXX should look for keystrokes, to cancel. */ 137950ce9ee0Sniklas } 1380aed035abSart } 138150ce9ee0Sniklas 138250ce9ee0Sniklas err: 138350ce9ee0Sniklas switch (error) { 1384a37778bcSderaadt #ifdef DEBUG 1385df930be7Sderaadt case ENXIO: 1386df930be7Sderaadt printf("device bad\n"); 1387df930be7Sderaadt break; 1388df930be7Sderaadt 1389df930be7Sderaadt case EFAULT: 1390df930be7Sderaadt printf("device not ready\n"); 1391df930be7Sderaadt break; 1392df930be7Sderaadt 1393df930be7Sderaadt case EINVAL: 1394df930be7Sderaadt printf("area improper\n"); 1395df930be7Sderaadt break; 1396df930be7Sderaadt 1397df930be7Sderaadt case EIO: 1398df930be7Sderaadt printf("i/o error\n"); 1399df930be7Sderaadt break; 1400df930be7Sderaadt 1401df930be7Sderaadt case EINTR: 1402df930be7Sderaadt printf("aborted from console\n"); 1403df930be7Sderaadt break; 1404a37778bcSderaadt #endif /* DEBUG */ 140550ce9ee0Sniklas case 0: 1406df930be7Sderaadt printf("succeeded\n"); 1407df930be7Sderaadt break; 140850ce9ee0Sniklas 140950ce9ee0Sniklas default: 141050ce9ee0Sniklas printf("error %d\n", error); 141150ce9ee0Sniklas break; 1412df930be7Sderaadt } 1413df930be7Sderaadt printf("\n\n"); 1414df930be7Sderaadt delay(1000); 1415df930be7Sderaadt } 1416df930be7Sderaadt 1417df930be7Sderaadt void 1418df930be7Sderaadt frametoreg(framep, regp) 1419df930be7Sderaadt struct trapframe *framep; 1420df930be7Sderaadt struct reg *regp; 1421df930be7Sderaadt { 1422df930be7Sderaadt 1423df930be7Sderaadt regp->r_regs[R_V0] = framep->tf_regs[FRAME_V0]; 1424df930be7Sderaadt regp->r_regs[R_T0] = framep->tf_regs[FRAME_T0]; 1425df930be7Sderaadt regp->r_regs[R_T1] = framep->tf_regs[FRAME_T1]; 1426df930be7Sderaadt regp->r_regs[R_T2] = framep->tf_regs[FRAME_T2]; 1427df930be7Sderaadt regp->r_regs[R_T3] = framep->tf_regs[FRAME_T3]; 1428df930be7Sderaadt regp->r_regs[R_T4] = framep->tf_regs[FRAME_T4]; 1429df930be7Sderaadt regp->r_regs[R_T5] = framep->tf_regs[FRAME_T5]; 1430df930be7Sderaadt regp->r_regs[R_T6] = framep->tf_regs[FRAME_T6]; 1431df930be7Sderaadt regp->r_regs[R_T7] = framep->tf_regs[FRAME_T7]; 1432df930be7Sderaadt regp->r_regs[R_S0] = framep->tf_regs[FRAME_S0]; 1433df930be7Sderaadt regp->r_regs[R_S1] = framep->tf_regs[FRAME_S1]; 1434df930be7Sderaadt regp->r_regs[R_S2] = framep->tf_regs[FRAME_S2]; 1435df930be7Sderaadt regp->r_regs[R_S3] = framep->tf_regs[FRAME_S3]; 1436df930be7Sderaadt regp->r_regs[R_S4] = framep->tf_regs[FRAME_S4]; 1437df930be7Sderaadt regp->r_regs[R_S5] = framep->tf_regs[FRAME_S5]; 1438df930be7Sderaadt regp->r_regs[R_S6] = framep->tf_regs[FRAME_S6]; 143950ce9ee0Sniklas regp->r_regs[R_A0] = framep->tf_regs[FRAME_A0]; 144050ce9ee0Sniklas regp->r_regs[R_A1] = framep->tf_regs[FRAME_A1]; 144150ce9ee0Sniklas regp->r_regs[R_A2] = framep->tf_regs[FRAME_A2]; 1442df930be7Sderaadt regp->r_regs[R_A3] = framep->tf_regs[FRAME_A3]; 1443df930be7Sderaadt regp->r_regs[R_A4] = framep->tf_regs[FRAME_A4]; 1444df930be7Sderaadt regp->r_regs[R_A5] = framep->tf_regs[FRAME_A5]; 1445df930be7Sderaadt regp->r_regs[R_T8] = framep->tf_regs[FRAME_T8]; 1446df930be7Sderaadt regp->r_regs[R_T9] = framep->tf_regs[FRAME_T9]; 1447df930be7Sderaadt regp->r_regs[R_T10] = framep->tf_regs[FRAME_T10]; 1448df930be7Sderaadt regp->r_regs[R_T11] = framep->tf_regs[FRAME_T11]; 1449df930be7Sderaadt regp->r_regs[R_RA] = framep->tf_regs[FRAME_RA]; 1450df930be7Sderaadt regp->r_regs[R_T12] = framep->tf_regs[FRAME_T12]; 1451df930be7Sderaadt regp->r_regs[R_AT] = framep->tf_regs[FRAME_AT]; 145250ce9ee0Sniklas regp->r_regs[R_GP] = framep->tf_regs[FRAME_GP]; 145350ce9ee0Sniklas /* regp->r_regs[R_SP] = framep->tf_regs[FRAME_SP]; XXX */ 1454df930be7Sderaadt regp->r_regs[R_ZERO] = 0; 1455df930be7Sderaadt } 1456df930be7Sderaadt 1457df930be7Sderaadt void 1458df930be7Sderaadt regtoframe(regp, framep) 1459df930be7Sderaadt struct reg *regp; 1460df930be7Sderaadt struct trapframe *framep; 1461df930be7Sderaadt { 1462df930be7Sderaadt 1463df930be7Sderaadt framep->tf_regs[FRAME_V0] = regp->r_regs[R_V0]; 1464df930be7Sderaadt framep->tf_regs[FRAME_T0] = regp->r_regs[R_T0]; 1465df930be7Sderaadt framep->tf_regs[FRAME_T1] = regp->r_regs[R_T1]; 1466df930be7Sderaadt framep->tf_regs[FRAME_T2] = regp->r_regs[R_T2]; 1467df930be7Sderaadt framep->tf_regs[FRAME_T3] = regp->r_regs[R_T3]; 1468df930be7Sderaadt framep->tf_regs[FRAME_T4] = regp->r_regs[R_T4]; 1469df930be7Sderaadt framep->tf_regs[FRAME_T5] = regp->r_regs[R_T5]; 1470df930be7Sderaadt framep->tf_regs[FRAME_T6] = regp->r_regs[R_T6]; 1471df930be7Sderaadt framep->tf_regs[FRAME_T7] = regp->r_regs[R_T7]; 1472df930be7Sderaadt framep->tf_regs[FRAME_S0] = regp->r_regs[R_S0]; 1473df930be7Sderaadt framep->tf_regs[FRAME_S1] = regp->r_regs[R_S1]; 1474df930be7Sderaadt framep->tf_regs[FRAME_S2] = regp->r_regs[R_S2]; 1475df930be7Sderaadt framep->tf_regs[FRAME_S3] = regp->r_regs[R_S3]; 1476df930be7Sderaadt framep->tf_regs[FRAME_S4] = regp->r_regs[R_S4]; 1477df930be7Sderaadt framep->tf_regs[FRAME_S5] = regp->r_regs[R_S5]; 1478df930be7Sderaadt framep->tf_regs[FRAME_S6] = regp->r_regs[R_S6]; 147950ce9ee0Sniklas framep->tf_regs[FRAME_A0] = regp->r_regs[R_A0]; 148050ce9ee0Sniklas framep->tf_regs[FRAME_A1] = regp->r_regs[R_A1]; 148150ce9ee0Sniklas framep->tf_regs[FRAME_A2] = regp->r_regs[R_A2]; 1482df930be7Sderaadt framep->tf_regs[FRAME_A3] = regp->r_regs[R_A3]; 1483df930be7Sderaadt framep->tf_regs[FRAME_A4] = regp->r_regs[R_A4]; 1484df930be7Sderaadt framep->tf_regs[FRAME_A5] = regp->r_regs[R_A5]; 1485df930be7Sderaadt framep->tf_regs[FRAME_T8] = regp->r_regs[R_T8]; 1486df930be7Sderaadt framep->tf_regs[FRAME_T9] = regp->r_regs[R_T9]; 1487df930be7Sderaadt framep->tf_regs[FRAME_T10] = regp->r_regs[R_T10]; 1488df930be7Sderaadt framep->tf_regs[FRAME_T11] = regp->r_regs[R_T11]; 1489df930be7Sderaadt framep->tf_regs[FRAME_RA] = regp->r_regs[R_RA]; 1490df930be7Sderaadt framep->tf_regs[FRAME_T12] = regp->r_regs[R_T12]; 1491df930be7Sderaadt framep->tf_regs[FRAME_AT] = regp->r_regs[R_AT]; 149250ce9ee0Sniklas framep->tf_regs[FRAME_GP] = regp->r_regs[R_GP]; 149350ce9ee0Sniklas /* framep->tf_regs[FRAME_SP] = regp->r_regs[R_SP]; XXX */ 1494df930be7Sderaadt /* ??? = regp->r_regs[R_ZERO]; */ 1495df930be7Sderaadt } 1496df930be7Sderaadt 1497df930be7Sderaadt void 1498df930be7Sderaadt printregs(regp) 1499df930be7Sderaadt struct reg *regp; 1500df930be7Sderaadt { 1501df930be7Sderaadt int i; 1502df930be7Sderaadt 1503df930be7Sderaadt for (i = 0; i < 32; i++) 1504df930be7Sderaadt printf("R%d:\t0x%016lx%s", i, regp->r_regs[i], 1505df930be7Sderaadt i & 1 ? "\n" : "\t"); 1506df930be7Sderaadt } 1507df930be7Sderaadt 1508df930be7Sderaadt void 1509df930be7Sderaadt regdump(framep) 1510df930be7Sderaadt struct trapframe *framep; 1511df930be7Sderaadt { 1512df930be7Sderaadt struct reg reg; 1513df930be7Sderaadt 1514df930be7Sderaadt frametoreg(framep, ®); 151550ce9ee0Sniklas reg.r_regs[R_SP] = alpha_pal_rdusp(); 151650ce9ee0Sniklas 1517df930be7Sderaadt printf("REGISTERS:\n"); 1518df930be7Sderaadt printregs(®); 1519df930be7Sderaadt } 1520df930be7Sderaadt 1521df930be7Sderaadt #ifdef DEBUG 1522df930be7Sderaadt int sigdebug = 0; 1523df930be7Sderaadt int sigpid = 0; 1524df930be7Sderaadt #define SDB_FOLLOW 0x01 1525df930be7Sderaadt #define SDB_KSTACK 0x02 1526df930be7Sderaadt #endif 1527df930be7Sderaadt 1528df930be7Sderaadt /* 1529df930be7Sderaadt * Send an interrupt to process. 1530df930be7Sderaadt */ 1531df930be7Sderaadt void 15325e1760a6Sderaadt sendsig(catcher, sig, mask, code, type, val) 1533df930be7Sderaadt sig_t catcher; 1534df930be7Sderaadt int sig, mask; 1535df930be7Sderaadt u_long code; 15365e1760a6Sderaadt int type; 15375e1760a6Sderaadt union sigval val; 1538df930be7Sderaadt { 1539df930be7Sderaadt struct proc *p = curproc; 1540df930be7Sderaadt struct sigcontext *scp, ksc; 1541df930be7Sderaadt struct trapframe *frame; 1542df930be7Sderaadt struct sigacts *psp = p->p_sigacts; 15432bf9c155Sderaadt int oonstack, fsize, rndfsize, kscsize; 15442bf9c155Sderaadt siginfo_t *sip, ksi; 1545df930be7Sderaadt 1546df930be7Sderaadt frame = p->p_md.md_tf; 1547df930be7Sderaadt oonstack = psp->ps_sigstk.ss_flags & SS_ONSTACK; 1548df930be7Sderaadt fsize = sizeof ksc; 1549df930be7Sderaadt rndfsize = ((fsize + 15) / 16) * 16; 15502bf9c155Sderaadt kscsize = rndfsize; 15512bf9c155Sderaadt if (psp->ps_siginfo & sigmask(sig)) { 15522bf9c155Sderaadt fsize += sizeof ksi; 15532bf9c155Sderaadt rndfsize = ((fsize + 15) / 16) * 16; 15542bf9c155Sderaadt } 155574652a67Sniklas 1556df930be7Sderaadt /* 1557df930be7Sderaadt * Allocate and validate space for the signal handler 1558df930be7Sderaadt * context. Note that if the stack is in P0 space, the 1559aed035abSart * call to uvm_grow() is a nop, and the useracc() check 1560df930be7Sderaadt * will fail if the process has not already allocated 1561df930be7Sderaadt * the space with a `brk'. 1562df930be7Sderaadt */ 1563df930be7Sderaadt if ((psp->ps_flags & SAS_ALTSTACK) && !oonstack && 1564df930be7Sderaadt (psp->ps_sigonstack & sigmask(sig))) { 15658bc2093aSderaadt scp = (struct sigcontext *)(psp->ps_sigstk.ss_sp + 1566df930be7Sderaadt psp->ps_sigstk.ss_size - rndfsize); 1567df930be7Sderaadt psp->ps_sigstk.ss_flags |= SS_ONSTACK; 1568df930be7Sderaadt } else 156950ce9ee0Sniklas scp = (struct sigcontext *)(alpha_pal_rdusp() - rndfsize); 1570df930be7Sderaadt if ((u_long)scp <= USRSTACK - ctob(p->p_vmspace->vm_ssize)) 1571aed035abSart (void)uvm_grow(p, (u_long)scp); 1572df930be7Sderaadt #ifdef DEBUG 1573df930be7Sderaadt if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid) 157450ce9ee0Sniklas printf("sendsig(%d): sig %d ssp %p usp %p\n", p->p_pid, 1575df930be7Sderaadt sig, &oonstack, scp); 1576df930be7Sderaadt #endif 1577df930be7Sderaadt 1578df930be7Sderaadt /* 1579df930be7Sderaadt * Build the signal context to be used by sigreturn. 1580df930be7Sderaadt */ 1581df930be7Sderaadt ksc.sc_onstack = oonstack; 1582df930be7Sderaadt ksc.sc_mask = mask; 158350ce9ee0Sniklas ksc.sc_pc = frame->tf_regs[FRAME_PC]; 158450ce9ee0Sniklas ksc.sc_ps = frame->tf_regs[FRAME_PS]; 1585df930be7Sderaadt 1586df930be7Sderaadt /* copy the registers. */ 1587df930be7Sderaadt frametoreg(frame, (struct reg *)ksc.sc_regs); 1588df930be7Sderaadt ksc.sc_regs[R_ZERO] = 0xACEDBADE; /* magic number */ 158950ce9ee0Sniklas ksc.sc_regs[R_SP] = alpha_pal_rdusp(); 1590df930be7Sderaadt 1591df930be7Sderaadt /* save the floating-point state, if necessary, then copy it. */ 1592433075b6Spvalchev if (p->p_addr->u_pcb.pcb_fpcpu != NULL) 1593433075b6Spvalchev fpusave_proc(p, 1); 1594df930be7Sderaadt ksc.sc_ownedfp = p->p_md.md_flags & MDP_FPUSED; 1595433075b6Spvalchev memcpy((struct fpreg *)ksc.sc_fpregs, &p->p_addr->u_pcb.pcb_fp, 1596df930be7Sderaadt sizeof(struct fpreg)); 1597433075b6Spvalchev #ifndef NO_IEEE 1598433075b6Spvalchev ksc.sc_fp_control = alpha_read_fp_c(p); 1599433075b6Spvalchev #else 1600433075b6Spvalchev ksc.sc_fp_control = 0; 1601433075b6Spvalchev #endif 1602433075b6Spvalchev memset(ksc.sc_reserved, 0, sizeof ksc.sc_reserved); /* XXX */ 1603433075b6Spvalchev memset(ksc.sc_xxx, 0, sizeof ksc.sc_xxx); /* XXX */ 1604df930be7Sderaadt 1605df930be7Sderaadt #ifdef COMPAT_OSF1 1606df930be7Sderaadt /* 1607df930be7Sderaadt * XXX Create an OSF/1-style sigcontext and associated goo. 1608df930be7Sderaadt */ 1609df930be7Sderaadt #endif 1610df930be7Sderaadt 16112bf9c155Sderaadt if (psp->ps_siginfo & sigmask(sig)) { 16122bf9c155Sderaadt initsiginfo(&ksi, sig, code, type, val); 16132bf9c155Sderaadt sip = (void *)scp + kscsize; 1614679ebc41Smiod if (copyout((caddr_t)&ksi, (caddr_t)sip, fsize - kscsize) != 0) 1615679ebc41Smiod goto trash; 1616aa540fb8Sart } else 1617aa540fb8Sart sip = NULL; 16182bf9c155Sderaadt 1619df930be7Sderaadt /* 1620df930be7Sderaadt * copy the frame out to userland. 1621df930be7Sderaadt */ 1622679ebc41Smiod if (copyout((caddr_t)&ksc, (caddr_t)scp, kscsize) != 0) { 1623679ebc41Smiod trash: 1624679ebc41Smiod #ifdef DEBUG 1625679ebc41Smiod if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid) 1626679ebc41Smiod printf("sendsig(%d): copyout failed on sig %d\n", 1627679ebc41Smiod p->p_pid, sig); 1628679ebc41Smiod #endif 1629679ebc41Smiod /* 1630679ebc41Smiod * Process has trashed its stack; give it an illegal 1631679ebc41Smiod * instruction to halt it in its tracks. 1632679ebc41Smiod */ 163386fd84b3Smiod sigexit(p, SIGILL); 163486fd84b3Smiod /* NOTREACHED */ 1635679ebc41Smiod } 1636df930be7Sderaadt #ifdef DEBUG 1637df930be7Sderaadt if (sigdebug & SDB_FOLLOW) 163850ce9ee0Sniklas printf("sendsig(%d): sig %d scp %p code %lx\n", p->p_pid, sig, 1639df930be7Sderaadt scp, code); 1640df930be7Sderaadt #endif 1641df930be7Sderaadt 1642df930be7Sderaadt /* 1643df930be7Sderaadt * Set up the registers to return to sigcode. 1644df930be7Sderaadt */ 16454a5480feSart frame->tf_regs[FRAME_PC] = p->p_sigcode; 164650ce9ee0Sniklas frame->tf_regs[FRAME_A0] = sig; 1647aa540fb8Sart frame->tf_regs[FRAME_A1] = (u_int64_t)sip; 164850ce9ee0Sniklas frame->tf_regs[FRAME_A2] = (u_int64_t)scp; 1649df930be7Sderaadt frame->tf_regs[FRAME_T12] = (u_int64_t)catcher; /* t12 is pv */ 165050ce9ee0Sniklas alpha_pal_wrusp((unsigned long)scp); 1651df930be7Sderaadt 1652df930be7Sderaadt #ifdef DEBUG 1653df930be7Sderaadt if (sigdebug & SDB_FOLLOW) 1654df930be7Sderaadt printf("sendsig(%d): pc %lx, catcher %lx\n", p->p_pid, 165550ce9ee0Sniklas frame->tf_regs[FRAME_PC], frame->tf_regs[FRAME_A3]); 1656df930be7Sderaadt if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid) 1657df930be7Sderaadt printf("sendsig(%d): sig %d returns\n", 1658df930be7Sderaadt p->p_pid, sig); 1659df930be7Sderaadt #endif 1660df930be7Sderaadt } 1661df930be7Sderaadt 1662df930be7Sderaadt /* 1663df930be7Sderaadt * System call to cleanup state after a signal 1664df930be7Sderaadt * has been taken. Reset signal mask and 1665df930be7Sderaadt * stack state from context left by sendsig (above). 1666df930be7Sderaadt * Return to previous pc and psl as specified by 1667df930be7Sderaadt * context left by sendsig. Check carefully to 1668df930be7Sderaadt * make sure that the user has not modified the 1669125cd19fSderaadt * psl to gain improper privileges or to cause 1670df930be7Sderaadt * a machine fault. 1671df930be7Sderaadt */ 1672df930be7Sderaadt /* ARGSUSED */ 1673df930be7Sderaadt int 1674df930be7Sderaadt sys_sigreturn(p, v, retval) 1675df930be7Sderaadt struct proc *p; 1676df930be7Sderaadt void *v; 1677df930be7Sderaadt register_t *retval; 1678df930be7Sderaadt { 1679df930be7Sderaadt struct sys_sigreturn_args /* { 1680df930be7Sderaadt syscallarg(struct sigcontext *) sigcntxp; 1681df930be7Sderaadt } */ *uap = v; 1682aa540fb8Sart struct sigcontext ksc; 168360959295Smartin #ifdef DEBUG 168460959295Smartin struct sigcontext *scp; 168560959295Smartin #endif 1686aa540fb8Sart int error; 1687df930be7Sderaadt 1688df930be7Sderaadt #ifdef DEBUG 1689df930be7Sderaadt if (sigdebug & SDB_FOLLOW) 169050ce9ee0Sniklas printf("sigreturn: pid %d, scp %p\n", p->p_pid, scp); 1691df930be7Sderaadt #endif 1692df930be7Sderaadt 1693df930be7Sderaadt /* 1694df930be7Sderaadt * Test and fetch the context structure. 1695df930be7Sderaadt * We grab it all at once for speed. 1696df930be7Sderaadt */ 1697aa540fb8Sart if ((error = copyin(SCARG(uap, sigcntxp), &ksc, sizeof(ksc))) != 0) 1698aa540fb8Sart return (error); 1699df930be7Sderaadt 1700df930be7Sderaadt if (ksc.sc_regs[R_ZERO] != 0xACEDBADE) /* magic number */ 1701df930be7Sderaadt return (EINVAL); 1702df930be7Sderaadt /* 1703df930be7Sderaadt * Restore the user-supplied information 1704df930be7Sderaadt */ 1705df930be7Sderaadt if (ksc.sc_onstack) 1706df930be7Sderaadt p->p_sigacts->ps_sigstk.ss_flags |= SS_ONSTACK; 1707df930be7Sderaadt else 1708df930be7Sderaadt p->p_sigacts->ps_sigstk.ss_flags &= ~SS_ONSTACK; 1709df930be7Sderaadt p->p_sigmask = ksc.sc_mask &~ sigcantmask; 1710df930be7Sderaadt 171150ce9ee0Sniklas p->p_md.md_tf->tf_regs[FRAME_PC] = ksc.sc_pc; 171250ce9ee0Sniklas p->p_md.md_tf->tf_regs[FRAME_PS] = 171350ce9ee0Sniklas (ksc.sc_ps | ALPHA_PSL_USERSET) & ~ALPHA_PSL_USERCLR; 1714df930be7Sderaadt 1715df930be7Sderaadt regtoframe((struct reg *)ksc.sc_regs, p->p_md.md_tf); 171650ce9ee0Sniklas alpha_pal_wrusp(ksc.sc_regs[R_SP]); 1717df930be7Sderaadt 1718df930be7Sderaadt /* XXX ksc.sc_ownedfp ? */ 1719433075b6Spvalchev if (p->p_addr->u_pcb.pcb_fpcpu != NULL) 1720433075b6Spvalchev fpusave_proc(p, 0); 1721433075b6Spvalchev memcpy(&p->p_addr->u_pcb.pcb_fp, (struct fpreg *)ksc.sc_fpregs, 1722df930be7Sderaadt sizeof(struct fpreg)); 1723433075b6Spvalchev #ifndef NO_IEEE 1724433075b6Spvalchev p->p_addr->u_pcb.pcb_fp.fpr_cr = ksc.sc_fpcr; 1725433075b6Spvalchev p->p_md.md_flags = ksc.sc_fp_control & MDP_FP_C; 1726433075b6Spvalchev #endif 1727df930be7Sderaadt 1728df930be7Sderaadt #ifdef DEBUG 1729df930be7Sderaadt if (sigdebug & SDB_FOLLOW) 1730df930be7Sderaadt printf("sigreturn(%d): returns\n", p->p_pid); 1731df930be7Sderaadt #endif 1732df930be7Sderaadt return (EJUSTRETURN); 1733df930be7Sderaadt } 1734df930be7Sderaadt 1735df930be7Sderaadt /* 1736df930be7Sderaadt * machine dependent system variables. 1737df930be7Sderaadt */ 173850ce9ee0Sniklas int 1739df930be7Sderaadt cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p) 1740df930be7Sderaadt int *name; 1741df930be7Sderaadt u_int namelen; 1742df930be7Sderaadt void *oldp; 1743df930be7Sderaadt size_t *oldlenp; 1744df930be7Sderaadt void *newp; 1745df930be7Sderaadt size_t newlen; 1746df930be7Sderaadt struct proc *p; 1747df930be7Sderaadt { 1748df930be7Sderaadt dev_t consdev; 1749df930be7Sderaadt 175045e5a1a0Sart if (name[0] != CPU_CHIPSET && namelen != 1) 1751df930be7Sderaadt return (ENOTDIR); /* overloaded */ 1752df930be7Sderaadt 1753df930be7Sderaadt switch (name[0]) { 1754df930be7Sderaadt case CPU_CONSDEV: 1755df930be7Sderaadt if (cn_tab != NULL) 1756df930be7Sderaadt consdev = cn_tab->cn_dev; 1757df930be7Sderaadt else 1758df930be7Sderaadt consdev = NODEV; 1759df930be7Sderaadt return (sysctl_rdstruct(oldp, oldlenp, newp, &consdev, 1760df930be7Sderaadt sizeof consdev)); 1761417eba8cSderaadt 1762417eba8cSderaadt case CPU_ROOT_DEVICE: 1763aed035abSart return (sysctl_rdstring(oldp, oldlenp, newp, 1764aed035abSart root_device)); 1765a37778bcSderaadt #ifndef SMALL_KERNEL 176650ce9ee0Sniklas case CPU_UNALIGNED_PRINT: 176750ce9ee0Sniklas return (sysctl_int(oldp, oldlenp, newp, newlen, 176850ce9ee0Sniklas &alpha_unaligned_print)); 176950ce9ee0Sniklas 177050ce9ee0Sniklas case CPU_UNALIGNED_FIX: 177150ce9ee0Sniklas return (sysctl_int(oldp, oldlenp, newp, newlen, 177250ce9ee0Sniklas &alpha_unaligned_fix)); 177350ce9ee0Sniklas 177450ce9ee0Sniklas case CPU_UNALIGNED_SIGBUS: 177550ce9ee0Sniklas return (sysctl_int(oldp, oldlenp, newp, newlen, 177650ce9ee0Sniklas &alpha_unaligned_sigbus)); 177750ce9ee0Sniklas 17783a630e3fSniklas case CPU_BOOTED_KERNEL: 1779aed035abSart return (sysctl_rdstring(oldp, oldlenp, newp, 1780aed035abSart bootinfo.booted_kernel)); 17813a630e3fSniklas 178245e5a1a0Sart case CPU_CHIPSET: 178345e5a1a0Sart return (alpha_sysctl_chipset(name + 1, namelen - 1, oldp, 178445e5a1a0Sart oldlenp)); 1785a37778bcSderaadt #endif /* SMALL_KERNEL */ 1786433075b6Spvalchev 1787433075b6Spvalchev #ifndef NO_IEEE 1788433075b6Spvalchev case CPU_FP_SYNC_COMPLETE: 1789433075b6Spvalchev return (sysctl_int(oldp, oldlenp, newp, newlen, 1790433075b6Spvalchev &alpha_fp_sync_complete)); 1791433075b6Spvalchev #endif 179227626149Smatthieu case CPU_ALLOWAPERTURE: 179327626149Smatthieu #ifdef APERTURE 179427626149Smatthieu if (securelevel > 0) 17951546ceefSderaadt return (sysctl_int_lower(oldp, oldlenp, newp, newlen, 17961546ceefSderaadt &allowaperture)); 179727626149Smatthieu else 179827626149Smatthieu return (sysctl_int(oldp, oldlenp, newp, newlen, 179927626149Smatthieu &allowaperture)); 180027626149Smatthieu #else 180127626149Smatthieu return (sysctl_rdint(oldp, oldlenp, newp, 0)); 180227626149Smatthieu #endif 1803df930be7Sderaadt default: 1804df930be7Sderaadt return (EOPNOTSUPP); 1805df930be7Sderaadt } 1806df930be7Sderaadt /* NOTREACHED */ 1807df930be7Sderaadt } 1808df930be7Sderaadt 1809df930be7Sderaadt /* 1810df930be7Sderaadt * Set registers on exec. 1811df930be7Sderaadt */ 1812df930be7Sderaadt void 1813df930be7Sderaadt setregs(p, pack, stack, retval) 1814df930be7Sderaadt register struct proc *p; 1815df930be7Sderaadt struct exec_package *pack; 1816df930be7Sderaadt u_long stack; 1817df930be7Sderaadt register_t *retval; 1818df930be7Sderaadt { 1819df930be7Sderaadt struct trapframe *tfp = p->p_md.md_tf; 18203a630e3fSniklas #ifdef DEBUG 18213a630e3fSniklas int i; 18223a630e3fSniklas #endif 1823df930be7Sderaadt 1824df930be7Sderaadt #ifdef DEBUG 182550ce9ee0Sniklas /* 182650ce9ee0Sniklas * Crash and dump, if the user requested it. 182750ce9ee0Sniklas */ 182850ce9ee0Sniklas if (boothowto & RB_DUMP) 182950ce9ee0Sniklas panic("crash requested by boot flags"); 183050ce9ee0Sniklas #endif 183150ce9ee0Sniklas 183250ce9ee0Sniklas #ifdef DEBUG 183350ce9ee0Sniklas for (i = 0; i < FRAME_SIZE; i++) 1834df930be7Sderaadt tfp->tf_regs[i] = 0xbabefacedeadbeef; 1835df930be7Sderaadt #else 183650ce9ee0Sniklas bzero(tfp->tf_regs, FRAME_SIZE * sizeof tfp->tf_regs[0]); 1837df930be7Sderaadt #endif 1838df930be7Sderaadt bzero(&p->p_addr->u_pcb.pcb_fp, sizeof p->p_addr->u_pcb.pcb_fp); 183950ce9ee0Sniklas alpha_pal_wrusp(stack); 184050ce9ee0Sniklas tfp->tf_regs[FRAME_PS] = ALPHA_PSL_USERSET; 184150ce9ee0Sniklas tfp->tf_regs[FRAME_PC] = pack->ep_entry & ~3; 1842df930be7Sderaadt 184350ce9ee0Sniklas tfp->tf_regs[FRAME_A0] = stack; 184450ce9ee0Sniklas /* a1 and a2 already zeroed */ 184550ce9ee0Sniklas tfp->tf_regs[FRAME_T12] = tfp->tf_regs[FRAME_PC]; /* a.k.a. PV */ 184650ce9ee0Sniklas 184750ce9ee0Sniklas p->p_md.md_flags &= ~MDP_FPUSED; 1848433075b6Spvalchev #ifndef NO_IEEE 1849433075b6Spvalchev if (__predict_true((p->p_md.md_flags & IEEE_INHERIT) == 0)) { 1850433075b6Spvalchev p->p_md.md_flags &= ~MDP_FP_C; 1851433075b6Spvalchev p->p_addr->u_pcb.pcb_fp.fpr_cr = FPCR_DYN(FP_RN); 1852433075b6Spvalchev } 1853433075b6Spvalchev #endif 1854433075b6Spvalchev if (p->p_addr->u_pcb.pcb_fpcpu != NULL) 1855433075b6Spvalchev fpusave_proc(p, 0); 1856ee2d823aSmiod 1857ee2d823aSmiod retval[1] = 0; 1858433075b6Spvalchev } 1859df930be7Sderaadt 1860433075b6Spvalchev /* 1861433075b6Spvalchev * Release the FPU. 1862433075b6Spvalchev */ 1863433075b6Spvalchev void 1864433075b6Spvalchev fpusave_cpu(struct cpu_info *ci, int save) 1865433075b6Spvalchev { 1866433075b6Spvalchev struct proc *p; 1867433075b6Spvalchev 1868433075b6Spvalchev KDASSERT(ci == curcpu()); 1869433075b6Spvalchev 1870433075b6Spvalchev #if defined(MULTIPROCESSOR) 1871433075b6Spvalchev atomic_setbits_ulong(&ci->ci_flags, CPUF_FPUSAVE); 1872433075b6Spvalchev #endif 1873433075b6Spvalchev 1874433075b6Spvalchev p = ci->ci_fpcurproc; 1875433075b6Spvalchev if (p == NULL) 1876433075b6Spvalchev goto out; 1877433075b6Spvalchev 1878433075b6Spvalchev if (save) { 1879433075b6Spvalchev alpha_pal_wrfen(1); 1880433075b6Spvalchev savefpstate(&p->p_addr->u_pcb.pcb_fp); 1881433075b6Spvalchev } 1882433075b6Spvalchev 1883433075b6Spvalchev alpha_pal_wrfen(0); 1884433075b6Spvalchev 1885433075b6Spvalchev p->p_addr->u_pcb.pcb_fpcpu = NULL; 1886433075b6Spvalchev ci->ci_fpcurproc = NULL; 1887433075b6Spvalchev 1888433075b6Spvalchev out: 1889433075b6Spvalchev #if defined(MULTIPROCESSOR) 1890433075b6Spvalchev atomic_clearbits_ulong(&ci->ci_flags, CPUF_FPUSAVE); 1891433075b6Spvalchev #endif 1892433075b6Spvalchev return; 1893433075b6Spvalchev } 1894433075b6Spvalchev 1895433075b6Spvalchev /* 1896433075b6Spvalchev * Synchronize FP state for this process. 1897433075b6Spvalchev */ 1898433075b6Spvalchev void 1899433075b6Spvalchev fpusave_proc(struct proc *p, int save) 1900433075b6Spvalchev { 1901433075b6Spvalchev struct cpu_info *ci = curcpu(); 1902433075b6Spvalchev struct cpu_info *oci; 1903433075b6Spvalchev #if defined(MULTIPROCESSOR) 1904433075b6Spvalchev u_long ipi = save ? ALPHA_IPI_SYNCH_FPU : ALPHA_IPI_DISCARD_FPU; 19052199c730Smartin int spincount; 1906433075b6Spvalchev #endif 1907433075b6Spvalchev 1908433075b6Spvalchev KDASSERT(p->p_addr != NULL); 1909433075b6Spvalchev 1910433075b6Spvalchev oci = p->p_addr->u_pcb.pcb_fpcpu; 1911433075b6Spvalchev if (oci == NULL) { 1912433075b6Spvalchev return; 1913433075b6Spvalchev } 1914433075b6Spvalchev 1915433075b6Spvalchev #if defined(MULTIPROCESSOR) 1916433075b6Spvalchev if (oci == ci) { 1917433075b6Spvalchev KASSERT(ci->ci_fpcurproc == p); 1918433075b6Spvalchev fpusave_cpu(ci, save); 1919433075b6Spvalchev return; 1920433075b6Spvalchev } 1921433075b6Spvalchev 1922433075b6Spvalchev KASSERT(oci->ci_fpcurproc == p); 1923433075b6Spvalchev alpha_send_ipi(oci->ci_cpuid, ipi); 1924433075b6Spvalchev 1925433075b6Spvalchev spincount = 0; 1926433075b6Spvalchev while (p->p_addr->u_pcb.pcb_fpcpu != NULL) { 1927433075b6Spvalchev spincount++; 1928433075b6Spvalchev delay(1000); /* XXX */ 1929433075b6Spvalchev if (spincount > 10000) 1930433075b6Spvalchev panic("fpsave ipi didn't"); 1931433075b6Spvalchev } 1932433075b6Spvalchev #else 1933433075b6Spvalchev KASSERT(ci->ci_fpcurproc == p); 1934433075b6Spvalchev fpusave_cpu(ci, save); 1935433075b6Spvalchev #endif /* MULTIPROCESSOR */ 1936df930be7Sderaadt } 1937df930be7Sderaadt 1938df930be7Sderaadt int 1939df930be7Sderaadt spl0() 1940df930be7Sderaadt { 1941df930be7Sderaadt 1942aed035abSart if (ssir) { 1943aed035abSart (void) alpha_pal_swpipl(ALPHA_PSL_IPL_SOFT); 19442a2685f2Sart softintr_dispatch(); 1945aed035abSart } 1946df930be7Sderaadt 194750ce9ee0Sniklas return (alpha_pal_swpipl(ALPHA_PSL_IPL_0)); 1948df930be7Sderaadt } 1949df930be7Sderaadt 1950df930be7Sderaadt /* 1951df930be7Sderaadt * The following primitives manipulate the run queues. _whichqs tells which 1952df930be7Sderaadt * of the 32 queues _qs have processes in them. Setrunqueue puts processes 1953e464495eSniklas * into queues, Remrunqueue removes them from queues. The running process is 1954e464495eSniklas * on no queue, other processes are on a queue related to p->p_priority, 1955e464495eSniklas * divided by 4 actually to shrink the 0-127 range of priorities into the 32 1956e464495eSniklas * available queues. 1957df930be7Sderaadt */ 1958df930be7Sderaadt /* 1959df930be7Sderaadt * setrunqueue(p) 1960df930be7Sderaadt * proc *p; 1961df930be7Sderaadt * 1962df930be7Sderaadt * Call should be made at splclock(), and p->p_stat should be SRUN. 1963df930be7Sderaadt */ 1964df930be7Sderaadt 19652a2685f2Sart /* XXXART - grmble */ 19662a2685f2Sart #define sched_qs qs 19672a2685f2Sart #define sched_whichqs whichqs 19682a2685f2Sart 1969df930be7Sderaadt void 1970df930be7Sderaadt setrunqueue(p) 1971df930be7Sderaadt struct proc *p; 1972df930be7Sderaadt { 1973df930be7Sderaadt int bit; 1974df930be7Sderaadt 1975df930be7Sderaadt /* firewall: p->p_back must be NULL */ 1976df930be7Sderaadt if (p->p_back != NULL) 1977df930be7Sderaadt panic("setrunqueue"); 1978df930be7Sderaadt 1979df930be7Sderaadt bit = p->p_priority >> 2; 19802a2685f2Sart sched_whichqs |= (1 << bit); 19812a2685f2Sart p->p_forw = (struct proc *)&sched_qs[bit]; 19822a2685f2Sart p->p_back = sched_qs[bit].ph_rlink; 1983df930be7Sderaadt p->p_back->p_forw = p; 19842a2685f2Sart sched_qs[bit].ph_rlink = p; 1985df930be7Sderaadt } 1986df930be7Sderaadt 1987df930be7Sderaadt /* 1988e464495eSniklas * remrunqueue(p) 1989df930be7Sderaadt * 1990df930be7Sderaadt * Call should be made at splclock(). 1991df930be7Sderaadt */ 1992df930be7Sderaadt void 1993d3cbbad5Skstailey remrunqueue(p) 1994df930be7Sderaadt struct proc *p; 1995df930be7Sderaadt { 1996df930be7Sderaadt int bit; 1997df930be7Sderaadt 1998df930be7Sderaadt bit = p->p_priority >> 2; 19992a2685f2Sart if ((sched_whichqs & (1 << bit)) == 0) 2000d3cbbad5Skstailey panic("remrunqueue"); 2001df930be7Sderaadt 2002df930be7Sderaadt p->p_back->p_forw = p->p_forw; 2003df930be7Sderaadt p->p_forw->p_back = p->p_back; 2004df930be7Sderaadt p->p_back = NULL; /* for firewall checking. */ 2005df930be7Sderaadt 20062a2685f2Sart if ((struct proc *)&sched_qs[bit] == sched_qs[bit].ph_link) 20072a2685f2Sart sched_whichqs &= ~(1 << bit); 2008df930be7Sderaadt } 2009df930be7Sderaadt 2010df930be7Sderaadt /* 2011417eba8cSderaadt * Wait "n" microseconds. 2012417eba8cSderaadt */ 201350ce9ee0Sniklas void 2014417eba8cSderaadt delay(n) 201550ce9ee0Sniklas unsigned long n; 2016417eba8cSderaadt { 20175d097e9eSmiod unsigned long pcc0, pcc1, curcycle, cycles, usec; 20185d097e9eSmiod 20195d097e9eSmiod if (n == 0) 20205d097e9eSmiod return; 20215d097e9eSmiod 20225d097e9eSmiod pcc0 = alpha_rpcc() & 0xffffffffUL; 20235d097e9eSmiod cycles = 0; 20245d097e9eSmiod usec = 0; 20255d097e9eSmiod 20265d097e9eSmiod while (usec <= n) { 20275d097e9eSmiod /* 20285d097e9eSmiod * Get the next CPU cycle count - assumes that we can not 20295d097e9eSmiod * have had more than one 32 bit overflow. 20305d097e9eSmiod */ 20315d097e9eSmiod pcc1 = alpha_rpcc() & 0xffffffffUL; 20325d097e9eSmiod if (pcc1 < pcc0) 20335d097e9eSmiod curcycle = (pcc1 + 0x100000000UL) - pcc0; 20345d097e9eSmiod else 20355d097e9eSmiod curcycle = pcc1 - pcc0; 2036417eba8cSderaadt 2037aed035abSart /* 20385d097e9eSmiod * We now have the number of processor cycles since we 20395d097e9eSmiod * last checked. Add the current cycle count to the 20405d097e9eSmiod * running total. If it's over cycles_per_usec, increment 20415d097e9eSmiod * the usec counter. 2042aed035abSart */ 20435d097e9eSmiod cycles += curcycle; 20445d097e9eSmiod while (cycles > cycles_per_usec) { 20455d097e9eSmiod usec++; 20465d097e9eSmiod cycles -= cycles_per_usec; 20475d097e9eSmiod } 20485d097e9eSmiod pcc0 = pcc1; 20495d097e9eSmiod } 2050417eba8cSderaadt } 2051417eba8cSderaadt 20529da89091Sderaadt #if defined(COMPAT_OSF1) 2053c4071fd1Smillert void cpu_exec_ecoff_setregs(struct proc *, struct exec_package *, 2054c4071fd1Smillert u_long, register_t *); 20553a630e3fSniklas 2056df930be7Sderaadt void 2057417eba8cSderaadt cpu_exec_ecoff_setregs(p, epp, stack, retval) 2058df930be7Sderaadt struct proc *p; 2059417eba8cSderaadt struct exec_package *epp; 2060df930be7Sderaadt u_long stack; 2061df930be7Sderaadt register_t *retval; 2062df930be7Sderaadt { 2063417eba8cSderaadt struct ecoff_exechdr *execp = (struct ecoff_exechdr *)epp->ep_hdr; 2064df930be7Sderaadt 2065417eba8cSderaadt setregs(p, epp, stack, retval); 206650ce9ee0Sniklas p->p_md.md_tf->tf_regs[FRAME_GP] = execp->a.gp_value; 2067df930be7Sderaadt } 2068df930be7Sderaadt 2069df930be7Sderaadt /* 2070df930be7Sderaadt * cpu_exec_ecoff_hook(): 2071df930be7Sderaadt * cpu-dependent ECOFF format hook for execve(). 2072df930be7Sderaadt * 2073df930be7Sderaadt * Do any machine-dependent diddling of the exec package when doing ECOFF. 2074df930be7Sderaadt * 2075df930be7Sderaadt */ 2076df930be7Sderaadt int 2077417eba8cSderaadt cpu_exec_ecoff_hook(p, epp) 2078df930be7Sderaadt struct proc *p; 2079df930be7Sderaadt struct exec_package *epp; 2080df930be7Sderaadt { 2081417eba8cSderaadt struct ecoff_exechdr *execp = (struct ecoff_exechdr *)epp->ep_hdr; 2082c3114d5bSericj extern struct emul emul_native; 2083aed035abSart int error; 20844e8700e2Sericj extern int osf1_exec_ecoff_hook(struct proc *, struct exec_package *); 2085df930be7Sderaadt 2086417eba8cSderaadt switch (execp->f.f_magic) { 2087df930be7Sderaadt #ifdef COMPAT_OSF1 2088df930be7Sderaadt case ECOFF_MAGIC_ALPHA: 20894e8700e2Sericj error = osf1_exec_ecoff_hook(p, epp); 2090df930be7Sderaadt break; 2091df930be7Sderaadt #endif 2092df930be7Sderaadt 209350ce9ee0Sniklas case ECOFF_MAGIC_NATIVE_ALPHA: 2094a2f8ce8dSderaadt epp->ep_emul = &emul_native; 2095aed035abSart error = 0; 2096df930be7Sderaadt break; 2097df930be7Sderaadt 2098df930be7Sderaadt default: 2099aed035abSart error = ENOEXEC; 2100df930be7Sderaadt } 2101aed035abSart return (error); 2102df930be7Sderaadt } 2103df930be7Sderaadt #endif 2104e464495eSniklas 2105aed035abSart int 2106aed035abSart alpha_pa_access(pa) 2107aed035abSart u_long pa; 2108aed035abSart { 2109aed035abSart int i; 2110aed035abSart 2111aed035abSart for (i = 0; i < mem_cluster_cnt; i++) { 2112aed035abSart if (pa < mem_clusters[i].start) 2113aed035abSart continue; 2114aed035abSart if ((pa - mem_clusters[i].start) >= 2115aed035abSart (mem_clusters[i].size & ~PAGE_MASK)) 2116aed035abSart continue; 2117aed035abSart return (mem_clusters[i].size & PAGE_MASK); /* prot */ 2118aed035abSart } 2119aed035abSart 2120aed035abSart /* 2121aed035abSart * Address is not a memory address. If we're secure, disallow 2122aed035abSart * access. Otherwise, grant read/write. 2123aed035abSart */ 2124aed035abSart if (securelevel > 0) 2125aed035abSart return (VM_PROT_NONE); 2126aed035abSart else 2127aed035abSart return (VM_PROT_READ | VM_PROT_WRITE); 2128aed035abSart } 2129aed035abSart 2130e464495eSniklas /* XXX XXX BEGIN XXX XXX */ 2131aed035abSart paddr_t alpha_XXX_dmamap_or; /* XXX */ 2132e464495eSniklas /* XXX */ 2133aed035abSart paddr_t /* XXX */ 2134e464495eSniklas alpha_XXX_dmamap(v) /* XXX */ 2135aed035abSart vaddr_t v; /* XXX */ 2136e464495eSniklas { /* XXX */ 2137e464495eSniklas /* XXX */ 2138e464495eSniklas return (vtophys(v) | alpha_XXX_dmamap_or); /* XXX */ 2139e464495eSniklas } /* XXX */ 2140e464495eSniklas /* XXX XXX END XXX XXX */ 2141