[net.unix-wizards] pdp11 loader options

arnold@gatech.UUCP (06/10/83)

	There is something that I've always wondered about on
pdp11 unix systems. What exactly is the difference between the
-i and -n loader options? The manual page is about as clear
as the New York Skyline is even.
	I know that they both separate your program into
separate I and D space, and that -i has to be used when a program
gets too big for -n. I don't understand how or why tho.

	Thanks in advance,

		Arnold Robbins
-- 
"The parchment and quill pen of Arnold Robbins"

Arnold @ GATech		          (CS Net)
Arnold.GATech @ UDel-Relay        (ARPA)	 School of ICS
...!{sb1, allegra}!gatech!arnold  (uucp)      	 Georgia Tech
...!duke!mcnc!msdc!gatech!arnold                 Atlanta, GA 30332
...!decvax!cornell!allegra!gatech!arnold

lwa%mit-csr@sri-unix.UUCP (06/11/83)

The -i and -n options to the pdp-11 loader actually do different
things.  -n produces a load image with separate "text" and
"data" segments, such that the text segment is read-only and
can be shared.  The data segment is relocated to begin at
the next 4K word boundary above the end of the text segment
(_etext) so that it will mapped by a different mapping register -
this allows the text and data segments to be non-contiguous in
physical memory.

The -i option goes further - it produces a program linked to run
with separated instruction and data (I and D) spaces.  In this
case both the text segment and the data segment are relocated to
begin at virtual address 0; the processor determines from the
type of reference (instruction fetch or not) whether the address
is to be mapped using the I-space mapping registers or the D-space
mapping registers.

Programs linked with -n can be run on any pdp-11; programs linked with
-i can be larger, but will only run on 11/44's, 45's, 50's, 55's, and 70's.
					-Larry Allen
-------

edhall%rand-unix@sri-unix.UUCP (06/12/83)

Actually, the data segment in separate I/D programs begins at location 2.
This is to confirm to K&R's dictum that ``it is guaranteed that assignment
of the constant 0 to a pointer will produce a null pointer distinguishable
from a pointer to any object''.

A while back there was a drawn-out discussion of de-referencing null
pointers, and I believe this fact was mentioned in passing.  A look at
the source to ld will confirm it.

		-Ed Hall
		edhall@rand-unix
		ucbvax!trw-unix!randvax!edhall

jcp%brl-bmd@sri-unix.UUCP (06/13/83)

From:      J. C. Pistritto <jcp@brl-bmd>

The -n option on the PDP-11 loader is often referred to as
	'write-protected text' loading.  It loads your program in to one
	(1) 16 bit address space, and results in a program that runs with
	both its instruction and data memory management registers, (on machines
	that have both, pointing to the same physical region of memory, just
	that the pages which refer to 'code' are write-protected.  A small
	side effect of this is that since data follows code, the first data
	address in your program will be a multiple of 8192 (bytes), as the
	data is adjusted upward in memory to the beginning of the next memory
	managment register address space, (there are only 8 for the entire
	64kbytes possible).  This means you could actually have a program
	which will load and run correctly without -n that will NOT with -n.
	I have actually seen this happen, and it means your program is\
	getting close the hairy edge.  One note: a '-n' loaded program may
	be run on ANY PDP-11 with memory management, (ie. runs UNIX). This
	is NOT true of a -i loaded program.

The -i option directs the loader to load code and data into two PHSYCIALLY
	DISTINCT regions of memory, which each have their own set of memory
	managment registers when the program is running.  This also means that
	this will NOT work on any machine that does not support the Split I&D
	register sets.  (Ex. PDP-11/23s, PDP-11/34s, PDP-11/60??).  Also,
	it means you get an entire 64Kbytes for code and 64Kbytes, (minus
	the stack), for data.  Also, there are certain functions which may
	not be used in a split I&D program, (on version 6, NARGS was an
	example of this).

Of course, it is not possible to write self-modifying code when either -n or
	-i are specified, (in fact, this is often the purpose of specifing
	them...)
						-JCP-

guy@rlgvax.UUCP (06/13/83)

Actually, the PDP-11 "crt0" C startup routine puts in a shim at location
0 to insure that real data starts at location 2; if you don't link with
it, you can end up with real data at location 0.  Anybody out there
planning an implementation of UNIX should ENSURE, using this or any
other trick, that no code (other than the start-up code) or data appear
at location 0 (one implementation did that, and it gave some of our
programs gastric distress; fortunately, they fixed that bug early on).

		Guy Harris
		RLG Corporation
		{seismo,mcnc,we13,brl-bmd,allegra}!rlgvax!guy

tom@rlgvax.UUCP (06/14/83)

Another note should be made about the "ld" option "-n".

As discussed, if NEITHER "-n" or "-i" is specified, you get the
default, which is that each user runs his own copy of the complete
program, with no sharing of the text and text is not write-protected.
In short, there is no distinction between text and data, and they are
put in the same memory mapping segments.

A program may fit in 16-bit addressing in the default case, but may
not fit when link-edited with the "-n" option.  This is because the text
must be set up in separate map segments to be protected and shared.
This generally requires an extra memory mapping register.  If your
program is big and using all them already it will no longer fit.

I believe the error you get is a simple "too big" when you try to execute
it without the program ever getting to first base.

- Tom Beres
{mcnc, seismo, allegra, brl-bmd}!rlgvax!tom