[comp.sys.ibm.pc.programmer] Some MS-DOS configuration questions

iwarner@axion.bt.co.uk (Ivan Warner) (03/21/90)

	My knowledge of MS-DOS is sparse, so I would like some of the gaps
filled in by your good selves. I am seeking information on the
configuration of MS-DOS, and its limitations.

1) MS-DOS has a limit of 640K memory, but can access extended memory in
a non standard(??) way.

	Q1. Why the 640K limit, when the 8086 can address 1Mb, I believe.
	Q2. Do memory resident programs have to reside in this address space,
or can they be in extended mem?
	Q3. Can an application be run ENTIRELY from extended memory?
	Q4. How is access achieved to the extended memory?

2) How is the location of TSR progs decided - how do several co-exist in
harmony? (in my experience, not very well :-( )

3) I/O addresses of add-on hardware boards: Is there an area of the
memory map set aside for these, and if so where?


	Thanks in advance

	Ivan Warner
	BT Research Labs
	Ipswich
	UK

cs4g6ag@maccs.dcss.mcmaster.ca (Stephen M. Dunn) (03/22/90)

In article <1990Mar20.171709.16368@axion.bt.co.uk> iwarner@axion.bt.co.uk (Ivan Warner) writes:
$1) MS-DOS has a limit of 640K memory, but can access extended memory in
$a non standard(??) way.
$	Q1. Why the 640K limit, when the 8086 can address 1Mb, I believe.

   This isn't a restriction on most versions of MS-DOS.  Rather, it's a
design decision IBM made - all the space above the first 640K is allocated
for other things (for example, the next 128K are allocated for video
cards, then you have space for ROM extensions and I/O cards needing memory
buffers, then you have the ROM BIOS itself).  Most versions of MS-DOS
will happily allow you to use more than 640K of memory as long as it's
contiguous - but then you can't have an advanced display card because
you're using its memory area for main RAM.

$	Q2. Do memory resident programs have to reside in this address space,
$or can they be in extended mem?

   Extended memory can only be accessed by a program running in protected
mode.  Protected mode and real mode (or the 8086 emulation mode - not to be
confused with virtual 8086 mode on a 386) programs are not compatible, so
unless the program was written specifically to run on a 286 or higher in
protected mode, the answer is no.

   The 386, however, includes memory mapping hardware which allows any
area of memory to appear to be anywhere else in the address space, so
it is possible to cleverly map memory to different places so that
chunks of what would normally be extended memory appear in the computer's
first 1M of memory.

$	Q3. Can an application be run ENTIRELY from extended memory?

   Once again, only if it's designed to do this.

$	Q4. How is access achieved to the extended memory?

   It's very icky.  You have to kick the processor into protected mode,
do what you need to do, and then reset the processor, since Intel never
foresaw the need for switching back into real mode from protected mode.
Writing programs to do this is _not_ recommended unless you really know
what you're doing.

   If all you need to do is to move the contents of a chunk of memory
between conventional and extended memory, there is a BIOS call (I forget
which one - you can look it up in Norton) that will handle all of the
icky stuff for you.

$2) How is the location of TSR progs decided - how do several co-exist in
$harmony? (in my experience, not very well :-( )

   TSRs are loaded just like anything else.  Normally, this means in the
lowest area of memory which is large enough to hold them, although in
more recent versions of DOS it is possible to change the strategy DOS
uses to allocate memory.

   As for how they co-exist in harmony ... well, if none of them did
anything potentially nasty (such as capturing interrupts or taking over
direct control of the hardware), there would be no problems.  But if
they want to do anything useful, they have to do at least some potentially
nasty stuff (for example, in order to make your program pop up when someone
presses a given key sequence, you have to capture the keyboard
interrupt).  When two of them try to do similar things, there is a
possibility of conflict.

$3) I/O addresses of add-on hardware boards: Is there an area of the
$memory map set aside for these, and if so where?

   The 8086 family has a separate I/O address space, which can not be
accessed using the normal memory access instructions.  There is a 64K
byte I/O address space which is accessed through special input and
output instructions.

   However, some I/O boards require a buffer to appear in main memory
(for example, a network interface card needs a buffer in main memory
which it can fill and software can then use).  These are usually put
somewhere in the area above video cards but below the BIOS ROM.  Most
boards which require memory in this area have several DIP switches on
them so that you can set their exact address; if they didn't, chances
are that if you added three or four boards, you'd have two of them
wanting the same memory address.  (Note that on microchannel systems,
a setup program is used to select where in the memory and I/O spaces
various cards go, instead of using DIP switches).
-- 
Stephen M. Dunn                               cs4g6ag@maccs.dcss.mcmaster.ca
          <std_disclaimer.h> = "\nI'm only an undergraduate!!!\n";
****************************************************************************
    "So sorry, I never meant to break your heart ... but you broke mine."