SlideShare a Scribd company logo
Segmentation in 80386
Subject : Processor Architecture & Interfacing
Class : SEIT
Prepared By
Ms. K. D. Patil, AP
Department of IT, Sanjivani COE, Kopargaon.
2020/1/16 Prepared By: Ms. K. D. Patil 1
Types of Address spaces
● Logical / Virtual address: Virtual addresses are used by an application
program. They consist of a 16-bit selector and a 32-bit offset. In the flat
memory model, the selectors are preloaded into segment registers CS, DS,
SS, and ES, which all refer to the same linear address.
● Linear Addresses: Linear addresses are calculated from virtual/logical
addresses by segment translation (Segmentation). The base of the segment
referred to by the selector is added to the virtual offset, giving a 32-bit linear
address. In segmentation, when paging is disabled linear address = physical
address
● Physical Address: Physical Address is nothing but, the address value that
appears on pins of processor during a memory read/memory write
operations. Physical addresses are calculated from linear addresses through
paging. The linear address is used as an index into the Page Table where the
CPU locates the corresponding physical address.
2020/1/16 Prepared By: Ms. K. D. Patil 2
Physical Address Formation in Real
Mode
2020/1/16 Prepared By: Ms. K. D. Patil 3
Physical Address Formation in Real
Mode
● In the real mode, the 80386 can address at the most 1Mbytes of physical memory using
address lines A 0 -A 19 .
● Paging unit is disabled in real addressing mode, and hence the real addresses are the same as
the physical addresses.
● To form a physical memory address, appropriate segment registers contents (16-bits) are
shifted left by four positions and then added to the 16-bit offset address formed using one of
the addressing modes, in the same way as in the 80386 real address mode.
● The segment in 80386 real mode can be read, write or executed, i.e. no protection is available.
● Any fetch or access past the end of the segment limit generate exception 13 in real address
mode.
● The segments in 80386 real mode may be overlapped or non- overlapped.
● The interrupt vector table of 80386 has been allocated 1Kbyte space starting from 00000H to
003FFH.
2020/1/16 Prepared By: Ms. K. D. Patil 4
Address Translation in 80386
● 80386 transforms logical addresses into physical
address two steps:
● Segment translation: a logical address is converted
to a linear address.
● Page translation: a linear address is converted to a
physical address (optional)
● These translations are performed in a way that is not
visible to applications programmers.
2020/1/16 Prepared By: Ms. K. D. Patil 5
Address Translation in 80386
2020/1/16 Prepared By: Ms. K. D. Patil 6
Protected Mode Addressing
● In this mode, the contents of segment registers are used as selectors to
address descriptors which contain the segment limit, base address and
access rights byte of the segment.
● The effective address (offset) is added with segment base address to
calculate linear address. This linear address is further used as physical
address, if the paging unit is disabled, otherwise the paging unit
converts the linear address into physical address.
● The paging unit is a memory management unit enabled only in
protected mode. The paging mechanism allows handling of large
segments of memory in terms of pages of 4Kbyte size.
● The paging unit operates under the control of segmentation unit. The
paging unit if enabled converts linear addresses into physical address,
in protected mode.
2020/1/16 Prepared By: Ms. K. D. Patil 7
Segmentation
● Addressable space of processor is divided into small parcels
called as segments.
● Segmentation is one method of memory management.
● Segmentation provides the basis for protection.
● Segments are used to encapsulate regions of memory which have
common attributes.
● For example, all of the code of a given program could be
contained in a segment, or an operating system table may reside
in a segment.
2020/1/16 Prepared By: Ms. K. D. Patil 8
Segmentation
● Segments can be defined in 8 basic types
– Data segments with or without write permission
– Stack segments with or without write permission
– Executable code segments with or without data read
permission
– Executable code segments with or without privilege
protection
2020/1/16 Prepared By: Ms. K. D. Patil 9
Segmentation
● Segments are
– Areas of memory
– Defined by programmer
– Used for different purposes such as code, data and stack
● Segments are not
– All the same size
– Necessarily paragraph aligned
– Limited to 64KB
2020/1/16 Prepared By: Ms. K. D. Patil 10
Logical to Physical/ Linear Address
Translation
2020/1/16 Prepared By: Ms. K. D. Patil 11
Memory Management Through
Segmentation
● Contents of segment registers (CS, DS, SS, ES, FS,GS) are used as
selectors to address descriptors which contain the segment limit, base
address and access rights byte of the segment.
● The processor must examine the value loaded in segment register. If
TI (Table Indicator) bit is not set, processor uses index portion (bit 3
through 15) of selector as a pointer to GDT to find correct segment
descriptor as well its upper limit can be located through GDTR.
● The processor then concentrates the fragments of base address field in
the segment descriptor and comes up with the base address of
respective segment.
● To this base address, it adds the offset. This is the linear address where
operand actually located.
2020/1/16 Prepared By: Ms. K. D. Patil 12
2020/1/16 Prepared By: Ms. K. D. Patil 13
2020/1/16 Prepared By: Ms. K. D. Patil 14
Segment Selector
● Segment Registers (CD,DS,SS,ES,FS,GS) are called
as segment selectors OR
● Any 16 bit value that you write into segment register
is called as selector because it selects a segment
descriptor from a descriptor table.
● Segment registers selects segment Descriptors
2020/1/16 Prepared By: Ms. K. D. Patil 15
Segment Selector
● There are 3 fields in segment selector
– Index (Descriptor Index) (bit 3 through 15) : This value
selects one of the 8192 descriptors in the descriptor table
(8192*16 bit = 65536 bytes = 64KB long)
– Table Indicator (bit 2) : Indicates which descriptor table
you want to refer
● When TI = 0 , the index portion refers to descriptor in GDT
● When TI = 1 , the index portion refers to descriptor in LDT
– Privilege checking (bit 0 & 1) : Used for privilege
checking by the protection mechanism
2020/1/16 Prepared By: Ms. K. D. Patil 16
Segment Descriptor
● All information about a segment is stored in an 8
byte data structure called a descriptor.
● All of the descriptors in a system are contained in
tables recognized by hardware.
● Exactly one descriptor must be defined for each
segment of memory to be used in running system
● Created by programmer
● Determines a segment’s base address
2020/1/16 Prepared By: Ms. K. D. Patil 17
Segment Descriptor
● Determines
– segment’s use
– segment’s size
– segment’s privilege level
– whether segment has been accessed before
● Defines type of segment
● Defines Segment limit
2020/1/16 Prepared By: Ms. K. D. Patil 18
Segment Descriptor Format
2020/1/16 Prepared By: Ms. K. D. Patil 19
Segment Descriptor
● Base Address Bits
– Lower 24 bits of segment address : 16 through 39
– Upper 8 bits of segment address : 56 through 63
– By internally concatenating the two portions of the base address field,
the processor can determine the linear address at which segment starts.
● Limit Field
– Lower 16 bits : 0 through 15
– Upper 4 bits : 48 through 51
– It is defined as length of segment in bytes minus 1
– The actual segment length is not used. The segment that is 1 byte length
would have limit of 0
2020/1/16 Prepared By: Ms. K. D. Patil 20
Segment Descriptor
● A (Access, Bit 40)
– 80386 automatically sets this bit whenever a memory
reference is made using the segment that this descriptor
defines
● Type (Segment Type, Bit 41 through 43)
– This 3 field indicates the types of segment you are defining,
like code, data and stack
● S (System, Bit 44)
– If this bit is clear, it indicates that it is a system segment
descriptor. If it is clear it is non-system (code,data,stack)
segment descriptor2020/1/16 Prepared By: Ms. K. D. Patil 21
Segment Descriptor
● DPL (Descriptor Privilege Level, bit 45 and 46)
– Indicates the level of privilege associated with the memory
space that the descriptor defines. DPL 0 is most privilege and
DPL3 is least privilege
● P (Present, bit 47)
– If this bit is clear, address range that the descriptor defines is
considered to be temporarily not present in physical memory
● U (User, bit 52)
– Undefined and 80386 ignores this bit
2020/1/16 Prepared By: Ms. K. D. Patil 22
Segment Descriptor
● D (Default size, bit 54)
– When it is cleared, operands within the segment are assumed
to be 32 bits
● G (Granularity, bit 55)
– When it is cleared, 20 bit limit field is assumed to be
measured in units of 1 byte. If it is set, Limit field is units of
4096 bytes
2020/1/16 Prepared By: Ms. K. D. Patil 23
Types of Segment Descriptors
2020/1/16 Prepared By: Ms. K. D. Patil 24
Non-system Segment Descriptors
● The format of descriptor is same , only the access byte rights
changes.
● Type 0: Data segment with read permission
● Type 1: Data segment with read/ write permission
● Type 2,3: Stack segment
● The addressable range of a segment stretches from the base
address to the base address plus limit definition.
● Valid offset ranges from 0 to limit. Any offset greater than limit
are not considered part of the segment and are not addressable.
2020/1/16 Prepared By: Ms. K. D. Patil 25
Expansion Direction
2020/1/16 Prepared By: Ms. K. D. Patil 26
Expansion Direction
● In the stack segment, if the type field defines a stack
(Type 2,3) then the limit field indicates what area of
segment is not addressable.
● In the stack segment, all offsets must be greater than
the limit.
● In case of data segments, all offsets less than or
equal to limit are valid. The first addressable byte is
at offset 0 and the last is at offset 1FFF, making data
segment 2000 bytes (8KB) long
2020/1/16 Prepared By: Ms. K. D. Patil 27
Expansion Direction
● In the stack segment, the first addressable byte is at offset 2000, and
the last is at FFFF. Offset address 0 is not valid.
● In data segment, lower limit is set by base address field of the
descriptor and upper limit is set by limit field.
● For stack segment, the lower limit is set by limit field and upper limit
have 2 choices,
- if D = 0, the upper limit is equal to the base address plus constant value
FFFF (64KB)
- if D = 1, the upper limit is equal to base address plus FFFFFFFF (4GB)
● A stack segment has minimum size when the limit is either FFFF (D =
0) or FFFFFFFF (D=1) producing a null segment with value zero
length.
2020/1/16 Prepared By: Ms. K. D. Patil 28
Non-system Segment Descriptors
● Type 4,5,6,7: Defines Executable segments. Here the code exists.
● Read permission is optional for the segments. If read permission
is denied (Type 4), the segment must contain pure code, no
constants are allowed since they cannot read out. Only code
fetching is allowed.
● If read permission is given (type 5), you can embed constants in
the code itself. Writing is never allowed to the executable code
segment.
● The two executable code segments are repeated with the
conforming attribute set (type 6,7). Conforming means these
code segments voluntarily forgo their privilege level protection.
2020/1/16 Prepared By: Ms. K. D. Patil 29
Non-system Segment Descriptors
● The format of descriptor is same , only the access
byte rights changes.
2020/1/16 Prepared By: Ms. K. D. Patil 30
System Segment Descriptors
2020/1/16 Prepared By: Ms. K. D. Patil 31
System Segment Descriptors
2020/1/16 Prepared By: Ms. K. D. Patil 32
● LDT Descriptor (Type 2)
– They are Local descriptor tables, present only in GDT.
– They contain information about LDT.
– Can be accessed only at privilege level 0.
● Gate Descriptor (Type 4,5,6,7,C,E,F)
– Allows 80386 to automatically perform the protection check
– Call Gate: Changes privilege level
– Task Gate: Performs a task switch
– Interrupt Gate/ Trap Gate: Used to specify the interrupt service routines
● TSS (Task State Segment) Descriptor (Type 1,3,9, B)
– When one task switches to another task, it stores all necessary information required to
restart the task, where it was left
– TSS stores the state/context of the task (location, size and privilege level) & linkage of
next task
References
● James Turley, "Advanced 80386 Programming
Techniques", McGraw Hill Education.
● Slides shared by Prof. Tushar Kute at the time of
PAI FDP

More Related Content

PPTX
80386 Architecture
PPT
Privilege levels 80386
PPTX
Register of 80386
PPTX
I/O system in intel 80386 microcomputer architecture
PPT
80486 microprocessor
PDF
PAI Unit 3 Paging in 80386 Microporcessor
PPT
Address translation-mechanism-of-80386 by aniket bhute
PPTX
80486 and pentium
80386 Architecture
Privilege levels 80386
Register of 80386
I/O system in intel 80386 microcomputer architecture
80486 microprocessor
PAI Unit 3 Paging in 80386 Microporcessor
Address translation-mechanism-of-80386 by aniket bhute
80486 and pentium

What's hot (20)

PPTX
Salient featurs of 80386
PPT
80286 microprocessor
PDF
Special of 80386 registers
PPT
Microprocessor 80386
PPTX
Segment registers
PDF
PAI Unit 3 Multitasking in 80386
PPTX
Pentium processor
PDF
8086 Register organization and Architecture details
PDF
Module 1 8086
PPT
Introduction to 8086 microprocessor
PPTX
INTEL 80386 MICROPROCESSOR
PPTX
Stacks & subroutines 1
PPT
Pin Description Diagram of Intel 80386 DX Microprocessor
PPT
Pin Description Of Intel 80386 DX Microprocessor
PDF
Memory segmentation-of-8086
PDF
Introduction to 80386
PPTX
Ethernet Computer network
PPTX
Addressing mode Computer Architecture
PPTX
Evolution of microprocessors and 80486 Microprocessor.
PPT
pin-diagram-details-of-8086-microprocessor
Salient featurs of 80386
80286 microprocessor
Special of 80386 registers
Microprocessor 80386
Segment registers
PAI Unit 3 Multitasking in 80386
Pentium processor
8086 Register organization and Architecture details
Module 1 8086
Introduction to 8086 microprocessor
INTEL 80386 MICROPROCESSOR
Stacks & subroutines 1
Pin Description Diagram of Intel 80386 DX Microprocessor
Pin Description Of Intel 80386 DX Microprocessor
Memory segmentation-of-8086
Introduction to 80386
Ethernet Computer network
Addressing mode Computer Architecture
Evolution of microprocessors and 80486 Microprocessor.
pin-diagram-details-of-8086-microprocessor
Ad

Similar to PAI Unit 2 Segmentation in 80386 microprocessor (20)

PPTX
UNIT-3.pptx digital electronics system 34
PPT
Intel microprocessor history lec12_x86arch.ppt
PDF
80386_AKRay.pdf study computer programme
PPT
80286 education project compiter application .ppt
PDF
80386 Basic Programming Model and Application
PPTX
32- bit Microprocessor-Indtel 80386.pptx
PPTX
PPTX
Internal microprocessor architecture
PPT
PPT
Architecture_of_80386_Microprocessor - Inroduction
PPT
Memory mgmt 80386
PPTX
Microprocessor Unit -1 SE computer-II.pptx
PPT
Architecture_of_80386_Micropro-An Introduction
PPTX
[ASM] Lab2
PDF
Microprocessor Unit-1( Introduction to 80386 Microprocessors)Second Year ppt
PDF
Cs14 406 80386-mod1
PPTX
Protected addressing mode and Paging
PPTX
Chapter 1 archietecture of 8086
PPTX
Lect 8 updated (1)
PPTX
Pai unit 1_l1-l2-l3-l4_upload
UNIT-3.pptx digital electronics system 34
Intel microprocessor history lec12_x86arch.ppt
80386_AKRay.pdf study computer programme
80286 education project compiter application .ppt
80386 Basic Programming Model and Application
32- bit Microprocessor-Indtel 80386.pptx
Internal microprocessor architecture
Architecture_of_80386_Microprocessor - Inroduction
Memory mgmt 80386
Microprocessor Unit -1 SE computer-II.pptx
Architecture_of_80386_Micropro-An Introduction
[ASM] Lab2
Microprocessor Unit-1( Introduction to 80386 Microprocessors)Second Year ppt
Cs14 406 80386-mod1
Protected addressing mode and Paging
Chapter 1 archietecture of 8086
Lect 8 updated (1)
Pai unit 1_l1-l2-l3-l4_upload
Ad

More from KanchanPatil34 (20)

PDF
Unit 1_Data Validation_Validation Techniques.pdf
PDF
Unit 1_Concet of Feature-Feature Selection Methods.pdf
PDF
Unit 1_Introduction to ML_Types_Applications.pdf
PDF
Unit 6_Cyber Laws Indian Act_Digital Signature.pdf
PDF
Unit 6_DoS and DDoS_SQL Injection_tools.pdf
PDF
Unit 6_keylogger_Spywares_virus_worms.pdf
PDF
Unit 6_Introduction_Phishing_Password Cracking.pdf
PDF
Unit 5_Social Engineering and Cyberstalking.pdf
PDF
Unit 5_Classification of Cyber Crimes.pdf
PDF
Unit 5_Introduction to Cyber Security.pdf
PDF
Unit 4_SSL_Handshake Protocol_Record Layer Protocol.pdf
PDF
Unit 4_IPSec_AH_ESP_IKE_SA_Tunnel_Transport.pdf
PDF
Unit 3_Private Key Management_Protection.pdf
PDF
Unit 3_Kerberos Protocol_Working_Version.pdf
PDF
Unit 3_Digital Certificate_Intro_Types.pdf
PDF
Unit 3_Digital Signature Model Details.pdf
PDF
Unit 3_Hash function and MD5 working.pdf
PDF
Unit 3_Secure Hash Algorithm_SHA_Working.pdf
PDF
AES Solved Example on Encryption all rounds.pdf
PDF
Unit 2_AES_AES_Structure_Encryption_Example.pdf
Unit 1_Data Validation_Validation Techniques.pdf
Unit 1_Concet of Feature-Feature Selection Methods.pdf
Unit 1_Introduction to ML_Types_Applications.pdf
Unit 6_Cyber Laws Indian Act_Digital Signature.pdf
Unit 6_DoS and DDoS_SQL Injection_tools.pdf
Unit 6_keylogger_Spywares_virus_worms.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 5_Social Engineering and Cyberstalking.pdf
Unit 5_Classification of Cyber Crimes.pdf
Unit 5_Introduction to Cyber Security.pdf
Unit 4_SSL_Handshake Protocol_Record Layer Protocol.pdf
Unit 4_IPSec_AH_ESP_IKE_SA_Tunnel_Transport.pdf
Unit 3_Private Key Management_Protection.pdf
Unit 3_Kerberos Protocol_Working_Version.pdf
Unit 3_Digital Certificate_Intro_Types.pdf
Unit 3_Digital Signature Model Details.pdf
Unit 3_Hash function and MD5 working.pdf
Unit 3_Secure Hash Algorithm_SHA_Working.pdf
AES Solved Example on Encryption all rounds.pdf
Unit 2_AES_AES_Structure_Encryption_Example.pdf

Recently uploaded (20)

PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Basic Mud Logging Guide for educational purpose
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Lesson notes of climatology university.
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Pre independence Education in Inndia.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Sports Quiz easy sports quiz sports quiz
PDF
Insiders guide to clinical Medicine.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Classroom Observation Tools for Teachers
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
O7-L3 Supply Chain Operations - ICLT Program
Basic Mud Logging Guide for educational purpose
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Lesson notes of climatology university.
Module 4: Burden of Disease Tutorial Slides S2 2025
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Pre independence Education in Inndia.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Final Presentation General Medicine 03-08-2024.pptx
Sports Quiz easy sports quiz sports quiz
Insiders guide to clinical Medicine.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
VCE English Exam - Section C Student Revision Booklet
Classroom Observation Tools for Teachers
school management -TNTEU- B.Ed., Semester II Unit 1.pptx

PAI Unit 2 Segmentation in 80386 microprocessor

  • 1. Segmentation in 80386 Subject : Processor Architecture & Interfacing Class : SEIT Prepared By Ms. K. D. Patil, AP Department of IT, Sanjivani COE, Kopargaon. 2020/1/16 Prepared By: Ms. K. D. Patil 1
  • 2. Types of Address spaces ● Logical / Virtual address: Virtual addresses are used by an application program. They consist of a 16-bit selector and a 32-bit offset. In the flat memory model, the selectors are preloaded into segment registers CS, DS, SS, and ES, which all refer to the same linear address. ● Linear Addresses: Linear addresses are calculated from virtual/logical addresses by segment translation (Segmentation). The base of the segment referred to by the selector is added to the virtual offset, giving a 32-bit linear address. In segmentation, when paging is disabled linear address = physical address ● Physical Address: Physical Address is nothing but, the address value that appears on pins of processor during a memory read/memory write operations. Physical addresses are calculated from linear addresses through paging. The linear address is used as an index into the Page Table where the CPU locates the corresponding physical address. 2020/1/16 Prepared By: Ms. K. D. Patil 2
  • 3. Physical Address Formation in Real Mode 2020/1/16 Prepared By: Ms. K. D. Patil 3
  • 4. Physical Address Formation in Real Mode ● In the real mode, the 80386 can address at the most 1Mbytes of physical memory using address lines A 0 -A 19 . ● Paging unit is disabled in real addressing mode, and hence the real addresses are the same as the physical addresses. ● To form a physical memory address, appropriate segment registers contents (16-bits) are shifted left by four positions and then added to the 16-bit offset address formed using one of the addressing modes, in the same way as in the 80386 real address mode. ● The segment in 80386 real mode can be read, write or executed, i.e. no protection is available. ● Any fetch or access past the end of the segment limit generate exception 13 in real address mode. ● The segments in 80386 real mode may be overlapped or non- overlapped. ● The interrupt vector table of 80386 has been allocated 1Kbyte space starting from 00000H to 003FFH. 2020/1/16 Prepared By: Ms. K. D. Patil 4
  • 5. Address Translation in 80386 ● 80386 transforms logical addresses into physical address two steps: ● Segment translation: a logical address is converted to a linear address. ● Page translation: a linear address is converted to a physical address (optional) ● These translations are performed in a way that is not visible to applications programmers. 2020/1/16 Prepared By: Ms. K. D. Patil 5
  • 6. Address Translation in 80386 2020/1/16 Prepared By: Ms. K. D. Patil 6
  • 7. Protected Mode Addressing ● In this mode, the contents of segment registers are used as selectors to address descriptors which contain the segment limit, base address and access rights byte of the segment. ● The effective address (offset) is added with segment base address to calculate linear address. This linear address is further used as physical address, if the paging unit is disabled, otherwise the paging unit converts the linear address into physical address. ● The paging unit is a memory management unit enabled only in protected mode. The paging mechanism allows handling of large segments of memory in terms of pages of 4Kbyte size. ● The paging unit operates under the control of segmentation unit. The paging unit if enabled converts linear addresses into physical address, in protected mode. 2020/1/16 Prepared By: Ms. K. D. Patil 7
  • 8. Segmentation ● Addressable space of processor is divided into small parcels called as segments. ● Segmentation is one method of memory management. ● Segmentation provides the basis for protection. ● Segments are used to encapsulate regions of memory which have common attributes. ● For example, all of the code of a given program could be contained in a segment, or an operating system table may reside in a segment. 2020/1/16 Prepared By: Ms. K. D. Patil 8
  • 9. Segmentation ● Segments can be defined in 8 basic types – Data segments with or without write permission – Stack segments with or without write permission – Executable code segments with or without data read permission – Executable code segments with or without privilege protection 2020/1/16 Prepared By: Ms. K. D. Patil 9
  • 10. Segmentation ● Segments are – Areas of memory – Defined by programmer – Used for different purposes such as code, data and stack ● Segments are not – All the same size – Necessarily paragraph aligned – Limited to 64KB 2020/1/16 Prepared By: Ms. K. D. Patil 10
  • 11. Logical to Physical/ Linear Address Translation 2020/1/16 Prepared By: Ms. K. D. Patil 11
  • 12. Memory Management Through Segmentation ● Contents of segment registers (CS, DS, SS, ES, FS,GS) are used as selectors to address descriptors which contain the segment limit, base address and access rights byte of the segment. ● The processor must examine the value loaded in segment register. If TI (Table Indicator) bit is not set, processor uses index portion (bit 3 through 15) of selector as a pointer to GDT to find correct segment descriptor as well its upper limit can be located through GDTR. ● The processor then concentrates the fragments of base address field in the segment descriptor and comes up with the base address of respective segment. ● To this base address, it adds the offset. This is the linear address where operand actually located. 2020/1/16 Prepared By: Ms. K. D. Patil 12
  • 13. 2020/1/16 Prepared By: Ms. K. D. Patil 13
  • 14. 2020/1/16 Prepared By: Ms. K. D. Patil 14
  • 15. Segment Selector ● Segment Registers (CD,DS,SS,ES,FS,GS) are called as segment selectors OR ● Any 16 bit value that you write into segment register is called as selector because it selects a segment descriptor from a descriptor table. ● Segment registers selects segment Descriptors 2020/1/16 Prepared By: Ms. K. D. Patil 15
  • 16. Segment Selector ● There are 3 fields in segment selector – Index (Descriptor Index) (bit 3 through 15) : This value selects one of the 8192 descriptors in the descriptor table (8192*16 bit = 65536 bytes = 64KB long) – Table Indicator (bit 2) : Indicates which descriptor table you want to refer ● When TI = 0 , the index portion refers to descriptor in GDT ● When TI = 1 , the index portion refers to descriptor in LDT – Privilege checking (bit 0 & 1) : Used for privilege checking by the protection mechanism 2020/1/16 Prepared By: Ms. K. D. Patil 16
  • 17. Segment Descriptor ● All information about a segment is stored in an 8 byte data structure called a descriptor. ● All of the descriptors in a system are contained in tables recognized by hardware. ● Exactly one descriptor must be defined for each segment of memory to be used in running system ● Created by programmer ● Determines a segment’s base address 2020/1/16 Prepared By: Ms. K. D. Patil 17
  • 18. Segment Descriptor ● Determines – segment’s use – segment’s size – segment’s privilege level – whether segment has been accessed before ● Defines type of segment ● Defines Segment limit 2020/1/16 Prepared By: Ms. K. D. Patil 18
  • 19. Segment Descriptor Format 2020/1/16 Prepared By: Ms. K. D. Patil 19
  • 20. Segment Descriptor ● Base Address Bits – Lower 24 bits of segment address : 16 through 39 – Upper 8 bits of segment address : 56 through 63 – By internally concatenating the two portions of the base address field, the processor can determine the linear address at which segment starts. ● Limit Field – Lower 16 bits : 0 through 15 – Upper 4 bits : 48 through 51 – It is defined as length of segment in bytes minus 1 – The actual segment length is not used. The segment that is 1 byte length would have limit of 0 2020/1/16 Prepared By: Ms. K. D. Patil 20
  • 21. Segment Descriptor ● A (Access, Bit 40) – 80386 automatically sets this bit whenever a memory reference is made using the segment that this descriptor defines ● Type (Segment Type, Bit 41 through 43) – This 3 field indicates the types of segment you are defining, like code, data and stack ● S (System, Bit 44) – If this bit is clear, it indicates that it is a system segment descriptor. If it is clear it is non-system (code,data,stack) segment descriptor2020/1/16 Prepared By: Ms. K. D. Patil 21
  • 22. Segment Descriptor ● DPL (Descriptor Privilege Level, bit 45 and 46) – Indicates the level of privilege associated with the memory space that the descriptor defines. DPL 0 is most privilege and DPL3 is least privilege ● P (Present, bit 47) – If this bit is clear, address range that the descriptor defines is considered to be temporarily not present in physical memory ● U (User, bit 52) – Undefined and 80386 ignores this bit 2020/1/16 Prepared By: Ms. K. D. Patil 22
  • 23. Segment Descriptor ● D (Default size, bit 54) – When it is cleared, operands within the segment are assumed to be 32 bits ● G (Granularity, bit 55) – When it is cleared, 20 bit limit field is assumed to be measured in units of 1 byte. If it is set, Limit field is units of 4096 bytes 2020/1/16 Prepared By: Ms. K. D. Patil 23
  • 24. Types of Segment Descriptors 2020/1/16 Prepared By: Ms. K. D. Patil 24
  • 25. Non-system Segment Descriptors ● The format of descriptor is same , only the access byte rights changes. ● Type 0: Data segment with read permission ● Type 1: Data segment with read/ write permission ● Type 2,3: Stack segment ● The addressable range of a segment stretches from the base address to the base address plus limit definition. ● Valid offset ranges from 0 to limit. Any offset greater than limit are not considered part of the segment and are not addressable. 2020/1/16 Prepared By: Ms. K. D. Patil 25
  • 26. Expansion Direction 2020/1/16 Prepared By: Ms. K. D. Patil 26
  • 27. Expansion Direction ● In the stack segment, if the type field defines a stack (Type 2,3) then the limit field indicates what area of segment is not addressable. ● In the stack segment, all offsets must be greater than the limit. ● In case of data segments, all offsets less than or equal to limit are valid. The first addressable byte is at offset 0 and the last is at offset 1FFF, making data segment 2000 bytes (8KB) long 2020/1/16 Prepared By: Ms. K. D. Patil 27
  • 28. Expansion Direction ● In the stack segment, the first addressable byte is at offset 2000, and the last is at FFFF. Offset address 0 is not valid. ● In data segment, lower limit is set by base address field of the descriptor and upper limit is set by limit field. ● For stack segment, the lower limit is set by limit field and upper limit have 2 choices, - if D = 0, the upper limit is equal to the base address plus constant value FFFF (64KB) - if D = 1, the upper limit is equal to base address plus FFFFFFFF (4GB) ● A stack segment has minimum size when the limit is either FFFF (D = 0) or FFFFFFFF (D=1) producing a null segment with value zero length. 2020/1/16 Prepared By: Ms. K. D. Patil 28
  • 29. Non-system Segment Descriptors ● Type 4,5,6,7: Defines Executable segments. Here the code exists. ● Read permission is optional for the segments. If read permission is denied (Type 4), the segment must contain pure code, no constants are allowed since they cannot read out. Only code fetching is allowed. ● If read permission is given (type 5), you can embed constants in the code itself. Writing is never allowed to the executable code segment. ● The two executable code segments are repeated with the conforming attribute set (type 6,7). Conforming means these code segments voluntarily forgo their privilege level protection. 2020/1/16 Prepared By: Ms. K. D. Patil 29
  • 30. Non-system Segment Descriptors ● The format of descriptor is same , only the access byte rights changes. 2020/1/16 Prepared By: Ms. K. D. Patil 30
  • 31. System Segment Descriptors 2020/1/16 Prepared By: Ms. K. D. Patil 31
  • 32. System Segment Descriptors 2020/1/16 Prepared By: Ms. K. D. Patil 32 ● LDT Descriptor (Type 2) – They are Local descriptor tables, present only in GDT. – They contain information about LDT. – Can be accessed only at privilege level 0. ● Gate Descriptor (Type 4,5,6,7,C,E,F) – Allows 80386 to automatically perform the protection check – Call Gate: Changes privilege level – Task Gate: Performs a task switch – Interrupt Gate/ Trap Gate: Used to specify the interrupt service routines ● TSS (Task State Segment) Descriptor (Type 1,3,9, B) – When one task switches to another task, it stores all necessary information required to restart the task, where it was left – TSS stores the state/context of the task (location, size and privilege level) & linkage of next task
  • 33. References ● James Turley, "Advanced 80386 Programming Techniques", McGraw Hill Education. ● Slides shared by Prof. Tushar Kute at the time of PAI FDP