<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Mon, 26 Nov 1990 09:58:58 PST
From   : Bridger Mitchell <bridger%monty@rand.org>
Subject: System use of Z80 registers

Mitch Mlinar wrote:
>> Regarding BIOS:  Kaypro assumed that you were in an 8080 world AND interrupts
>> do not exist.  (They wrote their BIOS in Z80 code, though, and used the
>> "back-side" Z80 registers.)  Bridger Mitchell (TurboROM) is better here in
>> that he understands that interrupts might exist, but ALSO assumes that one
>> lives in an 8080 world only.  In other words, the assumption is that IX and
>> IY registers are unchanged outside of your program.  KayPLUS does not make
>> any of those assumptions, especially since 90% of the CP/M computers are
>> Z80 and replacement operating systems (like QP/M or ZCPR) all exploit the
>> Z80 instruction set.
>> 
>> 

Not many people are writing Z80 operating systems today (although
interesting applications such as background reminder calendars
continue to appear).  However, I think some clarification of Mitch's
comments is desirable.

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.
                                ****

This rule ensures that an application that uses Z80 opcodes can run on
any z80 system without having to save and restore any of those
registers before every BIOS and BDOS call.

Note that system code can indeed *use* the Z80 registers (the TurboRom,
BackGrounder ii, and ZSDOS, for example, do so extensively).  The code
must just push/pop or save/restore from memory any registers that it
needs to use.

A flagrant violations of this guideline is found in an early
version of the Osborne Executive rom, which used an index register
(probably IY) in a service interrupt routine.  Not even the smartest
application can safely use IY, since the interrupt is asynchronous,
and until a corrected rom was issued early owners were baffled to find
that some programs would simply not run correctly.

Another egregious case is the BIOS in the ON! computer, which uses af'
without preserving it.

This topic -- appropriate use of registers -- is part of the larger
subject I have called "environmental programming" and discussed at
greater length in a column in The Computer Journal.  Each programmer
needs to be aware of the computer environment in which his/her code
may be executing, and take appropriate steps to preserve that
environment.  Systems code has an especially heavy obligation to allow
applications to thrive; hence the abvove guideline.  But applications
also have responsibilities -- for example, to verify that the host has
the necessary resources (devices, type of BIOS, etc.) before executing
code that can crash or do damage on the wrong platform.

-- bridger


End of INFO-CPM Digest V90 Issue #193
*************************************
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>