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