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

« back to all changes in this revision

Viewing changes to src/stack.h

  • 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
/*
 
2
 * $Id: stack.h,v 1.4 2003/12/01 07:35:54 troth Exp $
 
3
 *
 
4
 ****************************************************************************
 
5
 *
 
6
 * simulavr - A simulator for the Atmel AVR family of microcontrollers.
 
7
 * Copyright (C) 2001, 2002, 2003  Theodore A. Roth
 
8
 *
 
9
 * This program is free software; you can redistribute it and/or modify
 
10
 * it under the terms of the GNU General Public License as published by
 
11
 * the Free Software Foundation; either version 2 of the License, or
 
12
 * (at your option) any later version.
 
13
 *
 
14
 * This program is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 * GNU General Public License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU General Public License
 
20
 * along with this program; if not, write to the Free Software
 
21
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
22
 *
 
23
 ****************************************************************************
 
24
 */
 
25
 
 
26
#ifndef SIM_STACK_H
 
27
#define SIM_STACK_H
 
28
 
 
29
/****************************************************************************\
 
30
 *
 
31
 * Stack(AvrClass) Definition. 
 
32
 *
 
33
 * This is a virtual class for higher level stack implementations and as such
 
34
 * should not be used directly.
 
35
 *
 
36
\****************************************************************************/
 
37
 
 
38
typedef struct _Stack Stack;
 
39
 
 
40
typedef uint32_t (*StackFP_Pop) (Stack *stack, int bytes);
 
41
typedef void (*StackFP_Push) (Stack *stack, int bytes, uint32_t val);
 
42
 
 
43
typedef enum
 
44
{
 
45
    STACK_HARDWARE,
 
46
    STACK_MEMORY,
 
47
} StackType;
 
48
 
 
49
struct _Stack
 
50
{
 
51
    AvrClass parent;
 
52
    StackFP_Pop pop;
 
53
    StackFP_Push push;
 
54
};
 
55
 
 
56
extern Stack *stack_new (StackFP_Pop pop, StackFP_Push push);
 
57
extern void stack_construct (Stack *stack, StackFP_Pop pop,
 
58
                             StackFP_Push push);
 
59
extern void stack_destroy (void *stack);
 
60
 
 
61
extern uint32_t stack_pop (Stack *stack, int bytes);
 
62
extern void stack_push (Stack *stack, int bytes, uint32_t val);
 
63
 
 
64
/****************************************************************************\
 
65
 *
 
66
 * HWStack(Stack) Definition.
 
67
 *
 
68
\****************************************************************************/
 
69
 
 
70
typedef struct _Hardware_Stack HWStack;
 
71
 
 
72
struct _Hardware_Stack
 
73
{
 
74
    Stack parent;
 
75
    int depth;
 
76
    uint32_t *stack;            /* an array used as the stack */
 
77
};
 
78
 
 
79
extern HWStack *hwstack_new (int depth);
 
80
extern void hwstack_construct (HWStack *stack, int depth);
 
81
extern void hwstack_destroy (void *stack);
 
82
 
 
83
/****************************************************************************\
 
84
 *
 
85
 * MemStack(Stack) Definition.
 
86
 *
 
87
\****************************************************************************/
 
88
 
 
89
typedef struct _Memory_Stack MemStack;
 
90
 
 
91
enum _stack_point_constants
 
92
{
 
93
    STACK_POINTER_BASE = 0x5d,
 
94
    STACK_POINTER_SIZE = 2,
 
95
 
 
96
    SPL_ADDR = STACK_POINTER_BASE,
 
97
    SPH_ADDR = STACK_POINTER_BASE + 1,
 
98
 
 
99
    SPL_IO_REG = SPL_ADDR - IO_REG_ADDR_BEGIN,
 
100
    SPH_IO_REG = SPH_ADDR - IO_REG_ADDR_BEGIN,
 
101
};
 
102
 
 
103
struct _Memory_Stack
 
104
{
 
105
    Stack parent;
 
106
    Memory *mem;                /* Memory were the stack will live */
 
107
    VDevice *SP;                /* Virtual Device for the stack pointer */
 
108
};
 
109
 
 
110
extern MemStack *memstack_new (Memory *mem);
 
111
extern void memstack_construct (MemStack *stack, Memory *mem);
 
112
extern void memstack_destroy (void *stack);
 
113
 
 
114
#endif /* SIM_STACK_H */