1 /******************************************************************************
2 * *
3 * License Agreement *
4 * *
5 * Copyright (c) 2004 Altera Corporation, San Jose, California, USA. *
6 * All rights reserved. *
7 * *
8 * Permission is hereby granted, free of charge, to any person obtaining a *
9 * copy of this software and associated documentation files (the "Software"), *
10 * to deal in the Software without restriction, including without limitation *
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense, *
12 * and/or sell copies of the Software, and to permit persons to whom the *
13 * Software is furnished to do so, subject to the following conditions: *
14 * *
15 * The above copyright notice and this permission notice shall be included in *
16 * all copies or substantial portions of the Software. *
17 * *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
24 * DEALINGS IN THE SOFTWARE. *
25 * *
26 * *
27 ******************************************************************************/
28
29 #ifndef __ALT_STACK_H__
30 #define __ALT_STACK_H__
31
32 /*
33 * alt_stack.h is the nios2 specific implementation of functions used by the
34 * stack overflow code.
35 */
36
37 #include "nios2.h"
38
39 #include "alt_types.h"
40
41 #ifdef __cplusplus
42 extern "C"
43 {
44 #endif /* __cplusplus */
45
46
47 extern char * alt_stack_limit_value;
48
49 #ifdef ALT_EXCEPTION_STACK
50 extern char __alt_exception_stack_pointer[]; /* set by the linker */
51 #endif /* ALT_EXCEPTION_STACK */
52
53
54 /*
55 * alt_stack_limit can be called to determine the current value of the stack
56 * limit register.
57 */
58
alt_stack_limit(void)59 static ALT_INLINE char * ALT_ALWAYS_INLINE alt_stack_limit (void)
60 {
61 char * limit;
62 NIOS2_READ_ET(limit);
63
64 return limit;
65 }
66
67 /*
68 * alt_stack_pointer can be called to determine the current value of the stack
69 * pointer register.
70 */
71
alt_stack_pointer(void)72 static ALT_INLINE char * ALT_ALWAYS_INLINE alt_stack_pointer (void)
73 {
74 char * pointer;
75 NIOS2_READ_SP(pointer);
76
77 return pointer;
78 }
79
80
81 #ifdef ALT_EXCEPTION_STACK
82
83 /*
84 * alt_exception_stack_pointer returns the normal stack pointer from
85 * where it is stored on the exception stack (uppermost 4 bytes). This
86 * is really only useful during exception processing, and is only
87 * available if a separate exception stack has been configured.
88 */
89
alt_exception_stack_pointer(void)90 static ALT_INLINE char * ALT_ALWAYS_INLINE alt_exception_stack_pointer (void)
91 {
92 return (char *) *(alt_u32 *)(__alt_exception_stack_pointer - sizeof(alt_u32));
93 }
94
95 #endif /* ALT_EXCEPTION_STACK */
96
97
98 /*
99 * alt_set_stack_limit can be called to update the current value of the stack
100 * limit register.
101 */
102
alt_set_stack_limit(char * limit)103 static ALT_INLINE void ALT_ALWAYS_INLINE alt_set_stack_limit (char * limit)
104 {
105 alt_stack_limit_value = limit;
106 NIOS2_WRITE_ET(limit);
107 }
108
109 /*
110 * alt_report_stack_overflow reports that a stack overflow happened.
111 */
112
alt_report_stack_overflow(void)113 static ALT_INLINE void ALT_ALWAYS_INLINE alt_report_stack_overflow (void)
114 {
115 NIOS2_REPORT_STACK_OVERFLOW();
116 }
117
118
119 #ifdef __cplusplus
120 }
121 #endif /* __cplusplus */
122
123 #endif /* __ALT_STACK_H__ */
124