Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!mcnc!ece-csc!ncrcae!ncr-sd!hp-sdd!ucsdhub!jack!man!crash!jeh From: jeh@crash.CTS.COM (Jamie Hanrahan) Newsgroups: comp.os.vms Subject: Re: Help with a Kernal mode macro program Message-ID: <1369@crash.CTS.COM> Date: Sat, 11-Jul-87 09:36:33 EDT Article-I.D.: crash.1369 Posted: Sat Jul 11 09:36:33 1987 Date-Received: Sun, 12-Jul-87 16:09:49 EDT References: <870708122836.001@sitvxb> Reply-To: jeh@crash.CTS.COM (Jamie Hanrahan) Followup-To: comp.os.vms Distribution: world Organization: Crash TS, El Cajon, CA Lines: 41 Keywords: Mutex IOLOCK Summary: MOVCx (and LOCx) clobber registers; reg. save mask isn't enough! In article <870708122836.001@sitvxb> dstevens@sitvxb (David L Stevens) writes: > > ...the MOVC3 > statement in the Kernal Mode code, crashes the system every time I run it. I replied to this via mail, but since then several not-quite-correct responses have been posted as news, so here goes... The folks who point out that MOVC3 clobbers R0-R5 are correct. (And, by the bye, LOC3 hits R0-R3.) BUT, simply mentioning R2 through R5 in the kernel (not "kernal", please!) mode routine's entry point mask is not sufficient to avoid the crashes. The code shown is calling the VMS system routines EXE$IOLOCKR (lock I/O data base via mutex for read) and EXE$IOUNLOCK (unlock I/O data base mutex). These routines require R4 to point to the current process's PCB. The call to IOLOCKR works because the $CMKRNL service calls the target routine with R4 pointing to the PCB, but after the MOVC3, R4 contains 0. The mutex-handling routines check to ensure that R4 is pointing to a valid PCB and bugcheck if it doesn't; hence the crash. R4 can be pushed at the beginning of the routine and popped just before the call to UNLOCK, or pushed and popped around the MOVC3s. Personally, I would put the following statement just before the calls to both EXE$IOUNLOCK and EXE$IOLOCKR: MOVL G^SCH$GL_CURPCB, R4 ; get addr of cur proc PCB Sure, it's not necessary for IOLOCKR because of the context that this code happens to run in... but that might change someday. The MOVL makes the code less context-dependent, and also more understandable. One other thing: All references to system-space labels (EXE$IOLOCKR, EXE$UNLOCK) should be preceded with the G^ prefix to ensure that they're position independent. DISCLAIMER: Names of system-space labels in the above were typed from memory. The suffixes are correct but the prefixes (EXE$, SCH$, etc.) may be mixed up... it's late/early/not good.