1 /*
2 Copyright (c) 2018, MIPI Alliance, Inc.
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in
14 the documentation and/or other materials provided with the
15 distribution.
16
17 * Neither the name of the copyright holder nor the names of its
18 contributors may be used to endorse or promote products derived
19 from this software without specific prior written permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 /*
35 * Contributors:
36 * Norbert Schulz (Intel Corporation) - Initial API and implementation
37 */
38
39 /* Compiler dependent code */
40
41 #include "mipi_syst.h"
42
43 #if defined(_WIN32) /* MSVC Compiler section */
44
45 #include <intrin.h>
46 #pragma intrinsic(_ReturnAddress)
47
48 #if defined(MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS)
49 /**
50 * Return the instruction pointer address of the instruction
51 * that follows this function. It is used to compute
52 * location information for SyS-T instrumentation calls.
53 * These are the calls that end with the _LOCADDR suffix.
54 */
mipi_syst_return_addr()55 MIPI_SYST_EXPORT void *MIPI_SYST_CALLCONV mipi_syst_return_addr()
56 {
57 return _ReturnAddress();
58 }
59 #endif /* defined(MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS) */
60
61 #elif defined(__GNUC__) /* GNU-C Compiler section */
62
63 #if defined(MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS)
64 /**
65 * Return the instruction pointer address of the instruction
66 * that follows this function. It is used to compute
67 * location information for SyS-T instrumentation calls.
68 * These are the calls that end with the _LOCADDR suffix.
69 */
mipi_syst_return_addr()70 MIPI_SYST_EXPORT void *MIPI_SYST_CALLCONV mipi_syst_return_addr()
71 {
72 return __builtin_return_address(0);
73 }
74 #endif
75
76 #else
77 #error unknown compiler, copy and adapt one of the sections above
78 #endif