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

« back to all changes in this revision

Viewing changes to regress/test_opcodes/test_ROR.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_ROR.py,v 1.1 2002/02/23 01:35:39 troth Exp $
 
24
#
 
25
 
 
26
"""Test the ROR opcode.
 
27
"""
 
28
 
 
29
import base_test
 
30
from registers import Reg, SREG
 
31
 
 
32
class ROR_TestFail(base_test.TestFail): pass
 
33
 
 
34
class base_ROR(base_test.opcode_test):
 
35
        """Generic test case for testing ROR opcode.
 
36
 
 
37
        ROR - Rotate Right through Carry
 
38
        opcode is '1001 010d dddd 0111' where d is register (0-31)
 
39
 
 
40
        Only registers PC, Rd and SREG should be changed.
 
41
        """
 
42
        def setup(self):
 
43
                # Set SREG
 
44
                self.setup_regs[Reg.SREG] = (self.C << SREG.C)
 
45
 
 
46
                # Set the register values
 
47
                self.setup_regs[self.Rd] = self.Vd
 
48
 
 
49
                # Return the raw opcode
 
50
                return 0x9407 | (self.Rd << 4)
 
51
 
 
52
        def analyze_results(self):
 
53
                self.reg_changed.extend( [self.Rd, Reg.SREG] )
 
54
                
 
55
                # check that result is correct
 
56
                expect = ( ((self.Vd >> 1) & 0x7f) | (self.C << 7))
 
57
 
 
58
                got = self.anal_regs[self.Rd]
 
59
                
 
60
                if expect != got:
 
61
                        self.fail('ROR r%02d: 0x%02x = (expect=%02x, got=%02x)' % (
 
62
                                self.Rd, self.Vd, expect, got))
 
63
 
 
64
                expect_sreg = 0
 
65
 
 
66
                # calculate what we expect sreg to be (I, T and H should be zero)
 
67
                C = self.Vd & 1
 
68
                N = ((expect & 0x80) != 0)
 
69
                V = N ^ C
 
70
                expect_sreg += (N ^ V)       << SREG.S
 
71
                expect_sreg += V             << SREG.V
 
72
                expect_sreg += N             << SREG.N
 
73
                expect_sreg += (expect == 0) << SREG.Z
 
74
                expect_sreg += C             << SREG.C
 
75
 
 
76
                got_sreg = self.anal_regs[Reg.SREG]
 
77
 
 
78
                if expect_sreg != got_sreg:
 
79
                        self.fail('ROR r%02d: 0x%02x -> SREG (expect=%02x, got=%02x)' % (
 
80
                                self.Rd, self.Vd, expect_sreg, got_sreg))
 
81
 
 
82
#
 
83
# Template code for test case.
 
84
# The fail method will raise a test specific exception.
 
85
#
 
86
template = """
 
87
class ROR_r%02d_v%02x_C%d_TestFail(ROR_TestFail): pass
 
88
 
 
89
class test_ROR_r%02d_v%02x_C%d(base_ROR):
 
90
        Rd = %d
 
91
        Vd = 0x%x
 
92
        C  = %d
 
93
        def fail(self,s):
 
94
                raise ROR_r%02d_v%02x_C%d_TestFail, s
 
95
"""
 
96
 
 
97
#
 
98
# Define a list of test values such that we test all the cases of SREG bits being set.
 
99
#
 
100
vals = (
 
101
0x00,
 
102
0xff,
 
103
0x10,
 
104
0x80,
 
105
0xaa,
 
106
0x01,
 
107
0x08
 
108
)
 
109
 
 
110
#
 
111
# automagically generate the test_ROR_rNN_vXX_rrNN_kXX class definitions.
 
112
#
 
113
code = ''
 
114
for c in (0,1):
 
115
        for d in range(32):
 
116
                for vd in vals:
 
117
                        args = (d,vd,c)*4
 
118
                        code += template % args
 
119
 
 
120
exec code