]> git.proxmox.com Git - mirror_qemu.git/blame - util/cache-utils.c
translate-all: Change cpu_restore_state_from_tb() argument to CPUState
[mirror_qemu.git] / util / cache-utils.c
CommitLineData
664d2c44 1#include "qemu-common.h"
1de7afc9 2#include "qemu/cache-utils.h"
902b3d5c 3
e58ffeb3 4#if defined(_ARCH_PPC)
902b3d5c 5struct qemu_cache_conf qemu_cache_conf = {
6 .dcache_bsize = 16,
7 .icache_bsize = 16
8};
9
10#if defined _AIX
11#include <sys/systemcfg.h>
12
664d2c44 13void qemu_cache_utils_init(void)
902b3d5c 14{
15 qemu_cache_conf.icache_bsize = _system_configuration.icache_line;
16 qemu_cache_conf.dcache_bsize = _system_configuration.dcache_line;
17}
18
19#elif defined __linux__
664d2c44
RH
20#include "qemu/osdep.h"
21#include "elf.h"
4710036a 22
664d2c44 23void qemu_cache_utils_init(void)
902b3d5c 24{
664d2c44
RH
25 unsigned long dsize = qemu_getauxval(AT_DCACHEBSIZE);
26 unsigned long isize = qemu_getauxval(AT_ICACHEBSIZE);
902b3d5c 27
664d2c44
RH
28 if (dsize == 0 || isize == 0) {
29 if (dsize == 0) {
30 fprintf(stderr, "getauxval AT_DCACHEBSIZE failed\n");
31 }
32 if (isize == 0) {
33 fprintf(stderr, "getauxval AT_ICACHEBSIZE failed\n");
902b3d5c 34 }
664d2c44
RH
35 exit(1);
36
902b3d5c 37 }
664d2c44
RH
38 qemu_cache_conf.dcache_bsize = dsize;
39 qemu_cache_conf.icache_bsize = isize;
902b3d5c 40}
41
42#elif defined __APPLE__
7344da06 43#include <stdio.h>
902b3d5c 44#include <sys/types.h>
45#include <sys/sysctl.h>
46
664d2c44 47void qemu_cache_utils_init(void)
902b3d5c 48{
49 size_t len;
50 unsigned cacheline;
51 int name[2] = { CTL_HW, HW_CACHELINE };
52
7344da06 53 len = sizeof(cacheline);
902b3d5c 54 if (sysctl(name, 2, &cacheline, &len, NULL, 0)) {
55 perror("sysctl CTL_HW HW_CACHELINE failed");
56 } else {
57 qemu_cache_conf.dcache_bsize = cacheline;
58 qemu_cache_conf.icache_bsize = cacheline;
59 }
60}
902b3d5c 61
664d2c44 62#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
4836a2b0 63#include <errno.h>
e4ee916d 64#include <stdio.h>
4836a2b0
JL
65#include <stdlib.h>
66#include <string.h>
e4ee916d
JL
67#include <sys/types.h>
68#include <sys/sysctl.h>
69
664d2c44 70void qemu_cache_utils_init(void)
e4ee916d
JL
71{
72 size_t len = 4;
73 unsigned cacheline;
74
75 if (sysctlbyname ("machdep.cacheline_size", &cacheline, &len, NULL, 0)) {
76 fprintf(stderr, "sysctlbyname machdep.cacheline_size failed: %s\n",
77 strerror(errno));
78 exit(1);
79 }
80
81 qemu_cache_conf.dcache_bsize = cacheline;
82 qemu_cache_conf.icache_bsize = cacheline;
83}
12b6278f 84#endif
e4ee916d 85
e58ffeb3 86#endif /* _ARCH_PPC */