This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Segment register support for the i386


Hi all,

Over the last few days I have been looking into how I can get some
basic support for segmentation on the i386 into GCC.

A while ago Richard Henderson made a suggestion to have something
like:

   int * __attribute__((seggs)) ptr;

so that %gs is used whenever ptr is dereferenced[1]. However support
for multiple pointer types is completey absent in GCC as indicated by
Jeff Law[2].

An approach that seems to be easier to implement is to allow (global)
register variables bound to segment registers (fs, gs and maybe cs,
ds, es and ss), just like what can be done with other registers.

Consider the following code fragment:

   struct foo
   {
     int x;
     int y;
   };

   register struct foo *bar __asm__ ("gs");

   int
   foobar (int x)
   {
     return x + bar->y;
   }

In this example `bar->y' would refer to the member `y' of a `struct
foo' laid out at the start of the segment loaded into the "%gs"
register.  In principle this accomplishes the same as the `attribute'
approach suggested by Richard.

It seems that there is not a whole lot that needs to be done to
support this in GCC.  Basically, I added support for the "%gs"
register to `gcc/config/i386/i386.h' and extended `struct ix86_adress'
and `ix86_decompose_address()' in `gcc/config/i386/i386.c' with
support for a segment prefix.  The resulting compiler produced the
following assembler code for example above:

	   .file   "test-gs.c"
	   .version        "01.01"
   gcc2_compiled.:
   .text
	   .align 16
   .globl foobar
	   .type    foobar,@function
   foobar:
	   pushl   %ebp
	   movl    %esp, %ebp
	   movl    %gs:4, %eax
	   movl    8(%ebp), %edx
	   movl    %ebp, %esp
	   addl    %edx, %eax
	   popl    %ebp
	   ret
   .Lfe1:
	   .size    foobar,.Lfe1-foobar
	   .ident  "GCC: (GNU) 2.96 19991223 (experimental)"

Although I have a working example, I lot of work needs to be done to
assure that the compiler can handle more complex cases correctly, and
to make sure that the compiler signals invalid use of the segment
registers correctly.  However before doing this work (in which I might
need some assistence from more experienced GCC hackers) I first want
to ask if there is any chance for this feature to be included in GCC.

Mark

[1] http://sourceware.cygnus.com/ml/libc-hacker/1999-08/msg00153.html
[2] http://gcc.gnu.org/ml/gcc/1999-06/msg00706.html

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]