mirror of
https://github.com/mikpe/pdp10-tools.git
synced 2026-01-23 02:49:07 +00:00
sim: sim_moves: handle MOVES, add unit tests
This commit is contained in:
parent
9b37ac3702
commit
01bd93b3c3
@ -227,6 +227,7 @@ dispatch(Core, Mem, IR, EA) ->
|
||||
8#200 -> sim_moves:handle_MOVE(Core, Mem, IR, EA);
|
||||
8#201 -> sim_moves:handle_MOVEI(Core, Mem, IR, EA);
|
||||
8#202 -> sim_moves:handle_MOVEM(Core, Mem, IR, EA);
|
||||
8#203 -> sim_moves:handle_MOVES(Core, Mem, IR, EA);
|
||||
8#250 -> sim_moves:handle_EXCH(Core, Mem, IR, EA);
|
||||
_ ->
|
||||
PC = (Core#core.pc_section bsl 18) bor Core#core.pc_offset,
|
||||
|
||||
@ -28,6 +28,7 @@
|
||||
, handle_MOVE/4
|
||||
, handle_MOVEI/4
|
||||
, handle_MOVEM/4
|
||||
, handle_MOVES/4
|
||||
]).
|
||||
|
||||
-include("sim_core.hrl").
|
||||
@ -94,7 +95,30 @@ handle_MOVEM_1(Core, Mem, Word, EA) ->
|
||||
fun(Core1, Mem1) -> handle_MOVEM_1(Core1, Mem1, Word, EA) end)
|
||||
end.
|
||||
|
||||
-spec handle_MOVES(#core{}, sim_mem:mem(), IR :: word(), #ea{})
|
||||
-> {#core{}, sim_mem:mem(), {ok, integer()} | {error, {module(), term()}}}.
|
||||
handle_MOVES(Core, Mem, IR, EA) ->
|
||||
case sim_core:c(Core, Mem, EA) of
|
||||
{ok, CE} ->
|
||||
AC = IR band 8#17,
|
||||
handle_MOVES(Core, Mem, AC, EA, CE);
|
||||
{error, Reason} ->
|
||||
sim_core:page_fault(Core, Mem, ea_address(EA), read, Reason,
|
||||
fun(Core1, Mem1) -> handle_MOVES(Core1, Mem1, IR, EA) end)
|
||||
end.
|
||||
|
||||
handle_MOVES(Core, Mem, AC, EA, Word) ->
|
||||
case sim_core:cset(Core, Mem, EA, Word) of
|
||||
{ok, Core1} -> sim_core:next_pc(set_non_zero_ac(Core1, AC, Word), Mem);
|
||||
{error, Reason} ->
|
||||
sim_core:page_fault(Core, Mem, ea_address(EA), write, Reason,
|
||||
fun(Core1, Mem1) -> handle_MOVES(Core1, Mem1, AC, EA, Word) end)
|
||||
end.
|
||||
|
||||
%% Miscellaneous ===============================================================
|
||||
|
||||
ea_address(#ea{section = Section, offset = Offset}) ->
|
||||
(Section bsl 18) bor Offset.
|
||||
|
||||
set_non_zero_ac(Core, _AC = 0, _Word) -> Core;
|
||||
set_non_zero_ac(Core, AC, Word) -> sim_core:set_ac(Core, AC, Word).
|
||||
|
||||
@ -46,6 +46,7 @@
|
||||
-define(OP_MOVE, 8#200).
|
||||
-define(OP_MOVEI, 8#201).
|
||||
-define(OP_MOVEM, 8#202).
|
||||
-define(OP_MOVES, 8#203).
|
||||
-define(OP_EXCH, 8#250).
|
||||
|
||||
%% 2.1.1 Exchange Instruction ==================================================
|
||||
@ -108,6 +109,30 @@ movem_test() ->
|
||||
[ {#ea{section = 1, offset = 8#150, islocal = false}, 8#42} % C(1,,150) = 42
|
||||
]).
|
||||
|
||||
moves_ac_test() ->
|
||||
Prog =
|
||||
[ {1, 8#100, ?INSN(?OP_MOVEI, 1, 0, 0, 8#27)} % 1,,100/ MOVEI 1,27
|
||||
, {1, 8#101, ?INSN(?OP_MOVES, 1, 0, 0, 8#150)} % 1,,101/ MOVES 1,150
|
||||
, {1, 8#102, ?INSN_INVALID} % 1,,102/ <invalid>
|
||||
, {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 = 1, islocal = false}, 8#42} % AC1 = 42
|
||||
]).
|
||||
|
||||
moves_noac_test() ->
|
||||
Prog =
|
||||
[ {1, 8#100, ?INSN(?OP_MOVEI, 0, 0, 0, 8#27)} % 1,,100/ MOVEI 0,27
|
||||
, {1, 8#101, ?INSN(?OP_MOVES, 0, 0, 0, 8#150)} % 1,,101/ MOVES 0,150
|
||||
, {1, 8#102, ?INSN_INVALID} % 1,,102/ <invalid>
|
||||
, {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#27} % AC0 = 27
|
||||
]).
|
||||
|
||||
%% Common code to run short sequences ==========================================
|
||||
|
||||
expect(Prog, ACs, ExpectedPC, ExpectedFlags, ExpectedEs) ->
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user