Micro Arch2

14
Systems Design & Programming Micro. Arch. II CMPE 310 1 (Feb. 2, 2002) UMBC U M B C UN IV E R S IT Y O F M A R Y L A N D B A L T I M O R E C O U N T Y 1 9 6 6 Protected Mode Memory Addressing Segments are interpreted differently in Protected Mode vs. Real Mode: • Segment register contains a selector that selects a descriptor from the descriptor table. • The descriptor contains information about the segment, e.g., it’s base address, length and access rights. • The offset can be 32-bits. Descriptor Table FFFFFFFF 00000000 DS 0008 Memory System Data Segment ... ... + EBX ... 0000FF00 0000FF00 0000FF88 Selector 00000088 Offset Base

description

processor

Transcript of Micro Arch2

Page 1: Micro Arch2

Syst

ems

Des

ign

& P

rogr

amm

ing

Mic

ro. A

rch.

II

CM

PE 3

10

1(F

eb. 2

, 200

2)U

MB

CU

M B

C

UNIVERSITY OF M

AR

YL

AN

D B

ALTIM

ORE COUNTY

1 9

6 6

Pro

tect

ed M

ode

Mem

ory

Add

ress

ing

Segm

ents

are

inte

rpre

ted

diff

eren

tly in

Pro

tect

ed M

ode

vs. R

eal M

ode:

•Se

gmen

treg

iste

rcon

tain

sa

sele

ctor

that

sele

cts

ade

scri

ptor

from

the

desc

ript

orta

ble.

• T

hede

scri

ptor

con

tain

s in

form

atio

n ab

out t

he s

egm

ent,

e.g.

, it’s

bas

e ad

dres

s,le

ngth

and

acc

ess

righ

ts.

• T

he o

ffse

t can

be

32-b

its.

Des

crip

tor

Tabl

e

FFFF

FFFF

0000

0000

DS 00

08M

emor

y Sy

stem

Dat

aSe

gmen

t

... ...

+

EB

X

... 0

000F

F00

0000

FF00

0000

FF88

Sele

ctor

0000

0088

Off

set

Bas

e

Page 2: Micro Arch2

Syst

ems

Des

ign

& P

rogr

amm

ing

Mic

ro. A

rch.

II

CM

PE 3

10

2(F

eb. 2

, 200

2)U

MB

CU

M B

C

UNIVERSITY OF M

AR

YL

AN

D B

ALTIM

ORE COUNTY

1 9

6 6

Segm

ent

Des

crip

tors

in P

rote

cted

Mod

e

•B

ase

addr

ess:

Star

ting

loca

tion

of th

e m

emor

y se

gmen

t.

•L

imit

:L

engt

h of

the

segm

ent m

inus

1.

20-b

its a

llow

s se

gmen

ts u

p to

1 M

B.

Thi

sva

lue

issh

ifte

dby

12bi

tsto

the

left

whe

nth

eG

(Gra

nula

rity

bit)

isse

tto

1.

Lim

it

015

3916

40B

ase

(L15

-L0)

(B23

-B0)

Acc

ess

Rig

hts

4748

(L19

-55

56B

ase

(B31

-B24

)L

16)

01

23

45

67

GD

XU

5152

63

byte

PD

PLS

AT

YPE

Page 3: Micro Arch2

Syst

ems

Des

ign

& P

rogr

amm

ing

Mic

ro. A

rch.

II

CM

PE 3

10

3(F

eb. 2

, 200

2)U

MB

CU

M B

C

UNIVERSITY OF M

AR

YL

AN

D B

ALTIM

ORE COUNTY

1 9

6 6

Segm

ent

Des

crip

tors

in P

rote

cted

Mod

eSe

gmen

t Des

crip

tors

: Bits

52-

55•

G b

it:

Whe

n G

=0,

seg

men

ts c

an b

e 1

byte

to 1

MB

in le

ngth

.W

hen

G=

1, s

egm

ents

can

be

4KB

to 4

GB

in le

ngth

.

•U

bit

:U

ser

(OS)

defi

ned

bit.

•D

bit

:In

dica

tes

how

the

inst

ruct

ions

(80

386

and

up)

acce

ss r

egis

ter

and

mem

ory

data

in p

rote

cted

mod

e.•

Whe

n D

=0,

inst

ruct

ions

are

16-

bit i

nstr

uctio

ns, w

ith 1

6-bi

t off

sets

and

16-

bit

regi

ster

s. S

tack

s ar

e as

sum

ed 1

6-bi

t wid

e an

d SP

is u

sed.

• W

hen

D=

1, 3

2-bi

ts a

re a

ssum

ed.

Allo

ws

8086

-802

86 p

rogr

ams

to r

un.

•X

bit

:R

eser

ved

by I

ntel

Page 4: Micro Arch2

Syst

ems

Des

ign

& P

rogr

amm

ing

Mic

ro. A

rch.

II

CM

PE 3

10

4(F

eb. 2

, 200

2)U

MB

CU

M B

C

UNIVERSITY OF M

AR

YL

AN

D B

ALTIM

ORE COUNTY

1 9

6 6

Segm

ent

Des

crip

tors

in P

rote

cted

Mod

eSe

gmen

t Des

crip

tors

: Acc

ess

Rig

hts

(Byt

e 5)

:

The

Acc

ess

Rig

hts

(AR

) by

te c

ontr

ols

acce

ss to

a p

rote

cted

mod

e se

gmen

t and

how

the

segm

ent f

unct

ions

in th

e sy

stem

.

PD

PLS

A

A=

0, S

egm

ent n

ot a

cces

sed

A=

1, S

egm

ent h

as b

een

acce

ssed

000

Dat

a, r

ead-

only

001

Dat

a, r

ead/

wri

te

010

Sta

ck, r

ead-

only

S =

0, S

yste

m d

escr

ipto

rS

= 1

, Cod

e, d

ata

or s

tack

Sets

the

desc

. pri

vile

ge le

vel.

P =

0, d

escr

ipto

r is

und

efine

d.P

= 1

, des

crip

tor

cont

ains

a v

alid

base

and

lim

it.

011

Sta

ck, r

ead/

wri

te

100

Cod

e, e

xecu

te-o

nly

101

Cod

e, e

xecu

te/r

ead

110

Cod

e, e

xecu

te-o

nly,

con

form

ing

111

Cod

e, e

xecu

te/r

ead,

con

form

ing

TY

PE

Page 5: Micro Arch2

Syst

ems

Des

ign

& P

rogr

amm

ing

Mic

ro. A

rch.

II

CM

PE 3

10

5(F

eb. 2

, 200

2)U

MB

CU

M B

C

UNIVERSITY OF M

AR

YL

AN

D B

ALTIM

ORE COUNTY

1 9

6 6

Segm

ent

Des

crip

tors

in P

rote

cted

Mod

eD

etai

ls:

The

A (

acce

ssed

) bi

t is

set a

utom

atic

ally

by

the

mic

ropr

oces

sor

and

is n

ever

clea

red.

Thi

s al

low

s O

S co

de to

trac

k fr

eque

ncy

of u

sage

.

The

P (

pres

ent)

bit

shou

ld b

e in

terp

rete

d as

“de

scri

ptor

-is-

valid

”.If

this

bit

is 0

, the

mic

ropr

oces

sor

will

refu

se a

ny a

ttem

pts

to u

se th

isde

scri

ptor

in a

n in

stru

ctio

n.

Alth

ough

the

AR

mus

talw

ays

beva

lid,w

hen

P=0,

the

rest

ofth

ede

scri

ptor

can

be u

sed

in a

ny w

ay th

e O

S lik

es.

The

S (s

yste

m)

bit i

ndic

ates

how

the

desc

ript

or is

to b

e in

terp

rete

d.S=

1 in

dica

tes

a sy

stem

des

crip

tor

(mor

e on

this

late

r).

S=0

indi

cate

s a

code

, dat

a or

sta

ck d

escr

ipto

r.

039

40A

cces

sR

ight

s

47

Ava

ilabl

e

63

Ava

ilabl

e

Page 6: Micro Arch2

Syst

ems

Des

ign

& P

rogr

amm

ing

Mic

ro. A

rch.

II

CM

PE 3

10

6(F

eb. 2

, 200

2)U

MB

CU

M B

C

UNIVERSITY OF M

AR

YL

AN

D B

ALTIM

ORE COUNTY

1 9

6 6

Segm

ent

Des

crip

tors

in P

rote

cted

Mod

eD

etai

ls:

Non

-sys

tem

(S=

0) s

egm

ents

:•

Typ

e=0:

The

dat

a se

gmen

t is

basi

cally

a R

OM

.•

Typ

e=1:

Bot

h re

ad a

nd w

rite

ope

ratio

ns a

llow

ed.

Cod

e ca

nN

OT

be f

etch

ed a

nd e

xecu

ted

from

eith

er o

f th

ese

segm

ent t

ypes

.

•T

ype=

2 or

3: A

sta

ck s

egm

ent i

s de

fined

ana

logo

usly

to T

ypes

0 a

nd 1

.

How

ever

, the

inte

rpre

tatio

n of

the

limit

field

is d

iffe

rent

.In

this

cas

e, a

ll of

fset

s m

ust b

egr

eate

r th

an th

e lim

it.T

he u

pper

lim

it is

set

to b

ase

addr

ess

+ F

FFF

(with

D=

0) o

r ba

se a

ddre

ss +

FFFF

FFFF

(w

ith D

=1)

.

Thi

s m

eans

the

stac

k se

gmen

tend

s 1

byte

belo

w th

e ba

se a

ddre

ss.

Exp

andi

ng o

f th

e st

ack

segm

ent s

impl

y in

volv

esde

crea

sing

the

limit.

Page 7: Micro Arch2

Syst

ems

Des

ign

& P

rogr

amm

ing

Mic

ro. A

rch.

II

CM

PE 3

10

7(F

eb. 2

, 200

2)U

MB

CU

M B

C

UNIVERSITY OF M

AR

YL

AN

D B

ALTIM

ORE COUNTY

1 9

6 6

Segm

ent

Des

crip

tors

in P

rote

cted

Mod

eD

etai

ls:

•T

ype=

4: A

cod

e se

gmen

t with

no

read

per

mis

sion

.T

his

mea

ns n

o co

nsta

nts

are

allo

wed

, sin

ce th

ey c

anno

t be

read

out

.

•T

ype=

5: A

cod

e se

gmen

t in

whi

ch c

onst

ants

may

be

embe

dded

.

In e

ither

cas

e, n

o w

ritin

g (s

elf-

mod

ifyi

ng c

ode)

is p

erm

itted

.

•T

ype=

6 an

d 7:

Ana

logo

us to

Typ

es 4

and

5w

itho

utpr

ivile

ge p

rote

ctio

n.W

e’ll

disc

uss

the

mea

ning

of

“con

form

ing”

soo

n.4GB

0

Bas

e +

FFF

FFFF

F

Bas

e +

lim

itSt

ack

segm

ent a

rea

botto

m

top

Gro

wth

dir

ectio

n

Bas

e

Page 8: Micro Arch2

Syst

ems

Des

ign

& P

rogr

amm

ing

Mic

ro. A

rch.

II

CM

PE 3

10

8(F

eb. 2

, 200

2)U

MB

CU

M B

C

UNIVERSITY OF M

AR

YL

AN

D B

ALTIM

ORE COUNTY

1 9

6 6

Segm

ent

Reg

iste

rs in

Pro

tect

ed M

ode

Inte

rpre

tatio

n:

Des

crip

tor

Inde

x an

dTa

ble

Inde

x (T

I):

The

13bi

tdes

crip

tori

ndex

sele

cts

one

ofup

to8K

desc

ript

ors

inei

ther

the

GD

Tan

d L

DT,

as

spec

ified

by

the

TI

bit.

The

refo

re, t

hese

14

bits

allo

ws

acce

ss to

16K

8-b

yte

desc

ript

ors.

RP

L: T

he d

esir

ed p

rivi

lege

leve

l of

the

prog

ram

.A

cces

s is

gra

nted

if th

e R

PL v

alue

is lo

wer

(hi

gher

in p

rivi

lege

) th

an th

e A

R o

fth

e se

gmen

t. O

ther

wis

e, a

pri

vile

ge v

iola

tion

is is

sued

.

01

23

15Se

lect

or

TI

RPL

RPL

= R

eque

sted

pri

vile

gele

vel.

00 is

hig

hest

and

11

is lo

wes

t.T

I =

0, G

loba

l Des

crip

tor

Tabl

e.T

I =

1, L

ocal

Des

crip

tor

Tabl

e.

13-b

its

Sele

cts

one

of th

e 81

92de

scri

ptor

s.

Des

crip

tor

Inde

x

Page 9: Micro Arch2

Syst

ems

Des

ign

& P

rogr

amm

ing

Mic

ro. A

rch.

II

CM

PE 3

10

9(F

eb. 2

, 200

2)U

MB

CU

M B

C

UNIVERSITY OF M

AR

YL

AN

D B

ALTIM

ORE COUNTY

1 9

6 6

Segm

enta

tion

Add

ress

Tra

nsla

tion

So in

stea

d of

left

shi

ftin

g by

4 b

its in

Rea

l Mod

e to

for

m th

e se

gmen

t add

ress

, we

righ

t shi

ft b

y 3

bits

and

use

the

valu

e as

a ta

ble

inde

x.

Glo

bal D

escr

ipto

r Ta

ble

0100

00

92 1

0 00

00

00 F

F

FFFF

FF

0000

00

1000

00

DS

0 0

0 8

Mem

ory

Syst

em

1000

FF

Dat

aSe

gmen

tL

imit

Bas

e

Acc

ess

righ

ts

Not

e:D

escr

ipto

r 0

is c

alle

d th

eN

UL

Lde

scri

ptor

and

may

not

be u

sed

to a

cces

sm

emor

y.

2... ...

Not

e: th

ere

is n

om

eani

ngas

soci

ated

the

rela

tive

posi

tion

of th

e se

gmen

tde

scri

ptor

s in

the

tabl

e --

unl

ike

page

tabl

es a

sw

e w

ill s

ee.

+

ESI 00

0000

FF

Page 10: Micro Arch2

Syst

ems

Des

ign

& P

rogr

amm

ing

Mic

ro. A

rch.

II

CM

PE 3

10

10(F

eb. 2

, 200

2)U

MB

CU

M B

C

UNIVERSITY OF M

AR

YL

AN

D B

ALTIM

ORE COUNTY

1 9

6 6

Segm

enta

tion

Add

ress

Tra

nsla

tion

The

re a

re a

ctua

lly th

ree

diff

eren

t des

crip

tor

tabl

es,G

DT

,LD

T a

ndID

T.

Exa

ctly

one

GD

T a

ndID

T m

ust b

e de

fined

for

Pro

tect

ed M

ode

oper

atio

n.

• G

loba

l Des

crip

tor

Tabl

e (G

DT

).T

he G

DT

is u

sed

by a

ll pr

ogra

ms.

• L

ocal

Des

crip

tor

Tabl

e (L

DT

).A

n L

DT

can

opt

iona

lly b

e de

fined

on

a pe

r-ta

sk b

asis

and

is u

sed

to e

xpan

dth

e ad

dres

sabl

e ra

nge

of th

e ta

sk.

• In

terr

upt D

escr

ipto

r Ta

ble

(ID

T).

The

ID

T is

a d

irec

t rep

lace

men

t to

the

inte

rrup

t vec

tor

tabl

e us

ed in

808

6sy

stem

s.

Not

eth

atre

fere

nces

toID

Tar

edo

neth

roug

hth

eha

rdw

are

inte

rrup

tmec

hani

sm,a

ndno

t fro

m a

pro

gram

via

a s

elec

tor.

Page 11: Micro Arch2

Syst

ems

Des

ign

& P

rogr

amm

ing

Mic

ro. A

rch.

II

CM

PE 3

10

11(F

eb. 2

, 200

2)U

MB

CU

M B

C

UNIVERSITY OF M

AR

YL

AN

D B

ALTIM

ORE COUNTY

1 9

6 6

Segm

enta

tion

Add

ress

Tra

nsla

tion

Prog

ram

mer

invi

sibl

e re

gist

ers:

The

GD

T a

ndID

T (

and

LD

T)

are

loca

ted

in th

e m

emor

y sy

stem

.

The

add

ress

es o

f th

e G

DT

and

ID

T a

nd th

eir

limits

(up

to 6

4K b

ytes

) ar

e lo

aded

insp

ecia

lreg

iste

rs,G

DT

Ran

dID

TR

,bef

ore

switc

hing

toPr

otec

ted

Mod

eis

poss

ible

.

CS

DS

ES SS FS GS

Segm

ent

regi

ster

sD

escr

ipto

r C

ache

Bas

e A

ddre

ssL

imit

Acc

ess

TR

LD

TR

Bas

e A

ddre

ssL

imit

Acc

ess

Bas

e A

ddre

ssL

imit

Des

crip

tor

Tabl

e A

ddre

sses

GD

TR

IDT

R16

-bits

32-b

its

Sele

ctor

Sele

ctor

Sele

ctor

Page 12: Micro Arch2

Syst

ems

Des

ign

& P

rogr

amm

ing

Mic

ro. A

rch.

II

CM

PE 3

10

12(F

eb. 2

, 200

2)U

MB

CU

M B

C

UNIVERSITY OF M

AR

YL

AN

D B

ALTIM

ORE COUNTY

1 9

6 6

Segm

enta

tion

Add

ress

Tra

nsla

tion

Prog

ram

mer

invi

sibl

e re

gist

ers:

The

oth

er r

egis

ters

enc

lose

d by

the

red-

dotte

d lin

e ar

e pa

rt o

f th

e de

scri

ptor

cach

e.T

heca

che

isus

edto

redu

ceth

enu

mbe

rofa

ctua

lmem

ory

refe

renc

esne

eded

to c

onst

ruct

the

phys

ical

add

ress

.

The

reis

one

cach

ere

gist

erfo

rea

chof

the

6se

gmen

treg

iste

rs,C

S,D

S,et

c.an

dth

e L

DT

R (

Loc

al D

escr

ipto

r Ta

ble

Reg

iste

r) a

nd T

R (

Task

Reg

iste

r) s

elec

tors

.

The

bas

e ad

dres

s, li

mit

and

acce

ss r

ight

s of

the

desc

ript

or a

re lo

aded

fro

mm

emor

y ev

ery

time

the

corr

espo

ndin

gse

lect

orch

ange

s.

The

LD

TR

and

TR

sel

ecto

rs r

efer

to s

peci

alsy

stem

des

crip

tors

in th

e G

DT.

The

se r

egis

ters

pro

vide

har

dwar

e ac

cele

ratio

n su

ppor

t for

task

sw

itchi

ng.

Let

’sfir

stco

nsid

erho

wL

DT

sar

eus

edto

exte

ndth

ead

dres

ssp

ace

ofin

divi

dual

task

s.

Page 13: Micro Arch2

Syst

ems

Des

ign

& P

rogr

amm

ing

Mic

ro. A

rch.

II

CM

PE 3

10

13(F

eb. 2

, 200

2)U

MB

CU

M B

C

UNIVERSITY OF M

AR

YL

AN

D B

ALTIM

ORE COUNTY

1 9

6 6

Loc

al D

escr

ipto

r Ta

bles

The

LD

TR

sele

ctor

inde

xes

a G

DT

syst

em d

escr

ipto

r de

scri

bing

the

segm

ent c

on-

tain

ing

the

LD

T w

hile

the

cach

e st

ores

the

actu

al L

DT

des

crip

tor.

The

LD

TR

sel

ecto

r ca

n be

load

ed w

ith a

new

val

ue w

hen

anot

her

task

is r

un.

FFFF

FF

0000

00

DS

1

GD

TR

LD

TR

Des

crip

tor

LD

T D

escr

ipto

r

Des

crip

tor

Dat

a D

escr

ipto

r

ESI

Data LDT GDT

LD

Tca

che

32-b

it O

ffse

t

Page 14: Micro Arch2

Syst

ems

Des

ign

& P

rogr

amm

ing

Mic

ro. A

rch.

II

CM

PE 3

10

14(F

eb. 2

, 200

2)U

MB

CU

M B

C

UNIVERSITY OF M

AR

YL

AN

D B

ALTIM

ORE COUNTY

1 9

6 6

Loc

al D

escr

ipto

r Ta

bles

LD

T S

egm

ent D

escr

ipto

r:

Bit

44: T

he S

flag

is c

lear

to in

dica

te a

n L

DT

des

crip

tor.

Bit

40-4

3:T

heTy

pefie

ldis

exte

nded

to4

bits

(no

Acc

esse

dbi

t).T

ype

2(0

010)

indi

cate

s a

LD

T d

escr

ipto

r.

Bit

47:I

fth

ePr

esen

tbit

isno

tset

(e.g

.the

reis

noL

DT

defin

ed),

the

80x8

6w

illno

t allo

w y

ou to

load

the

LD

TR

with

its

sele

ctor

.

Bit

0-15

, 16-

19:A

lthou

gh th

e lim

it is

stil

l 20

bits

(an

d th

e G

bit

is a

lso

valid

),se

gmen

ts la

rger

than

64K

B d

on’t

mak

e se

nse!

Lim

it0

1539

1640

Bas

e(1

5-0)

(23-

0)P0

0000

10

4748

(19-

5556

Bas

e(3

1-24

)16

)

5152

63

0000

Lim