PDP-11: Magic constant at address 2 - Unix

This is a discussion on PDP-11: Magic constant at address 2 - Unix ; If you look at a low.s file from a PDP-11 UNIX source, you'll see that
the first instruction at address 0 is a short branch, then, at address
2, is a magic constant 4, e.g.
http://minnie.tuhs.org/UnixTree/V5/u...onf/low.s.html
http://minnie.tuhs.org/UnixTree/V7/u.../conf/l.s.html
What was the ...

What was the reason for this constant? It is unlikely that is is used
as PSW for the hypothetical interrupt vector 0, as the branch
instruction to address 40 is an odd number (000417) and cannot serve as
an
address.

Re: PDP-11: Magic constant at address 2

There are/were several "magic" words, 0407, 0410, 0413, ... The number
depended on the actual size of the a.out header, i.e. how many words
that needed to be jumped over.

From what I remeber 0407 was was an executable with writable text,
i.e. the machine code was put in the data segment. 0410 was one word
larger and put the code in the text segment. 0413 was a demand paged
binary.

I never programmed the pdp-11, but the a.out headers were wrapped
inside the COFF (Common Object File Format) header on the sys-V 68k I
did program in the early 80:s.

AFAIK the PC in a pdp-11 counts (16 bit) words, not bytes. There was
no way you could jump to an odd byte.

That's irrelevant to the question. The code I'm asking about is
*within* the code segment of the kernel.
> AFAIK the PC in a pdp-11 counts (16 bit) words, not bytes. There was
> no way you could jump to an odd byte.

No, the PC counts bytes but the offsets in the branch instructions are
in words. The fact that an odd value cannot serve as a PC is exactly my
point.

Re: PDP-11: Magic constant at address 2

"The eight bits of the offset are interpreted as the high eight bits
of a nine-bit signed offset whose last bit is zero. Thus if the
condition is met, we do R7
So your 017 offset is really 036.

I.e. you can not branch to an odd address, unless R7 was odd to start
with, which I assume is impossible.

So the PC counts bytes, but the offset count words.

Re: PDP-11: Magic constant at address 2

Thomas Tornblom wrote:
> Please have a read of:
> http://www.dgp.toronto.edu/~ajr/258/pdp11.pdf
>
> I quote from page 4:
>
> "The eight bits of the offset are interpreted as the high eight bits
> of a nine-bit signed offset whose last bit is zero. Thus if the
> condition is met, we do R7
>
> So your 017 offset is really 036.

I am very familiar with the PDP-11 instruction set, thank you. Let's
reiterate:

The interrupt vectors have the target PC in the first word, the PSW in
the second.
The branch instruction 000417 is odd, therefore it cannot serve as a PC
for an interrupt vector (thus disproving the hypothesis that the
interrupt vector 0 was used), and the word at address 2 is not a PSW of
any interrupt vector.