H From:	MERC::"uunet!CRVAX.SRI.COM!RELAY-INFO-VAX" 18-MAR-1993 02:16:39.89 To:	Info-VAX@KL.SRI.COM  CC:	 Subj:	Re: kernel routines in C  b In article <1993Mar15.211645.4492@nntpd.lkg.dec.com>, dipirro@star.dec.com (Steve DiPirro) writes: > k > In article <1993Mar9.231559.86@tachyon.lonestar.org>, wayne@tachyon.lonestar.org (Wayne Sewell) writes... c >>In article <1993Mar8.220607.9954@nntpd.lkg.dec.com>, dipirro@star.dec.com (Steve DiPirro) writes:  >>> m >>> In article <1993Mar3.152100.76@tachyon.lonestar.org>, wayne@tachyon.lonestar.org (Wayne Sewell) writes... K >>>>Is anyone writing kernel mode code in C?  If so, how do you prevent the 5 >>>>change-mode dispatcher from destroying registers?  >>>  >>[stuff deleted]  >>>  > E > I'll take your word for it that this is a problem on VAX (and in my B > opinion, a bug in the change-mode dispatcher), but it definitelyG > won't happen on AXP. As I was looking over the change-mode dispatcher D > code, I suddenly realized that the dispatcher can trash R4 and not3 > restore it and still have the right thing happen.   N It's really more of a documentation problem than anything else.  As I reportedO in an earlier post, the solution is very simple.  If you add register 4 to the  # mask on the transfer vector, as in:    	.mask  target_routine,^m<r4>   M the linker will pick up the register save mask from the target routine and OR O register 4 with it.  The resultant mask will contain the registers specified by J the target routine plus register 4.  All VMS documentation which discussesK privileged shareable images should recommend the above, in my opinion.  If  N your system service is written in a high-level language, that is the only way M it will work.  If written in macro, the above is still useful.  If you don't  M use r4 for anything within the procedure, you might forget to save it.  It's  ; not obvious looking at the procedure that r4 must be saved.   N The only reason you might not want register 4 to be saved is if you have macro* code that *expects* the PCB to be in R4.    2 Could you pass this comment to the VMS doc people?   > H > On AXP, CHME and CHMK are PAL calls which generate exceptions. As withI > all other exceptions, R2-R7, PC, and PS are pushed onto the stack prior E > to dispatching through the SCB to the handler. When the change-mode D > dispatcher executes the REI, another PAL call, the REI instructionH > assumes you have a valid exception frame on the stack, restores R2-R7,D > PC, and PS from there, and "jumps" to the PC. So R4 is being savedD > and restored by PAL code. The change-mode dispatcher would have toI > trash the saved R4 on the exception stack in order to affect your code.  >  > ------------0 > Steve DiPirro        dipirro@star.enet.dec.com > " >                               /\D >                      USE THIS || ADDRESS, not what's in the header > ------------  L I'm glad to hear that the save mask trick is not necessary on Alpha, becauseN transfer vectors are now handled by the linker.  I'm not sure how you would be able to do it.   Wayne   N ==============================================================================I Wayne Sewell                            |INET: wayne@tachyon.lonestar.org L Tachyon Software Consulting             |UUCP: ...!{letni,mic}!tachyon!wayneN P. O. Box 550937, Dallas TX  75355-0937 |Voice: (214)-553-9760, Fax: -553-0077N ==============================================================================5 Curly: "I keep tryin' to think, but nuthin' happens!"   