mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
sysconf: move in from cpp-cheat
arm baremetal: give more TTBR rationale
This commit is contained in:
19
README.adoc
19
README.adoc
@@ -11887,6 +11887,25 @@ What is POSIX:
|
|||||||
* https://stackoverflow.com/questions/1780599/what-is-the-meaning-of-posix/31865755#31865755
|
* https://stackoverflow.com/questions/1780599/what-is-the-meaning-of-posix/31865755#31865755
|
||||||
* https://unix.stackexchange.com/questions/11983/what-exactly-is-posix/220877#220877
|
* https://unix.stackexchange.com/questions/11983/what-exactly-is-posix/220877#220877
|
||||||
|
|
||||||
|
==== sysconf
|
||||||
|
|
||||||
|
https://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
* link:userland/posix/sysconf.c[]
|
||||||
|
* link:userland/linux/sysconf.c[] showcases Linux extensions to POSIX
|
||||||
|
|
||||||
|
Get lots of info on the system configuration.
|
||||||
|
|
||||||
|
The constants can also be viewed accessed on my Ubuntu 18.04 host with:
|
||||||
|
|
||||||
|
....
|
||||||
|
getconf -a
|
||||||
|
....
|
||||||
|
|
||||||
|
`getconf` is also specified by POSIX at: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/getconf.html but not the `-a` option which shows all configurations.
|
||||||
|
|
||||||
== Userland assembly
|
== Userland assembly
|
||||||
|
|
||||||
Programs under `userland/arch/<arch>/` are examples of userland assembly programming.
|
Programs under `userland/arch/<arch>/` are examples of userland assembly programming.
|
||||||
|
|||||||
@@ -22,10 +22,15 @@ int main(void) {
|
|||||||
uint64_t tcr_el1;
|
uint64_t tcr_el1;
|
||||||
__asm__ ("mrs %0, tcr_el1;" : "=r" (tcr_el1) : :);
|
__asm__ ("mrs %0, tcr_el1;" : "=r" (tcr_el1) : :);
|
||||||
printf("TCR_EL1 0x%" PRIX64 "\n", tcr_el1);
|
printf("TCR_EL1 0x%" PRIX64 "\n", tcr_el1);
|
||||||
|
printf("TCR_EL1.A1 0x%" PRIX64 "\n", (tcr_el1 >> 22) & 1);
|
||||||
|
|
||||||
uint64_t ttbr0_el1;
|
uint64_t ttbr0_el1;
|
||||||
__asm__ ("mrs %0, ttbr0_el1;" : "=r" (ttbr0_el1) : :);
|
__asm__ ("mrs %0, ttbr0_el1;" : "=r" (ttbr0_el1) : :);
|
||||||
printf("TTBR0_EL1 0x%" PRIX64 "\n", ttbr0_el1);
|
printf("TTBR0_EL1 0x%" PRIX64 "\n", ttbr0_el1);
|
||||||
|
|
||||||
|
uint64_t ttbr1_el1;
|
||||||
|
__asm__ ("mrs %0, ttbr1_el1;" : "=r" (ttbr1_el1) : :);
|
||||||
|
printf("TTBR1_EL1 0x%" PRIX64 "\n", ttbr1_el1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
13
userland/linux/sysconf.c
Normal file
13
userland/linux/sysconf.c
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
/* https://github.com/cirosantilli/linux-kernel-module-cheat#sysconf */
|
||||||
|
|
||||||
|
#define _XOPEN_SOURCE 700
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
/* Number of processors, not considering affinity:
|
||||||
|
* http://stackoverflow.com/questions/2693948/how-do-i-retrieve-the-number-of-processors-on-c-linux */
|
||||||
|
printf("_SC_NPROCESSORS_ONLN = %ld\n", sysconf(_SC_NPROCESSORS_ONLN));
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
12
userland/posix/sysconf.c
Normal file
12
userland/posix/sysconf.c
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
/* https://github.com/cirosantilli/linux-kernel-module-cheat#sysconf */
|
||||||
|
|
||||||
|
#define _XOPEN_SOURCE 700
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
/* Maximum lengh of command line arguments + environment variables: */
|
||||||
|
printf("_SC_ARG_MAX (MiB) = %ld\n", sysconf(_SC_ARG_MAX) / (1 << 20));
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user