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

Subversion Repositories aemb

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

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

Line No. Rev Author Line
1 151 sybreon
/* $Id: stack.hh,v 1.8 2008-04-28 20:29:15 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 145 sybreon
** under the terms of the GNU General Public License as published by
10
** the Free Software Foundation, either version 3 of the License, or
11
** (at your option) any later version.
12 107 sybreon
**
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 145 sybreon
** or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
16
** License for more details.
17 107 sybreon
**
18 145 sybreon
** You should have received a copy of the GNU General Public License
19
** along with AEMB.  If not, see .
20 107 sybreon
*/
21
 
22
/**
23
   Basic stack related functions
24
   @file stack.hh
25
 */
26
 
27 151 sybreon
#ifndef _AEMB_STACK_HH
28
#define _AEMB_STACK_HH
29 107 sybreon
 
30 139 sybreon
#ifdef __cplusplus
31 151 sybreon
extern "C" {
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 151 sybreon
  inline int aembGetStackSize()
40 107 sybreon
  {
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 151 sybreon
  inline int aembGetStackEnd()
53 107 sybreon
  {
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 151 sybreon
  inline int aembGetStackTop()
66 107 sybreon
  {
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 151 sybreon
  inline int aembGetStack()
78 107 sybreon
  {
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 151 sybreon
  inline int aembSetStack(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 151 sybreon
  inline void aembDupStack(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
        // this increments 1 word (not 1 byte)
110
        newp++;
111
        oldp++;
112
      }
113
  }
114
 
115 139 sybreon
#ifdef __cplusplus
116 107 sybreon
}
117 139 sybreon
#endif
118 107 sybreon
 
119
#endif
120
 
121
/*
122
  $Log: not supported by cvs2svn $
123 151 sybreon
  Revision 1.7  2008/04/27 16:33:42  sybreon
124
  License change to GPL3.
125
 
126 145 sybreon
  Revision 1.6  2008/04/27 16:04:42  sybreon
127
  Minor cosmetic changes.
128
 
129 141 sybreon
  Revision 1.5  2008/04/26 19:31:35  sybreon
130
  Made headers C compatible.
131
 
132 139 sybreon
  Revision 1.4  2008/04/26 18:04:31  sybreon
133
  Updated software to freeze T0 and run T1.
134
 
135 135 sybreon
  Revision 1.3  2008/04/23 14:19:39  sybreon
136
  Fixed minor bugs.
137
  Initial use of hardware mutex.
138
 
139 128 sybreon
  Revision 1.2  2008/04/20 16:35:53  sybreon
140
  Added C/C++ compatible #ifdef statements
141
 
142 121 sybreon
  Revision 1.1  2008/04/09 19:48:37  sybreon
143
  Added new C++ files
144
 
145 107 sybreon
*/

powered by: WebSVN 2.1.0

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