OpenCores
URL https://opencores.org/ocsvn/aemb/aemb/trunk

Subversion Repositories aemb

[/] [aemb/] [trunk/] [sw/] [cc/] [aemb/] [stack.hh] - Blame information for rev 141

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 141 sybreon
/* $Id: stack.hh,v 1.6 2008-04-27 16:04:42 sybreon Exp $
2 107 sybreon
**
3
** AEMB2 HI-PERFORMANCE CPU
4
** Copyright (C) 2004-2007 Shawn Tan Ser Ngiap 
5
**
6
** This file is part of AEMB.
7
**
8
** AEMB is free software: you can redistribute it and/or modify it
9
** under the terms of the GNU Lesser General Public License as
10
** published by the Free Software Foundation, either version 3 of the
11
** License, or (at your option) any later version.
12
**
13
** AEMB is distributed in the hope that it will be useful, but WITHOUT
14
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15
** or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
16
** Public License for more details.
17
**
18
** You should have received a copy of the GNU Lesser General Public
19
** License along with AEMB. If not, see .
20
*/
21
 
22
/**
23
   Basic stack related functions
24
   @file stack.hh
25
 */
26
 
27
#ifndef AEMB_STACK_HH
28
#define AEMB_STACK_HH
29
 
30 139 sybreon
#ifdef __cplusplus
31 107 sybreon
namespace aemb {
32 139 sybreon
#endif
33 107 sybreon
 
34
  /**
35
  Reads the size of the memory space allocated for the stack in bytes.
36
  @return size of stack
37
  */
38
 
39
  inline int getStackSize()
40
  {
41
    int tmp;
42
    asm ("la %0, r0, _STACK_SIZE":"=r"(tmp));
43
    return tmp;
44
  }
45
 
46
  /**
47 135 sybreon
  Reads the end of the memory space allocated for the stack. This is
48
  where the stack ends.
49 107 sybreon
  @return end of stack
50
  */
51
 
52
  inline int getStackEnd()
53
  {
54
    int tmp;
55
    asm ("la %0, r0, _stack_end":"=r"(tmp));
56
    return tmp;
57
  }
58
 
59
  /**
60 135 sybreon
  Reads the top of the memory space allocated for the stack. This is
61
  where the stack starts.
62 107 sybreon
  @return top of stack
63
  */
64
 
65
  inline int getStackTop()
66
  {
67
    int tmp;
68
    asm ("la %0, r0, _stack":"=r"(tmp));
69
    return tmp;
70
  }
71
 
72
  /**
73
  Reads register R1 which is the designated stack pointer.
74
  @return stack pointer
75
  */
76
 
77
  inline int getStack()
78
  {
79
    int tmp;
80 128 sybreon
    asm ("addk %0, r0, r1":"=r"(tmp));
81 107 sybreon
    return tmp;
82
  }
83
 
84
  /**
85
  Sets register R1 to the new stack pointer.
86
  @param stk new stack pointer
87 135 sybreon
  @return new stack pointer
88 107 sybreon
  */
89
 
90 135 sybreon
  inline int setStack(int stk)
91 107 sybreon
  {
92 128 sybreon
    asm ("addk r1, r0, %0"::"r"(stk));
93 135 sybreon
    return stk;
94 107 sybreon
  }
95 121 sybreon
 
96 135 sybreon
  /**
97
     Duplicates the stack
98
     @param newp new stack pointer
99
     @param oldp old stack pointer
100
     @param endp end of the stack
101
  */
102
 
103 141 sybreon
  inline void dupStack(unsigned int *newp, unsigned int *oldp, unsigned int *endp)
104 135 sybreon
  {
105
    while (oldp < endp)
106
      {
107
        // copy the stack content
108
        *newp = *oldp;
109
 
110
        // this increments 1 word (not 1 byte)
111
        newp++;
112
        oldp++;
113
      }
114
  }
115
 
116 139 sybreon
#ifdef __cplusplus
117 107 sybreon
}
118 139 sybreon
#endif
119 107 sybreon
 
120
#endif
121
 
122
/*
123
  $Log: not supported by cvs2svn $
124 141 sybreon
  Revision 1.5  2008/04/26 19:31:35  sybreon
125
  Made headers C compatible.
126
 
127 139 sybreon
  Revision 1.4  2008/04/26 18:04:31  sybreon
128
  Updated software to freeze T0 and run T1.
129
 
130 135 sybreon
  Revision 1.3  2008/04/23 14:19:39  sybreon
131
  Fixed minor bugs.
132
  Initial use of hardware mutex.
133
 
134 128 sybreon
  Revision 1.2  2008/04/20 16:35:53  sybreon
135
  Added C/C++ compatible #ifdef statements
136
 
137 121 sybreon
  Revision 1.1  2008/04/09 19:48:37  sybreon
138
  Added new C++ files
139
 
140 107 sybreon
*/

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.