Save USP when trapping from userspace.

Change register save structs according to this.
Be compatible with the way old init passes flags (in registers).
This commit is contained in:
ragge 1996-01-28 12:22:49 +00:00
parent d8e53d2958
commit 27a6a01b3a
4 changed files with 97 additions and 112 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: intvec.s,v 1.12 1995/11/10 19:05:46 ragge Exp $ */
/* $NetBSD: intvec.s,v 1.13 1996/01/28 12:22:55 ragge Exp $ */
/*
* Copyright (c) 1994 Ludd, University of Lule}, Sweden.
@ -56,7 +56,7 @@
.long label+stack;
.text
.globl _kernbase,_rpb
.globl _kernbase, _rpb
_kernbase:
_rpb:
/*
@ -212,15 +212,17 @@ ptelen: movl $T_PTELEN, (sp) # PTE must expand (or send segv)
syscall:
pushl $T_SYSCALL
pushr $0xfff
mfpr $PR_USP, -(sp)
pushl ap
pushl fp
pushl sp # pointer to syscall frame; defined in trap.h
calls $1,_syscall
movl (sp)+,fp
movl (sp)+,ap
calls $1, _syscall
movl (sp)+, fp
movl (sp)+, ap
mtpr (sp)+, $PR_USP
popr $0xfff
addl2 $8,sp
mtpr $0x1f,$PR_IPL # Be sure we can REI
addl2 $8, sp
mtpr $0x1f, $PR_IPL # Be sure we can REI
rei
STRAY(0, 44)
@ -259,7 +261,7 @@ syscall:
STRAY(0, B4)
STRAY(0, B8)
TRAPCALL(ddbtrap,T_KDBTRAP)
TRAPCALL(ddbtrap, T_KDBTRAP)
.align 2
.globl hardclock
@ -293,16 +295,26 @@ hardclock: mtpr $0xc1,$PR_ICCS # Reset interrupt flag
FASTINTR(consrint, gencnrint)
FASTINTR(constint, gencntint)
/*
* Main routine for traps; all go through this.
* Note that we put USP on the frame here, which sometimes should
* be KSP to be correct, but because we only alters it when we are
* called from user space it doesn't care.
* _sret is used in cpu_set_kpc to jump out to user space first time.
*/
.globl _sret
trap: pushr $0xfff
mfpr $PR_USP, -(sp)
pushl ap
pushl fp
pushl sp
calls $1,_arithflt
movl (sp)+,fp
movl (sp)+,ap
popr $0xfff
addl2 $8,sp
mtpr $0x1f,$PR_IPL # Be sure we can REI
calls $1, _arithflt
_sret: movl (sp)+, fp
movl (sp)+, ap
mtpr (sp)+, $PR_USP
popr $0xfff
addl2 $8, sp
mtpr $0x1f, $PR_IPL # Be sure we can REI
rei
#if VAX630 || VAX650

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.c,v 1.22 1996/01/04 22:22:58 jtc Exp $ */
/* $NetBSD: machdep.c,v 1.23 1996/01/28 12:22:54 ragge Exp $ */
/*
* Copyright (c) 1994 Ludd, University of Lule}, Sweden.
@ -350,8 +350,12 @@ setstatclockrate(hzrate)
consinit()
{
#ifdef DDB
db_machine_init();
/* db_machine_init(); */
ddb_init();
#ifdef donotworkbyunknownreason
if (boothowto & RB_KDB)
Debugger();
#endif
#endif
}
@ -385,19 +389,19 @@ sys_sigreturn(p, v, retval)
scf->fp = cntx->sc_fp;
scf->ap = cntx->sc_ap;
scf->pc = cntx->sc_pc;
scf->sp = cntx->sc_sp;
scf->psl = cntx->sc_ps;
mtpr(cntx->sc_sp, PR_USP);
return (EJUSTRETURN);
}
struct trampframe {
u_int sig; /* Signal number */
u_int code; /* Info code */
u_int scp; /* Pointer to struct sigcontext */
u_int r0, r1, r2, r3, r4, r5; /* Registers saved when
unsigned sig; /* Signal number */
unsigned code; /* Info code */
unsigned scp; /* Pointer to struct sigcontext */
unsigned r0, r1, r2, r3, r4, r5; /* Registers saved when
* interrupt */
u_int pc; /* Address of signal handler */
u_int arg; /* Pointer to first (and only) sigreturn
unsigned pc; /* Address of signal handler */
unsigned arg; /* Pointer to first (and only) sigreturn
* argument */
};
@ -407,14 +411,14 @@ sendsig(catcher, sig, mask, code)
int sig, mask;
u_long code;
{
struct proc *p = curproc;
struct sigacts *psp = p->p_sigacts;
struct trapframe *syscf;
struct sigcontext *sigctx;
struct trampframe *trampf;
u_int *cursp;
int oonstack;
extern char sigcode[], esigcode[];
struct proc *p = curproc;
struct sigacts *psp = p->p_sigacts;
struct trapframe *syscf;
struct sigcontext *sigctx;
struct trampframe *trampf;
unsigned cursp;
int oonstack;
extern char sigcode[], esigcode[];
/*
* Allocate and validate space for the signal handler context. Note
* that if the stack is in P0 space, the call to grow() is a nop, and
@ -422,26 +426,26 @@ sendsig(catcher, sig, mask, code)
* allocated the space with a `brk'. We shall allocate space on the
* stack for both struct sigcontext and struct calls...
*/
syscf = p->p_addr->u_pcb.framep;
/* First check what stack to work on */
if ((psp->ps_flags & SAS_ALTSTACK) && !oonstack &&
(psp->ps_sigonstack & sigmask(sig))) {
cursp = (u_int *) (psp->ps_sigstk.ss_sp +
psp->ps_sigstk.ss_size);
cursp = (int)(psp->ps_sigstk.ss_sp + psp->ps_sigstk.ss_size);
psp->ps_sigstk.ss_flags |= SS_ONSTACK;
} else
cursp = (u_int *) mfpr(PR_USP);
if ((u_int) cursp <= USRSTACK - ctob(p->p_vmspace->vm_ssize))
(void) grow(p, (u_int) cursp);
cursp = syscf->sp;
if (cursp <= USRSTACK - ctob(p->p_vmspace->vm_ssize))
(void) grow(p, cursp);
/* Set up positions for structs on stack */
sigctx = (struct sigcontext *) ((u_int) cursp -
sizeof(struct sigcontext));
trampf = (struct trampframe *) ((u_int) sigctx -
sigctx = (struct sigcontext *) (cursp - sizeof(struct sigcontext));
trampf = (struct trampframe *) ((unsigned)sigctx -
sizeof(struct trampframe));
cursp = (u_int *) sigctx - 2; /* Place for pointer to arg list in
* sigreturn */
syscf = p->p_addr->u_pcb.framep;
/* Place for pointer to arg list in sigreturn */
cursp = (unsigned)sigctx - 8;
if (useracc((caddr_t) cursp, sizeof(struct sigcontext) +
sizeof(struct trampframe), B_WRITE) == 0) {
/*
@ -458,7 +462,7 @@ sendsig(catcher, sig, mask, code)
}
/* Set up pointers for sigreturn args */
trampf->arg = (int) sigctx;
trampf->pc = (u_int) catcher;
trampf->pc = (unsigned) catcher;
trampf->scp = (int) sigctx;
trampf->code = code;
trampf->sig = sig;
@ -468,14 +472,14 @@ sendsig(catcher, sig, mask, code)
sigctx->sc_ps = syscf->psl;
sigctx->sc_ap = syscf->ap;
sigctx->sc_fp = syscf->fp;
sigctx->sc_sp = mfpr(PR_USP);
sigctx->sc_sp = syscf->sp;
sigctx->sc_onstack = oonstack;
sigctx->sc_mask = mask;
syscf->pc = (u_int) (((char *) PS_STRINGS) - (esigcode - sigcode));
syscf->pc = (unsigned) (((char *) PS_STRINGS) - (esigcode - sigcode));
syscf->psl = PSL_U | PSL_PREVU;
syscf->ap = (u_int) cursp;
mtpr(cursp, PR_USP);
syscf->ap = cursp;
syscf->sp = cursp;
}
int waittime = -1;
@ -616,21 +620,10 @@ process_read_regs(p, regs)
{
struct trapframe *tf = p->p_addr->u_pcb.framep;
regs->r0 = tf->r0;
regs->r1 = tf->r1;
regs->r2 = tf->r2;
regs->r3 = tf->r3;
regs->r4 = tf->r4;
regs->r5 = tf->r5;
regs->r6 = tf->r6;
regs->r7 = tf->r7;
regs->r8 = tf->r8;
regs->r9 = tf->r9;
regs->r10 = tf->r10;
regs->r11 = tf->r11;
bcopy(&tf->r0, &regs->r0, 12 * sizeof(int));
regs->ap = tf->ap;
regs->fp = tf->fp;
regs->sp = mfpr(PR_USP);
regs->sp = tf->sp;
regs->pc = tf->pc;
regs->psl = tf->psl;
return 0;
@ -643,21 +636,10 @@ process_write_regs(p, regs)
{
struct trapframe *tf = p->p_addr->u_pcb.framep;
tf->r0 = regs->r0;
tf->r1 = regs->r1;
tf->r2 = regs->r2;
tf->r3 = regs->r3;
tf->r4 = regs->r4;
tf->r5 = regs->r5;
tf->r6 = regs->r6;
tf->r7 = regs->r7;
tf->r8 = regs->r8;
tf->r9 = regs->r9;
tf->r10 = regs->r10;
tf->r11 = regs->r11;
bcopy(&regs->r0, &tf->r0, 12 * sizeof(int));
tf->ap = regs->ap;
tf->fp = regs->fp;
mtpr(regs->sp, PR_USP);
tf->sp = regs->sp;
tf->pc = regs->pc;
tf->psl = regs->psl;
return 0;
@ -665,11 +647,11 @@ process_write_regs(p, regs)
int
process_set_pc(p, addr)
struct proc *p;
caddr_t addr;
struct proc *p;
caddr_t addr;
{
void *ptr;
struct trapframe *tf;
struct trapframe *tf;
void *ptr;
if ((p->p_flag & P_INMEM) == 0)
return (EIO);
@ -677,7 +659,7 @@ process_set_pc(p, addr)
ptr = (char *) p->p_addr->u_pcb.framep;
tf = ptr;
tf->pc = (u_int) addr;
tf->pc = (unsigned) addr;
return (0);
}
@ -703,12 +685,6 @@ process_sstep(p, sstep)
return (0);
}
#undef setsoftnet
setsoftnet()
{
panic("setsoftnet");
}
ns_cksum()
{
panic("ns_cksum");
@ -716,8 +692,10 @@ ns_cksum()
cmrerr()
{
#if 0
switch (cpunumber) {
case VAX_750:
ka750_memerr();
}
#endif
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: subr.s,v 1.12 1995/11/10 19:08:59 ragge Exp $ */
/* $NetBSD: subr.s,v 1.13 1996/01/28 12:22:52 ragge Exp $ */
/*
* Copyright (c) 1994 Ludd, University of Lule}, Sweden.
@ -211,12 +211,12 @@ cs: ret
ret
_loswtch: .globl _loswtch,_rei
_loswtch: .globl _loswtch
mtpr _curpcb,$PR_PCBB
svpctx
mtpr _nypcb,$PR_PCBB
ldpctx
_rei: rei
rei
.data

View File

@ -1,4 +1,4 @@
/* $NetBSD: vm_machdep.c,v 1.18 1995/12/13 18:47:59 ragge Exp $ */
/* $NetBSD: vm_machdep.c,v 1.19 1996/01/28 12:22:49 ragge Exp $ */
#undef SWDEBUG
/*
@ -51,6 +51,7 @@
#include "machine/macros.h"
#include "machine/trap.h"
#include "machine/pcb.h"
#include "machine/frame.h"
#include <sys/syscallargs.h>
@ -126,7 +127,6 @@ cpu_fork(p1, p2)
nyproc->P0LR = AST_PCB;
nyproc->P1LR = 0x200000;
#endif
nyproc->USP = mfpr(PR_USP);
nyproc->iftrap = NULL;
nyproc->KSP = (u_int)p2->p_addr + USPACE;
@ -135,6 +135,7 @@ cpu_fork(p1, p2)
bcopy(&tf->r2,&nyproc->R[2],10*sizeof(int));
nyproc->AP = tf->ap;
nyproc->FP = tf->fp;
nyproc->USP = tf->sp;
nyproc->PC = tf->pc;
nyproc->PSL = tf->psl & ~PSL_C;
nyproc->R[0] = p1->p_pid; /* parent pid. (shouldn't be needed) */
@ -158,30 +159,25 @@ cpu_set_kpc(p, pc)
{
struct pcb *nyproc;
struct {
u_int chand;
u_int mask;
u_int ap;
u_int fp;
u_int pc;
u_int nargs;
u_int pp;
u_int rpc;
u_int rpsl;
struct callsframe cf;
struct trapframe tf;
} *kc;
extern int rei;
kc = (void *)p->p_addr + USPACE - sizeof(*kc);
kc->chand = 0;
kc->mask = 0x20000000;
kc->pc = (u_int)&rei;
kc->nargs = 1;
kc->pp = (u_int)p;
kc->rpsl = 0x3c00000;
extern int sret, boothowto;
nyproc = &p->p_addr->u_pcb;
nyproc->framep = (void *)p->p_addr + USPACE - sizeof(struct trapframe);
nyproc->AP = (u_int)&kc->nargs;
nyproc->FP = nyproc->KSP = (u_int)kc;
(unsigned)kc = nyproc->FP = nyproc->KSP =
(unsigned)p->p_addr + USPACE - sizeof(*kc);
kc->cf.ca_cond = 0;
kc->cf.ca_maskpsw = 0x20000000;
kc->cf.ca_pc = (unsigned)&sret;
kc->cf.ca_argno = 1;
kc->cf.ca_arg1 = (unsigned)p;
kc->tf.r11 = boothowto; /* If we have old init */
kc->tf.psl = 0x3c00000;
nyproc->framep = (void *)&kc->tf;
nyproc->AP = (unsigned)&kc->cf.ca_argno;
nyproc->FP = nyproc->KSP = (unsigned)kc;
nyproc->PC = pc + 2;
}
@ -453,7 +449,6 @@ cpu_coredump(p, vp, cred, chdr)
chdr->c_cpusize = sizeof(struct md_coredump);
bcopy(tf, &state, sizeof(struct md_coredump));
state.md_tf.code = mfpr(PR_USP); /* XXX */
CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_VAX, CORE_CPU);
cseg.c_addr = 0;
@ -506,7 +501,7 @@ cpu_swapin(p)
uarea = (u_int)p->p_addr;
for(i = uarea;i < uarea + USPACE;i += PAGE_SIZE) {
for (i = uarea;i < uarea + USPACE;i += PAGE_SIZE) {
j = (u_int *)kvtopte(i);
if ((*j & PG_V) == 0) {
rv = vm_fault(kernel_map, i,