Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in...

35
Microprocessor (COM 9323) Lecture 5: Memory Modes of Operation (cont’d) Ahmed Elnakib, PhD Assistant Professor, Mansoura University, Egypt 1 March 2 nd , 2016

Transcript of Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in...

Page 1: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

Microprocessor (COM 9323)

Lecture 5: Memory Modes of Operation (cont’d)

Ahmed Elnakib, PhD

Assistant Professor, Mansoura University, Egypt

1March 2nd, 2016

Page 2: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

Text Book/References*

Textbook:The Intel Microprocessors, Architecture, Programming and Interfacing, 8th edition, Barry

B. Brey, Prentice Hall, 2009 (Chapter 02)

References:Wikipedia

2

*The presentation is based on the text book and their official presentations

Page 3: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

Contents

oHow its memory space is addressed?

Real mode of operation

Protected mode of operation

Flat mode of operation

3

Page 4: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

o This shows a memory segment

beginning at 10000H, ending at

location IFFFFH

64K bytes in length

Because of the internally appended 0H,

real mode segments can begin only at a

l6-byte boundary in the memory system.

This l6-byte boundary is often called a

paragraph.

Also shows how an offset address,

called a displacement, of F000H selects

location 1F000H in the memory4

Real Mode Memory Addressing (Segmentation)

Page 5: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

o think of segments as

windows that can be

moved over any area

of memory to access

data or code

o a program can have

more than four or six

segments,

but only access four or

six segments at a time

5

A memory system showing the placement of four memory segments

A memory segment can touch or overlap if 64K bytes of memory are not required for a segment

Page 6: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

Overlapped Segments

6

o An application program containing a

code, data, and stack segment loaded

into a DOS system memory

o The side view of the segments clearly

shows the overlap.

o It also shows how segments can be

moved over any area of memory by

changing the segment starting address.

o Fortunately, the DOS program loader

calculates and assigns segment

starting addresses

Page 7: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

7

16-bit Default Segment and Offset Registers

Page 8: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

8

32-bit Default Segment and Offset Registers

Page 9: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

9

Examples of real mode segment addresses

Page 10: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

10

Examples 2

o The segment address is 4000H

o The offset address is specified as the sum of F000H plus 3000H

o What is the memory location that will be accessed?

Solution:

o Start Address: 40000H

o Offset Address: F000H + 3000H = 12000H

o This will access memory location 42000H instead of location 52000H (Why?)

When the F000H and 3000H are added, they form a l6-bit (modulo 16)

sum of 2000H used as the offset address; not 12000H, the true sum.

Note that the carry of 1 (F000H + 3000H = 12000H) is dropped for this

addition to form the offset address of 2000H. The address is generated as

4000:2000 or 42000H.

Page 11: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

oHow its memory space is addressed?

Real mode of operation

Protected mode of operation

Flat mode of operation

Contents

11

Page 12: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

12

Protected Mode Addressing

oProtected mode is where Windows operates.

oAllow the processor to perform multi-tasking: system protect each task in the memory from each other task

oSupports segmentation (real mode) and paging

oSupports virtual real mode: read address mode software in a protected-multitasking environment

oAllows access to data and programs located within (real mode) & above the first 1M byte of memory (protected mode).

Page 13: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

13

Protected Mode Application

oOperating systems operate in a 16- or 32-bit environment.

oDOS uses a 16-bit environment.

oMost Windows applications use a 32-bit environment called WIN32.

oMSDOS/PCDOS & Windows 3.1 operating systems require 16-bit instruction mode.

oInstruction mode is accessible only in a protected mode system such as Windows Vista.

Page 14: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

14

Protected Mode Addressing: the segment register contains a selectoroIn place of a segment address, the segment register contains a selector

that selects a descriptor from a descriptor table.

oThe descriptor describes the memory segment’s location, length, and access rights

Contains a selectors:Job: select a descriptor from a descriptor table

Page 15: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

15

Protected Mode Addressing: offset address

oOffset address be 16 bit or 32 bit In real mode only 16 bit is allowed

oIn case of a 32 bit offset, this allows the microprocessor to access data within a segment that can be up to 4G bytes in length In real mode the size of the segment is only 64k byte

Page 16: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

16

Selectors and Descriptors

oThe descriptor is located in the segment register & describes the location, length, and access rights of the segment of memory.

• it selects one of 8192 (8k: need 13 bits to select which one) descriptors from one of two tables of descriptors

oIn protected mode, this segment number can address any memory location in the system for the code segment.

oIndirectly, the register still selects a memory segment, but not directly as in real mode

Page 17: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

17

Global and Local Descriptors

oThere are two descriptor tables used with the segment registers

1. Global descriptors contain segment definitions that apply to all programs.

2. Local descriptors are usually unique to an application. a global descriptor might be called a system descriptor, and local descriptor an

application descriptor

oEach descriptor table contains 8192 descriptors, so a total of 16,384descriptors

Page 18: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

18

How many memory segments can be accessed in Protected mode?

oThere are two descriptor tables (local and global) used with the segment registers

oEach descriptor table contains 8192 (8k) descriptors, so a total of 16,384 (16k) descriptors

oBecause the descriptor describes a memory segment, this allows up to 16,384 memory segments to be described for each application.

oSince a memory segment can be up to 4G bytes in length, this means that an application could have access to 4G x 16k bytes of memory or 64T bytes.

Page 19: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

19

1. Using the DS register to select a description from the global descriptor table. o In this example, the DS register accesses

memory locations 00100000H–001000FFH as a data segment.

2. The entry in the global descriptor table selects a segment in the memory system.

Descriptor describes the

memory segment’s

location, length, and

access rights.

Selector

8 Bytes

Protected Mode Addressing

Page 20: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

20

Selector Format

The contents of a segment register during protected mode operation of the 80286 through Core2 microprocessors.

Page 21: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

21

Selector Format (cont’d)

o13-bit selector field: selects one of 8192 (8k) descriptors from one of two tables (global or local) of descriptors Each descriptor table contains 8192 descriptors, so a total of 16,384 total

descriptors 16,384 total descriptors

oThe TI bit (table selector bit) selects either the global or the local descriptor table.

oRequested Privilege Level (RPL) requests the access privilege level of a memory segment. If privilege levels are violated, system normally indicates an application or privilege

level violation

Page 22: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

22

Format of a descriptor for the 80286 through the Core2.

oEach descriptor is 8 bytes in lengthglobal and local descriptor tables are a maximum of 64K bytes in length

Page 23: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

23

Descriptors Format: Base Address

oThe base address of the descriptor indicates the starting location of the memory segment. the paragraph boundary limitation is removed in protected mode

segments may begin at any address

o The base address of the descriptor indicates the starting location of the memory segment

o For the 80286 microprocessor, the base address is a 24-bit address, so segments begin at any location in its 16M bytes of memory

o The 80386 and above use a 32-bit base address that allows segments to begin at any location in its 4G bytes of memory

Page 24: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

24

Descriptors Format: Segment Limit

oThe segment limit contains the last offset address found in a segment.

o80286 has a 16-bit limit:

an 80286 can access memory segments that are between 1 and 64K bytes in length

o80386 through the Pentium 4 have a 20-bit limit.

The 80386 and above access memory segments that are between 1 and 1M byte, or 4K and 4G bytes in length.

Page 25: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

25

Descriptors Format: Segment Limit (Example)

o If a segment begins at memory location F00000H and ends at location F000FFH, the base address is F00000H and limit is FFH.

oFor the 80286 microprocessor, the base address is F00000H and the limit is 00FFH:

oFor the 80386 and above, the base address is 00F00000H and the limit is 000FFH.

Page 26: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

26

Descriptors Format: Granularity Bit

oThere is another feature found in the 80386 through the Pentium 4 descriptor that is not found in the 80286 descriptor

oIf G=0, the limit specifies a segment limit of 00000H to FFFFFH.

oIf G=1, the value of the limit is multiplied by 4K bytes (appended with FFFH). The limit is then 00000FFFFH to FFFFFFFFH

oThe G, or granularity bit allows a segment length of 4K to 4G bytes in steps of 4K bytes. 32-bit offset address allows segment lengths of 4G bytes

16-bit offset address allows segment lengths of 64K bytes.

Page 27: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

27

Example-1 (G=0)

The segment start and end if the base address is 10000000H, the limit is 001FFH, and the G-bit G=0

Page 28: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

28

Example-2 (G=0)

The segment start and end if the base address is 10000000H, the limit is 001FFH, and the G-bit G=1

Note: limit is appended with FFFH to determine the ending segment address

Page 29: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

29

oIn the 64-bit descriptor, the L bit (probably means large, but Intel calls it the 64-bit) selects 64-bit addresses in a Pentium 4 or Core2 with 64-bit extensions when L = 1 and 32-bit compatibility mode when L=0.

oIn 64-bit protected operation, the code segment register is still used to select a section of code from the memory.

oNotice that the 64-bit descriptor has no limit or base address. It only contains an access rights byte and the control bits.

oIn the 64-bit mode, there is no segment or limit in the descriptor and the base address of the segment, although not placed in the descriptor, is 00 0000 0000H.

o This means that all code segments start at address zero for 64-bit operation. There are no limit checks for a 64-bit code segment

Descriptors Format: L- Bit

Page 30: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

30

oThe AV bit, in the 80386 and above descriptor, is used by some operating systems to indicate that the segment is available ( AV=1) or not available (AV=0 ).

Descriptors Format: AV- Bit

Page 31: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

31

oThe D bit indicates how the 80386 through the Core2 instructions access register and memory data in the protected or real mode.

oIf D=0, the instructions are 16-bit instructions, compatible with the 8086–80286 microprocessors. This means that the instructions use 16-bit offset addresses and 16-bit register by default. This mode is often called the 16-bit instruction mode or DOS mode.

oIf D=1, the instructions are 32-bit instructions. By default, the 32-bit instruction mode assumes that all offset addresses and all registers are 32 bits.

Descriptors Format: D- Bit

Page 32: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

32

oNote that the default for register size and offset address I overridden in both the 16- and 32-bit instruction modes.

oBoth the MSDOS and PCDOS operating systems require that the instructions are always used in the 16-bit instruction mode.

oWindows 3.1, and an application that was written for it, also requires that the 16-bit instruction mode is selected.

oNote that the instruction mode is accessible only in a protected mode system such as Windows Vista.

Descriptors Format: D- Bit (cont’d)

Page 33: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

33

Descriptors Format: Access Rights Byte

oThe access rights byte controls access to the protected mode segment. describes segment function in the system and allows complete control over the

segment

if the segment is a data segment, the direction of growth is specified

oIf the segment grows beyond its limit, the operating system is interrupted, indicating a general protection fault.

oYou can specify whether a data segment can be written or is write-protected.

Page 34: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

34

Bits of Access Rights Byte

The access rights byte for the 80286 through Core2 descriptor.

Page 35: Communication Theory II - ECED Mansoura · the paragraph boundary limitation is removed in protected mode segments may begin at any address oThe base address of the descriptor indicates

Questions

35