H From:	MERC::"uunet!CRVAX.SRI.COM!RELAY-INFO-VAX" 16-MAR-1993 00:01:26.52 To:	Info-VAX@KL.SRI.COM  CC:	' Subj:	Re: kernel routines in C (solved)   g In article <1993Mar3.152100.76@tachyon.lonestar.org>, wayne@tachyon.lonestar.org (Wayne Sewell) writes: I > Is anyone writing kernel mode code in C?  If so, how do you prevent the 3 > change-mode dispatcher from destroying registers?  > O > I have been writing kernel code for a long time, and have no problem with the P > mechanics of change-mode dipatchers or the cmkrnl system service.  Due to the L > coming of Alpha, I have decided not to write any more macro code, and have4 > started implementing privileged code in C instead. > K > As long as you are careful what you do, there is no reason you can't have P > kernel code in C.  I have been using C for FDT-stealing routines, user-written$ > system services, and other things. > C > The problem is that I have to fight the system a little to do so.  > N > When you call a user written system service, the change-mode dispatcher putsM > the address of the PCB into register 4.  Same thing with the $CMKRNL system Q > service.  In both cases the routine being called must specify register 4 in its I > save mask.  Otherwise the calling program will suddenly find the PCB in 
 > register 4.  > K > When calling a system service, user or otherwise, the registers are saved Q > according to the save mask of the transfer vector, which is itself derived from N > the save mask of the actual procedure.  Thus only the registers specified by! > the called procedure are saved.  > M > This is no problem in macro, but in C you have no control over the register P > save mask of a function, as far as I know.  C keeps track of its own register L > usage and saves only the registers it has personally destroyed within the M > procedure.  It doesn't know that the dispatcher clobbered register 4 before  > calling the function.  > G > I tried to force C to save register 4 by calling the builtin function K > _WRITE_GPR (write general purpose register).  I thought if I deliberately N > destroyed register 4 myself within the procedure, that would force C to saveO > it.  No effect, much to my surprise (that makes me wonder about the viability  > of those builtin functions). > O > I finally solved the problem by dorking around with the transfer vectors.  In N > my transfer vectors for kernel C routines, the .transfer statement points toP > the actual routine the way it's supposed to, but the .mask statement points toO > a dummy mask that saves all registers.  Kludgy, I know, but it works.  Now my N > system services written in C operate normally and register 4 isn't destroyed > any more.  > F > I do something similar for cmkrnl by calling a macro jacket routine. > K > These methods work okay.  I was just wondering if there was a better way.  >  > Wayne  >  > --  K > Wayne Sewell                            |INET: wayne@tachyon.lonestar.org   7 The problem has been solved over in vmsnet.internals.     
 > You can do:  >         .MASK   foo,^m<r4> > 3 > (I just digested a V4 MACRO manual last night :-)  > Kenn Humborg > elehumborg@orbsen.ucg.ie  M This is the solution to the problem.  It turns out you *can* OR an arbitrary  O value into the mask.  I have been programming in macro for over ten years, but  O I didn't know that .mask could do that.  I wonder if it was a recent addition,  M or the capability has been there all along (obviously it was in V4, according  to the above).  K This technique can be used for *all* user written system services, not just L those written in C.  If you do this, you don't have to remember to add R4 to! the save mask of a macro routine.    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!"   