From owner-svn-src-projects@FreeBSD.ORG Sun Nov 15 07:28:38 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 922A2106566B; Sun, 15 Nov 2009 07:28:38 +0000 (UTC) (envelope-from nwhitehorn@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 7EC288FC08; Sun, 15 Nov 2009 07:28:38 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nAF7ScsP027479; Sun, 15 Nov 2009 07:28:38 GMT (envelope-from nwhitehorn@svn.freebsd.org) Received: (from nwhitehorn@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nAF7ScQI027463; Sun, 15 Nov 2009 07:28:38 GMT (envelope-from nwhitehorn@svn.freebsd.org) Message-Id: <200911150728.nAF7ScQI027463@svn.freebsd.org> From: Nathan Whitehorn Date: Sun, 15 Nov 2009 07:28:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r199286 - in projects/ppc64/sys: conf powerpc/aim powerpc/include powerpc/powerpc powerpc64/conf X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Nov 2009 07:28:38 -0000 Author: nwhitehorn Date: Sun Nov 15 07:28:37 2009 New Revision: 199286 URL: http://svn.freebsd.org/changeset/base/199286 Log: First hash at 32-bit binary compatibility on PowerPC. This gets init almost running (it dies with an malloc assertion failure eventually). This commit almost certainly breaks Book-E. Added: projects/ppc64/sys/powerpc/powerpc/elf32_machdep.c - copied, changed from r198415, projects/ppc64/sys/powerpc/powerpc/elf_machdep.c projects/ppc64/sys/powerpc/powerpc/exec_machdep.c Deleted: projects/ppc64/sys/powerpc/powerpc/elf_machdep.c Modified: projects/ppc64/sys/conf/files.powerpc projects/ppc64/sys/conf/files.powerpc64 projects/ppc64/sys/conf/options.powerpc64 projects/ppc64/sys/powerpc/aim/machdep.c projects/ppc64/sys/powerpc/aim/trap.c projects/ppc64/sys/powerpc/aim/trap_subr64.S projects/ppc64/sys/powerpc/include/elf.h projects/ppc64/sys/powerpc/include/reg.h projects/ppc64/sys/powerpc/include/ucontext.h projects/ppc64/sys/powerpc/include/vmparam.h projects/ppc64/sys/powerpc/powerpc/db_trace.c projects/ppc64/sys/powerpc/powerpc/stack_machdep.c projects/ppc64/sys/powerpc/powerpc/sys_machdep.c projects/ppc64/sys/powerpc64/conf/GENERIC Modified: projects/ppc64/sys/conf/files.powerpc ============================================================================== --- projects/ppc64/sys/conf/files.powerpc Sun Nov 15 07:25:24 2009 (r199285) +++ projects/ppc64/sys/conf/files.powerpc Sun Nov 15 07:28:37 2009 (r199286) @@ -154,7 +154,8 @@ powerpc/powerpc/db_hwwatch.c optional dd powerpc/powerpc/db_interface.c optional ddb powerpc/powerpc/db_trace.c optional ddb powerpc/powerpc/dump_machdep.c standard -powerpc/powerpc/elf_machdep.c standard +powerpc/powerpc/elf32_machdep.c standard +powerpc/powerpc/exec_machdep.c standard powerpc/powerpc/fpu.c optional aim powerpc/powerpc/fuswintr.c standard powerpc/powerpc/gdb_machdep.c optional gdb Modified: projects/ppc64/sys/conf/files.powerpc64 ============================================================================== --- projects/ppc64/sys/conf/files.powerpc64 Sun Nov 15 07:25:24 2009 (r199285) +++ projects/ppc64/sys/conf/files.powerpc64 Sun Nov 15 07:28:37 2009 (r199286) @@ -107,7 +107,9 @@ powerpc/powerpc/db_hwwatch.c optional dd powerpc/powerpc/db_interface.c optional ddb powerpc/powerpc/db_trace.c optional ddb powerpc/powerpc/dump_machdep.c standard +powerpc/powerpc/elf32_machdep.c optional compat_freebsd32 powerpc/powerpc/elf64_machdep.c standard +powerpc/powerpc/exec_machdep.c standard powerpc/powerpc/fpu.c optional aim powerpc/powerpc/fuswintr.c standard powerpc/powerpc/gdb_machdep.c optional gdb @@ -129,3 +131,10 @@ powerpc/powerpc/suswintr.c standard powerpc/powerpc/syncicache.c standard powerpc/powerpc/sys_machdep.c standard powerpc/powerpc/uio_machdep.c standard + +compat/freebsd32/freebsd32_ioctl.c optional compat_freebsd32 +compat/freebsd32/freebsd32_misc.c optional compat_freebsd32 +compat/freebsd32/freebsd32_syscalls.c optional compat_freebsd32 +compat/freebsd32/freebsd32_sysent.c optional compat_freebsd32 +kern/imgact_elf32.c optional compat_ppc32 + Modified: projects/ppc64/sys/conf/options.powerpc64 ============================================================================== --- projects/ppc64/sys/conf/options.powerpc64 Sun Nov 15 07:25:24 2009 (r199285) +++ projects/ppc64/sys/conf/options.powerpc64 Sun Nov 15 07:28:37 2009 (r199286) @@ -6,6 +6,9 @@ E500 opt_global.h CELL MAMBO +COMPAT_PPC32 opt_compat.h +COMPAT_FREEBSD32 opt_compat.h + GFB_DEBUG opt_gfb.h GFB_NO_FONT_LOADING opt_gfb.h GFB_NO_MODE_CHANGE opt_gfb.h Modified: projects/ppc64/sys/powerpc/aim/machdep.c ============================================================================== --- projects/ppc64/sys/powerpc/aim/machdep.c Sun Nov 15 07:25:24 2009 (r199285) +++ projects/ppc64/sys/powerpc/aim/machdep.c Sun Nov 15 07:28:37 2009 (r199286) @@ -158,7 +158,6 @@ SYSCTL_INT(_machdep, CPU_CACHELINE, cach CTLFLAG_RD, &cacheline_size, 0, ""); uintptr_t powerpc_init(vm_offset_t, vm_offset_t, vm_offset_t, void *); -static int grab_mcontext(struct thread *, mcontext_t *, int); int setfault(faultbuf); /* defined in locore.S */ void asm_panic(char *); @@ -597,295 +596,6 @@ bzero(void *buf, size_t len) } void -sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask) -{ - struct trapframe *tf; - struct sigframe *sfp; - struct sigacts *psp; - struct sigframe sf; - struct thread *td; - struct proc *p; - int oonstack, rndfsize; - int sig; - int code; - - td = curthread; - p = td->td_proc; - PROC_LOCK_ASSERT(p, MA_OWNED); - sig = ksi->ksi_signo; - code = ksi->ksi_code; - psp = p->p_sigacts; - mtx_assert(&psp->ps_mtx, MA_OWNED); - tf = td->td_frame; - oonstack = sigonstack(tf->fixreg[1]); - - rndfsize = ((sizeof(sf) + 15) / 16) * 16; - - CTR4(KTR_SIG, "sendsig: td=%p (%s) catcher=%p sig=%d", td, p->p_comm, - catcher, sig); - - /* - * Save user context - */ - memset(&sf, 0, sizeof(sf)); - grab_mcontext(td, &sf.sf_uc.uc_mcontext, 0); - sf.sf_uc.uc_sigmask = *mask; - sf.sf_uc.uc_stack = td->td_sigstk; - sf.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK) - ? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE; - - sf.sf_uc.uc_mcontext.mc_onstack = (oonstack) ? 1 : 0; - - /* - * Allocate and validate space for the signal handler context. - */ - if ((td->td_pflags & TDP_ALTSTACK) != 0 && !oonstack && - SIGISMEMBER(psp->ps_sigonstack, sig)) { - sfp = (struct sigframe *)(td->td_sigstk.ss_sp + - td->td_sigstk.ss_size - rndfsize); - } else { - sfp = (struct sigframe *)(tf->fixreg[1] - rndfsize); - } - - /* - * Translate the signal if appropriate (Linux emu ?) - */ - if (p->p_sysent->sv_sigtbl && sig <= p->p_sysent->sv_sigsize) - sig = p->p_sysent->sv_sigtbl[_SIG_IDX(sig)]; - - /* - * Save the floating-point state, if necessary, then copy it. - */ - /* XXX */ - - /* - * Set up the registers to return to sigcode. - * - * r1/sp - sigframe ptr - * lr - sig function, dispatched to by blrl in trampoline - * r3 - sig number - * r4 - SIGINFO ? &siginfo : exception code - * r5 - user context - * srr0 - trampoline function addr - */ - tf->lr = (register_t)catcher; - tf->fixreg[1] = (register_t)sfp; - tf->fixreg[FIRSTARG] = sig; - tf->fixreg[FIRSTARG+2] = (register_t)&sfp->sf_uc; - if (SIGISMEMBER(psp->ps_siginfo, sig)) { - /* - * Signal handler installed with SA_SIGINFO. - */ - tf->fixreg[FIRSTARG+1] = (register_t)&sfp->sf_si; - - /* - * Fill siginfo structure. - */ - sf.sf_si = ksi->ksi_info; - sf.sf_si.si_signo = sig; - sf.sf_si.si_addr = (void *)((tf->exc == EXC_DSI) ? - tf->cpu.aim.dar : tf->srr0); - } else { - /* Old FreeBSD-style arguments. */ - tf->fixreg[FIRSTARG+1] = code; - tf->fixreg[FIRSTARG+3] = (tf->exc == EXC_DSI) ? - tf->cpu.aim.dar : tf->srr0; - } - mtx_unlock(&psp->ps_mtx); - PROC_UNLOCK(p); - - tf->srr0 = (register_t)(PS_STRINGS - *(p->p_sysent->sv_szsigcode)); - - /* - * copy the frame out to userland. - */ - if (copyout(&sf, sfp, sizeof(*sfp)) != 0) { - /* - * Process has trashed its stack. Kill it. - */ - CTR2(KTR_SIG, "sendsig: sigexit td=%p sfp=%p", td, sfp); - PROC_LOCK(p); - sigexit(td, SIGILL); - } - - CTR3(KTR_SIG, "sendsig: return td=%p pc=%#x sp=%#x", td, - tf->srr0, tf->fixreg[1]); - - PROC_LOCK(p); - mtx_lock(&psp->ps_mtx); -} - -int -sigreturn(struct thread *td, struct sigreturn_args *uap) -{ - ucontext_t uc; - int error; - - CTR2(KTR_SIG, "sigreturn: td=%p ucp=%p", td, uap->sigcntxp); - - if (copyin(uap->sigcntxp, &uc, sizeof(uc)) != 0) { - CTR1(KTR_SIG, "sigreturn: efault td=%p", td); - return (EFAULT); - } - - error = set_mcontext(td, &uc.uc_mcontext); - if (error != 0) - return (error); - - kern_sigprocmask(td, SIG_SETMASK, &uc.uc_sigmask, NULL, 0); - - CTR3(KTR_SIG, "sigreturn: return td=%p pc=%#x sp=%#x", - td, uc.uc_mcontext.mc_srr0, uc.uc_mcontext.mc_gpr[1]); - - return (EJUSTRETURN); -} - -#ifdef COMPAT_FREEBSD4 -int -freebsd4_sigreturn(struct thread *td, struct freebsd4_sigreturn_args *uap) -{ - - return sigreturn(td, (struct sigreturn_args *)uap); -} -#endif - -/* - * Construct a PCB from a trapframe. This is called from kdb_trap() where - * we want to start a backtrace from the function that caused us to enter - * the debugger. We have the context in the trapframe, but base the trace - * on the PCB. The PCB doesn't have to be perfect, as long as it contains - * enough for a backtrace. - */ -void -makectx(struct trapframe *tf, struct pcb *pcb) -{ - - pcb->pcb_lr = tf->srr0; - pcb->pcb_sp = tf->fixreg[1]; -} - -/* - * get_mcontext/sendsig helper routine that doesn't touch the - * proc lock - */ -static int -grab_mcontext(struct thread *td, mcontext_t *mcp, int flags) -{ - struct pcb *pcb; - - pcb = td->td_pcb; - - memset(mcp, 0, sizeof(mcontext_t)); - - mcp->mc_vers = _MC_VERSION; - mcp->mc_flags = 0; - memcpy(&mcp->mc_frame, td->td_frame, sizeof(struct trapframe)); - if (flags & GET_MC_CLEAR_RET) { - mcp->mc_gpr[3] = 0; - mcp->mc_gpr[4] = 0; - } - - /* - * This assumes that floating-point context is *not* lazy, - * so if the thread has used FP there would have been a - * FP-unavailable exception that would have set things up - * correctly. - */ - if (pcb->pcb_flags & PCB_FPU) { - KASSERT(td == curthread, - ("get_mcontext: fp save not curthread")); - critical_enter(); - save_fpu(td); - critical_exit(); - mcp->mc_flags |= _MC_FP_VALID; - memcpy(&mcp->mc_fpscr, &pcb->pcb_fpu.fpscr, sizeof(double)); - memcpy(mcp->mc_fpreg, pcb->pcb_fpu.fpr, 32*sizeof(double)); - } - - /* - * Repeat for Altivec context - */ - - if (pcb->pcb_flags & PCB_VEC) { - KASSERT(td == curthread, - ("get_mcontext: fp save not curthread")); - critical_enter(); - save_vec(td); - critical_exit(); - mcp->mc_flags |= _MC_AV_VALID; - mcp->mc_vscr = pcb->pcb_vec.vscr; - mcp->mc_vrsave = pcb->pcb_vec.vrsave; - memcpy(mcp->mc_avec, pcb->pcb_vec.vr, sizeof(mcp->mc_avec)); - } - - mcp->mc_len = sizeof(*mcp); - - return (0); -} - -int -get_mcontext(struct thread *td, mcontext_t *mcp, int flags) -{ - int error; - - error = grab_mcontext(td, mcp, flags); - if (error == 0) { - PROC_LOCK(curthread->td_proc); - mcp->mc_onstack = sigonstack(td->td_frame->fixreg[1]); - PROC_UNLOCK(curthread->td_proc); - } - - return (error); -} - -int -set_mcontext(struct thread *td, const mcontext_t *mcp) -{ - struct pcb *pcb; - struct trapframe *tf; - - pcb = td->td_pcb; - tf = td->td_frame; - - if (mcp->mc_vers != _MC_VERSION || - mcp->mc_len != sizeof(*mcp)) - return (EINVAL); - - /* - * Don't let the user set privileged MSR bits - */ - if ((mcp->mc_srr1 & PSL_USERSTATIC) != (tf->srr1 & PSL_USERSTATIC)) { - return (EINVAL); - } - - memcpy(tf, mcp->mc_frame, sizeof(mcp->mc_frame)); - - if (mcp->mc_flags & _MC_FP_VALID) { - if ((pcb->pcb_flags & PCB_FPU) != PCB_FPU) { - critical_enter(); - enable_fpu(td); - critical_exit(); - } - memcpy(&pcb->pcb_fpu.fpscr, &mcp->mc_fpscr, sizeof(double)); - memcpy(pcb->pcb_fpu.fpr, mcp->mc_fpreg, 32*sizeof(double)); - } - - if (mcp->mc_flags & _MC_AV_VALID) { - if ((pcb->pcb_flags & PCB_VEC) != PCB_VEC) { - critical_enter(); - enable_vec(td); - critical_exit(); - } - pcb->pcb_vec.vscr = mcp->mc_vscr; - pcb->pcb_vec.vrsave = mcp->mc_vrsave; - memcpy(pcb->pcb_vec.vr, mcp->mc_avec, sizeof(mcp->mc_avec)); - } - - - return (0); -} - -void cpu_boot(int howto) { } @@ -965,142 +675,6 @@ cpu_idle_wakeup(int cpu) return (0); } -/* - * Set set up registers on exec. - */ -void -exec_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings) -{ - struct trapframe *tf; - struct ps_strings arginfo; - #ifdef __powerpc64__ - register_t entry_desc[3]; - #endif - - tf = trapframe(td); - bzero(tf, sizeof *tf); - tf->fixreg[1] = -roundup(-stack + 8, 16); - - /* - * XXX Machine-independent code has already copied arguments and - * XXX environment to userland. Get them back here. - */ - (void)copyin((char *)PS_STRINGS, &arginfo, sizeof(arginfo)); - - /* - * Set up arguments for _start(): - * _start(argc, argv, envp, obj, cleanup, ps_strings); - * - * Notes: - * - obj and cleanup are the auxilliary and termination - * vectors. They are fixed up by ld.elf_so. - * - ps_strings is a NetBSD extention, and will be - * ignored by executables which are strictly - * compliant with the SVR4 ABI. - * - * XXX We have to set both regs and retval here due to different - * XXX calling convention in trap.c and init_main.c. - */ - /* - * XXX PG: these get overwritten in the syscall return code. - * execve() should return EJUSTRETURN, like it does on NetBSD. - * Emulate by setting the syscall return value cells. The - * registers still have to be set for init's fork trampoline. - */ - td->td_retval[0] = arginfo.ps_nargvstr; - td->td_retval[1] = (register_t)arginfo.ps_argvstr; - tf->fixreg[3] = arginfo.ps_nargvstr; - tf->fixreg[4] = (register_t)arginfo.ps_argvstr; - tf->fixreg[5] = (register_t)arginfo.ps_envstr; - tf->fixreg[6] = 0; /* auxillary vector */ - tf->fixreg[7] = 0; /* termination vector */ - tf->fixreg[8] = (register_t)PS_STRINGS; /* NetBSD extension */ - - #ifdef __powerpc64__ - /* - * For 64-bit, we need to disentangle the function descriptor - * - * 0. entry point - * 1. TOC value (r2) - * 2. Environment pointer (r11) - */ - - (void)copyin((void *)entry, entry_desc, sizeof(entry_desc)); - tf->srr0 = entry_desc[0]; - tf->fixreg[2] = entry_desc[1]; - tf->fixreg[11] = entry_desc[2]; - tf->srr1 = PSL_SF | PSL_MBO | PSL_USERSET | PSL_FE_DFLT; - #else - tf->srr0 = entry; - tf->srr1 = PSL_MBO | PSL_USERSET | PSL_FE_DFLT; - #endif - td->td_pcb->pcb_flags = 0; -} - -int -fill_regs(struct thread *td, struct reg *regs) -{ - struct trapframe *tf; - - tf = td->td_frame; - memcpy(regs, tf, sizeof(struct reg)); - - return (0); -} - -int -fill_dbregs(struct thread *td, struct dbreg *dbregs) -{ - /* No debug registers on PowerPC */ - return (ENOSYS); -} - -int -fill_fpregs(struct thread *td, struct fpreg *fpregs) -{ - struct pcb *pcb; - - pcb = td->td_pcb; - - if ((pcb->pcb_flags & PCB_FPU) == 0) - memset(fpregs, 0, sizeof(struct fpreg)); - else - memcpy(fpregs, &pcb->pcb_fpu, sizeof(struct fpreg)); - - return (0); -} - -int -set_regs(struct thread *td, struct reg *regs) -{ - struct trapframe *tf; - - tf = td->td_frame; - memcpy(tf, regs, sizeof(struct reg)); - - return (0); -} - -int -set_dbregs(struct thread *td, struct dbreg *dbregs) -{ - /* No debug registers on PowerPC */ - return (ENOSYS); -} - -int -set_fpregs(struct thread *td, struct fpreg *fpregs) -{ - struct pcb *pcb; - - pcb = td->td_pcb; - if ((pcb->pcb_flags & PCB_FPU) == 0) - enable_fpu(td); - memcpy(&pcb->pcb_fpu, fpregs, sizeof(struct fpreg)); - - return (0); -} - int ptrace_set_pc(struct thread *td, unsigned long addr) { Modified: projects/ppc64/sys/powerpc/aim/trap.c ============================================================================== --- projects/ppc64/sys/powerpc/aim/trap.c Sun Nov 15 07:25:24 2009 (r199285) +++ projects/ppc64/sys/powerpc/aim/trap.c Sun Nov 15 07:28:37 2009 (r199286) @@ -357,9 +357,9 @@ syscall(struct trapframe *frame) struct sysent *callp; struct thread *td; struct proc *p; - int error, n; - size_t narg; - register_t args[10]; + int error, n, i; + size_t narg, argsz; + u_register_t args[10]; u_int code; td = PCPU_GET(curthread); @@ -371,6 +371,11 @@ syscall(struct trapframe *frame) params = (caddr_t)(frame->fixreg + FIRSTARG); n = NARGREG; + if (p->p_sysent->sv_flags & SV_ILP32) + argsz = sizeof(uint32_t); + else + argsz = sizeof(uint64_t); + if (p->p_sysent->sv_prepsyscall) { /* * The prep code is MP aware. @@ -382,7 +387,7 @@ syscall(struct trapframe *frame) * code is first argument, * followed by actual args. */ - code = *(u_int *) params; + code = *(register_t *) params; params += sizeof(register_t); n -= 1; } else if (code == SYS___syscall) { @@ -391,10 +396,16 @@ syscall(struct trapframe *frame) * so as to maintain quad alignment * for the rest of the args. */ - params += sizeof(register_t); - code = *(u_int *) params; - params += sizeof(register_t); - n -= 2; + if (p->p_sysent->sv_flags & SV_ILP32) { + params += sizeof(register_t); + code = *(register_t *) params; + params += sizeof(register_t); + n -= 2; + } else { + code = *(register_t *) params; + params += sizeof(register_t); + n -= 1; + } } if (p->p_sysent->sv_mask) @@ -407,23 +418,27 @@ syscall(struct trapframe *frame) narg = callp->sy_narg; - if (narg > n) { - bcopy(params, args, n * sizeof(register_t)); + if (p->p_sysent->sv_flags & SV_ILP32) { + for (i = 0; i < n; i++) + args[i] = ((u_register_t *)(params))[i] & 0xffffffff; + } else { + for (i = 0; i < n; i++) + args[i] = ((u_register_t *)(params))[i]; + } + + if (narg > n) error = copyin(MOREARGS(frame->fixreg[1]), args + n, - (narg - n) * sizeof(register_t)); - params = (caddr_t)args; - } else + (narg - n) * argsz); + else error = 0; CTR5(KTR_SYSC, "syscall: p=%s %s(%x %x %x)", td->td_name, syscallnames[code], - frame->fixreg[FIRSTARG], - frame->fixreg[FIRSTARG+1], - frame->fixreg[FIRSTARG+2]); + args[0], args[1], args[2]); #ifdef KTRACE if (KTRPOINT(td, KTR_SYSCALL)) - ktrsyscall(code, narg, (register_t *)params); + ktrsyscall(code, narg, args); #endif td->td_syscalls++; @@ -437,7 +452,7 @@ syscall(struct trapframe *frame) PTRACESTOP_SC(p, td, S_PT_SCE); AUDIT_SYSCALL_ENTER(code, td); - error = (*callp->sy_call)(td, params); + error = (*callp->sy_call)(td, args); AUDIT_SYSCALL_EXIT(error, td); CTR3(KTR_SYSC, "syscall: p=%s %s ret=%x", td->td_name, Modified: projects/ppc64/sys/powerpc/aim/trap_subr64.S ============================================================================== --- projects/ppc64/sys/powerpc/aim/trap_subr64.S Sun Nov 15 07:25:24 2009 (r199285) +++ projects/ppc64/sys/powerpc/aim/trap_subr64.S Sun Nov 15 07:28:37 2009 (r199286) @@ -418,7 +418,11 @@ realtrap: bf 17,k_trap /* branch if PSL_PR is false */ GET_CPUINFO(%r1) ld %r1,PC_CURPCB(%r1) + mr %r27,%r28 /* Save LR, r29 */ + mtsprg2 %r29 RESTORE_KERN_SRS() /* enable kernel mapping */ + mfsprg2 %r29 + mr %r28,%r27 ba s_trap /* @@ -462,7 +466,11 @@ s_trap: GET_CPUINFO(%r1) u_trap: ld %r1,PC_CURPCB(%r1) + mr %r27,%r28 /* Save LR, r29 */ + mtsprg2 %r29 RESTORE_KERN_SRS() /* enable kernel mapping */ + mfsprg2 %r29 + mr %r28,%r27 /* * Now the common trap catching code. Modified: projects/ppc64/sys/powerpc/include/elf.h ============================================================================== --- projects/ppc64/sys/powerpc/include/elf.h Sun Nov 15 07:25:24 2009 (r199285) +++ projects/ppc64/sys/powerpc/include/elf.h Sun Nov 15 07:28:37 2009 (r199286) @@ -126,4 +126,40 @@ __ElfType(Auxinfo); #define ET_DYN_LOAD_ADDR 0x01010000 +/* + * Define some bits needed for 32-bit compatibility. + */ + +#if defined(_KERNEL) && defined(__powerpc64__) +#include +#include + +#include "opt_compat.h" + +#ifdef COMPAT_PPC32 +/* + * Alternative layouts for + * Used in core dumps, the reason for this file existing. + */ +struct prstatus32 { + int pr_version; + u_int pr_statussz; + u_int pr_gregsetsz; + u_int pr_fpregsetsz; + int pr_osreldate; + int pr_cursig; + pid_t pr_pid; + struct reg32 pr_reg; +}; + +struct prpsinfo32 { + int pr_version; + u_int pr_psinfosz; + char pr_fname[PRFNAMESZ+1]; + char pr_psargs[PRARGSZ+1]; +}; +#endif + +#endif + #endif /* !_MACHINE_ELF_H_ */ Modified: projects/ppc64/sys/powerpc/include/reg.h ============================================================================== --- projects/ppc64/sys/powerpc/include/reg.h Sun Nov 15 07:25:24 2009 (r199285) +++ projects/ppc64/sys/powerpc/include/reg.h Sun Nov 15 07:28:37 2009 (r199286) @@ -4,6 +4,10 @@ #ifndef _POWERPC_REG_H_ #define _POWERPC_REG_H_ +#ifdef _KERNEL +#include "opt_compat.h" +#endif + /* Must match struct trapframe */ struct reg { register_t fixreg[32]; @@ -21,9 +25,29 @@ struct fpreg { }; struct dbreg { - unsigned long junk; + unsigned int junk; +}; + +#ifdef COMPAT_PPC32 +/* Must match struct trapframe */ +struct reg32 { + int32_t fixreg[32]; + int32_t lr; + int32_t cr; + int32_t xer; + int32_t ctr; + int32_t pc; +}; + +struct fpreg32 { + struct fpreg data; }; +struct dbreg32 { + struct dbreg data; +}; +#endif + #ifdef _KERNEL /* * XXX these interfaces are MI, so they should be declared in a MI place. @@ -34,6 +58,18 @@ int fill_fpregs(struct thread *, struct int set_fpregs(struct thread *, struct fpreg *); int fill_dbregs(struct thread *, struct dbreg *); int set_dbregs(struct thread *, struct dbreg *); + +#ifdef COMPAT_PPC32 +int fill_regs32(struct thread *, struct reg32 *); +int set_regs32(struct thread *, struct reg32 *); +void ppc32_setregs(struct thread *, u_long, u_long, u_long); + +#define fill_fpregs32(td, reg) fill_fpregs(td,(struct fpreg *)reg) +#define set_fpregs32(td, reg) set_fpregs(td,(struct fpreg *)reg) +#define fill_dbregs32(td, reg) fill_dbregs(td,(struct dbreg *)reg) +#define set_dbregs32(td, reg) set_dbregs(td,(struct dbreg *)reg) +#endif + #endif #endif /* _POWERPC_REG_H_ */ Modified: projects/ppc64/sys/powerpc/include/ucontext.h ============================================================================== --- projects/ppc64/sys/powerpc/include/ucontext.h Sun Nov 15 07:25:24 2009 (r199285) +++ projects/ppc64/sys/powerpc/include/ucontext.h Sun Nov 15 07:28:37 2009 (r199286) @@ -48,6 +48,21 @@ typedef struct __mcontext { uint64_t mc_fpreg[33]; } mcontext_t __aligned(16); +#if defined(_KERNEL) && defined(__powerpc64__) +typedef struct __mcontext32 { + int mc_vers; + int mc_flags; +#define _MC_FP_VALID 0x01 +#define _MC_AV_VALID 0x02 + int mc_onstack; /* saved onstack flag */ + int mc_len; /* sizeof(__mcontext) */ + uint64_t mc_avec[32*2]; /* vector register file */ + uint32_t mc_av[2]; + uint32_t mc_frame[42]; + uint64_t mc_fpreg[33]; +} mcontext32_t __aligned(16); +#endif + /* GPRs and supervisor-level regs */ #define mc_gpr mc_frame #define mc_lr mc_frame[32] Modified: projects/ppc64/sys/powerpc/include/vmparam.h ============================================================================== --- projects/ppc64/sys/powerpc/include/vmparam.h Sun Nov 15 07:25:24 2009 (r199285) +++ projects/ppc64/sys/powerpc/include/vmparam.h Sun Nov 15 07:28:37 2009 (r199286) @@ -91,6 +91,7 @@ #endif /* LOCORE */ #define VM_MAX_ADDRESS VM_MAXUSER_ADDRESS +#define FREEBSD32_USRSTACK 0x7ffff000 #if defined(AIM) /* AIM */ Modified: projects/ppc64/sys/powerpc/powerpc/db_trace.c ============================================================================== --- projects/ppc64/sys/powerpc/powerpc/db_trace.c Sun Nov 15 07:25:24 2009 (r199285) +++ projects/ppc64/sys/powerpc/powerpc/db_trace.c Sun Nov 15 07:28:37 2009 (r199286) @@ -53,6 +53,12 @@ static db_varfcn_t db_frame; #define DB_OFFSET(x) (db_expr_t *)offsetof(struct trapframe, x) +#ifdef __powerpc64__ +#define CALLOFFSET 8 /* Include TOC reload slot */ +#else +#define CALLOFFSET 4 +#endif + struct db_variable db_regs[] = { { "r0", DB_OFFSET(fixreg[0]), db_frame }, { "r1", DB_OFFSET(fixreg[1]), db_frame }, @@ -205,11 +211,10 @@ db_backtrace(struct thread *td, db_addr_ * to determine if the callframe has to traverse a saved * trap context */ - if ((lr + 4 == (db_addr_t) &trapexit) || - (lr + 4 == (db_addr_t) &asttrapexit)) { + if ((lr + CALLOFFSET == (db_addr_t) &trapexit) || + (lr + CALLOFFSET == (db_addr_t) &asttrapexit)) { const char *trapstr; - struct trapframe *tf = (struct trapframe *) - (stackframe+8); + struct trapframe *tf = (struct trapframe *)(args); db_printf("%s ", tf->srr1 & PSL_PR ? "user" : "kernel"); switch (tf->exc) { case EXC_DSI: Copied and modified: projects/ppc64/sys/powerpc/powerpc/elf32_machdep.c (from r198415, projects/ppc64/sys/powerpc/powerpc/elf_machdep.c) ============================================================================== --- projects/ppc64/sys/powerpc/powerpc/elf_machdep.c Fri Oct 23 16:07:15 2009 (r198415, copy source) +++ projects/ppc64/sys/powerpc/powerpc/elf32_machdep.c Sun Nov 15 07:28:37 2009 (r199286) @@ -28,6 +28,9 @@ #include #include #include + +#define __ELF_WORD_SIZE 32 + #include #include #include @@ -46,11 +49,21 @@ #include #include +#include #include +#ifdef __powerpc64__ +#include +#include +#endif + struct sysentvec elf32_freebsd_sysvec = { .sv_size = SYS_MAXSYSCALL, +#ifdef __powerpc64__ + .sv_table = freebsd32_sysent, +#else .sv_table = sysent, +#endif .sv_mask = 0, .sv_sigsize = 0, .sv_sigtbl = NULL, @@ -72,8 +85,13 @@ struct sysentvec elf32_freebsd_sysvec = .sv_usrstack = USRSTACK, .sv_psstrings = PS_STRINGS, .sv_stackprot = VM_PROT_ALL, +#ifdef __powerpc64__ + .sv_copyout_strings = freebsd32_copyout_strings, + .sv_setregs = ppc32_setregs, +#else .sv_copyout_strings = exec_copyout_strings, .sv_setregs = exec_setregs, +#endif .sv_fixlimit = NULL, .sv_maxssiz = NULL, .sv_flags = SV_ABI_FREEBSD | SV_ILP32 @@ -111,14 +129,13 @@ SYSINIT(oelf32, SI_SUB_EXEC, SI_ORDER_AN (sysinit_cfunc_t) elf32_insert_brand_entry, &freebsd_brand_oinfo); - void elf32_dump_thread(struct thread *td __unused, void *dst __unused, size_t *off __unused) { } - +#ifndef __powerpc64__ /* Process one elf relocation with addend. */ static int elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data, @@ -137,8 +154,8 @@ elf_reloc_internal(linker_file_t lf, Elf break; case ELF_RELOC_RELA: rela = (const Elf_Rela *)data; - where = (Elf_Addr *) (relocbase + rela->r_offset); - hwhere = (Elf_Half *) (relocbase + rela->r_offset); + where = (Elf_Addr *) ((uintptr_t)relocbase + rela->r_offset); + hwhere = (Elf_Half *) ((uintptr_t)relocbase + rela->r_offset); addend = rela->r_addend; rtype = ELF_R_TYPE(rela->r_info); symidx = ELF_R_SYM(rela->r_info); @@ -236,3 +253,4 @@ elf_cpu_unload_file(linker_file_t lf __u return (0); } +#endif Added: projects/ppc64/sys/powerpc/powerpc/exec_machdep.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/ppc64/sys/powerpc/powerpc/exec_machdep.c Sun Nov 15 07:28:37 2009 (r199286) @@ -0,0 +1,758 @@ +/*- + * Copyright (C) 1995, 1996 Wolfgang Solfrank. + * Copyright (C) 1995, 1996 TooLs GmbH. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by TooLs GmbH. + * 4. The name of TooLs GmbH may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/*- + * Copyright (C) 2001 Benno Rice + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * $NetBSD: machdep.c,v 1.74.2.1 2000/11/01 16:13:48 tv Exp $ + */ + +#include +__FBSDID("$FreeBSD: projects/ppc64/sys/powerpc/aim/machdep.c 198753 2009-11-01 16:54:20Z nwhitehorn $"); + +#include "opt_compat.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef COMPAT_FREEBSD32 +#include +#include +#include +#endif + +static int grab_mcontext(struct thread *, mcontext_t *, int); + +void +sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask) +{ + struct trapframe *tf; + struct sigframe *sfp; + struct sigacts *psp; + struct sigframe sf; + struct thread *td; + struct proc *p; + int oonstack, rndfsize; + int sig; + int code; + + td = curthread; + p = td->td_proc; + PROC_LOCK_ASSERT(p, MA_OWNED); + sig = ksi->ksi_signo; + code = ksi->ksi_code; + psp = p->p_sigacts; + mtx_assert(&psp->ps_mtx, MA_OWNED); + tf = td->td_frame; + oonstack = sigonstack(tf->fixreg[1]); *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***