diff options
Diffstat (limited to 'libc/sysdeps/linux/kvx/bits')
| -rw-r--r-- | libc/sysdeps/linux/kvx/bits/atomic.h | 212 | ||||
| -rw-r--r-- | libc/sysdeps/linux/kvx/bits/fcntl.h | 3 | ||||
| -rw-r--r-- | libc/sysdeps/linux/kvx/bits/kernel_types.h | 2 | ||||
| -rw-r--r-- | libc/sysdeps/linux/kvx/bits/shm.h | 87 | ||||
| -rw-r--r-- | libc/sysdeps/linux/kvx/bits/stat.h | 145 | ||||
| -rw-r--r-- | libc/sysdeps/linux/kvx/bits/uClibc_arch_features.h | 3 | 
6 files changed, 373 insertions, 79 deletions
| diff --git a/libc/sysdeps/linux/kvx/bits/atomic.h b/libc/sysdeps/linux/kvx/bits/atomic.h index 3c423e9ba..6e81e6704 100644 --- a/libc/sysdeps/linux/kvx/bits/atomic.h +++ b/libc/sysdeps/linux/kvx/bits/atomic.h @@ -1,6 +1,7 @@ -/* Copyright (C) 2010-2012 Free Software Foundation, Inc. +/* Copyright (C) 2003-2017 Free Software Foundation, Inc. +   Copyright (C) 2023 Kalray Inc. +     This file is part of the GNU C Library. -   Contributed by Maxim Kuvyrkov <maxim@codesourcery.com>, 2010.     The GNU C Library is free software; you can redistribute it and/or     modify it under the terms of the GNU Lesser General Public @@ -16,10 +17,15 @@     License along with the GNU C Library.  If not, see     <http://www.gnu.org/licenses/>.  */ +/* Mostly copied from aarch64 atomic.h */ +  #ifndef _KVX_BITS_ATOMIC_H  #define _KVX_BITS_ATOMIC_H +#define typeof __typeof__ +  #include <stdint.h> +#include <sysdep.h>  typedef int8_t atomic8_t;  typedef uint8_t uatomic8_t; @@ -60,82 +66,130 @@ typedef uintmax_t uatomic_max_t;  # define atomic_write_barrier() __builtin_kvx_fence()  #endif -/* - * On kvx, we have a boolean compare and swap which means that the operation - * returns only the success of operation. - * If operation succeeds, this is simple, we just need to return the provided - * old value. However, if it fails, we need to load the value to return it for - * the caller. If the loaded value is different from the "old" provided by the - * caller, we can return it since it will mean it failed. - * However, if for some reason the value we read is equal to the old value - * provided by the caller, we can't simply return it or the caller will think it - * succeeded. So if the value we read is the same as the "old" provided by - * the caller, we try again until either we succeed or we fail with a different - * value than the provided one. - */ -#define __cmpxchg(ptr, old, new, op_suffix, load_suffix)		\ -({									\ -	register unsigned long __rn __asm__("r62");			\ -	register unsigned long __ro __asm__("r63");			\ -	__asm__ __volatile__ (						\ -		/* Fence to guarantee previous store to be committed */	\ -		"fence\n"						\ -		/* Init "expect" with previous value */			\ -		"copyd $r63 = %[rOld]\n"				\ -		";;\n"							\ -		"1:\n"							\ -		/* Init "update" value with new */			\ -		"copyd $r62 = %[rNew]\n"				\ -		";;\n"							\ -		"acswap" #op_suffix " 0[%[rPtr]], $r62r63\n"		\ -		";;\n"							\ -		/* if acswap succeeds, simply return */			\ -		"cb.dnez $r62? 2f\n"					\ -		";;\n"							\ -		/* We failed, load old value */				\ -		"l"  #op_suffix  #load_suffix" $r63 = 0[%[rPtr]]\n"	\ -		";;\n"							\ -		/* Check if equal to "old" one */			\ -		"compd.ne $r62 = $r63, %[rOld]\n"			\ -		";;\n"							\ -		/* If different from "old", return it to caller */	\ -		"cb.deqz $r62? 1b\n"					\ -		";;\n"							\ -		"2:\n"							\ -		: "+r" (__rn), "+r" (__ro)				\ -		: [rPtr] "r" (ptr), [rOld] "r" (old), [rNew] "r" (new)	\ -		: "memory");						\ -	(__ro);								\ -}) - -#define cmpxchg(ptr, o, n)						\ -({									\ -	unsigned long __cmpxchg__ret;					\ -	switch (sizeof(*(ptr))) {					\ -	case 4:								\ -		__cmpxchg__ret = __cmpxchg((ptr), (o), (n), w, s);	\ -		break;							\ -	case 8:								\ -		__cmpxchg__ret = __cmpxchg((ptr), (o), (n), d, );	\ -		break;							\ -	}								\ -	(__typeof(*(ptr))) (__cmpxchg__ret);				\ -}) - -#define atomic_compare_and_exchange_val_acq(mem, newval, oldval)	\ -	cmpxchg((mem), (oldval), (newval)) - - -#define atomic_exchange_acq(mem, newval)				\ -({									\ -	unsigned long __aea__ret, __aea__old;					\ -	volatile __typeof((mem)) __aea__m = (mem);				\ -	do {								\ -		__aea__old = *__aea__m;						\ -		__aea__ret = atomic_compare_and_exchange_val_acq((mem),	\ -						(newval), (__aea__old));\ -	} while (__aea__old != __aea__ret);					\ -	(__aea__old);							\ -}) +#define __HAVE_64B_ATOMICS 1 +#define USE_ATOMIC_COMPILER_BUILTINS 1 + +/* Compare and exchange. +   For all "bool" routines, we return FALSE if exchange succesful.  */ + +# define __arch_compare_and_exchange_bool_8_int(mem, newval, oldval, model) \ +  ({									\ +    typeof (*mem) __oldval = (oldval);					\ +    !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0,	\ +				  model, __ATOMIC_RELAXED);		\ +  }) + +# define __arch_compare_and_exchange_bool_16_int(mem, newval, oldval, model) \ +  ({									\ +    typeof (*mem) __oldval = (oldval);					\ +    !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0,	\ +				  model, __ATOMIC_RELAXED);		\ +  }) + +# define __arch_compare_and_exchange_bool_32_int(mem, newval, oldval, model) \ +  ({									\ +    typeof (*mem) __oldval = (oldval);					\ +    !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0,	\ +				  model, __ATOMIC_RELAXED);		\ +  }) + +#  define __arch_compare_and_exchange_bool_64_int(mem, newval, oldval, model) \ +  ({									\ +    typeof (*mem) __oldval = (oldval);					\ +    !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0,	\ +				  model, __ATOMIC_RELAXED);		\ +  }) + +# define __arch_compare_and_exchange_val_8_int(mem, newval, oldval, model) \ +  ({									\ +    typeof (*mem) __oldval = (oldval);					\ +    __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0,	\ +				 model, __ATOMIC_RELAXED);		\ +    __oldval;								\ +  }) + +# define __arch_compare_and_exchange_val_16_int(mem, newval, oldval, model) \ +  ({									\ +    typeof (*mem) __oldval = (oldval);					\ +    __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0,	\ +				 model, __ATOMIC_RELAXED);		\ +    __oldval;								\ +  }) + +# define __arch_compare_and_exchange_val_32_int(mem, newval, oldval, model) \ +  ({									\ +    typeof (*mem) __oldval = (oldval);					\ +    __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0,	\ +				 model, __ATOMIC_RELAXED);		\ +    __oldval;								\ +  }) + +#  define __arch_compare_and_exchange_val_64_int(mem, newval, oldval, model) \ +  ({									\ +    typeof (*mem) __oldval = (oldval);					\ +    __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0,	\ +				 model, __ATOMIC_RELAXED);		\ +    __oldval;								\ +  }) + + +/* Compare and exchange with "acquire" semantics, ie barrier after.  */ + +# define atomic_compare_and_exchange_bool_acq(mem, new, old)	\ +  __atomic_bool_bysize (__arch_compare_and_exchange_bool, int,	\ +			mem, new, old, __ATOMIC_ACQUIRE) + +# define atomic_compare_and_exchange_val_acq(mem, new, old)	\ +  __atomic_val_bysize (__arch_compare_and_exchange_val, int,	\ +		       mem, new, old, __ATOMIC_ACQUIRE) + +/* Compare and exchange with "release" semantics, ie barrier before.  */ + +# define atomic_compare_and_exchange_val_rel(mem, new, old)	 \ +  __atomic_val_bysize (__arch_compare_and_exchange_val, int,    \ +                       mem, new, old, __ATOMIC_RELEASE) + + +/* Atomic exchange (without compare).  */ + +# define __arch_exchange_8_int(mem, newval, model)	\ +  __atomic_exchange_n (mem, newval, model) + +# define __arch_exchange_16_int(mem, newval, model)	\ +  __atomic_exchange_n (mem, newval, model) + +# define __arch_exchange_32_int(mem, newval, model)	\ +  __atomic_exchange_n (mem, newval, model) + +#  define __arch_exchange_64_int(mem, newval, model)	\ +  __atomic_exchange_n (mem, newval, model) + +# define atomic_exchange_acq(mem, value)				\ +  __atomic_val_bysize (__arch_exchange, int, mem, value, __ATOMIC_ACQUIRE) + +# define atomic_exchange_rel(mem, value)				\ +  __atomic_val_bysize (__arch_exchange, int, mem, value, __ATOMIC_RELEASE) + + +/* Atomically add value and return the previous (unincremented) value.  */ + +# define __arch_exchange_and_add_8_int(mem, value, model)	\ +  __atomic_fetch_add (mem, value, model) + +# define __arch_exchange_and_add_16_int(mem, value, model)	\ +  __atomic_fetch_add (mem, value, model) + +# define __arch_exchange_and_add_32_int(mem, value, model)	\ +  __atomic_fetch_add (mem, value, model) + +#  define __arch_exchange_and_add_64_int(mem, value, model)	\ +  __atomic_fetch_add (mem, value, model) + +# define atomic_exchange_and_add_acq(mem, value)			\ +  __atomic_val_bysize (__arch_exchange_and_add, int, mem, value,	\ +		       __ATOMIC_ACQUIRE) + +# define atomic_exchange_and_add_rel(mem, value)			\ +  __atomic_val_bysize (__arch_exchange_and_add, int, mem, value,	\  #endif diff --git a/libc/sysdeps/linux/kvx/bits/fcntl.h b/libc/sysdeps/linux/kvx/bits/fcntl.h index ea0c59d09..79cd3f14e 100644 --- a/libc/sysdeps/linux/kvx/bits/fcntl.h +++ b/libc/sysdeps/linux/kvx/bits/fcntl.h @@ -227,3 +227,6 @@ extern ssize_t tee (int __fdin, int __fdout, size_t __len,  #endif  __END_DECLS + +/* Include generic Linux declarations.  */ +#include <bits/fcntl-linux.h> diff --git a/libc/sysdeps/linux/kvx/bits/kernel_types.h b/libc/sysdeps/linux/kvx/bits/kernel_types.h index 832b17674..8f6bda8e9 100644 --- a/libc/sysdeps/linux/kvx/bits/kernel_types.h +++ b/libc/sysdeps/linux/kvx/bits/kernel_types.h @@ -7,6 +7,8 @@  #ifndef __ASM_GENERIC_POSIX_TYPES_H  #define __ASM_GENERIC_POSIX_TYPES_H +#include <asm/bitsperlong.h> +  typedef unsigned long		__kernel_dev_t;  typedef unsigned long		__kernel_ino_t;  typedef unsigned int		__kernel_mode_t; diff --git a/libc/sysdeps/linux/kvx/bits/shm.h b/libc/sysdeps/linux/kvx/bits/shm.h new file mode 100644 index 000000000..bfb603499 --- /dev/null +++ b/libc/sysdeps/linux/kvx/bits/shm.h @@ -0,0 +1,87 @@ +/* + * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB + * in this tarball. + */ + +#ifndef _SYS_SHM_H +# error "Never include <bits/shm.h> directly; use <sys/shm.h> instead." +#endif + +#include <bits/types.h> + +/* Permission flag for shmget.  */ +#define SHM_R		0400		/* or S_IRUGO from <linux/stat.h> */ +#define SHM_W		0200		/* or S_IWUGO from <linux/stat.h> */ + +/* Flags for `shmat'.  */ +#define SHM_RDONLY	010000		/* attach read-only else read-write */ +#define SHM_RND		020000		/* round attach address to SHMLBA */ +#define SHM_REMAP	040000		/* take-over region on attach */ + +/* Commands for `shmctl'.  */ +#define SHM_LOCK	11		/* lock segment (root only) */ +#define SHM_UNLOCK	12		/* unlock segment (root only) */ + +__BEGIN_DECLS + +/* Segment low boundary address multiple.  */ +#define SHMLBA		(__getpagesize () << 2) +extern int __getpagesize (void) __THROW __attribute__ ((__const__)); + + +/* Type to count number of attaches.  */ +typedef unsigned long int shmatt_t; + +/* Data structure describing a set of semaphores.  */ +struct shmid_ds +  { +    struct ipc_perm shm_perm;		/* operation permission struct */ +    size_t shm_segsz;			/* size of segment in bytes */ +    __time_t shm_atime;			/* time of last shmat() */ +    __time_t shm_dtime;			/* time of last shmdt() */ +    __time_t shm_ctime;			/* time of last change by shmctl() */ +    __pid_t shm_cpid;			/* pid of creator */ +    __pid_t shm_lpid;			/* pid of last shmop */ +    shmatt_t shm_nattch;		/* number of current attaches */ +    unsigned long int __uclibc_unused1; +    unsigned long int __uclibc_unused2; +  }; + +#ifdef __USE_MISC + +/* ipcs ctl commands */ +# define SHM_STAT 	13 +# define SHM_INFO 	14 + +/* shm_mode upper byte flags */ +# define SHM_DEST	01000	/* segment will be destroyed on last detach */ +# define SHM_LOCKED	02000   /* segment will not be swapped */ +# define SHM_HUGETLB	04000	/* segment is mapped via hugetlb */ +# define SHM_NORESERVE	010000	/* don't check for reservations */ + +struct	shminfo +  { +    unsigned long int shmmax; +    unsigned long int shmmin; +    unsigned long int shmmni; +    unsigned long int shmseg; +    unsigned long int shmall; +    unsigned long int __uclibc_unused1; +    unsigned long int __uclibc_unused2; +    unsigned long int __uclibc_unused3; +    unsigned long int __uclibc_unused4; +  }; + +struct shm_info +  { +    int used_ids; +    unsigned long int shm_tot;	/* total allocated shm */ +    unsigned long int shm_rss;	/* total resident shm */ +    unsigned long int shm_swp;	/* total swapped shm */ +    unsigned long int swap_attempts; +    unsigned long int swap_successes; +  }; + +#endif /* __USE_MISC */ + +__END_DECLS diff --git a/libc/sysdeps/linux/kvx/bits/stat.h b/libc/sysdeps/linux/kvx/bits/stat.h new file mode 100644 index 000000000..716d86150 --- /dev/null +++ b/libc/sysdeps/linux/kvx/bits/stat.h @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org> + * + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +#ifndef _SYS_STAT_H +# error "Never include <bits/stat.h> directly; use <sys/stat.h> instead." +#endif + +#include <bits/align64bit.h> +#include <bits/wordsize.h> +#include <endian.h> + +/* Versions of the `struct stat' data structure.  */ +#define _STAT_VER_LINUX_OLD	1 +#define _STAT_VER_KERNEL	1 +#define _STAT_VER_SVR4		2 +#define _STAT_VER_LINUX		3 +#define _STAT_VER		_STAT_VER_LINUX	/* The one defined below.  */ + +/* Versions of the `xmknod' interface.  */ +#define _MKNOD_VER_LINUX	1 +#define _MKNOD_VER_SVR4		2 +#define _MKNOD_VER		_MKNOD_VER_LINUX /* The bits defined below.  */ + +/* + * This struct is exactly the same with the stat64 one because kvx is 64 bit + */ +struct stat +  { +    unsigned long long st_dev;			/* Device. */ +    unsigned long long st_ino;			/* 32bit file serial number. */ +    unsigned int st_mode;			/* File mode.  */ +    unsigned int st_nlink;			/* Link count.  */ +    unsigned int st_uid;			/* User ID of the file's owner.	*/ +    unsigned int st_gid;			/* Group ID of the file's group.*/ +    unsigned long long st_rdev;			/* Device number, if device.  */ +    unsigned long long _pad1; +    __off_t st_size;				/* SIze of file, in bytes. */ +    int st_blksize;				/* Optimal block size for I/O. */ +    int __pad2; +    long long st_blocks;			/* Number 512-byte blocks allocated */ +#if defined(__USE_MISC) || defined(__USE_XOPEN2K8) +    /* Nanosecond resolution timestamps are stored in a format +       equivalent to 'struct timespec'.  This is the type used +       whenever possible but the Unix namespace rules do not allow the +       identifier 'timespec' to appear in the <sys/stat.h> header. +       Therefore we have to handle the use of this header in strictly +       standard-compliant sources special.  */ +    struct timespec st_atim;			/* Time of last access.  */ +    struct timespec st_mtim;			/* Time of last modification.  */ +    struct timespec st_ctim;			/* Time of last status change.  */ +# define st_atime st_atim.tv_sec		/* Backward compatibility.  */ +# define st_mtime st_mtim.tv_sec +# define st_ctime st_ctim.tv_sec +#else +    long int st_atime;				/* Time of last access. */ +    unsigned long int st_atime_nsec; +    long int st_mtime;				/* Time of last modification. */ +    unsigned long int st_mtime_nsec; +    long int st_ctime;				/* Time of last status change. */ +    unsigned long int st_ctime_nsec; +#endif +    unsigned int __uclibc_unused4; +    unsigned int __uclibc_unused5; +  } __ARCH_64BIT_ALIGNMENT__; + + +#ifdef __USE_LARGEFILE64 +struct stat64 +  { +    unsigned long long st_dev;			/* Device. */ +    unsigned long long st_ino;			/* 32bit file serial number. */ +    unsigned int st_mode;			/* File mode.  */ +    unsigned int st_nlink;			/* Link count.  */ +    unsigned int st_uid;			/* User ID of the file's owner.	*/ +    unsigned int st_gid;			/* Group ID of the file's group.*/ +    unsigned long long st_rdev;			/* Device number, if device.  */ +    unsigned long long __pad3; +    long long st_size;				/* Size of file, in bytes. */ +    int st_blksize;				/* Optimal block size for I/O. */ +    int __pad4; +    long long st_blocks;			/* Number 512-byte blocks allocated */ +# if defined(__USE_MISC) || defined(__USE_XOPEN2K8) +    /* Nanosecond resolution timestamps are stored in a format +       equivalent to 'struct timespec'.  This is the type used +       whenever possible but the Unix namespace rules do not allow the +       identifier 'timespec' to appear in the <sys/stat.h> header. +       Therefore we have to handle the use of this header in strictly +       standard-compliant sources special.  */ +    struct timespec st_atim; 			/* Time of last access.  */ +    struct timespec st_mtim; 			/* Time of last modification.  */ +    struct timespec st_ctim; 			/* Time of last status change.  */ +# else +    long int st_atime;				/* Time of last access. */ +    unsigned long int st_atime_nsec; +    long int st_mtime;				/* Time of last modification. */ +    unsigned long int st_mtime_nsec; +    long int st_ctime;				/* Time of last status change. */ +    unsigned long int st_ctime_nsec; +# endif +    unsigned int __uclibc_unused4; +    unsigned int __uclibc_unused5; +}; +#endif + +/* Tell code we have these members.  */ +#define	_STATBUF_ST_BLKSIZE +#define _STATBUF_ST_RDEV +/* Nanosecond resolution time values are supported.  */ +#define _STATBUF_ST_NSEC + +/* Encoding of the file mode.  */ + +#define	__S_IFMT	0170000	/* These bits determine file type.  */ + +/* File types.  */ +#define	__S_IFDIR	0040000	/* Directory.  */ +#define	__S_IFCHR	0020000	/* Character device.  */ +#define	__S_IFBLK	0060000	/* Block device.  */ +#define	__S_IFREG	0100000	/* Regular file.  */ +#define	__S_IFIFO	0010000	/* FIFO.  */ +#define	__S_IFLNK	0120000	/* Symbolic link.  */ +#define	__S_IFSOCK	0140000	/* Socket.  */ + +/* POSIX.1b objects.  Note that these macros always evaluate to zero.  But +   they do it by enforcing the correct use of the macros.  */ +#define __S_TYPEISMQ(buf)  ((buf)->st_mode - (buf)->st_mode) +#define __S_TYPEISSEM(buf) ((buf)->st_mode - (buf)->st_mode) +#define __S_TYPEISSHM(buf) ((buf)->st_mode - (buf)->st_mode) + +/* Protection bits.  */ + +#define	__S_ISUID	04000	/* Set user ID on execution.  */ +#define	__S_ISGID	02000	/* Set group ID on execution.  */ +#define	__S_ISVTX	01000	/* Save swapped text after use (sticky).  */ +#define	__S_IREAD	0400	/* Read by owner.  */ +#define	__S_IWRITE	0200	/* Write by owner.  */ +#define	__S_IEXEC	0100	/* Execute by owner.  */ + +#ifdef __USE_ATFILE +# define UTIME_NOW	((1l << 30) - 1l) +# define UTIME_OMIT	((1l << 30) - 2l) +#endif diff --git a/libc/sysdeps/linux/kvx/bits/uClibc_arch_features.h b/libc/sysdeps/linux/kvx/bits/uClibc_arch_features.h index 7aae2d7c3..ecccdc7bb 100644 --- a/libc/sysdeps/linux/kvx/bits/uClibc_arch_features.h +++ b/libc/sysdeps/linux/kvx/bits/uClibc_arch_features.h @@ -11,6 +11,9 @@  /* can your target use syscall6() for mmap ? */  #define __UCLIBC_MMAP_HAS_6_ARGS__ +/* does your target use statx */ +#define __UCLIBC_HAVE_STATX__ +  /* does your target align 64bit values in register pairs ? (32bit arches only) */  #undef __UCLIBC_SYSCALL_ALIGN_64BIT__ | 
