Path: utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!nosc!ucsd!ucbvax!ji.Berkeley.EDU!carlton
From: carlton@ji.Berkeley.EDU (Mike Carlton)
Newsgroups: comp.sys.mac.programmer
Subject: Re: Register saving conventions
Message-ID: <25556@ucbvax.BERKELEY.EDU>
Date: 9 Aug 88 20:01:37 GMT
References: <664@iraun1.ira.uka.de> <1133@lzsc.ATT.COM> <15055@santra.UUCP> <6600@umn-cs.cs.umn.edu>
Sender: usenet@ucbvax.BERKELEY.EDU
Reply-To: carlton@ji.Berkeley.EDU.UUCP (Mike Carlton)
Organization: University of California, Berkeley
Lines: 38

In article <6600@umn-cs.cs.umn.edu> imp@crayview.msi.umn.edu (Chuck Lukaszewski) writes:
>In article <15055@santra.UUCP>, jmunkki@santra.HUT.FI (Juri Munkki) writes:
>> In article <1133@lzsc.ATT.COM> mkg@lzsc.ATT.COM (Marsh Gosnell) writes:
>> >When I patch traps I make it a point to save/restore everything (D0-D7/A0-A4)
>
>There really is no need for this.  Juri is right about the cycle consumption
>of register saving.  At a minimum, you can ignore D0-D2 and A0-A1 because Apple
>says you can trash them.  Indeed, the ROM code makes no assumptions about these
>five registers.
>
>In point of fact, given the above about D0-D2/A0-A1, you need no register store
>code at all because the trap dispatcher handles the other registers for you, so
>you're just wasting stack space and CPU cycles.

Be careful here.  Many traps pass args in D0, A0 and even A1.  Many return
results in A0 and D0.  Presumably you would see this in the calling sequence 
and allow for it.  

More subtle problems could occur with traps that use bits in the trap word
to pass paramaters (such as _UprString which uses bits for case sensitive
and diactritical sensitive).  The trap dispatcher stuffs the trap number in
D2 and the trap word in D1 (I may have these backwords).  The code for the
trap will then check one of these words and branch accordingly.  So you
better not munge D1 or D2 in these cases.

Another potential problem could be tail patches on register based traps.
(I know, tail patches are frowned upon, but they're useful sometimes).  If
a result is returned in D0 the dispatcher tests D0 before returning to set 
the condition codes.  I don't know if any code branches immediately, but to 
be safe you'd have to retest D0 to reset the condition codes if you've 
changed them.

I agree, save only what is necessary.  However, there are some gotchas.


Ease of use != ease of programming.  Ease of use == !ease of programming.

regards,
mike  (carlton@ji.berkeley.edu    ...!ucbvax!ji!carlton)