2016-12-14 12:43:13 +01:00
|
|
|
require_relative 'helper'
|
|
|
|
|
2017-01-03 21:37:55 +01:00
|
|
|
module Arm
|
|
|
|
class TestControl < MiniTest::Test
|
|
|
|
include ArmHelper
|
2016-12-14 12:43:13 +01:00
|
|
|
|
2017-01-03 21:37:55 +01:00
|
|
|
def test_b
|
|
|
|
# the address is what an assembler calculates (a signed number for the amount of instructions),
|
|
|
|
# ie the relative (to pc) address -8 (pipeline) /4 so save space
|
|
|
|
# so the cpu adds the value*4 and starts loading that (load, decode, execute)
|
2018-05-12 17:36:59 +02:00
|
|
|
code = @machine.b( 0 ) #this jumps to the next next instruction
|
|
|
|
assert_code code , :b , [0x0,0x0,0x0,0xea] #ea 00 00 00
|
2017-01-03 21:37:55 +01:00
|
|
|
end
|
|
|
|
def test_call #see comment above. bx not implemented (as it means into thumb, and no thumb here)
|
|
|
|
code = @machine.call( -4 ,{} )#this jumps to the next instruction
|
|
|
|
assert_code code , :call, [0xff,0xff,0xff,0xeb] #ea ff ff fe
|
|
|
|
end
|
2018-06-19 09:51:03 +02:00
|
|
|
def test_has_branch_to
|
|
|
|
label = Risc::Label.new("HI","ho" , FakeAddress.new(0))
|
|
|
|
code = @machine.b( label )
|
|
|
|
assert_equal label , code.branch_to
|
|
|
|
end
|
|
|
|
def test_branch_to_for_swi
|
|
|
|
code = @machine.swi( 0x05 )
|
|
|
|
assert_nil code.branch_to
|
|
|
|
end
|
2018-03-28 12:00:03 +02:00
|
|
|
def test_method_call
|
2019-02-08 22:03:23 +01:00
|
|
|
Parfait.boot!(Parfait.default_test_options)
|
2018-03-28 12:00:03 +02:00
|
|
|
bin = Parfait::BinaryCode.new(1)
|
2018-06-15 21:00:49 +02:00
|
|
|
Risc::Position.new(bin).set(0x20)
|
2018-03-28 12:00:03 +02:00
|
|
|
code = @machine.call( bin ,{} )#this jumps to the next instruction
|
2018-06-15 21:00:49 +02:00
|
|
|
Risc::Position.new(code).set(0)
|
2018-05-29 16:03:20 +02:00
|
|
|
assert_code code , :call, [0x08,0x0,0x0,0xeb]
|
2018-03-28 12:00:03 +02:00
|
|
|
end
|
2017-01-03 21:37:55 +01:00
|
|
|
def test_swi
|
|
|
|
code = @machine.swi( 0x05 )
|
|
|
|
assert_code code , :swi , [0x05,0x00,0x00,0xef]#ef 00 00 05
|
|
|
|
end
|
|
|
|
def test_swi_neg
|
|
|
|
assert_raises(RuntimeError) do
|
|
|
|
assert_code @machine.swi("0x05") , :swi , [0x05,0x00,0x00,0xef]
|
|
|
|
end
|
2016-12-14 18:06:32 +01:00
|
|
|
end
|
|
|
|
end
|
2016-12-14 12:43:13 +01:00
|
|
|
end
|