1 /* 2 * Copyright (C) 1995, 1996 Wolfgang Solfrank. 3 * Copyright (C) 1995, 1996 TooLs GmbH. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed by TooLs GmbH. 17 * 4. The name of TooLs GmbH may not be used to endorse or promote products 18 * derived from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 /* 32 * Copyright (C) 2001 Benno Rice 33 * All rights reserved. 34 * 35 * Redistribution and use in source and binary forms, with or without 36 * modification, are permitted provided that the following conditions 37 * are met: 38 * 1. Redistributions of source code must retain the above copyright 39 * notice, this list of conditions and the following disclaimer. 40 * 2. Redistributions in binary form must reproduce the above copyright 41 * notice, this list of conditions and the following disclaimer in the 42 * documentation and/or other materials provided with the distribution. 43 * 44 * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR 45 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 46 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 47 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 48 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 49 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 50 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 51 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 52 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 53 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 54 * $NetBSD: machdep.c,v 1.74.2.1 2000/11/01 16:13:48 tv Exp $ 55 */ 56 57 #ifndef lint 58 static const char rcsid[] = 59 "$FreeBSD$"; 60 #endif /* not lint */ 61 62 #include "opt_ddb.h" 63 #include "opt_compat.h" 64 #include "opt_msgbuf.h" 65 66 #include <sys/param.h> 67 #include <sys/systm.h> 68 #include <sys/eventhandler.h> 69 #include <sys/imgact.h> 70 #include <sys/sysproto.h> 71 #include <sys/lock.h> 72 #include <sys/mutex.h> 73 #include <sys/ktr.h> 74 #include <sys/signalvar.h> 75 #include <sys/kernel.h> 76 #include <sys/proc.h> 77 #include <sys/malloc.h> 78 #include <sys/reboot.h> 79 #include <sys/bio.h> 80 #include <sys/buf.h> 81 #include <sys/bus.h> 82 #include <sys/mbuf.h> 83 #include <sys/vmmeter.h> 84 #include <sys/msgbuf.h> 85 #include <sys/exec.h> 86 #include <sys/sysctl.h> 87 #include <sys/uio.h> 88 #include <sys/linker.h> 89 #include <sys/cons.h> 90 #include <sys/ucontext.h> 91 #include <sys/sysent.h> 92 #include <net/netisr.h> 93 #include <vm/vm.h> 94 #include <vm/vm_kern.h> 95 #include <vm/vm_page.h> 96 #include <vm/vm_map.h> 97 #include <vm/vm_extern.h> 98 #include <vm/vm_object.h> 99 #include <vm/vm_pager.h> 100 #include <sys/user.h> 101 #include <sys/ptrace.h> 102 #include <machine/bat.h> 103 #include <machine/clock.h> 104 #include <machine/md_var.h> 105 #include <machine/metadata.h> 106 #include <machine/reg.h> 107 #include <machine/fpu.h> 108 #include <machine/vmparam.h> 109 #include <machine/elf.h> 110 #include <machine/trap.h> 111 #include <machine/powerpc.h> 112 #include <dev/ofw/openfirm.h> 113 #include <ddb/ddb.h> 114 #include <sys/vnode.h> 115 #include <machine/sigframe.h> 116 117 long physmem = 0; 118 int cold = 1; 119 120 char pcpu0[PAGE_SIZE]; 121 char uarea0[UAREA_PAGES * PAGE_SIZE]; 122 struct trapframe frame0; 123 124 vm_offset_t kstack0; 125 vm_offset_t kstack0_phys; 126 127 char machine[] = "powerpc"; 128 SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD, machine, 0, ""); 129 130 static char model[128]; 131 SYSCTL_STRING(_hw, HW_MODEL, model, CTLFLAG_RD, model, 0, ""); 132 133 static int cacheline_size = CACHELINESIZE; 134 SYSCTL_INT(_machdep, CPU_CACHELINE, cacheline_size, 135 CTLFLAG_RD, &cacheline_size, 0, ""); 136 137 char bootpath[256]; 138 139 #ifdef DDB 140 /* start and end of kernel symbol table */ 141 void *ksym_start, *ksym_end; 142 #endif /* DDB */ 143 144 static void cpu_startup(void *); 145 SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL) 146 147 void powerpc_init(u_int, u_int, u_int, void *); 148 149 int save_ofw_mapping(void); 150 int restore_ofw_mapping(void); 151 152 void install_extint(void (*)(void)); 153 154 int setfault(faultbuf); /* defined in locore.S */ 155 156 static int 157 sysctl_hw_physmem(SYSCTL_HANDLER_ARGS) 158 { 159 u_long val; 160 161 val = ctob(physmem); 162 return (sysctl_handle_long(oidp, &val, 0, req)); 163 } 164 165 SYSCTL_PROC(_hw, HW_PHYSMEM, physmem, CTLTYPE_ULONG | CTLFLAG_RD, 166 0, 0, sysctl_hw_physmem, "LU", ""); 167 168 long Maxmem = 0; 169 170 static int chosen; 171 172 struct pmap ofw_pmap; 173 extern int ofmsr; 174 175 struct bat battable[16]; 176 177 static void identifycpu(void); 178 179 struct kva_md_info kmi; 180 181 static void 182 powerpc_ofw_shutdown(void *junk, int howto) 183 { 184 if (howto & RB_HALT) { 185 OF_exit(); 186 } 187 } 188 189 static void 190 cpu_startup(void *dummy) 191 { 192 193 /* 194 * Good {morning,afternoon,evening,night}. 195 */ 196 identifycpu(); 197 198 /* startrtclock(); */ 199 #ifdef PERFMON 200 perfmon_init(); 201 #endif 202 printf("real memory = %ld (%ldK bytes)\n", ptoa(Maxmem), 203 ptoa(Maxmem) / 1024); 204 205 /* 206 * Display any holes after the first chunk of extended memory. 207 */ 208 if (bootverbose) { 209 int indx; 210 211 printf("Physical memory chunk(s):\n"); 212 for (indx = 0; phys_avail[indx + 1] != 0; indx += 2) { 213 int size1 = phys_avail[indx + 1] - phys_avail[indx]; 214 215 printf("0x%08x - 0x%08x, %d bytes (%d pages)\n", 216 phys_avail[indx], phys_avail[indx + 1] - 1, size1, 217 size1 / PAGE_SIZE); 218 } 219 } 220 221 vm_ksubmap_init(&kmi); 222 223 printf("avail memory = %ld (%ldK bytes)\n", ptoa(cnt.v_free_count), 224 ptoa(cnt.v_free_count) / 1024); 225 226 /* 227 * Set up buffers, so they can be used to read disk labels. 228 */ 229 bufinit(); 230 vm_pager_bufferinit(); 231 232 EVENTHANDLER_REGISTER(shutdown_final, powerpc_ofw_shutdown, 0, 233 SHUTDOWN_PRI_LAST); 234 235 #ifdef SMP 236 /* 237 * OK, enough kmem_alloc/malloc state should be up, lets get on with it! 238 */ 239 mp_start(); /* fire up the secondaries */ 240 mp_announce(); 241 #endif /* SMP */ 242 } 243 244 void 245 identifycpu() 246 { 247 unsigned int pvr, version, revision; 248 249 /* 250 * Find cpu type (Do it by OpenFirmware?) 251 */ 252 __asm ("mfpvr %0" : "=r"(pvr)); 253 version = pvr >> 16; 254 revision = pvr & 0xffff; 255 switch (version) { 256 case 0x0000: 257 sprintf(model, "Simulator (psim)"); 258 break; 259 case 0x0001: 260 sprintf(model, "601"); 261 break; 262 case 0x0003: 263 sprintf(model, "603 (Wart)"); 264 break; 265 case 0x0004: 266 sprintf(model, "604 (Zephyr)"); 267 break; 268 case 0x0005: 269 sprintf(model, "602 (Galahad)"); 270 break; 271 case 0x0006: 272 sprintf(model, "603e (Stretch)"); 273 break; 274 case 0x0007: 275 if ((revision && 0xf000) == 0x0000) 276 sprintf(model, "603ev (Valiant)"); 277 else 278 sprintf(model, "603r (Goldeneye)"); 279 break; 280 case 0x0008: 281 if ((revision && 0xf000) == 0x0000) 282 sprintf(model, "G3 / 750 (Arthur)"); 283 else 284 sprintf(model, "G3 / 755 (Goldfinger)"); 285 break; 286 case 0x0009: 287 if ((revision && 0xf000) == 0x0000) 288 sprintf(model, "604e (Sirocco)"); 289 else 290 sprintf(model, "604r (Mach V)"); 291 break; 292 case 0x000a: 293 sprintf(model, "604r (Mach V)"); 294 break; 295 case 0x000c: 296 sprintf(model, "G4 / 7400 (Max)"); 297 break; 298 case 0x0014: 299 sprintf(model, "620 (Red October)"); 300 break; 301 case 0x0081: 302 sprintf(model, "8240 (Kahlua)"); 303 break; 304 case 0x8000: 305 sprintf(model, "G4 / 7450 (V'ger)"); 306 break; 307 case 0x800c: 308 sprintf(model, "G4 / 7410 (Nitro)"); 309 break; 310 case 0x8081: 311 sprintf(model, "8245 (Kahlua II)"); 312 break; 313 default: 314 sprintf(model, "Version %x", version); 315 break; 316 } 317 sprintf(model + strlen(model), " (Revision %x)", revision); 318 printf("CPU: PowerPC %s\n", model); 319 } 320 321 extern char kernel_text[], _end[]; 322 323 extern void *trapcode, *trapsize; 324 extern void *alitrap, *alisize; 325 extern void *dsitrap, *dsisize; 326 extern void *isitrap, *isisize; 327 extern void *decrint, *decrsize; 328 extern void *tlbimiss, *tlbimsize; 329 extern void *tlbdlmiss, *tlbdlmsize; 330 extern void *tlbdsmiss, *tlbdsmsize; 331 extern void *extint, *extsize; 332 333 #if 0 /* XXX: interrupt handler. We'll get to this later */ 334 extern void ext_intr(void); 335 #endif 336 337 #ifdef DDB 338 extern ddblow, ddbsize; 339 #endif 340 #ifdef IPKDB 341 extern ipkdblow, ipkdbsize; 342 #endif 343 344 void 345 powerpc_init(u_int startkernel, u_int endkernel, u_int basekernel, void *mdp) 346 { 347 struct pcpu *pc; 348 vm_offset_t end, off; 349 void *kmdp; 350 351 end = 0; 352 kmdp = NULL; 353 354 /* 355 * Parse metadata if present and fetch parameters. Must be done 356 * before console is inited so cninit gets the right value of 357 * boothowto. 358 */ 359 if (mdp != NULL) { 360 preload_metadata = mdp; 361 kmdp = preload_search_by_type("elf kernel"); 362 if (kmdp != NULL) { 363 boothowto = MD_FETCH(kmdp, MODINFOMD_HOWTO, int); 364 kern_envp = MD_FETCH(kmdp, MODINFOMD_ENVP, char *); 365 end = MD_FETCH(kmdp, MODINFOMD_KERNEND, vm_offset_t); 366 } 367 } 368 369 /* 370 * Initialize the console before printing anything. 371 */ 372 cninit(); 373 374 /* 375 * Complain if there is no metadata. 376 */ 377 if (mdp == NULL || kmdp == NULL) { 378 printf("powerpc_init: no loader metadata.\n"); 379 } 380 381 #ifdef DDB 382 kdb_init(); 383 #endif 384 385 /* 386 * XXX: Initialize the interrupt tables. 387 */ 388 bcopy(&dsitrap, (void *)EXC_DSI, (size_t)&dsisize); 389 bcopy(&isitrap, (void *)EXC_ISI, (size_t)&isisize); 390 bcopy(&trapcode, (void *)EXC_EXI, (size_t)&trapsize); 391 bcopy(&trapcode, (void *)EXC_ALI, (size_t)&trapsize); 392 bcopy(&trapcode, (void *)EXC_PGM, (size_t)&trapsize); 393 bcopy(&trapcode, (void *)EXC_FPU, (size_t)&trapsize); 394 bcopy(&trapcode, (void *)EXC_DECR, (size_t)&trapsize); 395 bcopy(&trapcode, (void *)EXC_SC, (size_t)&trapsize); 396 bcopy(&trapcode, (void *)EXC_TRC, (size_t)&trapsize); 397 398 /* 399 * Start initializing proc0 and thread0. 400 */ 401 proc_linkup(&proc0, &ksegrp0, &kse0, &thread0); 402 proc0.p_uarea = (struct user *)uarea0; 403 proc0.p_stats = &proc0.p_uarea->u_stats; 404 thread0.td_frame = &frame0; 405 406 /* 407 * Set up per-cpu data. 408 */ 409 pc = (struct pcpu *)(pcpu0 + PAGE_SIZE) - 1; 410 pcpu_init(pc, 0, sizeof(struct pcpu)); 411 pc->pc_curthread = &thread0; 412 pc->pc_curpcb = thread0.td_pcb; 413 pc->pc_cpuid = 0; 414 /* pc->pc_mid = mid; */ 415 416 __asm __volatile("mtsprg 0, %0" :: "r"(pc)); 417 418 mutex_init(); 419 420 /* 421 * Make sure translation has been enabled 422 */ 423 mtmsr(mfmsr() | PSL_IR|PSL_DR|PSL_ME|PSL_RI); 424 425 /* 426 * Initialise virtual memory. 427 */ 428 pmap_bootstrap(startkernel, endkernel); 429 430 /* 431 * Initialize tunables. 432 */ 433 init_param1(); 434 init_param2(physmem); 435 436 /* 437 * Finish setting up thread0. 438 */ 439 thread0.td_kstack = kstack0; 440 thread0.td_pcb = (struct pcb *) 441 (thread0.td_kstack + KSTACK_PAGES * PAGE_SIZE) - 1; 442 443 /* 444 * Map and initialise the message buffer. 445 */ 446 for (off = 0; off < round_page(MSGBUF_SIZE); off += PAGE_SIZE) 447 pmap_kenter((vm_offset_t)msgbufp + off, msgbuf_phys + off); 448 msgbufinit(msgbufp, MSGBUF_SIZE); 449 } 450 451 void 452 bzero(void *buf, size_t len) 453 { 454 caddr_t p; 455 456 p = buf; 457 458 while (((vm_offset_t) p & (sizeof(u_long) - 1)) && len) { 459 *p++ = 0; 460 len--; 461 } 462 463 while (len >= sizeof(u_long) * 8) { 464 *(u_long*) p = 0; 465 *((u_long*) p + 1) = 0; 466 *((u_long*) p + 2) = 0; 467 *((u_long*) p + 3) = 0; 468 len -= sizeof(u_long) * 8; 469 *((u_long*) p + 4) = 0; 470 *((u_long*) p + 5) = 0; 471 *((u_long*) p + 6) = 0; 472 *((u_long*) p + 7) = 0; 473 p += sizeof(u_long) * 8; 474 } 475 476 while (len >= sizeof(u_long)) { 477 *(u_long*) p = 0; 478 len -= sizeof(u_long); 479 p += sizeof(u_long); 480 } 481 482 while (len) { 483 *p++ = 0; 484 len--; 485 } 486 } 487 488 void 489 sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code) 490 { 491 struct trapframe *tf; 492 struct sigframe *sfp; 493 struct sigacts *psp; 494 struct sigframe sf; 495 struct thread *td; 496 struct proc *p; 497 int oonstack, rndfsize; 498 499 td = curthread; 500 p = td->td_proc; 501 psp = p->p_sigacts; 502 tf = td->td_frame; 503 oonstack = sigonstack(tf->fixreg[1]); 504 505 rndfsize = ((sizeof(sf) + 15) / 16) * 16; 506 507 CTR4(KTR_SIG, "sendsig: td=%p (%s) catcher=%p sig=%d", td, p->p_comm, 508 catcher, sig); 509 510 /* 511 * Save user context 512 */ 513 memset(&sf, 0, sizeof(sf)); 514 sf.sf_uc.uc_sigmask = *mask; 515 sf.sf_uc.uc_stack = p->p_sigstk; 516 sf.sf_uc.uc_stack.ss_flags = (p->p_flag & P_ALTSTACK) 517 ? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE; 518 519 sf.sf_uc.uc_mcontext.mc_onstack = (oonstack) ? 1 : 0; 520 memcpy(&sf.sf_uc.uc_mcontext.mc_frame, tf, sizeof(struct trapframe)); 521 522 /* 523 * Allocate and validate space for the signal handler context. 524 */ 525 if ((p->p_flag & P_ALTSTACK) != 0 && !oonstack && 526 SIGISMEMBER(psp->ps_sigonstack, sig)) { 527 sfp = (struct sigframe *)((caddr_t)p->p_sigstk.ss_sp + 528 p->p_sigstk.ss_size - rndfsize); 529 } else { 530 sfp = (struct sigframe *)(tf->fixreg[1] - rndfsize); 531 } 532 PROC_UNLOCK(p); 533 534 /* 535 * Translate the signal if appropriate (Linux emu ?) 536 */ 537 if (p->p_sysent->sv_sigtbl && sig <= p->p_sysent->sv_sigsize) 538 sig = p->p_sysent->sv_sigtbl[_SIG_IDX(sig)]; 539 540 /* 541 * Save the floating-point state, if necessary, then copy it. 542 */ 543 /* XXX */ 544 545 /* 546 * Set up the registers to return to sigcode. 547 * 548 * r1/sp - sigframe ptr 549 * lr - sig function, dispatched to by blrl in trampoline 550 * r3 - sig number 551 * r4 - SIGINFO ? &siginfo : exception code 552 * r5 - user context 553 * srr0 - trampoline function addr 554 */ 555 tf->lr = (register_t)catcher; 556 tf->fixreg[1] = (register_t)sfp; 557 tf->fixreg[FIRSTARG] = sig; 558 tf->fixreg[FIRSTARG+2] = (register_t)&sfp->sf_uc; 559 560 PROC_LOCK(p); 561 if (SIGISMEMBER(p->p_sigacts->ps_siginfo, sig)) { 562 /* 563 * Signal handler installed with SA_SIGINFO. 564 */ 565 tf->fixreg[FIRSTARG+1] = (register_t)&sfp->sf_si; 566 567 /* 568 * Fill siginfo structure. 569 */ 570 sf.sf_si.si_signo = sig; 571 sf.sf_si.si_code = code; 572 sf.sf_si.si_addr = (void *)tf->srr0; 573 sf.sf_si.si_pid = p->p_pid; 574 sf.sf_si.si_uid = p->p_ucred->cr_uid; 575 } else { 576 /* Old FreeBSD-style arguments. */ 577 tf->fixreg[FIRSTARG+1] = code; 578 } 579 PROC_UNLOCK(p); 580 581 tf->srr0 = (register_t)(PS_STRINGS - *(p->p_sysent->sv_szsigcode)); 582 583 /* 584 * copy the frame out to userland. 585 */ 586 if (copyout((caddr_t)&sf, (caddr_t)sfp, sizeof(sf)) != 0) { 587 /* 588 * Process has trashed its stack. Kill it. 589 */ 590 CTR2(KTR_SIG, "sendsig: sigexit td=%p sfp=%p", td, sfp); 591 PROC_LOCK(p); 592 sigexit(td, SIGILL); 593 } 594 595 CTR3(KTR_SIG, "sendsig: return td=%p pc=%#x sp=%#x", td, 596 tf->srr0, tf->fixreg[1]); 597 598 PROC_LOCK(p); 599 } 600 601 /* 602 * Stub to satisfy the reference to osigreturn in the syscall table. This 603 * is needed even for newer arches that don't support old signals because 604 * the syscall table is machine-independent. 605 */ 606 int 607 osigreturn(struct thread *td, struct osigreturn_args *uap) 608 { 609 610 return (nosys(td, (struct nosys_args *)uap)); 611 } 612 613 int 614 sigreturn(struct thread *td, struct sigreturn_args *uap) 615 { 616 struct trapframe *tf; 617 struct proc *p; 618 ucontext_t uc; 619 620 CTR2(KTR_SIG, "sigreturn: td=%p ucp=%p", td, uap->sigcntxp); 621 622 if (copyin(uap->sigcntxp, &uc, sizeof(uc)) != 0) { 623 CTR1(KTR_SIG, "sigreturn: efault td=%p", td); 624 return (EFAULT); 625 } 626 627 /* 628 * Don't let the user set privileged MSR bits 629 */ 630 tf = td->td_frame; 631 if ((uc.uc_mcontext.mc_frame.srr1 & PSL_USERSTATIC) != 632 (tf->srr1 & PSL_USERSTATIC)) { 633 return (EINVAL); 634 } 635 636 /* 637 * Restore the user-supplied context 638 */ 639 memcpy(tf, &uc.uc_mcontext.mc_frame, sizeof(struct trapframe)); 640 641 p = td->td_proc; 642 PROC_LOCK(p); 643 p->p_sigmask = uc.uc_sigmask; 644 SIG_CANTMASK(p->p_sigmask); 645 signotify(p); 646 PROC_UNLOCK(p); 647 648 /* 649 * Restore FP state 650 */ 651 /* XXX */ 652 653 CTR3(KTR_SIG, "sigreturn: return td=%p pc=%#x sp=%#x", 654 td, tf->srr0, tf->fixreg[1]); 655 656 return (EJUSTRETURN); 657 } 658 659 void 660 cpu_boot(int howto) 661 { 662 } 663 664 /* 665 * Shutdown the CPU as much as possible. 666 */ 667 void 668 cpu_halt(void) 669 { 670 671 OF_exit(); 672 } 673 674 /* 675 * Set set up registers on exec. 676 */ 677 void 678 exec_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings) 679 { 680 struct trapframe *tf; 681 struct ps_strings arginfo; 682 683 tf = trapframe(td); 684 bzero(tf, sizeof *tf); 685 tf->fixreg[1] = -roundup(-stack + 8, 16); 686 687 /* 688 * XXX Machine-independent code has already copied arguments and 689 * XXX environment to userland. Get them back here. 690 */ 691 (void)copyin((char *)PS_STRINGS, &arginfo, sizeof(arginfo)); 692 693 /* 694 * Set up arguments for _start(): 695 * _start(argc, argv, envp, obj, cleanup, ps_strings); 696 * 697 * Notes: 698 * - obj and cleanup are the auxilliary and termination 699 * vectors. They are fixed up by ld.elf_so. 700 * - ps_strings is a NetBSD extention, and will be 701 * ignored by executables which are strictly 702 * compliant with the SVR4 ABI. 703 * 704 * XXX We have to set both regs and retval here due to different 705 * XXX calling convention in trap.c and init_main.c. 706 */ 707 /* 708 * XXX PG: these get overwritten in the syscall return code. 709 * execve() should return EJUSTRETURN, like it does on NetBSD. 710 * Emulate by setting the syscall return value cells. The 711 * registers still have to be set for init's fork trampoline. 712 */ 713 td->td_retval[0] = arginfo.ps_nargvstr; 714 td->td_retval[1] = (register_t)arginfo.ps_argvstr; 715 tf->fixreg[3] = arginfo.ps_nargvstr; 716 tf->fixreg[4] = (register_t)arginfo.ps_argvstr; 717 tf->fixreg[5] = (register_t)arginfo.ps_envstr; 718 tf->fixreg[6] = 0; /* auxillary vector */ 719 tf->fixreg[7] = 0; /* termination vector */ 720 tf->fixreg[8] = (register_t)PS_STRINGS; /* NetBSD extension */ 721 722 tf->srr0 = entry; 723 tf->srr1 = PSL_MBO | PSL_USERSET | PSL_FE_DFLT; 724 td->td_pcb->pcb_flags = 0; 725 } 726 727 #if !defined(DDB) 728 void 729 Debugger(const char *msg) 730 { 731 732 printf("Debugger(\"%s\") called.\n", msg); 733 } 734 #endif /* !defined(DDB) */ 735 736 /* XXX: dummy {fill,set}_[fp]regs */ 737 int 738 fill_regs(struct thread *td, struct reg *regs) 739 { 740 741 return (ENOSYS); 742 } 743 744 int 745 fill_dbregs(struct thread *td, struct dbreg *dbregs) 746 { 747 748 return (ENOSYS); 749 } 750 751 int 752 fill_fpregs(struct thread *td, struct fpreg *fpregs) 753 { 754 755 return (ENOSYS); 756 } 757 758 int 759 set_regs(struct thread *td, struct reg *regs) 760 { 761 762 return (ENOSYS); 763 } 764 765 int 766 set_dbregs(struct thread *td, struct dbreg *dbregs) 767 { 768 769 return (ENOSYS); 770 } 771 772 int 773 set_fpregs(struct thread *td, struct fpreg *fpregs) 774 { 775 776 return (ENOSYS); 777 } 778 779 int 780 ptrace_set_pc(struct thread *td, unsigned long addr) 781 { 782 783 /* XXX: coming soon... */ 784 return (ENOSYS); 785 } 786 787 int 788 ptrace_single_step(struct thread *td) 789 { 790 791 /* XXX: coming soon... */ 792 return (ENOSYS); 793 } 794 795 /* 796 * Initialise a struct pcpu. 797 */ 798 void 799 cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t sz) 800 { 801 802 pcpu->pc_current_asngen = 1; 803 } 804 805 /* 806 * kcopy(const void *src, void *dst, size_t len); 807 * 808 * Copy len bytes from src to dst, aborting if we encounter a fatal 809 * page fault. 810 * 811 * kcopy() _must_ save and restore the old fault handler since it is 812 * called by uiomove(), which may be in the path of servicing a non-fatal 813 * page fault. 814 */ 815 int 816 kcopy(const void *src, void *dst, size_t len) 817 { 818 struct thread *td; 819 faultbuf env, *oldfault; 820 int rv; 821 822 td = PCPU_GET(curthread); 823 oldfault = td->td_pcb->pcb_onfault; 824 if ((rv = setfault(env)) != 0) { 825 td->td_pcb->pcb_onfault = oldfault; 826 return rv; 827 } 828 829 memcpy(dst, src, len); 830 831 td->td_pcb->pcb_onfault = oldfault; 832 return (0); 833 } 834