sysconf: move in from cpp-cheat

arm baremetal: give more TTBR rationale
This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-07-18 00:00:00 +00:00
parent 3ea041e4d9
commit afb38d249b
4 changed files with 49 additions and 0 deletions

View File

@@ -11887,6 +11887,25 @@ What is POSIX:
* 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
==== 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
Programs under `userland/arch/<arch>/` are examples of userland assembly programming.

View File

@@ -22,10 +22,15 @@ int main(void) {
uint64_t tcr_el1;
__asm__ ("mrs %0, tcr_el1;" : "=r" (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;
__asm__ ("mrs %0, ttbr0_el1;" : "=r" (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;

13
userland/linux/sysconf.c Normal file
View 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
View 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;
}