Professional Documents
Culture Documents
SHARING
ACCESSING RESOURCES
If file is to printed – it cannot be done in 10ms interval
So several access attempts are required
Other processes may also be currently accessing resources
Flag/Semaphore
While the process is using the resource – semaphore set
When resource released – semaphore reset
One process
incrementing a value in a given memory location
Read value
Inc value
Write value
Two processes
2 processes are running incrementing a single, shared
memory location
Read value
Suspend
Inc value
Task1
Read value
Inc value
Restore
Write value Task1
Write value
MEMORY PROTECTION
Section of the program where the value of the variable is being
examined and changed must be protected – until tasks complete
This section of code – critical section
Memory protection technique used - mutex
USER 1 /USER2 -CS
MOV AL,01
X1: XCHG AL,SEMAPHORE
CMP AL,01
JE X1
……
MOV SEMAPHORE,00
80286,80386 &
80486
Memory Management
Global Space
Global
Data
OS
Data
OS OS
Code Data
A OS OS C
Code Data Data Code
OS
A Data C
Data Data Task C
B B
Task A Code Data
Task B
Memory Management – why?
Size of Physical memory
Executing Tasks should not access protected memory
Memory management functions can be minimally implemented
by OS
But for completed Memory Management H/w support is
needed
MMU
Virtual memories & MMU
In Virtual Memory System
Code & Data currently used for execution are loaded from
disk into RAM
If executing program needs a segment currently not in
memory – segment is moved from disk to memory
If DRAM is full it is swapped with existing segment
Setting up of code and data blocks
for swapping
Swap segments
Fixed sized pages
Logical segments – divide into 4k spaces
80386/80486
Virtual Memory
Refers to memory space that appears to be present from the
programmer’s point of view but is not physically present in the
DRAM
Virtual memory is larger as not all logical segment are present
in memory
This works b’coz most programs need only small section of
data/code at a particular time
80286, 80386 &
80486
Memory Protection
MMU
Handle virtual Memory
Functionally positioned between processor and actual
memory
ALP – logical address/ labels
When program assembled logical address is replaced
by segment and offset in 8086
If MMU – selector and offset – descriptor
Descriptor – physical base address of segment ,
privilege level and some control bits
Selector Offset Logical Address
Physical Address
80286 – Virtual Memory
1GB
MMU functions
Logical address received
MMU checks to see if segment is present in memory
If yes – Calculates Physical Address
If segment not present in memory it raises an int to processor
ISR – Read code from HDD and transfer into memory
Op is semi automatic – hence delay negligible
Well structured MMU hit rate 90-95 %
MMU & Memory protection
Selector – Privilege level
Descriptors – Privilege level
Segment selector ≥ Descriptor
Access Allowed
80286, 80386 &
80486
Special Registers
MSW
TS EM MP PE
Switched
EmulateCoprocessor
Tasks
–Protect
INT7 Enabled
present
Special 80386 Registers
P 000 0000 0000 0000 0000 0000 000 E T E M P
G T S M P E
Not Used
Selects 80287 as
Pageco-processor
Fault Linear Address
GDTR
IDTR
Segment Privilege levels
Checks
1. Valid descriptor
2. Descriptor – beyond limits of DT – exception
3. Right type
Read only –SS
Execute only –DS
4. P –bit is checked
INT 11 if not
Segment Privilege Level
5. After loading
Write CS
Write read-only data
Inst address should not cross limits defined for
segment
3000 0200
GDTR
IDTR
Task Switching
Each task is assigned a Task State Segment
TSS contains
Register & Flag contents
Selector for tasks LDT
Link to TSS of previously executing task(Call/INT)
Task State Segment
Call/Jump
Directly Point
Indirectly Point via Task Gate
INT
Indirect via Task Gate
IRET
0000 0000 0000 0000 Link
ESP0
0000 0000 0000 0000 SS0
ESP1
0000 0000 0000 0000 SS1
ESP2
0000 0000 0000 0000 SS2
CR3
EIP
EFLAGS
EAX
ECX
EDX
EBX
ESP
EBP
ESI
EDI
0000 0000 0000 0000 ES
0000 0000 0000 0000 CS
0000 0000 0000 0000 SS
0000 0000 0000 0000 DS
0000 0000 0000 0000 FS
0000 0000 0000 0000 GS
0000 0000 0000 0000 LDT
Available T
Available to user
Task Switch using TSS - direct
1. CALL/JMP – Far
Segment – Selector
2. CPL & RPL ≤ DPL
If no- exception
3. Check if TSS is in memory
If no loaded into memory by exception ISR
4. Copies Current Task’s Registers content to
Current Tasks TSS
5. Load TR with selector & descriptor of new task
TSS
6. Register values copied from TSS into registers
7. New task Begins
Task Switch using TSS – indirect –Task gate
1. CALL/JMP – Far
Segment – Selector
2. CPL & RPL ≤ DPL
If no- exception
3. Task Gate
Selector - descriptor
3. Check if TSS is in memory
If no loaded into memory by exception ISR
4. Copies Current Task’s Registers content to
Current Tasks TSS
5. Load TR with selector & descriptor of new task
TSS
6. Register values copied from TSS into registers
7. New task Begins
80386 & 80486
Paging
Paging – 80386 onwards
Linear – physical
CR0 – CR3
Page directory – 1024 entries – 4 bytes – each point to Page
Table
Page table – 1024 entries – 4 bytes – each point to Page
Page block of 4k
CR0 -3
CR0 – MSB PG bit, CD, NWT
CR3 – BITS 12 -31- base address of Page Directory
PD/ PT ENTRY
P P
Address (31-12) D A C W U W P
D T
U W PL3 PL0-2
0 0 None Read/Write
0 1 None Read/Write
1 0 Read only Read/Write
1 1 Read/Write Read/Write
TLB – Translation Look ahead buffer
Cache
Page table entries for 32 most recently used tables
Linear Address – upper 20 –bit tags