From f2fd1ffde0a11a02366f760b811490bd6fa38088 Mon Sep 17 00:00:00 2001 From: Mikael Pettersson Date: Fri, 24 Jul 2020 19:34:36 +0200 Subject: [PATCH] sim: sim_boolean: handle IOR, 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 6d42675..35ffa6a 100644 --- a/erlang/apps/sim/src/sim_boolean.erl +++ b/erlang/apps/sim/src/sim_boolean.erl @@ -36,6 +36,7 @@ , handle_ANDCMM/4 , handle_ANDI/4 , handle_ANDM/4 + , handle_IOR/4 , handle_SETMB/4 , handle_SETMI/4 , handle_SETMM/4 @@ -345,6 +346,22 @@ handle_XORB(Core, Mem, IR, EA) -> fun(Core1, Mem1) -> handle_XORB(Core1, Mem1, IR, EA) end) end. +%% IOR - Inclusive Or with AC + +-spec handle_IOR(#core{}, sim_mem:mem(), IR :: word(), #ea{}) + -> {#core{}, sim_mem:mem(), {ok, integer()} | {error, {module(), term()}}}. +handle_IOR(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 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_IOR(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 ce4edfa..f70bdf2 100644 --- a/erlang/apps/sim/src/sim_core.erl +++ b/erlang/apps/sim/src/sim_core.erl @@ -281,6 +281,7 @@ dispatch(Core, Mem, IR, EA) -> 8#431 -> sim_boolean:handle_XORI(Core, Mem, IR, EA); 8#432 -> sim_boolean:handle_XORM(Core, Mem, IR, EA); 8#433 -> sim_boolean:handle_XORB(Core, Mem, IR, EA); + 8#434 -> sim_boolean:handle_IOR(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 9ffa883..6710b9f 100644 --- a/erlang/apps/sim/test/sim_boolean_tests.erl +++ b/erlang/apps/sim/test/sim_boolean_tests.erl @@ -72,6 +72,7 @@ -define(OP_XORI, 8#431). -define(OP_XORM, 8#432). -define(OP_XORB, 8#433). +-define(OP_IOR, 8#434). %% 2.4 Boolean Functions ======================================================= @@ -424,6 +425,19 @@ xorb_test() -> , {#ea{section = 1, offset = 1, islocal = false}, 8#434343} % AC1 = 0,,434343 ]). +%% IOR - Inclusive Or with AC + +ior_test() -> + Prog = + [ {1, 8#100, ?INSN(?OP_MOVEI, 1, 0, 0, 8#707070)} % 1,,100/ MOVEI 1,707070 + , {1, 8#101, ?INSN(?OP_IOR, 1, 0, 0, 8#200)} % 1,,101/ IOR 1,200 + , {1, 8#102, ?INSN_INVALID} % 1,,102/ + , {1, 8#200, ?COMMA2(0, 8#070707)} % 1,,200/ 0,,070707 + ], + expect(Prog, [], {1, 8#102}, ?DEFAULT_FLAGS, + [ {#ea{section = 1, offset = 1, islocal = false}, 8#777777} % AC1 = 0,,-1 + ]). + %% Common code to run short sequences ========================================== expect(Prog, ACs, ExpectedPC, ExpectedFlags, ExpectedEs) ->