From: Yann Sionneau ysionneau@kalray.eu
The only difference, with regard to libc, is the compile flag: -march=
Signed-off-by: Yann Sionneau ysionneau@kalray.eu --- Rules.mak | 3 ++- extra/Configs/Config.kvx | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/Rules.mak b/Rules.mak index 8984edb38..c3313b257 100644 --- a/Rules.mak +++ b/Rules.mak @@ -459,7 +459,8 @@ ifeq ($(TARGET_ARCH),csky) endif
ifeq ($(TARGET_ARCH),kvx) - CPU_CFLAGS-$(CONFIG_KVX) += -march=kvx + CPU_CFLAGS-y += -march=$(call qstrip,$(TARGET_MARCH)) + CPU_LDFLAGS-y += -march=$(call qstrip,$(TARGET_MARCH)) endif
ifeq ($(TARGET_ARCH),m68k) diff --git a/extra/Configs/Config.kvx b/extra/Configs/Config.kvx index 398ffceaa..04df53c38 100644 --- a/extra/Configs/Config.kvx +++ b/extra/Configs/Config.kvx @@ -7,6 +7,24 @@ config TARGET_ARCH string default "kvx"
+choice + prompt "Target architecture variant" + help + Select CPU variant to use + +config CONFIG_KVX_COOLIDGE_V1 + bool "Coolidge V1" + +config CONFIG_KVX_COOLIDGE_V2 + bool "Coolidge V2" + +endchoice + +config TARGET_MARCH + string + default "kv3-1" if CONFIG_KVX_COOLIDGE_V1 + default "kv3-2" if CONFIG_KVX_COOLIDGE_V2 + config FORCE_OPTIONS_FOR_ARCH bool default y
From: Yann Sionneau ysionneau@kalray.eu
Signed-off-by: Yann Sionneau ysionneau@kalray.eu --- libc/sysdeps/linux/kvx/bits/atomic.h | 212 +++++++++++++++++---------- 1 file changed, 133 insertions(+), 79 deletions(-)
diff --git a/libc/sysdeps/linux/kvx/bits/atomic.h b/libc/sysdeps/linux/kvx/bits/atomic.h index 3c423e9ba..cbab813fd 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
From: Yann Sionneau ysionneau@kalray.eu
Align the specification of the ptrace interface with how it is specified on RISC-V.
Signed-off-by: Yann Sionneau ysionneau@kalray.eu --- libc/sysdeps/linux/kvx/sys/procfs.h | 13 ++++--------- libc/sysdeps/linux/kvx/sys/ucontext.h | 5 ++--- libc/sysdeps/linux/kvx/sys/user.h | 28 +-------------------------- 3 files changed, 7 insertions(+), 39 deletions(-)
diff --git a/libc/sysdeps/linux/kvx/sys/procfs.h b/libc/sysdeps/linux/kvx/sys/procfs.h index bbbfb838e..b72322888 100644 --- a/libc/sysdeps/linux/kvx/sys/procfs.h +++ b/libc/sysdeps/linux/kvx/sys/procfs.h @@ -31,20 +31,15 @@ #include <sys/time.h> #include <sys/types.h> #include <sys/user.h> +#include <sys/ucontext.h>
-__BEGIN_DECLS +#define ELF_NGREG NGREG
-/* Type for a general-purpose register. */ typedef unsigned long elf_greg_t; -/* No FP registers for kvx. */ +typedef elf_greg_t elf_gregset_t[ELF_NGREG]; typedef struct {} elf_fpregset_t;
-/* And the whole bunch of them. We could have used `struct - pt_regs' directly in the typedef, but tradition says that - the register set is an array, which does have some peculiar - semantics, so leave it that way. */ -#define ELF_NGREG (sizeof (struct user_regs_struct) / sizeof(elf_greg_t)) -typedef elf_greg_t elf_gregset_t[ELF_NGREG]; +__BEGIN_DECLS
/* Signal info. */ struct elf_siginfo diff --git a/libc/sysdeps/linux/kvx/sys/ucontext.h b/libc/sysdeps/linux/kvx/sys/ucontext.h index 548892389..a97b83cad 100644 --- a/libc/sysdeps/linux/kvx/sys/ucontext.h +++ b/libc/sysdeps/linux/kvx/sys/ucontext.h @@ -12,12 +12,11 @@ #include <signal.h> #include <bits/sigcontext.h>
+#define NGREG 70 + /* Type for general register. */ typedef unsigned long greg_t;
-/* Number of general registers. */ -#define NGREG 64 - typedef struct ucontext { unsigned long uc_flags; struct ucontext *uc_link; diff --git a/libc/sysdeps/linux/kvx/sys/user.h b/libc/sysdeps/linux/kvx/sys/user.h index 2e228ff19..c871f1a03 100644 --- a/libc/sysdeps/linux/kvx/sys/user.h +++ b/libc/sysdeps/linux/kvx/sys/user.h @@ -1,27 +1 @@ -/* - * This file is subject to the terms and conditions of the LGPL V2.1 - * License. See the file "COPYING" in the main directory of this archive - * for more details. - * - * Copyright (C) 2019 Kalray Inc. - */ - -#ifndef _SYS_USER_H -#define _SYS_USER_H 1 - -struct user_regs_struct -{ - /* GPR */ - unsigned long long gpr_regs[64]; - - /* SFR */ - unsigned long lc; - unsigned long le; - unsigned long ls; - unsigned long ra; - - unsigned long cs; - unsigned long spc; -}; - -#endif +/* This file is not needed, but in practice gdb might try to include it. */
From: Yann Sionneau ysionneau@kalray.eu
Define that kvx Linux port supports statx syscall.
Signed-off-by: Yann Sionneau ysionneau@kalray.eu --- libc/sysdeps/linux/kvx/bits/uClibc_arch_features.h | 3 +++ 1 file changed, 3 insertions(+)
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__
From: Yann Sionneau ysionneau@kalray.eu
Use a custom stat.h header for kvx arch. This makes sure it is aligned with Linux kernel one.
Signed-off-by: Yann Sionneau ysionneau@kalray.eu --- libc/sysdeps/linux/kvx/bits/stat.h | 145 +++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 libc/sysdeps/linux/kvx/bits/stat.h
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
Hi Yann, yann@sionneau.net wrote,
From: Yann Sionneau ysionneau@kalray.eu
The only difference, with regard to libc, is the compile flag: -march=
Signed-off-by: Yann Sionneau ysionneau@kalray.eu
Series applied and pushed, best regards Waldemar