From abe2cdde6d2948aeeefba56b5625f18741130c5f Mon Sep 17 00:00:00 2001 From: Mikael Pettersson Date: Sat, 25 Jul 2020 16:28:48 +0200 Subject: [PATCH] sim: sim_boolean: handle SETCM, add unit test --- erlang/apps/sim/src/sim_boolean.erl | 16 ++++++++++++++++ erlang/apps/sim/src/sim_core.erl | 1 + erlang/apps/sim/test/sim_boolean_tests.erl | 13 +++++++++++++ 3 files changed, 30 insertions(+) diff --git a/erlang/apps/sim/src/sim_boolean.erl b/erlang/apps/sim/src/sim_boolean.erl index cd681e9..2da88dc 100644 --- a/erlang/apps/sim/src/sim_boolean.erl +++ b/erlang/apps/sim/src/sim_boolean.erl @@ -55,6 +55,7 @@ , handle_SETCA/4 , handle_SETCAB/4 , handle_SETCAM/4 + , handle_SETCM/4 , handle_SETMB/4 , handle_SETMI/4 , handle_SETMM/4 @@ -598,6 +599,21 @@ handle_ORCAB(Core, Mem, IR, EA) -> fun(Core1, Mem1) -> handle_ORCAB(Core1, Mem1, IR, EA) end) end. +%% SETCM - Set to Complement of Memory + +-spec handle_SETCM(#core{}, sim_mem:mem(), IR :: word(), #ea{}) + -> {#core{}, sim_mem:mem(), {ok, integer()} | {error, {module(), term()}}}. +handle_SETCM(Core, Mem, IR, EA) -> + case sim_core:c(Core, Mem, EA) of + {ok, CE} -> + AC = IR band 8#17, + Word = (bnot CE) 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_SETCM(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 965464f..fd6b294 100644 --- a/erlang/apps/sim/src/sim_core.erl +++ b/erlang/apps/sim/src/sim_core.erl @@ -301,6 +301,7 @@ dispatch(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); + 8#460 -> sim_boolean:handle_SETCM(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 8bfe954..23e5cc7 100644 --- a/erlang/apps/sim/test/sim_boolean_tests.erl +++ b/erlang/apps/sim/test/sim_boolean_tests.erl @@ -92,6 +92,7 @@ -define(OP_ORCAI, 8#455). -define(OP_ORCAM, 8#456). -define(OP_ORCAB, 8#457). +-define(OP_SETCM, 8#460). %% 2.4 Boolean Functions ======================================================= @@ -673,6 +674,18 @@ orcab_test() -> , {#ea{section = 1, offset = 1, islocal = false}, ?COMMA2(-1, 8#373737)} % AC1 = -1,,373737 ]). +%% SETCM - Set to Complement of Memory + +setcm_test() -> + Prog = + [ {1, 8#100, ?INSN(?OP_SETCM, 1, 0, 0, 8#200)} % 1,,100/ SETCM 1,200 + , {1, 8#101, ?INSN_INVALID} % 1,,101/ + , {1, 8#200, ?COMMA2(0, 8#707070)} % 1,,200/ 0,,707070 + ], + expect(Prog, [], {1, 8#101}, ?DEFAULT_FLAGS, + [ {#ea{section = 1, offset = 1, islocal = false}, ?COMMA2(-1, 8#070707)} % AC1 = -1,,070707 + ]). + %% Common code to run short sequences ========================================== expect(Prog, ACs, ExpectedPC, ExpectedFlags, ExpectedEs) ->