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

« back to all changes in this revision

Viewing changes to regress/test_opcodes/test_CALL.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_CALL.py,v 1.1 2002/03/26 05:26:54 troth Exp $
 
24
#
 
25
 
 
26
"""Test the CALL opcode.
 
27
"""
 
28
 
 
29
import base_test
 
30
from registers import Reg
 
31
 
 
32
class CALL_TestFail(base_test.TestFail): pass
 
33
 
 
34
class base_CALL(base_test.opcode_stack_32_test):
 
35
        """Generic test case for testing CALL opcode.
 
36
 
 
37
        The derived class must provide the reg member and the fail method.
 
38
 
 
39
        CALL - Relative call to subroutine
 
40
 
 
41
          PC <- k
 
42
          STACK <- PC + 2
 
43
          
 
44
          SP <- SP - 2         __or__         SP <- SP - 3
 
45
          (2 bytes, 16 bit PC)                (3 bytes, 22 bit PC)
 
46
          
 
47
        opcode is '1001 010k kkkk 111k kkkk kkkk kkkk kkkk'  0 <= k < 4M
 
48
        """
 
49
        def setup(self):
 
50
                self.setup_regs[Reg.PC] = 0xff * 2
 
51
 
 
52
                tmp = self.k >> 16 & 0x3f
 
53
                op = 0x940e | (tmp << 3) & 0x1f0 | tmp & 0x1
 
54
                op =  (op << 16 | self.k & 0xffff)
 
55
                #print 'setting up op: %x' %(op)
 
56
                return op
 
57
 
 
58
        def analyze_results(self):
 
59
                self.reg_changed.append( Reg.SP )
 
60
                self.is_pc_checked = 1
 
61
 
 
62
                expect = self.k
 
63
                got = self.anal_regs[Reg.PC] / 2
 
64
 
 
65
                if expect != got:
 
66
                        self.fail('CALL failed: expect=%x, got=%x' % (expect, got))
 
67
 
 
68
                sp_expect = self.setup_regs[Reg.SP] - 2 # 16 bit PC
 
69
                sp_got    = self.anal_regs[Reg.SP]
 
70
 
 
71
                if sp_got != sp_expect:
 
72
                        self.fail('CALL stack push failed: expect=%x, got=%x' % (
 
73
                                sp_expect, sp_got ))
 
74
 
 
75
#
 
76
# Template code for test case.
 
77
# The fail method will raise a test specific exception.
 
78
#
 
79
template = """
 
80
class CALL_%06x_TestFail(CALL_TestFail): pass
 
81
 
 
82
class test_CALL_%06x(base_CALL):
 
83
        k = 0x%x
 
84
        def fail(self,s):
 
85
                raise CALL_%06x_TestFail, s
 
86
"""
 
87
 
 
88
#
 
89
# automagically generate the test_CALL_* class definitions
 
90
#
 
91
# FIXME: TRoth 2002-02-22: Really need to check jumps which wrap around the
 
92
# ends of flash memory. Will need to know the size of the device's flash space
 
93
# to do that though.
 
94
#
 
95
code = ''
 
96
for k in (0x100, 0x3ff):
 
97
        code += template % ((k & 0xffffff), (k & 0xffffff), k, (k & 0xffffff))
 
98
exec code