China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-20 10:21
中国DOS联盟论坛 » DOS学习入门 & 精彩文章 (教学室) » Original: DOS Memory Basics DigestI View 16,888 Replies 37
Original Poster Posted 2003-11-28 00:00 ·  中国 广东 佛山 三水区 电信
元老会员
★★★★
Credits 5,170
Posts 1,637
Joined 2002-10-16 00:00
23-year member
UID 8
Gender Male
From 广东佛山
Status Offline
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.
Recent Ratings for This Post ( 3 in total) Click for details
RaterScoreTime
xue1995 +1 2010-04-07 14:07
ytfy +2 2010-09-24 00:00
sl543001 +8 2010-11-23 11:55
我的网志
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
Floor 2 Posted 2003-12-02 00:00 ·  中国 山东 德州 联通
初级用户
Credits 114
Posts 3
Joined 2003-11-28 00:00
22-year member
UID 13496
Gender Male
Status Offline
Nice
Floor 3 Posted 2003-12-02 00:00 ·  中国 北京 朝阳区 联通
银牌会员
★★★
颓废青年
Credits 2,265
Posts 721
Joined 2003-05-12 00:00
23-year member
UID 2032
Gender Male
Status Offline
Great! It clarified many concepts!
Floor 4 Posted 2003-12-02 00:00 ·  中国 广东 珠海 教育网
初级用户
★★
DOS爱好者
Credits 478
Posts 100
Joined 2003-04-22 00:00
23-year member
UID 1648
Gender Male
Status Offline
Good article
Thanks

|||||||  寻人启示:姓名:
| c●● ~年龄:20,性别:男
|  ♂▃~ 特征:帅.很帅.酷.特别酷....
| |︺英俊潇洒.风流倜傥,玉树临风→我

单钓E时代论坛
Floor 5 Posted 2003-12-04 00:00 ·  中国 山东 滨州 联通
高级用户
★★
Credits 948
Posts 271
Joined 2002-12-13 00:00
23-year member
UID 502
Gender Male
From sd
Status Offline
Awesome, expert!!
Floor 6 Posted 2003-12-04 00:00 ·  中国 广东 广州 海珠区 电信
初级用户
Credits 130
Posts 6
Joined 2003-10-05 00:00
22-year member
UID 10729
Gender Male
Status Offline
Thanks, friend

Actually the third picture above has an error; the 1068K-> inside should be 1088K
Floor 7 Posted 2003-12-04 00:00 ·  中国 广东 佛山 三水区 电信
元老会员
★★★★
Credits 5,170
Posts 1,637
Joined 2002-10-16 00:00
23-year member
UID 8
Gender Male
From 广东佛山
Status Offline
Yes, I found it later too. Thanks sizzling
我的网志
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
Floor 8 Posted 2003-12-08 00:00 ·  中国 北京 科技网
银牌会员
★★★
颓废青年
Credits 2,265
Posts 721
Joined 2003-05-12 00:00
23-year member
UID 2032
Gender Male
Status Offline

I have fixed it.
Floor 9 Posted 2003-12-08 00:00 ·  中国 北京 科技网
银牌会员
★★★
颓废青年
Credits 2,265
Posts 721
Joined 2003-05-12 00:00
23-year member
UID 2032
Gender Male
Status Offline

Hehe
Floor 10 Posted 2006-10-03 04:47 ·  中国 广东 东莞 电信
新手上路
Credits 2
Posts 1
Joined 2006-09-06 21:09
19-year member
UID 61978
Gender Male
Status Offline
Bump
Floor 11 Posted 2006-10-03 06:20 ·  中国 广东 广州 教育网
铂金会员
★★★★
C++启程者
Credits 5,154
Posts 1,827
Joined 2003-07-18 00:00
22-year member
UID 7105
Gender Male
Status Offline
DOS memory is actually just a tangled mess!
A patched-up hundred-piece robe

[ Last edited by GOTOmsdos on 2006-10-8 at 01:15 ]
Floor 12 Posted 2006-10-03 08:54 ·  中国 四川 成都 电信
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
This summary is pretty classic, ^_^~

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 13 Posted 2006-10-07 23:45 ·  中国 广东 东莞 电信
中级用户
★★
Credits 282
Posts 130
Joined 2006-09-20 22:25
19-year member
UID 63201
From 广东
Status Offline
555
Too long...
I'll save it first...
Read it later...
Thanks OP...
Floor 14 Posted 2006-10-08 01:14 ·  中国 广东 广州 教育网
铂金会员
★★★★
C++启程者
Credits 5,154
Posts 1,827
Joined 2003-07-18 00:00
22-year member
UID 7105
Gender Male
Status Offline
"Because WINDOWS95 and later versions can use all the memory without any human intervention, no matter how large it is."

WIN32 with a DOS kernel (95, 98, me) should have a 4GB limit for managing memory, right? (DOS's dpmi seems to as well, I think)

[ Last edited by GOTOmsdos on 2006-10-8 at 01:19 ]
Floor 15 Posted 2006-10-08 04:31 ·  中国 广东 深圳 电信
新手上路
Credits 4
Posts 2
Joined 2006-10-07 02:00
19-year member
UID 64756
Gender Male
Status Offline
Benefited from it!!!
Forum Jump: