diff --git a/erlang/apps/sim/src/sim_boolean.erl b/erlang/apps/sim/src/sim_boolean.erl index dd487c3..b77c8cc 100644 --- a/erlang/apps/sim/src/sim_boolean.erl +++ b/erlang/apps/sim/src/sim_boolean.erl @@ -32,6 +32,7 @@ , handle_ANDCAM/4 , handle_ANDI/4 , handle_ANDM/4 + , handle_SETMB/4 , handle_SETMI/4 , handle_SETMM/4 , handle_SETZ/4 @@ -219,6 +220,19 @@ handle_SETMM(Core, Mem, IR, EA) -> fun(Core1, Mem1) -> handle_SETMM(Core1, Mem1, IR, EA) end) end. +-spec handle_SETMB(#core{}, sim_mem:mem(), IR :: word(), #ea{}) + -> {#core{}, sim_mem:mem(), {ok, integer()} | {error, {module(), term()}}}. +handle_SETMB(Core, Mem, IR, EA) -> + %% Like MOVES, but writes also to AC 0. + case sim_core:c(Core, Mem, EA) of + {ok, CE} -> + AC = IR band 8#17, + handle_ANDB(Core, Mem, AC, EA, CE); + {error, Reason} -> + sim_core:page_fault(Core, Mem, ea_address(EA), read, Reason, + fun(Core1, Mem1) -> handle_SETMB(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 ea1f9fd..cdecb64 100644 --- a/erlang/apps/sim/src/sim_core.erl +++ b/erlang/apps/sim/src/sim_core.erl @@ -268,6 +268,7 @@ dispatch(Core, Mem, IR, EA) -> 8#414 -> sim_moves:handle_MOVE(Core, Mem, IR, EA); % SETM = MOVE 8#415 -> sim_boolean:handle_SETMI(Core, Mem, IR, EA); % SETMI = MOVEI in section 0, XMOVEI elsewhere 8#416 -> sim_boolean:handle_SETMM(Core, Mem, IR, EA); + 8#417 -> sim_boolean:handle_SETMB(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 d14cff2..1909979 100644 --- a/erlang/apps/sim/test/sim_boolean_tests.erl +++ b/erlang/apps/sim/test/sim_boolean_tests.erl @@ -59,6 +59,7 @@ -define(OP_SETMI, 8#415). -define(OP_XMOVEI, ?OP_SETMI). -define(OP_SETMM, 8#416). +-define(OP_SETMB, 8#417). %% 2.4 Boolean Functions ======================================================= @@ -271,6 +272,18 @@ setmm_test() -> , {#ea{section = 1, offset = 1, islocal = false}, 3} ]). +setmb_test() -> + Prog = + [ {1, 8#100, ?INSN(?OP_MOVEI, 0, 0, 0, 8#27)} % 1,,100/ MOVEI 0,27 + , {1, 8#101, ?INSN(?OP_SETMB, 0, 0, 0, 8#150)} % 1,,101/ SETMB 0,150 + , {1, 8#102, ?INSN_INVALID} % 1,,102/ + , {1, 8#150, 8#42} % 1,,150/ 0,,42 + ], + expect(Prog, [], {1, 8#102}, ?DEFAULT_FLAGS, + [ {#ea{section = 1, offset = 8#150, islocal = false}, 8#42} % C(1,,150) = 42 + , {#ea{section = 1, offset = 0, islocal = false}, 8#42} % AC0 = 42 + ]). + %% Common code to run short sequences ========================================== expect(Prog, ACs, ExpectedPC, ExpectedFlags, ExpectedEs) ->