DOS Memory Basics
For people who have always used WINDOWS98 or XP, knowing that they have 128M or 256M of memory is enough. Because WINDOWS95 and later versions can use all the memory without any human intervention, no matter how large it is. However, in DOS, configuring memory is a field of knowledge, and it requires a certain understanding of DOS's memory structure. Below, we will first introduce the basic knowledge of DOS memory together with the development of the PC.
4.2.1 DOS's 640K Memory Problem
Perhaps you have heard others say that DOS can only use 640K of memory. This is both right and not entirely right. The 640K memory problem was a major problem that once limited the development of DOS; like the Year 2000 problem, it was caused by people in the early days of computer development failing to foresee its later rapid development.
This starts in 1980. At that time IBM decided to enter the personal computer market, and it chose INTEL's 16-bit 8086/8088 chip as the CPU for the PC. The 8086/8088 had 20 address lines and could read and write 1M (that is, 1024K) of memory. When Microsoft and IBM designed the DOS operating system, they decided to divide this 1024K of memory into two parts: 640K was left for the DOS system and DOS programs to use, and the remaining 384K was reserved for other purposes<>, such as display RAM, motherboard BIOS, and so on. This 640K of memory was also called conventional memory or base memory. Early DOS and DOS programs could only operate within this range; this is what later became known as the 640K memory limit.
At the time, however, this was a very forward-looking design, because the competitor the PC was aimed at then—the APPLE II machine using Motorola's 8-bit 6502 chip as its CPU (the most advanced personal computer before the IBM PC was born)—could only support 64K of memory. So Bill Gates said at the time: "640K of memory will definitely be enough forever."
However, when the PC became popular around the world and more and more software and hardware joined the PC camp, 640K of memory began to become stretched. First, the DOS system itself had to take up more than 50K of memory, then there were the drivers for various devices (drivers for peripherals such as the mouse, sound card, CD-ROM drive, game controller, as well as DOS's own ANSI.SYS and virtual disk driver RAMDIRVE, etc.), and other TSR (memory-resident) programs such as various anti-virus monitoring software. Not only did all these programs compete for the 640K memory space, they also "refused to leave." The space left for other DOS applications was greatly reduced.
On the other hand, software under DOS became more and more powerful and larger and larger, and therefore needed more and more memory. For example, the famous spreadsheet software LOTUS 1-2-3 required at least 256K of memory as soon as it was released; for a Chinese character support system, 256K of memory was only enough to put in the 16-dot display fonts; the famous domestic word-processing software WPS itself also required at least 180K of memory; the database software FOXBASE required around 400K of memory, and WINDOWS goes without saying. The forward-looking design that the PC architecture was once proud of quickly became a huge obstacle.

4.2.2 Expanded Memory EMS (Expanded Memory Specification) or LIM Memory
In 1986, the most popular software on the PC—spreadsheet LOTUS 1-2-3—released its new version 2.0, and it soon sold hundreds of thousands of copies. However, on many users' PCs (286 machines were not yet common at the time, 386 had just come out, and most machines were still PCs using 8088 CPUs), it actually could not obtain enough memory to run. LOTUS, at its wits' end, had no choice but to ask INTEL for help, and later MicroSoft also joined in. Together they formulated a plan to add memory to PCs, resulting in the LIM specification, that is, a plan jointly customized by LOTUS, INTEL, and MicroSoft. The final version was LIM 4.0. Its product was an expanded memory controller board with its own memory chips, inserted into the PC's expansion slot. Through it, a PC could be provided with up to 32M of paged expanded memory, abbreviated as expanded memory (EMS).
How could the 8086/8088, which could only access 1M of memory, suddenly get an extra 32M of memory? Of course, the CPU cannot directly access EMS memory, and programs using EMS do not know where this memory actually is. They only know that there are some "pages" in the system that can store information. Didn't the 8086/8088 have access to 1024K of memory? In that 384K reserved space there was still some free space, and the expanded memory controller board used 64K of free memory in the 384K reserved memory. This 64K of memory was divided into 4 pages, each 16K. This part of the pages was called the "page frame." EMS memory was also divided into 16K pages, with the total number reaching 2000. A program using EMS is allowed to access at most 4 pages at the same time. When the program wants to access a certain page, the memory controller board copies the contents of the corresponding EMS page into the page frame for the program to read and write. After reading and writing, it copies the contents of the page in the page frame back to the corresponding EMS memory page, then copies the contents of another EMS page into the page frame for the program to read and write. So LIM memory is called "paged expanded memory"<>. This is a bit like Raise the Red Lantern: every day the housekeeper hangs the red lantern at one doorway, and when the master sees which doorway the red lantern is hanging at, he goes into that room to sleep. The role of the frame page is equivalent to that red lantern. Perhaps you think doing this would be very troublesome, and it certainly is troublesome, but it is still better than not having it.
4.2.3 Extended Memory XMS (Extended Memory Specification)
INTEL's later product 80286 was still a 16-bit chip, but its address lines increased to 24 bits, allowing it to access 16M of memory. Its memory above 1M was called extended memory (XMS). In order to be compatible with earlier DOS programs, the 80286 had two operating modes: one was real mode, in which the 286 worked just like the 8086/8088 and could only use 1M of memory; at this time DOS programs ran inside a "faster" 8086. The other was protected mode, in which the 80286 could use up to 16M of memory. Unfortunately, in protected mode, DOS programs that needed real mode could no longer run.
Later, the 80386 was a 32-bit chip, and its address lines increased to 32 bits, allowing it to access 4G of memory. Unlike the 286, when the 803386 runs in protected mode, it also provides a virtual 86 (V86) mode, providing functionality equivalent to an 8086. DOS programs that need real mode would still find themselves running inside an "8086" CPU at this time. This also made multitasking in DOS possible. Therefore MS-DOS5.0 and later versions simply ran in the 386's protected mode; new DOS programs such as FOXPRO also worked in protected mode, while the V86 mode provided by the 80386 supported earlier DOS programs that needed real mode.
Starting from MS-DOS5.0, we got a HIMEM.SYS to manage XMS memory in a unified way.
4.2.4 High Memory Area HMA (High memory area)
People were pleasantly surprised to find that when the 21st address line (a20) of the 286 and later CPUs was enabled, the first 64K segment immediately following the first 1024K of memory could also be directly accessed by real-mode DOS programs (through the 20th address line a19), that is, real-mode DOS programs could access up to 1088K of memory. It is just that this 64K of memory cannot be split up and can only be exclusively occupied by one DOS program, so it is generally used to store the resident memory portion of DOS's command interpreter COMMAND.COM (specified in config.sys through the dos=high command). Thus this 64K of memory was separated from the original XMS and called the high memory area (HMA)<>. After putting COMMAND.COM into HMA, the conventional memory occupied by DOS can be reduced by more than 50K.

4.2.5 Upper Memory Blocks UMB (Upper Memory Blocks) and Reserved Memory
Didn't we say earlier that 384K of reserved memory was allocated in the early days of DOS? In fact, this part of memory was basically never truly occupied. The motherboard BIOS uses its own storage chips, and the graphics card also has its own video memory... However, in order to be compatible with past DOS programs, the system still has to map in part of the BIOS and video memory, etc., and this part of the space cannot be used by other DOS programs. But even so, almost half of the entire reserved memory still has free space. For real-mode DOS programs, this was the last piece of virgin land that could be developed.
However, although the 8086 and 286 theoretically also have reserved memory areas, in practice only 386 or higher computers can support UMB.
MS-DOS5.0 provided an Emm386.exe, which can collect the free space in reserved memory to form UMB, and provides the devicehigh command in config.sys to load drivers such as CD-ROM and sound-card drivers into UMB. It also provides the loadhigh(LH) command at the command line to load TSR programs such as mouse drivers into UMB, thereby freeing more conventional memory. Now there are some newer DOS software tools such as SMARTDRV and UCDOS, CCDOS97 that can also automatically store themselves in UMB.
There is still other potential to dig out of the reserved area. For example, now everyone uses VGA, so the 16K of memory in the reserved area allocated to monochrome display (HGA) can now be completely taken out and added to UMB. EMM386.EXE provides an I(nclude) parameter, which can allocate a specified area of reserved memory into UMB. There is a section of code in the BIOS used for the computer self-test and loading DOS at startup. After the computer starts up, the space occupied by this part of the code can also be freed up.
4.2.6 Emulating EMS with XMS
Since the 80386 in protected mode can have vast XMS and can also run real-mode DOS programs, why not emulate part of XMS as EMS, so that DOS programs needing EMS can also get some benefit? Then users would not need to buy any expansion boards separately, would they?
This was indeed done. EMM386.EXE has a RAM parameter. It sets aside 64K of free memory in reserved memory to become the page frame, then puts all EMS "pages" into XMS. In this way, DOS programs needing EMS can obtain EMS, and for programs using EMS there is no difference from before. EMS emulated in XMS is even faster than real EMS. However, this is also the reason many people cannot distinguish the difference between XMS and EMS.
If the user really does not need EMS (after all, new DOS programs do not use EMS and have switched to XMS), the NOEMS parameter can be added when loading EMM386.EXE. In this way the system does not provide EMS, and therefore does not need a page frame, so an extra 64K of UMB can be used.
4.2.7 Memory Management Corresponding to WINDOWS
WINDOWS 1.x/2.x/3.x, generally speaking, supports three modes. Real mode corresponds to DOS's 8086 real mode; standard mode corresponds to the 286's 16-bit protected mode; enhanced mode corresponds to the 386's 32-bit protected mode. Among them, standard mode and enhanced mode require the support of HIMEM.SYS, that is, they support XMS.
WINDOWS95/98/ME all use the 386's 32-bit protected mode, but no longer require the user to specify loading HIMEM.SYS in CONFIG.SYS. They automatically load HIMEM.SYS at startup. WINME's system file IO.SYS even includes HIMEM.SYS inside it.
WINDOWSNT/2000/XP/2003 work in the 386's 32-bit protected mode, but they were developed on the basis of OS/2 and no longer use DOS as their supporting system, so the above memory modes do not apply to them.
For people who have always used WINDOWS98 or XP, knowing that they have 128M or 256M of memory is enough. Because WINDOWS95 and later versions can use all the memory without any human intervention, no matter how large it is. However, in DOS, configuring memory is a field of knowledge, and it requires a certain understanding of DOS's memory structure. Below, we will first introduce the basic knowledge of DOS memory together with the development of the PC.
4.2.1 DOS's 640K Memory Problem
Perhaps you have heard others say that DOS can only use 640K of memory. This is both right and not entirely right. The 640K memory problem was a major problem that once limited the development of DOS; like the Year 2000 problem, it was caused by people in the early days of computer development failing to foresee its later rapid development.
This starts in 1980. At that time IBM decided to enter the personal computer market, and it chose INTEL's 16-bit 8086/8088 chip as the CPU for the PC. The 8086/8088 had 20 address lines and could read and write 1M (that is, 1024K) of memory. When Microsoft and IBM designed the DOS operating system, they decided to divide this 1024K of memory into two parts: 640K was left for the DOS system and DOS programs to use, and the remaining 384K was reserved for other purposes<>, such as display RAM, motherboard BIOS, and so on. This 640K of memory was also called conventional memory or base memory. Early DOS and DOS programs could only operate within this range; this is what later became known as the 640K memory limit.
At the time, however, this was a very forward-looking design, because the competitor the PC was aimed at then—the APPLE II machine using Motorola's 8-bit 6502 chip as its CPU (the most advanced personal computer before the IBM PC was born)—could only support 64K of memory. So Bill Gates said at the time: "640K of memory will definitely be enough forever."
However, when the PC became popular around the world and more and more software and hardware joined the PC camp, 640K of memory began to become stretched. First, the DOS system itself had to take up more than 50K of memory, then there were the drivers for various devices (drivers for peripherals such as the mouse, sound card, CD-ROM drive, game controller, as well as DOS's own ANSI.SYS and virtual disk driver RAMDIRVE, etc.), and other TSR (memory-resident) programs such as various anti-virus monitoring software. Not only did all these programs compete for the 640K memory space, they also "refused to leave." The space left for other DOS applications was greatly reduced.
On the other hand, software under DOS became more and more powerful and larger and larger, and therefore needed more and more memory. For example, the famous spreadsheet software LOTUS 1-2-3 required at least 256K of memory as soon as it was released; for a Chinese character support system, 256K of memory was only enough to put in the 16-dot display fonts; the famous domestic word-processing software WPS itself also required at least 180K of memory; the database software FOXBASE required around 400K of memory, and WINDOWS goes without saying. The forward-looking design that the PC architecture was once proud of quickly became a huge obstacle.

4.2.2 Expanded Memory EMS (Expanded Memory Specification) or LIM Memory
In 1986, the most popular software on the PC—spreadsheet LOTUS 1-2-3—released its new version 2.0, and it soon sold hundreds of thousands of copies. However, on many users' PCs (286 machines were not yet common at the time, 386 had just come out, and most machines were still PCs using 8088 CPUs), it actually could not obtain enough memory to run. LOTUS, at its wits' end, had no choice but to ask INTEL for help, and later MicroSoft also joined in. Together they formulated a plan to add memory to PCs, resulting in the LIM specification, that is, a plan jointly customized by LOTUS, INTEL, and MicroSoft. The final version was LIM 4.0. Its product was an expanded memory controller board with its own memory chips, inserted into the PC's expansion slot. Through it, a PC could be provided with up to 32M of paged expanded memory, abbreviated as expanded memory (EMS).
How could the 8086/8088, which could only access 1M of memory, suddenly get an extra 32M of memory? Of course, the CPU cannot directly access EMS memory, and programs using EMS do not know where this memory actually is. They only know that there are some "pages" in the system that can store information. Didn't the 8086/8088 have access to 1024K of memory? In that 384K reserved space there was still some free space, and the expanded memory controller board used 64K of free memory in the 384K reserved memory. This 64K of memory was divided into 4 pages, each 16K. This part of the pages was called the "page frame." EMS memory was also divided into 16K pages, with the total number reaching 2000. A program using EMS is allowed to access at most 4 pages at the same time. When the program wants to access a certain page, the memory controller board copies the contents of the corresponding EMS page into the page frame for the program to read and write. After reading and writing, it copies the contents of the page in the page frame back to the corresponding EMS memory page, then copies the contents of another EMS page into the page frame for the program to read and write. So LIM memory is called "paged expanded memory"<>. This is a bit like Raise the Red Lantern: every day the housekeeper hangs the red lantern at one doorway, and when the master sees which doorway the red lantern is hanging at, he goes into that room to sleep. The role of the frame page is equivalent to that red lantern. Perhaps you think doing this would be very troublesome, and it certainly is troublesome, but it is still better than not having it.
4.2.3 Extended Memory XMS (Extended Memory Specification)
INTEL's later product 80286 was still a 16-bit chip, but its address lines increased to 24 bits, allowing it to access 16M of memory. Its memory above 1M was called extended memory (XMS). In order to be compatible with earlier DOS programs, the 80286 had two operating modes: one was real mode, in which the 286 worked just like the 8086/8088 and could only use 1M of memory; at this time DOS programs ran inside a "faster" 8086. The other was protected mode, in which the 80286 could use up to 16M of memory. Unfortunately, in protected mode, DOS programs that needed real mode could no longer run.
Later, the 80386 was a 32-bit chip, and its address lines increased to 32 bits, allowing it to access 4G of memory. Unlike the 286, when the 803386 runs in protected mode, it also provides a virtual 86 (V86) mode, providing functionality equivalent to an 8086. DOS programs that need real mode would still find themselves running inside an "8086" CPU at this time. This also made multitasking in DOS possible. Therefore MS-DOS5.0 and later versions simply ran in the 386's protected mode; new DOS programs such as FOXPRO also worked in protected mode, while the V86 mode provided by the 80386 supported earlier DOS programs that needed real mode.
Starting from MS-DOS5.0, we got a HIMEM.SYS to manage XMS memory in a unified way.
4.2.4 High Memory Area HMA (High memory area)
People were pleasantly surprised to find that when the 21st address line (a20) of the 286 and later CPUs was enabled, the first 64K segment immediately following the first 1024K of memory could also be directly accessed by real-mode DOS programs (through the 20th address line a19), that is, real-mode DOS programs could access up to 1088K of memory. It is just that this 64K of memory cannot be split up and can only be exclusively occupied by one DOS program, so it is generally used to store the resident memory portion of DOS's command interpreter COMMAND.COM (specified in config.sys through the dos=high command). Thus this 64K of memory was separated from the original XMS and called the high memory area (HMA)<>. After putting COMMAND.COM into HMA, the conventional memory occupied by DOS can be reduced by more than 50K.

4.2.5 Upper Memory Blocks UMB (Upper Memory Blocks) and Reserved Memory
Didn't we say earlier that 384K of reserved memory was allocated in the early days of DOS? In fact, this part of memory was basically never truly occupied. The motherboard BIOS uses its own storage chips, and the graphics card also has its own video memory... However, in order to be compatible with past DOS programs, the system still has to map in part of the BIOS and video memory, etc., and this part of the space cannot be used by other DOS programs. But even so, almost half of the entire reserved memory still has free space. For real-mode DOS programs, this was the last piece of virgin land that could be developed.
However, although the 8086 and 286 theoretically also have reserved memory areas, in practice only 386 or higher computers can support UMB.
MS-DOS5.0 provided an Emm386.exe, which can collect the free space in reserved memory to form UMB, and provides the devicehigh command in config.sys to load drivers such as CD-ROM and sound-card drivers into UMB. It also provides the loadhigh(LH) command at the command line to load TSR programs such as mouse drivers into UMB, thereby freeing more conventional memory. Now there are some newer DOS software tools such as SMARTDRV and UCDOS, CCDOS97 that can also automatically store themselves in UMB.
There is still other potential to dig out of the reserved area. For example, now everyone uses VGA, so the 16K of memory in the reserved area allocated to monochrome display (HGA) can now be completely taken out and added to UMB. EMM386.EXE provides an I(nclude) parameter, which can allocate a specified area of reserved memory into UMB. There is a section of code in the BIOS used for the computer self-test and loading DOS at startup. After the computer starts up, the space occupied by this part of the code can also be freed up.
4.2.6 Emulating EMS with XMS
Since the 80386 in protected mode can have vast XMS and can also run real-mode DOS programs, why not emulate part of XMS as EMS, so that DOS programs needing EMS can also get some benefit? Then users would not need to buy any expansion boards separately, would they?
This was indeed done. EMM386.EXE has a RAM parameter. It sets aside 64K of free memory in reserved memory to become the page frame, then puts all EMS "pages" into XMS. In this way, DOS programs needing EMS can obtain EMS, and for programs using EMS there is no difference from before. EMS emulated in XMS is even faster than real EMS. However, this is also the reason many people cannot distinguish the difference between XMS and EMS.
If the user really does not need EMS (after all, new DOS programs do not use EMS and have switched to XMS), the NOEMS parameter can be added when loading EMM386.EXE. In this way the system does not provide EMS, and therefore does not need a page frame, so an extra 64K of UMB can be used.
4.2.7 Memory Management Corresponding to WINDOWS
WINDOWS 1.x/2.x/3.x, generally speaking, supports three modes. Real mode corresponds to DOS's 8086 real mode; standard mode corresponds to the 286's 16-bit protected mode; enhanced mode corresponds to the 386's 32-bit protected mode. Among them, standard mode and enhanced mode require the support of HIMEM.SYS, that is, they support XMS.
WINDOWS95/98/ME all use the 386's 32-bit protected mode, but no longer require the user to specify loading HIMEM.SYS in CONFIG.SYS. They automatically load HIMEM.SYS at startup. WINME's system file IO.SYS even includes HIMEM.SYS inside it.
WINDOWSNT/2000/XP/2003 work in the 386's 32-bit protected mode, but they were developed on the basis of OS/2 and no longer use DOS as their supporting system, so the above memory modes do not apply to them.
Recent Ratings for This Post
( 3 in total)
Click for details
我的网志
http://hzmys.blog.163.com/
我的网盘
firststep.qjwm.com
fsmys.ys168.com
ssmys.ys168.com
www.brsbox.com/fsmys
www.brsbox.com/ssmys
www.brsbox.com/ccdos
http://hzmys.blog.163.com/
我的网盘
firststep.qjwm.com
fsmys.ys168.com
ssmys.ys168.com
www.brsbox.com/fsmys
www.brsbox.com/ssmys
www.brsbox.com/ccdos

DigestI





