]>
Commit | Line | Data |
---|---|---|
7adcbafe | 1 | /* Copyright (C) 2011-2022 Free Software Foundation, Inc. |
aebac0ca RH |
2 | Contributed by Richard Henderson <rth@redhat.com>. |
3 | ||
4 | This file is part of the GNU Transactional Memory Library (libitm). | |
5 | ||
6 | Libitm is free software; you can redistribute it and/or modify it | |
7 | under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 3 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | Libitm is distributed in the hope that it will be useful, but WITHOUT ANY | |
12 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
13 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
14 | more details. | |
15 | ||
16 | Under Section 7 of GPL version 3, you are granted additional | |
17 | permissions described in the GCC Runtime Library Exception, version | |
18 | 3.1, as published by the Free Software Foundation. | |
19 | ||
20 | You should have received a copy of the GNU General Public License and | |
21 | a copy of the GCC Runtime Library Exception along with this program; | |
22 | see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | <http://www.gnu.org/licenses/>. */ | |
24 | ||
25 | /* This file initializes GTM_hwcap in some os-specific way to indicate | |
26 | what ISA extensions are present for ARM. */ | |
27 | ||
28 | #include "libitm_i.h" | |
29 | #include "hwcap.h" | |
30 | ||
31 | /* Begin by defaulting to whatever options were given to the compiler. */ | |
32 | int GTM_hwcap HIDDEN = 0 | |
33 | #ifdef __VFP_FP__ | |
34 | | HWCAP_ARM_VFP | |
35 | #endif | |
36 | #ifdef __IWMMXT__ | |
37 | | HWCAP_ARM_IWMMXT | |
38 | #endif | |
39 | ; | |
40 | ||
41 | #ifdef __linux__ | |
42 | #include <unistd.h> | |
96ce40cb | 43 | #include <fcntl.h> |
aebac0ca RH |
44 | #include <elf.h> |
45 | ||
46 | static void __attribute__((constructor)) | |
47 | init_gtm_hwcap(void) | |
48 | { | |
49 | int fd = open ("/proc/self/auxv", O_RDONLY); | |
50 | if (fd < 0) | |
51 | return; | |
52 | ||
53 | Elf32_auxv_t pairs[512]; | |
54 | ssize_t rlen = read (fd, pairs, sizeof(pairs)); | |
55 | close (fd); | |
56 | if (rlen < 0) | |
57 | return; | |
58 | ||
59 | size_t n = (size_t)rlen / sizeof(pairs[0]); | |
60 | for (size_t i = 0; i < n; ++i) | |
61 | if (pairs[i].a_type == AT_HWCAP) | |
62 | { | |
63 | GTM_hwcap = pairs[i].a_un.a_val; | |
64 | return; | |
65 | } | |
66 | } | |
67 | #endif |