sim: sim_boolean: handle ANDB, add unit test

This commit is contained in:
Mikael Pettersson 2020-07-22 23:46:23 +02:00
parent df8b526bbd
commit 409457dffc
3 changed files with 37 additions and 0 deletions

View File

@ -25,6 +25,7 @@
-module(sim_boolean).
-export([ handle_AND/4
, handle_ANDB/4
, handle_ANDI/4
, handle_ANDM/4
, handle_SETZ/4
@ -112,6 +113,28 @@ handle_ANDM_1(Core, Mem, EA, Word) ->
fun(Core1, Mem1) -> handle_ANDM_1(Core1, Mem1, EA, Word) end)
end.
-spec handle_ANDB(#core{}, sim_mem:mem(), IR :: word(), #ea{})
-> {#core{}, sim_mem:mem(), {ok, integer()} | {error, {module(), term()}}}.
handle_ANDB(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 band CA,
handle_ANDB(Core, Mem, AC, EA, Word);
{error, Reason} ->
sim_core:page_fault(Core, Mem, ea_address(EA), read, Reason,
fun(Core1, Mem1) -> handle_ANDB(Core1, Mem1, IR, EA) end)
end.
handle_ANDB(Core, Mem, AC, EA, Word) ->
case sim_core:cset(Core, Mem, EA, Word) of
{ok, Core1} -> sim_core:next_pc(sim_core:set_ac(Core1, AC, Word), Mem);
{error, Reason} ->
sim_core:page_fault(Core, Mem, ea_address(EA), write, Reason,
fun(Core1, Mem1) -> handle_ANDB(Core1, Mem1, AC, EA, Word) end)
end.
%% Miscellaneous ===============================================================
ea_address(#ea{section = Section, offset = Offset}) ->

View File

@ -260,6 +260,7 @@ dispatch(Core, Mem, IR, EA) ->
8#404 -> sim_boolean:handle_AND(Core, Mem, IR, EA);
8#405 -> sim_boolean:handle_ANDI(Core, Mem, IR, EA);
8#406 -> sim_boolean:handle_ANDM(Core, Mem, IR, EA);
8#407 -> sim_boolean:handle_ANDB(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

@ -50,6 +50,7 @@
-define(OP_AND, 8#404).
-define(OP_ANDI, 8#405).
-define(OP_ANDM, 8#406).
-define(OP_ANDB, 8#407).
%% 2.4 Boolean Functions =======================================================
@ -131,6 +132,18 @@ andm_test() ->
[ {#ea{section = 1, offset = 8#200, islocal = false}, 8#303030} % C(1,,200) = 0,,303030
]).
andb_test() ->
Prog =
[ {1, 8#100, ?INSN(?OP_MOVEI, 1, 0, 0, 8#707070)} % 1,,100/ MOVEI 1,707070
, {1, 8#101, ?INSN(?OP_ANDB, 1, 0, 0, 8#200)} % 1,,101/ ANDB 1,200
, {1, 8#102, ?INSN_INVALID} % 1,,102/ <invalid>
, {1, 8#200, ?COMMA2(-1, 8#333333)} % 1,,200/ -1,333333
],
expect(Prog, [], {1, 8#102}, ?DEFAULT_FLAGS,
[ {#ea{section = 1, offset = 8#200, islocal = false}, 8#303030} % C(1,,200) = 0,,303030
, {#ea{section = 1, offset = 1, islocal = false}, 8#303030} % AC1 = 0,,303030
]).
%% Common code to run short sequences ==========================================
expect(Prog, ACs, ExpectedPC, ExpectedFlags, ExpectedEs) ->