From: Keir Fraser Date: Wed, 15 Jul 2009 08:09:48 +0000 (+0100) Subject: minios: switch to C99 integer types X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=824eebe86f5832f6e9783ba9f2d5d45efbfa59dc;p=people%2Fliuw%2Flibxenctrl-split%2Fmini-os.git minios: switch to C99 integer types This is a necessary step to make minios build on NetBSD. Signed-off-by: Christoph Egger --- diff --git a/arch/ia64/common.c b/arch/ia64/common.c index 45b7703..c82e604 100644 --- a/arch/ia64/common.c +++ b/arch/ia64/common.c @@ -68,7 +68,7 @@ char boot_cmd_line[COMMAND_LINE_SIZE+1]; void -ia64_write_itr_i(ia64_pte_t* pteP, u32 reg, uint64_t vAddr, +ia64_write_itr_i(ia64_pte_t* pteP, uint32_t reg, uint64_t vAddr, uint64_t ps, uint64_t pk) { /* The virtual address. */ diff --git a/arch/ia64/time.c b/arch/ia64/time.c index d358730..4a3a558 100644 --- a/arch/ia64/time.c +++ b/arch/ia64/time.c @@ -178,7 +178,7 @@ timer_interrupt(evtchn_port_t port, struct pt_regs* regsP, void *data) /* * monotonic_clock(): returns # of nanoseconds passed since time_init() */ -u64 +uint64_t monotonic_clock(void) { uint64_t delta; diff --git a/arch/x86/time.c b/arch/x86/time.c index 4af0b89..a55bf59 100644 --- a/arch/x86/time.c +++ b/arch/x86/time.c @@ -46,15 +46,15 @@ /* These are peridically updated in shared_info, and then copied here. */ struct shadow_time_info { - u64 tsc_timestamp; /* TSC at last update of time vals. */ - u64 system_timestamp; /* Time, in nanosecs, since boot. */ - u32 tsc_to_nsec_mul; - u32 tsc_to_usec_mul; + uint64_t tsc_timestamp; /* TSC at last update of time vals. */ + uint64_t system_timestamp; /* Time, in nanosecs, since boot. */ + uint32_t tsc_to_nsec_mul; + uint32_t tsc_to_usec_mul; int tsc_shift; - u32 version; + uint32_t version; }; static struct timespec shadow_ts; -static u32 shadow_ts_version; +static uint32_t shadow_ts_version; static struct shadow_time_info shadow; @@ -84,11 +84,11 @@ static inline int time_values_up_to_date(void) * Scale a 64-bit delta by scaling and multiplying by a 32-bit fraction, * yielding a 64-bit result. */ -static inline u64 scale_delta(u64 delta, u32 mul_frac, int shift) +static inline uint64_t scale_delta(uint64_t delta, uint32_t mul_frac, int shift) { - u64 product; + uint64_t product; #ifdef __i386__ - u32 tmp1, tmp2; + uint32_t tmp1, tmp2; #endif if ( shift < 0 ) @@ -106,11 +106,11 @@ static inline u64 scale_delta(u64 delta, u32 mul_frac, int shift) "xor %5,%5 ; " "adc %5,%%edx ; " : "=A" (product), "=r" (tmp1), "=r" (tmp2) - : "a" ((u32)delta), "1" ((u32)(delta >> 32)), "2" (mul_frac) ); + : "a" ((uint32_t)delta), "1" ((uint32_t)(delta >> 32)), "2" (mul_frac) ); #else __asm__ ( "mul %%rdx ; shrd $32,%%rdx,%%rax" - : "=a" (product) : "0" (delta), "d" ((u64)mul_frac) ); + : "=a" (product) : "0" (delta), "d" ((uint64_t)mul_frac) ); #endif return product; @@ -119,7 +119,7 @@ static inline u64 scale_delta(u64 delta, u32 mul_frac, int shift) static unsigned long get_nsec_offset(void) { - u64 now, delta; + uint64_t now, delta; rdtscll(now); delta = now - shadow.tsc_timestamp; return scale_delta(delta, shadow.tsc_to_nsec_mul, shadow.tsc_shift); @@ -151,10 +151,10 @@ static void get_time_values_from_xen(void) * Note: This function is required to return accurate * time even in the absence of multiple timer ticks. */ -u64 monotonic_clock(void) +uint64_t monotonic_clock(void) { - u64 time; - u32 local_time_version; + uint64_t time; + uint32_t local_time_version; do { local_time_version = shadow.version; @@ -185,7 +185,7 @@ static void update_wallclock(void) int gettimeofday(struct timeval *tv, void *tz) { - u64 nsec = monotonic_clock(); + uint64_t nsec = monotonic_clock(); nsec += shadow_ts.tv_nsec; diff --git a/events.c b/events.c index 9ca78d0..c907e65 100644 --- a/events.c +++ b/events.c @@ -28,7 +28,7 @@ typedef struct _ev_action_t { evtchn_handler_t handler; void *data; - u32 count; + uint32_t count; } ev_action_t; static ev_action_t ev_actions[NR_EVS]; diff --git a/gnttab.c b/gnttab.c index 18fd87e..9b35052 100644 --- a/gnttab.c +++ b/gnttab.c @@ -102,7 +102,7 @@ gnttab_grant_transfer(domid_t domid, unsigned long pfn) int gnttab_end_access(grant_ref_t ref) { - u16 flags, nflags; + uint16_t flags, nflags; BUG_ON(ref >= NR_GRANT_ENTRIES || ref < NR_RESERVED_ENTRIES); @@ -123,7 +123,7 @@ unsigned long gnttab_end_transfer(grant_ref_t ref) { unsigned long frame; - u16 flags; + uint16_t flags; BUG_ON(ref >= NR_GRANT_ENTRIES || ref < NR_RESERVED_ENTRIES); diff --git a/hypervisor.c b/hypervisor.c index 936a17b..dad8b59 100644 --- a/hypervisor.c +++ b/hypervisor.c @@ -87,13 +87,13 @@ void force_evtchn_callback(void) }; } -inline void mask_evtchn(u32 port) +inline void mask_evtchn(uint32_t port) { shared_info_t *s = HYPERVISOR_shared_info; synch_set_bit(port, &s->evtchn_mask[0]); } -inline void unmask_evtchn(u32 port) +inline void unmask_evtchn(uint32_t port) { shared_info_t *s = HYPERVISOR_shared_info; vcpu_info_t *vcpu_info = &s->vcpu_info[smp_processor_id()]; @@ -114,7 +114,7 @@ inline void unmask_evtchn(u32 port) } } -inline void clear_evtchn(u32 port) +inline void clear_evtchn(uint32_t port) { shared_info_t *s = HYPERVISOR_shared_info; synch_clear_bit(port, &s->evtchn_pending[0]); diff --git a/include/arch/cc.h b/include/arch/cc.h index 02aeb2f..85cfbdb 100644 --- a/include/arch/cc.h +++ b/include/arch/cc.h @@ -13,17 +13,17 @@ #include #include #include -typedef u8 u8_t; -typedef s8 s8_t; -typedef u16 u16_t; -typedef s16 s16_t; -typedef u32 u32_t; -typedef s32 s32_t; -typedef u64 u64_t; -typedef s64 s64_t; +typedef uint8_t u8_t; +typedef int8_t s8_t; +typedef uint16_t u16_t; +typedef int16_t s16_t; +typedef uint32_t u32_t; +typedef int32_t s32_t; +typedef uint64_t u64_t; +typedef int64_t s64_t; typedef uintptr_t mem_ptr_t; -typedef u16 u_short; +typedef uint16_t u_short; /* Compiler hints for packing lwip's structures - */ #define PACK_STRUCT_FIELD(_x) _x diff --git a/include/fs.h b/include/fs.h index aa19135..2f91f8d 100644 --- a/include/fs.h +++ b/include/fs.h @@ -11,13 +11,13 @@ struct fs_import { domid_t dom_id; /* dom id of the exporting domain */ - u16 export_id; /* export id (exporting dom specific) */ - u16 import_id; /* import id (specific to this domain) */ + uint16_t export_id; /* export id (exporting dom specific) */ + uint16_t import_id; /* import id (specific to this domain) */ struct minios_list_head list; /* list of all imports */ unsigned int nr_entries; /* Number of entries in rings & request array */ struct fsif_front_ring ring; /* frontend ring (contains shared ring) */ - u32 gnt_refs[FSIF_RING_SIZE_PAGES]; /* grant references to the shared ring */ + uint32_t gnt_refs[FSIF_RING_SIZE_PAGES]; /* grant references to the shared ring */ evtchn_port_t local_port; /* local event channel port */ char *backend; /* XenBus location of the backend */ struct fs_request *requests; /* Table of requests */ diff --git a/include/hypervisor.h b/include/hypervisor.h index b4c7292..e299df1 100644 --- a/include/hypervisor.h +++ b/include/hypervisor.h @@ -40,9 +40,9 @@ extern union start_info_union start_info_union; /* hypervisor.c */ void force_evtchn_callback(void); void do_hypervisor_callback(struct pt_regs *regs); -void mask_evtchn(u32 port); -void unmask_evtchn(u32 port); -void clear_evtchn(u32 port); +void mask_evtchn(uint32_t port); +void unmask_evtchn(uint32_t port); +void clear_evtchn(uint32_t port); extern int in_callback; diff --git a/include/linux/types.h b/include/linux/types.h index 978f29e..ac596a7 100644 --- a/include/linux/types.h +++ b/include/linux/types.h @@ -1,5 +1,5 @@ #ifndef _LINUX_TYPES_H_ #define _LINUX_TYPES_H_ #include -typedef u64 __u64; +typedef uint64_t __u64; #endif /* _LINUX_TYPES_H_ */ diff --git a/include/sched.h b/include/sched.h index c60e61e..538bed5 100644 --- a/include/sched.h +++ b/include/sched.h @@ -20,7 +20,7 @@ struct thread thread_regs_t regs; #endif /* !defined(__ia64__) */ struct minios_list_head thread_list; - u32 flags; + uint32_t flags; s_time_t wakeup_time; #ifdef HAVE_LIBC struct _reent reent; @@ -54,6 +54,6 @@ void schedule(void); void wake(struct thread *thread); void block(struct thread *thread); -void msleep(u32 millisecs); +void msleep(uint32_t millisecs); #endif /* __SCHED_H__ */ diff --git a/include/time.h b/include/time.h index ac83df8..5d6ed67 100644 --- a/include/time.h +++ b/include/time.h @@ -29,7 +29,7 @@ * The other macros are for convenience to approximate short intervals * of real time into system time */ -typedef s64 s_time_t; +typedef int64_t s_time_t; #define NOW() ((s_time_t)monotonic_clock()) #define SECONDS(_s) (((s_time_t)(_s)) * 1000000000UL ) #define TENTHS(_ts) (((s_time_t)(_ts)) * 100000000UL ) @@ -57,7 +57,7 @@ void init_time(void); void fini_time(void); s_time_t get_s_time(void); s_time_t get_v_time(void); -u64 monotonic_clock(void); +uint64_t monotonic_clock(void); void block_domain(s_time_t until); #endif /* _MINIOS_TIME_H_ */ diff --git a/include/types.h b/include/types.h index 19b7302..456e21a 100644 --- a/include/types.h +++ b/include/types.h @@ -21,20 +21,6 @@ #define _TYPES_H_ #include -typedef signed char s8; -typedef unsigned char u8; -typedef signed short s16; -typedef unsigned short u16; -typedef signed int s32; -typedef unsigned int u32; -#ifdef __i386__ -typedef signed long long s64; -typedef unsigned long long u64; -#elif defined(__x86_64__) || defined(__ia64__) -typedef signed long s64; -typedef unsigned long u64; -#endif - /* FreeBSD compat types */ #ifndef HAVE_LIBC typedef unsigned char u_char; @@ -72,15 +58,22 @@ typedef int intptr_t; typedef unsigned long uintptr_t; typedef long intptr_t; #endif /* __i386__ || __x86_64__ */ -typedef u8 uint8_t; -typedef s8 int8_t; -typedef u16 uint16_t; -typedef s16 int16_t; -typedef u32 uint32_t; -typedef s32 int32_t; -typedef u64 uint64_t, uintmax_t; -typedef s64 int64_t, intmax_t; -typedef u64 off_t; +typedef unsigned char uint8_t; +typedef signed char int8_t; +typedef unsigned short uint16_t; +typedef signed short int16_t; +typedef unsigned int uint32_t; +typedef signed int int32_t; +#ifdef __i386__ +typedef signed long long int64_t; +typedef unsigned long long uint64_t; +#elif defined(__x86_64__) || defined(__ia64__) +typedef signed long int64_t; +typedef unsigned long uint64_t; +#endif +typedef uint64_t uintmax_t; +typedef int64_t intmax_t; +typedef uint64_t off_t; #endif typedef intptr_t ptrdiff_t; diff --git a/include/x86/os.h b/include/x86/os.h index 7fc3a83..6bd0ebe 100644 --- a/include/x86/os.h +++ b/include/x86/os.h @@ -445,7 +445,7 @@ static __inline__ unsigned long __ffs(unsigned long word) : /* no outputs */ \ : "c" (msr), "a" (val1), "d" (val2)) -#define wrmsrl(msr,val) wrmsr(msr,(u32)((u64)(val)),((u64)(val))>>32) +#define wrmsrl(msr,val) wrmsr(msr,(uint32_t)((uint64_t)(val)),((uint64_t)(val))>>32) #else /* ifdef __x86_64__ */ diff --git a/include/x86/x86_32/hypercall-x86_32.h b/include/x86/x86_32/hypercall-x86_32.h index d5f5b1e..43028ee 100644 --- a/include/x86/x86_32/hypercall-x86_32.h +++ b/include/x86/x86_32/hypercall-x86_32.h @@ -174,7 +174,7 @@ HYPERVISOR_sched_op( static inline long HYPERVISOR_set_timer_op( - u64 timeout) + uint64_t timeout) { unsigned long timeout_hi = (unsigned long)(timeout>>32); unsigned long timeout_lo = (unsigned long)timeout; @@ -197,7 +197,7 @@ HYPERVISOR_get_debugreg( static inline int HYPERVISOR_update_descriptor( - u64 ma, u64 desc) + uint64_t ma, uint64_t desc) { return _hypercall4(int, update_descriptor, ma, ma>>32, desc, desc>>32); } diff --git a/include/x86/x86_64/hypercall-x86_64.h b/include/x86/x86_64/hypercall-x86_64.h index 32ea5bd..b874f03 100644 --- a/include/x86/x86_64/hypercall-x86_64.h +++ b/include/x86/x86_64/hypercall-x86_64.h @@ -178,7 +178,7 @@ HYPERVISOR_sched_op( static inline long HYPERVISOR_set_timer_op( - u64 timeout) + uint64_t timeout) { return _hypercall1(long, set_timer_op, timeout); } diff --git a/kernel.c b/kernel.c index f2bd01f..33c91b5 100644 --- a/kernel.c +++ b/kernel.c @@ -49,7 +49,7 @@ static struct netfront_dev *net_dev; -u8 xen_features[XENFEAT_NR_SUBMAPS * 32]; +uint8_t xen_features[XENFEAT_NR_SUBMAPS * 32]; void setup_xen_features(void) { diff --git a/lib/math.c b/lib/math.c index f1f7826..55ece1e 100644 --- a/lib/math.c +++ b/lib/math.c @@ -68,8 +68,8 @@ * one or more of the following formats. */ union uu { - s64 q; /* as a (signed) quad */ - s64 uq; /* as an unsigned quad */ + int64_t q; /* as a (signed) quad */ + int64_t uq; /* as an unsigned quad */ long sl[2]; /* as two signed longs */ unsigned long ul[2]; /* as two unsigned longs */ }; @@ -90,7 +90,7 @@ union uu { #ifndef HAVE_LIBC #define CHAR_BIT 8 /* number of bits in a char */ #endif -#define QUAD_BITS (sizeof(s64) * CHAR_BIT) +#define QUAD_BITS (sizeof(int64_t) * CHAR_BIT) #define LONG_BITS (sizeof(long) * CHAR_BIT) #define HALF_BITS (sizeof(long) * CHAR_BIT / 2) @@ -147,8 +147,8 @@ shl(register digit *p, register int len, register int sh) * divisor are 4 `digits' in this base (they are shorter if they have * leading zeros). */ -u64 -__qdivrem(u64 uq, u64 vq, u64 *arq) +uint64_t +__qdivrem(uint64_t uq, uint64_t vq, uint64_t *arq) { union uu tmp; digit *u, *v, *q; @@ -348,31 +348,31 @@ __qdivrem(u64 uq, u64 vq, u64 *arq) * Divide two signed quads. * ??? if -1/2 should produce -1 on this machine, this code is wrong */ -s64 -__divdi3(s64 a, s64 b) +int64_t +__divdi3(int64_t a, int64_t b) { - u64 ua, ub, uq; + uint64_t ua, ub, uq; int neg; if (a < 0) - ua = -(u64)a, neg = 1; + ua = -(uint64_t)a, neg = 1; else ua = a, neg = 0; if (b < 0) - ub = -(u64)b, neg ^= 1; + ub = -(uint64_t)b, neg ^= 1; else ub = b; - uq = __qdivrem(ua, ub, (u64 *)0); + uq = __qdivrem(ua, ub, (uint64_t *)0); return (neg ? -uq : uq); } /* * Divide two unsigned quads. */ -u64 -__udivdi3(u64 a, u64 b) +uint64_t +__udivdi3(uint64_t a, uint64_t b) { - return (__qdivrem(a, b, (u64 *)0)); + return (__qdivrem(a, b, (uint64_t *)0)); } diff --git a/lib/sys.c b/lib/sys.c index 166ecc9..8cb5d28 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -1189,7 +1189,7 @@ int clock_gettime(clockid_t clk_id, struct timespec *tp) } case CLOCK_REALTIME: { - u64 nsec = monotonic_clock(); + uint64_t nsec = monotonic_clock(); tp->tv_sec = nsec / 1000000000ULL; tp->tv_nsec = nsec % 1000000000ULL; diff --git a/lwip-arch.c b/lwip-arch.c index cdd4fa6..e634ef4 100644 --- a/lwip-arch.c +++ b/lwip-arch.c @@ -20,7 +20,7 @@ void sys_init(void) /* Creates and returns a new semaphore. The "count" argument specifies * the initial state of the semaphore. */ -sys_sem_t sys_sem_new(u8_t count) +sys_sem_t sys_sem_new(uint8_t count) { struct semaphore *sem = xmalloc(struct semaphore); sem->count = count; @@ -50,13 +50,13 @@ void sys_sem_signal(sys_sem_t sem) * semaphore wasn't signaled within the specified time, the return value is * SYS_ARCH_TIMEOUT. If the thread didn't have to wait for the semaphore * (i.e., it was already signaled), the function may return zero. */ -u32_t sys_arch_sem_wait(sys_sem_t sem, u32_t timeout) +uint32_t sys_arch_sem_wait(sys_sem_t sem, uint32_t timeout) { /* Slightly more complicated than the normal minios semaphore: * need to wake on timeout *or* signal */ sys_prot_t prot; - s64_t then = NOW(); - s64_t deadline; + int64_t then = NOW(); + int64_t deadline; if (timeout == 0) deadline = 0; @@ -174,9 +174,9 @@ static void do_mbox_fetch(sys_mbox_t mbox, void **msg) * The return values are the same as for the sys_arch_sem_wait() function: * Number of milliseconds spent waiting or SYS_ARCH_TIMEOUT if there was a * timeout. */ -u32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout) +uint32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, uint32_t timeout) { - u32 rv; + uint32_t rv; if (mbox == SYS_MBOX_NULL) return SYS_ARCH_TIMEOUT; @@ -199,7 +199,7 @@ u32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout) * sys_arch_mbox_fetch(mbox,msg,1) * although this would introduce unnecessary delays. */ -u32_t sys_arch_mbox_tryfetch(sys_mbox_t mbox, void **msg) { +uint32_t sys_arch_mbox_tryfetch(sys_mbox_t mbox, void **msg) { if (mbox == SYS_MBOX_NULL) return SYS_ARCH_TIMEOUT; diff --git a/lwip-net.c b/lwip-net.c index 194ae27..9fded11 100644 --- a/lwip-net.c +++ b/lwip-net.c @@ -207,7 +207,7 @@ netfront_input(struct netif *netif, unsigned char* data, int len) etharp_ip_input(netif, p); #endif /* skip Ethernet header */ - pbuf_header(p, -(s16)sizeof(struct eth_hdr)); + pbuf_header(p, -(int16_t)sizeof(struct eth_hdr)); /* pass to network layer */ if (tcpip_input(p, netif) == ERR_MEM) /* Could not store it, drop */ diff --git a/sched.c b/sched.c index ab454cd..b1e1d28 100644 --- a/sched.c +++ b/sched.c @@ -227,7 +227,7 @@ void block(struct thread *thread) clear_runnable(thread); } -void msleep(u32 millisecs) +void msleep(uint32_t millisecs) { struct thread *thread = get_current(); thread->wakeup_time = NOW() + MILLISECS(millisecs);