sim: sim_boolean: handle SETMI/XMOVEI, add unit tests

This commit is contained in:
Mikael Pettersson
2020-07-23 18:46:32 +02:00
parent dcfe8cafab
commit 40c36a5f6e
4 changed files with 83 additions and 0 deletions

View File

@@ -32,6 +32,7 @@
, handle_ANDCAM/4
, handle_ANDI/4
, handle_ANDM/4
, handle_SETMI/4
, handle_SETZ/4
, handle_SETZB/4
, handle_SETZM/4
@@ -191,6 +192,20 @@ handle_ANDCAB(Core, Mem, IR, EA) ->
fun(Core1, Mem1) -> handle_ANDCAB(Core1, Mem1, IR, EA) end)
end.
%% SETM - Set to Memory
-spec handle_SETMI(#core{}, sim_mem:mem(), IR :: word(), #ea{})
-> {#core{}, sim_mem:mem(), {ok, integer()} | {error, {module(), term()}}}.
handle_SETMI(Core, Mem, IR, #ea{section = Section0, offset = Offset, islocal = IsLocal}) ->
AC = IR band 8#17,
%% Behave as MOVEI in section 0, and as XMOVEI (2.1.3) in non-zero sections.
Section1 =
if IsLocal, Offset =< 8#17, Section0 > 1 -> 1; % change local AC address to global one
true -> Section0
end,
Word = (Section1 bsl 18) bor Offset,
sim_core:next_pc(sim_core:set_ac(Core, AC, Word), Mem).
%% Miscellaneous ===============================================================
ea_address(#ea{section = Section, offset = Offset}) ->

View File

@@ -266,6 +266,7 @@ dispatch(Core, Mem, IR, EA) ->
8#412 -> sim_boolean:handle_ANDCAM(Core, Mem, IR, EA);
8#413 -> sim_boolean:handle_ANDCAB(Core, Mem, IR, EA);
8#414 -> sim_moves:handle_MOVE(Core, Mem, IR, EA); % SETM = MOVE
8#415 -> sim_boolean:handle_SETMI(Core, Mem, IR, EA); % SETMI = MOVEI in section 0, XMOVEI elsewhere
_ ->
PC = (Core#core.pc_section bsl 18) bor Core#core.pc_offset,
{Core, Mem, {error, {?MODULE, {dispatch, PC, IR, EA}}}}

View File

@@ -56,6 +56,8 @@
-define(OP_ANDCAM, 8#412).
-define(OP_ANDCAB, 8#413).
-define(OP_SETM, 8#414).
-define(OP_SETMI, 8#415).
-define(OP_XMOVEI, ?OP_SETMI).
%% 2.4 Boolean Functions =======================================================
@@ -207,6 +209,55 @@ setm_test() ->
[ {#ea{section = 1, offset = 1, islocal = false}, 8#42} % AC1 = 42
]).
setmi_test() ->
%% In section 0, SETMI = MOVEI.
Prog =
[ {0, 8#100, ?INSN(?OP_SETMI, 1, 0, 0, 8#200)} % 0,,100/ SETMI 1,200
, {0, 8#101, ?INSN_INVALID} % 0,,101/ <invalid>
],
expect(Prog, [], {0, 8#101}, ?DEFAULT_FLAGS,
[ {#ea{section = 1, offset = 1, islocal = false}, 8#200} % AC1 = 200
]).
xmovei_ac_test() ->
%% In sections > 0, SETMI = XMOVEI.
%% Check that a local AC address is converted to a global one.
Prog =
[ {2, 8#100, ?INSN(?OP_XMOVEI, 1, 0, 0, 6)} % 2,,100/ XMOVEI 1,6
, {2, 8#101, ?INSN_INVALID} % 2,,101/ <invalid>
],
expect(Prog, [], {2, 8#101}, ?DEFAULT_FLAGS,
[ {#ea{section = 1, offset = 1, islocal = false}, ?COMMA2(1, 6)} % AC1 = 1,,6
]).
xmovei_section_zero_ac_test() ->
%% In sections > 0, SETMI = XMOVEI.
%% Check that a local AC address in section zero is not converted to a global one.
%% See "Extended Addressing", Rev. 5, Jul. 1983, KC10 / Project Jupiter docs,
%% section 8.10, second example. The example is incorrect, in that its
%% EA-calculation dereferences an uninitialized word. The third example in
%% section 7.0 shows the correct setup.
Prog =
[ {2, 8#100, ?INSN(?OP_XMOVEI, 1, 1, 0, 8#150)} % 2,,100/ XMOVEI 1,@150
, {2, 8#101, ?INSN_INVALID} % 2,,101/ <invalid>
, {2, 8#150, ?COMMA2(8#200000, 8#100)} % 2,,150/ 200000,,100 ; indirect EFIW
, {0, 8#100, ?COMMA2(0, 6)} % 0,,100/ 0,,6 ; IFIW
],
expect(Prog, [], {2, 8#101}, ?DEFAULT_FLAGS,
[ {#ea{section = 0, offset = 1, islocal = false}, 6} % AC1 = 0,,6
]).
xmovei_non_ac_test() ->
%% In sections > 0, SETMI = XMOVEI.
%% Check that an EA not denoting a local AC address is loaded as-is.
Prog =
[ {2, 8#100, ?INSN(?OP_XMOVEI, 1, 0, 0, 8#42)} % 2,,100/ XMOVEI 1,42
, {2, 8#101, ?INSN_INVALID} % 2,,101/ <invalid>
],
expect(Prog, [], {2, 8#101}, ?DEFAULT_FLAGS,
[ {#ea{section = 1, offset = 1, islocal = false}, ?COMMA2(2, 8#42)} % AC1 = 2,,42
]).
%% Common code to run short sequences ==========================================
expect(Prog, ACs, ExpectedPC, ExpectedFlags, ExpectedEs) ->

View File

@@ -151,6 +151,22 @@ multi_section_ea_calcs_7_0_test() ->
],
expect(Prog3, [], {3, 8#100}, #ea{section = 0, offset = 8#201, islocal = true}).
xmovei_and_xhlli_8_10_test() ->
Prog1 =
[ {2, 8#100, ?INSN(?OP_INVALID, 1, 0, 0, 6)} % 2,,100/ XMOVEI 1,6
],
expect(Prog1, [], {2, 8#100}, #ea{section = 2, offset = 6, islocal = true}),
%% The second example in 8.10 is broken, in that the EA-calculcation follows
%% an indirect EFIW into section zero expecting to find an IFIW at 0,,6.
%% Compare this with the third example in 7.0 which also defines the IFIW
%% that the indirect EFIW points to.
Prog2 =
[ {2, 8#100, ?INSN(?OP_INVALID, 1, 1, 0, 8#150)} % 2,,100/ XMOVEI 1,@150
, {2, 8#150, ?COMMA2(8#200000, 8#100)} % 2,,150/ 200000,,100 ; indirect EFIW
, {0, 8#100, ?COMMA2(0, 6)} % 0,,100/ 0,,6 ; IFIW
],
expect(Prog2, [], {2, 8#100}, #ea{section = 0, offset = 6, islocal = true}).
%% Remaining examples from the "Extended Addressing" document relate to
%% instructions using the EA not the initial EA calculation itself, and
%% they will be added as those instructions are implemented.