Seventh Edition Unix on the PDP-11 used a 16-bit form of a.out, described in
its a.out(5) manual page. Numbers below are octal, as in the manual. The
header has eight fields in 020 (16) bytes, so each field is a 16-bit word, and the
symbol entries use the same word size. The words are stored little-endian, the
PDP-11’s own order: checked on the 80 real Fifth Edition programs and objects of the UNIX disk image that
ships with the PDP-11 emulator on this site (the Seventh Edition manual page does not say). The
Fifth Edition header is the same eight words, and in every one of those files the file size is exactly
020 + text + data + (relocation, only when the flag is 0) + symbols.
Header
| Offset (octal) | Size | Field | Meaning |
|---|---|---|---|
00 | 2 | a_magic | Magic number, below. |
02 | 2 | a_text | Size of the text segment. |
04 | 2 | a_data | Size of the initialised data. |
06 | 2 | a_bss | Size of the uninitialised data. |
010 | 2 | a_syms | Size of the symbol table. |
012 | 2 | a_entry | Entry point. |
014 | 2 | a_unused | Not used. |
016 | 2 | a_flag | Set if the relocation information has been stripped. |
Sizes are in bytes, always even, and do not include the header.
Magic numbers
| Octal | Meaning |
|---|---|
0407 | Normal: the text is not write-protected or shared, and the data follows the text directly. |
0410 | Read-only text shared between processes; the data starts at the next 8K boundary after the text. |
0411 | Separate instruction and data spaces: the text is pure and shared, and text and data both start at address 0. |
0405 | Overlay: the text replaces that of a running 0411 or 0405 program, and the data segment is kept. |
Layout
Header, text, data, relocation, symbol table. The relocation and symbol parts may
be empty after ld -s or strip(1). With St the text
size and Sd the data size:
| Part | File offset (octal) |
|---|---|
| text | 020 |
| data | 020 + St |
| relocation | 020 + St + Sd |
| symbol table | 020 + 2(St + Sd) with relocation, 020 + St + Sd without |
The header is not loaded into memory. The text starts at address 0; uninitialised
data follows initialised data and starts as zeros. The stack starts at the top of the
address space (0177776) and grows down.
Relocation words
There is one 16-bit relocation word for each word of text and initialised data, so the relocation part is as long as text and data together.
| Bits | Meaning |
|---|---|
| 0 | 1: the reference is PC-relative; 0: a reference to the actual symbol. |
| 3–1 | Segment, as the value of the word with bit 0 clear: 00 absolute number, 02 text segment, 04 initialised data, 06 BSS, 010 undefined external. |
| 15–4 | For an external reference, the symbol’s number in the symbol table (from 0); unused otherwise. |
The value of a text or data word that is not a reference to an undefined external symbol is exactly the value that will be in memory when the program runs. When a word does refer to an undefined external symbol (as its relocation word says), the stored word is an offset from that symbol: the link editor adds the symbol’s value to it once the symbol is defined. There is no relocation information when the “relocation stripped” flag in the header is set.
Symbol table
| Offset | Size | Field | Meaning |
|---|---|---|---|
0 | 8 | n_name | Name, 8 characters. |
8 | 2 | n_type | Type, below. |
10 | 2 | n_value | Value. |
| Octal | Name | Meaning |
|---|---|---|
0 | N_UNDF | undefined |
01 | N_ABS | absolute |
02 | N_TEXT | text symbol |
03 | N_DATA | data symbol |
04 | N_BSS | BSS symbol |
024 | N_REG | register name |
037 | N_FN | file name symbol |
037 | N_TYPE | mask for the type bits |
040 | N_EXT | external bit, ORed in |
The manual lists these as the principal flag values and adds that other values may occur if an assembly language program defines machine instructions; the explorer shows such a value as its number.
An undefined external symbol with a non-zero value is taken by ld as a
common area of that size.
In the explorer
A file that starts with one of the four magic numbers, written little-endian (07 01 for 0407), whose sizes make it exactly as long as it is, opens as a
PDP-11 a.out program: the header field by field, the segments and the process image, the relocation words, the symbol table, the strings in the data, and the
text disassembled at address 0 with the PDP-11 decoder in UNIX assembler syntax. A symbol names its address, a relocation word marks the instruction it belongs to, and a
trap (written sys) is named with the call it makes. The test is strict, because the same extensions also hold ELF, Mach-O and other files:
the size rule, an even size for every part, a symbol table of whole 12-byte entries, a flag of 0 or 1, and an image that fits in 64 KB.
Code and data are not told apart, the data is not decoded, and the 0410 data gap is shown as a note, not as address space. The system call names are those of the Seventh Edition; the numbers the Fifth Edition programs on the disk image use for the calls they share are the same.
System calls
A system call is the instruction trap n, written sys n in the UNIX assembler. Its arguments are in registers R0 and R1 and in the words that
follow the instruction, which the kernel skips over: sys write is followed by the buffer address and the count, with the file descriptor in R0. sys 0 (indir) is followed by the address of a block that holds the real call.
The table is the Seventh Edition kernel’s sysent: the arguments column counts words (a long is two), the next column how many go in registers, so the words after the instruction are the difference (our reading of the table).
A number in parentheses is reserved or unused. The explorer names the call under each trap.
| Octal | Number | Name | Arguments | In registers |
|---|---|---|---|---|
0 | 0 | indir | 0 | 0 |
1 | 1 | exit | 1 | 1 |
2 | 2 | fork | 0 | 0 |
3 | 3 | read | 3 | 1 |
4 | 4 | write | 3 | 1 |
5 | 5 | open | 2 | 0 |
6 | 6 | close | 1 | 1 |
7 | 7 | wait | 0 | 0 |
10 | 8 | creat | 2 | 0 |
11 | 9 | link | 2 | 0 |
12 | 10 | unlink | 1 | 0 |
13 | 11 | exec | 2 | 0 |
14 | 12 | chdir | 1 | 0 |
15 | 13 | time | 0 | 0 |
16 | 14 | mknod | 3 | 0 |
17 | 15 | chmod | 2 | 0 |
20 | 16 | chown | 3 | 0 |
21 | 17 | break | 1 | 0 |
22 | 18 | stat | 2 | 0 |
23 | 19 | seek | 4 | 1 |
24 | 20 | getpid | 0 | 0 |
25 | 21 | mount | 3 | 0 |
26 | 22 | umount | 1 | 0 |
27 | 23 | setuid | 1 | 1 |
30 | 24 | getuid | 0 | 0 |
31 | 25 | stime | 2 | 2 |
32 | 26 | ptrace | 4 | 1 |
33 | 27 | alarm | 1 | 1 |
34 | 28 | fstat | 2 | 1 |
35 | 29 | pause | 0 | 0 |
36 | 30 | utime | 2 | 0 |
37 | 31 | stty | 2 | 1 |
40 | 32 | gtty | 2 | 1 |
41 | 33 | access | 2 | 0 |
42 | 34 | nice | 1 | 1 |
43 | 35 | ftime | 1 | 0 |
44 | 36 | sync | 0 | 0 |
45 | 37 | kill | 2 | 1 |
46 | 38 | switch | 0 | 0 |
47 | 39 | setpgrp | 0 | 0 |
50 | 40 | tell | 1 | 1 |
51 | 41 | dup | 2 | 2 |
52 | 42 | pipe | 0 | 0 |
53 | 43 | times | 1 | 0 |
54 | 44 | prof | 4 | 0 |
55 | 45 | (unused) | 0 | 0 |
56 | 46 | setgid | 1 | 1 |
57 | 47 | getgid | 0 | 0 |
60 | 48 | sig | 2 | 0 |
61 | 49 | (reserved for USG) | 0 | 0 |
62 | 50 | (reserved for USG) | 0 | 0 |
63 | 51 | acct | 1 | 0 |
64 | 52 | phys | 3 | 0 |
65 | 53 | lock | 1 | 0 |
66 | 54 | ioctl | 3 | 0 |
67 | 55 | (readwrite) | 0 | 0 |
70 | 56 | mpxchan | 4 | 0 |
71 | 57 | (reserved for USG) | 0 | 0 |
72 | 58 | (reserved for USG) | 0 | 0 |
73 | 59 | exece | 3 | 0 |
74 | 60 | umask | 1 | 0 |
75 | 61 | chroot | 1 | 0 |
76 | 62 | (unused) | 0 | 0 |
77 | 63 | (used internally) | 0 | 0 |
Not described
Known, not yet covered
- Reference: the First to Fourth Edition headers (the Fifth Edition header read here is the same eight words), the magic numbers
0430and0431of some later systems, the 2.11BSD form, and the Sixth Edition call table (calls 0 to 48 differ from the Seventh in a few places). - Viewer: the code is every even offset decoded as an instruction, the data is not decoded, and the words after a system call are decoded as instructions too.
Unknown
- What the second argument-count column of
sysentis called in the kernel source (it is read here as the number of arguments passed in registers).
Sources
The Seventh Edition a.out(5) manual page, as reproduced at
typewritten.org.
The system call table is the Seventh Edition kernel’s sysent.c
(its text read in full and compared with the table above: all 64 rows agree in the two counts; the names are the comments of the source, shortened for calls 51 to 57; call 62 is just “x” there). The byte order, the size rule and the 12-byte symbol entries were checked on the real
Fifth Edition programs of the UNIX disk image that ships with the
PDP-11 emulator.
Links
Reference
- PDP-11 instruction set – the processor these programs run on
- UNIX Assembler Reference Manual – the assembler syntax the viewer writes