diff options
author | malc <malc@c046a42c-6fe2-441c-8c8c-71466251a162> | 2008-12-10 19:18:40 +0000 |
---|---|---|
committer | malc <malc@c046a42c-6fe2-441c-8c8c-71466251a162> | 2008-12-10 19:18:40 +0000 |
commit | 933538ba553a59ed04f74eabffad5ab63ebb57bd (patch) | |
tree | cad585902aebf14be473f75fe5bf9c09b4e1b7a1 /cache-utils.c | |
parent | de9c7008151324a1512b438b5bc673ec730cedc8 (diff) | |
download | qemu-933538ba553a59ed04f74eabffad5ab63ebb57bd.tar.gz qemu-933538ba553a59ed04f74eabffad5ab63ebb57bd.tar.bz2 qemu-933538ba553a59ed04f74eabffad5ab63ebb57bd.zip |
Introduce and use cache-utils.[ch]
Thanks to Segher Boessenkool and Holis Blanchard.
AIX and Darwin cache inquiry:
http://gcc.gnu.org/ml/gcc-patches/2007-08/msg00388.html
Auxiliary vectors:
http://manugarg.googlepages.com/aboutelfauxiliaryvectors
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5973 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'cache-utils.c')
-rw-r--r-- | cache-utils.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/cache-utils.c b/cache-utils.c new file mode 100644 index 0000000000..0b4a5acb82 --- /dev/null +++ b/cache-utils.c @@ -0,0 +1,68 @@ +#include "cache-utils.h" + +#ifdef __powerpc__ +struct qemu_cache_conf qemu_cache_conf = { + .dcache_bsize = 16, + .icache_bsize = 16 +}; + +#if defined _AIX +#include <sys/systemcfg.h> + +static void ppc_init_cacheline_sizes(void) +{ + qemu_cache_conf.icache_bsize = _system_configuration.icache_line; + qemu_cache_conf.dcache_bsize = _system_configuration.dcache_line; +} + +#elif defined __linux__ +#include <linux/auxvec.h> + +static void ppc_init_cacheline_sizes(char **envp) +{ + unsigned long *auxv; + + while (*envp++); + + for (auxv = (unsigned long *) envp; *auxv != AT_NULL; auxv += 2) { + switch (*auxv) { + case AT_DCACHEBSIZE: qemu_cache_conf.dcache_bsize = auxv[1]; break; + case AT_ICACHEBSIZE: qemu_cache_conf.icache_bsize = auxv[1]; break; + default: break; + } + } +} + +#elif defined __APPLE__ +#include <sys/types.h> +#include <sys/sysctl.h> + +static void ppc_init_cacheline_sizes(void) +{ + size_t len; + unsigned cacheline; + int name[2] = { CTL_HW, HW_CACHELINE }; + + if (sysctl(name, 2, &cacheline, &len, NULL, 0)) { + perror("sysctl CTL_HW HW_CACHELINE failed"); + } else { + qemu_cache_conf.dcache_bsize = cacheline; + qemu_cache_conf.icache_bsize = cacheline; + } +} +#endif + +#ifdef __linux__ +void qemu_cache_utils_init(char **envp) +{ + ppc_init_cacheline_sizes(envp); +} +#else +void qemu_cache_utils_init(char **envp) +{ + (void) envp; + ppc_init_cacheline_sizes(); +} +#endif + +#endif /* __powerpc__ */ |