From b3038df02b1ffa2bac81ca6a389770c0df1ec699 Mon Sep 17 00:00:00 2001 From: Mikael Pettersson Date: Fri, 24 Jul 2020 18:12:44 +0200 Subject: [PATCH] sim: sim_boolean: handle XOR, add unit test --- erlang/apps/sim/src/sim_boolean.erl | 17 +++++++++++++++++ erlang/apps/sim/src/sim_core.erl | 1 + erlang/apps/sim/test/sim_boolean_tests.erl | 14 ++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/erlang/apps/sim/src/sim_boolean.erl b/erlang/apps/sim/src/sim_boolean.erl index 24b6f17..2155aa2 100644 --- a/erlang/apps/sim/src/sim_boolean.erl +++ b/erlang/apps/sim/src/sim_boolean.erl @@ -42,6 +42,7 @@ , handle_SETZ/4 , handle_SETZB/4 , handle_SETZM/4 + , handle_XOR/4 ]). -include("sim_core.hrl"). @@ -289,6 +290,22 @@ handle_ANDCMB(Core, Mem, IR, EA) -> fun(Core1, Mem1) -> handle_ANDCMB(Core1, Mem1, IR, EA) end) end. +%% XOR - Exclusive Or with AC + +-spec handle_XOR(#core{}, sim_mem:mem(), IR :: word(), #ea{}) + -> {#core{}, sim_mem:mem(), {ok, integer()} | {error, {module(), term()}}}. +handle_XOR(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 bxor CA, + 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_XOR(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 6914464..e1c99d8 100644 --- a/erlang/apps/sim/src/sim_core.erl +++ b/erlang/apps/sim/src/sim_core.erl @@ -277,6 +277,7 @@ dispatch(Core, Mem, IR, EA) -> 8#425 -> next_pc(Core, Mem); % SETAI = no-op 8#426 -> sim_moves:handle_MOVEM(Core, Mem, IR, EA); % SETAM = MOVEM 8#427 -> sim_moves:handle_MOVEM(Core, Mem, IR, EA); % SETAB = MOVEM + 8#430 -> sim_boolean:handle_XOR(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 ee4a850..591dca1 100644 --- a/erlang/apps/sim/test/sim_boolean_tests.erl +++ b/erlang/apps/sim/test/sim_boolean_tests.erl @@ -68,6 +68,7 @@ -define(OP_SETAI, 8#425). -define(OP_SETAM, 8#426). -define(OP_SETAB, 8#426). +-define(OP_XOR, 8#430). %% 2.4 Boolean Functions ======================================================= @@ -374,6 +375,19 @@ setab_test() -> [ {#ea{section = 1, offset = 8#150, islocal = false}, 8#42} % C(1,,150) = 42 ]). +%% XOR - Exclusive Or with AC + +xor_test() -> + Prog = + [ {1, 8#100, ?INSN(?OP_MOVEI, 1, 0, 0, 8#707070)} % 1,,100/ MOVEI 1,707070 + , {1, 8#101, ?INSN(?OP_XOR, 1, 0, 0, 8#200)} % 1,,101/ XOR 1,200 + , {1, 8#102, ?INSN_INVALID} % 1,,102/ + , {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}, 8#434343} % AC1 = 0,,434343 + ]). + %% Common code to run short sequences ========================================== expect(Prog, ACs, ExpectedPC, ExpectedFlags, ExpectedEs) ->