From 89686df60c35921c98c79b05100ba9253bae9b4c Mon Sep 17 00:00:00 2001 From: Mikael Pettersson Date: Fri, 17 Jul 2020 20:18:27 +0200 Subject: [PATCH] sim: sim_moves: handle DMOVEM, add unit test --- erlang/apps/sim/src/sim_core.erl | 1 + erlang/apps/sim/src/sim_moves.erl | 19 +++++++++++++++++++ erlang/apps/sim/test/sim_moves_tests.erl | 15 +++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/erlang/apps/sim/src/sim_core.erl b/erlang/apps/sim/src/sim_core.erl index c68585e..a01c838 100644 --- a/erlang/apps/sim/src/sim_core.erl +++ b/erlang/apps/sim/src/sim_core.erl @@ -232,6 +232,7 @@ dispatch(Core, Mem, IR, EA) -> case IR bsr 4 of 8#104 -> sim_kernel:handle_JSYS(Core, Mem, IR, EA); 8#120 -> sim_moves:handle_DMOVE(Core, Mem, IR, EA); + 8#124 -> sim_moves:handle_DMOVEM(Core, Mem, IR, EA); 8#200 -> sim_moves:handle_MOVE(Core, Mem, IR, EA); 8#201 -> sim_moves:handle_MOVEI(Core, Mem, IR, EA); 8#202 -> sim_moves:handle_MOVEM(Core, Mem, IR, EA); diff --git a/erlang/apps/sim/src/sim_moves.erl b/erlang/apps/sim/src/sim_moves.erl index 7fba568..1764ff0 100644 --- a/erlang/apps/sim/src/sim_moves.erl +++ b/erlang/apps/sim/src/sim_moves.erl @@ -26,6 +26,7 @@ -export([ handle_EXCH/4 , handle_DMOVE/4 + , handle_DMOVEM/4 , handle_MOVE/4 , handle_MOVEI/4 , handle_MOVEM/4 @@ -298,6 +299,24 @@ handle_DMOVE(Core, Mem, IR, EA, Word0) -> fun(Core1, Mem1) -> handle_DMOVE(Core1, Mem1, IR, EA, Word0) end) end. +%% DMOVEM - Double Move to Memory + +-spec handle_DMOVEM(#core{}, sim_mem:mem(), IR :: word(), #ea{}) + -> {#core{}, sim_mem:mem(), {ok, integer()} | {error, {module(), term()}}}. +handle_DMOVEM(Core, Mem, IR, EA) -> + AC = IR band 8#17, + Word0 = sim_core:get_ac(Core, AC), + Word1 = sim_core:get_ac(Core, ac_plus_1(AC)), + handle_DMOVEM(Core, Mem, Word0, Word1, EA). + +handle_DMOVEM(Core, Mem, Word0, Word1, EA) -> + case sim_core:cset(Core, Mem, EA, Word0) of + {ok, Core1} -> handle_MOVEM_1(Core1, Mem, Word1, ea_plus_1(EA)); + {error, Reason} -> + sim_core:page_fault(Core, Mem, ea_address(EA), write, Reason, + fun(Core1, Mem1) -> handle_DMOVEM(Core1, Mem1, Word0, Word1, EA) end) + end. + %% Miscellaneous =============================================================== ac_plus_1(AC) -> diff --git a/erlang/apps/sim/test/sim_moves_tests.erl b/erlang/apps/sim/test/sim_moves_tests.erl index 87d61b4..270a7a3 100644 --- a/erlang/apps/sim/test/sim_moves_tests.erl +++ b/erlang/apps/sim/test/sim_moves_tests.erl @@ -44,6 +44,7 @@ -define(OP_INVALID, 0). -define(OP_DMOVE, 8#120). +-define(OP_DMOVEM, 8#124). -define(OP_MOVE, 8#200). -define(OP_MOVEI, 8#201). -define(OP_MOVEM, 8#202). @@ -377,6 +378,20 @@ dmove_test() -> , {#ea{section = 1, offset = 0, islocal = false}, 8#27} % AC0 = 27 ]). +dmovem_test() -> + Prog = + [ {1, 8#100, ?INSN(?OP_MOVEI, 1, 0, 0, 8#42)} % 1,,100/ MOVEI 1,42 + , {1, 8#101, ?INSN(?OP_MOVEI, 2, 0, 0, 8#27)} % 1,,101/ MOVEI 2,27 + , {1, 8#102, ?INSN(?OP_DMOVEM, 1, 0, 0, 8#150)} % 1,,102/ MOVEM 1,150 + , {1, 8#103, ?INSN_INVALID} % 1,,103/ + , {1, 8#150, 0} % 1,,150/ 0 + , {1, 8#151, 0} % 1,,151/ 0 + ], + expect(Prog, [], {1, 8#103}, ?DEFAULT_FLAGS, + [ {#ea{section = 1, offset = 8#150, islocal = false}, 8#42} % C(1,,150) = 42 + , {#ea{section = 1, offset = 8#151, islocal = false}, 8#27} % C(1,,151) = 27 + ]). + %% Common code to run short sequences ========================================== expect(Prog, ACs, ExpectedPC, ExpectedFlags, ExpectedEs) ->