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

Post on 22-Jan-2020

2 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

Transcript

x86 PC Overview

Outline

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

x86 PC Board

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

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 (;;) {

EIP Register == Next Instruction

instruction

instruction

instruction

data

data data

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

Registers == Work Space

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

EFLAGS Register == Information

• 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

Stack == Memory + Operations

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

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

Physical Memory Layout

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)

gcc Calling Conventions

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

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

Example

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

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

Emulation of Hardware

Emulation of CPU

Emulation of x86 Memory

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

top related