[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MiNT] Scratch registers



Hi Miro,

> I've bumped into an interesting issue (thanks ggn!) -- it's not a secret
> that TOS uses a0-a2/d0-a2 as so called scratch registers. ...
> However, this seems to be not true for TOS earlier than 2.x, i.e. TOS
> utilizes only d0/a0 as the scratch registers and the other registers must
> be preserved.

Are you sure, this has changed?

> In practice, it doesn't pose much problems as there are very few people
> running gcc+mintlib apps on TOS 1.x machines but it is a problem in general.

No, i dont see any problem.

> For me the use case is a GEMDOS driver/handler -- I call a C function from
> my asm code, d1/d2/a1/a2 get trashed, I pass execution back to TOS and bam,
> crash because the original TOS handler expected the regs wouldn't change.

No, it does not bam. I think, you mix the view of TOS and of the
application.

You gcc application expect, that d1/d2/a1/a2 may be destroyed. So if
the gcc generated code wants to have the old value, it generates code
to preserve this registers. All other registers are preserved by TOS.

It is a general rule: if TOS uses this registers as scratch registers,
this mean this registers may be destroyed and your code must preserve
them. Not TOS!

If it is true, that the old TOS version did not use d1/d2/a1/a2 as
scratch Registers, they are not destroyed. So if gcc code expects,
they are destroyed it is no problem. It doesnt matter if the contents
of this registers are really changed or not. The gcc code did not
rely on former content of this registers.

> Of course, I could (and will) store the regs before calling the C function
> but in general, it's a bug, not so well known, as the rule for scratch
> registers had changed after TOS 2.x release.

If the rule has changed, it is a problem for old applications which
expect, that d1/d2/a1/a2 have not changed and then they may crash on
newer TOS version.

Best regards
Michael