alt_sim.h 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef __ALT_SIM_H__
  2. #define __ALT_SIM_H__
  3. /******************************************************************************
  4. * *
  5. * License Agreement *
  6. * *
  7. * Copyright (c) 2007 Altera Corporation, San Jose, California, USA. *
  8. * All rights reserved. *
  9. * *
  10. * Permission is hereby granted, free of charge, to any person obtaining a *
  11. * copy of this software and associated documentation files (the "Software"), *
  12. * to deal in the Software without restriction, including without limitation *
  13. * the rights to use, copy, modify, merge, publish, distribute, sublicense, *
  14. * and/or sell copies of the Software, and to permit persons to whom the *
  15. * Software is furnished to do so, subject to the following conditions: *
  16. * *
  17. * The above copyright notice and this permission notice shall be included in *
  18. * all copies or substantial portions of the Software. *
  19. * *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
  21. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
  22. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
  23. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
  24. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
  25. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
  26. * DEALINGS IN THE SOFTWARE. *
  27. * *
  28. * This agreement shall be governed in all respects by the laws of the State *
  29. * of California and by the laws of the United States of America. *
  30. * *
  31. ******************************************************************************/
  32. #include "system.h"
  33. #include "alt_types.h"
  34. /*
  35. * Instructions that might mean something special to a simulator.
  36. * These have no special effect on real hardware (they are just nops).
  37. */
  38. #define ALT_SIM_FAIL() \
  39. do { __asm volatile ("cmpltui r0, r0, 0xabc1"); } while (0)
  40. #define ALT_SIM_PASS() \
  41. do { __asm volatile ("cmpltui r0, r0, 0xabc2"); } while (0)
  42. #define ALT_SIM_IN_TOP_OF_HOT_LOOP() \
  43. do { __asm volatile ("cmpltui r0, r0, 0xabc3"); } while (0)
  44. /*
  45. * Routine called on exit.
  46. */
  47. static ALT_INLINE ALT_ALWAYS_INLINE void alt_sim_halt(int exit_code)
  48. {
  49. register int r2 asm ("r2") = exit_code;
  50. #if defined(NIOS2_HAS_DEBUG_STUB) && (defined(ALT_BREAK_ON_EXIT) || defined(ALT_PROVIDE_GMON))
  51. register int r3 asm ("r3") = (1 << 2);
  52. #ifdef ALT_PROVIDE_GMON
  53. extern unsigned int alt_gmon_data[];
  54. register int r4 asm ("r4") = (int)alt_gmon_data;
  55. r3 |= (1 << 4);
  56. #define ALT_GMON_DATA ,"r"(r4)
  57. #else
  58. #define ALT_GMON_DATA
  59. #endif /* ALT_PROVIDE_GMON */
  60. if (r2) {
  61. ALT_SIM_FAIL();
  62. } else {
  63. ALT_SIM_PASS();
  64. }
  65. __asm__ volatile ("\n0:\n\taddi %0,%0, -1\n\tbgt %0,zero,0b" : : "r" (ALT_CPU_FREQ/100) ); /* Delay for >30ms */
  66. __asm__ volatile ("break 2" : : "r"(r2), "r"(r3) ALT_GMON_DATA );
  67. #else /* !DEBUG_STUB */
  68. if (r2) {
  69. ALT_SIM_FAIL();
  70. } else {
  71. ALT_SIM_PASS();
  72. }
  73. #endif /* DEBUG_STUB */
  74. }
  75. #define ALT_SIM_HALT(exit_code) \
  76. alt_sim_halt(exit_code)
  77. #endif /* __ALT_SIM_H__ */