From 5979bb0b7dfd69f1ea0742468d1704ab5a959769 Mon Sep 17 00:00:00 2001 From: Justin Hibbits Date: Sun, 17 Nov 2019 01:01:02 +0000 Subject: [PATCH] powerpc: Return SIGILL if DSCR does not exist in m{f,t}spr emulation Guard against programs written for one powerpc target running on another, and panicking the system due to not having the DSCR register. --- sys/powerpc/powerpc/exec_machdep.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sys/powerpc/powerpc/exec_machdep.c b/sys/powerpc/powerpc/exec_machdep.c index aebdcc4a029..1339fb48f91 100644 --- a/sys/powerpc/powerpc/exec_machdep.c +++ b/sys/powerpc/powerpc/exec_machdep.c @@ -1086,15 +1086,17 @@ emulate_mfspr(int spr, int reg, struct trapframe *frame){ td = curthread; if (spr == SPR_DSCR || spr == SPR_DSCRP) { + if (!(cpu_features2 & PPC_FEATURE2_DSCR)) + return (SIGILL); // If DSCR was never set, get the default DSCR if ((td->td_pcb->pcb_flags & PCB_CDSCR) == 0) td->td_pcb->pcb_dscr = mfspr(SPR_DSCRP); frame->fixreg[reg] = td->td_pcb->pcb_dscr; frame->srr0 += 4; - return 0; + return (0); } else - return SIGILL; + return (SIGILL); } static int @@ -1104,13 +1106,15 @@ emulate_mtspr(int spr, int reg, struct trapframe *frame){ td = curthread; if (spr == SPR_DSCR || spr == SPR_DSCRP) { + if (!(cpu_features2 & PPC_FEATURE2_DSCR)) + return (SIGILL); td->td_pcb->pcb_flags |= PCB_CDSCR; td->td_pcb->pcb_dscr = frame->fixreg[reg]; mtspr(SPR_DSCRP, frame->fixreg[reg]); frame->srr0 += 4; - return 0; + return (0); } else - return SIGILL; + return (SIGILL); } #define XFX 0xFC0007FF