alt_stack.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. * This agreement shall be governed in all respects by the laws of the State *
  27. * of California and by the laws of the United States of America. *
  28. * *
  29. ******************************************************************************/
  30. #ifndef __ALT_STACK_H__
  31. #define __ALT_STACK_H__
  32. /*
  33. * alt_stack.h is the nios2 specific implementation of functions used by the
  34. * stack overflow code.
  35. */
  36. #include "nios2.h"
  37. #include "alt_types.h"
  38. #ifdef __cplusplus
  39. extern "C"
  40. {
  41. #endif /* __cplusplus */
  42. extern char * alt_stack_limit_value;
  43. #ifdef ALT_EXCEPTION_STACK
  44. extern char __alt_exception_stack_pointer[]; /* set by the linker */
  45. #endif /* ALT_EXCEPTION_STACK */
  46. /*
  47. * alt_stack_limit can be called to determine the current value of the stack
  48. * limit register.
  49. */
  50. static ALT_INLINE char * ALT_ALWAYS_INLINE alt_stack_limit (void)
  51. {
  52. char * limit;
  53. NIOS2_READ_ET(limit);
  54. return limit;
  55. }
  56. /*
  57. * alt_stack_pointer can be called to determine the current value of the stack
  58. * pointer register.
  59. */
  60. static ALT_INLINE char * ALT_ALWAYS_INLINE alt_stack_pointer (void)
  61. {
  62. char * pointer;
  63. NIOS2_READ_SP(pointer);
  64. return pointer;
  65. }
  66. #ifdef ALT_EXCEPTION_STACK
  67. /*
  68. * alt_exception_stack_pointer returns the normal stack pointer from
  69. * where it is stored on the exception stack (uppermost 4 bytes). This
  70. * is really only useful during exception processing, and is only
  71. * available if a separate exception stack has been configured.
  72. */
  73. static ALT_INLINE char * ALT_ALWAYS_INLINE alt_exception_stack_pointer (void)
  74. {
  75. return (char *) *(alt_u32 *)(__alt_exception_stack_pointer - sizeof(alt_u32));
  76. }
  77. #endif /* ALT_EXCEPTION_STACK */
  78. /*
  79. * alt_set_stack_limit can be called to update the current value of the stack
  80. * limit register.
  81. */
  82. static ALT_INLINE void ALT_ALWAYS_INLINE alt_set_stack_limit (char * limit)
  83. {
  84. alt_stack_limit_value = limit;
  85. NIOS2_WRITE_ET(limit);
  86. }
  87. /*
  88. * alt_report_stack_overflow reports that a stack overflow happened.
  89. */
  90. static ALT_INLINE void ALT_ALWAYS_INLINE alt_report_stack_overflow (void)
  91. {
  92. NIOS2_REPORT_STACK_OVERFLOW();
  93. }
  94. #ifdef __cplusplus
  95. }
  96. #endif /* __cplusplus */
  97. #endif /* __ALT_STACK_H__ */