From patchwork Mon Aug 8 11:04:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georg-Johann Lay X-Patchwork-Id: 656652 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 3s7F0x6BBQz9s9W for ; Mon, 8 Aug 2016 21:04:33 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=tE7SbqhL; 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:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=goS1Z+D9bhxXeW38W Q9myo7DBZNJl5HsmTtOTEapzgBDI9HF5Y06hymEQ51Hnymc77ckG8Zl7jSx+m0n9 m/KEFrfLfev3uwvSJozdikRMip3aSk/ZevMClnlzmq78+JVPTcrqjhr+gvJE8GfE agqGW/co8CPywNfqGY3z4d/0Kk= 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:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=jJcZqLnYMMPmFauamFcbmfs YqXs=; b=tE7SbqhLNaNHQozi/Scv/+VNJk0yi9rz1UVEjTmOIqUqq71kB+XXdcA jh0xO+lS5TEdzicHYPQP9OgV9Uq1TT56KmnO3/l5aiGn4+AxL5uSZ/IaPdjjcd2g nIZ2I7tcjo13onxiez4BVT3wibOJTZtbiXzekS/5oOv1NHURHiHQ= Received: (qmail 51719 invoked by alias); 8 Aug 2016 11:04:26 -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 51704 invoked by uid 89); 8 Aug 2016 11:04:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.8 required=5.0 tests=AWL, BAYES_00, KAM_ASCII_DIVIDERS, KAM_STOCKGEN, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 spammy=loosemore, Loosemore, sk:SYMBOL_, Pmode X-HELO: mo4-p00-ob.smtp.rzone.de Received: from mo4-p00-ob.smtp.rzone.de (HELO mo4-p00-ob.smtp.rzone.de) (81.169.146.221) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 08 Aug 2016 11:04:14 +0000 X-RZG-AUTH: :LXoWVUeid/7A29J/hMvvT3ol15ykJcYwR/bcHRirORRW3yMcVao= X-RZG-CLASS-ID: mo00 Received: from [192.168.0.143] (mail.hightec-rt.com [213.135.1.215]) by smtp.strato.de (RZmta 38.13 DYNA|AUTH) with ESMTPSA id y06079s78B474sZ (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Mon, 8 Aug 2016 13:04:07 +0200 (CEST) Subject: Re: [avr, RFC, patch] Add var attribute "absdata" to support LDS / STS on AVR_TINY. To: Sandra Loosemore References: <9680f386-48a4-9080-77db-e8dc93cdaa63@gjlay.de> <57A81452.4000200@codesourcery.com> Cc: gcc-patches , Denis Chertykov , Senthil Kumar Selvaraj , Pitchumani Sivanupandi From: Georg-Johann Lay Message-ID: Date: Mon, 8 Aug 2016 13:04:07 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <57A81452.4000200@codesourcery.com> X-IsSubscribed: yes On 08.08.2016 07:10, Sandra Loosemore wrote: > On 08/03/2016 10:17 AM, Georg-Johann Lay wrote: > >> Index: doc/extend.texi >> =================================================================== >> --- doc/extend.texi (revision 238983) >> +++ doc/extend.texi (working copy) >> @@ -5957,6 +5957,25 @@ memory-mapped peripherals that may lie o >> volatile int porta __attribute__((address (0x600))); >> @end smallexample >> >> +@item absdata >> +@cindex @code{absdata} variable attribute, AVR >> +Variables in static storage and with the @code{absdata} attribute can >> +be accessed by the @code{LDS} and @code{STS} instructions which take >> +absolute addresses. >> + >> +@itemize @bullet >> +@item >> +This attribute is only supported for the reduced AVR Tiny core >> +like @code{ATtiny40}. >> + >> +@item >> +There is currently no Binutils support for this attribute and the user has >> +to make sure that respective data is located into an address range that >> +can actually be handled by @code{LDS} and @code{STS}. >> +This applies to addresses in the range @code{0x40}@dots{}@code{0xbf}. > > The wording here is a little awkward -- in particular, "the user" is really > "you", the reader of the manual. How about something like this instead? > > @item > You must use an appropriate linker script to locate the data in the address > range accessible by @code{LDS} and @code{STS} (@code{0x40}@dots{}@code{0xbf}). > > -Sandra > Thanks for the help. Attached is an updated patch. Index: doc/extend.texi =================================================================== --- doc/extend.texi (revision 238983) +++ doc/extend.texi (working copy) @@ -5957,6 +5957,32 @@ memory-mapped peripherals that may lie o volatile int porta __attribute__((address (0x600))); @end smallexample +@item absdata +@cindex @code{absdata} variable attribute, AVR +Variables in static storage and with the @code{absdata} attribute can +be accessed by the @code{LDS} and @code{STS} instructions which take +absolute addresses. + +@itemize @bullet +@item +This attribute is only supported for the reduced AVR Tiny core +like @code{ATtiny40}. + +@item +You must use an appropriate linker script to locate the data in the +address range accessible by @code{LDS} and @code{STS} +(@code{0x40}@dots{}@code{0xbf}). + +@item +If the location does not fit the address range of @code{LDS} +and @code{STS}, there is currently (Binutils 2.26) just an unspecific +warning like +@quotation +@code{module.c:(.text+0x1c): warning: internal error: out of range error} +@end quotation + +@end itemize + @end table @node Blackfin Variable Attributes Index: config/avr/avr.c =================================================================== --- config/avr/avr.c (revision 238983) +++ config/avr/avr.c (working copy) @@ -81,9 +81,13 @@ / SYMBOL_FLAG_MACH_DEP) /* (AVR_TINY only): Symbol has attribute progmem */ -#define AVR_SYMBOL_FLAG_TINY_PM \ +#define AVR_SYMBOL_FLAG_TINY_PM \ (SYMBOL_FLAG_MACH_DEP << 7) +/* (AVR_TINY only): Symbol has attribute absdata */ +#define AVR_SYMBOL_FLAG_TINY_ABSDATA \ + (SYMBOL_FLAG_MACH_DEP << 8) + #define TINY_ADIW(REG1, REG2, I) \ "subi " #REG1 ",lo8(-(" #I "))" CR_TAB \ "sbci " #REG2 ",hi8(-(" #I "))" @@ -1802,6 +1806,28 @@ avr_mode_dependent_address_p (const_rtx } +/* Return true if rtx X is a CONST_INT, CONST or SYMBOL_REF + address with the `absdata' variable attribute, i.e. respective + data can be read / written by LDS / STS instruction. + This is used only for AVR_TINY. */ + +static bool +avr_address_tiny_absdata_p (rtx x, machine_mode mode) +{ + if (CONST == GET_CODE (x)) + x = XEXP (XEXP (x, 0), 0); + + if (SYMBOL_REF_P (x)) + return SYMBOL_REF_FLAGS (x) & AVR_SYMBOL_FLAG_TINY_ABSDATA; + + if (CONST_INT_P (x) + && IN_RANGE (INTVAL (x), 0, 0xc0 - GET_MODE_SIZE (mode))) + return true; + + return false; +} + + /* Helper function for `avr_legitimate_address_p'. */ static inline bool @@ -1886,8 +1912,7 @@ avr_legitimate_address_p (machine_mode m /* avrtiny's load / store instructions only cover addresses 0..0xbf: IN / OUT range is 0..0x3f and LDS / STS can access 0x40..0xbf. */ - ok = (CONST_INT_P (x) - && IN_RANGE (INTVAL (x), 0, 0xc0 - GET_MODE_SIZE (mode))); + ok = avr_address_tiny_absdata_p (x, mode); } if (avr_log.legitimate_address_p) @@ -1929,8 +1954,7 @@ avr_legitimize_address (rtx x, rtx oldx, if (AVR_TINY) { if (CONSTANT_ADDRESS_P (x) - && !(CONST_INT_P (x) - && IN_RANGE (INTVAL (x), 0, 0xc0 - GET_MODE_SIZE (mode)))) + && ! avr_address_tiny_absdata_p (x, mode)) { x = force_reg (Pmode, x); } @@ -9124,6 +9148,32 @@ avr_handle_fntype_attribute (tree *node, } static tree +avr_handle_absdata_attribute (tree *node, tree name, tree /* args */, + int /* flags */, bool *no_add) +{ + location_t loc = DECL_SOURCE_LOCATION (*node); + + if (AVR_TINY) + { + if (TREE_CODE (*node) != VAR_DECL + || (!TREE_STATIC (*node) && !DECL_EXTERNAL (*node))) + { + warning_at (loc, OPT_Wattributes, "%qE attribute only applies to" + " variables in static storage", name); + *no_add = true; + } + } + else + { + warning_at (loc, OPT_Wattributes, "%qE attribute only supported" + " for reduced Tiny cores", name); + *no_add = true; + } + + return NULL_TREE; +} + +static tree avr_handle_addr_attribute (tree *node, tree name, tree args, int flags ATTRIBUTE_UNUSED, bool *no_add) { @@ -9230,6 +9280,8 @@ avr_attribute_table[] = false }, { "address", 1, 1, false, false, false, avr_handle_addr_attribute, false }, + { "absdata", 0, 0, true, false, false, avr_handle_absdata_attribute, + false }, { NULL, 0, 0, false, false, false, NULL, false } }; @@ -9314,6 +9366,17 @@ avr_progmem_p (tree decl, tree attribute } +/* Return true if DECL has attribute `absdata' set. This function should + only be used for AVR_TINY. */ + +static bool +avr_decl_absdata_p (tree decl, tree attributes) +{ + return (TREE_CODE (decl) == VAR_DECL + && NULL_TREE != lookup_attribute ("absdata", attributes)); +} + + /* Scan type TYP for pointer references to address space ASn. Return ADDR_SPACE_GENERIC (i.e. 0) if all pointers targeting the AS are also declared to be CONST. @@ -9738,14 +9801,29 @@ avr_encode_section_info (tree decl, rtx if (AVR_TINY && decl && VAR_DECL == TREE_CODE (decl) - && -1 == avr_progmem_p (decl, DECL_ATTRIBUTES (decl)) && MEM_P (rtl) && SYMBOL_REF_P (XEXP (rtl, 0))) { - /* Tag symbols for later addition of 0x4000 (AVR_TINY_PM_OFFSET). */ - rtx sym = XEXP (rtl, 0); - SYMBOL_REF_FLAGS (sym) |= AVR_SYMBOL_FLAG_TINY_PM; + + if (-1 == avr_progmem_p (decl, DECL_ATTRIBUTES (decl))) + { + // Tag symbols for later addition of 0x4000 (AVR_TINY_PM_OFFSET). + SYMBOL_REF_FLAGS (sym) |= AVR_SYMBOL_FLAG_TINY_PM; + } + + if (avr_decl_absdata_p (decl, DECL_ATTRIBUTES (decl))) + { + // May be accessed by LDS / STS. + SYMBOL_REF_FLAGS (sym) |= AVR_SYMBOL_FLAG_TINY_ABSDATA; + } + + if (-1 == avr_progmem_p (decl, DECL_ATTRIBUTES (decl)) + && avr_decl_absdata_p (decl, DECL_ATTRIBUTES (decl))) + { + error ("%q+D has incompatible attributes %qs and %qs", + decl, "progmem", "absdata"); + } } }