Path: utzoo!utgpu!watmath!clyde!att!rutgers!apple!vsi1!wyse!mips!prls!philabs!micomvax!ray From: ray@micomvax.UUCP (Ray Dunn) Newsgroups: comp.sys.ibm.pc Subject: Re: extended vs. expanded Message-ID: <1446@micomvax.UUCP> Date: 6 Dec 88 00:26:53 GMT References: <1717I78BC@CUNYVM> <1090@esunix.UUCP> <1970@hoqax.UUCP> <404@unicom.UUCP> Reply-To: ray@micomvax.UUCP (Ray Dunn) Organization: Philips Electronics Ltd. (TDS - Montreal) St. Laurent QC, Canada Lines: 207 There has been a lot of half truths and plain nonsense posted on this subject amongst the pearls of wisdom, so I post the following which I had previously sent privately, and to which I have made a couple of additions. Excuse the length. 'n' now if you know all there is to know on this subject. It is the truth. Honest. It is also in TFM!!!! Extended memory is memory directly in the CPU memory address space, above the 1 megabyte address. It is "extended" because the 8088 can only access 1 meg. Thus "extended memory" is part of the "extended memory addressing" of the 286 & 386 processors. Expanded memory is paged memory which can be addressed through a Page Frame within the first 1 megabyte. Expanded memory can be provided in a number of ways (see below). The mnemonic is easy, it is in the meaning of the words: Extended is longer. Expanded is fatter. When you buy a 80286 or 386 based machine which has more than 640K of RAM, that extra memory must be mapped somewhere, because *normally*, in the architecture of the PC, the area between 640K and 1M is used for video RAM, option card ROM and RAM, and the BIOS ROM. Some machines map the 384K from this hole on top of any *other* memory above 1M. I.e. if the machine has 1M memory, the 384K is mapped at 1M. If the machine has 2M memory, the 384K is mapped at 2M etc. Some machines just map the memory away out of trouble at say 16 or 24Meg. Some machines use all or part of it to "shadow" the system BIOS, and sometimes a proprietary Video BIOS. Thus during system initialization, these BIOSes are copied into the fast (16-bit or 32-bit) RAM, write-protected, and the BIOS from then on executes from there. This obviously requires motherboard hardware support. Some machines allow all or part of the extended memory to be used as expanded memory. This is achieved either by hardware support or software emulation as described below. *Some* machines allow all sorts of permutations of the above! This is an area where manufacturers of clones can *add value*. Extended Memory: --------------- As *MSDOS* can only address the first 1 Megabyte of the address space, extended memory on a 286 or 386 has limited use with DOS. It is most commonly used as a RAM disk, because this involves only *block* access to the memory and is a nicely self-contained application, but it could also be used for cacheing or directly by an application or to implement some Expanded Memory scheme (EMS). An 80286 has a 24 bit address space, i.e. 16 megabytes (1 meg plus 15 meg of extended memory). An 80386 has a full 32 bit address space (work it out yourself!). Most AT architecture implementations using an 80386 use a private memory address bus which limits the addressing to 16 or 24 or 32 Megabytes. Extended memory not widely used in the MSDOS environment other than by RAM disk programs, disk caches, and expanded memory emulations, for several reasons: - It is not available on 8088 machines so *applications* stay away from using it directly. - It is not a standard resource, so there is no proper management of it for co-existing software. - It is very slow and a pain in the neck to access because MSDOS runs the 80286 in native mode (i.e. as an 8088). To access above 1 meg the 80286 must be switched into protected mode. This is fine, but there is no way to switch it back to native mode!! So, the trick used is to get the keyboard controller to RESET the CPU, and the BIOS reset code recognizes this and continues! Thus it is really only good for some sort of *block* access to the memory, and there is an INT15 function in the BIOS which does this for you. All of this can be done more easily on an 80386, using its virtual 86 mode, but there are other problems running DOS in this mode (you have to trap I/O etc) and I wont go into that here. There are also the usual "how does the DMA interact with logical addressing" type problems. The good news is that Unix and OS/2 make *full* use of extended memory, as they run the machine in protected mode. Exercise for the reader: It *is* possible to access the first 64K of extended memory *without* going into protected mode. How? Expanded Memory: --------------- There have been several standards for expanded memory. Currently this is settling down into the LIM 4.0 standard (_L_otus _I_ntel _M_icrosoft in agreement). LIM 4.0 describes the following architecture: PC MAIN MEMORY LIM EXPANDED MEMORY -------------- ------------------- +-------------+ | | . Extended . . Memory . . up to . . 16M on the . . 80286 or . . 4096M on . . the 80386 . | | ---- +-------------+ 32M 1M +-------------+ ---- | | | | ---- | | 960K +-------------+ --- | Expanded | | Page Frame | | Memory | | 12*16K | | | | Physical | | Divided | | Pages | | into | 768K +-------------+ - | logical | | | - . pages . 640K +-------------+ - . . | 24*16K | - . | Physical | - | | | Pages | - | | | | - | | | | - | | 256K +-------------+ - | | | | - | | | | - | | | | - | | 0 +-------------+ - | | -- +-------------+ 0 Assuming you are familiar with the PC memory map (if not, read the tech reference manuals quick quick), as you can see, the expanded memory gives you up to 32M to map into up to 36 16K pages in the positions shown above. The page frame below 640K which allows the existing RAM to be shadowed are usually regarded as being for the use of operating systems/environments. The page frame above 640K, in the "PROM" area, is for applications. Code can be run or data stored interchangably in any of these frames. 30 functions are defined using int 67H, to allocate, map, swap etc these pages. These are provided, depending on the implementation, as a loadable driver, an extension to the motherboard BIOS, or on a PROM on a LIM 4.0 option card. The number of pages available in the page frame depends on the implementaion, and how much of the address space is already occupied by option card ROMS (and perhaps RAM's) in the machine. LIM 4.0 can be implemented in many ways: - as an option card with memory and page registers etc as I/O hardware to provide the mapping etc, and an on-board BIOS PROM to provide the functionality. - as a pure software emulation in a .sys or TSR driver: - using extended memory and virtual 86 mode on an 80386 so that the memory is mapped using the MMU into any of the physical LIM pages. I currently run a 6Meg 80386 based machine that gives me this capability. - *copying* into the RAM pages existing below 640K, either from extended memory (if other than 8088), or from, say, disk. This is much slower as pages are swapped using copying rather than just updating page registers. - using extended memory and mapping and page register logic built into the motherboard ASICs or logic on an 80286 or 80386 machine. We (Philips) make several PC's based on this approach. - combinations of the above etc. LIM 4.0 management is handled by its BIOS only in so far as the application can ask it what pages are free, how much memory is free to map etc. The actual use of this paging is left up to the application. DOS does not depand page or anything remotely like that, or support an application's use of LIM in any way. Two or more co-existing applications can share the LIM quite happily if they are well behaved (i.e. use LIM *only* through the BIOS calls). Functionality is provided to allow the saving and restoring of the page registers etc, so that even interrupt routines can safely be written to use LIM memory, assuming they allocate all their requirements up front. DOS 4.0 *does* recognize LIM 4.0's presence, and allows buffers and fastopen file names etc to be allocated in LIM pages. In no way is LIM *integrated* into the operating system though. The "Lotus/Intel/Microsoft Expanded Memory Specification Version 4.0" (published by, you guessed it, Lotus, Intel and Microsoft), is the definitive manual. -- Ray Dunn. | UUCP: ..!philabs!micomvax!ray Philips Electronics Ltd. | TEL : (514) 744-8200 Ext: 2347 600 Dr Frederik Philips Blvd | FAX : (514) 744-6455 St Laurent. Quebec. H4M 2S9 | TLX : 05-824090