Mail Archives: djgpp/1996/08/07/14:55:21
alaric AT abwillms DOT demon DOT co DOT uk (Alaric B. Williams) wrote:
>Mark Habersack <grendel AT ananke DOT amu DOT edu DOT pl> wrote:
>>On Mon, 29 Jul 1996, Helge Kruse wrote:
>>The hack is OK, but where does MYDATA section go? Does it go to separate
>>segment when proggy is loaded? If so, you have to use far pointers/switch DS
>>selector if you want to access the data - BY HAND.
>Is this really true?
>I mean, will the stub actually allocate seperate selectors with DPMI
>for other sections, or just load all those sections into the same
>virtual address space, as I thought?
I'm vindicated! The following will print the value 123 on screen, as
expected!
I hope it's useful for anyone else fiddling with their own sections.
There was an (unofficial) patch posted here a while ago to fix gcc's
__attribute__ ((section)) problem - I haven't checked it out yet, but
it'll go in my hardware ints tutorial...
Enjoy,
ABW
=============DJGPP.LNK:
OUTPUT_FORMAT("coff-go32")
ENTRY(start)
SECTIONS
{
.text 0x1000+SIZEOF_HEADERS : {
*(.text)
etext = . ; _etext = .;
sltext = . ;
*(.ltxt)
eltext = . ;
. = ALIGN(0x200);
}
.data ALIGN(0x200) : {
djgpp_first_ctor = . ;
*(.ctor)
djgpp_last_ctor = . ;
djgpp_first_dtor = . ;
*(.dtor)
djgpp_last_dtor = . ;
*(.data)
edata = . ; _edata = .;
sldata = . ;
*(.ldat)
eldata = . ;
. = ALIGN(0x200);
}
.bss SIZEOF(.data) + ADDR(.data) :
{
*(.bss)
*(COMMON)
end = . ; _end = .;
. = ALIGN(0x200);
}
}
=========MAKEFILE:
sections.exe : sections.S sect.cc
gcc -g sections.S sect.cc -liostr -o sections
=========SECT.CC
#include <dpmi.h>
#include <go32.h>
#include <iostream.h>
#define LOCKED_VAR section (".ldat"), nocommon
#define LOCKED_FUNC section (".ltxt")
extern int sltext __asm__("sltext");
extern int eltext __asm__("eltext");
extern int sldata __asm__("sldata");
extern int eldata __asm__("eldata");
void lock_everything() {
_go32_dpmi_lock_data(&sldata,(long)&eldata - (long)&sldata);
_go32_dpmi_lock_code(&sltext,(long)&eltext - (long)&sltext);
}
extern "C" int my_var;
extern "C" void my_func(void);
main() {
lock_everything();
cout << my_var;
my_func();
}
==============SECTIONS.S
..section .ldat
..globl _my_var
_my_var: .long 123
..section .ltxt
..globl _my_func
_my_func:
ret
--
I have become... Comfortably numb...
Alaric B. Williams Internet : alaric AT abwillms DOT demon DOT co DOT uk
<A HREF="http://www.hardcafe.co.uk/Alaric/">http://www.hardcafe.co.uk/Alaric/</A>
- Raw text -