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-24 05:10
中国DOS联盟论坛 » DOS学习入门 & 精彩文章 (教学室) » Thoroughly Understanding Memory Concepts Repost DigestI View 4,198 Replies 13
Original Poster Posted 2007-05-27 17:47 ·  中国 黑龙江 哈尔滨 电信
初级用户
Credits 38
Posts 10
Joined 2006-11-11 12:18
19-year member
UID 70225
Gender Male
Status Offline
I’ve been wandering around the forum these past few days, wanting to study DOS in depth, but I ran into some problems. I searched in the forum for a long time and still didn’t find a comprehensive and detailed post, so I’ll repost one here!

People who often use DOS all know about emm386.exe and himem.sys, which often appear in config.sys. And then there are expanded memory, extended memory, upper memory, the high memory area, protected mode, real mode, and so on—enough to give you a headache, right? No problem; as long as you read this post carefully to the end, you are sure to gain something from it.

  Physical memory refers to actual, concrete memory chips that exist. For example, the memory modules plugged into the motherboard, the ROM chip loaded with the system BIOS, the display RAM chip on the display card and the ROM chip loaded with the display BIOS, as well as RAM chips and ROM chips on various adapter cards, are all physical memory.
  The memory address space refers to the range in which memory is coded (coded addresses). So-called coding means assigning a number to every physical memory unit (one byte), usually called “addressing.” The purpose of assigning a number to a memory unit is to make it easy to find it and complete data reading and writing; this is what is called “addressing” (therefore, some people also call address space addressing space).
  The size of the address space and the size of the physical memory are not necessarily equal. Here is an example to explain this issue: suppose one floor has 17 rooms in total, numbered 801~817. These 17 rooms are physical, while its address space uses three-digit coding, with a range of 800~899, for a total of 100 addresses. Clearly the address space is larger than the actual number of rooms.
  For microcomputers of the 386 class and above, the address bus is 32 bits, so the address space can reach 232, namely 4GB. But in reality the physical memory we configure is usually only 1MB, 2MB, 4MB, 8MB, 16MB, 32MB, etc., far smaller than the range allowed by the address space. From the figure below we can see the relationship between address space and physical memory.
  
  All right, now we can explain why different memory types such as conventional memory, reserved memory, upper memory, high memory, expanded memory, and extended memory arise.

  Various memory concepts

  What needs to be made clear here is that the concepts of different kinds of memory we are discussing are based on the addressing space.
  The CPU used in the first PC introduced by IBM was the 8088 chip. It had only 20 address lines, which is to say its address space was 1MB.
  The designers of the PC used the lower 640KB of the 1MB as RAM, for DOS and application programs to use, while the upper 384KB was reserved for system use such as ROM and video adapter cards. From then on, this boundary was fixed and has been used to this day. The lower 640KB is called conventional memory, that is, the PC’s basic RAM area; see Figure 1. In reserved memory, the lower 128KB is the display buffer area, the upper 64KB is the system BIOS (Basic Input/Output System) space, and the remaining 192KB space is left for use. Looking at the corresponding physical memory, the basic memory area uses only 512KB of chips, occupying the 512KB of addresses from 0000 to 80000. Although the display memory area has 128KB of space, for a monochrome display (MDA card) only 4KB is enough, so only 4KB of physical memory chips are installed, occupying the 4KB of space from B0000 to B10000. If using a color display (CGA card), 16KB of physical memory must be installed, occupying the 16KB of space from B8000 to BC000. It can be seen that the address range actually used is smaller than the address space allowed for use.
  At the time (late 1980 to early 1981), such a “large” capacity of memory seemed already sufficient for PC users. But as programs kept growing, images and sound kept becoming richer, and new CPUs capable of accessing larger memory spaces appeared one after another, the limitations of the original PC and MS-DOS design became more and more obvious.

  1. What is expanded memory?
  How EMS works
  By 1984, not long after the 286 was widely accepted, people increasingly realized that the 640KB limit had become an obstacle for large programs. At this time, Intel and Lotus, two outstanding representatives of hardware and software, joined forces to formulate a scheme combining hardware and software. This method made it possible for all PCs to access RAM above 640KB. Microsoft had just introduced Windows not long before, and its requirements for memory space were also very high, so it also joined in promptly.
  In early 1985, Lotus, Intel, and Microsoft jointly defined LIM-EMS, that is, the Expanded Memory Specification. EMS is usually called expanded memory. At that time, to use EMS, you needed a memory expansion card installed in an I/O slot and an expanded memory manager called EMS. But the I/O slot’s address lines had only 24 bits (ISA bus), which could not adapt to 32-bit machines of the 386 class and above. Therefore, memory expansion cards are rarely used now. Expanded memory in today’s microcomputers is usually implemented by software, such as EMM386 in DOS, which emulates or expands extended memory for use as expanded memory. Therefore, the difference between expanded memory and extended memory does not lie in the location of their physical memory, but in what method is used to read and write it. This will be introduced further below.
  As mentioned earlier, expanded memory can also be emulated and converted from extended memory. The principle of EMS is different from XMS; it uses a page frame method. A page frame designates a 64KB space within the 1MB space (usually within the reserved memory area, but its physical memory comes from extended memory), divided into 4 pages, each 16KB. EMS memory is also paged in 16KB units, and the contents of 4 pages can be exchanged each time. In this way, all EMS memory can be accessed. Figure 2 gives the working principle of EMS. There are many drivers conforming to EMS; commonly used ones include EMM386.EXE, QEMM, TurboEMS, 386MAX, etc. EMM386.EXE is provided in both DOS and Windows.

  2. What is extended memory?
  We know that the 286 has 24 address lines and can address a 16MB address space, while the 386 has 32 address lines and can address a space as high as 4GB. For distinction, we call the address space above 1MB extended memory XMS (eXtend memory).
  In microcomputers of the 386 class and above, there are two memory working modes. One is called real-address mode or real mode, and the other is called protected mode. In real mode, physical addresses still use 20 bits, so the maximum addressing space is 1MB, in order to be compatible with the 8086. Protected mode uses 32-bit physical addresses, and the addressing range can reach 4GB. The DOS system works in real mode, and the memory space it manages is still 1MB, so it cannot directly use extended memory. For this reason, Lotus, Intel, AST, and Microsoft established a standard for using extended memory under MS-DOS, namely the Extended Memory Specification XMS. The Himem.sys we often see in the Config.sys file is the driver that manages extended memory.
  The extended memory management specification appeared later than the expanded memory management specification.

  3. What is the high memory area?
  In real mode, the address of a memory unit can be written as:
       segment address: offset within segment
  It is usually written in hexadecimal as XXXX:XXXX. The actual physical address is formed by shifting the segment address left 4 bits and then adding the offset within the segment. If every bit of the address is 1, it is FFFF:FFFF. Its actual physical address is: FFF0+FFFF=10FFEF, about 1088KB (minus 16 bytes), which has already exceeded the 1MB range and entered extended memory. This area that enters extended memory is about 64KB, the first 64KB of space above 1MB. We call it the high memory area HMA (High Memory Area). The physical memory of the HMA is obtained from extended memory. Therefore, to use HMA, physical extended memory must exist. In addition, the establishment and use of HMA also require support from the XMS driver HIMEM.SYS, so HMA can only be used after HIMEM.SYS has been loaded.

  4. What is upper memory?
  To explain the concept of upper memory, we still have to go back and look at the reserved memory area. The reserved memory area refers to the 640KB~1024KB (384KB total) area. When the PC was born, this part of the area was clearly reserved for system use, and user programs could not get involved. But this space was not fully used, so everyone wanted to find a way to use the remaining part and carve out a block of address space (note: address space, not physical memory) for use. Thus another memory area, UMB, was obtained.
  UMB (Upper Memory Blocks) is called upper memory or upper memory blocks. It is produced by squeezing into the remaining unused space in reserved memory. Its physical memory is still taken from physical extended memory, and its management driver is an EMS driver.

  5. What is SHADOW memory?
  Careful readers may also discover a problem: for machines with 1MB or more physical memory installed, how is the physical memory in the 640KB~1024KB portion used? Since this part of the address space has already been allocated for system use, it cannot be used again repeatedly. In order to make use of this part of physical memory, some 386 systems provide a relocation function, namely relocating the addresses of this part of physical memory to 1024KB~1408KB. In this way, this part of physical memory becomes extended memory and of course can be used. But this relocation function is no longer used in today’s high-end machines; instead, this part of physical memory is reserved as Shadow memory. The address space that Shadow memory can occupy is the same as the corresponding ROM. Shadow is composed of RAM, and its speed is much higher than ROM. When the contents in ROM (various BIOS programs) are loaded into Shadow RAM at the same addresses, BIOS can be accessed from RAM instead of having to access ROM. This will greatly improve system performance. Therefore, when setting CMOS parameters, the corresponding Shadow areas should be set to allow use (Enabled).

  Summary

  Through the above analysis, the division of internal memory can be summarized as follows:
  ●Basic memory Occupies the 0~640KB address space.
  ●Reserved memory Occupies the 640KB~1024KB address space. Allocated to the display buffer memory, ROM on various adapter cards, and the system ROM BIOS; the remaining space can be used as upper memory UMB. The physical memory of UMB is taken from physical extended memory. Physical RAM in this range can be used as Shadow RAM.
  ●Upper memory (UMB) Established using the unallocated address space in reserved memory; its physical memory is obtained from physical extended memory. UMB is managed by EMS, and its size can be set by the EMS driver.
  ●High memory (HMA) The first 64KB area in extended memory (1024KB~1088KB). Established and managed by HIMEM.SYS.
  ●XMS memory An extended memory area managed in compliance with the XMS specification. Its driver is HIMEM.SYS.
  ●EMS memory An expanded memory area managed in compliance with the EMS specification. Its driver is EMM386.EXE, etc.
Floor 2 Posted 2007-05-28 19:16 ·  中国 山东 济南 移动
钻石会员
★★★★★
Credits 10,046
Posts 3,039
Joined 2002-11-11 00:00
23-year member
UID 223
Gender Male
Status Offline
Right now I just want to expand my memory to 3000000K.
简单就是美
Floor 3 Posted 2007-05-28 22:39 ·  中国 陕西 西安 电信
新手上路
Credits 13
Posts 7
Joined 2007-05-27 13:48
19-year member
UID 89466
Gender Male
Status Offline
I’ve learned something
To the poster above, memory has been too cheap lately, expanding to 3000000K isn’t a problem ^_^
Floor 4 Posted 2007-05-29 18:58 ·  中国 山东 济南 移动
钻石会员
★★★★★
Credits 10,046
Posts 3,039
Joined 2002-11-11 00:00
23-year member
UID 223
Gender Male
Status Offline
Yeah, it’s gotten cheap.
简单就是美
Floor 5 Posted 2007-06-01 21:05 ·  中国 安徽 合肥 电信
初级用户
Credits 32
Posts 14
Joined 2005-09-11 12:07
20-year member
UID 42424
Gender Male
From ah
Status Offline
But DDR is still staying high, so sad……
Floor 6 Posted 2007-06-02 11:11 ·  中国 江西 九江 柴桑区 电信
新手上路
Credits 11
Posts 6
Joined 2006-10-20 01:09
19-year member
UID 67081
Status Offline
Came in to learn, gained some knowledge, thanks!
Floor 7 Posted 2007-06-02 19:32 ·  中国 浙江 台州 电信
管理员
★★★★
DOS非常爱好者
Credits 6,215
Posts 2,601
Joined 2006-01-20 13:00
20-year member
UID 49256
Status Offline
I heard it has already hit bottom, and may rise soon, so hurry up and buy:)
Floor 8 Posted 2007-06-08 10:57 ·  中国 北京 航天一院
初级用户
Credits 24
Posts 11
Joined 2007-05-04 09:52
19-year member
UID 87422
Gender Male
From beijing
Status Offline
Very detailed... bump
Floor 9 Posted 2007-06-09 10:25 ·  中国 广西 百色 电信
初级用户
Credits 78
Posts 23
Joined 2007-02-27 01:59
19-year member
UID 80264
Gender Female
Status Offline
Make a copy of it.
Floor 10 Posted 2007-06-09 23:52 ·  中国 广东 深圳 电信
中级用户
★★
部落守望者
Credits 351
Posts 140
Joined 2006-06-19 17:11
20-year member
UID 57261
Gender Male
Status Offline
Originally posted by tiancai4126 at 2007-5-27 17:47:
Upper memory (UMB) Established using the unallocated address space in reserved memory; its physical memory is obtained from physical extended memory. UMB is managed by EMS


Since it says “UMB is obtained from extended memory,” then it should be managed by the Extended Memory Specification XMS (himem.sys). Why does it also say at the same time that UMB is managed by EMS? Isn’t this a contradiction? Could the friends above explain it, thanks!
一切从底层开始
Floor 11 Posted 2007-06-18 14:43 ·  中国 浙江 杭州 电信
新手上路
Credits 8
Posts 4
Joined 2007-06-18 14:01
19-year member
UID 91700
Gender Male
Status Offline
Thank you for your memory concepts
Floor 12 Posted 2007-11-28 13:16 ·  中国 浙江 宁波 电信
新手上路
Credits 2
Posts 1
Joined 2007-11-28 12:47
18-year member
UID 104039
Gender Male
Status Offline
Thanks, very well said
Floor 13 Posted 2007-11-28 14:46 ·  中国 上海 电信
新手上路
Credits 10
Posts 5
Joined 2007-11-27 11:08
18-year member
UID 103919
Gender Male
Status Offline
Good post, learned from it so I’ll bump it
Floor 14 Posted 2007-11-29 13:38 ·  中国 广东 佛山 电信
新手上路
Credits 7
Posts 4
Joined 2007-11-29 13:13
18-year member
UID 104148
Gender Male
Status Offline
Good post, thanks
Forum Jump: