From 0da7e91bacdc8ab0fb82c5448448f9bead329367 Mon Sep 17 00:00:00 2001 From: Mikael Pettersson Date: Thu, 23 Jul 2020 14:44:09 +0200 Subject: [PATCH] sim: sim_boolean: handle ANDCAM, 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 | 12 ++++++++++++ 3 files changed, 28 insertions(+) diff --git a/erlang/apps/sim/src/sim_boolean.erl b/erlang/apps/sim/src/sim_boolean.erl index 19c8be0..c1eb2d2 100644 --- a/erlang/apps/sim/src/sim_boolean.erl +++ b/erlang/apps/sim/src/sim_boolean.erl @@ -28,6 +28,7 @@ , handle_ANDB/4 , handle_ANDCA/4 , handle_ANDCAI/4 + , handle_ANDCAM/4 , handle_ANDI/4 , handle_ANDM/4 , handle_SETZ/4 @@ -161,6 +162,20 @@ handle_ANDCAI(Core, Mem, IR, EA) -> Word = EA#ea.offset band bnot CA, sim_core:next_pc(sim_core:set_ac(Core, AC, Word), Mem). +-spec handle_ANDCAM(#core{}, sim_mem:mem(), IR :: word(), #ea{}) + -> {#core{}, sim_mem:mem(), {ok, integer()} | {error, {module(), term()}}}. +handle_ANDCAM(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 band bnot CA, + handle_ANDM_1(Core, Mem, EA, Word); + {error, Reason} -> + sim_core:page_fault(Core, Mem, ea_address(EA), read, Reason, + fun(Core1, Mem1) -> handle_ANDCAM(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 b6f61f7..9212cab 100644 --- a/erlang/apps/sim/src/sim_core.erl +++ b/erlang/apps/sim/src/sim_core.erl @@ -263,6 +263,7 @@ dispatch(Core, Mem, IR, EA) -> 8#407 -> sim_boolean:handle_ANDB(Core, Mem, IR, EA); 8#410 -> sim_boolean:handle_ANDCA(Core, Mem, IR, EA); 8#411 -> sim_boolean:handle_ANDCAI(Core, Mem, IR, EA); + 8#412 -> sim_boolean:handle_ANDCAM(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 99b5426..0271801 100644 --- a/erlang/apps/sim/test/sim_boolean_tests.erl +++ b/erlang/apps/sim/test/sim_boolean_tests.erl @@ -53,6 +53,7 @@ -define(OP_ANDB, 8#407). -define(OP_ANDCA, 8#410). -define(OP_ANDCAI, 8#411). +-define(OP_ANDCAM, 8#412). %% 2.4 Boolean Functions ======================================================= @@ -169,6 +170,17 @@ andcai_test() -> [ {#ea{section = 1, offset = 1, islocal = false}, 8#030303} % AC1 = 0,,030303 ]). +andcam_test() -> + Prog = + [ {1, 8#100, ?INSN(?OP_MOVEI, 1, 0, 0, 8#707070)} % 1,,100/ MOVEI 1,707070 + , {1, 8#101, ?INSN(?OP_ANDCAM, 1, 0, 0, 8#200)} % 1,,101/ ANDCAM 1,200 + , {1, 8#102, ?INSN_INVALID} % 1,,102/ + , {1, 8#200, ?COMMA2(-1, 8#333333)} % 1,,200/ -1,,333333 + ], + expect(Prog, [], {1, 8#102}, ?DEFAULT_FLAGS, + [ {#ea{section = 1, offset = 8#200, islocal = false}, ?COMMA2(-1, 8#030303)} % C(1,,200) = -1,,030303 + ]). + %% Common code to run short sequences ========================================== expect(Prog, ACs, ExpectedPC, ExpectedFlags, ExpectedEs) ->