home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 September / Simtel20_Sept92.cdr / msdos / info / ext_ram.arc / EXT-RAM.TXT
Encoding:
Text File  |  1989-05-18  |  13.9 KB  |  311 lines

  1. This article appeared on USENET
  2.  
  3. Subject: Re: Extended Memory
  4. From:  (Raymond Dunn @ Philips Electronics Ltd. -  St. Laurent  P.Q., Canada)
  5.  
  6.  
  7.  
  8. Memory up to 1 Megabyte:
  9. -----------------------
  10.  
  11. MSDOS is designed around the 8088 CPU which can address up to 1 megabyte of
  12. memory.
  13.  
  14. In "industry standard" IBM PC architecture, this memory is organized in the
  15. following way:
  16.  
  17.  
  18.       1M +-------------+ FFFFF
  19.          |             |          System BIOS ROM
  20.          |             |
  21.          |             |
  22.          |             |
  23.     960K +-------------+ F0000
  24.          |             |           Option ROM and RAM
  25.          |             |
  26.          |             |
  27.     816K +-------------+ CC000
  28.          |             |           XT Hard Disk Controller BIOS ROM
  29.     800K +-------------+ C8000
  30.          |             |           Video BIOS ROM and option ROM and RAM
  31.          |             |
  32.     768K +-------------+ C0000
  33.          |             |           Video RAM space - various video types
  34.          |             |           have different requirements and starting
  35.          |             |           locations.
  36.          |             |
  37.     640K +-------------+ A0000
  38.          |             |
  39.          |             |
  40.  
  41.          |             |           Base system RAM
  42.          |             |
  43.          |             |
  44.     1286 +-------------+ 506
  45.          |             |           Interrupt vectors and BIOS data area
  46.        0 +-------------+ 0
  47.  
  48. MSDOS expects this architecture, and assumes that the RAM up to 640K is
  49. its resource to manage.
  50.  
  51. Although MSDOS will not expect to find any RAM above 640K except video RAM,
  52. even though there actually may be some which it could use, e.g.  unused on a
  53. video card, on a special option card etc, it *will* however use any memory
  54. immediately above 640K if the BIOS specifies it is available.  This is
  55. communicated to MSDOS at boot time by BIOS setting the memory size in location
  56. 413H of the BIOS data area.
  57.  
  58. As an example of this, the Philips P3345 386SX based machine allows the system
  59. to be configured so that 64K is allocated at 640K to give a total of 704K of
  60. "base" system RAM.  This is *only* legal if an EGA/VGA video card is not
  61. present, as this has video RAM at this address.
  62.  
  63.  
  64. Some option cards provide RAM at other locations in the map.  Applications
  65. programs may use that RAM in a proprietary way.  It is not normally considered
  66. a DOS resource.
  67.  
  68. An example of this is the Philips P3105 XT system.  It is more convenient on
  69. this machine to provide 768K of RAM using all 256K chips rather than be
  70. involved with 64K chips to provide 640K.  This "extra" 128K of RAM can be
  71. enabled if required at D0000.  A ramdisk driver is provided to use this
  72. memory.
  73.  
  74.  
  75. Extended and Expanded Memory:
  76. ----------------------------
  77.  
  78. Extended memory is an intrinsic part of the architecture of the Intel
  79. processor family, expanded memory is only defined in the architecture of the
  80. IBM-PC standard.
  81.  
  82. *Extended* memory is memory directly in the CPU memory address space, above
  83. the 1 megabyte address.
  84.  
  85. It is "extended" because the 8088 can only access 1 meg.  Thus "extended
  86.  
  87. memory" is part of the "extended memory addressing" of the 80286 & 80386
  88. processors.
  89.  
  90. *Expanded* memory is paged memory which can be addressed through a Page Frame
  91. within the first 1 megabyte, and is thus accessible on all processors, even the
  92. 8088.  Expanded memory can be provided in a number of ways (see below).
  93.  
  94. The mnemonic is easy, it is in the meaning of the words:
  95.  
  96. -> -> ->        Extended is longer.        <- <- <-
  97.  
  98. -> -> ->        Expanded is fatter.        <- <- <-
  99.  
  100. When you buy an 80286, 80386 or 80386SX based machine which has more than 640K
  101. of RAM, that extra memory must be mapped somewhere, because *normally*, in the
  102. architecture of the PC, the area between 640K and 1M is used for video RAM,
  103. option card ROM and RAM, and the BIOS ROM.
  104.  
  105. Some machines map the 384K from this hole on top of any *other* extended
  106. memory above 1M.  I.e. if the machine has 1M memory, the 384K is mapped at
  107. 1M.  If the machine has 2M memory, the 384K is mapped at 2M etc.
  108.  
  109.  
  110. Some machines just map the memory away out of trouble at say 16 or 24Meg.
  111.  
  112. Some machines use all or part of it to "shadow" the system BIOS, and
  113. sometimes a proprietary Video BIOS.  Thus during system initialization, these
  114. BIOSes are copied from ROM into the fast (16-bit or 32-bit) RAM,
  115. write-protected, and the BIOS from then on executes from there.  This
  116. obviously requires motherboard hardware support.
  117.  
  118. Some machines allow all or part of the extended memory to be used as
  119. expanded memory.  This is achieved either by hardware support or software
  120. emulation as described below.
  121.  
  122. *Some* machines allow all sorts of permutations of the above!  This is an
  123. area where manufacturers of clones can *add value*.
  124.  
  125.  
  126.  
  127. Extended Memory:
  128. ---------------
  129.  
  130. As *MSDOS* assumes an 8088 and can thus only address the first 1 Megabyte of
  131. the address space, extended memory on a 286 or 386 has limited use with DOS.
  132.  
  133.  
  134.  
  135. It is most commonly used as a RAM disk, because this involves only *block*
  136. access to the memory and is a nicely self-contained application, but it
  137. could also be used for caching, directly by an application, or to implement
  138. some *Expanded* Memory Scheme (EMS).
  139.  
  140. An 80286 has a 24 bit address space, i.e. 16 megabytes (1 meg plus 15 meg of
  141. extended memory).
  142.  
  143. An 80386 has a full 32 bit address space (work it out yourself!).  Most AT
  144. architecture implementations using an 80386 use a private memory address bus
  145. which limits the addressing to 16 or 24 or 32 Megabytes.
  146.  
  147. Extended memory is not generally used in the MSDOS environment other than by
  148. RAM disk programs, disk caches, and expanded memory emulations, for several
  149. reasons:
  150.  
  151. - It is not available on 8088 machines so *applications* which wish to be
  152. compatible across the whole product line stay away from using it directly.
  153.  
  154. - It is not a standard resource, so there is no proper management of it for
  155. co-existing software (but see MSDOS 4.0 below).
  156.  
  157.  
  158.  
  159. - It is very slow and a pain in the neck to access because MSDOS runs the
  160. 80286 in native mode (i.e.  as an 8088).  To access above 1 meg the 80286 must
  161. be switched into protected mode.  This is fine, but there is no way to switch
  162. it back to native mode (this is one of the reasons that the 80286 is regarded
  163. as a brain-dead processor)!!  So, the trick used is to get the keyboard
  164. controller to RESET the CPU, and the BIOS reset code recognizes this and
  165. continues!  Thus it is really only good for some sort of *block* access to the
  166. memory, and there is an INT15 function in the BIOS which does this for you.
  167. All of this can be done more easily on an 80386, using its virtual 86 mode,
  168. but there are other problems running DOS in this mode (you have to trap I/O
  169. etc) and I wont go into that here.  There are also the usual "how does the DMA
  170. interact with logical addressing" type problems.
  171.  
  172. The good news is that Unix and OS/2 make *full* use of extended memory, as
  173. they run the machine in protected mode.
  174.  
  175. With release 4.0, MSDOS recognizes extended memory for the first time as
  176. more than just a RAM disk resource.  In addition to RAMDRIVE.SYS and a disk
  177. caching program, SMARTDRV.SYS, a device driver, HIMEM.SYS, is provided to
  178. manage the extended memory according to XMS 2.0 specification.
  179.  
  180.  
  181. XMS is an eXtended Memory Specification standard defined jointly by
  182. Microsoft, Intel, Lotus and AST (not to be confused with LIM, see below).
  183. This specification is available from them.  XMS 2.0 allows extended memory
  184. to be used by co-resident software, and, for example, allows TSR's to be
  185. positioned in extended memory.  
  186.  
  187. Very few applications are currently written to make use of this standard -
  188. it is somewhat ironic that the provided RAM disk and disk caching routines
  189. RAMDRIVE.SYS and SMARTDRV.SYS do *not* use the XMS management routines when
  190. using extended memory, but *do* use LIM 4.0 when using expanded memory (see
  191. below)!
  192.  
  193. XMS 2.0 also formally makes the first 64K of extended memory available as a
  194. non protected mode memory resource using the overflow into A20 trick.
  195.  
  196.  
  197. Expanded Memory:
  198. ---------------
  199.  
  200. There have been several standards for expanded memory.  Currently this has
  201. settled down into the LIM 4.0 standard (_L_otus _I_ntel _M_icrosoft in
  202. agreement).
  203.  
  204.  
  205.  
  206. LIM 4.0 describes the following architecture:
  207.  
  208.          PC MAIN MEMORY                LIM EXPANDED MEMORY
  209.          --------------                -------------------
  210.  
  211.          +-------------+
  212.          |             |
  213.          . Extended    .
  214.          . Memory      .
  215.          . up to       .               /+-------------+ 32M
  216.          . 16M on the  .             // |             |
  217.          . '286,       .           / /  |             |
  218.          . 4096M on    .         /  /   |  Expanded   |
  219.          . the '386    .       /   /    |  Memory     |
  220.          |             |     /    /     |             |
  221.       1M +-------------+   /     /      |  Divided    |
  222.          |             | /      /       |  into 16K   |
  223.     960K +-------------+       /        |  logical    |
  224.          | Page Frame  |      /         |  pages      |
  225.          | 12*16K      |     /          |             |
  226.          | Physical    |    /           |             |
  227.  
  228.          | Pages       |   /            |             |
  229.     768K +-------------+\ /             .             .
  230.          |             | /              .             .
  231.     640K +-------------+/ \             .             .
  232.          | Page Frame  |   \            .             .
  233.          | 24*16K      |    \           |             |
  234.          | Physical    |     \          |             |
  235.          | Pages       |      \         |             |
  236.          |             |       \        |             |
  237.     256K +-------------+        \       |             |
  238.          |             | \       \      |             |
  239.          |             |   \      \     |             |
  240.          |             |     \     \    |             |
  241.        0 +-------------+       \    \   |             |
  242.                                  \   \  |             |
  243.                                    \  \ |             |
  244.                                      \ \|             |
  245.                                        \+-------------+  0
  246.  
  247. The expanded memory gives you up to 32M to map into up to 36 16K pages in
  248. the positions shown above.
  249.  
  250.  
  251. The page frame below 640K which allows the existing RAM to be shadowed are
  252. usually regarded as being for the use of operating systems/environments.
  253. The page frame above 640K, in the video RAM and "PROM" area, is for
  254. applications.  Code can be run or data stored interchangably in any of these
  255. frames.
  256.  
  257. 30 functions are defined using int 67H, to allocate, map, swap etc these
  258. pages.  These are provided, depending on the implementation, as a loadable
  259. driver (usually), an extension to the motherboard BIOS, or on a PROM on a LIM
  260. 4.0 option card (not usual).
  261.  
  262. The number of actual pages available in the page frame depends on the
  263. implementaion, and how much of the address space is already occupied by
  264. option card ROMS (and perhaps RAM's) in the machine.
  265.  
  266. Applications which use LIM 4.0 can thus have a very large physical memory
  267. available to them, but must access it by manually switching pages as
  268. required (come back Z80 systems, all is forgiven!!)
  269.  
  270. LIM 4.0 can be implemented in many ways:
  271.  
  272. - as an option card with memory and page registers etc as I/O hardware to
  273.  
  274. provide the mapping etc, and an on-board BIOS PROM to provide the
  275. functionality.
  276.  
  277. - as a pure software emulation in a .SYS or TSR driver:
  278.  
  279.   - using extended memory and virtual 86 mode on an 80386 so that the
  280.     memory is mapped using the MMU into any of the physical LIM pages.
  281.  
  282.   - *copying* into the RAM pages existing below 640K, either from extended
  283.     memory (if other than 8088), or from, say, disk.  This is much slower as
  284.     pages are swapped using copying rather than just updating page registers.
  285.  
  286. - using extended memory and mapping and page register logic built into the
  287. motherboard ASICs or logic on an 80286 or 80386 machine.  Philips has two
  288. machines using this approach, the 80386SX based P3345 using the NEAT chipset,
  289. and the 80286 based P2230 using the G2 chipset.
  290.  
  291. - combinations of the above etc.
  292.  
  293. LIM 4.0 management is handled by its BIOS only in so far as the application
  294. can ask it what pages are free, how much memory is free to map etc., and to
  295. perform the actual mapping.  The actual use of this paging is left up to the
  296.  
  297. application.  Neither LIM 4.0 nor DOS demand pages or anything remotely like
  298. that, nor do they support an application's use of LIM in any other way.  Two
  299. or more co-existing applications can share the LIM quite happily if they are
  300. well behaved (i.e.  use LIM *only* through the BIOS calls).
  301.  
  302. Functionality is provided to allow the saving and restoring of the page
  303. registers etc, so that even interrupt routines can safely be written to use
  304. LIM memory, assuming they allocate all their requirements up front.
  305.  
  306. Whether or not LIM memory will be useful to you is *application* dependant.
  307. Check to see if the applications you propose to use can take advantage of
  308. it.
  309.  
  310. Release 4.0x of MSDOS *does* recognize LIM 4.0's presence, and allows buffers
  311. and fastopen file names etc to be allocated in LIM pages, and DEBUG now
  312. "understands" LIM.  In no way is LIM *integrated* into the operating system
  313. though.  A driver, EMM386.SYS, is provided in DOS 4.0 to emulate LIM 4.0 using
  314. the *extended* memory of a 386 based machine.
  315.  
  316. The RAM disk and disk caching routines RAMDRIVE.SYS and SMARTDRV.SYS can be
  317. configured to use extended memory, *or* expanded memory under the control of
  318. LIM 4.0.
  319.  
  320.  
  321.  
  322. The "Lotus/Intel/Microsoft Expanded Memory Specification Version 4.0"
  323. (published by, you guessed it, Lotus, Intel and Microsoft), is the
  324. definitive manual, and is available from them.
  325.  
  326. -- 
  327. Ray Dunn. 
  328. Philips Electronics Ltd.     | TEL : (514) 744-8200  Ext: 2347
  329.