Data in text segment

Jerry Aguirre jerry at olivey.olivetti.com
Thu Oct 20 15:23:26 AEST 1988


In article <10440 at tekecs.TEK.COM> andrew at frip.gwd.tek.com (Andrew Klossner) writes:
>Yes the hardware has a line to tell the memory whether I or D is being
>requested.  But the program has no control over that line!  There's no
>general use "load from instruction space" instruction on any
>architecture I've looked at, so there's no way for a program to use
>data in a separated instruction space.  (Sometimes there's a "load from
>user's instruction space," but it's restricted to supervisor mode.)

Well, actually there is.  If an instuction refference a value that is PC
relative then the value is fetched from text space.  This is fairly easy
to do in the hardware and doesn't require adding new instructions or
addressing modes.  I am pretty sure this is the way the PDPs handled
split I/D.

In practice his means that simple constants (values and addresses) were
placed in the text segment.  What you can't do is take or pass the
address of the constants.  There isn't any segment information to go
along with the address to say what segment it is in.  So you can't put
printf strings, the most common shared data hack, in the text area.
(This also made sense in that once you take an address of data you
can't be sure it won't be written to.  So, lacking a keyword to indicate
that, the compiler can't be sure it can be placed in a read only shared
area.)

I saw this demonstrated once in some code I wrote to initialize
something.  (Not on a PDP so I don't know if it would have handled
this.)  I didn't want to use any library calls and I wanted the code to
be small so I wound up writing something like:

	i = 0;
	while (buf[i] = "Initialization string"[i]) i++;

My supprise was that the compiler was smart enough to realize the the
string could never be written to and placed it in the shared readonly
area.  If the hardware had a load PC plus register addressing mode then
the string could be placed in the text area.  Maybe someone with a
PDP11/45 or 70 can compile the above and see what the assembler output
looks like?
			Jerry Aguirre



More information about the Comp.unix.wizards mailing list