Mail Archives: djgpp/1997/03/26/10:21:10
On Tue, 25 Mar 1997, Eli Zaretskii wrote:
> On Mon, 24 Mar 1997, Peter Berdeklis wrote:
> > > The problem is NOT how to use segment prefixes. The problem is how do
> > > you make, say, GS have the value that will point to a certain section.
> >
> > If this is the problem (I didn't read the original post), then I don't
> > understand why there is a problem.
> >
> > You simply load GS with the appropriate selector and use a byte prefix
> > whenever you want to reference that part of memory. How you get the
> > selector has nothing to do with ASM.
>
> I could miss something very obvious here, but I think the problems is
> how do you know the selector value which you should load into GS. The
> .section directive, AFAIK, doesn't generate any selector that, when
> used, will result in offsets being relative to that section. As a
> matter of fact, I think .section doesn't create a descriptor at all,
> so there's no selector to begin with. This is, AFAIK, the problem
> behind the lack of support for multi-section programs in Gas.
For multi section programs it is the job of the compiler/linker to create
the appropriate descriptor in the local descriptor table (LDT) and load
the selector into a segment register to make the reference. This is what
gcc doesn't do. It assumes that the segment registers are pointing to
the proper segments (not necessarily the same for code and data I think,
although that is the way it's implemented in DJGPP) and then assumes that
these segment registers do not change during the life of the program.
However, for many uses the selector you use is returned by the appropriate
DPMI function. Ex., if you allocate DOS memory the function
_dpmi_allocate_dos_memory returns the appropriate selector to you. Or
you could use the standard selectors, like my_ds(), my_cs() or dos_ds().
If you want to create a selector to an arbitrary address in physical/virtual
memory you have to allocate and initialize the descriptor yourself.
There are DPMI calls to do this and return the selector to the allocated
descriptor. You can also create an alias descriptor to create, for
example, an data section on top of a code section so that you can modify
your code (run-time).
Selectors are easy to get and the Intel instruction set gives you
everything you need to use them, whether you use Intel or AT&T style
assembly. What gcc does not provide is automatic support for changing
selectors, but if you've gotten to the point where you can allocate and
initialize one yourself that probably isn't a big concern to you. :)
---------------
Peter Berdeklis
Dept. of Physics, Univ. of Toronto
- Raw text -