Re: A89: Re: Re: Re: Re: CORRECTION: Shift+ON


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

Re: A89: Re: Re: Re: Re: CORRECTION: Shift+ON




Hi!

> the only place I can remember the unused bits of address being 
> used is in the main headers.
> nostub.h:
> asm("bset #7,(%sp)  /* The support for ~exit~ and ~atexit~ */
>      jmp _main");   /* and the workaround for a bug in TI-GCC */
> 
> and I am guessing, but I think that is used so that zeljko can
> remove stack frames until he hits the one that is marked with 
> the highest bit set.

Exactly true.

By the way, "exit" is principally (without restoring some
registers) implemented as:

exit: unlk a6
      cmpi.l #0x200000,(sp)
      bcs.s exit
      rts

More important reason for "marking" is to locate a place on
the stack which need to be "patched" if "atexit" is used:
see implementation of "atexit" in "sources" file.

Why I used such dirty hacks? In a lot of implementations, usage
of "exit" and "atexit" requires about 50-100 bytes long "stub"
which must be embedded in the program regardless of whether the
program would use "atexit" and "exit" or not. In my implementation,
the only "stub" is two-byte long instruction bset #7,(sp) :-)

> Note: never stick a number on the stack (with asm) with the 
> high bit set if you expect to be able to exit().

Not so exactly true: first "unlk a6" will clear such pushed
value from the stack before the comparison.

Cheers,

Zeljko Juric