From: Mike McCarty (jmccarty_at_ssd.usa.alcatel.com)
Date: 2001-11-06 21:00:23
On Tue, 6 Nov 2001, Ullrich von Bassewitz wrote:
>
> On Tue, Nov 06, 2001 at 11:11:09AM -0600, Mike McCarty wrote:
> > Yes there is. It makes perfect sense that if X is a relocatable symbol,
> > that one can write
> >
> > .org X+10
> >
> > especially if X is the symbol for the current location counter, and
> > produce relocatable code.
>
> So for which purpose do you want this feature? I can see that this may be
> done, but I cannot imagine why anyone wants to do something like this. Is
> there really a use for this construct, and if so, is it really true that this
> cannot be achieved by other measures already available?
>
> Regards
First, I didn't ask for it, I responded to a statement that said it
didn't make sense.
However, I have made use of such constructs before, and here's and
example of how it may be useful.
Suppose there is a structure which is being built, which has pointers
to various other places in the code. One can then put the
initialization for that structure in the source where the various
things are created. I don't know the syntax of your assembler, but it
could be done like this:
=====================================
file1.inc
-------------------------------------
PrgEntryOfs .equ 0
PrgHandlrOfs .equ PrgEntryOfs+2
...
PrgPtrsSize .equ LastPtr+2
=====================================
file1.asm
-------------------------------------
.include file1.inc
.section ProgStructs,relocatable
PrgPtrs:
.reserve PrgPtrsSize
=====================================
file2.asm
-------------------------------------
.include file1.inc
.section ProgStructs,relocatable
.org PrgPtrs+PrgHandlrOfs
.word Handler
.section Code,relocatable
Handler:
<code goes here>
=====================================
file3.asm
-------------------------------------
.include file1.inc
.section ProgStructs,relocatable
.org PrgPtrs+EntryOfs
.word Entry
.section Code,relocatable
Entry:
<code goes here>
=====================================
In this way, file1.asm does not have to have embedded knowledge of the
names of the external addresses used, or even which ones are actually
present. If the assembler/linker support an OVERLAY attribute for
relocatable sections, then default addresses to a "crash" location can
be inserted in file1.asm, which then get overwritten by the values in
the other files. A reference to one of the unimplemented handlers then
automatically results in an appropriate "crash" which can display which
of the handlers got inappropriately invoked.
This type of device is appropriate for processors which do not have
fixed addresses for the interrupt vectors to be placed (in which case
it is appropriate to use a section with attributes of ABSOLUTE,
OVERLAY), like the Z8000, MC680x0, etc. processors have a register
which points to the interrupt vector area.
Another, more mundane use, is to implement placing things in a
relocatable area, but on an address which is divisible by some
particular size, especially if the assembler does not support an .align
to that size. For example, suppose some piece of the code must reside at
an address divisible by 16, and no .align 16 directive exists. Then code
like this
Location: .org ((Location+15)/16)*16
places the next code at an address divisible by 16. I have used
assemblers which supported
.align word
.align dword
but only for certain specified values, like word for 2, dword for 4,
but no alignment for 16 existed.
Mike
--
char *p="char *p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
This message made from 100% recycled bits.
I can explain it for you, but I can't understand it for you.
I don't speak for Alcatel <- They make me say that.
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
This archive was generated by hypermail 2.1.3 : 2001-12-14 22:05:44 CET