From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10997 invoked by alias); 28 Nov 2002 15:34:31 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 10988 invoked from network); 28 Nov 2002 15:34:29 -0000 Received: from unknown (HELO localhost.redhat.com) (216.138.202.10) by sources.redhat.com with SMTP; 28 Nov 2002 15:34:29 -0000 Received: from redhat.com (localhost [127.0.0.1]) by localhost.redhat.com (Postfix) with ESMTP id 930CB3F30; Thu, 28 Nov 2002 10:34:22 -0500 (EST) Message-ID: <3DE6377E.1040106@redhat.com> Date: Thu, 28 Nov 2002 07:34:00 -0000 From: Andrew Cagney User-Agent: Mozilla/5.0 (X11; U; NetBSD macppc; en-US; rv:1.0.0) Gecko/20020824 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Keith Walker Cc: Richard.Earnshaw@arm.com, Andreas Schwab , gdb-patches@sources.redhat.com Subject: Re: [rfa?] Add frame_align(); Was: ARM stack alignment on hand called functions References: <4.3.2.7.2.20021128105650.01e91010@mhsun1.maidenhead.arm.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2002-11/txt/msg00714.txt.bz2 > At 10:40 28/11/2002 +0000, Richard Earnshaw wrote: >> Richard Earnshaw writes: >> >> |> > +/* Ensure that the ARM's stack pointer has the correct alignment for a >> |> > + new frame. */ >> |> > +static CORE_ADDR >> |> > +arm_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr) >> |> > +{ >> |> > + return (addr & -16); >> |> > +} >> |> >> |> Yuck, two's complement assumption. >> >> No, -16 is implicitly cast to bfd_vma, which is unsigned, and this >> operation is completely defined independent of the representation of >> signed integers. > > Hmm, strictly speaking you are correct. I don't have to like it though, > and it means that the code is heavily dependent on the non-obvious fact > that addr is an unsigned type to get the correct behaviour (if bfd_vma > were to be changed to a signed type then this code would quietly break). > > So I'll change my comment to: > > Yuck, implicit cast of negative number to unsigned. > > I notice that the h8300-tdep.c file defines some macros to do this sort of rounding ... round_up() and round_down(). As aligning addresses is a reasonable common thing to do maybe these macros should be moved to a more generic place and used whenever such rounding is required. It doesn't fix the implicit cast issue, but would at least make finding where such alignment occurs easier. Hmm, the've been breeding. So does the MIPS and s390 .... Equivalent functions that spell out each step vis: ULONGEST mask = -(ULONGEST)(n); ULONGEST maddr = (addr & mask); return maddr; and have a 10:1 comment:code ratio sound like a good idea. A GDB goal can be to debug this at -O3 :-) Andrew