sim: sim_moves: handle MOVMS, add unit tests

This commit is contained in:
Mikael Pettersson
2020-07-16 18:20:55 +02:00
parent 97ce9c742d
commit 05ec9c75dd
3 changed files with 40 additions and 0 deletions

View File

@@ -246,6 +246,7 @@ dispatch(Core, Mem, IR, EA) ->
8#214 -> sim_moves:handle_MOVM(Core, Mem, IR, EA);
8#215 -> sim_moves:handle_MOVEI(Core, Mem, IR, EA); % MOVMI = MOVEI
8#216 -> sim_moves:handle_MOVMM(Core, Mem, IR, EA);
8#217 -> sim_moves:handle_MOVMS(Core, Mem, IR, EA);
8#250 -> sim_moves:handle_EXCH(Core, Mem, IR, EA);
_ ->
PC = (Core#core.pc_section bsl 18) bor Core#core.pc_offset,

View File

@@ -31,6 +31,7 @@
, handle_MOVES/4
, handle_MOVM/4
, handle_MOVMM/4
, handle_MOVMS/4
, handle_MOVN/4
, handle_MOVNI/4
, handle_MOVNM/4
@@ -256,6 +257,19 @@ handle_MOVMM(Core, Mem, IR, EA) ->
{Magnitude, Flags} = magnitude(CA),
handle_MOVNM(Core, Mem, Magnitude, Flags, EA).
-spec handle_MOVMS(#core{}, sim_mem:mem(), IR :: word(), #ea{})
-> {#core{}, sim_mem:mem(), {ok, integer()} | {error, {module(), term()}}}.
handle_MOVMS(Core, Mem, IR, EA) ->
case sim_core:c(Core, Mem, EA) of
{ok, CE} ->
AC = IR band 8#17,
{Magnitude, Flags} = magnitude(CE),
handle_MOVNS(Core, Mem, AC, EA, Magnitude, Flags);
{error, Reason} ->
sim_core:page_fault(Core, Mem, ea_address(EA), read, Reason,
fun(Core1, Mem1) -> handle_MOVMS(Core1, Mem1, IR, EA) end)
end.
%% Miscellaneous ===============================================================
ea_address(#ea{section = Section, offset = Offset}) ->

View File

@@ -58,6 +58,7 @@
-define(OP_MOVM, 8#214).
-define(OP_MOVMI, 8#215).
-define(OP_MOVMM, 8#216).
-define(OP_MOVMS, 8#217).
-define(OP_EXCH, 8#250).
%% 2.1.1 Exchange Instruction ==================================================
@@ -337,6 +338,30 @@ movmm_test() ->
[ {#ea{section = 1, offset = 8#150, islocal = false}, 8#42} % C(1,,150) = 42
]).
movms_ac_test() ->
Prog =
[ {1, 8#100, ?INSN(?OP_MOVEI, 1, 0, 0, 0)} % 1,,100/ MOVEI 1,0
, {1, 8#101, ?INSN(?OP_MOVMS, 1, 0, 0, 8#150)} % 1,,101/ MOVMS 1,150
, {1, 8#102, ?INSN_INVALID} % 1,,102/ <invalid>
, {1, 8#150, (-8#42) band ((1 bsl 36) - 1)} % 1,,150/ -42
],
expect(Prog, [], {1, 8#102}, ?DEFAULT_FLAGS,
[ {#ea{section = 1, offset = 8#150, islocal = false}, 8#42} % C(1,,150) = 42
, {#ea{section = 1, offset = 1, islocal = false}, 8#42} % AC1 = 42
]).
movms_noac_test() ->
Prog =
[ {1, 8#100, ?INSN(?OP_MOVEI, 0, 0, 0, 0)} % 1,,100/ MOVEI 0,0
, {1, 8#101, ?INSN(?OP_MOVMS, 0, 0, 0, 8#150)} % 1,,101/ MOVMS 0,150
, {1, 8#102, ?INSN_INVALID} % 1,,102/ <invalid>
, {1, 8#150, (-8#42) band ((1 bsl 36) - 1)} % 1,,150/ -42
],
expect(Prog, [], {1, 8#102}, ?DEFAULT_FLAGS,
[ {#ea{section = 1, offset = 8#150, islocal = false}, 8#42} % C(1,,150) = 42
, {#ea{section = 1, offset = 0, islocal = false}, 0} % AC0 = 0
]).
%% Common code to run short sequences ==========================================
expect(Prog, ACs, ExpectedPC, ExpectedFlags, ExpectedEs) ->