public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew Haley <aph-gcc@littlepinkcloud.COM>
To: Nick Maclaren <nmm1@cus.cam.ac.uk>
Cc: gcc-help@gcc.gnu.org
Subject: Re: RTL obscurities
Date: Fri, 25 May 2007 14:06:00 -0000	[thread overview]
Message-ID: <18006.60444.920388.680142@zebedee.pink> (raw)
In-Reply-To: <E1HrZtv-0007E1-8w@virgo.cus.cam.ac.uk>

Nick Maclaren writes:
 > > If course, but you haven't told us what you want to know.  The
 > > question above reads like a request for a detailed RTL cookbook and
 > > manual, and you aren't going to get that in an email response.
 > 
 > ANY pointer to ANY information that will save me time reverse
 > engineering the code!

Well, I don't know what you don't know.  Have you found the GCC
internals manual?

 > It is the same requirement that I had before, and which you gave me
 > some pointers on the second aspect.  Unfortunately, it is the first
 > one that is critical :-(
 > 
 > I really do mean that I have drawn a complete blank looking for any
 > useful information, and have looked through several gcc internals
 > documents

Okay, so you have found the GCC internals manual.

 > and searched the Web as far as I can!  Some time back, I found the
 > right place to modify (ix86_expand_prologue in i386.c), and have
 > inserted some RTL, but not useful RTL.
 > 
 > What I need to do is to insert the following:
 > 
 >     extern void *__limit;
 >     extern void __failure (void);
 >     if (%SP < __limit) __failure();
 > 
 > 
 > And the call doesn't need to be a standard one, either, though it
 > does need to provide __failure with a way of getting back.

Firstly, you'll need to generate decls for the externs.  Then you'll
need to generate RTL like this:

(insn 13 12 14 1 (set (reg:CC 17 flags)
        (compare:CC (reg:SP)
            (mem:DI (symbol_ref:DI ("__limit") <var_decl 0x2aaaae1958f0 __limit>) ))) -1 (nil)
    (nil))

(jump_insn 14 13 15 1 (set (pc)
        (if_then_else (geu (reg:CC 17 flags)
                (const_int 0 [0x0]))
            (label_ref 18)
            (pc))) -1 (nil)
    )

(call_insn 17 16 18 2 (call (mem:DI (symbol_ref:DI ("__failure") <function_decl 0x2aaaae196b00 __failure>))
        (const_int 0 [0x0])) -1 (nil)
    (nil)
    (nil))

(code_label 18 17 19 3 2 "" [1 uses])

This construct doesn't need any scratch registers.  This is good.

You've already seen how to generate RTL by perusing
ix86_expand_prologue, so you know that generating this RTL will be
done by things like

  tmp = ix86_expand_int_compare (GEU, stack_pointer_rtx, limit);
  tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
			      gen_rtx_LABEL_REF (VOIDmode, label),
		              pc_rtx);

  emit_jump_insn (tmp);
  emit_call_insn ...
  emit_label (label);

... etc.

Andrew.

  reply	other threads:[~2007-05-25 14:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-25 14:01 Nick Maclaren
2007-05-25 14:06 ` Andrew Haley [this message]
2007-05-25 19:27   ` Nick Maclaren
2007-05-25 16:46 ` Ian Lance Taylor
  -- strict thread matches above, loose matches on Subject: below --
2007-05-25 13:15 Nick Maclaren
2007-05-25 13:32 ` Andrew Haley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=18006.60444.920388.680142@zebedee.pink \
    --to=aph-gcc@littlepinkcloud.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=nmm1@cus.cam.ac.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).