Docsity

Understanding Memory Management: Non-Contiguous Allocation & Descriptor Tables, Study notes of System Programming

Toggle sidebar
bg1
Lecture # 43
#include <stdio.h>
#include <conio.h>
#include <bios.h>
#include <dos.h>
typedef struct tagMCB {
unsigned char sig;
unsigned int pspseg;
unsigned int paras;
unsigned char reserved[11];
}MCB;
void main (void)
{unsigned int seg,off;
unsigned int far * temp;
unsigned long i;
char st[20];
MCB far * pmcb;
_AH=0x52;
geninterrupt(0x21);
seg = _ES;
off = _BX;
off = off- 4;
temp = (unsigned int far *) MK_FP(seg,off);
seg = *(temp+1);
pmcb = (MCB far *)MK_FP(seg,*temp);
while (pmcb->sig == 'M')
{printf("\nSegment Address of PSP is %x",pmcb->pspseg);
printf("\nNo of Paras controlled by MCB = %x\n",pmcb->paras);
seg = seg + pmcb->paras + 1;
pmcb = (MCB far *)MK_FP(seg,*temp);
}
if (pmcb->sig == 'Z')
{printf("\nLast MCB found");
printf("\nNo of free Paras = %x",pmcb->paras);
i = (pmcb->paras)*16L;
ltoa(i,st,10);
printf("\nLargest contigous block = " );
puts (st);
}
}
This program used the same method as discussed in previous lecture to get the address of
first MCB, calculate the addresses of subsequent MCBs and traverse the MCBs to reach
the last MCB.
docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Understanding Memory Management: Non-Contiguous Allocation & Descriptor Tables and more Study notes System Programming in PDF only on Docsity!

Lecture # 43

#include <stdio.h> #include <conio.h> #include <bios.h> #include <dos.h>

typedef struct tagMCB { unsigned char sig; unsigned int pspseg; unsigned int paras; unsigned char reserved[11]; }MCB;

void main (void) { unsigned int seg,off; unsigned int far * temp; unsigned long i; char st[20]; MCB far * pmcb; _AH=0x52; geninterrupt(0x21);

seg = _ES; off = _BX; off = off- 4; temp = (unsigned int far *) MK_FP(seg,off); seg = (temp+1); pmcb = (MCB far )MK_FP(seg,temp); while (pmcb->sig == 'M') { printf("\nSegment Address of PSP is %x",pmcb->pspseg); printf("\nNo of Paras controlled by MCB = % x\n",pmcb->paras); seg = seg + pmcb->paras + 1; pmcb = (MCB far )MK_FP(seg,temp); } if (pmcb->sig == 'Z') { printf("\nLast MCB found"); printf("\nNo of free Paras = %x",pmcb->paras); i = (pmcb->paras)16L; ltoa(i,st,10); printf("\nLargest contigous block = " ); puts (st); } }

This program used the same method as discussed in previous lecture to get the address of

first MCB, calculate the addresses of subsequent MCBs and traverse the MCBs to reach

the last MCB.

Non-Contiguous Allocation

  • Earlier Operating System like DOS has contiguous memory

management system i.e. a program cannot be loaded in memory if a

contiguous block of memory is not available to accommodate it.

  • 80286 and higher processors support non-contiguous allocation.
  • 80286 support Segmentation in Protected Mode, i.e. a process is

subdivided into segment of variable size and each segment or few

segments of the process can be placed anywhere in memory

  • 80386 and higher processors also support Paging, i.e. a Process

may be divided into fixed size Pages and then only few pages may

be loaded any where in memory for Process Execution.

  • The key to such non-contiguous allocation systems is the

addressing technique.

Address Translation

โ€ข In Protected Mode the direct method of

seg * 10H + offset for Logical to Physical

address translation is discarded and an

indirect method is adopted.

The following slide shows the structure of descriptors of 80286 and 80386 processors

Limit (L15 โ€“ L0)

Base (B15 โ€“ B0)

Access Base(B23- B16) Rights

Reserved

Lim (L15 โ€“ L0)

Base (B15 โ€“ B0)

Access Base(B23-B16) Rights

Base A Limit (B24 โ€“ B31) G D 0 V (L16 โ€“ L 19) L

80286 Descriptor

  • Base (B31 โ€“ B0) contains the base address of Segment within the

4GB Physical space.

  • Limit (L19 โ€“ L0) define the length of segment in units of bytes

if G = 0 and in units of 4K (pages) if G= 1.

This allow the Segment to be of 1M if G = 0 and of 4G if G = 1.

80386 Descriptor

Descriptor

  • Access Right: contains the privilege level and other

information depending upon the type of descriptor.

  • G: the granularity bit selects the multiplier of 1

or 4K times the limit field. If G = 0 multiplier is 1; if G = 1

multiplier is 4K.

  • D: selects the default registers size. If D = 0 the

default register size is 16-bit, if D = 1 the size is 32-bit.

  • AVL: the Operating System often uses this bit to

indicate that the segment described by the Descriptor is available in

memory

Segment Descriptor

  • If the Descriptor describes a memory segment then the Access Rights Byte will have the following meaning.
  • P: Present bit, if P = 1 Seg ment is Present, if P = 0 Segment is not Present.
  • DPL: Descriptor Privilege level 00 for highest and 11 for lowest. Low privilege level memory area cannot access a memory area with hig h privilege whereas vice versa is TRUE.
  • S: Indicates data or code segment if S = 1 or a System Descriptor if S = 0.
  • E: Executable, if E = 0 Then itโ€™s a Data/Stack Segment, if E = 1 Then itโ€™s a Code Segment.
  • X: If E = 0 then X indicates the direction of expansion of the Segment. If X = 0 Seg ment expands upwards (i.e. Data Seg ment) If X = 1 Seg ment expands downwards (i.e. Stack Seg ment) If E =1 then X indicates if the privilege level of Code Segment is ignored (X = 0) or observed (X = 1).
  • A Accessed is set whenever the Segment is set.

DP S E X RW A

L

P

Lim (L15 โ€“ L0)

Base (B15 โ€“ B0)

Base(B23-B16) P DPL 0 TYPE

Base Limit (B24 โ€“ B31) G 0 0 0 (L16 โ€“ L19)^6

System Descriptor & Access Byte