sim: sim_boolean: handle EQV, add unit test

This commit is contained in:
Mikael Pettersson 2020-07-24 23:44:42 +02:00
parent f8ed5a7cf0
commit b8593cff3b
3 changed files with 32 additions and 0 deletions

View File

@ -40,6 +40,7 @@
, handle_ANDCMM/4
, handle_ANDI/4
, handle_ANDM/4
, handle_EQV/4
, handle_IOR/4
, handle_IORB/4
, handle_IORI/4
@ -457,6 +458,22 @@ handle_ANDCBB(Core, Mem, IR, EA) ->
fun(Core1, Mem1) -> handle_ANDCBB(Core1, Mem1, IR, EA) end)
end.
%% EQV - Equivalence with AC
-spec handle_EQV(#core{}, sim_mem:mem(), IR :: word(), #ea{})
-> {#core{}, sim_mem:mem(), {ok, integer()} | {error, {module(), term()}}}.
handle_EQV(Core, Mem, IR, EA) ->
case sim_core:c(Core, Mem, EA) of
{ok, CE} ->
AC = IR band 8#17,
CA = sim_core:get_ac(Core, AC),
Word = (bnot (CE bxor CA)) band ((1 bsl 36) - 1),
sim_core:next_pc(sim_core:set_ac(Core, AC, Word), Mem);
{error, Reason} ->
sim_core:page_fault(Core, Mem, ea_address(EA), read, Reason,
fun(Core1, Mem1) -> handle_EQV(Core1, Mem1, IR, EA) end)
end.
%% Miscellaneous ===============================================================
ea_address(#ea{section = Section, offset = Offset}) ->

View File

@ -289,6 +289,7 @@ dispatch(Core, Mem, IR, EA) ->
8#441 -> sim_boolean:handle_ANDCBI(Core, Mem, IR, EA);
8#442 -> sim_boolean:handle_ANDCBM(Core, Mem, IR, EA);
8#443 -> sim_boolean:handle_ANDCBB(Core, Mem, IR, EA);
8#444 -> sim_boolean:handle_EQV(Core, Mem, IR, EA);
_ ->
PC = (Core#core.pc_section bsl 18) bor Core#core.pc_offset,
{Core, Mem, {error, {?MODULE, {dispatch, PC, IR, EA}}}}

View File

@ -80,6 +80,7 @@
-define(OP_ANDCBI, 8#441).
-define(OP_ANDCBM, 8#442).
-define(OP_ANDCBB, 8#443).
-define(OP_EQV, 8#444).
%% 2.4 Boolean Functions =======================================================
@ -524,6 +525,19 @@ andcbb_test() ->
, {#ea{section = 1, offset = 1, islocal = false}, ?COMMA2(-1, 0)} % AC1 = -1,,0
]).
%% EQV - Equivalence with AC
eqv_test() ->
Prog =
[ {1, 8#100, ?INSN(?OP_MOVEI, 1, 0, 0, 8#707070)} % 1,,100/ MOVEI 1,707070
, {1, 8#101, ?INSN(?OP_EQV, 1, 0, 0, 8#200)} % 1,,101/ EQV 1,200
, {1, 8#102, ?INSN_INVALID} % 1,,102/ <invalid>
, {1, 8#200, ?COMMA2(0, 8#333333)} % 1,,200/ 0,,333333
],
expect(Prog, [], {1, 8#102}, ?DEFAULT_FLAGS,
[ {#ea{section = 1, offset = 1, islocal = false}, ?COMMA2(-1, 8#343434)} % AC1 = -1,,343434
]).
%% Common code to run short sequences ==========================================
expect(Prog, ACs, ExpectedPC, ExpectedFlags, ExpectedEs) ->