sim: sim_boolean: handle ORCAB, add unit test

This commit is contained in:
Mikael Pettersson 2020-07-25 16:07:44 +02:00
parent c2e4ac4805
commit 9bdf6331a4
3 changed files with 29 additions and 0 deletions

View File

@ -49,6 +49,7 @@
, handle_IORI/4
, handle_IORM/4
, handle_ORCA/4
, handle_ORCAB/4
, handle_ORCAI/4
, handle_ORCAM/4
, handle_SETCA/4
@ -583,6 +584,20 @@ handle_ORCAM(Core, Mem, IR, EA) ->
fun(Core1, Mem1) -> handle_ORCAM(Core1, Mem1, IR, EA) end)
end.
-spec handle_ORCAB(#core{}, sim_mem:mem(), IR :: word(), #ea{})
-> {#core{}, sim_mem:mem(), {ok, integer()} | {error, {module(), term()}}}.
handle_ORCAB(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 bnot CA) band ((1 bsl 36) - 1),
handle_ANDB(Core, Mem, AC, EA, Word);
{error, Reason} ->
sim_core:page_fault(Core, Mem, ea_address(EA), read, Reason,
fun(Core1, Mem1) -> handle_ORCAB(Core1, Mem1, IR, EA) end)
end.
%% Miscellaneous ===============================================================
ea_address(#ea{section = Section, offset = Offset}) ->

View File

@ -300,6 +300,7 @@ dispatch(Core, Mem, IR, EA) ->
8#454 -> sim_boolean:handle_ORCA(Core, Mem, IR, EA);
8#455 -> sim_boolean:handle_ORCAI(Core, Mem, IR, EA);
8#456 -> sim_boolean:handle_ORCAM(Core, Mem, IR, EA);
8#457 -> sim_boolean:handle_ORCAB(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

@ -91,6 +91,7 @@
-define(OP_ORCA, 8#454).
-define(OP_ORCAI, 8#455).
-define(OP_ORCAM, 8#456).
-define(OP_ORCAB, 8#457).
%% 2.4 Boolean Functions =======================================================
@ -660,6 +661,18 @@ orcam_test() ->
[ {#ea{section = 1, offset = 8#200, islocal = false}, ?COMMA2(-1, 8#373737)} % C(1,,200) = -1,,373737
]).
orcab_test() ->
Prog =
[ {1, 8#100, ?INSN(?OP_MOVEI, 1, 0, 0, 8#707070)} % 1,,100/ MOVEI 1,707070
, {1, 8#101, ?INSN(?OP_ORCAB, 1, 0, 0, 8#200)} % 1,,101/ ORCAB 1,200
, {1, 8#102, ?INSN_INVALID} % 1,,102/ <invalid>
, {1, 8#200, ?COMMA2(0, 8#303030)} % 1,,200/ 0,,303030
],
expect(Prog, [], {1, 8#102}, ?DEFAULT_FLAGS,
[ {#ea{section = 1, offset = 8#200, islocal = false}, ?COMMA2(-1, 8#373737)} % C(1,,200) = -1,,373737
, {#ea{section = 1, offset = 1, islocal = false}, ?COMMA2(-1, 8#373737)} % AC1 = -1,,373737
]).
%% Common code to run short sequences ==========================================
expect(Prog, ACs, ExpectedPC, ExpectedFlags, ExpectedEs) ->