Skip to content

Commit

Permalink
Imlpemented RTI. Testing RTS and FIXED test for BL.
Browse files Browse the repository at this point in the history
  • Loading branch information
snim2 committed Jun 28, 2015
1 parent f8390ee commit 4dde4f9
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 19 deletions.
2 changes: 1 addition & 1 deletion epiphany/execute_branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def execute_bcond(s, inst):
cond = inst.cond
imm = inst.bcond_imm
if cond == 0b1111: # Branch and link (BL).
s.rf[epiphany.isa.reg_map['LR']] = s.pc + 2 if is16bit else s.pc + 4
s.rf[epiphany.isa.reg_map['LR']] = (s.pc + 2) if is16bit else (s.pc + 4)
if should_branch(s, cond):
s.pc += (sext_8(signed_8(imm)) << 1) if is16bit else (sext_24(signed_24(imm)) << 1)
else:
Expand Down
11 changes: 10 additions & 1 deletion epiphany/execute_interrupt.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,16 @@ def execute_sync16(s, inst):
# rti16
#-----------------------------------------------------------------------
def execute_rti16(s, inst):
raise NotImplementedError('Interrupts not implemented.')
"""
IPEND[_i_] = 0; where _i_ is the current interrupt level being serviced
STATUS[1] = 0;
PC = IRET;
<execute instruction at PC>
"""
# FIXME: Set IPEND.
mask = 0xFFFFFFFD
s.rf[epiphany.isa.reg_map['STATUS']] &= mask
s.pc = s.rf[epiphany.isa.reg_map['IRET']]


#-----------------------------------------------------------------------
Expand Down
26 changes: 14 additions & 12 deletions epiphany/test/asm/bl.S
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
#include "epiphany-macros.h"
SET_UP
; Temporary register - r14
; Function argument - r15
; Function return - r16
mov r15, #5
mov r16, #0
; Temporary register - r0
; Function argument - r1
; Function return - r2
mov r1, #5
mov r2, #0
bl _my_func ; save PC to LR and jump to _my_func
TEAR_DOWN ; Sets breakpoint.
b _end
_my_func:
mov r14, #0
mov r16, #0
mov r0, #0
mov r2, #0
_loop:
add r14, r14, r15
sub r15, r15, #1
add r0, r0, r1
sub r1, r1, #1
bne _loop
add r16, r16, r14
rts ; branch back to callee
add r2, r0, #0
rts ; branch back to callee
_end:
TEAR_DOWN ; Sets breakpoint.
Binary file modified epiphany/test/asm/bl.elf
Binary file not shown.
12 changes: 11 additions & 1 deletion epiphany/test/asm/rts.S
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
#include "epiphany-macros.h"
SET_UP
rts
bl _my_func ; save PC to LR and jump to _my_func
nop
nop
nop
b _end
_my_func:
mov r1, #100
mov r2, #200
add r3, r1, r2
rts ; branch back to callee
_end:
TEAR_DOWN
Binary file modified epiphany/test/asm/rts.elf
Binary file not shown.
4 changes: 2 additions & 2 deletions epiphany/test/test_asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
('asr.elf', StateChecker(pc=(10 + + RESET_ADDR), rf0=1, rf1=5, rf2=0, rf3=0)),
('bcond.elf', StateChecker(pc=(12 + RESET_ADDR), rf0=0, rf1=110)),
('bitr.elf', StateChecker(pc=(6 + RESET_ADDR), rf0=170, rf1=85)),
('bl.elf', StateChecker(rf14=15, rf15=0, rf16=15)),
('bl.elf', StateChecker(pc=114, rf0=15, rf1=0, rf2=15)),
pytest.mark.xfail(('dma_transfer.elf', StateChecker())),
('eor.elf', StateChecker(pc=(8 + RESET_ADDR), rf0=5, rf1=7, rf2=2)),
('fix.elf', StateChecker(pc=(8 + RESET_ADDR), rf0=5)),
Expand All @@ -35,7 +35,7 @@
('nop.elf', StateChecker(pc=(4 + RESET_ADDR))),
('orr.elf', StateChecker(pc=(8 + RESET_ADDR), rf0=5, rf1=7, rf2=7)),
pytest.mark.xfail(('rti.elf', StateChecker())),
pytest.mark.xfail(('rts.elf', StateChecker())),
('rts.elf', StateChecker(pc=110, rf1=100, rf2=200, rf3=300, rfLR=90)),
('sub.elf', StateChecker(pc=(12 + RESET_ADDR), rf0=100, rf1=20, rf2=80, rf3=80)),
pytest.mark.xfail(('trap.elf', StateChecker(pc=(6 + RESET_ADDR)))),
])
Expand Down
12 changes: 10 additions & 2 deletions epiphany/test/test_execute_interrupt.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,16 @@ def test_execute_bkpt16():
assert not state.running


@pytest.mark.parametrize('name,instr', [('rti16', opcode_factory.rti16()),
('trap16', opcode_factory.trap16(0b111111))])
def test_execute_rti16():
state = new_state(rfIRET=224, rfSTATUS=0b10, pc=0)
instr = opcode_factory.rti16()
name, executefn = decode(instr)
executefn(state, Instruction(instr, None))
expected_state = StateChecker(pc=224, rfIRET=224, rfSTATUS=0b00)
expected_state.check(state)


@pytest.mark.parametrize('name,instr', [('trap16', opcode_factory.trap16(0b111111))])
def test_execute_interrupt_instructions(name, instr):
with pytest.raises(NotImplementedError):
state = new_state()
Expand Down

0 comments on commit 4dde4f9

Please sign in to comment.