Xref: news2.mv.net comp.os.msdos.djgpp:6756 From: alaric AT abwillms DOT demon DOT co DOT uk (Alaric B. Williams) Newsgroups: comp.os.msdos.djgpp Subject: Re: __attribute__((section)) Date: Fri, 02 Aug 1996 19:13:38 GMT Lines: 121 Message-ID: <839013106.23117.0@abwillms.demon.co.uk> References: <838840319 DOT 11194 DOT 2 AT abwillms DOT demon DOT co DOT uk> NNTP-Posting-Host: abwillms.demon.co.uk To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp alaric AT abwillms DOT demon DOT co DOT uk (Alaric B. Williams) wrote: >Mark Habersack 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 #include #include #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 http://www.hardcafe.co.uk/Alaric/