sim: sim_boolean: handle SETCAM, add unit test

This commit is contained in:
Mikael Pettersson 2020-07-25 15:08:26 +02:00
parent cc90c106a8
commit 9f273f13ec
3 changed files with 22 additions and 0 deletions

View File

@ -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}) ->

View File

@ -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}}}}

View File

@ -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/ <invalid>
, {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) ->