Unit 3 - MMA
Unit 3 - MMA
Unit 3 - MMA
Applications
Course Code: CSE2PM02A Credits: 3 TH
9/25/2024 8
Unit 3 MMA-CSE2PM02A 2024-25 S3
Data Segment Descriptor
OR
DPL >= Max(CPL and RPL)
DPL =3
1
CPL =2
RPL = 1
3
⮚To access operand from Data Segment, the segment selector must
be loaded into the data segment register (DS,ES,FS or GS) or SS
CPL = DPL
Achieved by checking conditions based on
RPL, DPL and CPL
The NEAR forms of the JMP, CALL, and RET instructions transfer
program control within the current code segment, so privilege-level
checks are not performed.
9/25/2024 Unit 3 MMA-CSE2PM02A 2024-25 S3 32
Privilege Level Checking When Accessing Other Code Segments
⮚ Code segments can be either conforming or nonconforming.
⮚ A transfer of execution from code (e.g. CPL=3) into a more privileged conforming
segment(e.g. CPL=1) allows execution to continue at the current privilege level
(i.e. CPL=3).
⮚ A transfer of execution from code segment into a nonconforming segment at a
different privilege level results in a general-protection exception (#GP), unless a
call gate or task gate is used
Rule
DPL = CPL
Code Segment
X One code segment can access another non
conforming code segment with different
Data Segment Register
CPL = 1 RPL = 1 privilege level only using a special descriptor
called “Call Gate” which is discussed later in
the unit.
9/25/2024 Unit 3 MMA-CSE2PM02A 2024-25 S3 36
Code accessing Code (Conforming Code Segments)
Code Segment ------(Accessing)----🡪 Conforming Code Segment [C=1]
⮚Can be called by a code with CPL >= DPL of destination code
segment
⮚Conforms to the privilege level of the caller code
⮚E.g. If PL 3 code transfers control to a conforming code segment
then conforming code runs at CPL=3.
⮚CPL does not change
⮚Allow sharing by codes with different privilege levels
⮚Application – math libraries
Call Gates
⮚ System descriptor
⮚ Do not define any memory space
⮚ Defines entry points in a more privileged
code to which control can be transferred
⮚ Only way to inter level transfer control
⮚ Must be invoked using CALL instruction
(therefore name is CALL Gate)
RPL
Gate DPL
Target DPL
0 0 0 0,1,2,3 0
1 1 0,1 1,2,3 0,1
2 2 0,1,2 2,3 0,1,2
3 3 0,1,2,3 3 0,1,2,3
Gate
for X
Question:
Question:
9/25/2024 Unit 3 MMA-CSE2PM02A 2024-25 S3 60
Task Structure
⮚ A task is made up of two parts: a task execution space and a task-state
segment (TSS). TSS requires 104 bytes (68 H) memory space.
⮚ The task execution space consists of a code segment, a stack segment, and
one or more data segments.
⮚ The TSS specifies the segments that make up the task execution space
and provides a storage place for task state information.
⮚ In multitasking systems, the TSS also provides a mechanism for linking
tasks.
⮚ A task is identified by the segment selector for its TSS. When a task is
loaded into the processor for execution, the segment selector, base address,
limit, and segment descriptor attributes for the TSS are loaded into the
Task Register (TR).
9/25/2024 Unit 3 MMA-CSE2PM02A 2024-25 S3 61
Static set (Green Colour)
TSS- Task State Segment (TSS requires 104 bytes (68 H) memory space)
⮚ It is that where processor reads but
does not change.
⮚ This set includes the fields that store: The
selector of the task's LDT.
⮚ The register (PDBR) that contains the base
address of the task's page directory (read only
when paging is enabled).
⮚ Pointers to the stacks for privilege levels 0-2.
⮚ The T-bit (debug trap bit) which causes the
processor to raise a debug exception when a
task switch occurs.
⮚ The I/O map base address
Dynamic set (Blue Colour)
⮚ where processor updates with each switch from the
task.
⮚ This set includes the fields that store: The general
registers (EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI).
⮚ The segment registers (ES, CS, SS, DS, FS, GS).
⮚ The flags register (EFLAGS).
back link field ⮚ The instruction pointer (EIP).
26 Rows, each row=4 bytes ⮚ The selector of the TSS (back link field) of the previously
executing task (updated only when a return is expected).
⮚ The I/O map base address points to the beginning of the I/O
permission bit map and the end of the interrupt redirection bit map.
Task Gate
Descriptor
⮚ The SELECTOR field of a task gate must refer to a TSS descriptor. The
value of the RPL in this selector is not used by the processor.
⮚ The DPL field of a task gate controls the right to use the descriptor to cause a task
switch.
⮚ A procedure may not select a task gate descriptor unless the maximum of the
selector's RPL and the CPL of the procedure is numerically less than or equal to
the DPL of the descriptor.
Max(CPL,RPL) <= Task Gate DPL
⮚ Task Gate can reside anywhere in GDT, LDT or IDT.
9/25/2024 Unit 3 MMA-CSE2PM02A 2024-25 S3 84
Task Switching
The Processor switches execution to another task in
any of Four cases:
1. The current task executes a JMP or CALL that refers to a TSS
descriptor.
2. The current task executes a JMP or CALL that refers to a Task Gate.
3. An interrupt or exception vectors to a task gate in the IDT.
4. The current task executes an IRET when the NT flag is set.
Question: Which four methods are used to invoke a task? Describe the steps involved in task
switching. What is the significance of NT bit and back link field?