Add the netbsd32 MD bits for sparc64 and amd64 to support SA.

Many thanks to all who helped for that little project, notably Martin
Husemann for teaching me a bit about the very special sparc64 world.
This commit is contained in:
cube 2006-03-29 23:07:49 +00:00
parent 69a77971a8
commit 473e9e89bf
5 changed files with 73 additions and 26 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: netbsd32_machdep.c,v 1.21 2006/03/12 20:25:25 cube Exp $ */
/* $NetBSD: netbsd32_machdep.c,v 1.22 2006/03/29 23:07:50 cube Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.21 2006/03/12 20:25:25 cube Exp $");
__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.22 2006/03/29 23:07:50 cube Exp $");
#include "opt_compat_netbsd.h"
#include "opt_execfmt.h"
@ -931,6 +931,42 @@ check_mcontext32(const mcontext32_t *mcp, struct trapframe *tf)
return 0;
}
void
netbsd32_cpu_upcall(struct lwp *l, int type, int nevents, int ninterrupted,
void *sas, void *ap, void *sp, sa_upcall_t upcall)
{
struct trapframe *tf;
struct netbsd32_saframe *sf, frame;
tf = l->l_md.md_regs;
frame.sa_type = type;
frame.sa_sas = (uintptr_t)sas;
frame.sa_events = nevents;
frame.sa_interrupted = ninterrupted;
frame.sa_arg = (uintptr_t)ap;
frame.sa_ra = 0;
sf = (struct netbsd32_saframe *)sp - 1;
if (copyout(&frame, sf, sizeof(frame)) != 0) {
sigexit(l, SIGILL);
/* NOTREACHED */
}
tf->tf_rip = (uintptr_t)upcall;
tf->tf_rsp = (uintptr_t)sf;
tf->tf_rbp = 0;
tf->tf_gs = GSEL(GUDATA32_SEL, SEL_UPL);
tf->tf_fs = GSEL(GUDATA32_SEL, SEL_UPL);
tf->tf_es = GSEL(GUDATA32_SEL, SEL_UPL);
tf->tf_ds = GSEL(GUDATA32_SEL, SEL_UPL);
tf->tf_cs = GSEL(GUCODE32_SEL, SEL_UPL);
tf->tf_ss = GSEL(GUDATA32_SEL, SEL_UPL);
tf->tf_rflags &= ~(PSL_T|PSL_VM|PSL_AC);
l->l_md.md_flags |= MDP_IRET;
}
vaddr_t
netbsd32_vm_default_addr(struct proc *p, vaddr_t base, vsize_t size)
{

View File

@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.7 2005/12/11 12:16:25 christos Exp $ */
/* $NetBSD: mcontext.h,v 1.8 2006/03/29 23:07:50 cube Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@ -138,6 +138,8 @@ typedef __greg32_t __gregset32_t[_NGREG32];
#define _REG32_UESP 17
#define _REG32_SS 18
#define _UC_MACHINE32_SP(uc) ((uc)->uc_mcontext.__gregs[_REG32_UESP])
/*
* Floating point register state
*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: netbsd32_machdep.h,v 1.9 2006/03/12 20:25:25 cube Exp $ */
/* $NetBSD: netbsd32_machdep.h,v 1.10 2006/03/29 23:07:50 cube Exp $ */
#ifndef _MACHINE_NETBSD32_H_
#define _MACHINE_NETBSD32_H_
@ -130,6 +130,15 @@ struct x86_64_set_mtrr_args32 {
uint32_t n;
};
struct netbsd32_saframe {
int sa_ra;
int sa_type;
netbsd32_pointer_t sa_sas;
int sa_events;
int sa_interrupted;
netbsd32_pointer_t sa_arg;
};
struct env87 {
int32_t en_cw;
int32_t en_sw;

View File

@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.7 2005/12/11 12:19:05 christos Exp $ */
/* $NetBSD: mcontext.h,v 1.8 2006/03/29 23:07:49 cube Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -158,6 +158,7 @@ typedef struct {
#define _UC_MACHINE_PAD 8 /* Padding appended to ucontext_t */
#define _UC_MACHINE_SP(uc) (((uc)->uc_mcontext.__gregs[_REG_O6])+0x7ff)
#define _UC_MACHINE32_PAD 43 /* compat_netbsd32 variant */
#define _UC_MACHINE32_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_O6])
#else
#define _UC_MACHINE_PAD 43 /* Padding appended to ucontext_t */
#define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_O6])

View File

@ -1,4 +1,4 @@
/* $NetBSD: netbsd32_machdep.c,v 1.58 2006/03/14 22:05:05 cube Exp $ */
/* $NetBSD: netbsd32_machdep.c,v 1.59 2006/03/29 23:07:49 cube Exp $ */
/*
* Copyright (c) 1998, 2001 Matthew R. Green
@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.58 2006/03/14 22:05:05 cube Exp $");
__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.59 2006/03/29 23:07:49 cube Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd.h"
@ -92,8 +92,6 @@ const char machine_arch32[] = "sparc";
static int ev_out32(struct firm_event *, int, struct uio *);
#endif
void netbsd32_upcall(struct lwp *, int, int, int, void *, void *, void *, sa_upcall_t);
/*
* Set up registers on exec.
*
@ -414,33 +412,34 @@ netbsd32_sendsig(const ksiginfo_t *ksi, const sigset_t *mask)
* trampolines.
*/
void
netbsd32_upcall(struct lwp *l, int type, int nevents, int ninterrupted,
netbsd32_cpu_upcall(struct lwp *l, int type, int nevents, int ninterrupted,
void *sas, void *ap, void *sp, sa_upcall_t upcall)
{
struct proc *p = l->l_proc;
struct trapframe *tf;
vaddr_t addr;
tf = l->l_md.md_tf;
addr = (vaddr_t) upcall;
addr = (vaddr_t)p->p_sigctx.ps_sigcode;
/* Jump to the upcall handler */
tf->tf_pc = addr;
tf->tf_npc = addr + 4;
#if 0
/* XXX */
/* The upcall itself is in %g1 */
tf->tf_global[1] = upcall;
/* Arguments to the upcall... */
tf->tf_out[0] = type;
tf->tf_out[1] = sas;
tf->tf_out[1] = (vaddr_t) sas;
tf->tf_out[2] = nevents;
tf->tf_out[3] = ninterrupted;
tf->tf_out[4] = ap;
tf->tf_out[6] = (vaddr_t)sp;
#endif
tf->tf_out[4] = (vaddr_t) ap;
/*
* Ensure the stack is double-word aligned, and provide a
* C call frame.
*/
sp = (void *)(((vaddr_t)sp & ~0x7) - CCFSZ);
/* Arrange to begin execution at the upcall handler. */
tf->tf_pc = addr;
tf->tf_npc = addr + 4;
tf->tf_out[6] = (vaddr_t) sp;
tf->tf_out[7] = -1; /* "you lose" if upcall returns */
}
#undef DEBUG