Docsity

Microprocessor Programming : 80386 Architecture, Paging, Modes and Pentium Pipeline, Study notes of Computer science

Toggle sidebar
bg1
1. Introduction to the Evolution of Intel Processors
The Intel 80386 (also called the i386) is a 32-bit microprocessor designed by Intel and released in
October 1985. It was an upgraded version of the 80286 microprocessor, with processing speed
roughly twice that of the 80286.
Key background points:
โ€ข 8086 was a 16-bit microprocessor; 80286 improved on it but was still limited in memory
addressing and protection.
โ€ข 80386 introduced a full 32-bit data bus, 32-bit address bus, and the concept of Virtual
Mode.
โ€ข It was the first Intel processor to introduce full memory protection (4 privilege levels) for
supporting multitasking operating systems.
1.1 Evolution Table of Intel Processors
Processor
Prefetch
Queue Size
CLK Speed
Data /
Address Bus
Special Features
4004
-
740 kHz
4 bits / 4 bits
World's first microprocessor
4040
-
-
4 bits / 4 bits
Interrupts were introduced
8008
-
-
8 bits / 8 bits
-
8080
-
2 MHz
8 bits / 16 bits
-
8085
-
3 MHz, 5 MHz
8 bits / 8 bits
Serial Communication introduced
8086
6
5, 8, 10 MHz
16 bits / 20
bits
Multibus compatible, pipelining
introduced, memory segmentation
concept
8088
4
5 MHz
8 bits / 20 bits
-
80186
6
5 MHz
-
2 on-chip timers, DMA controller,
interrupt controller
80286
6
6 MHz
16 bits / 24
bits
Memory protection to support
multitasking
80386
16
16, 20, 25, 33
MHz
32 bits / 32
bits
Concept of Virtual Mode
80486
32
25, 33, 50 MHz
-
Level 1 cache on-chip
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a

Partial preview of the text

Download Microprocessor Programming : 80386 Architecture, Paging, Modes and Pentium Pipeline and more Study notes Computer science in PDF only on Docsity!

1. Introduction to the Evolution of Intel Processors

The Intel 80386 (also called the i386) is a 32-bit microprocessor designed by Intel and released in October 1985. It was an upgraded version of the 80286 microprocessor, with processing speed roughly twice that of the 80286.

Key background points:

  • 8086 was a 16-bit microprocessor; 80286 improved on it but was still limited in memory addressing and protection.
  • 80386 introduced a full 32-bit data bus, 32-bit address bus, and the concept of Virtual Mode.
  • It was the first Intel processor to introduce full memory protection (4 privilege levels) for supporting multitasking operating systems.

1.1 Evolution Table of Intel Processors

Processor Prefetch Queue Size

CLK Speed Data / Address Bus

Special Features

4004 - 740 kHz 4 bits / 4 bits World's first microprocessor 4040 - - 4 bits / 4 bits Interrupts were introduced

8008 - - 8 bits / 8 bits -

8080 - 2 MHz 8 bits / 16 bits - 8085 - 3 MHz, 5 MHz 8 bits / 8 bits Serial Communication introduced

8086 6 5, 8, 10 MHz 16 bits / 20 bits

Multibus compatible, pipelining introduced, memory segmentation concept

8088 4 5 MHz 8 bits / 20 bits - 80186 6 5 MHz - 2 on-chip timers, DMA controller, interrupt controller

80286 6 6 MHz 16 bits / 24 bits

Memory protection to support multitasking

80386 16 16, 20, 25, 33 MHz

32 bits / 32 bits

Concept of Virtual Mode

80486 32 25, 33, 50 MHz - Level 1 cache on-chip

2. Overview of 80386DX

  • 32-bit microprocessor with a 32-bit ALU.
  • Two versions exist: 80386DX (Double Execution, 32-bit data bus) and 80386SX (Single Execution, 16-bit data bus). SX allows systems built for 8086 to gain some 80386 features without redesigning the whole system, since 8086 uses a 16-bit/2-bank data path.
  • Packaged in a 132-pin Ceramic Pin Grid Array (PGA). A PGA package is square/rectangular with pins arranged in a regular array on the underside, commonly spaced 2.54 mm apart.
  • Data bus: 32 bits. Address bus: 32 bits.
  • Physical memory addressability: 4 GB (2^32 = 4 GB). Virtual memory addressability: 64 TB.
  • Supports clock frequencies: 16 MHz, 20 MHz, 25 MHz, and 33 MHz.
  • Offers a 3-stage pipeline: Fetch, Decode, and Execute โ€” performed simultaneously, along with memory management and bus accessing, all operating in parallel. This reduces overall processing time and increases system performance.
  • Provides a hardware Protection Mechanism (PM) for memory.

3. Architecture of 80386DX

The 80386 has 5 functional units that all operate in parallel (pipelined):

  • Bus Interface Unit (BIU)
  • Code Prefetch Unit
  • Instruction Decode Unit
  • Execution Unit
  • Memory Management Unit (MMU)

3.2 Code Prefetch Unit

This unit fetches instructions from memory in advance, using the system buses, and stores them in a 16-byte prefetch queue so the CPU rarely has to wait for the next instruction.

  • Fetches instructions ahead of time; the order of fetching matches the order instructions exist in memory.
  • Fetches one double word (4 bytes) per memory access, so a single fetch may contain parts of two different instructions.
  • Code prefetching has lower priority than data transfer. Whenever the system needs to transfer data, the prefetcher immediately releases control of the buses so the BIU can transfer the required data.

3.3 Instruction Decode Unit

Instructions in memory are stored as bits. This unit decodes the instructions held in the prefetch queue.

  • The Instruction Decoder converts the machine language code into microcode/assembly-level form and passes it to the Execution Unit part (Decode and Sequencing, Control ROM) for further processing.
  • Decoded instructions are placed into a Decode Instruction Queue, which works as a FIFO (First In, First Out).

3.4 Execution Unit

The decoded instructions are supplied to the Execution Unit, which controls their execution.

  • Contains a 32-bit ALU (Arithmetic and Logic Unit) that performs operations on 32-bit data in a single cycle.
  • Contains 8 general-purpose registers and 8 special-purpose registers, used for data handling and calculation of offset addresses.
  • The control unit within it contains microcode and parallel hardware for fast multiply, divide, and effective address calculation.
  • Also includes a Barrel Shifter and a Multiply/Divide unit.

3.5 Memory Management Unit (MMU)

The MMU has two separate sub-units: the Segmentation Unit and the Paging Unit.

3.5.1 Segmentation Unit

Provides a protection mechanism to protect code or data in memory from application programs.

  • Gives 4 levels of protection to data/code in memory: Privilege Levels PL0 to PL3.
  • PL0 holds the highest priority (most privileged); PL3 holds the lowest priority (least privileged).
  • Rule: information stored at a given privilege level can only be accessed by programs running at that level or a higher-priority (lower-numbered) level.
  • Program with PL0 can access data with PL0, PL1, PL2, PL3 (i.e., everything).
  1. It changes the task map into 4K pages
  2. It supports multitasking.

3.5.3 Address Translation in Protected Mode

The 80386 converts a logical address (as viewed by the programmer) into a physical address (actual address in physical memory) in two steps:

Step 1: Segment Translation: Logical Address (Selector + Offset) โ†’ Linear Address, using Linear Address = Base Address + Offset.

Step 2: Page Translation: Linear Address โ†’ Physical Address (only if paging is enabled; if paging is disabled the linear address is used directly as the physical address).

4. 80386 Registers

The 80386 registers fall into four categories:

  • General Purpose Registers
  • EFLAGS Register (and Instruction Pointer)
  • Segment Registers
  • Control Registers

4.1 General Purpose Registers

  • 80386DX has eight 32-bit general-purpose registers: EAX, EBX, ECX, EDX, ESI, EDI, EBP, and ESP.
  • Used to hold instruction operands โ€” an operand may be data or an address.
  • The lower 16 bits of the 32-bit registers can be accessed separately using the 16-bit names AX, BX, CX, DX, SI, DI, BP, and SP.
  • When accessed as a 16-bit operand, the upper 16 bits of the register are neither used nor changed.
  • 8-bit operations can individually access the lowest byte (bits 0โ€“7) and the higher byte (bits 8 โ€“ 15) of AX, BX, CX, and DX.
  • Lowest bytes are named AL, BL, CL, DL (each 8-bit). Higher bytes are named AH, BH, CH, DH (each 8-bit).

4.2 Instruction Pointer (EIP)

  • The instruction pointer is a 32-bit register named EIP.
  • EIP holds the offset of the next instruction to be executed.
  • This offset is always relative to the base of the Code Segment (CS).
  • The lower 16 bits (bits 0โ€“15) of EIP form the 16-bit instruction pointer IP, used for 16-bit addressing.

4.3 EFLAGS Register

  • 80386DX has a 32-bit Flags Register named EFLAGS.
  • Controls certain processor operations and indicates the status of the 80386DX.
  • Contains information about: the result of the most recent arithmetic/logical operation, the state of the processor, and the state of the current task.
  • The lower 16 bits (bits 0โ€“15) of EFLAGS form the 16-bit FLAGS register, useful when executing 8086/80286 code.

ZF โ€” Zero Flag (bit 6) Set if all bits of the result are 0; otherwise reset. AF โ€” Auxiliary Carry Flag (bit 4)

Used to simplify addition/subtraction of packed BCD quantities. Set if the operation resulted in a carry out of bit 3; otherwise reset.

PF โ€” Parity Flag (bit 2) Set if the low-order 8 bits of the result contain an even number of 1s (even parity); reset if odd parity.

CF โ€” Carry Flag (bit 0) Set if the operation resulted in a carry out (addition) or a borrow into (subtraction) the high- order bit; otherwise reset.

4.4 Segment Registers

  • There are six 16-bit segment registers: CS, DS, ES, SS, FS, GS.
  • In real mode they contain the base address of a segment: CS = base address of the code segment; SS = base address of the stack segment; DS = base address of the data segment; ES, FS, GS = base addresses of other data segments.
  • The six 16-bit segment registers hold segment selector values identifying the currently addressable memory segments.
  • In protected mode, each segment may range in size from 1 byte up to 4 GB.
  • In real address mode, the maximum segment size is fixed at 64 KB.

4.5 Control Registers

The 80386DX has three 32-bit control registers, CR0, CR2, and CR3, that hold machine state of a global nature (not specific to an individual task). Load and store instructions are used to access them. (Note: full protection-mode features are available only in Protected Mode.)

4.5.1 CR0 โ€” Machine Control Register

CR0 includes the 80286 Machine Status Word (MSW) in its low-order 16 bits, retained for compatibility with 80286 Protected Mode. It contains 6 defined bits for control and status purposes.

Bit Meaning

PG โ€” Paging Enable (bit 31)

Set to enable the on-chip paging unit; reset to disable it.

R โ€” Reserved (bit 4) Reserved by Intel. Care must be taken not to alter this bit's value when loading CR0.

TS โ€” Task Switched (bit 3)

Set automatically by the processor whenever a task switch operation is performed. Never cleared automatically; the programmer can clear it using the CLTS instruction.

EM โ€” Emulate Coprocessor (bit 2)

Set to cause all coprocessor opcodes to generate a coprocessor-not- available fault (exception 7). Reset to allow coprocessor opcodes to run on an actual Intel 387DX coprocessor.

MP โ€” Monitor Coprocessor (bit 1)

When set, the 80386 assumes real floating-point hardware is present. When reset, it assumes no such hardware is present. PE โ€” Protection Enable (bit 0)

Set to enable Protected Mode. If reset, the processor operates in Real Mode. PE can be set using the LMSW (Load Machine Status Word) instruction but cannot be reset using LMSW.

4.5.2 CR1, CR2, CR

  • CR1 โ€” Reserved for future use by Intel.
  • CR2 โ€” Page Fault Linear Address register. Holds the 32-bit linear address that caused the last detected page fault.
  • CR3 โ€” Page Directory Base Address register. Contains the physical base address of the page directory table. A task switch through a TSS (Task State Segment) changes the value in CR3.
  • Grants access to privileged instructions and registers not available in Real Mode.
  • Supports virtual memory, allowing the system to use more memory than is physically available by swapping pages to and from disk.
  • In Protected Mode, the 80386 operates similarly to the 80286 but with much higher memory-addressing capability.

5.3 Virtual 8086 Mode

Allows the 80386 to run multiple virtual environments simultaneously, each compatible with the 8086, while sharing the same physical memory.

  • Each virtual environment has its own registers and memory space.
  • Frequently used to run older DOS-era applications on more modern systems/operating systems.
  • A system for handling interrupts and exceptions allows the 80386 to switch between virtual environments as needed.
  • Simulates the behavior of a real 8086 CPU within a protected virtual memory environment, letting multiple virtual machines run without interfering with one another.
  • Related concept โ€” Virtual Real Mode: allows the system to run multiple programs in protected memory such that if one program crashes, it does not adversely affect other parts of memory.

5.4 Comparison of Modes

Mode Address Space

Register Size

Key Features Typical Use Case

Memory Management Features

Backward Compatibilit y

Real Mode

1 MB

(20-bit)

16 - bit No protection; segmentation (segment ร— 16 + offset); fully backward compatible

DOS,

system startup, legacy software

None Fully compatible with 8086/ processors

Protected Mode

4 GB

(32-bit)

32 - bit Memory protection, multitasking, paging, privilege levels, virtual memory

Modern OS (Linux, Windows NT/95, etc.)

Segmentation, Paging, privileged instructions

Partial compatibility with 8086/ processors

Virtual 8086 Mode

1 MB per virtual machine

16 - bit (virtual)

Runs 8086 programs inside protected mode; supports multiple DOS apps

DOS apps inside a multitaskin g OS (Windows)

Virtualization of 8086 environment

Fully compatible with 8086/ processors

System Managem ent Mode (SMM)

Hidden (separate address space)

  • Power management, hardware control, entered via SMI (System Management Interrupt)

System- level power/ther mal managemen t

6. Pentium Architecture

6.1 Introduction

The Pentium architecture is a family of x86 microprocessors introduced by Intel in 1993. It was the successor to the Intel 80486 (i486) and the first processor in the Pentium line. The architecture has since evolved through several generations, including Pentium II, Pentium III, Pentium 4, and Pentium D.

6.2 Clock Speed and Performance

  • The original Pentium processor had a clock speed of 60 MHz, later increased to 66 MHz and then to 100 MHz.
  • This high clock speed, combined with the architecture's superscalar design, allowed Pentium processors to achieve high performance across a variety of applications.

6.3 Cache Memory

  • The Pentium architecture features cache memory: a small amount of high-speed memory used to store frequently accessed data and instructions.
  • Cache is divided into two levels: Level 1 (L1) and Level 2 (L2).
  • L1 cache is located on the processor itself; it is very fast but has small capacity.
  • L2 cache is located outside the processor; it is larger but slower than L1 cache.

6.7 Applications

  • Embedded systems, such as automotive systems, medical devices, and industrial robots.
  • Mobile devices, such as smartphones and tablets.
  • Server applications, such as web servers and database servers.

Overall, the Pentium architecture is a powerful set of instructions and features that allows efficient and reliable computing, and it played a significant role in the development of personal computing over the past few decades.

7. Pentium Internal Architecture Details

7.1 Key Functional Blocks (from Pentium block diagram)

BTB (Branch Target Buffer) โ€” Holds addresses and converts the linear address into the physical address used by the code cache (instruction cache). It also sends instructions to the prefetch buffer.

Code cache โ€” Holds instructions and sends them on to the prefetch buffer.

TLB (Translation Lookaside Buffer) โ€” A cache used to speed up translation from linear to physical addresses.

Prefetch Buffer (2โ€“32 bytes) โ€” There are two prefetch buffers (M and Code Cache Prefetch Buffer). Both operate independently, but not at the same time โ€” one buffer fetches instructions sequentially until a branch instruction occurs.

7.2 Five-Stage Pipeline

The Pentium uses a 5-stage pipeline:

    1. Prefetch
    1. Decode-1 (D1)
    1. Decode-2 (D2)
    1. Execute
    1. Writeback

The Pentium has two parallel integer pipelines:

  • U-Pipeline โ€” responsible for executing all integer as well as floating-point instructions.
  • V-Pipeline โ€” responsible for executing simple integer, sum, and some floating-point instructions.

7.3 Control ROM

  • Controls the operation of the Pentium processor.
  • Contains microcode: a very low-level instruction set stored permanently in ROM that controls the operation of the device.
  • The Control ROM directly controls both the U-pipeline and V-pipeline.

7.4 Code and Data Cache

  • The code cache connects to the prefetch buffer via a 256-bit bus, so 256/8 = 32 bytes of opcode can be buffered in one clock cycle.
  • The data cache has two ports, allowing it to simultaneously service two data references.

7.5 Superscalar Operation

Superscalar operation means the Pentium can issue and execute more than one instruction per clock cycle by running the U-pipeline and V-pipeline in parallel.

7.7 Pentium Block Diagram โ€” Stage-by-Stage Description

Pentium uses a 5-stage pipeline with the following stages, as shown in the block diagram:

1. Pre-fetch stage: Instructions are prefetched from the on-chip instruction cache. 2. Decode1 (D1): Two parallel decoders attempt to decode and issue the next two sequential instructions. Checks whether the instructions can be paired for simultaneous execution, decodes the instruction to generate a control word, and participates in branch address prediction. 3. Decode2 (D2): Decodes the control word; the address of memory-resident operands is calculated in this stage. 4. Execute stage: Carries out data cache fetch, ALU operation, or FPU (Floating Point Unit) operation. The execution unit contains two integer pipelines (U-pipe and V-pipe), each with its own separate ALU. 5. Write back stage: Registers and flags are updated based on the results of execution.

7.8 Floating-Point Pipeline (8 Stages)

Data type handled: real numbers (fractions, decimal values). Hardware requirement: FPU and co- processor. Note: FP instructions do not get paired with integer instructions.

1. Prefetch (PF): Instructions are prefetched from the on-chip instruction cache. 2. Instruction Decode (D1): Two parallel decoders attempt to decode the next two sequential instructions; checks whether the instructions can be paired; decodes the instruction to generate a control word. 3. Address Generate (D2): Decodes the control word; address of memory-resident operands is calculated. 4. Memory and Register Read โ€” Execution Stage (EX): Register read or memory read is performed as required by the instruction to access an operand. 5. Floating Point Execution Stage 1 (X1): Information from register or memory is written into the FP register. Data is converted to floating-point format before being loaded into the floating- point unit. 6. Floating Point Execution Stage 2 (X2): The floating-point operation is performed within the floating-point unit. 7. Write FP Result (WF): Floating point results are rounded and the result is written to the target floating-point register.