~ubuntu-branches/ubuntu/dapper/simulavr/dapper

« back to all changes in this revision

Viewing changes to regress/test_opcodes/test_RETI.py

  • Committer: Bazaar Package Importer
  • Author(s): Shaun Jackman
  • Date: 2004-04-10 13:54:17 UTC
  • Revision ID: james.westby@ubuntu.com-20040410135417-zywapjyz252y65se
Tags: upstream-0.1.2.1
ImportĀ upstreamĀ versionĀ 0.1.2.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
 
2
###############################################################################
 
3
#
 
4
# simulavr - A simulator for the Atmel AVR family of microcontrollers.
 
5
# Copyright (C) 2001, 2002  Theodore A. Roth
 
6
#
 
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.
 
11
#
 
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.
 
16
#
 
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
 
20
#
 
21
###############################################################################
 
22
#
 
23
# $Id: test_RETI.py,v 0.5 josef
 
24
#
 
25
 
 
26
"""Test the RETI opcode.
 
27
"""
 
28
 
 
29
import base_test
 
30
from registers import Reg, SREG
 
31
 
 
32
class RETI_TestFail(base_test.TestFail): pass
 
33
 
 
34
class base_RETI(base_test.opcode_stack_test):
 
35
        """Generic test case for testing RETI opcode.
 
36
 
 
37
        The derived class must provide the reg member and the fail method.
 
38
        
 
39
        description: RETI - return from interrupt routine the return address
 
40
                     is loaded from the stack and set the global interrupt flag
 
41
        syntax:      RETI
 
42
        
 
43
        opcode is '1001 0101 0001 1000'
 
44
        """
 
45
        def setup(self):
 
46
                # set the pc to a different position
 
47
                self.setup_regs[Reg.PC] = self.old_pc * 2
 
48
 
 
49
                # put the value on the stack
 
50
                self.setup_word_to_stack(self.new_pc)
 
51
 
 
52
                # zero the SREG
 
53
                self.setup_regs[Reg.SREG] = 0
 
54
 
 
55
                return 0x9518
 
56
 
 
57
        def analyze_results(self):
 
58
 
 
59
                self.is_pc_checked = 1
 
60
                self.reg_changed.extend( [ Reg.SP, Reg.SREG ] )
 
61
 
 
62
                # check that SP changed correctly
 
63
                expect = self.setup_regs[Reg.SP] + 2
 
64
                got    = self.anal_regs[Reg.SP]
 
65
 
 
66
                if got != expect:
 
67
                        self.fail('RETI stack pop failed! SP: expect=%x, got=%x' % (
 
68
                                expect, got ))
 
69
 
 
70
                # check that PC changed correctly
 
71
                expect = self.new_pc
 
72
                got = self.anal_regs[Reg.PC]/2
 
73
 
 
74
                if got != expect:
 
75
                        self.fail('RETI operation failed! PC: expect=%x, got=%x' % (
 
76
                                expect, got ))
 
77
 
 
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]
 
81
 
 
82
                if got != expect:
 
83
                        self.fail('SREG incorrectly updated: expect=%02x, got=%02x' %(expect, got))
 
84
 
 
85
#
 
86
# Template code for test case.
 
87
# The fail method will raise a test specific exception.
 
88
#
 
89
 
 
90
template = """class RETI_new_%06x_old_%06x_TestFail(RETI_TestFail): pass
 
91
 
 
92
class test_RETI_old_%06x_new_%06x(base_RETI):
 
93
        old_pc = 0x%06x
 
94
        new_pc = 0x%06x
 
95
        def fail(self,s):
 
96
                raise RETI_new_%06x_old_%06x_TestFail, s
 
97
"""
 
98
 
 
99
#
 
100
# automagically generate the test_RETI_* class definitions
 
101
#
 
102
code = ''
 
103
 
 
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
 
108
exec code