25
x86 PC Overview

Welcome to the Department of Computer Science - l …hilder/cs430-833/Notes/x86 PC... · Web viewx86 PC Architecture x86 Instruction Set gcc Calling Conventions x86 PC Emulation x86

  • Upload
    others

  • View
    11

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Welcome to the Department of Computer Science - l …hilder/cs430-833/Notes/x86 PC... · Web viewx86 PC Architecture x86 Instruction Set gcc Calling Conventions x86 PC Emulation x86

x86 PC Overview

Page 2: Welcome to the Department of Computer Science - l …hilder/cs430-833/Notes/x86 PC... · Web viewx86 PC Architecture x86 Instruction Set gcc Calling Conventions x86 PC Emulation x86

Outline

• x86 PC Architecture • x86 Instruction Set • gcc Calling Conventions • x86 PC Emulation

Page 3: Welcome to the Department of Computer Science - l …hilder/cs430-833/Notes/x86 PC... · Web viewx86 PC Architecture x86 Instruction Set gcc Calling Conventions x86 PC Emulation x86

x86 PC Board

Page 4: Welcome to the Department of Computer Science - l …hilder/cs430-833/Notes/x86 PC... · Web viewx86 PC Architecture x86 Instruction Set gcc Calling Conventions x86 PC Emulation x86

Abstract Model

• I/O: Communicating data to and from devices • CPU: Digital logic for performing computation • Memory: N words of B bits

Memory

Main Input/Output

Unit Processing

Central

Page 5: Welcome to the Department of Computer Science - l …hilder/cs430-833/Notes/x86 PC... · Web viewx86 PC Architecture x86 Instruction Set gcc Calling Conventions x86 PC Emulation x86

The Stored Program Computer

• Memory holds instructions and data • CPU interpreter of instructions

Main Memory CPU

data

data data

instruction

instruction

instruction

} next instruction for (;;) {

Page 6: Welcome to the Department of Computer Science - l …hilder/cs430-833/Notes/x86 PC... · Web viewx86 PC Architecture x86 Instruction Set gcc Calling Conventions x86 PC Emulation x86

EIP Register == Next Instruction

instruction

instruction

instruction

data

data data

Page 7: Welcome to the Department of Computer Science - l …hilder/cs430-833/Notes/x86 PC... · Web viewx86 PC Architecture x86 Instruction Set gcc Calling Conventions x86 PC Emulation x86

• EIP is incremented after each instruction • EIP modified by CALL, RET, JMP, and conditional JMP

Registers == Work Space

Page 8: Welcome to the Department of Computer Science - l …hilder/cs430-833/Notes/x86 PC... · Web viewx86 PC Architecture x86 Instruction Set gcc Calling Conventions x86 PC Emulation x86

• 8, 16, and 32 bit versions • By convention some registers for special purposes

EFLAGS Register == Information

Page 9: Welcome to the Department of Computer Science - l …hilder/cs430-833/Notes/x86 PC... · Web viewx86 PC Architecture x86 Instruction Set gcc Calling Conventions x86 PC Emulation x86

• Test instructions: TEST $0, %EAX• Conditional JMP instructions: JNZ address

Memory == More Work Space

• Memory instructions: MOV, PUSH, POP, others • Most instructions can take a memory address

Page 10: Welcome to the Department of Computer Science - l …hilder/cs430-833/Notes/x86 PC... · Web viewx86 PC Architecture x86 Instruction Set gcc Calling Conventions x86 PC Emulation x86

Stack == Memory + Operations

• Stack grows “downward” in addresses• Used during function calls

Page 11: Welcome to the Department of Computer Science - l …hilder/cs430-833/Notes/x86 PC... · Web viewx86 PC Architecture x86 Instruction Set gcc Calling Conventions x86 PC Emulation x86

More Memory• 80386: 32 bit data and bus addresses• Now: 64 bit data and bus addresses • Backwards compatibility: Boots in 16-bit mode,

then boot.S switches to protected mode with 32-bit addresses

• 80386 also added virtual memory addresses – Page table hardware

Page 12: Welcome to the Department of Computer Science - l …hilder/cs430-833/Notes/x86 PC... · Web viewx86 PC Architecture x86 Instruction Set gcc Calling Conventions x86 PC Emulation x86

Physical Memory Layout

Page 13: Welcome to the Department of Computer Science - l …hilder/cs430-833/Notes/x86 PC... · Web viewx86 PC Architecture x86 Instruction Set gcc Calling Conventions x86 PC Emulation x86

x86 Instruction Set• Instructions classes:

– Movement: MOV, PUSH, POP, … – Arithmetic: TEST, SHL, ADD, … – I/O: IN, OUT, … – Control: JMP, JZ, JNZ, CALL, RET – String: REP, MOVSB, … – System: IRET, INT, …

• Assembly language syntax:– Intel syntax: op dst, src – AT&T (gcc/gas) syntax: op src, dst (used by xv6)

Page 14: Welcome to the Department of Computer Science - l …hilder/cs430-833/Notes/x86 PC... · Web viewx86 PC Architecture x86 Instruction Set gcc Calling Conventions x86 PC Emulation x86

gcc Calling Conventions

• Saved %ebp  ’s form a chain, can walk stack • Arguments and locals at fixed offsets from EBP  

Page 15: Welcome to the Department of Computer Science - l …hilder/cs430-833/Notes/x86 PC... · Web viewx86 PC Architecture x86 Instruction Set gcc Calling Conventions x86 PC Emulation x86

More gcc Calling Conventions• %eax contains return value, %ecx, %edx may be trashed • %ebp, %ebx, %esi, %edi must be as before call

Page 16: Welcome to the Department of Computer Science - l …hilder/cs430-833/Notes/x86 PC... · Web viewx86 PC Architecture x86 Instruction Set gcc Calling Conventions x86 PC Emulation x86

Example

Page 17: Welcome to the Department of Computer Science - l …hilder/cs430-833/Notes/x86 PC... · Web viewx86 PC Architecture x86 Instruction Set gcc Calling Conventions x86 PC Emulation x86

From C to Running Program

•  Compiler, assembler, linker, and loader

memory loader

ld a.out

gas gcc .asm .c .o

gas gcc .asm .c .o

Page 18: Welcome to the Department of Computer Science - l …hilder/cs430-833/Notes/x86 PC... · Web viewx86 PC Architecture x86 Instruction Set gcc Calling Conventions x86 PC Emulation x86

x86 PC Emulator• QEMU PC emulator

– Does what a real PC does– Does it using software

• Programs will run like they do on “host” operating system

Page 19: Welcome to the Department of Computer Science - l …hilder/cs430-833/Notes/x86 PC... · Web viewx86 PC Architecture x86 Instruction Set gcc Calling Conventions x86 PC Emulation x86

Emulation of Hardware

Page 20: Welcome to the Department of Computer Science - l …hilder/cs430-833/Notes/x86 PC... · Web viewx86 PC Architecture x86 Instruction Set gcc Calling Conventions x86 PC Emulation x86

Emulation of CPU

Page 21: Welcome to the Department of Computer Science - l …hilder/cs430-833/Notes/x86 PC... · Web viewx86 PC Architecture x86 Instruction Set gcc Calling Conventions x86 PC Emulation x86

Emulation of x86 Memory

Page 22: Welcome to the Department of Computer Science - l …hilder/cs430-833/Notes/x86 PC... · Web viewx86 PC Architecture x86 Instruction Set gcc Calling Conventions x86 PC Emulation x86

Emulation of Devices• Hard disk: Using a file on the host • VGA display: Draw in a host window • Keyboard: Using hosts’s keyboard API• Clock chip: Using host’s clock