Path: utzoo!attcan!uunet!peregrine!elroy.jpl.nasa.gov!ncar!noao!amethyst!organpipe!afthree.as.arizona.edu!tom From: tom@afthree.as.arizona.edu (Thomas J. Trebisky) Newsgroups: comp.os.cpm Subject: Re: System use of Z80 registers Message-ID: <629@organpipe.UUCP> Date: 5 Dec 90 21:27:16 GMT References: <9011261759.AA10916@newton> <6209@balu.UUCP> Sender: news@organpipe.UUCP Organization: University of Arizona, Tucson, AZ Lines: 37 >Bridger Mitchell writes: >> I (and others) have long argued strenuously for strict adherence to >> the following systems-programming guideline: >> >> **** >> SYSTEM CODE (BIOS, BDOS, INTERRUPT-SERVICE ROUTINES, AND BACKGROUND >> UTILITIES) SHOULD *ALWAYS PRESERVE* THE NON-8080 REGISTERS. >> **** > > Tilmann Reh writes >The above guideline opens the door to very improper application programming. >The only way to ensure that a program runs on *every* CP/M machine is to >save all registers which must stay valid prior to any system call. BTW, I >don't see why this should be so hard... Sorry to take exception with this. I don't think it is the applications programmers responsibility to guard against all manner of stupidity on the part of those writing systems code. Believe me, every modern OS puts the burden of saving and restoring machine state on the OS -- on a Unix system a system call is commonly implemented by a TRAP or INT, and the first thing the OS will do is save all the registers and whatever else is involved with the user context so it can restore it transparently. As you point out there is no possible way that user code can "guard against" what is done with registers in interrupt routines since they are completely asynchronous. The sad reality of things though is that you are right in a way, due to the abundance of funky systems software in the CPM realm. In the hey-day of CPM every Tom, Dick, and Harry was in a rush to port CPM to this or that platform, and some of the work was poorly done. This forces you and I to go to lengths we shouldn't have to, if we really want "portability" to every sleaze-ball system. However if the above guidelines for SYSTEMS code were followed, we would not have to do this. Another case could be made perhaps for efficiency, the applications programmer knows at any time exactly what he needs to save, whereas a systems call handler must necessarily save everything to be general. In the Z80 realm where every machine cycle is precious, this might have merit, but I would rather save the code space (and my keystrokes :-) ).