From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3718 invoked by alias); 2 Jan 2012 09:44:54 -0000 Received: (qmail 3710 invoked by uid 22791); 2 Jan 2012 09:44:54 -0000 X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-vw0-f41.google.com (HELO mail-vw0-f41.google.com) (209.85.212.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 02 Jan 2012 09:44:39 +0000 Received: by vbbfn1 with SMTP id fn1so14190079vbb.0 for ; Mon, 02 Jan 2012 01:44:38 -0800 (PST) Received: by 10.52.173.176 with SMTP id bl16mr22753225vdc.47.1325497477662; Mon, 02 Jan 2012 01:44:37 -0800 (PST) MIME-Version: 1.0 Received: by 10.52.67.105 with HTTP; Mon, 2 Jan 2012 01:44:16 -0800 (PST) From: Julius Baxter Date: Mon, 02 Jan 2012 09:44:00 -0000 Message-ID: Subject: Encoding of immediates different to label addresses To: cgen@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 X-IsSubscribed: yes Mailing-List: contact cgen-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cgen-owner@sourceware.org X-SW-Source: 2012-q1/txt/msg00001.txt.bz2 Hi, I'm working on fixing up the OpenRISC 1000 CGEN port and have come across something I find I can't quite do with CGEN. For the jump and branch instructions, if we use immediate value number specified in the assembly, we need that encoded into the instruction without any shifting occurring to it. Eg. "l.bf 1" should become 0x10000001, "l.bf 4" should become 0x10000004 etc. These target addresses are shifted-left by two during decoding, and so "l.bf 1" is actually a branch of 4 bytes. If we use a label for an address, though, I'm seeing that we're getting the offset in bytes during encoding, which then needs to be shifted right by two before being put in the instruction. But it seems we can have the shifting on both numerical immediates and labels, or neither. (Pardon my incorrect use of terminology, I have a feeling I'm not quite calling everything its right name!) Upon inspecttion, it looks like the binutils port we have been using for the past few years (not CGEN-based) has a right-shift of 2 in the md_apply_fix() function in binutils/gas/config/tc-or32.c ( http://sourceware.org/git/?p=binutils.git;a=blob;f=gas/config/tc-or32.c;h=7234fb837e006f979c255f62206e39a9822046d2;hb=HEAD#l603 ) when the instruction had the actual value of the label inserted into it. Is there any way to handle this using the CGEN description? The current instruction field definition being used is: (df f-disp26 "disp26" (PCREL-ADDR) 25 26 INT ((value pc) (sra WI (sub WI value pc) (const 2))) ((value pc) (add WI (sll WI value (const 2)) pc))) This does the shifting on encode and the target label addresses are right but the numerical immediates are wrong, but if I remove the sra on the encode, the numerical immediates are right but the target label addresses are wrong. I've had a bit of a poke around and seen the function gas_cgen_md_apply_fix() is used as a generic md_apply_fix() function, but can't quite see where I might be able to hook in things for particular encoding cases. If anyone could point out how I could handle this case it'd be appreciated. Thanks, Julius