From 9f273f13ec33aec56dd7ee58708d8f3e712d2c6e Mon Sep 17 00:00:00 2001 From: Mikael Pettersson Date: Sat, 25 Jul 2020 15:08:26 +0200 Subject: [PATCH] sim: sim_boolean: handle SETCAM, add unit test --- erlang/apps/sim/src/sim_boolean.erl | 9 +++++++++ erlang/apps/sim/src/sim_core.erl | 1 + erlang/apps/sim/test/sim_boolean_tests.erl | 12 ++++++++++++ 3 files changed, 22 insertions(+) diff --git a/erlang/apps/sim/src/sim_boolean.erl b/erlang/apps/sim/src/sim_boolean.erl index 00f52cd..3af5ae5 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_SETCA/4 + , handle_SETCAM/4 , handle_SETMB/4 , handle_SETMI/4 , handle_SETMM/4 @@ -524,6 +525,14 @@ handle_SETCA(Core, Mem, IR, _EA) -> Word = (bnot CA) band ((1 bsl 36) - 1), sim_core:next_pc(sim_core:set_ac(Core, AC, Word), Mem). +-spec handle_SETCAM(#core{}, sim_mem:mem(), IR :: word(), #ea{}) + -> {#core{}, sim_mem:mem(), {ok, integer()} | {error, {module(), term()}}}. +handle_SETCAM(Core, Mem, IR, EA) -> + AC = IR band 8#17, + CA = sim_core:get_ac(Core, AC), + Word = (bnot CA) band ((1 bsl 36) - 1), + handle_ANDM_1(Core, Mem, EA, Word). + %% 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 6577a50..5812a96 100644 --- a/erlang/apps/sim/src/sim_core.erl +++ b/erlang/apps/sim/src/sim_core.erl @@ -295,6 +295,7 @@ dispatch(Core, Mem, IR, EA) -> 8#447 -> sim_boolean:handle_EQVB(Core, Mem, IR, EA); 8#450 -> sim_boolean:handle_SETCA(Core, Mem, IR, EA); 8#451 -> sim_boolean:handle_SETCA(Core, Mem, IR, EA); % SETCAI = SETCA + 8#452 -> sim_boolean:handle_SETCAM(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 e95706b..ecb11a3 100644 --- a/erlang/apps/sim/test/sim_boolean_tests.erl +++ b/erlang/apps/sim/test/sim_boolean_tests.erl @@ -86,6 +86,7 @@ -define(OP_EQVB, 8#447). -define(OP_SETCA, 8#450). -define(OP_SETCAI, 8#451). +-define(OP_SETCAM, 8#452). %% 2.4 Boolean Functions ======================================================= @@ -598,6 +599,17 @@ setcai_test() -> [ {#ea{section = 1, offset = 1, islocal = false}, ?COMMA2(-1, 8#070707)} % AC1 = -1,,070707 ]). +setcam_test() -> + Prog = + [ {1, 8#100, ?INSN(?OP_MOVEI, 1, 0, 0, 8#707070)} % 1,,100/ MOVEI 1,707070 + , {1, 8#101, ?INSN(?OP_SETCAM, 1, 0, 0, 8#200)} % 1,,101/ SETCAM 1,200 + , {1, 8#102, ?INSN_INVALID} % 1,,102/ + , {1, 8#200, 0} % 1,,200/ 0 + ], + expect(Prog, [], {1, 8#102}, ?DEFAULT_FLAGS, + [ {#ea{section = 1, offset = 8#200, islocal = false}, ?COMMA2(-1, 8#070707)} % C(1,,200) = -1,,070707 + ]). + %% Common code to run short sequences ========================================== expect(Prog, ACs, ExpectedPC, ExpectedFlags, ExpectedEs) ->