From: NoEmailAds AT execpc DOT com (Chris Giese) Newsgroups: comp.os.msdos.djgpp Subject: Re: Mapping a data structure into DOS memory space Date: Tue, 05 Dec 2000 19:33:18 GMT Organization: PROPULSION GROUP References: X-Newsreader: Forte Free Agent 1.11/32.235 Lines: 60 Message-ID: <3a2d42da$0$35011$6d6c75b@news.execpc.com> NNTP-Posting-Host: b7b6b875.news.execpc.com X-Trace: DXC=8W8b AT ZCh?ha=>N\5^GS8_hh4`>8YbCYbkmn_g AT WNcf8Bi=CX3hleRV`nN==IYeDU4>l X-Complaints-To: abuse AT execpc DOT com To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com "Alex Oleynikov" wrote: >For that matter I will use a 128K NVRAM chip, which is mapped into a UMB >memory space through a 32K frame. The data I have to store there is >organized as a set of structures. >Now I have a problem - how can I neatly access that data from my program? As >far as I understand, there is no way to tell the linker to use the physical >address for relocation of the data structures, since it is below the 1MB >limit. I have investigated different possibilities of accessing that data >( through _farX functions, or using "Fat DS" trick ), but they all >effectively limit my ability to use trivial "dot-style" variable access >within the structures. How about this: #include /* printf() */ #include /* __djgpp_conventional_base, __djgpp_nearptr_enable() */ #include /* crtNNN */ typedef unsigned char u8; typedef unsigned short u16; typedef unsigned long u32; struct nvram_struct { volatile u8 byte __attribute__((packed)); volatile u16 word __attribute__((packed)); volatile u32 dword __attribute__((packed)); }; /***************************************************************************** *****************************************************************************/ int main(void) { struct nvram_struct *foo; if(!(_crt0_startup_flags & _CRT0_FLAG_NEARPTR)) { if(!__djgpp_nearptr_enable()) { printf("Could not enable nearptr access\n"); return 1; } } /* the NVRAM is at linear address 000D0000 (real-mode address D000:0000) */ foo = (struct nvram_struct *)(0xD0000 + __djgpp_conventional_base); /* write the 8-bit value */ foo->byte = 0; /* read values */ printf("byte = 0x%X\n", foo->byte); printf("word = 0x%X\n", foo->word); printf("dword = 0x%lX\n", foo->dword); return 0; } -- geezer@ | pmode tutorial, homebrew OS: execpc.com | http://www.execpc.com/~geezer/os