Darshan Institute of Engineering & Technology: Advance Processors UNIT-2
Darshan Institute of Engineering & Technology: Advance Processors UNIT-2
Darshan Institute of Engineering & Technology: Advance Processors UNIT-2
- If the program is not available in the physical memory, it is brought from the secondary memory to
the physical memory for execution.
- If available space is inadequate in the physical memory, some less important or unused program
can be swapped back to the secondary memory to create space.
5. Explain Operating Modes of 80286
80286 works in two operating mode:
i. Real Address Mode (Just act as a fast 8086).
- Instruction set is upwardly compatible
- Because of extra pipelining and other circuit level improvements, in real address mode
also, the 80286 operates at a much faster rate than 8086, although functionally they
work in an identical fashion.
- As in 8086, the physical memory is organized in terms of segments of 64Kbyte
maximum size.
- In the real mode the first 1Kbyte of memory starting from address 0000H to 003FFH is
reserved for interrupt vector table.
- The addresses from FFFF0H to FFFFFH are reserved for system initialization.
- When the 80286 is reset, it always starts the execution in real address mode.
- In real address mode, it initializes the IP and other registers of 80286.
- Each task assigned a privilege level, which indicates the priority or privilege of that task.
- It can only changed by transferring the control, using gate descriptors, to a new segment.
- A task executing at level 0, the most privileged level, can access all the data segment defined in
GDT and LDT of the task.
- A task executing at level 3, the least privileged level, will have the most limited access to data and
other descriptors.
- The use of rings allows for system software to restrict tasks from accessing data.
- In most environments, the operating system and some device drivers run in ring 0 and applications
run in ring 3.
7. What is Descriptor table? What is its use? Differentiate between GDT and LDT.
Ans - Descriptor is a identifier of a program segment or page.
- A segment cannot be accessed, if its descriptor does not exist in either LDT or GDT.
- Set of descriptor (descriptor table) arranged in a proper sequence describes the complete program.
- The descriptor is a block of contiguous memory location containing information of a segment, like
i. Segment base address
ii. Segment limit
- The memory management section of 80386 supports virtual memory, paging and four levels of
protection.
- The 80386 includes special hardware for task switching.
11. Explain 80386 Architecture
Ans - The internal architecture of the 80386 includes six functional units that operate in parallel. The
parallel operation is called as pipeline processing.
- Fetching, decoding execution, memory management, and bus access for several instructions are
performed simultaneously.
- The six functional units of the 80386 are
1. Bus Interface Unit
2. Code Pre-fetch Unit
3. Instruction Decoder Unit
4. Execution Unit
5. Segmentation Unit
6. Paging Unit
decode unit.
- The instruction decode unit translates instructions from the pre-fetch queue into micro-codes.
The decoded instructions are then stored in an instruction queue (FIFO) for processing by the
execution unit.
- The execution unit processes the instructions from the instruction queue. It contains a control
unit, a data unit and a protection test unit.
- The control unit contains microcode and parallel hardware for fast multiply, divide and effective
address calculation. The unit includes a 32-bit ALU, 8 general purpose registers and a 64-bit barrel
shifter for performing multiple bit shifts in one clock. The data unit carries out data operations
requested by the control unit.
- The protection test unit checks for segmentation violations under the control of microcode.
- The segmentation unit calculates and translates the logical address into linear addresses at the
request of the execution unit.
- The translated linear address is sent to the paging unit. Upon enabling the paging mechanism, the
80386 translates these linear addresses into physical addresses. If paging is not enabled, the
physical address is identical to the linear address and no translation is necessary.
11. Register organization of 80386
Ans The Register organization of 80386 is as follows:
registers.
- EAX (ACCUMULATOR): The accumulator is used for instructions such as multiplication, division and
some of the adjustment instructions. In 80386 and above, the EAX register may also hold the offset
address of a location in memory system.
- EBX (BASE INDEX): This can hold the offset address of a location in the memory system in all
version of the microprocessor. It the 80386 and above EBX also can address memory data.
- ECX (count): This acts as a counter for various instructions.
- EDX (data): EDX is a general-purpose registers that holds a part of the result for multiplication or
part of the division. In the 80386 and above this register can also address memory data.
Pointer and Index Register
- EBP (Base Pointer): EBP points to a memory location in all version of the microprocessor for
memory data transfers.
- ESP (Stack Pointer): ESP addresses an area of memory called the stack. The stack memory is a
data LIFO data structure. The register is referred to as SP if used in 16 bit mode and ESP if referred
to as a 32 bit register.
- EDI (Destination index): EDI often addresses string destination data for the string instruction. It
also functions as either a 32-bit (EDI) or 16-bit (DI) general-purpose register.
- ESI (Source index): ESI can either be used as ESI or SI. It is often used to the address source
string data for the string instructions. Like EDI ESI also functions as a general-purpose registers.
EIP (Instruction Pointer): EIP addresses the next instruction in a section of memory defined as a code
segment. This register is IP (16bit) when microprocessor operates in the real mode and EIP (32 bits) when
80386 and above operate in protected mode
- LDTR (Local Descriptor Table Register) and TR (Task Register) can be loaded with instructions which
take a 16-bit segment selector as an operand.
address mode.
- MP (Math Present, bit 1)
MP controls the function of the WAIT instruction, which is used to coordinate a coprocessor.
- EM (Emulation, bit 2)
EM indicates whether coprocessor functions are to be emulated.
- TS (Task Switched, bit 3)
The processor sets TS with every task switch and tests TS when interpreting coprocessor
instructions.
- ET (Extension Type, bit 4)
ET indicates the type of coprocessor present in the system (80287 or 80387).
- PG (Paging, bit 31)
PG indicates whether the processor uses page tables to translate linear addresses into physical
addresses.
CR2:
- CR2 is used for handling page faults when PG is set. The processor stores in CR2 the linear address
that triggers the fault.
- Contains a value called Page Fault Linear Address (PFLA). When a page fault occurs, the address
the program attempted to access is stored in the CR2 register.
CR3:
- It is used when virtual addressing is enabled; hence when the PG bit is set in CR0, CR3 enables the
processor to translate linear addresses into physical addresses by locating the page directory
and page tables for the current task.
- Typically, the upper 20 bits of CR3 become the page directory base register (PDBR), which stores
the physical address of the first page directory entry.
Note: Reserved field shown in figure are kept reserved by manufacturer
13. Explain Debug Register in detail.
Ans Debugging of 80386 allows data access breakpoints as well as code execution breakpoints.
- 80386 contains 6 debug registers to specify
4 breakpoints
Breakpoint Control options
Breakpoint Status
- The program invisible registers are not directly addressed by software so they are given name.
- The GDTR (global descriptor table register) and IDTR (interrupt descriptor table register) contain
the base addresses of the descriptor table and its limit.
- The limit of each descriptor table is 16 bits because the maximum table length is 64 Kbytes.
- When the protected mode operation is desired, the address of the global descriptor table and its
limit are loaded into the GDTR.
16. Explain Real Modes of 80386
Ans - Default Mode
- After reset, the 80386 starts from the memory location FFFFFFF0 H under real address mode.
- In real address mode, 80386 works as a fast 8086 with 32 bit registers and data types.
- Real-address mode is in effect after a signal on the RESET pin. Even if the system is going to be
used in protected mode, the start-up program will execute in real-address mode temporarily while
initializing for protected mode.
- The addressing techniques, memory size, interrupt handling in this mode of 80386 are similar to
the real addressing mode of 80286.
- In real address mode, the default operand size is 16 bit but 32 bit operands and addressing modes
may be used with the help of override prefixed.
- Maximum physical memory = 1Mega byte (1MB)
- The only way to leave real-address mode is to switch to protected mode.
17. Explain PVAM of 80386
Ans - Introduced in the 80386 processor.
- 32-bit address bus => access up to 232 bytes = 22. 230 B = 4 GB
- Base address => 32-bit value
- Offset =>16-bit or 32-bit value
- Linear address = base address + offset
- Linear address physical address with paging
- In protected mode, the segment registers contain an index into a table of segment descriptors.
- Each segment descriptor contains the start address of the segment, to which the offset is
added to generate the address.
- In addition, the segment descriptor contains memory protection information.
- This includes an offset limit and bits for write and read permission.
- This allows the processor to prevent memory accesses to certain data.
- Protected mode is accessed by placing a logic 1 into the PE bit of CR0
- This system contains one data segment descriptor and one code segment descriptor with each
segment set to 4G bytes in length.
- PVAM mode support memory management, virtual memory, multitasking, protection, debugging,
segmentation and paging.
45-46 DPL (Descriptor Indicates privilege level associated with memory space. 0 - most
Privilege level) privileged 3 least privileged
47 Present If set 0 , indicates that the address range that is specified by the
descriptor is temporarily not present.
53 X Reserved by Intel
- The Above figure is the format of the code/data descriptor; one descriptor is 64-bit long.
- As we can see, a descriptor actually includes a 32-bit base address and a 20-bit limit and some
attributes, the 32-bit base address indicate where the segment starts, and the 20-bit limit indicates
the length of the segment.
- However, a problem comes up, 20-bit limit can only represent 2^20 = 1MB memory, to access a
4GB memory space, descriptor uses G bit to indicate whether the limit use 4K or 1 byte for one
unit, that means if G bit is set then we get 2^20*4K = 4GB memory, if it is unset then we only use
a memory space under 1MB.
21. Explain Descriptor tables in 80386
Ans - The segment descriptors that we defined are grouped together and placed in a continuous memory
location. The group arrangement called Descriptor Table.
- Each descriptor requires 8byte in order to store the info of a particular segment.
- Descriptor table can contain 8192(8K) descriptors at the max.
- The maximum length of a descriptor table is a 64Kbytes.
- The descriptor tables define all the segments used in the 80386 when it operates in the protected
mode.
- There are three types of descriptor tables: the global descriptor table (GDT), the local descriptor
table (LDT), and the interrupt descriptor table (IDT).
- The registers used by the 80386 to address these three tables are called the global descriptor table
register (GDTR), the local descriptor table register (LDTR), and the interrupt descriptor table
register (IDTR).
- These registers are loaded with the LGDT, LLDT, and LIDT instructions, respectively.
- The local and global descriptor tables hold up to 8192 entries each, and the interrupt descriptor
table holds up to 256 entries.
- A descriptor is indexed from either the local or global descriptor table by the selector that appears in
a segment register.
- Whenever a new selector is placed into one of the segment registers, the 80386 accesses one of the
descriptor tables and automatically loads the descriptor into a program-invisible cache portion of the
segment register.
Global Descriptor Table (GDT):
- This is the main table of descriptors.
- The same GDT can be used by all programs to refer to segment of memory.
- 80386 can have many LDTs but only one GDT.
- Each entry in the page directory translates the leftmost 10 bits of the memory address. This 10-bit
portion of the linear address is used to locate different page tables for different page table entries.
Page Table
- The page table contains 1024 physical page addresses, accessed to translate a linear address into a
physical address.
Page Directory Entry
- Total Page Directory Entries are1024
- Each directory entry is of 4 byte
- P-bit: Present bit, if logic 1 indicates that the entry can be used in address translation. If P = 0,
the entry cannot be used for translation. When P = 0, the remaining bits of the entry can be used to
levels:
i. Supervisor level (U/S=0) -- for the operating system and other systems software and
related data.
ii. User level (U/S=1) -- for applications procedures and data.
The current level (U or S) is related to CPL. If CPL is 0, 1, or 2, the processor is executing at
supervisor level. If CPL is 3, the processor is executing at user level. When the processor is
executing at supervisor level, all pages are addressable, but, when the processor is
executing at user level, only pages that belong to the user level are addressable.
2. Type checking:
At the level of page addressing, two types are defined:
i. Read-only access (R/W=0)
ii. Read/write access (R/W=1)
When the processor is executing at supervisor level, all pages are both readable and
writable. When the processor is executing at user level, only pages that belong to user level
and are marked for read/write access are writable; pages that belong to supervisor level are
neither readable nor writable from user level.
28. Explain the concepts of Call gates with suitable example.
Ans - Call Gates are required at procedure entry point check.
- Call gates allow a program to directly call system calls.
- However, since system calls are often in a privileged ring, calling them directly is not allowed
because of the ring protection. The 80386 protection mode uses a call-gate concept to allow this
kind of transfer.
- Call gates enable programs in a lower privileged ring to jump to designated places in a higher
privileged ring.
- It is used to control the transfer of execution between procedures of different privilege level.
Privilege Check for Control Transfer without Using a Gate (Figure b):
Policy
- For non-conforming segment: transfer is allowed when CPL = DPL.
- For conforming segment: transfer is allowed when CPL >= DPL.
- RPL does not have much effect here.
Why cant we access code with a higher DPL (i.e., lower privilege)?
- Possible reason 1:
It is easy to jump (lower the CPL) to the code with higher DPL, but it is difficult to return back,
because on returning, we jump from a lower privileged ring to a higher privileged ring. This violates
the mandatory access control policy.
- Possible reason 2:
Another reason is the data access. If a code A jumps to another code B at a lower privilege level, B
cannot access As data because the data are most likely in As ring level.
- Possible reason 3: Is there really a need to allow jumping from a higher privilege to a lower
privilege?
Why cant we jump to code with a lower DPL (i.e., higher privilege)?
- For security reasons, we cannot do this.
How can we achieve jumping to lower DPL?
- Gates are designed for this purpose.
30. Multitasking in 80386
Ans - Protected mode has the ability to support execution of multiple programs (called tasks)
simultaneously.
Task Descriptor
- The BASE, LIMIT, and DPL fields and the G-bit and P-bit have functions similar to their counterparts
in data-segment descriptors.
- A procedure that has access to a TSS descriptor can cause a task switch.
- TSS descriptors may reside only in the GDT
- These mechanisms operate only in protected mode, including virtual 8086 mode; they do not
operate in real mode.
- In real mode, there is no protection of the I/O space; any procedure can execute I/O instructions,
and any I/O port can be addressed by the I/O instructions.
I/O Privilege Level (IOPL):
- Instructions that deal with I/O need to be restricted but also need to be executed by procedures
executing at privilege levels other than zero.
- For this reason, the processor uses two bits of the flags register to store the I/O privilege level
(IOPL).
- The IOPL defines the privilege level needed to execute I/O-related instructions.
- I/O instructions can be executed only if CPL <= IOPL
I/O Permission Bit Map:
- The I/O operations are allowed on a port by port basis via permission bits stored in the I/O
permission bit map section of the tasks TSS.
- Each byte in the bit map stores permission bits for eight consecutive ports.
Cache Unit :
- 8KB cache
- Additional high speed cache memory provides a way of improving overall system performance.
- It Contains the recently used instructions, data or both.
- The main aim is that the microprocessor unit access code and data in the cache most of time,
instead from the main memory.
41. Explain EFLAG Register Of The 80486.
Ans The extended flag register EFLAG is illustrated in the figure below:-