public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Segment registers support for i386
@ 2006-04-04  9:44 Rémy Saissy
  2006-04-04 10:54 ` Andrew Haley
  0 siblings, 1 reply; 17+ messages in thread
From: Rémy Saissy @ 2006-04-04  9:44 UTC (permalink / raw)
  To: gcc

> It would take a massive target-specific backend hack to make that happen, as GCC > currently only supports flat address spaces. ;-)

I don't understand why.
gcc currently consider every data access on i386 to be %ds:offset or %ss:offset
depending on the instruction. The purpose is only to add a way to
explicitly indicate
the section to use then is could be %gs:offset or %fs:offset.

I'm new in gcc hacking therefore I still have to learn more about the
internals but
at first glance it doesn't sounds like a so big work.
Could you explain me why do you think it would take a massive
target-specific backend ?
Thanks a lot.


--
Rémy Saissy            JabberID: remy.saissy@jabber.fr
                                Web:     http://remysaissy.free.fr
"L'homme qui a le plus vécu n'est pas celui qui a compté le plus d'années,
mais celui qui a le plus senti la vie."
J.-J. Rousseau, Emile.

^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: Segment registers support for i386
@ 2006-06-02  1:49 Rémy Saissy
  0 siblings, 0 replies; 17+ messages in thread
From: Rémy Saissy @ 2006-06-02  1:49 UTC (permalink / raw)
  To: rridge, gcc

>Remy Saissy wrote:
>>I've looked for a target specific callback to modify but I've found
>>nothing, even in the gcc internals info pages. Do you mean I would
>>have to modify some code outside of the i386 directory ? Or maybe to
>>add such a callback if it doesn't exist ;)

>You'ld have to modify code in the main GCC directory, probably a lot
>of code.  Since it's target dependent, you'ld need to implement it using
>a hook or hooks.

>>In which file does the tree to RTL conversion code is located ?

>There are several files that do this jobs.  See the internals
>documentation.

>>Does it mean that an RTL expression which use reg: force gcc to use a
>>particular pseudo register ?

>Pseudo registers aren't real registers.  They either get changed to real
>hard registers, or memory references to stack slots.  See the internals
>documentation for more details.

>					Ross Ridge

Ok,
Thanks a lot for your help, I'm going to see what I can do and if I
don't give up now ;)
Have a great day.


-- 
Rémy Saissy            JabberID: remy.saissy@jabber.fr
                                Web:     http://remysaissy.free.fr
"L'homme qui a le plus vécu n'est pas celui qui a compté le plus d'années,
mais celui qui a le plus senti la vie."
J.-J. Rousseau, Emile.

^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: Segment registers support for i386
@ 2006-06-01  1:48 Ross Ridge
  0 siblings, 0 replies; 17+ messages in thread
From: Ross Ridge @ 2006-06-01  1:48 UTC (permalink / raw)
  To: gcc

Remy Saissy wrote:
>I've looked for a target specific callback to modify but I've found
>nothing, even in the gcc internals info pages. Do you mean I would
>have to modify some code outside of the i386 directory ? Or maybe to
>add such a callback if it doesn't exist ;)

You'ld have to modify code in the main GCC directory, probably a lot
of code.  Since it's target dependent, you'ld need to implement it using
a hook or hooks.

>In which file does the tree to RTL conversion code is located ?

There are several files that do this jobs.  See the internals
documentation.

>Does it mean that an RTL expression which use reg: force gcc to use a
>particular pseudo register ? 

Pseudo registers aren't real registers.  They either get changed to real
hard registers, or memory references to stack slots.  See the internals
documentation for more details.

					Ross Ridge

^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: Segment registers support for i386
@ 2006-05-29 15:11 Rémy Saissy
  0 siblings, 0 replies; 17+ messages in thread
From: Rémy Saissy @ 2006-05-29 15:11 UTC (permalink / raw)
  To: rridge; +Cc: gcc

>Ross Ridge wrote:
>>Remy Saissy wrote:

>> What I understand is that there is two kind of managment for attribute :

>Attributes are handled in various different ways depending on what the
>attribute does.  To handle your case correctly, you'ld have to change how
>the tree to RTL conversion generates RTL addresses expressions whenever
>a pointer with the "far" attribute is dereferenced.  This is probably
>going to be a lot work.

I've looked for a target specific callback to modify but I've found
nothing, even in the gcc internals info pages. Do you mean I would
have to modify some code outside of the i386 directory ? Or maybe to
add such a callback if it doesn't exist ;)
In which file does the tree to RTL conversion code is located ?

>> Therefore, I can consider the following relationship:
>>  (mem:SI (plus:SI (unspec:SI [(reg:HI fs)] SEGREF) (reg:SI var)))
>>       |      |                    |                    |
>>      \/     \/                   \/                   \/
>>      int *                 __attribute__((far("fs")))                      p;

>No, that's not what the RTL expression represents.  Declarations aren't
>represented in RTL.  The example RTL expression I gave is just an
>expression, not a full RTL instruction.  It's something that could be
>used as the memory operand of an instruction.  The RTL expression I gave
>would correspond to a C expression (not a statement) like this:

>	*(int * __atribute__((far("fs")))) var

Ok, I thanks for the precisions :)

>> does (reg:HI fs) care about the type of the parameter fs ?

>See the GCC Internals documentation.  In my example, since I don't know
>what the actual hard register number you assigned to the FS segment
>register, I just put "fs" in the place where the actual register number
>would appear.  Similarily, the "var" in  "(reg:SI var)" represents
>the number of the pseudo-register GCC would allocate for an automatic
>variable named "var".

Does it mean that an RTL expression which use reg: force gcc to use a
particular pseudo
register ? Is there something I should care about when I choose the
number of this pseudo
register ?

>> how does gcc recognize such an expression ?

>Since this expression is a memory operand, it's recognized by the
>GO_IF_LEGITIMATE_ADDRESS() macro.  In the i386 port, that's implemented
>by legitimate_address_p() in "i386.c".

Ok thank you very much.

>					Ross Ridge


-- 
Rémy Saissy            JabberID: remy.saissy@jabber.fr
                                Web:     http://remysaissy.free.fr
"L'homme qui a le plus vécu n'est pas celui qui a compté le plus d'années,
mais celui qui a le plus senti la vie."
J.-J. Rousseau, Emile.

^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: Segment registers support for i386
@ 2006-05-29 10:49 Ross Ridge
  0 siblings, 0 replies; 17+ messages in thread
From: Ross Ridge @ 2006-05-29 10:49 UTC (permalink / raw)
  To: gcc

Remy Saissy wrote:
>if I understand well, to make gcc generating rtx according to an
>__attribute__((far("fs"))) on a pointer I only have to add or modify
>rtx in the i386.md file and add an UNSPEC among the constants ?

No, the work you need to on the backend, adding an UNSPEC constant to
"i386.md" and writing code to handle the UNSPEC in "i386.c" is just the
easy part.

> What I understand is that there is two kind of managment for attribute :

Attributes are handled in various different ways depending on what the
attribute does.  To handle your case correctly, you'ld have to change how
the tree to RTL conversion generates RTL addresses expressions whenever
a pointer with the "far" attribute is dereferenced.  This is probably
going to be a lot work.

> Therefore, I can consider the following relationship:
>  (mem:SI (plus:SI (unspec:SI [(reg:HI fs)] SEGREF) (reg:SI var)))
>       |      |                    |                    |
>      \/     \/                   \/                   \/
>      int *                 __attribute__((far("fs")))                      p;

No, that's not what the RTL expression represents.  Declarations aren't
represented in RTL.  The example RTL expression I gave is just an
expression, not a full RTL instruction.  It's something that could be
used as the memory operand of an instruction.  The RTL expression I gave
would correspond to a C expression (not a statement) like this:

	*(int * __atribute__((far("fs")))) var

> does (reg:HI fs) care about the type of the parameter fs ?

See the GCC Internals documentation.  In my example, since I don't know
what the actual hard register number you assigned to the FS segment
register, I just put "fs" in the place where the actual register number
would appear.  Similarily, the "var" in  "(reg:SI var)" represents
the number of the pseudo-register GCC would allocate for an automatic
variable named "var".

> how does gcc recognize such an expression ? 

Since this expression is a memory operand, it's recognized by the
GO_IF_LEGITIMATE_ADDRESS() macro.  In the i386 port, that's implemented
by legitimate_address_p() in "i386.c".

					Ross Ridge

^ permalink raw reply	[flat|nested] 17+ messages in thread
[parent not found: <17fd5360605282307g63e833b5y9569a4c0ca2c1904@mail.gmail.com>]
* Re: Segment registers support for i386
@ 2006-05-26  6:40 Rémy Saissy
  0 siblings, 0 replies; 17+ messages in thread
From: Rémy Saissy @ 2006-05-26  6:40 UTC (permalink / raw)
  To: gcc

>You won't be able to.  You're going to need to write your own code that,
>during the conversion of the tree to RTL, creates RTL expressions which
>indicate that the memory references use segment registers.  This probably
>won't be easy since there are a lot of contexts where your "far" pointer
>can be used.  I suspect this is where you're going to give up on your
>project, but if you do then RTL expressions you'll need to create should
>probably look like:

>	(mem:SI (plus:SI (unspec:SI [(reg:HI fs)] SEGREF) (reg:SI var)))

>After getting GCC to generate expressions like these, then it's a
>realtively simple case of modifying ix86_decompose_address() to handle
>the unspec.  You might also need to change other backend code for
>handling addresses.

>					Ross Ridge

Thanks for your precisions.


-- 
Rémy Saissy            JabberID: remy.saissy@jabber.fr
                                Web:     http://remysaissy.free.fr
"L'homme qui a le plus vécu n'est pas celui qui a compté le plus d'années,
mais celui qui a le plus senti la vie."
J.-J. Rousseau, Emile.

^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: Segment registers support for i386
@ 2006-05-21 20:06 Ross Ridge
  0 siblings, 0 replies; 17+ messages in thread
From: Ross Ridge @ 2006-05-21 20:06 UTC (permalink / raw)
  To: gcc

Remy Saissy wrote:
>I don't really understand how to access the attribute set up in the
>tree in the rtx struct.

You won't be able to.  You're going to need to write your own code that,
during the conversion of the tree to RTL, creates RTL expressions which
indicate that the memory references use segment registers.  This probably
won't be easy since there are a lot of contexts where your "far" pointer
can be used.  I suspect this is where you're going to give up on your
project, but if you do then RTL expressions you'll need to create should
probably look like:

	(mem:SI (plus:SI (unspec:SI [(reg:HI fs)] SEGREF) (reg:SI var)))

After getting GCC to generate expressions like these, then it's a
realtively simple case of modifying ix86_decompose_address() to handle
the unspec.  You might also need to change other backend code for
handling addresses. 

					Ross Ridge

^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: Segment registers support for i386
@ 2006-05-14 16:09 Rémy Saissy
  2006-05-14 17:54 ` Rask Ingemann Lambertsen
  2006-05-17 18:40 ` Rask Ingemann Lambertsen
  0 siblings, 2 replies; 17+ messages in thread
From: Rémy Saissy @ 2006-05-14 16:09 UTC (permalink / raw)
  To: gcc

Hi everybody,
I decided to split the modification in two parts:
 - add an __asm__ () statement to control the value of
   the segment registers from an high level language;
   This __asm__ () statement is then used as follow:
    register short a __asm__ ("es");

    int main(int argc, char **argv)
     {
	short b;

	b = a;
	a = 0x2a;
	printf("old value: %x new value: %x\n", b, a);
	return (0);
     }

 - add an __attribute__ ((__far__())) to allow pointers to
   choose their data segment.
   This __attribute__(()) statement is then used as follow:
	int	*gs_p __attribute__ ((__far__("gs"))) = 0x2a;

   int main(int argc, char **argv)
    {
	int	*fs_p __attribute__((__far__("fs"))) = 0x0;

	fs_p[1] = 10;
	gs_p[0] = fs_p[0];
	return (0);
    }

 Presently I have a problem with the first part.
 I have added the the entries for es,fs and gs at the end of
 FIXED_REGISTERS under the value 1,1,1 and in
 CALL_USED_REGISTERS with the value 1,1,1
 I also add the entries at the end of REG_ALLOC_ORDER and in
 both HI_REGISER_NAMES and ADDITIONAL_REGISTER_NAMES.
 Because those registers are different, I have created a new
 register class at the end of the reg_class enum and added
 the relevant REG_CLASS_NAMES and REG_CLASS_CONTENTS entries.
 At least, I added the 's' id in REG_CLASS_FROM_LETTER.

To manage the manipulation of the register class, I added entries in
the i386.md file.

;; get a value from a segment register.
(define_insn "store_seg"
  [(set (match_operand:SI 0 "nonimmediate_operand" "")
        (match_operand:SI 1 "general_operand" "s"))]
        ""
        "movl\t%1,%0")

;; set a value in a segment register.
(define_insn "load_seg"
  [(set (match_operand:SI 0 "general_operand" "=s")
        (match_operand:SI 1 "register_operand" ""))]
        ""
        "movl\t%1,%0")

I think I did everything needed to make it working but when I compile
gcc I get the following error:
../.././gcc/crtstuff.c:301: error: unable to generate reloads for:
(insn:HI 17 15 18 1 (set (reg:SI 0 ax [orig:62 p.25 ] [62])
        (mem/f/c/i:SI (symbol_ref:SI ("p.5512") [flags 0x2] <var_decl
0x3b01dc60 p>) [7 p+0 S4 A32])) 28 {store_seg} (nil)
    (nil))
../.././gcc/crtstuff.c:301: internal compiler error: in find_reloads,
at reload.c:3734
Please submit a full bug report,
[...]

This is the 4.1.0 version of the compiler.
If somebody can light me... Thanks.


-- 
Rémy Saissy            JabberID: remy.saissy@jabber.fr
                                Web:     http://remysaissy.free.fr
"L'homme qui a le plus vécu n'est pas celui qui a compté le plus d'années,
mais celui qui a le plus senti la vie."
J.-J. Rousseau, Emile.

^ permalink raw reply	[flat|nested] 17+ messages in thread
* Segment registers support for i386
@ 2006-03-31  8:55 Rémy Saissy
  2006-03-31 15:51 ` Lucas (a.k.a T-Bird or bsdfan3)
  0 siblings, 1 reply; 17+ messages in thread
From: Rémy Saissy @ 2006-03-31  8:55 UTC (permalink / raw)
  To: gcc

Hi everybody,
I'm looking for gcc support of x86-32 segment registers but the only information
I've found about it is in this old thread:
http://gcc.gnu.org/ml/gcc/1999-12/msg00526.html
I was wondering what happened since this thread, does somebody have integrated
the segment register support for i386 in gcc ?
There is nothing about it in the manual pages and gcc 4.0.3 doesn't
seem to support it.
Thank for your precisions.
Have a great day.


--
Rémy Saissy            JabberID: remy.saissy@jabber.fr
                                Web:     http://remysaissy.free.fr
"L'homme qui a le plus vécu n'est pas celui qui a compté le plus d'années,
mais celui qui a le plus senti la vie."
J.-J. Rousseau, Emile.

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2006-06-02  1:49 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-04-04  9:44 Segment registers support for i386 Rémy Saissy
2006-04-04 10:54 ` Andrew Haley
2006-04-04 12:16   ` Rémy Saissy
  -- strict thread matches above, loose matches on Subject: below --
2006-06-02  1:49 Rémy Saissy
2006-06-01  1:48 Ross Ridge
2006-05-29 15:11 Rémy Saissy
2006-05-29 10:49 Ross Ridge
     [not found] <17fd5360605282307g63e833b5y9569a4c0ca2c1904@mail.gmail.com>
2006-05-29  6:22 ` Rémy Saissy
2006-05-26  6:40 Rémy Saissy
2006-05-21 20:06 Ross Ridge
2006-05-14 16:09 Rémy Saissy
2006-05-14 17:54 ` Rask Ingemann Lambertsen
2006-05-15  1:00   ` Rémy Saissy
2006-05-17 18:40 ` Rask Ingemann Lambertsen
2006-05-21 11:01   ` Rémy Saissy
2006-03-31  8:55 Rémy Saissy
2006-03-31 15:51 ` Lucas (a.k.a T-Bird or bsdfan3)

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).