[comp.os.msdos.programmer] memory

razor@matt.ksu.ksu.edu (03/30/91)

I have a question about memory and extended memories on a pc.  Here is my
question:

	Up to 640K memory, this is called BASE memory?

	From 640K to 1024K, this is called XMS?  What does XMS stand for?

	From 1024K on up is called EMS?  What does EMS stand for?

In addition, what device drivers does one need to use to access this 
memory using DOS?

THanks
razor@matt.ksu.ksu.edu

dj@bragi.ctron.com (DJ Delorie) (03/30/91)

In article <1991Mar29.163548.768@maverick.ksu.ksu.edu> razor@matt.ksu.ksu.edu writes:
>I have a question about memory and extended memories on a pc.  Here is my
>question:
>
>	Up to 640K memory, this is called BASE memory?
>
>	From 640K to 1024K, this is called XMS?  What does XMS stand for?
>
>	From 1024K on up is called EMS?  What does EMS stand for?

Here's a short tutorial on memory types (I had to give this speech a lot
in a previous job):

0K - 640K is called "conventional" memory.  It can be accessed by
any program.  This is the default arena for MSDOS programs.

640K - 1024K is called "high" memory, otherwise known as XT/AT
channel, device memory, and a variety of other meaningless names.
This memory can be accessed by any program, and there are utilities
(QEMM, 386MAX for 386's, plus a plethora of PD's) that can run
programs up there when there's memory present.

1024K - 1088K is usually also called "high" memory, but often
abbreviated as the HMA for High Memory Area.  This is accessible by
any program, but only on 286's and 386's, and only after you shut off
gate-A20.  Himem.sys normally manages this memory.

1024K-16M (or 4G on 386's) is called "extended" memory.  You must
enter protected mode to access this memory.

XMS stands for Extended Memory Specification.  It is a method by
which extended memory can be properly shared and re-used by many
programs.  Himem.sys, for example, provides an XMS interface for
extended memory.

EMS stands for the Expanded Memory Specification.  "Expanded" memory is
memory whose interface meets the EMS specification.  This type of
memory is selectively paged (from a pool of up to 16M) into the
640K-1024K range, or more recently into anywhere from 0K-1024K.  Any
program can access this memory.  EMS was used by PC & XT class
machines to break the 640K memory restriction.

LIM stands for Lotus-Microsoft-Intel, the controllers of EMS (although
we all know that public acceptance controls everything).  LIM 3.x
allows up to 64K of EMS at a time to be paged in.  LIM 4.x allows any
amount to be paged in.

Some programs & hardware enhancements allow a computer to use some or
all of its extended memory as expanded memory by controlling the
mapping of physical memory into the program's address space.

Some 286/386 terms:

"Real" memory is usually 0-1M.  This is what can be accessed from "real"
mode.

"Protected" memory is 1M-16M (4G on 386's), but really refers to 0-16M(4G),
as you can access everything from protected memory.

386's only:

"Physical" memory is what hardware sees as RAM.

"Linear" memory is what the application sees after the memory
references pass through the paging unit.  Also known as Virtual
memory.

resnicks@netcom.COM (Steve Resnick) (03/30/91)

In article <1991Mar29.163548.768@maverick.ksu.ksu.edu> razor@matt.ksu.ksu.edu writes:
>I have a question about memory and extended memories on a pc.  Here is my
>question:
>
>	Up to 640K memory, this is called BASE memory?
>
>	From 640K to 1024K, this is called XMS?  What does XMS stand for?
>
>	From 1024K on up is called EMS?  What does EMS stand for?
>
>In addition, what device drivers does one need to use to access this 
>memory using DOS?

	For memory below 640K it's called BASE memory.
	For memory between 640K-1M is called a kludge - that area is
	reserved for devices and ROM. If there is RAM there it's because
	a memory manager put it there.

	For memory between 1M and 1M+63K is XMS (eXtended Memory Specification)
	this requires a software driver.

	For 1024K on up it's called extended memory. EMS stands for
	Expanded Memory Specification. It's a sophisticated bank-switched
	memory scheme. And it's a BIG KLUDGE to make up for XT's which
	couldn't acces more than 1M of any kind of memory.

 Cheers!
Steve

-- 
-------------------------------------------------------------------------------
	resnicks@netcom.com, steve@camphq, IFNA:	1:143/105.0, 
USNail: 530 Lawrence Expressway, Suite 374 
        Sunnyvale, Ca 94086
- In real life: Steve Resnick. Flames, grammar and spelling errors >/dev/null
0x2b |~ 0x2b, THAT is the question.
The Asylum OS/2 BBS - (408)263-8017 12/2400,8,1 - Running Maximus CBCS 1.2
-------------------------------------------------------------------------------

252u3715@fergvax.unl.edu (Teik Leong Tan) (04/04/91)

dj@bragi.ctron.com (DJ Delorie) writes:

>.... 1024K - 1088K is usually also called "high" memory, but often
>abbreviated as the HMA for High Memory Area.  This is accessible by
>any program, but only on 286's and 386's, and only after you shut off
>gate-A20.  Himem.sys normally manages this memory.

I have seen gate-A20 being displayed on my screen before, but never
really knew what it is for. Does it mean that if A20 is disabled, then
the computer will have more access to its memory, and that this extra
memory would be available to DOS applications as expanded memory?

By the way does "high" memory refers to expanded memory only? Or does
"high" memory include both expanded and extended memory?

How can I enable or disable gate-A20?

From what I know, himem.sys only makes available 64K of high memory.
Does anyone out know of other software that would provide us with more
high memory than himem.sys, and which is relatively cheap, say free?

Many a time, my friends would come across "insufficient memory" errors
when they try to run some games. This is especially irritating when we
are in the middle of playing an exciting game.
My friend has a 25MHz 386 computer, with 4MB RAM, and 40MB hard drive.
The recommended memory needed to play the game is 590K. What I don't
understand is why is it that the computer system always restrict us only
to use the 640K conventional memory when we have a total of 4MB of
memory. So I thought "maybe the software didn't take advantage
of the available expanded/extended memory". Then I tried running the game
in the Windows 3.0 enhanced mode environment so that the computer will 
"know" that there exists these extra memory, but the game still terminates 
in the middle, giving error message "insufficient memory". So I thought
maybe the game itself has an error/bug in it, but that turns out to be
false. I tried uploading as little TSR programs as possible, thus
leaving more than 590K of conventional memory. And when I run the game,
I confront no interruptions at all -- I manage to finished the entire
game. My question here is "what are the possible causes for this
phenomena (insufficient memory) to happen?" Further explanations or
elaborations on the causes are very much appreciated.

Thank you,
Teik Leong Tan
252u3715@fergvax.unl.edu

dj@bragi.ctron.com (DJ Delorie) (04/04/91)

In article <252u3715.670712175@fergvax> 252u3715@fergvax.unl.edu (Teik Leong Tan) writes:

>I have seen gate-A20 being displayed on my screen before, but never
>really knew what it is for. Does it mean that if A20 is disabled, then
>the computer will have more access to its memory, and that this extra
>memory would be available to DOS applications as expanded memory?

Gate-A20 is a kludge put into the original AT to make it more backward
compatible with the XTs.  It turns out that some applications
*required* that the memory space wrap at the 1M boundary (examples:
CPM-86 and MS Flight Simulator 2.x).  When you enable gate-A20, the
_hardware_ shuts off address line #20, so that memory references in
odd numbered 1M regions (like 1M-2M) instead go to the even region
before it (like 0M-1M).

>By the way does "high" memory refers to expanded memory only? Or does
>"high" memory include both expanded and extended memory?

High memory does not refer to expanded memory, only a small range of
extended memory.  When you refer to, say, address FFFF:0000, you get
physical address FFFF0 (seg*16+ofs).  Thus, FFFF:0010 is physical
100000! FFFF:1000 is 100FF0, etc.

>How can I enable or disable gate-A20?

This is tricky at best.  The AT class method involves sending a stream
of commands to the keyboard controller (non-trivial).  The PS/2 has an
I/O port that toggles it (trivial).  Check out an AT hardware tech ref
manual for detailed information.

>From what I know, himem.sys only makes available 64K of high memory.
>Does anyone out know of other software that would provide us with more
>high memory than himem.sys, and which is relatively cheap, say free?

How about the BIOS itself?  Functions 0x87 (I think) of INT 15h allows
you to transfer blocks of data between conventional and extended
memory.

>Many a time, my friends would come across "insufficient memory" errors
>when they try to run some games. This is especially irritating when we
>are in the middle of playing an exciting game.

Lots of software are designed to be compatible with the XT.  They
can't take advantage of the AT's extra memory because the XY can't
to that.  Some can autodetect a 286 or 386 and do different things,
but most don't - it's cheaper to develop it that way.

Trimming drivers and TSRs out of config.sys and autoexec.bat is the
only globally accepted way of getting more memory.  Even if you run
under Windows, you might not get all of your memory back, as Windows
itself uses some of it to communicate with your process.

DJ
dj@ctron.com

ralf+@cs.cmu.edu (Ralf Brown) (04/06/91)

In article <1396@bragi.ctron.com> dj@bragi.ctron.com (DJ Delorie) writes:
}Gate-A20 is a kludge put into the original AT to make it more backward
}compatible with the XTs.  It turns out that some applications
}*required* that the memory space wrap at the 1M boundary (examples:
}CPM-86 and MS Flight Simulator 2.x).  When you enable gate-A20, the

Add *all* versions of MSDOS, at least when invoked via the CP/M compatibility
entry point at offset 5 in the PSP.  That entry does a FAR jump to absolute
1000C0h, which is expected to wrap to 000C0h.  That location contains
another FAR jump into the DOS kernal; DESQview is smart enough to make a copy
of that jump instruction beyond the 1M mark when it loads itself into the
HMA.

--
{backbone}!cs.cmu.edu!ralf  ARPA: RALF@CS.CMU.EDU   FIDO: Ralf Brown 1:129/3.1
BITnet: RALF%CS.CMU.EDU@CMUCCVMA   AT&Tnet: (412)268-3053 (school)   FAX: ask
DISCLAIMER?  Did  | It isn't what we don't know that gives us trouble, it's
I claim something?| what we know that ain't so.  --Will Rogers