From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 111888 invoked by alias); 29 Feb 2016 06:25:22 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 111862 invoked by uid 89); 29 Feb 2016 06:25:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-spam-relays-external:sk:nasmtp0, H*RU:sk:nasmtp0, Lowest, H*M:atmel X-HELO: SJOEDG01.corp.atmel.com Received: from nasmtp02.atmel.com (HELO SJOEDG01.corp.atmel.com) (204.2.163.16) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Mon, 29 Feb 2016 06:25:18 +0000 Received: from apsmtp01.atmel.com (10.168.254.30) by sjoedg01.corp.atmel.com (10.64.253.30) with Microsoft SMTP Server (TLS) id 14.3.235.1; Sun, 28 Feb 2016 22:33:47 -0800 Received: from PENCHT01.corp.atmel.com (10.168.5.161) by apsmtp01.corp.atmel.com (10.168.254.30) with Microsoft SMTP Server (TLS) id 14.3.235.1; Mon, 29 Feb 2016 14:27:15 +0800 Received: from penmbx02.corp.atmel.com ([fe80::b4e4:e0f6:b17c:e55f]) by PENCHT01.corp.atmel.com ([fe80::95df:d3d0:4452:28e3%12]) with mapi id 14.03.0235.001; Mon, 29 Feb 2016 14:25:14 +0800 From: "Sivanupandi, Pitchumani" To: Luis Machado CC: "gdb-patches@sourceware.org" Subject: Re: [patch, avr] Fix incorrect argument register for push dummy call Date: Mon, 29 Feb 2016 06:25:00 -0000 Message-ID: References: <20160225123448.GA10608@CHELT0346> <56D05E07.5000102@codesourcery.com> In-Reply-To: <56D05E07.5000102@codesourcery.com> user-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 x-ms-exchange-imapappendstamp: PENCHT02.corp.atmel.com (14.03.0227.000) Content-Type: text/plain; charset="us-ascii" Content-ID: <3EE111E252166F48AC28AC595A015DAF@atmel.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-SW-Source: 2016-02/txt/msg00884.txt.bz2 On 26-02-2016 19:45, Luis Machado wrote: > Hi, > > On 02/25/2016 09:34 AM, Pitchumani Sivanupandi wrote: >> There are few failures for avr-gdb in callfuncs.exp. These failures are >> due to the incorrect argument passing in case of push dummy call. The >> last argument register is calculated incorrectly that caused this issue. >> >> Attached patch fixes the calculation so that the push dummy call aligns >> with the code generated by avr-gcc. >> >> No new regressions found when tested with internal simulator. >> >> If ok, could someone commit please? >> >> Regards, >> Pitchumani >> >> gdb/ChangeLog >> >> 2016-02-25 Pitchumani Sivanupandi >> >> * avr-tdep.c (AVR_LAST_ARG_REGNUM): Define. >> (avr_push_dummy_call): Correct last needed argument register. >> >> >> avr-last-argument-register-fix.patch >> >> >> diff --git a/gdb/avr-tdep.c b/gdb/avr-tdep.c >> index 597cfb4..18ecfe4 100644 >> --- a/gdb/avr-tdep.c >> +++ b/gdb/avr-tdep.c >> @@ -111,6 +111,7 @@ enum >> >> AVR_ARG1_REGNUM =3D 24, /* Single byte argument */ >> AVR_ARGN_REGNUM =3D 25, /* Multi byte argments */ >> + AVR_LAST_ARG_REGNUM =3D 8, /* Last argument register */ >> >> AVR_RET1_REGNUM =3D 24, /* Single byte return value */ >> AVR_RETN_REGNUM =3D 25, /* Multi byte return value */ >> @@ -1298,12 +1299,14 @@ avr_push_dummy_call (struct gdbarch *gdbarch, >> struct value *function, >> const bfd_byte *contents =3D value_contents (arg); >> int len =3D TYPE_LENGTH (type); >> >> - /* Calculate the potential last register needed. */ >> - last_regnum =3D regnum - (len + (len & 1)); >> + /* Calculate the potential last register needed. >> + E.g. For length 2, registers regnum and regnum-1 (say 25 and >> 24) > > Is that how the code works? It seems a bit confusing, because we want to > start in even-aligned registers, so we'd use r25:r24, r23:r22 etc. Yes. Lowest even register will be loaded with LSB of argument, and=20 subsequent bytes passed in subsequent registers (i.e. in increasing=20 register number). > So last_regnum always ends up pointing at an odd-numbered register, so > the code can decrement the odd-numbered register if needed (in case we > have data of length 1/3/...). > > /* Skip a register for odd length args. */ > if (len & 1) > regnum--; No, last_regnum should point at last even register where LSB of argument=20 should be loaded. Variable 'regnum' should point to register which loads=20 MSB of argument. In case of odd length argument, regnum-1 will hold the=20 MSB of argument. So, it is decremented. Ref: https://gcc.gnu.org/wiki/avr-gcc#Calling_Convention >> + shall be used. So, last needed register will be >> regnum-1(24). */ >> + last_regnum =3D regnum - (len + (len & 1)) + 1; >> > > Isn't this going to be incorrect for, say, data of length 3? > > last_regnum =3D 25 - (3 + (3 & 1)) + 1 -> 25 - (3 + 1) + 1 -> 22 > > But it should've been 21, because data would occupy registers 25:24 and > 23:22 and then we'd need an even-aligned register to start with? Variable last_regnum indicates the end of register that required to pass=20 the argument. In case of length 3, we need 22 (LSB), 23 and 24(MSB) to=20 pass the argument. So, last register required is 22, not 21. Regards, Pitchumani