Memory Management-System Programming-Lecture Notes, Study notes of System Programming

This lecture handout is for System Programming course. It was provided by Prof. Indubhushan Vijayabhas at Ambedkar University, Delhi. It includes: Memory, Managment, Data, Structure, operating, System, Map, Area, Expanded, Extended

Typology: Study notes

2011/2012

Uploaded on 08/07/2012

anishay
anishay 🇮🇳

4.2

(25)

118 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lecture # 42
Memory Management
Understanding of the data structures and
techniques used for memory management.
Study of the overall memory areas used by
operating system and applications.
The following slide shows the memory map of the first 1MB of RAM. The first 640KB is
called conventional RAM and the higher 384KB is called system memory. Some of the
memory areas are reserved for special purposes as described by the slide rest is user area
where user application can reside.
Memory Map
Shadow RAM
Unused
Text Displ ay
Graphi cs Display
Command .Com
(Transient Part)
User Applicati ons
Command .Com (Residen t
Part)
Other D evice Drivers
MSDOS.Sys
IO.Sys
DOS Data Area
BIOS D ata Area
IVT
Earlier PCs ( 20-bit Address Bus
Converted RAM
( 640 KB )
System Memory
( 384 KB )
0000 : 0000H
9000 : FFFFH
A000 : 0000H
F000 : 0000H
F000 : FFFFH
docsity.com
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Memory Management-System Programming-Lecture Notes and more Study notes System Programming in PDF only on Docsity!

Lecture # 42

Memory Management

• Understanding of the data structures and

techniques used for memory management.

• Study of the overall memory areas used by

operating system and applications.

The following slide shows the memory map of the first 1MB of RAM. The first 640KB is

called conventional RAM and the higher 384KB is called system memory. Some of the

memory areas are reserved for special purposes as described by the slide rest is user area

where user application can reside.

Memory Map

Shadow RAM

Unused

Text Display

Graphics Display

Command.Com

(Transient Part)

User Applications

Command.Com (Resident

Part)

Other Device Drivers

MSDOS.Sys

IO.Sys

DOS Data Area

BIOS Data Area

IVT

Earlier PCs ( 20-bit Address Bus

Converted RAM

( 640 KB )

System Memory

( 384 KB )

0000 : 0000H

9000 : FFFFH

A000 : 0000H

F000 : 0000H

F000 : FFFFH

In higher processors, the main memory may be greater than 1MB. In this slide it shows

that the memory portion higher than 1MB is called extended memory and some unused

portion in system memory is called the expanded memory.

Memory Map

Higher Processors with 24-bit or 32-bit Address Bus

Expanded Memory (64 KB)

Extended Memory

(higher than 1 MB)

Conventional RAM (640 KB)

System RAM (384 KB)

Expanded Memory

• also called EMS

• can be accessed using a driver called EMM386.EXE

• this driver allows the use of unused memory within

system memory.

Extended Memory

• also called XMS

• can be accessed by installing the driver HIMEM.SYS

• this driver enable the extended memory by shifting from

Real to Protected Mode.

Protected Mode

  • PC has to be shifted to Protected Mode if originally

boots in Real Mode.

  • In Protected Mode whole of the RAM is accessible that

includes the Conventional, Expanded and Extended

Memories.

  • OS like Windows has a memory management system

for Protected Mode.

  • A privilege level can be assigned to a memory area

restricting its access.

Memory Management in DOS

  • DOS uses the conventional memory first 640 KB for its

memory management.

  • Additional 64 KB can be utilized by installing

EMM386.EXE and additional 64 KB in the start of

extended memory by installing HIMEM.SYS

  • Smallest allocatable unit in DOS is a Paragraph, not a

Byte.

Paragraph

  • Whenever memory is to be allocated DOS allocates memory in form of

Paragraph.

  • A Paragraph can be understood from the following examp le

consider two Physical Addresses

1234 H : 0000 H

1235 H : 0000 H

  • Note there is a difference of 1 between the Segment address.
  • Now lets calculate the Physical address

12340 H

12350 H

Difference = 10 H

  • A difference of 1 H in Seg ment address cause a difference of 10 H in Physical

address.

  • DOS loader assign a segment address whenever memo ry area is allocated,

hence a change of 1 in Seg ment address will impart a d ifference of 16 D | 10 H

in physical address.

Data Structures for Memory

Management

  • DOS makes use of various Data Structures for Memory

Management:

  • MCB ( Memory Control Block )
  • EB ( Environment Block )
  • PSP ( Program Segment Prefix )

PSP

  • is situated before the start of a process.
  • contains control information like DTA ( Disk Transfer

Area) and command line parameters.

The following slide shows that two MCBs are allocated for each program typically. The

first MCB controls the Environment Block the next MCB controls the PSP and the

program. If this is the last program in memory then the MCB after the program has ‘Z’ in

its first byte indicating that it is the last MCB in the chain.

Typical Memory Organization

Free

Z

Program

PSP

M

E.B

M

Program

PSP

M

E.B

M

All the MCB forms a chain. If the address of first MCB is known the segment

address of next MCB can be determined by adding the number of paragraph

controlled by MCB +! into the segment address of the MCB. Same is true for all

MCBs and hence the whole chain can be traversed.

How to Access the Start of Chain

  • An documented service can be used to obtain the

address of the first MCB.

  • Service 21H/52H is used for this purpose.
  • This service returns

The address of DOS internal data structures in ES : BX

  • 4-bytes behind the address returned lies the far address

of the first MCB in memory.

  • Using this address and hence traversing through the

chain of MCBs using the information within MCBs.

-a

13B0:0100 mov ah,

13B0:0102 int 21

13B0:

-p

AX=5200 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 D I=

DS=13B0 ES=13B0 SS=13B0 CS=13B0 IP=0102 NV UP EI PL NZ NA PO NC

13B0:0102 CD21 INT 21

-p

AX=5200 BX=0026 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 D I=

DS=13B0 ES=00A7 SS=13B0 CS=13B0 IP=0104 NV UP EI PL NZ NA PO NC

13B0:0104 0000 ADD [BX+SI],AL

DS:0026=FF

-d a7:

00A7:0020 00 00 08 02 EA 15-A7 00 CE 00 A7 00 5A 00 ............Z.

00A7:0030 70 00 24 00 70 00 80 00-00 00 00 00 00 00 7C 03 p.$.p.........|.

00A7:0040 00 00 72 03 00 00 04 04-00 00 D9 02 04 80 C6 0D ..r.............

00A7:0050 CC 0D 4E 55 4C 20 20 20-20 20 00 00 00 00 00 00 ..NUL ......

00A7:0060 00 AB 73 03 0E 00 00 00-00 03 01 00 04 00 00 00 ..s.............

00A7:0070 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................

00A7:0080 00 FF FF 00 00 00 00 0E-00 00 00 05 FF 9F 08 02 ................

00A7:0090 82 14 D3 28 2E FE D7 28-2E FE D7 28 2E FE D3 28 ...(...(...(...(

00A7:00A0 2E FE ..

-q

The above slide shows how service 21H/52H is used to get the address of first MCB in

memory.

In the following slide the dump of the first MCB is taken. ‘M’ in the first byte at the

location read indicates the placement of MCB at this location. The address of next MCB

can be calculated by adding the number of paragraphs controlled by MCB + 1 into the