sim: sim_moves: handle MOVNM, add unit test

This commit is contained in:
Mikael Pettersson 2020-07-15 21:38:58 +02:00
parent ba7a498893
commit d06ab5c614
3 changed files with 36 additions and 0 deletions

View File

@ -241,6 +241,7 @@ dispatch(Core, Mem, IR, EA) ->
8#207 -> sim_moves:handle_MOVSS(Core, Mem, IR, EA);
8#210 -> sim_moves:handle_MOVN(Core, Mem, IR, EA);
8#211 -> sim_moves:handle_MOVNI(Core, Mem, IR, EA);
8#212 -> sim_moves:handle_MOVNM(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_MOVN/4
, handle_MOVNI/4
, handle_MOVNM/4
, handle_MOVS/4
, handle_MOVSI/4
, handle_MOVSM/4
@ -182,6 +183,28 @@ handle_MOVNI(Core, Mem, IR, #ea{offset = E}) ->
AC = IR band 8#17,
sim_core:next_pc(sim_core:set_ac(Core, AC, (-E) band ((1 bsl 36) - 1)), Mem).
-spec handle_MOVNM(#core{}, sim_mem:mem(), IR :: word(), #ea{})
-> {#core{}, sim_mem:mem(), {ok, integer()} | {error, {module(), term()}}}.
handle_MOVNM(Core, Mem, IR, EA) ->
AC = IR band 8#17,
CA = sim_core:get_ac(Core, AC),
{Negated, Flags} = negate(CA),
handle_MOVNM(Core, Mem, Negated, Flags, EA).
handle_MOVNM(Core, Mem, Word, Flags, EA) ->
%% "2.9.6.1 Overflow Trapping in the KL10, KS10, and KI10 Processors" and
%% "2.9.6.2 Overflow Trapping in the XKL-1 Processor" both state that if
%% an instruction causes both overflow and a page failure, the page failure
%% is handled first, and the overflow trap is handled after the instruction
%% has restarted and completed.
%% Therefore complete the store before updating flags and proceeding.
case sim_core:cset(Core, Mem, EA, Word) of
{ok, Core1} -> sim_core:next_pc(sim_core:set_flags(Core1, Flags), Mem);
{error, Reason} ->
sim_core:page_fault(Core, Mem, ea_address(EA), write, Reason,
fun(Core1, Mem1) -> handle_MOVNM(Core1, Mem1, Word, Flags, EA) end)
end.
%% Miscellaneous ===============================================================
ea_address(#ea{section = Section, offset = Offset}) ->

View File

@ -53,6 +53,7 @@
-define(OP_MOVSS, 8#207).
-define(OP_MOVN, 8#210).
-define(OP_MOVNI, 8#211).
-define(OP_MOVNM, 8#212).
-define(OP_EXCH, 8#250).
%% 2.1.1 Exchange Instruction ==================================================
@ -234,6 +235,17 @@ movni_test() ->
[ {#ea{section = 1, offset = 1, islocal = false}, (-8#42) band ((1 bsl 36) - 1)} % AC1 = -42
]).
movnm_test() ->
Prog =
[ {1, 8#100, ?INSN(?OP_MOVEI, 1, 0, 0, 8#42)} % 1,,100/ MOVEI 1,42
, {1, 8#101, ?INSN(?OP_MOVNM, 1, 0, 0, 8#150)} % 1,,101/ MOVNM 1,150
, {1, 8#102, ?INSN_INVALID} % 1,,102/ <invalid>
, {1, 8#150, 8#27} % 1,,150/ 0,,27
],
expect(Prog, [], {1, 8#102}, ?DEFAULT_FLAGS,
[ {#ea{section = 1, offset = 8#150, islocal = false}, (-8#42) band ((1 bsl 36) - 1)} % C(1,,150) = -42
]).
%% Common code to run short sequences ==========================================
expect(Prog, ACs, ExpectedPC, ExpectedFlags, ExpectedEs) ->