diff options
author | Keir Fraser <keir.fraser@citrix.com> | 2009-01-06 09:14:39 +0000 |
---|---|---|
committer | Keir Fraser <keir.fraser@citrix.com> | 2009-01-06 09:14:39 +0000 |
commit | 7e72c30726d6c5588affffcfc9ee21ca32888030 (patch) | |
tree | 983e7ad7caeb3cb1642907949b64c2d13a8c19c1 | |
parent | c5e9f7aa3a7c36f7649f15a2c94a3ffd310c5bc5 (diff) | |
download | xen-7e72c30726d6c5588affffcfc9ee21ca32888030.tar.gz xen-7e72c30726d6c5588affffcfc9ee21ca32888030.tar.bz2 xen-7e72c30726d6c5588affffcfc9ee21ca32888030.zip |
libxc: Define xc_ffs{8,16,32,64} functions. Use them.
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
-rw-r--r-- | tools/libxc/xc_pagetab.c | 3 | ||||
-rw-r--r-- | tools/libxc/xc_private.c | 27 | ||||
-rw-r--r-- | tools/libxc/xc_private.h | 5 | ||||
-rw-r--r-- | tools/libxc/xc_ptrace.c | 5 | ||||
-rw-r--r-- | tools/libxc/xg_private.c | 1 |
5 files changed, 35 insertions, 6 deletions
diff --git a/tools/libxc/xc_pagetab.c b/tools/libxc/xc_pagetab.c index 8c628b4404..824cbbe988 100644 --- a/tools/libxc/xc_pagetab.c +++ b/tools/libxc/xc_pagetab.c @@ -4,7 +4,6 @@ * Function to translate virtual to physical addresses. */ #include "xc_private.h" -#include <strings.h> #define CR0_PG 0x80000000 #define CR4_PAE 0x20 @@ -77,7 +76,7 @@ unsigned long xc_translate_foreign_address(int xc_handle, uint32_t dom, /* Walk the pagetables */ for (level = pt_levels; level > 0; level--) { - paddr += ((virt & mask) >> (ffsll(mask) - 1)) * size; + paddr += ((virt & mask) >> (xc_ffs64(mask) - 1)) * size; map = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, PROT_READ, paddr >>PAGE_SHIFT); if (!map) diff --git a/tools/libxc/xc_private.c b/tools/libxc/xc_private.c index 5990415d9e..e0613b9e4f 100644 --- a/tools/libxc/xc_private.c +++ b/tools/libxc/xc_private.c @@ -639,6 +639,33 @@ int write_exact(int fd, const void *data, size_t size) return 0; } +int xc_ffs8(uint8_t x) +{ + int i; + for ( i = 0; i < 8; i++ ) + if ( x & (1u << i) ) + return i+1; + return 0; +} + +int xc_ffs16(uint16_t x) +{ + uint8_t h = x>>8, l = x; + return l ? xc_ffs8(l) : h ? xc_ffs8(h) + 8 : 0; +} + +int xc_ffs32(uint32_t x) +{ + uint16_t h = x>>16, l = x; + return l ? xc_ffs16(l) : h ? xc_ffs16(h) + 16 : 0; +} + +int xc_ffs64(uint64_t x) +{ + uint32_t h = x>>32, l = x; + return l ? xc_ffs32(l) : h ? xc_ffs32(h) + 32 : 0; +} + /* * Local variables: * mode: C diff --git a/tools/libxc/xc_private.h b/tools/libxc/xc_private.h index ef8e3d2f7a..d95bd0675d 100644 --- a/tools/libxc/xc_private.h +++ b/tools/libxc/xc_private.h @@ -218,4 +218,9 @@ int xc_flush_mmu_updates(int xc_handle, struct xc_mmu *mmu); int read_exact(int fd, void *data, size_t size); int write_exact(int fd, const void *data, size_t size); +int xc_ffs8(uint8_t x); +int xc_ffs16(uint16_t x); +int xc_ffs32(uint32_t x); +int xc_ffs64(uint64_t x); + #endif /* __XC_PRIVATE_H__ */ diff --git a/tools/libxc/xc_ptrace.c b/tools/libxc/xc_ptrace.c index 094bf165df..4fe67e9343 100644 --- a/tools/libxc/xc_ptrace.c +++ b/tools/libxc/xc_ptrace.c @@ -44,8 +44,7 @@ static uint64_t online_cpumap; static uint64_t regs_valid; static vcpu_guest_context_any_t ctxt[MAX_VIRT_CPUS]; -extern int ffsll(long long int); -#define FOREACH_CPU(cpumap, i) for ( cpumap = online_cpumap; (i = ffsll(cpumap)); cpumap &= ~(1 << (index - 1)) ) +#define FOREACH_CPU(cpumap, i) for ( cpumap = online_cpumap; (i = xc_ffs64(cpumap)); cpumap &= ~(1 << (index - 1)) ) static int fetch_regs(int xc_handle, int cpu, int *online) @@ -136,7 +135,7 @@ online_vcpus_changed(uint64_t cpumap) uint64_t changed_cpumap = cpumap ^ online_cpumap; int index; - while ( (index = ffsll(changed_cpumap)) ) { + while ( (index = xc_ffs64(changed_cpumap)) ) { if ( cpumap & (1 << (index - 1)) ) { if (handlers.td_create) handlers.td_create(index - 1); diff --git a/tools/libxc/xg_private.c b/tools/libxc/xg_private.c index 544d089cdf..36eb1c7758 100644 --- a/tools/libxc/xg_private.c +++ b/tools/libxc/xg_private.c @@ -7,7 +7,6 @@ #include <stdlib.h> #include <unistd.h> #include <zlib.h> -#include <strings.h> #include <malloc.h> #include "xg_private.h" |