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 In article <1993Mar15.211645.4492@nntpd.lkg.dec.com>, dipirro@star.dec.com (Steve DiPirro) writes: > > In article <1993Mar9.231559.86@tachyon.lonestar.org>, wayne@tachyon.lonestar.org (Wayne Sewell) writes... >>In article <1993Mar8.220607.9954@nntpd.lkg.dec.com>, dipirro@star.dec.com (Steve DiPirro) writes: >>> >>> In article <1993Mar3.152100.76@tachyon.lonestar.org>, wayne@tachyon.lonestar.org (Wayne Sewell) writes... >>>>Is anyone writing kernel mode code in C? If so, how do you prevent the >>>>change-mode dispatcher from destroying registers? >>> >>[stuff deleted] >>> > > I'll take your word for it that this is a problem on VAX (and in my > opinion, a bug in the change-mode dispatcher), but it definitely > won't happen on AXP. As I was looking over the change-mode dispatcher > code, I suddenly realized that the dispatcher can trash R4 and not > restore it and still have the right thing happen. It's really more of a documentation problem than anything else. As I reported 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 the linker will pick up the register save mask from the target routine and OR register 4 with it. The resultant mask will contain the registers specified by the target routine plus register 4. All VMS documentation which discusses privileged shareable images should recommend the above, in my opinion. If your system service is written in a high-level language, that is the only way it will work. If written in macro, the above is still useful. If you don't 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. 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. Could you pass this comment to the VMS doc people? > > On AXP, CHME and CHMK are PAL calls which generate exceptions. As with > all other exceptions, R2-R7, PC, and PS are pushed onto the stack prior > to dispatching through the SCB to the handler. When the change-mode > dispatcher executes the REI, another PAL call, the REI instruction > assumes you have a valid exception frame on the stack, restores R2-R7, > PC, and PS from there, and "jumps" to the PC. So R4 is being saved > and restored by PAL code. The change-mode dispatcher would have to > trash the saved R4 on the exception stack in order to affect your code. > > ------------ > Steve DiPirro dipirro@star.enet.dec.com > > /\ > USE THIS || ADDRESS, not what's in the header > ------------ I'm glad to hear that the save mask trick is not necessary on Alpha, because transfer vectors are now handled by the linker. I'm not sure how you would be able to do it. Wayne ============================================================================== Wayne Sewell |INET: wayne@tachyon.lonestar.org Tachyon Software Consulting |UUCP: ...!{letni,mic}!tachyon!wayne P. O. Box 550937, Dallas TX 75355-0937 |Voice: (214)-553-9760, Fax: -553-0077 ============================================================================== Curly: "I keep tryin' to think, but nuthin' happens!"