T2-64 code
T2-code for som 5.1. The instructions are exactly the same as v5, only
the encoding is different. To simplify everything only one format
(3-arg) is used (instead of two formats)
3-arg a:16 c:10 op:6, b:32
op is 6 bits. b is 32 bits so it does not need decoding. Some
instructions use only 32 bits.
bop
dest
(c), src1(a), src2 (b) ;; c = a op b
ldx dest (c), idx (a), base
(b)
stx src (c), idx (a),
base (b)
not dest (c), src (a)
jmp disp (a)
jt disp (a), src (c)
jop disp (a), src1 (c),
src2 (b)
efor disp (a), src+ (c), src2 (b)
disp of jump is 16 bits so use (a).
fun
arty
(a), fs (c)
ret src (a), fs (c)
push src (a)
Give as large source as possible (16 bits). To reduce the chance of
argument not fit into the field, we use the
larger field first (as a priority). Therefore "call" use "a" then "c"
and "sys" use "b" then "a".
call
arg2
(c), arg1 (a), ads (b)
sys num (c), src2
(a), src1 (b)
case src (c),
lo (a), hi (b)
mov is an exception, it uses largest dest/src to access large address
space and to move values around.
2-arg d:26 op:6, b:32
mov
dest
(d), src (b)
Note: There are 38 instructions, only 6 bits is necessary, so op code
field is 6 bits. That leaves 26 bits to be divided between two
arguments. One argument should be a bit large because it is used
as displacement in conditional jump instructions, so it is divided into
16-bit and 10-bit. This is a bit improvement from v5 which has
8-bit op and leaves only 16+8 bits for arguments. A 8-bit field is too
small because even a small immediate can hardly be fitted.
case instruction
case
src lo hi
<jmp table>
$end
The jump table is a table of displacement relative to the address of
"case" instruction. Each entry is a 32-bit value. The size of the table
will be padded at the end so that the address $end aligns at an even
address. Its organisation is as follows:
disp.
to the end of table, the "else" case
disp. to case lo
(case_1)
disp. to case lo+1 (case_2)
....
disp. to case hi
(case_n)
<pad>
$end:
jmp
else_case
case_1: ... , jmp exit
case_2: ... , jmp exit
...
case_n: ... , jmp exit
else_case: ...
$exit
The first entry in the table is the displacement to $end. It is
used to jump to else_case. This arrangement makes it easy to
locate the end of the table. The jump table is fully mapped to values
in the range lo..hi. It is a direct map. Any missing label
will be filled with a displacement to $end (so it goes to else_case).
The size of table is even(hi-lo+2).
The code for body of each case is located after the end of table. The
first instruction at the end of table is "jmp else_case". Each case is
ended with "jmp exit".
20 Dec 2010