cs5600 - pc h/w & assembly...• alternatives: amiga, powepc, dec alpha, sparc, etc. • 1981...

70
CS5600 - PC H/W & Assembly

Upload: others

Post on 31-Mar-2021

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

CS5600 - PC H/W & Assembly

Page 2: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Overview

• Hardware basics

• PC Bootup Sequence

• x86 basics

• Intro to OS

Page 3: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Hardware Basics• PC compatible, “Wintel"

• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc.

• 1981 IBM PC (compete with Apple)

• 1982 Compaq IBM-compatible PC

• 1985 IBM clones everywhere!

• 1986 Compaq 80386-based PC

• 1990s Wintel

• x86, Pemtium I, II, III …

• x86_64 AMD … tomorrow?

Page 4: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Motherboard CPU I/O Memory BIOS South-Bridge • I/O between CPU,

devices and MM North-Bridge • Coordinates access

to MM Storage Connectors • (S)ATA

Page 5: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Conceptually

16

North/South+BridgeGraphics

Graphics+Memory

I/O I/O I/O…

Memory

CPU(s)L1,+L2,+L3+Cache All+devices+

compete+for+access+to+memory

Page 6: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Simplified CPU LayoutControl Unit

ALU ALU FPU Registers

System Bus

Cache L1, L2, L3

InstructionDecode

InstructionFetch

Page 7: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Registers• Storage build into the CPU

• Can hold valued or pointer

• Instructions operate directly on registers

• Load from memory

• Load to memory

Page 8: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Registers• Some registers are special

• point to the current instruction in memory

• point to top of the stack

• configure low-level CPU features

• …

Page 9: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUSControl

UnitALU

ACC

SR MDR

MAR

CIR

PC

RAM Addr

Page 10: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUSControl

UnitALU

ACC

SR MDR

MAR

CIR

PC

RAM Addr

ProgramCounter

Page 11: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUSControl

UnitALU

ACC

SR MDR

MAR

CIR

PC

RAM Addr

MemoryAddressRegister

Page 12: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUSControl

UnitALU

ACC

SR MDR

MAR

CIR

PC

RAM Addr

CurrentInstructionRegister

Page 13: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUSControl

UnitALU

ACC

SR MDR

MAR

CIR

PC

RAM Addr

Memory(Data OR

Buffer) Register

Page 14: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUSControl

UnitALU

ACC

SR MDR

MAR

CIR

PC

RAM Addr

StatusRegister

Page 15: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUSControl

UnitALU

ACC

SR MDR

MAR

CIR

PC

RAM Addr

Arithmetic and Logic

Unit

Page 16: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUSControl

UnitALU

ACC

SR MDR

MAR

CIR

PC

RAM Addr

AccumulatorRegister

Page 17: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUSControl

UnitALU

ACC

SR MDR

MAR

CIR

PC

RAM Addr

GeneralPurposeRegisters

r1 .. rn

Page 18: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUS

0010010100111000111001100000111001101

000100001111

000111001111ControlUnitALU

001111 ACC

SR MDR

MAR

CIR

PC

RAM Addr

It’s all bits!

00000000001

00000000002

00000000003

00000000004

00000000005000000000060000000000700000000008

….

Page 19: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUS

load 008, r1load #1

add r1, r2

load 007, r2

store r1, 008

100

11

ControlUnitALU

ACC

SR MDR

MAR

CIR

PC

RAM Addr

Use Assembly instruction names and numbers

00000000001

00000000002

00000000003

00000000004

00000000005000000000060000000000700000000008

….

Page 20: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUS

load 008, r1load #1

add r1, r2

load 007, r2

store r1, 008

100

11

001

ControlUnitALU

ACC

SR MDR

MAR

CIR

PC

RAM Addr

It all starts with the PC

00000000001

00000000002

00000000003

00000000004

00000000005000000000060000000000700000000008

….

Page 21: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUS

load 008, r1load #1

add r1, r2

load 007, r2

store r1, 008

100

11

001001

ControlUnitALU

ACC

SR MDR

MAR

CIR

PC

RAM Addr

Copy the contents of PC into MAR

00000000001

00000000002

00000000003

00000000004

00000000005000000000060000000000700000000008

….

Page 22: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUS

load 008, r1load #1

add r1, r2

load 007, r2

store r1, 008

100

11

001001

ControlUnitALU

ACC

SR MDR

MAR

CIR

PC

RAM Addr

To fetch the contents of the address, place it on the bus

00000000001

00000000002

00000000003

00000000004

00000000005000000000060000000000700000000008

….

Page 23: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUS

load 008, r1load #1

add r1, r2

load 007, r2

store r1, 008

100

11

001001

ControlUnitALU

ACC

SR MDR

MAR

CIR

PC

RAM Addr

Control unit notifies MDR to be on the look out

00000000001

00000000002

00000000003

00000000004

00000000005000000000060000000000700000000008

….

Page 24: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUS

load 008, r1load #1

add r1, r2

load 007, r2

store r1, 008

100

11

001001

load #1

load #1ControlUnitALU

ACC

SR MDR

MAR

CIR

PC

RAM Addr

MDR picks the result of fetch from the bus and copies to CIR

00000000001

00000000002

00000000003

00000000004

00000000005000000000060000000000700000000008

….

Page 25: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUS

load 008, r1load #1

add r1, r2

load 007, r2

store r1, 008

100

11

001001

load #1

load #1ControlUnitALU

ACC

SR MDR

MAR

CIR

PC

RAM Addr

CU decodes to figure out which instruction we have

00000000001

00000000002

00000000003

00000000004

00000000005000000000060000000000700000000008

….

Decode

Page 26: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUS

load 008, r1load #1

add r1, r2

load 007, r2

store r1, 008

100

11

001001

load #1

load #1ControlUnitALU

1 ACC

SR MDR

MAR

CIR

PC

RAM Addr

It’s a load of number 1, execute it and load 1 in ACC

00000000001

00000000002

00000000003

00000000004

00000000005000000000060000000000700000000008

….

Page 27: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUS

load 008, r1load #1

add r1, r2

load 007, r2

store r1, 008

100

11

001001

load #1

load #1ControlUnitALU

1 ACC

SR MDR

MAR

CIR

PC

RAM Addr

Check if there is an interrupt

00000000001

00000000002

00000000003

00000000004

00000000005000000000060000000000700000000008

….

Page 28: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUS

load 008, r1load #1

add r1, r2

load 007, r2

store r1, 008

100

11

001002

load #1

load #1ControlUnitALU

1 ACC

SR MDR

MAR

CIR

PC

RAM Addr

PC moves to the next instruction (next address), repeat!

00000000001

00000000002

00000000003

00000000004

00000000005000000000060000000000700000000008

….

Page 29: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUS

load 008, r1load #1

add r1, r2

load 007, r2

store r1, 008

100

11

002002

load #1

load #1ControlUnitALU

1 ACC

SR MDR

MAR

CIR

PC

RAM Addr

Repeating the process for the next instruction with less detail

00000000001

00000000002

00000000003

00000000004

00000000005000000000060000000000700000000008

….

Page 30: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUS

load 008, r1load #1

add r1, r2

load 007, r2

store r1, 008

100

11

002002

load 008,r1

load 008,r1ControlUnitALU

1 ACC

SR MDR

MAR

CIR

PC

RAM Addr

Repeating the process for the next instruction with less detail

00000000001

00000000002

00000000003

00000000004

00000000005000000000060000000000700000000008

….

Page 31: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUS

load 008, r1load #1

add r1, r2

load 007, r2

store r1, 008

100

11

002002

100

100ControlUnitALU

1 ACC

SR MDR

MAR

CIR

PC

RAM Addr

Repeating the process for the next instruction with less detail

00000000001

00000000002

00000000003

00000000004

00000000005000000000060000000000700000000008

….

Page 32: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUS

load 008, r1load #1

add r1, r2

load 007, r2

store r1, 008

100

11

002002

100

100ControlUnitALU

1 ACC

SR MDR

MAR

CIR

PC

RAM Addr

Repeating the process for the next instruction with less detail

00000000001

00000000002

00000000003

00000000004

00000000005000000000060000000000700000000008

….

100

Page 33: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUS

load 008, r1load #1

add r1, r2

load 007, r2

store r1, 008

100

11

003003

100

100ControlUnitALU

1 ACC

SR MDR

MAR

CIR

PC

RAM Addr

Repeating the process for the next instruction with less detail

00000000001

00000000002

00000000003

00000000004

00000000005000000000060000000000700000000008

….

100

Page 34: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUS

load 008, r1load #1

add r1, r2

load 007, r2

store r1, 008

100

11

003003

load 007,r2

load 007,r2ControlUnitALU

1 ACC

SR MDR

MAR

CIR

PC

RAM Addr

Repeating the process for the next instruction with less detail

00000000001

00000000002

00000000003

00000000004

00000000005000000000060000000000700000000008

….

100

Page 35: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUS

load 008, r1load #1

add r1, r2

load 007, r2

store r1, 008

100

11

003003

11

11ControlUnitALU

1 ACC

SR MDR

MAR

CIR

PC

RAM Addr

Repeating the process for the next instruction with less detail

00000000001

00000000002

00000000003

00000000004

00000000005000000000060000000000700000000008

….

100

Page 36: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUS

load 008, r1load #1

add r1, r2

load 007, r2

store r1, 008

100

11

003003

11

11ControlUnitALU

1 ACC

SR MDR

MAR

CIR

PC

RAM Addr

Repeating the process for the next instruction with less detail

00000000001

00000000002

00000000003

00000000004

00000000005000000000060000000000700000000008

….

100

11

Page 37: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUS

load 008, r1load #1

add r1, r2

load 007, r2

store r1, 008

100

11

004004

11

11ControlUnitALU

1 ACC

SR MDR

MAR

CIR

PC

RAM Addr

Repeating the process for the next instruction with less detail

00000000001

00000000002

00000000003

00000000004

00000000005000000000060000000000700000000008

….

100

11

Page 38: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUS

load 008, r1load #1

add r1, r2

load 007, r2

store r1, 008

100

11

004004

add r1,r2

add r1,r2ControlUnitALU

1 ACC

SR MDR

MAR

CIR

PC

RAM Addr

Repeating the process for the next instruction with less detail

00000000001

00000000002

00000000003

00000000004

00000000005000000000060000000000700000000008

….

100

11

Page 39: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUS

load 008, r1load #1

add r1, r2

load 007, r2

store r1, 008

100

11

004004

add r1,r2

add r1,r2ControlUnitALU

111 ACC

SR MDR

MAR

CIR

PC

RAM Addr

Repeating the process for the next instruction with less detail

00000000001

00000000002

00000000003

00000000004

00000000005000000000060000000000700000000008

….

111

11

add r1, r2

Page 40: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUS

load 008, r1load #1

add r1, r2

load 007, r2

store r1, 008

100

11

005005

add r1,r2

add r1,r2ControlUnitALU

111 ACC

SR MDR

MAR

CIR

PC

RAM Addr

Repeating the process for the next instruction with less detail

00000000001

00000000002

00000000003

00000000004

00000000005000000000060000000000700000000008

….

111

11

Page 41: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUS

load 008, r1load #1

add r1, r2

load 007, r2

store r1, 008

100

11

005005

store r1, 008

store r1, 008ControlUnitALU

111 ACC

SR MDR

MAR

CIR

PC

RAM Addr

Repeating the process for the next instruction with less detail

00000000001

00000000002

00000000003

00000000004

00000000005000000000060000000000700000000008

….

111

11

Page 42: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Toy CPU

BUS

load 008, r1load #1

add r1, r2

load 007, r2

store r1, 008

111

11

005005

store r1, 008

store r1, 008ControlUnitALU

111 ACC

SR MDR

MAR

CIR

PC

RAM Addr

Repeating the process for the next instruction with less detail

00000000001

00000000002

00000000003

00000000004

00000000005000000000060000000000700000000008

….

111

11

Updated

Page 43: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Actual CPU• Architectures Vary (Intel, DEC Alpha, AMIGA etc.)

• different layouts, numbers of registers etc.

• registers for stack points (sp), frame base pointer (sb), flag registers (EFLAGS)

• Instruction Set Architecture varies

• CISC vs RISC (X86, Sparc)

• branching and jumping instructions manipulate the PC

• The course will use X86, 32bit

Page 44: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Memory Hierarchy

Page 45: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

x86_32 Registers

Page 46: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

x86 Registers• EIP (PC)

• Points to currently executing instruction

• EFLAGS

• Think of it as scratch register, e.g., results after comparison, carry after addition.

• Sometimes referred to as the machine status word register

Page 47: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

x86 instructions Instruction Description Example

mov Move data src -> dst mov eax,7 mov edx,[0xF0FF]

add/sub Add/subtract vals in reg. add eax,eab

inc/dec Increment/decrement value in reg. inc eax

call Push EIP onto stack & jump to func call 0x80FEAC

ret Pop the stack into EIP ret

push/pop Push/pop onto stack push eax

int Execute interrupt handler int 0x70

jmp Load value into EIP jmp 0x80FEAC

cmp Compare 2 regs, put result in flags register cmp ebx,edx

jz/jnz/jXXX Load value in EIP if zero or non-zero in flags register jnz 0x80FEAC

Page 48: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Assembly Language• Contents of the file is text. Much like your C

programs.It’s a programming language (not high level)

• assembler takes text file with assembly instructions and creates a file with 0s and1s see (as, as86, nasm)

• syntax is simple

• label: instruction ; comment

• sections and directives; .data .bss .text

Page 49: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Assembly Language• Contents of the file is text. Much like your C

programs.It’s a programming language (not high level)

• assembler takes text file with assembly instructions and creates a file with 0s and1s see (as, as86, nasm)

• syntax is simple

• label: instruction ; comment

• sections and directives; .data .bss .text

Initialize data, constants

Page 50: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Assembly Language• Contents of the file is text. Much like your C

programs.It’s a programming language (not high level)

• assembler takes text file with assembly instructions and creates a file with 0s and1s see (as, as86, nasm)

• syntax is simple

• label: instruction ; comment

• sections and directives; .data .bss .text

Un-initialized data, local vars

Page 51: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Assembly Language• Contents of the file is text. Much like your C

programs.It’s a programming language (not high level)

• assembler takes text file with assembly instructions and creates a file with 0s and1s see (as, as86, nasm)

• syntax is simple

• label: instruction ; comment

• sections and directives; .data .bss .text

Code

Page 52: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Example x86 assembly

xorl %edx,%edx # i = 0 (more compact than movl) cmpl %ecx,%edx # test (i - a) jge .L4 # >= 0 ? jump to end movl sum,%eax # cache value of sum in register

.L6: addl %edx,%eax # sum += i incl %edx # i++ cmpl %ecx,%edx # test (i - a) jl .L6 # < 0 ? go to top of loop movl %eax,sum # store value of sum back in memory .L4

for (i = 0; i < a; i++) sum += i;

Page 53: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Main Memory• CPU is fast and dumb

• Manipulations involve memory

• Memory is used by more components!

• Devices

• Kernel

• more than one program

• Shared resource!

Page 54: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Memory LayoutMemory'mapped'devices

Free'Memory

BIOS'Code

Interrupt'Vector

0x0000

0x00FF

0x0DFF

0xF000

0xFFFFTop

Page 55: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

CPU and Device Communication

• CPU and devices execute concurrently

• Communication happens

1. I/O ports

• Specific addresses on I/O Bus

2. Memory mapping

• RAM region shared by device and CPU

3. Direct Memory Map

• Device writes directly to share region in RAM

4. Interrupts

• Signal from device to CPU. OS has to switch to handler code

Page 56: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

ExamplesSharedMemory

Interrupt

I/O Ports

Page 57: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Device, CPU communication• I/O Ports

• virtual memory shared between them

• Synchronous + CPU has to copy data over

• SLOW!

• Memory Mapped

• RAM shared between them, CPU involved in all memory transactions

• Direct Memory Acces (DMA)

• device reads/writes to memory without involving the CPU

Page 58: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Interrupts• Interrupt Vector

• Maps interrupts to handler’s address

• Interrupt causes context switch

Interrupt Vector

Handler (0x01)

Number Handler

0x01 0xAAA1

0x02 0xBBB1

0xAAA1

0x0000

Page 59: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

How does it all start? Big Bang!

Page 60: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

PC Bootup Process

Page 61: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Power On• Start the BIOS (Basic Input/Output System)

• code from BIOS gets copied to RAM

• load EIP register with starting address

• Load setting from CMOS

• Initialize devices

• CPU, MEM, Keyboard, Video

• Install Interrupt Vector Table

• Run POST (Power On Self Test)

• Initiate the bootstrap sequence (configurable, HD, CD, net)

Page 62: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

MBR

Page 63: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

MBR

• Special 512 byte file in sector 1 address 0

• Too small for a full OS

• points to another section of your drive

• starts chain loading

Page 64: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

The Kernel• The program that always runs on your machine

• Started by the boot loader

• Features

• Device management

• loading and executing your programs

• System calls and APIs

• Protection

• Fault tolerance

• Security

Page 65: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Kernel Architectures• Monolithic

• one big code base, one big binary

• Code Runs in privileged Kernel-space

• Microkernels

• Only core components in the kernel

• Rest of kernel components run in user space

• Hybrid kernels

• Most components run in the kernel

• Some loaded dynamically

Page 66: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

MonolithicKernel Space User Space

MMM ProgramLoader

Device Drivers

FileSystems

Security Policies Scheduler

SystemAPIs

UserProgram

Page 67: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

MicrokernelKernel Space User Space

MMM ProgramLoader

DeviceDrivers

FileSystems

SecurityPoliciesScheduler

InterprocessCommunication

UserProgram

Page 68: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

HybridKernel Space User Space

MMM ProgramLoader

DeviceDrivers

FileSystems

Security Policies Scheduler

SystemAPIs User

Program

Kernel Code

3rd-Party Code

Page 69: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

ExamplesMicrokernels Hybrid Monolithic

Mach Windows DOS

L4 iOS SunOS

GNU Hurd OS/2 Linux

QNX BeOS OpenVMS

Page 70: CS5600 - PC H/W & Assembly...• alternatives: Amiga, PowePC, DEC Alpha, SPARC, etc. • 1981 IBM PC (compete with Apple) • 1982 Compaq IBM-compatible PC • 1985 IBM clones everywhere!

Monolithic Vs Micro Vs..

• Linux Vs Tanenbaum

• http://www.oreilly.com/openbook/opensources/book/appa.html