sim: sim_moves: handle DMOVE, add unit test

This commit is contained in:
Mikael Pettersson
2020-07-16 20:53:06 +02:00
parent 05ec9c75dd
commit 98249be331
3 changed files with 54 additions and 0 deletions

View File

@@ -231,6 +231,7 @@ dispatch(Core, Mem, IR, EA) ->
%% Dispatch on the opcode (top 9 bits).
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#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);

View File

@@ -25,6 +25,7 @@
-module(sim_moves).
-export([ handle_EXCH/4
, handle_DMOVE/4
, handle_MOVE/4
, handle_MOVEI/4
, handle_MOVEM/4
@@ -270,11 +271,48 @@ handle_MOVMS(Core, Mem, IR, EA) ->
fun(Core1, Mem1) -> handle_MOVMS(Core1, Mem1, IR, EA) end)
end.
%% 2.1.4 Double Move Instructions ==============================================
%% DMOVE - Double Move
-spec handle_DMOVE(#core{}, sim_mem:mem(), IR :: word(), #ea{})
-> {#core{}, sim_mem:mem(), {ok, integer()} | {error, {module(), term()}}}.
handle_DMOVE(Core, Mem, IR, EA) ->
case sim_core:c(Core, Mem, EA) of
{ok, Word0} ->
handle_DMOVE(Core, Mem, IR, ea_plus_1(EA), Word0);
{error, Reason} ->
sim_core:page_fault(Core, Mem, ea_address(EA), read, Reason,
fun(Core1, Mem1) -> handle_DMOVE(Core1, Mem1, IR, EA) end)
end.
handle_DMOVE(Core, Mem, IR, EA, Word0) ->
case sim_core:c(Core, Mem, EA) of
{ok, Word1} ->
AC = IR band 8#17,
Core1 = sim_core:set_ac(Core, AC, Word0),
Core2 = sim_core:set_ac(Core1, ac_plus_1(AC), Word1),
sim_core:next_pc(Core2, Mem);
{error, Reason} ->
sim_core:page_fault(Core, Mem, ea_address(EA), read, Reason,
fun(Core1, Mem1) -> handle_DMOVE(Core1, Mem1, IR, EA, Word0) end)
end.
%% Miscellaneous ===============================================================
ac_plus_1(AC) ->
(AC + 1) band 8#17.
ea_address(#ea{section = Section, offset = Offset}) ->
(Section bsl 18) bor Offset.
ea_plus_1(#ea{offset = Offset, islocal = true} = EA) ->
EA#ea{offset = (Offset + 1) band ((1 bsl 18) - 1)};
ea_plus_1(#ea{section = Section, offset = ((1 bsl 18) - 1)} = EA) ->
EA#ea{section = (Section + 1) band ((1 bsl 12) - 1), offset = 0};
ea_plus_1(#ea{offset = Offset} = EA) ->
EA#ea{offset = Offset + 1}.
magnitude(Word) ->
case Word band (1 bsl 35) of
0 -> % non-negative

View File

@@ -43,6 +43,7 @@
-define(INSN_INVALID, ?INSN(0, 0, 0, 0, 0)).
-define(OP_INVALID, 0).
-define(OP_DMOVE, 8#120).
-define(OP_MOVE, 8#200).
-define(OP_MOVEI, 8#201).
-define(OP_MOVEM, 8#202).
@@ -362,6 +363,20 @@ movms_noac_test() ->
, {#ea{section = 1, offset = 0, islocal = false}, 0} % AC0 = 0
]).
%% 2.1.4 Double Move Instructions ==============================================
dmove_test() ->
Prog =
[ {1, 8#100, ?INSN(?OP_DMOVE, 8#17, 0, 0, 8#150)} % 1,,100/ DMOVE 17,150
, {1, 8#101, ?INSN_INVALID} % 1,,101/ <invalid>
, {1, 8#150, 8#42} % 1,,150/ 0,,42
, {1, 8#151, 8#27} % 1,,151/ 0,,27
],
expect(Prog, [], {1, 8#101}, ?DEFAULT_FLAGS,
[ {#ea{section = 1, offset = 8#17, islocal = false}, 8#42} % AC17 = 42
, {#ea{section = 1, offset = 0, islocal = false}, 8#27} % AC0 = 27
]).
%% Common code to run short sequences ==========================================
expect(Prog, ACs, ExpectedPC, ExpectedFlags, ExpectedEs) ->