]>
Commit | Line | Data |
---|---|---|
d614a753 | 1 | /* Copyright (C) 2017-2020 Free Software Foundation, Inc. |
6d58ce5e RH |
2 | This file is part of the GNU C Library. |
3 | ||
4 | The GNU C Library is free software; you can redistribute it and/or | |
5 | modify it under the terms of the GNU Lesser General Public | |
6 | License as published by the Free Software Foundation; either | |
7 | version 2.1 of the License, or (at your option) any later version. | |
8 | ||
9 | The GNU C Library is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | Lesser General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU Lesser General Public | |
15 | License along with the GNU C Library. If not, see | |
5a82c748 | 16 | <https://www.gnu.org/licenses/>. */ |
6d58ce5e RH |
17 | |
18 | #include <assert.h> | |
19 | #include <stdbool.h> | |
20 | #include <stdlib.h> | |
21 | #include <unistd.h> | |
22 | ||
23 | ||
24 | static long int linux_sysconf (int name); | |
25 | ||
26 | /* Get the value of the system variable NAME. */ | |
27 | long int | |
28 | __sysconf (int name) | |
29 | { | |
30 | unsigned ctr; | |
31 | ||
32 | /* Unfortunately, the registers that contain the actual cache info | |
33 | (CCSIDR_EL1, CLIDR_EL1, and CSSELR_EL1) are protected by the Linux | |
34 | kernel (though they need not have been). However, CTR_EL0 contains | |
35 | the *minimum* linesize in the entire cache hierarchy, and is | |
36 | accessible to userland, for use in __aarch64_sync_cache_range, | |
37 | and it is a reasonable assumption that the L1 cache will have that | |
38 | minimum line size. */ | |
39 | switch (name) | |
40 | { | |
41 | case _SC_LEVEL1_ICACHE_LINESIZE: | |
42 | asm("mrs\t%0, ctr_el0" : "=r"(ctr)); | |
43 | return 4 << (ctr & 0xf); | |
44 | case _SC_LEVEL1_DCACHE_LINESIZE: | |
45 | asm("mrs\t%0, ctr_el0" : "=r"(ctr)); | |
46 | return 4 << ((ctr >> 16) & 0xf); | |
47 | } | |
48 | ||
49 | return linux_sysconf (name); | |
50 | } | |
51 | ||
52 | /* Now the generic Linux version. */ | |
53 | #undef __sysconf | |
54 | #define __sysconf static linux_sysconf | |
55 | #include <sysdeps/unix/sysv/linux/sysconf.c> |