ack/doc/em/mach.nr

361 lines
12 KiB
Plaintext
Raw Permalink Normal View History

1993-03-30 15:43:44 +00:00
.bp
.P1 "EM MACHINE LANGUAGE"
.PP
1984-06-29 14:46:39 +00:00
The EM machine language is designed to make program text compact
and to make decoding easy.
Compact program text has many advantages: programs execute faster,
programs occupy less primary and secondary storage and loading
programs into satellite processors is faster.
The decoding of EM machine language is so simple,
that it is feasible to use interpreters as long as EM hardware
machines are not available.
This chapter is irrelevant when back ends are used to
produce executable target machine code.
1993-03-30 15:43:44 +00:00
.P2 "Instruction encoding"
.PP
1984-06-29 14:46:39 +00:00
A design goal of EM is to make the
program text as compact as possible.
Decoding must be easy, however.
The encoding is fully byte oriented, without any small bit fields.
There are 256 primary opcodes, two of which are an escape to
two groups of 256 secondary opcodes each.
1993-03-30 15:43:44 +00:00
.QQ
1984-06-29 14:46:39 +00:00
EM instructions without arguments have a single opcode assigned,
possibly escaped:
1993-03-30 15:43:44 +00:00
.ta 12n 24n
1987-03-31 07:45:17 +00:00
.Dr 6
1984-06-29 14:46:39 +00:00
|--------------|
| opcode |
|--------------|
1987-03-31 07:45:17 +00:00
.De
or
.Dr 6
1984-06-29 14:46:39 +00:00
|--------------|--------------|
| escape | opcode |
|--------------|--------------|
1986-02-04 17:37:41 +00:00
.De
1984-06-29 14:46:39 +00:00
The encoding for instructions with an argument is more complex.
Several instructions have an address from the global data area
as argument.
Other instructions have different opcodes for positive
and negative arguments.
1993-03-30 15:43:44 +00:00
.LP
1984-06-29 14:46:39 +00:00
There is always an opcode that takes the next two bytes as argument,
high byte first:
1987-03-31 07:45:17 +00:00
.Dr 6
1984-06-29 14:46:39 +00:00
|--------------|--------------|--------------|
| opcode | hibyte | lobyte |
|--------------|--------------|--------------|
1987-03-31 07:45:17 +00:00
.De
or
.Dr 6
1984-06-29 14:46:39 +00:00
|--------------|--------------|--------------|--------------|
| escape | opcode | hibyte | lobyte |
|--------------|--------------|--------------|--------------|
1986-02-04 17:37:41 +00:00
.De
1984-06-29 14:46:39 +00:00
An extra escape is provided for instructions with four or eight byte arguments.
1986-02-04 17:37:41 +00:00
.Dr 6
1990-02-05 10:06:42 +00:00
|--------------|--------------|--------------| |--------------|
| ESCAPE | opcode | hibyte |...| lobyte |
|--------------|--------------|--------------| |--------------|
1986-02-04 17:37:41 +00:00
.De
1984-06-29 14:46:39 +00:00
For most instructions some argument values predominate.
The most frequent combinations of instruction and argument
will be encoded in a single byte, called a mini:
1986-02-04 17:37:41 +00:00
.Dr 6
1984-06-29 14:46:39 +00:00
|---------------|
|opcode+argument| (mini)
|---------------|
1986-02-04 17:37:41 +00:00
.De
1984-06-29 14:46:39 +00:00
The number of minis is restricted, because only
254 primary opcodes are available.
Many instructions have the bulk of their arguments
fall in the range 0 to 255.
Instructions that address global data have their arguments
distributed over a wider range,
but small values of the high byte are common.
For all these cases there is another encoding
that combines the instruction and the high byte of the argument
into a single opcode.
These opcodes are called shorties.
Shorties may be escaped.
1987-03-31 07:45:17 +00:00
.Dr 6
1984-06-29 14:46:39 +00:00
|--------------|--------------|
| opcode+high | lobyte | (shortie)
|--------------|--------------|
1987-03-31 07:45:17 +00:00
.De
or
.Dr 6
1984-06-29 14:46:39 +00:00
|--------------|--------------|--------------|
| escape | opcode+high | lobyte |
|--------------|--------------|--------------|
1986-02-04 17:37:41 +00:00
.De
1984-06-29 14:46:39 +00:00
Escaped shorties are useless if the normal encoding has a primary opcode.
Note that for some instruction-argument combinations
several different encodings are available.
It is the task of the assembler to select the shortest of these.
The savings by these mini and shortie
opcodes are considerable, about 55%.
1993-03-30 15:43:44 +00:00
.PP
1984-06-29 14:46:39 +00:00
Further improvements are possible:
the arguments of
many instructions are a multiple of the wordsize.
Some do also not allow zero as an argument.
If these arguments are divided by the wordsize and,
when zero is not allowed, then decremented by 1, more of them can
be encoded as shortie or mini.
The arguments of some other instructions
rarely or never assume the value 0, but start at 1.
The value 1 is then encoded as 0,
2 as 1 and so on.
1993-03-30 15:43:44 +00:00
.PP
1984-06-29 14:46:39 +00:00
Assigning opcodes to instructions by the assembler is completely
table driven.
For details see appendix B.
1993-03-30 15:43:44 +00:00
.P2 "Procedure descriptors"
.PP
1984-06-29 14:46:39 +00:00
The procedure identifiers used in the interpreter are indices
into a table of procedure descriptors.
Each descriptor contains:
1993-03-30 15:43:44 +00:00
.IP 1.
1984-06-29 14:46:39 +00:00
the number of bytes to be reserved for locals at each
invocation.
1993-03-30 15:43:44 +00:00
.br
1990-02-05 10:06:42 +00:00
This is a pointer-sized integer.
1993-03-30 15:43:44 +00:00
.IP 2.
1984-06-29 14:46:39 +00:00
the start address of the procedure
1993-03-30 15:43:44 +00:00
.P2 "Load format"
.PP
1984-06-29 14:46:39 +00:00
The EM machine language load format defines the interface between
the EM assembler/loader and the EM machine itself.
A load file consists of a header, the program text to be executed,
a description of the global data area and the procedure descriptor table,
in this order.
All integers in the load file are presented with the
least significant byte first.
1993-03-30 15:43:44 +00:00
.PP
1984-06-29 14:46:39 +00:00
The header has two parts: the first half (eight 16-bit integers)
aids in selecting
the correct EM machine or interpreter.
Some EM machines, for instance, may have hardware floating point
instructions.
.N
The header entries are as follows (bit 0 is rightmost):
1993-03-30 15:43:44 +00:00
.IP 1:
1984-06-29 14:46:39 +00:00
magic number (07255)
1993-03-30 15:43:44 +00:00
.IP 2:
1984-06-29 14:46:39 +00:00
flag bits with the following meaning:
1993-03-30 15:43:44 +00:00
.RS
.IP "bit 0"
1984-06-29 14:46:39 +00:00
TEST; test for integer overflow etc.
1993-03-30 15:43:44 +00:00
.IP "bit 1"
1984-06-29 14:46:39 +00:00
PROFILE; for each source line: count the number of memory
cycles executed.
1993-03-30 15:43:44 +00:00
.IP "bit 2"
1984-06-29 14:46:39 +00:00
FLOW; for each source line: set a bit in a bit map table if
instructions on that line are executed.
1993-03-30 15:43:44 +00:00
.IP "bit 3"
1984-06-29 14:46:39 +00:00
COUNT; for each source line: increment a counter if that line
is entered.
1993-03-30 15:43:44 +00:00
.IP "bit 4"
1984-06-29 14:46:39 +00:00
REALS; set if a program uses floating point instructions.
1993-03-30 15:43:44 +00:00
.IP "bit 5"
1984-06-29 14:46:39 +00:00
EXTRA; more tests during compiler debugging.
1993-03-30 15:43:44 +00:00
.RE
.IP 3:
1984-06-29 14:46:39 +00:00
number of unresolved references.
1993-03-30 15:43:44 +00:00
.IP 4:
1984-06-29 14:46:39 +00:00
version number; used to detect obsolete EM load files.
1993-03-30 15:43:44 +00:00
.IP 5:
1984-06-29 14:46:39 +00:00
wordsize ; the number of bytes in each machine word.
1993-03-30 15:43:44 +00:00
.IP 6:
1984-06-29 14:46:39 +00:00
pointer size ; the number of bytes available for addressing.
1993-03-30 15:43:44 +00:00
.IP 7:
1984-06-29 14:46:39 +00:00
unused
1993-03-30 15:43:44 +00:00
.IP 8:
1984-06-29 14:46:39 +00:00
unused
1993-03-30 15:43:44 +00:00
.LP
1984-06-29 14:46:39 +00:00
The second part of the header (eight entries, of pointer size bytes each)
describes the load file itself:
1993-03-30 15:43:44 +00:00
.IP 1:
1984-06-29 14:46:39 +00:00
NTEXT; the program text size in bytes.
1993-03-30 15:43:44 +00:00
.IP 2:
1984-06-29 14:46:39 +00:00
NDATA; the number of load-file descriptors (see below).
1993-03-30 15:43:44 +00:00
.IP 3:
1984-06-29 14:46:39 +00:00
NPROC; the number of entries in the procedure descriptor table.
1993-03-30 15:43:44 +00:00
.IP 4:
1984-06-29 14:46:39 +00:00
ENTRY; procedure number of the procedure to start with.
1993-03-30 15:43:44 +00:00
.IP 5:
1984-06-29 14:46:39 +00:00
NLINE; the maximum source line number.
1993-03-30 15:43:44 +00:00
.IP 6:
1984-06-29 14:46:39 +00:00
SZDATA; the address of the lowest uninitialized data byte.
1993-03-30 15:43:44 +00:00
.IP 7:
1984-06-29 14:46:39 +00:00
unused
1993-03-30 15:43:44 +00:00
.IP 8:
1984-06-29 14:46:39 +00:00
unused
1993-03-30 15:43:44 +00:00
.PP
1984-06-29 14:46:39 +00:00
The program text consists of NTEXT bytes.
NTEXT is always a multiple of the wordsize.
The first byte of the program text is the
first byte of the instruction address
space, i.e. it has address 0.
Pointers into the program text are found in the procedure descriptor
table where relocation is simple and in the global data area.
The initialization of the global data area allows easy
relocation of pointers into both address spaces.
1993-03-30 15:43:44 +00:00
.PP
1984-06-29 14:46:39 +00:00
The global data area is described by the NDATA descriptors.
Each descriptor describes a number of consecutive words (of~wordsize)
and consists of a sequence of bytes.
While reading the descriptors from the load file, one can
initialize the global data area from low to high addresses.
The size of the initialized data area is given by SZDATA,
this number can be used to check the initialization.
1993-03-30 15:43:44 +00:00
.br
1984-06-29 14:46:39 +00:00
The header of each descriptor consists of a byte, describing the type,
and a count.
The number of bytes used for this (unsigned) count depends on the
type of the descriptor and
is either a pointer-sized integer
or one byte.
The meaning of the count depends on the descriptor type.
At load time an interpreter can
perform any conversion deemed necessary, such as
reordering bytes in integers
and pointers and adding base addresses to pointers.
1993-03-30 15:43:44 +00:00
.QQ
1984-06-29 14:46:39 +00:00
In the following pictures we show a graphical notation of the
initializers.
The leftmost rectangle represents the leading byte.
1993-03-30 15:43:44 +00:00
.LP
1984-06-29 14:46:39 +00:00
Fields marked with
1993-03-30 15:43:44 +00:00
.TS
tab(:);
l l.
n:contain a pointer-sized integer used as a count
m:contain a one-byte integer used as a count
b:contain a one-byte integer
w:contain a wordsized integer
p:contain a data or instruction pointer
s:contain a null terminated ASCII string
.TE
1986-02-04 17:37:41 +00:00
.Dr 6
1984-06-29 14:46:39 +00:00
-------------------
| 0 | n | repeat last initialization n times
-------------------
1986-02-04 17:37:41 +00:00
.De
.Dr 4
1984-06-29 14:46:39 +00:00
---------
| 1 | m | m uninitialized words
---------
1986-02-04 17:37:41 +00:00
.De
.Dr 6
1984-06-29 14:46:39 +00:00
____________
/ bytes \e
----------------- -----
| 2 | m | b | b |...| b | m initialized bytes
----------------- -----
1986-02-04 17:37:41 +00:00
.De
.Dr 6
1984-06-29 14:46:39 +00:00
_________
/ word \e
-----------------------
| 3 | m | w |... m initialized wordsized integers
-----------------------
1986-02-04 17:37:41 +00:00
.De
.Dr 6
1984-06-29 14:46:39 +00:00
_________
/ pointer \e
-----------------------
| 4 | m | p |... m initialized data pointers
-----------------------
1986-02-04 17:37:41 +00:00
.De
.Dr 6
1984-06-29 14:46:39 +00:00
_________
/ pointer \e
-----------------------
| 5 | m | p |... m initialized instruction pointers
-----------------------
1986-02-04 17:37:41 +00:00
.De
.Dr 6
1984-06-29 14:46:39 +00:00
____________
/ bytes \e
-------------------------
| 6 | m | b | b |...| b | initialized integer of size m
-------------------------
1986-02-04 17:37:41 +00:00
.De
.Dr 6
1984-06-29 14:46:39 +00:00
____________
/ bytes \e
-------------------------
| 7 | m | b | b |...| b | initialized unsigned of size m
-------------------------
1986-02-04 17:37:41 +00:00
.De
.Dr 6
1984-06-29 14:46:39 +00:00
____________
/ string \e
-------------------------
| 8 | m | s | initialized float of size m
-------------------------
1990-02-05 10:06:42 +00:00
.De
1993-03-30 15:43:44 +00:00
.IP type~0: 10
1984-06-29 14:46:39 +00:00
If the last initialization initialized k bytes starting
at address \fIa\fP, do the same initialization again n times,
starting at \fIa\fP+k, \fIa\fP+2*k, .... \fIa\fP+n*k.
This is the only descriptor whose starting byte
is followed by an integer with the
size of a
pointer,
in all other descriptors the first byte is followed by a one-byte count.
This descriptor must be preceded by a descriptor of
another type.
1993-03-30 15:43:44 +00:00
.IP type~1: 10
1984-06-29 14:46:39 +00:00
Reserve m words, not explicitly initialized (BSS and HOL).
1993-03-30 15:43:44 +00:00
.IP type~2: 10
1984-06-29 14:46:39 +00:00
The m bytes following the descriptor header are
initializers for the next m bytes of the
global data area.
m is divisible by the wordsize.
1993-03-30 15:43:44 +00:00
.IP type~3: 10
1984-06-29 14:46:39 +00:00
The m words following the header are initializers for the next m words of the
global data area.
1993-03-30 15:43:44 +00:00
.IP type~4: 10
1984-06-29 14:46:39 +00:00
The m data address space pointers following the header are
initializers for the next
m data pointers in the global data area.
Interpreters that represent EM pointers by
target machine addresses must relocate all data pointers.
1993-03-30 15:43:44 +00:00
.IP type~5: 10
1984-06-29 14:46:39 +00:00
The m instruction address space pointers following the header are
initializers for the next
m instruction pointers in the global data area.
Interpreters that represent EM instruction pointers by
target machine addresses must relocate these pointers.
1993-03-30 15:43:44 +00:00
.IP type~6: 10
1984-06-29 14:46:39 +00:00
The m bytes following the header form
a signed integer number with a size of m bytes,
which is an initializer for the next m bytes
of the global data area.
m is governed by the same restrictions as for
transfer of objects to/from memory.
1993-03-30 15:43:44 +00:00
.IP type~7: 10
1984-06-29 14:46:39 +00:00
The m bytes following the header form
an unsigned integer number with a size of m bytes,
which is an initializer for the next m bytes
of the global data area.
m is governed by the same restrictions as for
transfer of objects to/from memory.
1993-03-30 15:43:44 +00:00
.IP type~8: 10
1984-06-29 14:46:39 +00:00
The header is followed by an ASCII string, null terminated, to
initialize, in global data,
a floating point number with a size of m bytes.
m is governed by the same restrictions as for
transfer of objects to/from memory.
The ASCII string contains the notation of a real as used in the
Pascal language.
1993-03-30 15:43:44 +00:00
.PP
1984-06-29 14:46:39 +00:00
The NPROC procedure descriptors on the load file consist of
an instruction space address (of~pointer~size) and
an integer (of~pointer~size) specifying the number of bytes for
locals.