This code should now build the x86_x64-softmmu part 2.
This commit is contained in:
@ -18,7 +18,12 @@
|
||||
/* For C11 atomic ops */
|
||||
|
||||
/* Compiler barrier */
|
||||
#ifdef _MSC_VER
|
||||
// TODO: fix me!!!
|
||||
#define barrier() //{ __asm volatile("" ::: "memory"); (void)0; }
|
||||
#else
|
||||
#define barrier() ({ asm volatile("" ::: "memory"); (void)0; })
|
||||
#endif
|
||||
|
||||
#ifndef __ATOMIC_RELAXED
|
||||
|
||||
@ -31,9 +36,19 @@
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
#if !QEMU_GNUC_PREREQ(4, 4)
|
||||
#if defined __x86_64__
|
||||
#define smp_mb() ({ asm volatile("mfence" ::: "memory"); (void)0; })
|
||||
# ifdef _MSC_VER
|
||||
// TODO: fix me!!!
|
||||
# define smp_mb() //{ __asm volatile("mfence" ::: "memory"); (void)0; }
|
||||
# else
|
||||
# define smp_mb() ({ asm volatile("mfence" ::: "memory"); (void)0; })
|
||||
# endif
|
||||
#else
|
||||
#define smp_mb() ({ asm volatile("lock; addl $0,0(%%esp) " ::: "memory"); (void)0; })
|
||||
# ifdef _MSC_VER
|
||||
// TODO: fix me!!!
|
||||
# define smp_mb() //{ __asm volatile("lock; addl $0,0(%esp) " ::: "memory"); (void)0; }
|
||||
# else
|
||||
# define smp_mb() ({ asm volatile("lock; addl $0,0(%%esp) " ::: "memory"); (void)0; })
|
||||
# endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
@ -183,6 +198,19 @@
|
||||
#endif
|
||||
|
||||
/* Provide shorter names for GCC atomic builtins. */
|
||||
#ifdef _MSC_VER
|
||||
#ifdef _WIN64
|
||||
#define atomic_fetch_inc(ptr) InterlockedIncrement64(ptr)
|
||||
#define atomic_fetch_dec(ptr) InterlockedDecrement64(ptr)
|
||||
#define atomic_fetch_add(ptr, n) InterlockedAdd64(ptr, n)
|
||||
#define atomic_fetch_sub(ptr, n) InterlockedAdd64(ptr, -n)
|
||||
#else
|
||||
#define atomic_fetch_inc(ptr) InterlockedIncrement(ptr)
|
||||
#define atomic_fetch_dec(ptr) InterlockedDecrement(ptr)
|
||||
#define atomic_fetch_add(ptr, n) InterlockedAdd(ptr, n)
|
||||
#define atomic_fetch_sub(ptr, n) InterlockedAdd(ptr, -n)
|
||||
#endif
|
||||
#else
|
||||
#define atomic_fetch_inc(ptr) __sync_fetch_and_add(ptr, 1)
|
||||
#define atomic_fetch_dec(ptr) __sync_fetch_and_add(ptr, -1)
|
||||
#define atomic_fetch_add __sync_fetch_and_add
|
||||
@ -190,13 +218,28 @@
|
||||
#define atomic_fetch_and __sync_fetch_and_and
|
||||
#define atomic_fetch_or __sync_fetch_and_or
|
||||
#define atomic_cmpxchg __sync_val_compare_and_swap
|
||||
#endif
|
||||
|
||||
/* And even shorter names that return void. */
|
||||
#ifdef _MSC_VER
|
||||
#ifdef _WIN64
|
||||
#define atomic_inc(ptr) ((void) InterlockedIncrement64(ptr))
|
||||
#define atomic_dec(ptr) ((void) InterlockedDecrement64(ptr))
|
||||
#define atomic_add(ptr, n) ((void) InterlockedAdd64(ptr, n))
|
||||
#define atomic_sub(ptr, n) ((void) InterlockedAdd64(ptr, -n))
|
||||
#else
|
||||
#define atomic_inc(ptr) ((void) InterlockedIncrement(ptr))
|
||||
#define atomic_dec(ptr) ((void) InterlockedDecrement(ptr))
|
||||
#define atomic_add(ptr, n) ((void) InterlockedAdd(ptr, n))
|
||||
#define atomic_sub(ptr, n) ((void) InterlockedAdd(ptr, -n))
|
||||
#endif
|
||||
#else
|
||||
#define atomic_inc(ptr) ((void) __sync_fetch_and_add(ptr, 1))
|
||||
#define atomic_dec(ptr) ((void) __sync_fetch_and_add(ptr, -1))
|
||||
#define atomic_add(ptr, n) ((void) __sync_fetch_and_add(ptr, n))
|
||||
#define atomic_sub(ptr, n) ((void) __sync_fetch_and_sub(ptr, n))
|
||||
#define atomic_and(ptr, n) ((void) __sync_fetch_and_and(ptr, n))
|
||||
#define atomic_or(ptr, n) ((void) __sync_fetch_and_or(ptr, n))
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -12,7 +12,7 @@
|
||||
#ifndef BITOPS_H
|
||||
#define BITOPS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include <assert.h>
|
||||
|
||||
#include "host-utils.h"
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define BSWAP_H
|
||||
|
||||
#include "config-host.h"
|
||||
#include <inttypes.h>
|
||||
#include "platform.h"
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include "fpu/softfloat.h"
|
||||
|
@ -5,6 +5,58 @@
|
||||
|
||||
#include "config-host.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// MSVC support
|
||||
|
||||
#define inline __inline
|
||||
#define __func__ __FUNCTION__
|
||||
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#define isinf(x) (!_finite(x))
|
||||
|
||||
static double rint( double x )
|
||||
{
|
||||
return floor(x < 0 ? x - 0.5 : x + 0.5);
|
||||
}
|
||||
|
||||
union MSVC_FLOAT_HACK
|
||||
{
|
||||
unsigned char Bytes[4];
|
||||
float Value;
|
||||
};
|
||||
|
||||
#ifndef NAN
|
||||
static union MSVC_FLOAT_HACK __NAN = {{0x00, 0x00, 0xC0, 0x7F}};
|
||||
#define NAN (__NAN.Value)
|
||||
#endif
|
||||
|
||||
#define QEMU_DIV0 __pragma(warning(suppress:2124)) // divide by zero error
|
||||
|
||||
#define QEMU_GNUC_PREREQ(maj, min) 0
|
||||
|
||||
#define QEMU_NORETURN __declspec(noreturn)
|
||||
#define QEMU_UNUSED_VAR __pragma(warning(suppress:4100)) // unused variables only
|
||||
#define QEMU_UNUSED_FUNC
|
||||
#define QEMU_WARN_UNUSED_RESULT
|
||||
#define QEMU_ARTIFICIAL
|
||||
#define QEMU_PACK( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop) )
|
||||
|
||||
#define QEMU_ALIGN(A, B) __declspec(align(A)) B
|
||||
|
||||
#define cat(x,y) x ## y
|
||||
#define cat2(x,y) cat(x,y)
|
||||
#define QEMU_BUILD_BUG_ON(x) \
|
||||
typedef char cat2(qemu_build_bug_on__,__LINE__)[(x)?-1:1] QEMU_UNUSED_VAR;
|
||||
|
||||
#define GCC_FMT_ATTR(n, m)
|
||||
|
||||
#else
|
||||
|
||||
#ifndef NAN
|
||||
#define NAN (0.0 / 0.0)
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| The macro QEMU_GNUC_PREREQ tests for minimum version of the GNU C compiler.
|
||||
| The code is a copy of SOFTFLOAT_GNUC_PREREQ, see softfloat-macros.h.
|
||||
@ -18,6 +70,9 @@
|
||||
|
||||
#define QEMU_NORETURN __attribute__ ((__noreturn__))
|
||||
|
||||
#define QEMU_UNUSED_VAR __attribute__((unused))
|
||||
#define QEMU_UNUSED_FUNC __attribute__((unused))
|
||||
|
||||
#if QEMU_GNUC_PREREQ(3, 4)
|
||||
#define QEMU_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
|
||||
#else
|
||||
@ -31,11 +86,13 @@
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
# define QEMU_PACKED __attribute__((gcc_struct, packed))
|
||||
# define QEMU_PACK( __Declaration__ ) __Declaration__ __attribute__((gcc_struct, packed))
|
||||
#else
|
||||
# define QEMU_PACKED __attribute__((packed))
|
||||
# define QEMU_PACK( __Declaration__ ) __Declaration__ __attribute__((packed))
|
||||
#endif
|
||||
|
||||
#define QEMU_ALIGN(A, B) B __attribute__((aligned(A)))
|
||||
|
||||
#define cat(x,y) x ## y
|
||||
#define cat2(x,y) cat(x,y)
|
||||
#define QEMU_BUILD_BUG_ON(x) \
|
||||
@ -58,4 +115,6 @@
|
||||
#define GCC_FMT_ATTR(n, m)
|
||||
#endif
|
||||
|
||||
#endif // _MSC_VER
|
||||
|
||||
#endif /* COMPILER_H */
|
||||
|
@ -150,7 +150,7 @@ static inline int clz64(uint64_t val)
|
||||
val >>= 32;
|
||||
}
|
||||
|
||||
return cnt + clz32(val);
|
||||
return cnt + clz32((uint32_t)val);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -240,7 +240,7 @@ static inline int ctz64(uint64_t val)
|
||||
val >>= 32;
|
||||
}
|
||||
|
||||
return cnt + ctz32(val);
|
||||
return cnt + ctz32((uint32_t)val);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -357,7 +357,7 @@ static inline int ctpop64(uint64_t val)
|
||||
val = (val & 0x0000ffff0000ffffULL) + ((val >> 16) & 0x0000ffff0000ffffULL);
|
||||
val = (val & 0x00000000ffffffffULL) + ((val >> 32) & 0x00000000ffffffffULL);
|
||||
|
||||
return val;
|
||||
return (int)val;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -379,4 +379,13 @@ static inline int ctpop64(uint64_t val)
|
||||
# error Unknown sizeof long
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <float.h>
|
||||
#if defined(_WIN64)
|
||||
#define isnan _isnanf
|
||||
#else
|
||||
#define isnan _isnan
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -2,8 +2,7 @@
|
||||
#define INT128_H
|
||||
|
||||
//#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "platform.h"
|
||||
|
||||
typedef struct Int128 Int128;
|
||||
|
||||
@ -14,7 +13,8 @@ struct Int128 {
|
||||
|
||||
static inline Int128 int128_make64(uint64_t a)
|
||||
{
|
||||
return (Int128) { a, 0 };
|
||||
Int128 i128 = { a, 0 };
|
||||
return i128;
|
||||
}
|
||||
|
||||
static inline uint64_t int128_get64(Int128 a)
|
||||
@ -35,17 +35,20 @@ static inline Int128 int128_one(void)
|
||||
|
||||
static inline Int128 int128_2_64(void)
|
||||
{
|
||||
return (Int128) { 0, 1 };
|
||||
Int128 i128 = { 0, 1 };
|
||||
return i128;
|
||||
}
|
||||
|
||||
static inline Int128 int128_exts64(int64_t a)
|
||||
{
|
||||
return (Int128) { .lo = a, .hi = (a < 0) ? -1 : 0 };
|
||||
Int128 i128 = { a, (a < 0) ? -1 : 0 };
|
||||
return i128;
|
||||
}
|
||||
|
||||
static inline Int128 int128_and(Int128 a, Int128 b)
|
||||
{
|
||||
return (Int128) { a.lo & b.lo, a.hi & b.hi };
|
||||
Int128 i128 = { a.lo & b.lo, a.hi & b.hi };
|
||||
return i128;
|
||||
}
|
||||
|
||||
static inline Int128 int128_rshift(Int128 a, int n)
|
||||
@ -56,9 +59,11 @@ static inline Int128 int128_rshift(Int128 a, int n)
|
||||
}
|
||||
h = a.hi >> (n & 63);
|
||||
if (n >= 64) {
|
||||
return (Int128) { h, h >> 63 };
|
||||
Int128 i128 = { h, h >> 63 };
|
||||
return i128;
|
||||
} else {
|
||||
return (Int128) { (a.lo >> n) | ((uint64_t)a.hi << (64 - n)), h };
|
||||
Int128 i128 = { (a.lo >> n) | ((uint64_t)a.hi << (64 - n)), h };
|
||||
return i128;
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,18 +77,21 @@ static inline Int128 int128_add(Int128 a, Int128 b)
|
||||
*
|
||||
* So the carry is lo < a.lo.
|
||||
*/
|
||||
return (Int128) { lo, (uint64_t)a.hi + b.hi + (lo < a.lo) };
|
||||
Int128 i128 = { lo, (uint64_t)a.hi + b.hi + (lo < a.lo) };
|
||||
return i128;
|
||||
}
|
||||
|
||||
static inline Int128 int128_neg(Int128 a)
|
||||
{
|
||||
uint64_t lo = -a.lo;
|
||||
return (Int128) { lo, ~(uint64_t)a.hi + !lo };
|
||||
uint64_t lo = 0-a.lo;
|
||||
Int128 i128 = { lo, ~(uint64_t)a.hi + !lo };
|
||||
return i128;
|
||||
}
|
||||
|
||||
static inline Int128 int128_sub(Int128 a, Int128 b)
|
||||
{
|
||||
return (Int128){ a.lo - b.lo, (uint64_t)a.hi - b.hi - (a.lo < b.lo) };
|
||||
Int128 i128 = { a.lo - b.lo, (uint64_t)a.hi - b.hi - (a.lo < b.lo) };
|
||||
return i128;
|
||||
}
|
||||
|
||||
static inline bool int128_nonneg(Int128 a)
|
||||
|
@ -2,8 +2,7 @@
|
||||
#define QEMU_LOG_H
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include "platform.h"
|
||||
#include "qemu/compiler.h"
|
||||
#include "qom/cpu.h"
|
||||
|
||||
|
@ -26,15 +26,17 @@ void DSO_STAMP_FUN(void);
|
||||
* check fails during module loading */
|
||||
void qemu_module_dummy(void);
|
||||
|
||||
//static void __attribute__((constructor)) do_qemu_init_ ## function(void)
|
||||
//static void __attribute__((constructor)) do_qemu_init_ ## function(void)
|
||||
#define module_init(function, type) \
|
||||
static void __attribute__((constructor)) do_qemu_init_ ## function(void) \
|
||||
INITIALIZER(do_qemu_init_ ## function) \
|
||||
{ \
|
||||
register_dso_module_init(function, type); \
|
||||
}
|
||||
#else
|
||||
/* This should not be used directly. Use block_init etc. instead. */
|
||||
#define module_init(function, type) \
|
||||
static void __attribute__((constructor)) do_qemu_init_ ## function(void) \
|
||||
INITIALIZER(do_qemu_init_ ## function) \
|
||||
{ \
|
||||
register_module_init(function, type); \
|
||||
}
|
||||
|
@ -4,8 +4,7 @@
|
||||
#include "config-host.h"
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include <sys/types.h>
|
||||
#ifdef __OpenBSD__
|
||||
#include <sys/signal.h>
|
||||
@ -18,7 +17,7 @@
|
||||
#define WEXITSTATUS(x) (x)
|
||||
#endif
|
||||
|
||||
#include <sys/time.h>
|
||||
#include "platform.h"
|
||||
|
||||
#if defined(CONFIG_SOLARIS) && CONFIG_SOLARIS_VERSION < 10
|
||||
/* [u]int_fast*_t not in <sys/int_types.h> */
|
||||
@ -44,15 +43,19 @@ typedef signed int int_fast16_t;
|
||||
#endif
|
||||
|
||||
#ifndef container_of
|
||||
#ifndef _MSC_VER
|
||||
#define container_of(ptr, type, member) ({ \
|
||||
const typeof(((type *) 0)->member) *__mptr = (ptr); \
|
||||
(type *) ((char *) __mptr - offsetof(type, member));})
|
||||
#else
|
||||
#define container_of(ptr, type, member) ((type *)((char *)(ptr) -offsetof(type,member)))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Convert from a base type to a parent type, with compile time checking. */
|
||||
#ifdef __GNUC__
|
||||
#define DO_UPCAST(type, field, dev) ( __extension__ ( { \
|
||||
char __attribute__((unused)) offset_must_be_zero[ \
|
||||
char QEMU_UNUSED_VAR offset_must_be_zero[ \
|
||||
-offsetof(type, field)]; \
|
||||
container_of(dev, type, field);}))
|
||||
#else
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef QEMU_RANGE_H
|
||||
#define QEMU_RANGE_H
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "platform.h"
|
||||
#include <qemu/typedefs.h>
|
||||
#include "qemu/queue.h"
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
#ifndef __QEMU_THREAD_H
|
||||
#define __QEMU_THREAD_H 1
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#include "platform.h"
|
||||
|
||||
typedef struct QemuMutex QemuMutex;
|
||||
typedef struct QemuThread QemuThread;
|
||||
|
@ -493,7 +493,7 @@ static inline int64_t get_clock(void)
|
||||
{
|
||||
LARGE_INTEGER ti;
|
||||
QueryPerformanceCounter(&ti);
|
||||
return muldiv64(ti.QuadPart, get_ticks_per_sec(), clock_freq);
|
||||
return muldiv64(ti.QuadPart, (uint32_t)get_ticks_per_sec(), (uint32_t)clock_freq);
|
||||
}
|
||||
|
||||
#else
|
||||
@ -545,9 +545,13 @@ static inline int64_t cpu_get_real_ticks(void)
|
||||
|
||||
static inline int64_t cpu_get_real_ticks(void)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
return __rdtsc();
|
||||
#else
|
||||
int64_t val;
|
||||
asm volatile ("rdtsc" : "=A" (val));
|
||||
return val;
|
||||
#endif
|
||||
}
|
||||
|
||||
#elif defined(__x86_64__)
|
||||
|
Reference in New Issue
Block a user