From: robk AT cyberway DOT com DOT sg (Rob Kramer) Newsgroups: comp.os.msdos.djgpp Subject: Re: DJGPP and Mapping physical memory from a PCI device Date: Tue, 13 Jun 2000 10:48:04 +0800 Message-ID: References: <39417171_1 AT news DOT siscom DOT net> Organization: Infologic Pte Ltd X-Newsreader: Anawave Gravity v2.00 NNTP-Posting-Host: 203.116.150.10 Lines: 82 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com In article <39417171_1 AT news DOT siscom DOT net>, cfought AT siscom DOT net says... > I work for an engineering firm and we have a shared memory product that > requires that we be able to map physical memory from a PCI device so that it > can be accessed by user applications. I was wondering if anyone could tell > me of a location of some sample programs that demostrate memory mapping with > DJGPP DPMI calls....Thanks for any help in advance......... This is a Quick Hack (but it works), so don't comment on the coding style please! Cheers, RoB bool mapMemory (ulong PhysicalAddr, ulong SizeOfRegion, int *Selector, ulong *LinearAddress) { __dpmi_meminfo info; info.address = PhysicalAddr; info.size = SizeOfRegion; /* Map physical device to linear memory (dpmi 0x800). */ if (__dpmi_physical_address_mapping (&info) == -1) return false; ulong laddress = info.address; /* Allocate a LDT descriptor (dpmi 0x0000). */ int selector = __dpmi_allocate_ldt_descriptors (1); if (selector == -1) return false; /* Set segment base address in descriptor (dpmi 0x0007). */ if (__dpmi_set_segment_base_address (selector, laddress) == -1) { __dpmi_free_ldt_descriptor (selector); return false; } /* Set segment limit in descriptor (dpmi 0x0008). */ if (__dpmi_set_segment_limit (selector, SizeOfRegion - 1) == -1) { __dpmi_free_ldt_descriptor (selector); return false; } info.address = laddress; info.size = SizeOfRegion; /* Lock segment (dpmi 0x0600). */ if (__dpmi_lock_linear_region (&info) == -1) { __dpmi_free_ldt_descriptor (selector); return false; } *LinearAddress = laddress; *Selector = selector; return true; } bool unmapMemory (ulong SizeOfRegion, int selector, ulong LinearAddress) { __dpmi_meminfo info; /* DPMI info block */ info.address = LinearAddress; info.size = SizeOfRegion; /* Unlock segment (dpmi 0x601). */ if (__dpmi_unlock_linear_region (&info) == -1) return false; /* Free LDT descriptor (dpmi 0x0001). */ if (__dpmi_free_ldt_descriptor (selector) == -1) return false; /* Free mapped region? (DPMI 1.0 function 0x0801) */ return true; }