1
0
mirror of https://github.com/wfjm/w11.git synced 2026-01-12 00:43:01 +00:00
wfjm.w11/doc/simh_diff_jsr_sp.md
wfjm 00559faaaa minor updates
- tools
  - asm-11/lib/defs_xu.mac: add xt.* and xr.* definitions
  - oskit/211bsd_rk/211bsd_rk_boot.ecmd: add tt1: mode: definition
  - tcl/rw11/shell.tcl: update '.h' and '.ha' text output
  - tcode/cpu_basics.mac: A4.4: change exemptions, e11 now like 11/70 and w11
2023-05-19 17:34:57 +02:00

56 lines
2.2 KiB
Markdown

## Known differences between SimH, 11/70, and w11a
### SimH: `JSR SP` pushes modified `SP` value
In the logic of the `JSR` instruction is the given register the
_linkage register_, meant to be used for parameter passing.
`JSR` pushes the _linkage register_ to the stack, and the matching `RTS`
will restore it. That works fine for `R0` to `R5` and for `PC`.
But in a `JSR SP` that interferes with the implicit use of `SP`
as the stack pointer, `SP` is saved on the stack which is defined by `SP`.
The question is whether the original `SP` value is saved, or the `SP`
value after it has been decremented to hold the address for the write
to stack. The specification simply says
```
down(sp) := sp
```
and the question is whether the side effect of the left side happens before
the right side is evaluated.
The 11/70 implementation saves the value of the linkage register value in
an internal register in `JSR.00` before the `SP` is decremented in `JSR.20`
and write the saved valued to stack in `JSR.30`. See flow 11:
```
JSR.00: PCA := DR ; save dst addr in PCA
SR := GS[SF] if -SF7 ; get modified source field reg to SR
SR := PCB if SF7 ; get modified source field reg to SR
JSR.10: DR := GS[6] ; get SP
BR := SR ; get modified source field reg to BR
JSR.20 DR,GR[6] := DR-2 ; step SP back for push
JSR.30 write BR to DR ; write old source field to stack
JSR.40 GR[SF] := PCB ; old PC goes to src field reg
PCB := PCA ; dst addr goes tp PC
```
Therefore, the 11/70 writes the original `SP` value.
SimH writes the modified `SP`
```c
srcspec = srcspec & 07;
dst = GeteaW (dstspec);
SP = (SP - 2) & 0177777;
WriteW (R[srcspec], SP | dsenable);
R[srcspec] = PC;
JMP_PC (dst & 0177777);
```
`JSR SP` is never used due to its bizarre behavior. The matching `RTS SP`
results in a useless `SP` too. Given that, this is considered an
acceptable deviation from 11/70 behavior.
The w11 correctly implements the 11/70 behavior.
This is verified in a [tcode](../tools/tcode/README.md), the test is
modified when executed on SimH
(see [cpu_basics](../tools/tcode/cpu_basics.mac) tests A4.4).
Tested with SimH V3.12-3.