From patchwork Thu Nov 15 01:47:24 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: DJ Delorie X-Patchwork-Id: 199099 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]) by ozlabs.org (Postfix) with SMTP id DF2C62C0089 for ; Thu, 15 Nov 2012 12:47:44 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1353548866; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:Message-Id:From:To:Subject:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=cCI1KBWBVfrORWEO21YJTn6rZmI=; b=LBZV0mgURIxvvLJa9tAlEC1LGPJvKuF304n8WVZ6/ER19HaoKegAt/uqXxhAXt y6VHLgVpsgjCQo43pVRzoD2q1H50bA2Km/5v+UQ5PNvw/lbS/ZLQQQW8DuIZgIjt 1PEIR5Ctr6+0WA6ds2QvqpBShd9ThvYXCSj9pZgA/Hq5g= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Date:Message-Id:From:To:Subject:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=WcZqtOVJ05kCMpNeyXWU6OIMoC/WBTq2sJUeuIKD/V/nmaqlYdIJA35b6gZdz8 mliXeKD63le+2gDLBmiC88raKQzakjWvYR9xoQkao1r5EFw7loxlA5E5riO+UWEe qQroxsDhBjLws0YCt7vA4AL2qNsOdK8HUkmD5PMZbiA6I=; Received: (qmail 21500 invoked by alias); 15 Nov 2012 01:47:38 -0000 Received: (qmail 21484 invoked by uid 22791); 15 Nov 2012 01:47:35 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 15 Nov 2012 01:47:26 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qAF1lQxB016252 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 14 Nov 2012 20:47:26 -0500 Received: from greed.delorie.com (ovpn-113-48.phx2.redhat.com [10.3.113.48]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id qAF1lPN0026853 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 14 Nov 2012 20:47:26 -0500 Received: from greed.delorie.com (greed.delorie.com [127.0.0.1]) by greed.delorie.com (8.14.4/8.14.4) with ESMTP id qAF1lOjG021899 for ; Wed, 14 Nov 2012 20:47:24 -0500 Received: (from dj@localhost) by greed.delorie.com (8.14.4/8.14.4/Submit) id qAF1lOXv021898; Wed, 14 Nov 2012 20:47:24 -0500 Date: Wed, 14 Nov 2012 20:47:24 -0500 Message-Id: <201211150147.qAF1lOXv021898@greed.delorie.com> From: DJ Delorie To: gcc-patches@gcc.gnu.org Subject: [patch] rx: create interrupt vector aliases by attributes X-IsSubscribed: yes 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 This patch allows the user to specify a vector number in an interrupt attribute, allowing for more generic creation of vector tables. Ok? * doc/extend.texi (Function Attributes): Document RX extensions to "interrupt" attribute. * config/rx/rx.c (has_interrupt_vector): New. (rx_output_function_prologue): If a function has an interrupt vector assigned, emit a vector-specific alias for it. (rx_handle_func_attribute): Allow args to attributes. (rx_attribute_table): Allow the interrupt attribute to take an argument. Index: gcc/doc/extend.texi =================================================================== --- gcc/doc/extend.texi (revision 193523) +++ gcc/doc/extend.texi (working copy) @@ -2892,12 +2892,39 @@ void __attribute__ ((interrupt, use_shad @end smallexample On RL78, use @code{brk_interrupt} instead of @code{interrupt} for handlers intended to be used with the @code{BRK} opcode (i.e. those that must end with @code{RETB} instead of @code{RETI}). +On RX targets, you can specify an interrupt vector number, which +causes gcc to emit a vector-specific alias for the function: + +@smallexample +void f () __attribute__((interrupt (15))); +@end smallexample + +In the above example, an additional global symbol +@code{__gcc_autovector_func_15} would be created to reference this +function, which can be referenced by some other function or linker +script to build the vector table: + +@smallexample +extern __gcc_autovector_func_15() __attribute__((weak)); +@{ @dots{} __gcc_autovector_func_15; @dots{} @} + +.weak __gcc_autovector_func_15 +.long __gcc_autovector_func_15 + +PROVIDE(__gcc_autovector_func_15=0) +LONG (__gcc_autovector_func_15) +@end smallexample + +Note that the PROVIDE must be outside any section block +(i.e. @code{.text : @{ ... @} }) or else the value will be relocated +and result in a non-zero address. + @item interrupt_handler @cindex interrupt handler functions on the Blackfin, m68k, H8/300 and SH processors Use this attribute on the Blackfin, m68k, H8/300, H8/300H, H8S, and SH to indicate that the specified function is an interrupt handler. The compiler generates function entry and exit sequences suitable for use in an interrupt handler when this attribute is present. Index: gcc/config/rx/rx.c =================================================================== --- gcc/config/rx/rx.c (revision 193523) +++ gcc/config/rx/rx.c (working copy) @@ -1184,12 +1184,44 @@ is_fast_interrupt_func (const_tree decl) static inline bool is_interrupt_func (const_tree decl) { return has_func_attr (decl, "interrupt"); } +/* Returns true if the provided function has the "vector" attribute. + If true, it also returns the vector in *RET if RET is not NULL. */ + +static inline bool +has_interrupt_vector (const_tree decl, int *ret) +{ + tree vec_attr; + int rv; + + if (decl == NULL_TREE) + decl = current_function_decl; + + vec_attr = lookup_attribute ("interrupt", DECL_ATTRIBUTES (decl)); + if (!vec_attr) + return false; + + vec_attr = TREE_VALUE (vec_attr); + if (!vec_attr) + return false; + + vec_attr = TREE_VALUE (vec_attr); + if (!vec_attr) + return false; + + if (TREE_CODE (vec_attr) != INTEGER_CST) + return false; + + if (ret) + *ret = TREE_INT_CST_LOW (vec_attr); + return true; +} + /* Returns true if the provided function has the "naked" attribute. */ static inline bool is_naked_func (const_tree decl) { return has_func_attr (decl, "naked"); @@ -1768,12 +1800,27 @@ rx_expand_prologue (void) } static void rx_output_function_prologue (FILE * file, HOST_WIDE_INT frame_size ATTRIBUTE_UNUSED) { + int v; + + if (has_interrupt_vector (NULL_TREE, &v)) + { + if (0 <= v && v <= 255) + { + asm_fprintf (file, "\t.global\t__gcc_autovector_func_%d\n", v); + asm_fprintf (file, "__gcc_autovector_func_%d:\n", v); + } + else + { + error ("interrupt vector %d must be in the range 0..255", v); + } + } + if (is_fast_interrupt_func (NULL_TREE)) asm_fprintf (file, "\t; Note: Fast Interrupt Handler\n"); if (is_interrupt_func (NULL_TREE)) asm_fprintf (file, "\t; Note: Interrupt Handler\n"); @@ -2549,13 +2596,12 @@ rx_handle_func_attribute (tree * node, tree name, tree args, int flags ATTRIBUTE_UNUSED, bool * no_add_attrs) { gcc_assert (DECL_P (* node)); - gcc_assert (args == NULL_TREE); if (TREE_CODE (* node) != FUNCTION_DECL) { warning (OPT_Wattributes, "%qE attribute only applies to functions", name); * no_add_attrs = true; @@ -2572,13 +2618,13 @@ rx_handle_func_attribute (tree * node, const struct attribute_spec rx_attribute_table[] = { /* Name, min_len, max_len, decl_req, type_req, fn_type_req, handler, affects_type_identity. */ { "fast_interrupt", 0, 0, true, false, false, rx_handle_func_attribute, false }, - { "interrupt", 0, 0, true, false, false, rx_handle_func_attribute, + { "interrupt", 0, 1, true, false, false, rx_handle_func_attribute, false }, { "naked", 0, 0, true, false, false, rx_handle_func_attribute, false }, { NULL, 0, 0, false, false, false, NULL, false } };