* Function to translate virtual to physical addresses.
*/
#include "xc_private.h"
-#include <strings.h>
#define CR0_PG 0x80000000
#define CR4_PAE 0x20
/* 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)
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
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__ */
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)
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);
#include <stdlib.h>
#include <unistd.h>
#include <zlib.h>
-#include <strings.h>
#include <malloc.h>
#include "xg_private.h"