Path: utzoo!attcan!uunet!steinmetz!zephyrus!dixon
From: dixon@zephyrus.steinmetz (Walter V. Dixon)
Newsgroups: comp.sys.ibm.pc
Subject: Re: help needed with memory organizatio
Message-ID: <11307@steinmetz.ge.com>
Date: 21 Jun 88 15:22:26 GMT
References: <39500012@pyr1.cs.ucl.ac.uk>
Sender: news@steinmetz.ge.com
Reply-To: dixon@zephyrus.UUCP (Walter V. Dixon)
Organization: General Electric CRD, Schenectady, NY
Lines: 40

Under DOS 3.0 and above,  one can obtain the listhead of the
memory control block chain using the undocumented int 21h ah=52h.
This function returns a pointer to a "list of lists".  The initial
paragraph of the first MCB is at es:[bx-2].  Each MCB has the
following structure:

typedef struct sMCB {
  BYTE		MCB_B_Signature;	/* Block signature */
  WORD		MCB_W_Owner;		/* PSP of owner */
  WORD		MCB_W_Size;		/* Size of MCB (paragraphs) */
  BYTE		MCB_T_Unused[11];	/* Not used by DOS */
  BYTE		MCB_T_Data[1];		/* Data begins here */
} MCB;

#define MCB_C_NotLastBlock	'M'
#define MCB_C_LastBlock		'Z'

All MCBs except the last have a signature of M;  the last has a
signature of Z.  One traverses this list by adding MCB_W_Size+1 to
the segment of the current MCB.  MCB_W_Owner=0 indicates that the
block is free;  all other values indicate that the block is owned.
In most cases MCB_W_Owner has a PSP.  When IBMBIO loads drivers
it allocates memory from this list;  of course, drivers do not have
a PSP --  some other value is used.

NB: The free memory computed by adding the sizes of any unowned
MCBs will differ from that reported by chkdsk.  Chkdsk computes
the free memory by subtracting the memory size in the PSP from the
PSP segment (neglecting any other unallocated blocks).

You will have to get the total memory from the PSP (if a COM file)
or from BIOS.

I hope this helps.

Walt Dixon		(ARPA:     Dixon@GE-CRD.ARPA        )
			(US Mail:  General Electric Corp R&D)
			(          PO Box 8                 )
			(          Schenectady NY 12345     )
			(Phone:    518-387-5798             )