Debian Codegraph @

common/paf-common.h

raw
1 /*
2 * PAFlib common definitions.
3 *
4 * Copyright IBM Corp. 2013, 2014
5 *
6 * The MIT License (MIT)
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * 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 FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 *
26 * Contributors:
27 * IBM Corporation, Adhemerval Zanella - Initial implementation.
28 */
29
30 #ifndef _PAF_COMMON_H
31 # define _PAF_COMMON_H
32
33 #define attribute_hidden __attribute__ ((visibility ("hidden")))
34 #define attribute_constructor __attribute__ ((constructor))
35 #define attribute_initial_exec __attribute__ ((tls_model ("initial-exec")))
36 #define attribute_noinline __attribute__ ((noinline))
37 #define attribute_alwaysinline __attribute__ ((always_inline))
38 #define attribute_noreturn __attribute__ ((noreturn))
39
40
41 typedef unsigned long int spr_t;
42
43 #define __stringify_1(x) #x
44 #define __stringify(x) __stringify_1(x)
45
46 #define mfspr(rn) \
47 ({ spr_t __spr; \
48 asm volatile("mfspr %0," __stringify(rn) \
49 : "=r" (__spr)); \
50 __spr; \
51 })
52 #define mtspr(rn, v) \
53 ({ spr_t __spr = (spr_t)v; \
54 asm volatile("mtspr " __stringify(rn) ",%0" \
55 : : "r" (__spr)); \
56 })
57
58 #define mb() \
59 asm volatile("sync" : : : "memory");
60
61
62 #ifdef ENABLE_DEBUG
63 # define DEBUG(fmt, args...) fprintf(stderr, "%s:%d: debug: " fmt "\n", \
64 __FUNCTION__, __LINE__, ## args)
65 #else
66 # define DEBUG(fmt, args...) do { } while(0)
67 #endif
68
69 #endif