From owner-svn-src-all@freebsd.org Mon Nov 28 20:33:32 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1A286C5913C; Mon, 28 Nov 2016 20:33:32 +0000 (UTC) (envelope-from cognet@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D65ED18EA; Mon, 28 Nov 2016 20:33:31 +0000 (UTC) (envelope-from cognet@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uASKXVA2058305; Mon, 28 Nov 2016 20:33:31 GMT (envelope-from cognet@FreeBSD.org) Received: (from cognet@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uASKXUqA058302; Mon, 28 Nov 2016 20:33:30 GMT (envelope-from cognet@FreeBSD.org) Message-Id: <201611282033.uASKXUqA058302@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cognet set sender to cognet@FreeBSD.org using -f From: Olivier Houchard Date: Mon, 28 Nov 2016 20:33:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r309267 - in head/sys/contrib/ck/include: . gcc/arm X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Nov 2016 20:33:32 -0000 Author: cognet Date: Mon Nov 28 20:33:30 2016 New Revision: 309267 URL: https://svnweb.freebsd.org/changeset/base/309267 Log: Add FreeBSD-specific files. Added: head/sys/contrib/ck/include/ck_md.h (contents, props changed) head/sys/contrib/ck/include/gcc/arm/ck_pr_armv4.h (contents, props changed) Modified: head/sys/contrib/ck/include/ck_pr.h Added: head/sys/contrib/ck/include/ck_md.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/contrib/ck/include/ck_md.h Mon Nov 28 20:33:30 2016 (r309267) @@ -0,0 +1,71 @@ +/* + * Copyright 2011-2012 Samy Al Bahra. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef CK_MD_H +#define CK_MD_H + +#ifndef CK_MD_CACHELINE +#define CK_MD_CACHELINE (64) +#endif + +#ifndef CK_MD_PAGESIZE +#define CK_MD_PAGESIZE (4096) +#endif + +#ifndef CK_MD_RTM_DISABLE +#define CK_MD_RTM_DISABLE +#endif /* CK_MD_RTM_DISABLE */ + +#ifndef CK_MD_POINTER_PACK_DISABLE +#define CK_MD_POINTER_PACK_DISABLE +#endif /* CK_MD_POINTER_PACK_DISABLE */ + +#ifndef CK_MD_VMA_BITS_UNKNOWN +#define CK_MD_VMA_BITS_UNKNOWN +#endif /* CK_MD_VMA_BITS_UNKNOWN */ + +#ifndef CK_MD_RMO +#define CK_MD_RMO +#endif /* CK_MD_RMO */ + +#define CK_VERSION "0.5.2" +#define CK_GIT_SHA "" + +/* + * CK expects those, which are normally defined by the build system. + */ +#if defined(__i386__) && !defined(__x86__) +#define __x86__ +#elif defined(__sparc64__) && !defined(__sparcv9__) +#define __sparcv9__ +#elif defined(__powerpc64__) && !defined(__ppc64__) +#define __ppc64__ +#elif defined(__powerpc__) && !defined(__ppc__) +#define __ppc__ +#endif +#endif /* CK_MD_H */ Modified: head/sys/contrib/ck/include/ck_pr.h ============================================================================== --- head/sys/contrib/ck/include/ck_pr.h Mon Nov 28 20:27:58 2016 (r309266) +++ head/sys/contrib/ck/include/ck_pr.h Mon Nov 28 20:33:30 2016 (r309267) @@ -46,7 +46,11 @@ #elif defined(__ppc__) #include "gcc/ppc/ck_pr.h" #elif defined(__arm__) +#if __ARM_ARCH >= 6 #include "gcc/arm/ck_pr.h" +#else +#include "gcc/arm/ck_pr_armv4.h" +#endif #elif defined(__aarch64__) #include "gcc/aarch64/ck_pr.h" #elif !defined(__GNUC__) Added: head/sys/contrib/ck/include/gcc/arm/ck_pr_armv4.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/contrib/ck/include/gcc/arm/ck_pr_armv4.h Mon Nov 28 20:33:30 2016 (r309267) @@ -0,0 +1,350 @@ +/* + * Copyright 2009-2016 Samy Al Bahra. + * Copyright 2016 Olivier Houchard. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef CK_PR_ARM_H +#define CK_PR_ARM_H + +#ifndef CK_PR_H +#error Do not include this file directly, use ck_pr.h +#endif + +#include +#include + +#include + +/* + * armv4/v5 CPUs lack any instruction that would let us implement an atomic CAS + * so we have to give atomicity by disabling interrupts. This only works in + * the kernel, obviously. + */ +#define __with_interrupts_disabled(expr) \ + do { \ + u_int cpsr_save, tmp; \ + \ + __asm __volatile( \ + "mrs %0, cpsr;" \ + "orr %1, %0, %2;" \ + "msr cpsr_fsxc, %1;" \ + : "=r" (cpsr_save), "=r" (tmp) \ + : "I" (PSR_I | PSR_F) \ + : "cc" ); \ + (expr); \ + __asm __volatile( \ + "msr cpsr_fsxc, %0" \ + : /* no output */ \ + : "r" (cpsr_save) \ + : "cc" ); \ + } while(0) +/* + * The following represent supported atomic operations. + * These operations may be emulated. + */ +#include "ck_f_pr.h" + +/* + * Minimum interface requirement met. + */ +#define CK_F_PR + +CK_CC_INLINE static void +ck_pr_stall(void) +{ + + __asm__ __volatile__("" ::: "memory"); + return; +} + +#define CK_PR_FENCE(T, I) \ + CK_CC_INLINE static void \ + ck_pr_fence_strict_##T(void) \ + { \ + I; \ + } + +/* + * ARM CPUs prior to armv6 didn't reorder instructions, and we don't + * support any SMP system, so a compiler barrier should be enough for fences + */ +CK_PR_FENCE(atomic, ck_pr_stall()) +CK_PR_FENCE(atomic_store, ck_pr_stall()) +CK_PR_FENCE(atomic_load, ck_pr_stall()) +CK_PR_FENCE(store_atomic, ck_pr_stall()) +CK_PR_FENCE(load_atomic, ck_pr_stall()) +CK_PR_FENCE(store, ck_pr_stall()) +CK_PR_FENCE(store_load, ck_pr_stall()) +CK_PR_FENCE(load, ck_pr_stall()) +CK_PR_FENCE(load_store, ck_pr_stall()) +CK_PR_FENCE(memory, ck_pr_stall()) +CK_PR_FENCE(acquire, ck_pr_stall()) +CK_PR_FENCE(release, ck_pr_stall()) +CK_PR_FENCE(acqrel, ck_pr_stall()) +CK_PR_FENCE(lock, ck_pr_stall()) +CK_PR_FENCE(unlock, ck_pr_stall()) + +#undef CK_PR_FENCE + +#define CK_PR_LOAD(S, M, T, C, I) \ + CK_CC_INLINE static T \ + ck_pr_md_load_##S(const M *target) \ + { \ + long r = 0; \ + __asm__ __volatile__(I " %0, [%1];" \ + : "=r" (r) \ + : "r" (target) \ + : "memory"); \ + return ((T)r); \ + } + +CK_PR_LOAD(ptr, void, void *, uint32_t, "ldr") + +#define CK_PR_LOAD_S(S, T, I) CK_PR_LOAD(S, T, T, T, I) + +CK_PR_LOAD_S(32, uint32_t, "ldr") +CK_PR_LOAD_S(16, uint16_t, "ldrh") +CK_PR_LOAD_S(8, uint8_t, "ldrb") +CK_PR_LOAD_S(uint, unsigned int, "ldr") +CK_PR_LOAD_S(int, int, "ldr") +CK_PR_LOAD_S(short, short, "ldrh") +CK_PR_LOAD_S(char, char, "ldrb") + +#undef CK_PR_LOAD_S +#undef CK_PR_LOAD + +#define CK_PR_STORE(S, M, T, C, I) \ + CK_CC_INLINE static void \ + ck_pr_md_store_##S(M *target, T v) \ + { \ + __asm__ __volatile__(I " %1, [%0]" \ + : \ + : "r" (target), \ + "r" (v) \ + : "memory"); \ + return; \ + } + +CK_PR_STORE(ptr, void, const void *, uint32_t, "str") + +#define CK_PR_STORE_S(S, T, I) CK_PR_STORE(S, T, T, T, I) + +CK_PR_STORE_S(32, uint32_t, "str") +CK_PR_STORE_S(16, uint16_t, "strh") +CK_PR_STORE_S(8, uint8_t, "strb") +CK_PR_STORE_S(uint, unsigned int, "str") +CK_PR_STORE_S(int, int, "str") +CK_PR_STORE_S(short, short, "strh") +CK_PR_STORE_S(char, char, "strb") + +#undef CK_PR_STORE_S +#undef CK_PR_STORE + +#define CK_PR_CAS(N, M, T) \ +CK_CC_INLINE static bool \ +ck_pr_cas_##N##_value(M *target, T compare, T set, M *value) \ +{ \ + bool ret; \ + __with_interrupts_disabled( \ + { \ + *(T *)value = *(T *)target; \ + if (*(T *)target == compare) { \ + *(T *)target = set; \ + ret = true; \ + } else \ + ret = false; \ + } \ + ); \ + return ret; \ +} \ +CK_CC_INLINE static bool \ +ck_pr_cas_##N(M *target, T compare, T set) \ +{ \ + bool ret; \ + __with_interrupts_disabled( \ + { \ + if (*(T *)target == compare) { \ + *(T *)target = set; \ + ret = true; \ + } else \ + ret = false; \ + } \ + ); \ + return ret; \ +} + +CK_PR_CAS(ptr, void, void *) + +#define CK_PR_CAS_S(N, T) CK_PR_CAS(N, T, T) +CK_PR_CAS_S(32, uint32_t) +CK_PR_CAS_S(uint, unsigned int) +CK_PR_CAS_S(int, int) +CK_PR_CAS_S(16, uint16_t) +CK_PR_CAS_S(8, uint8_t) +CK_PR_CAS_S(short, short) +CK_PR_CAS_S(char, char) + +#undef CK_PR_CAS_S +#undef CK_PR_CAS + +#define CK_PR_FAS(N, M, T, W) \ + CK_CC_INLINE static T \ + ck_pr_fas_##N(M *target, T v) \ + { \ + T previous = 0; \ + __with_interrupts_disabled( \ + { \ + previous = *(T *)target; \ + *(T *)target = v; \ + } \ + ); \ + return (previous); \ + } + +CK_PR_FAS(32, uint32_t, uint32_t, "") +CK_PR_FAS(ptr, void, void *, "") +CK_PR_FAS(int, int, int, "") +CK_PR_FAS(uint, unsigned int, unsigned int, "") +CK_PR_FAS(16, uint16_t, uint16_t, "h") +CK_PR_FAS(8, uint8_t, uint8_t, "b") +CK_PR_FAS(short, short, short, "h") +CK_PR_FAS(char, char, char, "b") + + +#undef CK_PR_FAS + +#define CK_PR_UNARY(O, N, M, T, I, W) \ + CK_CC_INLINE static void \ + ck_pr_##O##_##N(M *target) \ + { \ + __with_interrupts_disabled( \ + { \ + I; \ + } \ + ); \ + return; \ + } + +CK_PR_UNARY(inc, ptr, void, void *, (*(int *)target)++, "") +CK_PR_UNARY(dec, ptr, void, void *, (*(int *)target)--, "") +CK_PR_UNARY(not, ptr, void, void *, *(int *)target = !(*(int*)target), "") +CK_PR_UNARY(neg, ptr, void, void *, *(int *)target = -(*(int *)target), "") + +#define CK_PR_UNARY_S(S, T, W) \ + CK_PR_UNARY(inc, S, T, T, *target++, W) \ + CK_PR_UNARY(dec, S, T, T, *target--, W) \ + CK_PR_UNARY(not, S, T, T, *target = !*target, W) \ + CK_PR_UNARY(neg, S, T, T, *target = -*target, W) \ + +CK_PR_UNARY_S(32, uint32_t, "") +CK_PR_UNARY_S(uint, unsigned int, "") +CK_PR_UNARY_S(int, int, "") +CK_PR_UNARY_S(16, uint16_t, "h") +CK_PR_UNARY_S(8, uint8_t, "b") +CK_PR_UNARY_S(short, short, "h") +CK_PR_UNARY_S(char, char, "b") + +#undef CK_PR_UNARY_S +#undef CK_PR_UNARY + +#define CK_PR_BINARY(O, N, M, T, I, W) \ + CK_CC_INLINE static void \ + ck_pr_##O##_##N(M *target, T delta) \ + { \ + __with_interrupts_disabled( \ + { \ + I; \ + } \ + ); \ + return; \ + } + +CK_PR_BINARY(and, ptr, void, uintptr_t, *((uintptr_t *)target) &= delta, "") +CK_PR_BINARY(add, ptr, void, uintptr_t, *((uintptr_t *)target) += delta, "") +CK_PR_BINARY(or, ptr, void, uintptr_t, *((uintptr_t *)target) |= delta, "") +CK_PR_BINARY(sub, ptr, void, uintptr_t, *((uintptr_t *)target) -= delta, "") +CK_PR_BINARY(xor, ptr, void, uintptr_t, *((uintptr_t *)target) ^= delta, "") + +#define CK_PR_BINARY_S(S, T, W) \ + CK_PR_BINARY(and, S, T, T, *target &= delta, W) \ + CK_PR_BINARY(add, S, T, T, *target += delta, W) \ + CK_PR_BINARY(or, S, T, T, *target |= delta, W) \ + CK_PR_BINARY(sub, S, T, T, *target -= delta, W) \ + CK_PR_BINARY(xor, S, T, T, *target ^= delta, W) + +CK_PR_BINARY_S(32, uint32_t, "") +CK_PR_BINARY_S(uint, unsigned int, "") +CK_PR_BINARY_S(int, int, "") +CK_PR_BINARY_S(16, uint16_t, "h") +CK_PR_BINARY_S(8, uint8_t, "b") +CK_PR_BINARY_S(short, short, "h") +CK_PR_BINARY_S(char, char, "b") + +#undef CK_PR_BINARY_S +#undef CK_PR_BINARY + +CK_CC_INLINE static void * +ck_pr_faa_ptr(void *target, uintptr_t delta) +{ + uintptr_t previous; + __with_interrupts_disabled( + { + previous = *(uintptr_t *)target; + *(uintptr_t *)target += delta; + } + ); + return (void *)(previous); +} + +#define CK_PR_FAA(S, T, W) \ + CK_CC_INLINE static T \ + ck_pr_faa_##S(T *target, T delta) \ + { \ + T previous = 0; \ + __with_interrupts_disabled( \ + { \ + previous = *target; \ + *target += delta; \ + } \ + ); \ + return (previous); \ + } + +CK_PR_FAA(32, uint32_t, "") +CK_PR_FAA(uint, unsigned int, "") +CK_PR_FAA(int, int, "") +CK_PR_FAA(16, uint16_t, "h") +CK_PR_FAA(8, uint8_t, "b") +CK_PR_FAA(short, short, "h") +CK_PR_FAA(char, char, "b") + +#undef CK_PR_FAA + +#undef __with_interrupts_disabled + +#endif /* CK_PR_ARM_H */ +