Subject: SRR1 bits in signal trampolines
To: None <port-powerpc@netbsd.org>
From: Aymeric Vincent <vincent@labri.fr>
List: port-powerpc
Date: 04/14/2004 13:01:27
Hi,

when I run "startx", the X server immediately dies as soon as it gets a 
SIGALRM, which is as soon as it gets started.

    248 XFree86  PSIG  SIGALRM caught handler=0x18ae57c mask=())
    248 XFree86  CALL  compat_16___sigreturn14(0xffffe7e0)
    248 XFree86  RET   compat_16___sigreturn14 -1 errno 22 Invalid 
argument
    248 XFree86  CALL  exit(0x16)

The problem is with the following test in 
powerpc/powerpc/compat_16_machdep.c:compat_16_sys___sigreturn14():

   if ((sc.sc_frame.srr1 & PSL_USERSTATIC) != (tf->srr1 &PSL_USERSTATIC))
     return (EINVAL);

and/or with this definition in powerpc/include/psl.h:

/*
  * A user is not allowed to change any MSR bits except the following:
  */
#define PSL_USERSTATIC 
(~(PSL_VEC|PSL_FP|PSL_FE0|PSL_FE1|PSL_LE|PSL_SE|PSL_BE))

SRR1 can have bits 1-4 and 10-15 modified depending on the exception 
taken. In my case, a printf() shows that bit 2 (0x40000000) gets set in 
sc.sc_frame.srr1. I don't know why it does now and why it didn't 
before, but the fact is that it does, and the documentation says we 
shouldn't assume it doesn't.

I think the test in compat_16_sys___sigreturn14() should change to be 
less tight (SRR1 is not the MSR), but I am completely unaware of the 
consequences of doing so. Could someone knowing the PowerPC better than 
me please give a look at this?

Thanks,
  Aymeric