6.828: PC hardware and x86 Frans Kaashoek

Slides:



Advertisements
Similar presentations
Practical Malware Analysis
Advertisements

CS 4284 Systems Capstone Godmar Back Processes and Threads.
Machine/Assembler Language Putting It All Together Noah Mendelsohn Tufts University Web:
C Programming and Assembly Language Janakiraman V – NITK Surathkal 2 nd August 2014.
Lecture 6 Machine Code: How the CPU is programmed.
Context Switch Animation Another one by Anastasia.
X86 segmentation, page tables, and interrupts 3/17/08 Frans Kaashoek MIT
© 2006 Pearson Education, Upper Saddle River, NJ All Rights Reserved.Brey: The Intel Microprocessors, 7e Chapter 2 The Microprocessor and its Architecture.
PC hardware and x86 3/3/08 Frans Kaashoek MIT
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
1 Lecture 5: Procedures Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
1 Function Calls Professor Jennifer Rexford COS 217 Reading: Chapter 4 of “Programming From the Ground Up” (available online from the course Web site)
Accessing parameters from the stack and calling functions.
Assembly Language for Intel-Based Computers Chapter 2: IA-32 Processor Architecture Kip Irvine.
ICS312 Set 3 Pentium Registers. Intel 8086 Family of Microprocessors All of the Intel chips from the 8086 to the latest pentium, have similar architectures.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Stack Operations Runtime Stack PUSH Operation POP.
© 2006 Pearson Education, Upper Saddle River, NJ All Rights Reserved.Brey: The Intel Microprocessors, 7e Chapter 2 The Microprocessor and its Architecture.
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 7 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
The Intel Microprocessors. Real Mode Memory Addressing Real mode, also called real address mode, is an operating mode of and later x86-compatible.
1 Carnegie Mellon Stacks : Introduction to Computer Systems Recitation 5: September 24, 2012 Joon-Sup Han Section F.
CSC 221 Computer Organization and Assembly Language
Fall 2012 Chapter 2: x86 Processor Architecture. Irvine, Kip R. Assembly Language for x86 Processors 6/e, Chapter Overview General Concepts IA-32.
The x86 Architecture Lecture 15 Fri, Mar 4, 2005.
IA32 (Pentium) Processor Architecture. Processor modes: 1.Protected (mode we will study) – 32-bit mode – 32-bit (4GB) address space 2.Virtual 8086 modes.
1 Homework Reading –PAL pp , Continue mp1 –Questions? Continue lab sessions with your section.
Derived from "x86 Assembly Registers and the Stack" by Rodney BeedeRodney Beede x86 Assembly Registers and the Stack Nov 2009.
1 ICS 51 Introductory Computer Organization Fall 2009.
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
Low Level Programming Lecturer: Duncan Smeed The Interface Between High-Level and Low-Level Languages.
Chapter 2 Parts of a Computer System. 2.1 PC Hardware: Memory.
Functions/Methods in Assembly
Compiler Construction Code Generation Activation Records
X86 Assembly Language We will be using the nasm assembler (other assemblers: MASM, as, gas)
University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 1 Computer Systems The instruction set architecture.
University of Sargodha, Lahore Campus Prepared by Ali Saeed.
What You Need to Know for Project Three Steve Muckle Wednesday, February 19 th Spring 2003.
Arrays. Outline 1.(Introduction) Arrays An array is a contiguous block of list of data in memory. Each element of the list must be the same type and use.
1 Assembly Language: Function Calls Jennifer Rexford.
CSC 221 Computer Organization and Assembly Language Lecture 15: STACK Related Instructions.
1 x86 Programming Model Microprocessor Computer Architectures Lab Components of any Computer System Control – logic that controls fetching/execution of.
Week 6 Dr. Muhammad Ayaz Intro. to Assembly Language.
Computer Organization & Assembly Language University of Sargodha, Lahore Campus Prepared by Ali Saeed.
BITS Pilani Pilani Campus Pawan Sharma Lecture / ES C263 INSTR/CS/EEE F241 Microprocessor Programming and Interfacing.
The Microprocessor & Its Architecture A Course in Microprocessor Electrical Engineering Department Universitas 17 Agustus 1945 Jakarta.
Chapter Overview General Concepts IA-32 Processor Architecture
CS 177 Computer Security Lecture 9
Instruction Set Architecture
Assembly language.
Credits and Disclaimers
Format of Assembly language
C function call conventions and the stack
x86 Processor Architecture
Anton Burtsev February, 2017
Aaron Miller David Cohen Spring 2011
Introduction to Compilers Tim Teitelbaum
Basic Microprocessor Architecture
Assembly IA-32.
x86 segmentation, page tables, and interrupts
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures
Assembly Language Programming II: C Compiler Calling Sequences
CS 301 Fall 2002 Computer Organization
MIPS Procedure Calls CSE 378 – Section 3.
The Microprocessor & Its Architecture
Computer Architecture CST 250
X86 Assembly Review.
CSC 497/583 Advanced Topics in Computer Security
Credits and Disclaimers
Computer Architecture and System Programming Laboratory
Presentation transcript:

6.828: PC hardware and x86 Frans Kaashoek

A PC how to make it to do something useful?

Outline PC architecture x86 instruction set gcc calling conventions PC emulation Illustrate a few big CS ideas

PC board

Abstract model I/O: communicating data to and from devices CPU: digital logic for performing computation Memory: N words of B bits Central Processing Unit Input/Output Main Memory

The stored program computer Memory holds instructions and data CPU interpreter of instructions for (;;) { next instruction } instruction data CPU Main memory

x86 implementation EIP is incremented after each instruction Instructions are different length EIP modified by CALL, RET, JMP, and conditional JMP instruction data

Registers for work space 8, 16, and 32 bit versions By convention some registers for special purposes Example: ADD EAX, 10 Other instructions: SUB, AND, etc.

EFLAGS register Test instructions: TEST EAX, 0 Conditional JMP instructions: JNZ address

Memory: more work space Memory instructions: MOV, PUSH, POP, etc Most instructions can take a memory address

Stack memory + operations Stack grows down Use to implement procedure calls

More memory registers and 20-bit bus addresses The extra 4 bits come segment registers –CS: code segment, for EIP –SS: stack segment, for SP and BP –DS: data segment for load/store via other registers –ES: another data segment, destination for string ops –For example: CS=4096 to start executing at Makes life more complicated –Cannot use 16 bit address of stack variable as pointer –Pointer arithmetic and array indexing across segment boundaries –For a far pointer programmer must include segment reg

And more memory 80386: 32 bit data and bus addresses Now: the transition to 64 bit addresses Backwards compatibility: –Boots in 16-bit mode, and boot.S switches to protected mode with 32-bit addresses –Prefix 0x66 gets you 32-bit: MOVW = 0x66 MOVW –.code32 in boot.S tells assembler to insert 0x also added virtual memory addresses –Segment registers are indices into a table –Page table hardware

I/O space and instructions 8086: Only 1024 I/O addresses

Memory-mapped I/O Use normal addresses –No need for special instructions –No 1024 limit –System controller routes to device Works like “magic” memory –Addressed and accessed like memory –But does not behave like memory –Reads and writes have “side effects” –Read result can change due to external events

Physical memory layout

x86 instruction set Instructions classes: –Data movement: MOV, PUSH, POP, … –Arithmetic: TEST, SHL, ADD, … –I/O: IN, OUT, … –Control: JMP, JZ, JNZ, CALL, RET –String: REP, MOVSB, … –System: IRET, INT, … Intel architecture manual Volume 2 –Intel syntax: op dst, src –AT&T (gcc/gas) syntax: op src, dst

Gcc calling conventions for JOS Prologue: pushl %ebp movl %esp, %ebp Epilogue: movl %ebp, %esp popl %ebp Saved %ebp’s form a chain, can walk stack Arguments and locals at fixed offsets from EBP

gcc procedure calling conventions –%eax contains return value, %ecx, %edx may be trashed –%ebp, %ebx, %esi, %edi must be as before call –Note that %ebp isn’t strictly necessary, but we compile JOS and xv6 this way for convenience of walking up the stack. Caller saved Callee saved

Example

From C to running program Compiler, assembler, linker, and loader.o.c.asm gccgas.o.c.asm gccgas a.out ld loader memory

Development using PC emulator QEMU PC emulator –does what a real PC does –Only implemented in software! Runs like a normal program on “host” operating system PC emulator Linux PC JOS

Emulation of memory

Emulation of CPU

Emulation x86 memory

Emulating devices Hard disk: using a file of the host VGA display: draw in a host window Keyboard: hosts’s keyboard API Clock chip: host’s clock Etc.

Summary For lab: PC and x86 Illustrate several big ideas: –Stored program computer –Stack –Memory-mapped I/O –Software = hardware