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

Subversion Repositories aemb

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

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

Line No. Rev Author Line
1 135 sybreon
/* $Id: stack.hh,v 1.4 2008-04-26 18:04:31 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
namespace aemb {
31
 
32
  /**
33
  Reads the size of the memory space allocated for the stack in bytes.
34
  @return size of stack
35
  */
36
 
37
  inline int getStackSize()
38
  {
39
    int tmp;
40
    asm ("la %0, r0, _STACK_SIZE":"=r"(tmp));
41
    return tmp;
42
  }
43
 
44
  /**
45 135 sybreon
  Reads the end of the memory space allocated for the stack. This is
46
  where the stack ends.
47 107 sybreon
  @return end of stack
48
  */
49
 
50
  inline int getStackEnd()
51
  {
52
    int tmp;
53
    asm ("la %0, r0, _stack_end":"=r"(tmp));
54
    return tmp;
55
  }
56
 
57
  /**
58 135 sybreon
  Reads the top of the memory space allocated for the stack. This is
59
  where the stack starts.
60 107 sybreon
  @return top of stack
61
  */
62
 
63
  inline int getStackTop()
64
  {
65
    int tmp;
66
    asm ("la %0, r0, _stack":"=r"(tmp));
67
    return tmp;
68
  }
69
 
70
  /**
71
  Reads register R1 which is the designated stack pointer.
72
  @return stack pointer
73
  */
74
 
75
  inline int getStack()
76
  {
77
    int tmp;
78 128 sybreon
    asm ("addk %0, r0, r1":"=r"(tmp));
79 107 sybreon
    return tmp;
80
  }
81
 
82
  /**
83
  Sets register R1 to the new stack pointer.
84
  @param stk new stack pointer
85 135 sybreon
  @return new stack pointer
86 107 sybreon
  */
87
 
88 135 sybreon
  inline int setStack(int stk)
89 107 sybreon
  {
90 128 sybreon
    asm ("addk r1, r0, %0"::"r"(stk));
91 135 sybreon
    return stk;
92 107 sybreon
  }
93 121 sybreon
 
94 135 sybreon
  /**
95
     Duplicates the stack
96
     @param newp new stack pointer
97
     @param oldp old stack pointer
98
     @param endp end of the stack
99
  */
100
 
101
  inline void dupStack(int *newp, int *oldp, int *endp)
102
  {
103
    while (oldp < endp)
104
      {
105
        // copy the stack content
106
        *newp = *oldp;
107
 
108
        // this increments 1 word (not 1 byte)
109
        newp++;
110
        oldp++;
111
      }
112
  }
113
 
114 107 sybreon
}
115
 
116
#endif
117
 
118
/*
119
  $Log: not supported by cvs2svn $
120 135 sybreon
  Revision 1.3  2008/04/23 14:19:39  sybreon
121
  Fixed minor bugs.
122
  Initial use of hardware mutex.
123
 
124 128 sybreon
  Revision 1.2  2008/04/20 16:35:53  sybreon
125
  Added C/C++ compatible #ifdef statements
126
 
127 121 sybreon
  Revision 1.1  2008/04/09 19:48:37  sybreon
128
  Added new C++ files
129
 
130 107 sybreon
*/

powered by: WebSVN 2.1.0

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