sim: sim_boolean: handle IOR, add unit test

This commit is contained in:
Mikael Pettersson 2020-07-24 19:34:36 +02:00
parent 6b43d21578
commit f2fd1ffde0
3 changed files with 32 additions and 0 deletions

View File

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

View File

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

View File

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