diff --git a/README.adoc b/README.adoc index 23dddd0..1bfac40 100644 --- a/README.adoc +++ b/README.adoc @@ -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//` are examples of userland assembly programming. diff --git a/baremetal/arch/aarch64/dump_regs.c b/baremetal/arch/aarch64/dump_regs.c index d9ab7ca..68f067c 100644 --- a/baremetal/arch/aarch64/dump_regs.c +++ b/baremetal/arch/aarch64/dump_regs.c @@ -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; diff --git a/userland/linux/sysconf.c b/userland/linux/sysconf.c new file mode 100644 index 0000000..cd27b77 --- /dev/null +++ b/userland/linux/sysconf.c @@ -0,0 +1,13 @@ +/* https://github.com/cirosantilli/linux-kernel-module-cheat#sysconf */ + +#define _XOPEN_SOURCE 700 +#include +#include +#include + +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; +} diff --git a/userland/posix/sysconf.c b/userland/posix/sysconf.c new file mode 100644 index 0000000..8c39d87 --- /dev/null +++ b/userland/posix/sysconf.c @@ -0,0 +1,12 @@ +/* https://github.com/cirosantilli/linux-kernel-module-cheat#sysconf */ + +#define _XOPEN_SOURCE 700 +#include +#include +#include + +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; +}