From 9bdf6331a4867210cd0f7db3a350b8441cdd55c1 Mon Sep 17 00:00:00 2001 From: Mikael Pettersson Date: Sat, 25 Jul 2020 16:07:44 +0200 Subject: [PATCH] sim: sim_boolean: handle ORCAB, add unit test --- erlang/apps/sim/src/sim_boolean.erl | 15 +++++++++++++++ erlang/apps/sim/src/sim_core.erl | 1 + erlang/apps/sim/test/sim_boolean_tests.erl | 13 +++++++++++++ 3 files changed, 29 insertions(+) diff --git a/erlang/apps/sim/src/sim_boolean.erl b/erlang/apps/sim/src/sim_boolean.erl index 574b9ce..cd681e9 100644 --- a/erlang/apps/sim/src/sim_boolean.erl +++ b/erlang/apps/sim/src/sim_boolean.erl @@ -49,6 +49,7 @@ , handle_IORI/4 , handle_IORM/4 , handle_ORCA/4 + , handle_ORCAB/4 , handle_ORCAI/4 , handle_ORCAM/4 , handle_SETCA/4 @@ -583,6 +584,20 @@ handle_ORCAM(Core, Mem, IR, EA) -> fun(Core1, Mem1) -> handle_ORCAM(Core1, Mem1, IR, EA) end) end. +-spec handle_ORCAB(#core{}, sim_mem:mem(), IR :: word(), #ea{}) + -> {#core{}, sim_mem:mem(), {ok, integer()} | {error, {module(), term()}}}. +handle_ORCAB(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 = (CE bor bnot CA) band ((1 bsl 36) - 1), + handle_ANDB(Core, Mem, AC, EA, Word); + {error, Reason} -> + sim_core:page_fault(Core, Mem, ea_address(EA), read, Reason, + fun(Core1, Mem1) -> handle_ORCAB(Core1, Mem1, IR, EA) end) + end. + %% Miscellaneous =============================================================== ea_address(#ea{section = Section, offset = Offset}) -> diff --git a/erlang/apps/sim/src/sim_core.erl b/erlang/apps/sim/src/sim_core.erl index 4036602..965464f 100644 --- a/erlang/apps/sim/src/sim_core.erl +++ b/erlang/apps/sim/src/sim_core.erl @@ -300,6 +300,7 @@ dispatch(Core, Mem, IR, EA) -> 8#454 -> sim_boolean:handle_ORCA(Core, Mem, IR, EA); 8#455 -> sim_boolean:handle_ORCAI(Core, Mem, IR, EA); 8#456 -> sim_boolean:handle_ORCAM(Core, Mem, IR, EA); + 8#457 -> sim_boolean:handle_ORCAB(Core, Mem, IR, EA); _ -> PC = (Core#core.pc_section bsl 18) bor Core#core.pc_offset, {Core, Mem, {error, {?MODULE, {dispatch, PC, IR, EA}}}} diff --git a/erlang/apps/sim/test/sim_boolean_tests.erl b/erlang/apps/sim/test/sim_boolean_tests.erl index 4a981bd..8bfe954 100644 --- a/erlang/apps/sim/test/sim_boolean_tests.erl +++ b/erlang/apps/sim/test/sim_boolean_tests.erl @@ -91,6 +91,7 @@ -define(OP_ORCA, 8#454). -define(OP_ORCAI, 8#455). -define(OP_ORCAM, 8#456). +-define(OP_ORCAB, 8#457). %% 2.4 Boolean Functions ======================================================= @@ -660,6 +661,18 @@ orcam_test() -> [ {#ea{section = 1, offset = 8#200, islocal = false}, ?COMMA2(-1, 8#373737)} % C(1,,200) = -1,,373737 ]). +orcab_test() -> + Prog = + [ {1, 8#100, ?INSN(?OP_MOVEI, 1, 0, 0, 8#707070)} % 1,,100/ MOVEI 1,707070 + , {1, 8#101, ?INSN(?OP_ORCAB, 1, 0, 0, 8#200)} % 1,,101/ ORCAB 1,200 + , {1, 8#102, ?INSN_INVALID} % 1,,102/ + , {1, 8#200, ?COMMA2(0, 8#303030)} % 1,,200/ 0,,303030 + ], + expect(Prog, [], {1, 8#102}, ?DEFAULT_FLAGS, + [ {#ea{section = 1, offset = 8#200, islocal = false}, ?COMMA2(-1, 8#373737)} % C(1,,200) = -1,,373737 + , {#ea{section = 1, offset = 1, islocal = false}, ?COMMA2(-1, 8#373737)} % AC1 = -1,,373737 + ]). + %% Common code to run short sequences ========================================== expect(Prog, ACs, ExpectedPC, ExpectedFlags, ExpectedEs) ->