2
###############################################################################
4
# simulavr - A simulator for the Atmel AVR family of microcontrollers.
5
# Copyright (C) 2001, 2002 Theodore A. Roth
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 2 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
###############################################################################
23
# $Id: test_RETI.py,v 0.5 josef
26
"""Test the RETI opcode.
30
from registers import Reg, SREG
32
class RETI_TestFail(base_test.TestFail): pass
34
class base_RETI(base_test.opcode_stack_test):
35
"""Generic test case for testing RETI opcode.
37
The derived class must provide the reg member and the fail method.
39
description: RETI - return from interrupt routine the return address
40
is loaded from the stack and set the global interrupt flag
43
opcode is '1001 0101 0001 1000'
46
# set the pc to a different position
47
self.setup_regs[Reg.PC] = self.old_pc * 2
49
# put the value on the stack
50
self.setup_word_to_stack(self.new_pc)
53
self.setup_regs[Reg.SREG] = 0
57
def analyze_results(self):
59
self.is_pc_checked = 1
60
self.reg_changed.extend( [ Reg.SP, Reg.SREG ] )
62
# check that SP changed correctly
63
expect = self.setup_regs[Reg.SP] + 2
64
got = self.anal_regs[Reg.SP]
67
self.fail('RETI stack pop failed! SP: expect=%x, got=%x' % (
70
# check that PC changed correctly
72
got = self.anal_regs[Reg.PC]/2
75
self.fail('RETI operation failed! PC: expect=%x, got=%x' % (
78
# check that the SREG.I flag is set and no others changed
79
expect = 0x1 << SREG.I
80
got = self.anal_regs[Reg.SREG]
83
self.fail('SREG incorrectly updated: expect=%02x, got=%02x' %(expect, got))
86
# Template code for test case.
87
# The fail method will raise a test specific exception.
90
template = """class RETI_new_%06x_old_%06x_TestFail(RETI_TestFail): pass
92
class test_RETI_old_%06x_new_%06x(base_RETI):
96
raise RETI_new_%06x_old_%06x_TestFail, s
100
# automagically generate the test_RETI_* class definitions
104
for old_pc in (0,255,256,(8*1024/2-1)):
105
for new_pc in (0,1,2,3,255,256,(8*1024/2-1)):
106
args = (old_pc,new_pc)*4
107
code += template % args