home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / alt / msdos / programm / 2700 < prev    next >
Encoding:
Internet Message Format  |  1992-11-10  |  9.4 KB

  1. Path: sparky!uunet!snorkelwacker.mit.edu!ai-lab!zurich.ai.mit.edu!pshuang
  2. From: pshuang@zurich.ai.mit.edu (Ping Huang)
  3. Newsgroups: alt.msdos.programmer
  4. Subject: Re: QEMM/386
  5. Date: 10 Nov 92 09:16:00
  6. Organization: M.I.T. Artificial Intelligence Lab.
  7. Lines: 149
  8. Message-ID: <PSHUANG.92Nov10091600@rolex.ai.mit.edu>
  9. References: <4141@bcstec.ca.boeing.com>
  10. NNTP-Posting-Host: rolex.ai.mit.edu
  11. In-reply-to: silverm@bcstec.ca.boeing.com's message of 9 Nov 92 05:44:05 GMT
  12.  
  13. In article <4141@bcstec.ca.boeing.com> silverm@bcstec.ca.boeing.com (Jeff Silverman) writes:
  14.  
  15.  > What does QEMM/386 do, from a programmers point of view?
  16.  
  17. From a VMS perspective, or from the perspective of a programmer used to
  18. UNIX or OS's with flat virtual memory, QEMM/386 doesn't do very much for
  19. you directly. What QEMM/386 does is to act as a EMS, XMS, VCPI, and DPMI
  20. server. What does this mean? Jump to a couple of paragraphs below. But
  21. first, keep in mind that from the 80386 processor and up, Intel's CPU's
  22. support multiple views of memory which can be confusing. In real mode,
  23. the chips emulate the 8086 which cannot address more than one megabyte
  24. of memory. Addresses are generated as a 16-bit segment and a 16-bit
  25. offset, which are combined by shifting the former 4 bits to the left and
  26. adding, to create a 20-bit physical address. This is a pain for compiler
  27. writers and assembly programers because segments are 64Kb in size and
  28. you often need to use different sizes of pointers (16-bit near pointers
  29. and 16:16-bit far pointers). (Note that this description more or less
  30. still applies in V86 mode, which these chips have in order to be able to
  31. emulate an 8086 while still running a real operating system in protected
  32. mode, except that the 20-bit address formed is a linear and not physical
  33. address -- the next paragraph explains the difference.)
  34.  
  35. In protected mode (note I omit specific discussion of the 80286 here),
  36. the chips deal with memory in a slightly more complicated way. Instead
  37. of 16-bit segment values which translate directly to the physical
  38. address, you load 16-bit segment selectors into the segment registers.
  39. You can then use offsets up to 32 bits in size (each selector has
  40. information associated with it in a table, indicating the 32-bit linear
  41. address which the segment starts at, whether the contents are data or
  42. code and how large the segment is to allow memory protection, and other
  43. information), so a pointer is 16:32 bits, or 48 bits (making the virtual
  44. address space of the chips some pretty large number:
  45. 281,474,976,710,656). However, commonly code which takes advantage of
  46. the 80386 simply set the segment registers to selectors which point to a
  47. common place in linear memory, set the limits to the full 4Gb, and
  48. thereafter never twiddle the selectors again, thereby implementing a
  49. flat memory address space with 32-bit "pointers".  In addition to this
  50. segmentation organization, the chips are capable of paging. Once the
  51. chips resolve a memory reference from a 16:32 pointer to a 32-bit linear
  52. address, they go through page translation (standard 4Kb page size) to
  53. the 32-bit physical address, e.g. actually goes out on the memory bus.
  54.  
  55. OK, back to QEMM/386:
  56.  
  57. (a) EMS and XMS: QEMM/386 takes charge of as much of the conventional
  58.     and extended memory as you direct (defaults to all). It takes charge
  59.     of conventional memory so that if you run Desqview, it will be able
  60.     to page different collections of memory pages into the conventional
  61.     memory space so that DOS programs can be multitasked. QEMM/386
  62.     allows programs which understand how to make use of expanded (EMS)
  63.     or extended (XMS) memory to do so, with the advantage that it will
  64.     freely interconvert between the two as necessary because it acts as
  65.     the EMS and XMS servers. For example, if you have 7 megabytes of
  66.     memory free, you can sequentially run program A, which uses six
  67.     megabytes of expanded memory, and then program B, which uses six
  68.     megabytes of extended memory, without having to tell QEMM/386 to
  69.     shift memory from the EMS pool to the XMS pool: it is automatic.
  70.  
  71. (b) VCPI and DPMI: in the late 1980's, a number of software applications
  72.     were starting to take advantage of the protected mode features of
  73.     the 386+ chips (which include more than just changing the memory
  74.     model). However, these programs would get into each others way by
  75.     clobbering each other's data because there was no protocol to manage
  76.     the chip's resources. VCPI (Virtual Control Program Interface) was
  77.     created by Quarterdeck in conjunction with a number of other
  78.     companies who were writing system-level software (386 DOS extenders,
  79.     multitaskers like Desqview) or applications so big that they needed
  80.     to use protected mode to fit to allow multiple programs which used
  81.     the 80386 to co-exist. VCPI is simple and mostly allows programs not
  82.     to get into each other's way. DPMI (DOS Protected Mode Interface)
  83.     was created by Microsoft, Intel, and a committee of other companies.
  84.     A program which is compatible with DPMI calls the DPMI server
  85.     software to access the special features of the 386+ chips. I believe
  86.     only one of the most recent revisions of QEMM allows it to act as a
  87.     DPMI server. Windows 3.x is the best known and commonest DPMI server.
  88.  
  89.  > How is this possible?  If something, say, a TSR, is moved out of low
  90.  > memory and into either High Memory (By high memory, I mean the region
  91.  > between 640K and 1 Mbyte) or extended memory, how does it keep working?
  92.  
  93. TSR's and device drivers which are loaded in high memory or the HMA (an
  94. area of memory slightly less than 64Kb which isn't in the first megabyte
  95. of memory but which can be accessed by opcodes executing in real or V86
  96. mode due to an artifact of creating the 20-bit address: if you take the
  97. segment value to be 0xFFFF, you can access 65536-16 bytes of memory past
  98. the first megabyte because adding offsets greater than 16 when using
  99. registers which are 32-bits yields an address with the twenty-first bit
  100. turned on, two) don't really notice anything different than if they were
  101. loaded normally. Yes, they have been relocated in the first megabyte
  102. address space, but the normal DOS .COM, .SYS, and .EXE formats are
  103. designed so that they can be loaded anywhere in that first megabyte.
  104.  
  105. If you are really asking how programs like Desqview which can multitask
  106. DOS programs can work, Desqview at every task switch remaps the sets of
  107. memory pages which contains the applications being multitasked into the
  108. first megabyte of linear address space, either by calling on QEMM/386 or
  109. alternatively by calling on any EMS 4.0 servers loaded which has the
  110. hardware to remap memory pages.
  111.  
  112.  > How does QuarterDeck's OPTIMIZE program work?  Please don't say it works
  113.  > well, I KNOW it works well, I've been playing with it, I can see that it
  114.  > works, but don't know what it's doing or how it does it.
  115.  
  116. OPTIMIZE tries to figure out how much memory all the TSR's and device
  117. drivers you use on your machine takes up, and which ones would fit into
  118. high (640-1024Kb) memory and the HMA. Note that various memory managers
  119. have come up with tricks to make more high memory available, most of
  120. which plays tricks with mapping memory pages into the linear space that
  121. would otherwise be taken up by ROM-BIOS code that isn't being used any
  122. more in the operation of the computer.
  123.  
  124.  > Why does DOS have a 640Kbyte limit?  Why would anybody ever want to use
  125.  > expanded RAM if extended RAM is available?  If I have a "C" program
  126.  > which runs properly under VMS, but needs, say, 3 Mbytes of RAM to store
  127.  > all its data structures, what is the best way to run it under DOS?
  128.  > Under Windows?
  129.  
  130. IBM made a reasonable decision back in 1981 to reserve some of the
  131. one-megabyte address space of 8088/8086 chip for future use and
  132. expansion purposes. The correct limit to complain about isn't the 640Kb
  133. limit, it's the one megabyte limit imposed by the 8088/8086 CPU, and it
  134. is unfortunate that so much effort and software has been written to try
  135. to wring the last tiny bit out of the 384Kb difference between 640Kb and
  136. 1024Kb when the horizons could be so much larger.
  137.  
  138. If you have to write programs which needs lots of memory space, want
  139. excellent performance and don't need to worry about whether your
  140. customers will be able to run your programs (e.g. your code won't be
  141. redistributed or is an in-house application), your best bet is to look
  142. at the 32-bit C compilers that support going past DOS and 8088/8086
  143. limitations -- you get much better compatibility with code which makes
  144. evil assumptions like sizeof(int)==sizeof(pointer) and that of course it
  145. is OK to do a malloc(1048576). There are a couple of commercial C
  146. compilers for DOS which support use with a 386 DOS extender, but there
  147. are also freely distributable ports of the GNU gcc/g++ compiler for DOS
  148. (DJGPP) and for OS/2 2.0 (actually two slightly different ports). The
  149. reason that a number of commercial applications support using expanded
  150. or extended memory rather than using a DOS extender, even though it
  151. takes more effort to write such code, is that expanded memory can be
  152. added to *ANY* PC-compatible, including 8088/8086 machines, and extended
  153. memory can be added to 80286 machines. Therefore, by writing to these
  154. lower denominators, the applications will work passably on a larger
  155. number of machines than if you were to limit their use to 386+ CPU's.
  156.  
  157. --
  158. | Ping Huang (INTERNET: pshuang@martigny.ai.mit.edu) speaking for himself.
  159. | "One Thing to name them all, One Thing to define them,
  160. |  One Thing to place them in environments and bind them..."
  161.  
  162.