| 1 |
2 |
alfik |
#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 |
|
|
* This agreement shall be governed in all respects by the laws of the State *
|
| 30 |
|
|
* of California and by the laws of the United States of America. *
|
| 31 |
|
|
* *
|
| 32 |
|
|
******************************************************************************/
|
| 33 |
|
|
#include "system.h"
|
| 34 |
|
|
#include "alt_types.h"
|
| 35 |
|
|
|
| 36 |
|
|
/*
|
| 37 |
|
|
* Instructions that might mean something special to a simulator.
|
| 38 |
|
|
* These have no special effect on real hardware (they are just nops).
|
| 39 |
|
|
*/
|
| 40 |
|
|
#define ALT_SIM_FAIL() \
|
| 41 |
|
|
do { __asm volatile ("cmpltui r0, r0, 0xabc1"); } while (0)
|
| 42 |
|
|
|
| 43 |
|
|
#define ALT_SIM_PASS() \
|
| 44 |
|
|
do { __asm volatile ("cmpltui r0, r0, 0xabc2"); } while (0)
|
| 45 |
|
|
|
| 46 |
|
|
#define ALT_SIM_IN_TOP_OF_HOT_LOOP() \
|
| 47 |
|
|
do { __asm volatile ("cmpltui r0, r0, 0xabc3"); } while (0)
|
| 48 |
|
|
|
| 49 |
|
|
/*
|
| 50 |
|
|
* Routine called on exit.
|
| 51 |
|
|
*/
|
| 52 |
|
|
static ALT_INLINE ALT_ALWAYS_INLINE void alt_sim_halt(int exit_code)
|
| 53 |
|
|
{
|
| 54 |
|
|
int r2 = exit_code;
|
| 55 |
|
|
|
| 56 |
|
|
#if defined(NIOS2_HAS_DEBUG_STUB) && (defined(ALT_BREAK_ON_EXIT) || defined(ALT_PROVIDE_GMON))
|
| 57 |
|
|
|
| 58 |
|
|
int r3 = (1 << 2);
|
| 59 |
|
|
|
| 60 |
|
|
#ifdef ALT_PROVIDE_GMON
|
| 61 |
|
|
extern unsigned int alt_gmon_data[];
|
| 62 |
|
|
int r4 = (int)alt_gmon_data;
|
| 63 |
|
|
r3 |= (1 << 4);
|
| 64 |
|
|
#define ALT_GMON_DATA ,"D04"(r4)
|
| 65 |
|
|
#else
|
| 66 |
|
|
#define ALT_GMON_DATA
|
| 67 |
|
|
#endif /* ALT_PROVIDE_GMON */
|
| 68 |
|
|
|
| 69 |
|
|
if (r2) {
|
| 70 |
|
|
ALT_SIM_FAIL();
|
| 71 |
|
|
} else {
|
| 72 |
|
|
ALT_SIM_PASS();
|
| 73 |
|
|
}
|
| 74 |
|
|
|
| 75 |
|
|
__asm__ volatile ("\n0:\n\taddi %0,%0, -1\n\tbgt %0,zero,0b" : : "r" (ALT_CPU_FREQ/100) ); /* Delay for >30ms */
|
| 76 |
|
|
|
| 77 |
|
|
__asm__ volatile ("break 2" : : "D02"(r2), "D03"(r3) ALT_GMON_DATA );
|
| 78 |
|
|
|
| 79 |
|
|
#else /* !DEBUG_STUB */
|
| 80 |
|
|
if (r2) {
|
| 81 |
|
|
ALT_SIM_FAIL();
|
| 82 |
|
|
} else {
|
| 83 |
|
|
ALT_SIM_PASS();
|
| 84 |
|
|
}
|
| 85 |
|
|
#endif /* DEBUG_STUB */
|
| 86 |
|
|
}
|
| 87 |
|
|
|
| 88 |
|
|
#define ALT_SIM_HALT(exit_code) \
|
| 89 |
|
|
alt_sim_halt(exit_code)
|
| 90 |
|
|
|
| 91 |
|
|
#endif /* __ALT_SIM_H__ */
|