The various x86 ‘modes’ On understanding key differences among the processor’s several execution-architectures.

Slides:



Advertisements
Similar presentations
CPU Structure and Function
Advertisements

Intel MP.
Computer Organization and Architecture
Computer Organization and Architecture
Ring-transitions for EM64T How the CPU can accomplish transitions among its differing privilege-levels in 64-bit mode.
Microprocessors system architectures – IA32 real and virtual-8086 mode Jakub Yaghob.
IA32 Paging Scheme Introduction to the Pentium’s support for “virtual” memory.
Task-Switching How the x86 processor assists with context-switching among multiple program-threads.
Introduction to the Intel x86’s support for “virtual” memory
Interrupts in Protected-Mode Writing a protected-mode interrupt-service routine for the timer-tick interrupt.
Interrupts in Protected-Mode Writing a protected-mode interrupt-service routine for the timer-tick interrupt.
IA32 Paging Scheme Introduction to the Intel x86’s support for “virtual” memory.
Getting Ready to Enter x86 Protected Mode Survival tactics for enabling Protected-Mode with a minimum of supporting infrastructure.
EM64T ‘fast’ system-calls A look at the requirements for using Intel’s ‘syscall’ and ‘sysret’ instructions in 64-bit mode.
Page-Faults in Linux How can we study the handling of page-fault exceptions?
Exceptions and Interrupts How does Linux handle service- requests from the cpu and from the peripheral devices?
Interrupts in Protected-Mode Writing a protected-mode interrupt-service routine for the timer-tick interrupt.
Defining protected-mode segment-descriptors An example of a protected-mode bootsector application that draws a message to the video display.
Processor Privilege-Levels How the x86 processor accomplishes transitions among its four distinct privilege-levels.
Deferred segment-loading An exercise on implementing the concept of ‘load-on-demand’ for the program-segments in an ELF executable file.
Venturing into protected-mode A first look at the CPU registers and instructions which provide the essential supporting infrastructure.
X86 segmentation, page tables, and interrupts 3/17/08 Frans Kaashoek MIT
IA32 Paging Scheme Introduction to the Pentium’s support for “virtual” memory.
Processor Exceptions A survey of the x86 exceptions and mechanism for handling faults, traps, and aborts.
Task-Switching How the x86 processor assists with context-switching among multiple program-threads.
Venturing into 64-bit mode Examining the steps needed to take the processor into IA-32e mode -- and then back out again.
Segment-registers’ hidden bits A look at how segmentation attributes are cached within the CPU’s segment-registers.
Deferred segment-loading An exercise on implementing the concept of ‘load-on-demand’
Venturing into protected-mode
ARM 7 Datapath. Has “BIGEND” input bit, which defines whether the memory is big or little endian Modes: ARM7 supports six modes of operation: (1) User.
Special segment-registers
A ‘protected-mode’ exploration A look at the steps needed to build segment-descriptors for displaying a message while in protected-mode.
Microprocessor Systems Design I Instructor: Dr. Michael Geiger Fall 2012 Lecture 15: Protected mode intro.
Our planned VMX demo Implementation-code for our ‘Guest’ VM and ‘Host’ VMM.
8086 emulation Using Virtual-8086 mode to execute real-mode procedures in a protected-mode environment.
Venturing into protected-mode A first look at the CPU registers and instructions which provide the essential supporting infrastructure.
Interrupts in Protected-Mode Writing a protected-mode interrupt-service routine for the timer-tick interrupt.
UNIT 2 Memory Management Unit and Segment Description and Paging
Intel
80386DX.
The Pentium Processor.
The Pentium Processor Chapter 3 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
System Address Registers/Memory Management Registers Four memory management registers are used to specify the locations of data structures which control.
80386DX.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
1 i386 Memory Management Professor Ching-Chi Hsu 1998 年 4 月.
Virtual 8086 Mode  The supports execution of one or more 8086, 8088, 80186, or programs in an protected-mode environment.  An 8086.
EFLAG Register of The The only new flag bit is the AC alignment check, used to indicate that the microprocessor has accessed a word at an odd.
Microprocessor system architectures – IA32 tasks Jakub Yaghob.
80386DX. Programming Model The basic programming model consists of the following aspects: – Registers – Instruction Set – Addressing Modes – Data Types.
Segment Descriptor Segments are areas of memory defined by a programmer and can be a code, data or stack segment. In segments need not be all the.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
1 Microprocessors CSE Protected Mode Memory Addressing Remember using real mode addressing we were previously able to address 1M Byte of memory.
Information Security - 2. Other Registers EFLAGS – 32 Bit Register CFPFAFZFSFTFIFDFOFIO PL IO PL NTRFVM Bits 1,3,5,15,22-31 are RESERVED. 18: AC, 19:VIF,
Information Security - 2. Descriptor Tables Descriptors are stored in three tables: – Global descriptor table (GDT) Maintains a list of most segments.
Information Security - 2. CISC Vs RISC X86 is CISC while ARM is RISC CISC is Compiler’s heaven while RISC is Architecture’s heaven Orthogonal ISA in RISC.
contains 8086 processor and several additional functional chips: –clock generator –2 independent DMA channels –PIC –3 programmable 16-bit.
Microprocessor Architecture
Descriptor Table & Register
contains 8086 processor and several additional functional chips: clock generator 2 independent DMA channels PIC 3 programmable 16-bit timers.
x86 segmentation, page tables, and interrupts
Operating Modes UQ: State and explain the operating modes of X86 family of processors. Show the mode transition diagram highlighting important features.(10.
Introduction to the Intel x86’s support for “virtual” memory
REGISTER ORGANIZATION OF 80386
CS444/544 Operating Systems II Virtual Memory
Presentation transcript:

The various x86 ‘modes’ On understanding key differences among the processor’s several execution-architectures

The x86 operating modes Real mode Protected mode IA-32e mode Virtual 8086 mode System Management mode 64-bit mode Compatibility mode Power on

Why ‘mode’ matters Key differences among the x86 modes: –How memory is addressed and mapped –What instruction-set is available –Which registers are accessible –Which ‘exceptions’ may be generated –What data-structures are required –How task-switching can be accomplished –How interrupts will be processed

Mode transitions The processor starts up in ‘real mode’ Mode-transitions normally happen under program control (except for transitions to System Management Mode) Details of programming a mode-change depend on which modes are involved Some mode-transfers aren’t possible (and some mode-changes aren’t documented)

Classroom/Lab machines The workstations in our Kudlick classroom and Fifth-Floor CS Labs use slightly older Pentium processors that lack the circuitry for supporting the IA-32e mode But the new Core-2 Duo machines, which we can access remotely, do implement all of the ‘modes’ we previously depicted

Enabling ‘protected-mode’ Protected-mode was first introduced in the processor (used in the IBM-PC/AT) Intel added some special system registers to support protected-mode, and to control the transition from the power-on ‘real-mode’ –Global Descriptor Table register (GDTR) –Interrupt Descriptor Table register (IDTR) –Local Descriptor Table register (LDTR) –Task Register (TR) –Machine Status Word (MSW)

Machine Status Word TSTS EMEM MPMP PEPE Legend: PE (Protected-Mode Enabled): 0=no, 1=yes MP (Math-coprocessor Present): 0=no, 1=yes EM (Emulate Math-coprocessor): 0=no, 1=yes TS (Task has been Switched): 0=no, 1=yes This register’s defined bits would initially be zeros at system startup, but they could be modified under program control by executing the special LMSW instruction (Load Machine Status Word), or could be inspected by executing the SMSW instruction (Store Machine Status Word) ‘sticky’ bit

Coding the transition So here’s the code-fragment for switching to ‘protected-mode’ from ‘real-mode’: # This code illustrates an processor’s transition from real-mode # to protected-mode – but note that interrupts must not be allowed here cli# clear IF-bit in FLAGS register smsw%ax# get current settings from MSW or$1, %ax# set the PE-bit’s image to 1 lmsw%ax# load the new setting into MSW # OK, the processor is now executing in ‘protected-mode’

Descriptor tables Memory-addressing in protected-mode is based upon some special data-structures called ‘Segment Descriptors’ that define a memory-region and assign its properties Not used by the (reserved) Type and access-rights Segment-Base[15..0]Segment-Limit[15..0] Segment- Base[23..16] The quadword descriptor data-structure (64-bits) Word 0Word 1 Word 2Word 3

Type and access-rights PDPLSXC/DR/WA Legend: P = Present (1=yes, 0=no) DPL = Descriptor Privilege Level (00=supervisor, 11=user) S = System-segment (0=yes, 1=no) X = eXecutable: 1=yes (i.e., code-segment), 0=no (i.e., data-segment) C/D = Conforming code (1=yes, 0=no) when X-bit equals 1 expands-Down (1=yes, 0=no) when X-bit equals 0 R/W = Readable (1=yes, 0=no) when X-bit equals 1 Writable (1=yes, 0=no) when X-bit equals 0 A = segment has been Accessed by the CPU (1=yes, 0=no)

Global Descriptor Table 0x68 0x60 0x58 0x50 0x48 0x40 0x38 0x30 0x28 0x20 0x18 0x10 0x08 0x00 baselimit Global Descriptor Table Register (GDTR) base-address segment-limit “null” descriptor Special instructions LGDT and SGDT

Backward compatibility Intel’s (and later) processors are ‘backwardly compatible’ with the 80286, but they implement some extensions to support 32-bit registers and addresses (and some early forms of ‘virtualization’) Register MSW is enlarged and renamed, (and its ‘stickly PE-bit’ design-flaw is corrected in the renamed mechanism)

Control Register 0 Register CR0 is the 32-bit version of the old MSW register (Machine Status Word) It contains the PE-bit (Protection Enabled) –when PE=0 the CPU is in real-mode –when PE=1 the CPU is in protected-mode PGPG CDCD NWNW AMAM WPWP NENE ETET TSTS EMEM MPMP PEPE Machine Status Word

Enter or leave protected-mode Here are code-fragments for entering, and for leaving, protected-mode on 32-bit CPU # entering protected-mode (with interrupts turned off) mov%cr0, %eax# get current Machine Status bts$0, %eax# set image of bit #0 (the PE-bit) mov%eax, %cr0# enter protected-mode # leaving protected-mode (with interrupts turned off) mov%cr0, %eax# get current Machine Status btr$0, %eax# reset image of bit #0 (the PE-bit) mov%eax, %cr0# leave protected mode

Enhanced Descriptor-Format Base[31..24]GD RSVRSV AVLAVL Limit [19..16] P DPLDPL SX C/DC/D R/WR/W ABase[23..16] Base[15..0]Limit[15..0] Several instances of this basic ‘segment-descriptor’ data-structure will occur in the Global Descriptor Table (and maybe also in some Local Descriptor Tables) Legend: G = Granularity: (0=byte-granularity, 1=page-granularity) D = Default operand and address size: (0=16-bits, 1=32-bits) RSV = Reserved bit (but recently used for 64-bit technology) AVL = Available (this bit can be used by programmers for any purpose)

Initializing register GDTR Setting up your Global Descriptor Table might be accomplished as in this fragment # We shall assume that this segment resides at memory-address 0x10000 … lgdtregGDT# load system register GDTR … # theGDT:.quad0x # the required ‘null’ descriptor.quad0x008F FFFF# 4GB writable data-segment.quad0x00009A010000FFFF# 64KB readable code-segment.equlimGDT, (. – theGDT) – 1# segment-limit for this GDT # regGDT:.wordlimGDT, theGDT, 0x0001# image for register GDTR #

Examining register CR0 We could modify our ‘eflags.s’ program so it would display the current value in CR0 Just remember that CR0 is the renamed Machine Status Word register, then use the (unprivileged) ‘smsw’ instruction – but use an ‘l’ suffix (for longword) and a 32-bit register-operand (e.g., %eax), like this: smswl%eax# store current value from register CR0 into EAX

In-class exercise #1 Make a copy of the ‘eflags.s’ demo (from our class website), and name it ‘cr0.s’ Replace the two instructions that it uses to get the value of EFLAGS with just a single instruction that will get the value of CR0 Change the message-string appropriately Then assemble, link, and execute your modified demo-program

In-class exercise #2 Can you write a program that will show the contents of the system-register GDTR? You need to use the SGDT-instruction But it will require a memory-operand big enough to hold this register’s 48-bits And you will need to adjust the counter in your program-loop for 48 binary-digits, as well as your message-string’s format