Mail Archives: djgpp/2013/03/09/19:30:24
"Gisle Vanem" <gvanem AT broadpark DOT no> wrote in message
news:56DBAFDDD8D54E7FA53359A52B14D263 AT dev DOT null...
> <starus2013 AT gmail DOT com> wrote:
> > #include <LIBC\farptrgs.h>
>
> Never use this in app-code. It's for djgpp internal use.
> Do a "#include <sys/farptr.h>" instead. Your use fall
> under the category "undefined behavior".
>
> > int main(){
> > int f,selector;
> >
> > __dpmi_meminfo info;
> >
> > info.size=1023;
> > info.address=0x50000;
> >
> > selector = __dpmi_allocate_ldt_descriptors(1);
> > if(selector == -1) return 0;
> > if(__dpmi_set_segment_base_address(selector,info.address)==-1)
> > return 0;
> > if(__dpmi_set_segment_limit(selector,info.size-1)==-1)
> > return 0;
> >
> > _farsetsel(selector);
>
> Read the comment in <sys/farptr.h>:
>
> Warning: These routines all use the %fs register for their
> accesses. GCC normally uses only %ds and %es, and libc
> functions (movedata, dosmemget, dosmemput) use %gs. Still,
> you should be careful about assumptions concerning whether or
> not the value you put in %fs will be preserved across calls to
> other functions. If you guess wrong, your program will crash.
> Better safe than sorry.
>
> So GS register is in practice reserved for libc internal stuff.
> AFAICR movedata() etc. don't preserve it. Check for yourself.
>
> Also note that real-mode callbacks (RMCB code) doesn't either
> push/pop the FS+GS registers. Your callback should do it if you
> these registers.
>
%gs is used by a bunch of other stuff too...
%cs _my_cs()
%cs _go32_my_cs()
%ds _my_ds()
%ds _go32_my_ds()
%ss _my_ss()
%ss _go32_my_ss()
%es same as %ds
%fs used by farpeek(), farpoke()
mirror of %ds __djgpp_ds_alias
%gs __djgpp_dos_sel
%gs _dos_ds
%gs _go32_info_block.selector_for_linear_memory
%gs _go32_info_block+26
%gs _go32_conventional_mem_selector()
You can use _farsetsel to set %fs, e.g., to _dos_ds or _my_ds().
_dos_ds is mapped to the first 1MB plus 64KB. _my_ds() is the
application data space. Or, you can enable 'nearptrs'.
Rod Pemberton
- Raw text -