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_CALL.py,v 1.1 2002/03/26 05:26:54 troth Exp $
26
"""Test the CALL opcode.
30
from registers import Reg
32
class CALL_TestFail(base_test.TestFail): pass
34
class base_CALL(base_test.opcode_stack_32_test):
35
"""Generic test case for testing CALL opcode.
37
The derived class must provide the reg member and the fail method.
39
CALL - Relative call to subroutine
44
SP <- SP - 2 __or__ SP <- SP - 3
45
(2 bytes, 16 bit PC) (3 bytes, 22 bit PC)
47
opcode is '1001 010k kkkk 111k kkkk kkkk kkkk kkkk' 0 <= k < 4M
50
self.setup_regs[Reg.PC] = 0xff * 2
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)
58
def analyze_results(self):
59
self.reg_changed.append( Reg.SP )
60
self.is_pc_checked = 1
63
got = self.anal_regs[Reg.PC] / 2
66
self.fail('CALL failed: expect=%x, got=%x' % (expect, got))
68
sp_expect = self.setup_regs[Reg.SP] - 2 # 16 bit PC
69
sp_got = self.anal_regs[Reg.SP]
71
if sp_got != sp_expect:
72
self.fail('CALL stack push failed: expect=%x, got=%x' % (
76
# Template code for test case.
77
# The fail method will raise a test specific exception.
80
class CALL_%06x_TestFail(CALL_TestFail): pass
82
class test_CALL_%06x(base_CALL):
85
raise CALL_%06x_TestFail, s
89
# automagically generate the test_CALL_* class definitions
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
96
for k in (0x100, 0x3ff):
97
code += template % ((k & 0xffffff), (k & 0xffffff), k, (k & 0xffffff))