From patchwork Wed Nov 9 14:53:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Andre Vieira (lists)" X-Patchwork-Id: 692807 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tDTh02ypsz9t10 for ; Thu, 10 Nov 2016 01:53:19 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="iFp+xIRQ"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=G5GRdp4KiBE9ZHulK BNmYLaaMEQZ6HB1DYcsRAf2PntUS2U9rWspDKhkV0l6pmRtVlO4c34nY1B/kIesV lcigZ4SO4gB7+m/JsWp6kHZ7gKogwAJk6JfzEbx6fsxdYUvzOkai4wiuSCHK1ecc MvpZlpXNZ4i1B9duOOjV9WMKbs= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=Q1EH1SLWmeBnyzaY4NiP/Ej fidI=; b=iFp+xIRQ5jrrKMHLe4S08pGVczotgZLN13OVHhzvyLucmnXD9ZqSiYR giSHxkiFOQonUFabbPs77tNycv02tOK1jse09fV1HJtlW6dmUR6JBuejKs3HnL9O eyzmcaKc/oXRPHe/Yq3jnWgzr7hvTyZPLmRkDj9LH8pqWFpwQMvI= Received: (qmail 87865 invoked by alias); 9 Nov 2016 14:53:11 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 87854 invoked by uid 89); 9 Nov 2016 14:53:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.6 required=5.0 tests=BAYES_00, KAM_LOTSOFHASH, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=bic X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 09 Nov 2016 14:53:09 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BDE8AAD7; Wed, 9 Nov 2016 06:53:05 -0800 (PST) Received: from [10.2.206.251] (e107157-lin.cambridge.arm.com [10.2.206.251]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4CCFD3F220; Wed, 9 Nov 2016 06:53:05 -0800 (PST) Subject: Re: [PATCH 7/7, GCC, ARM, V8M] Added support for ARMV8-M Security Extension cmse_nonsecure_caller intrinsic To: Kyrill Tkachov , gcc-patches@gcc.gnu.org References: <5796116C.6010100@arm.com> <57961419.8040904@arm.com> <57BD7EA4.4010500@arm.com> <580F889A.1030802@arm.com> <5822F9E5.8040400@foss.arm.com> From: "Andre Vieira (lists)" Message-ID: <5823384F.7070604@arm.com> Date: Wed, 9 Nov 2016 14:53:03 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <5822F9E5.8040400@foss.arm.com> X-IsSubscribed: yes On 09/11/16 10:26, Kyrill Tkachov wrote: > > @@ -1832,6 +1834,17 @@ arm_init_builtins (void) > = add_builtin_function ("__builtin_arm_stfscr", ftype_set_fpscr, > ARM_BUILTIN_SET_FPSCR, BUILT_IN_MD, NULL, NULL_TREE); > } > + > + if (arm_arch_cmse) > + { > + tree ftype_cmse_nonsecure_caller > + = build_function_ty > > Should this be use_cmse ? > This looks ok to me otherwise. > I believe patch [6/7] is the only one needing approval after this... > > Kyrill Hi, Yeah it should indeed be 'use_cmse'. Here is the reworked version, no changes to ChangeLog. Cheers, Andre diff --git a/gcc/config/arm/arm-builtins.c b/gcc/config/arm/arm-builtins.c index e73043db6db69fa64bb1e72cf71a36d7169062db..232d2de52106324e9f22b535a1b02cb95a2294b7 100644 --- a/gcc/config/arm/arm-builtins.c +++ b/gcc/config/arm/arm-builtins.c @@ -528,6 +528,8 @@ enum arm_builtins ARM_BUILTIN_GET_FPSCR, ARM_BUILTIN_SET_FPSCR, + ARM_BUILTIN_CMSE_NONSECURE_CALLER, + #undef CRYPTO1 #undef CRYPTO2 #undef CRYPTO3 @@ -1832,6 +1834,17 @@ arm_init_builtins (void) = add_builtin_function ("__builtin_arm_stfscr", ftype_set_fpscr, ARM_BUILTIN_SET_FPSCR, BUILT_IN_MD, NULL, NULL_TREE); } + + if (use_cmse) + { + tree ftype_cmse_nonsecure_caller + = build_function_type_list (unsigned_type_node, NULL); + arm_builtin_decls[ARM_BUILTIN_CMSE_NONSECURE_CALLER] + = add_builtin_function ("__builtin_arm_cmse_nonsecure_caller", + ftype_cmse_nonsecure_caller, + ARM_BUILTIN_CMSE_NONSECURE_CALLER, BUILT_IN_MD, + NULL, NULL_TREE); + } } /* Return the ARM builtin for CODE. */ @@ -2452,6 +2465,12 @@ arm_expand_builtin (tree exp, emit_insn (pat); return target; + case ARM_BUILTIN_CMSE_NONSECURE_CALLER: + target = gen_reg_rtx (SImode); + op0 = arm_return_addr (0, NULL_RTX); + emit_insn (gen_addsi3 (target, op0, const1_rtx)); + return target; + case ARM_BUILTIN_TEXTRMSB: case ARM_BUILTIN_TEXTRMUB: case ARM_BUILTIN_TEXTRMSH: diff --git a/gcc/config/arm/arm_cmse.h b/gcc/config/arm/arm_cmse.h index 894343bb835b61e09c14668d45aa43a8693fd011..82b58b1c4f4a12ba6062e2cc2632653788d0eeb7 100644 --- a/gcc/config/arm/arm_cmse.h +++ b/gcc/config/arm/arm_cmse.h @@ -163,6 +163,13 @@ __attribute__ ((__always_inline__)) cmse_TTAT (void *__p) __CMSE_TT_ASM (at) +/* FIXME: diagnose use outside cmse_nonsecure_entry functions. */ +__extension__ static __inline int __attribute__ ((__always_inline__)) +cmse_nonsecure_caller (void) +{ + return __builtin_arm_cmse_nonsecure_caller (); +} + #define CMSE_AU_NONSECURE 2 #define CMSE_MPU_NONSECURE 16 #define CMSE_NONSECURE 18 diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 462e6c71e20791b35f02adabfc97b9b013fd296a..88f6e014c3def8e6a2d2452df5d4937a4f0dd1ef 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -12625,6 +12625,7 @@ cmse_address_info_t cmse_TTAT_fptr (FPTR) void * cmse_check_address_range (void *, size_t, int) typeof(p) cmse_nsfptr_create (FPTR p) intptr_t cmse_is_nsfptr (FPTR) +int cmse_nonsecure_caller (void) @end smallexample @node AVR Built-in Functions diff --git a/gcc/testsuite/gcc.target/arm/cmse/cmse-1.c b/gcc/testsuite/gcc.target/arm/cmse/cmse-1.c index d5b9a2d9d59569de170da814ae660e9fb2b943e7..ddcf12a30a6c1806969d239c448da81ccf49532e 100644 --- a/gcc/testsuite/gcc.target/arm/cmse/cmse-1.c +++ b/gcc/testsuite/gcc.target/arm/cmse/cmse-1.c @@ -65,3 +65,32 @@ int foo (char * p) /* { dg-final { scan-assembler-times "ttat " 2 } } */ /* { dg-final { scan-assembler-times "bl.cmse_check_address_range" 7 } } */ /* { dg-final { scan-assembler-not "cmse_check_pointed_object" } } */ + +typedef int (*int_ret_funcptr_t) (void); +typedef int __attribute__ ((cmse_nonsecure_call)) (*int_ret_nsfuncptr_t) (void); + +int __attribute__ ((cmse_nonsecure_entry)) +baz (void) +{ + return cmse_nonsecure_caller (); +} + +int __attribute__ ((cmse_nonsecure_entry)) +qux (int_ret_funcptr_t int_ret_funcptr) +{ + int_ret_nsfuncptr_t int_ret_nsfunc_ptr; + + if (cmse_is_nsfptr (int_ret_funcptr)) + { + int_ret_nsfunc_ptr = cmse_nsfptr_create (int_ret_funcptr); + return int_ret_nsfunc_ptr (); + } + return 0; +} +/* { dg-final { scan-assembler "baz:" } } */ +/* { dg-final { scan-assembler "__acle_se_baz:" } } */ +/* { dg-final { scan-assembler-not "\tcmse_nonsecure_caller" } } */ +/* { dg-final { scan-rtl-dump "and.*reg.*const_int 1" expand } } */ +/* { dg-final { scan-assembler "bic" } } */ +/* { dg-final { scan-assembler "push\t\{r4, r5, r6" } } */ +/* { dg-final { scan-assembler "msr\tAPSR_nzcvq" } } */