INF[34]151 – Operating Systems From Real Mode to Protected ... · (Brief description) ... .word...

19
From Real Mode to From Real Mode to Protected Mode Protected Mode 04/09 – 2009 INF[34]151 – Operating Systems

Transcript of INF[34]151 – Operating Systems From Real Mode to Protected ... · (Brief description) ... .word...

Page 1: INF[34]151 – Operating Systems From Real Mode to Protected ... · (Brief description) ... .word bla bla bla # limit.long bla bla bla # base address.align 8 gdt: # the first entry

From Real Mode to From Real Mode to Protected ModeProtected Mode

04/09 – 2009

INF[34]151 – Operating Systems

Page 2: INF[34]151 – Operating Systems From Real Mode to Protected ... · (Brief description) ... .word bla bla bla # limit.long bla bla bla # base address.align 8 gdt: # the first entry

2007 Jørn Uno Myrvoll & Jon Anders SkorpenINF[34]151 – Operating Systems

Topics Today

Basic Execution Environment (Brief description)

Protected Mode (Setup)

Code Example (Next week!)

Next Weeks (What lies ahead?)

Page 3: INF[34]151 – Operating Systems From Real Mode to Protected ... · (Brief description) ... .word bla bla bla # limit.long bla bla bla # base address.align 8 gdt: # the first entry

2007 Jørn Uno Myrvoll & Jon Anders SkorpenINF[34]151 – Operating Systems

Basic Execution Environment

Address space Basic program execution registers x87 FPU registers Stack MMX registers XMM registers

I/O ports, Control registers, Memory management registers, Debug registers, memory type range registers, Machine specific registers, Machine check registers, Performance monitoring counters.

Page 4: INF[34]151 – Operating Systems From Real Mode to Protected ... · (Brief description) ... .word bla bla bla # limit.long bla bla bla # base address.align 8 gdt: # the first entry

2007 Jørn Uno Myrvoll & Jon Anders SkorpenINF[34]151 – Operating Systems

Three Memory Models

Real-Address Mode Model Segmented Model Flat Model

Much more on memory organizationlater in the course.

Page 5: INF[34]151 – Operating Systems From Real Mode to Protected ... · (Brief description) ... .word bla bla bla # limit.long bla bla bla # base address.align 8 gdt: # the first entry

Protected Mode

Page 6: INF[34]151 – Operating Systems From Real Mode to Protected ... · (Brief description) ... .word bla bla bla # limit.long bla bla bla # base address.align 8 gdt: # the first entry

2007 Jørn Uno Myrvoll & Jon Anders SkorpenINF[34]151 – Operating Systems

Control Registers CR0 - CR3

CR0 Used to enable protected mode and paging

(PM enabled by writing 1 to bit 0 after setup.)

CR1 Not implemented on any x86 processors ->

Pentium

CR2 (more later) Page fault linear address

CR3 (more later) Page Directory Base Address Register

31 0PEPG

Page 7: INF[34]151 – Operating Systems From Real Mode to Protected ... · (Brief description) ... .word bla bla bla # limit.long bla bla bla # base address.align 8 gdt: # the first entry

2007 Jørn Uno Myrvoll & Jon Anders SkorpenINF[34]151 – Operating Systems

Segment Registers in Real Mode

Contains only the upper 16 bits of a segment's base address.

The lower nibble is asumed to be 0000, giving a 20 bit base address.

Page 8: INF[34]151 – Operating Systems From Real Mode to Protected ... · (Brief description) ... .word bla bla bla # limit.long bla bla bla # base address.align 8 gdt: # the first entry

2007 Jørn Uno Myrvoll & Jon Anders SkorpenINF[34]151 – Operating Systems

Segment Registers in Protected Mode

The segment registers contains the visible part of a segment selector.

An invisible part is stored in memory in a Global Descriptor Table (GDT) or Local Descriptor Table (LDT).

Page 9: INF[34]151 – Operating Systems From Real Mode to Protected ... · (Brief description) ... .word bla bla bla # limit.long bla bla bla # base address.align 8 gdt: # the first entry

2007 Jørn Uno Myrvoll & Jon Anders SkorpenINF[34]151 – Operating Systems

Privilege Levels

Page 10: INF[34]151 – Operating Systems From Real Mode to Protected ... · (Brief description) ... .word bla bla bla # limit.long bla bla bla # base address.align 8 gdt: # the first entry

2007 Jørn Uno Myrvoll & Jon Anders SkorpenINF[34]151 – Operating Systems

What does the OS need to know?

Wich task? Start address. Length. Access attribute.

Read only, Execute only, Read/Write

Privilege level (minimum level to access.) Code, data or special segment? Present in memory?

Page 11: INF[34]151 – Operating Systems From Real Mode to Protected ... · (Brief description) ... .word bla bla bla # limit.long bla bla bla # base address.align 8 gdt: # the first entry

2007 Jørn Uno Myrvoll & Jon Anders SkorpenINF[34]151 – Operating Systems

GDTR -> GDT [-> LDT] -> Segments

The Descriptor Tables GDT and LDT

Page 12: INF[34]151 – Operating Systems From Real Mode to Protected ... · (Brief description) ... .word bla bla bla # limit.long bla bla bla # base address.align 8 gdt: # the first entry

2007 Jørn Uno Myrvoll & Jon Anders SkorpenINF[34]151 – Operating Systems

Local Descriptor Table Descriptor

Page 13: INF[34]151 – Operating Systems From Real Mode to Protected ... · (Brief description) ... .word bla bla bla # limit.long bla bla bla # base address.align 8 gdt: # the first entry

2007 Jørn Uno Myrvoll & Jon Anders SkorpenINF[34]151 – Operating Systems

Local Descriptor Table

Page 14: INF[34]151 – Operating Systems From Real Mode to Protected ... · (Brief description) ... .word bla bla bla # limit.long bla bla bla # base address.align 8 gdt: # the first entry

2007 Jørn Uno Myrvoll & Jon Anders SkorpenINF[34]151 – Operating Systems

General Format of Segment Descriptor

Page 15: INF[34]151 – Operating Systems From Real Mode to Protected ... · (Brief description) ... .word bla bla bla # limit.long bla bla bla # base address.align 8 gdt: # the first entry

2007 Jørn Uno Myrvoll & Jon Anders SkorpenINF[34]151 – Operating Systems

Global Descriptor Table

Page 16: INF[34]151 – Operating Systems From Real Mode to Protected ... · (Brief description) ... .word bla bla bla # limit.long bla bla bla # base address.align 8 gdt: # the first entry

2007 Jørn Uno Myrvoll & Jon Anders SkorpenINF[34]151 – Operating Systems

GDT and LDT

Page 17: INF[34]151 – Operating Systems From Real Mode to Protected ... · (Brief description) ... .word bla bla bla # limit.long bla bla bla # base address.align 8 gdt: # the first entry

2007 Jørn Uno Myrvoll & Jon Anders SkorpenINF[34]151 – Operating Systems

Switching to Protected Modeclilgdt gdtrsmsw %axorw $1,%axlmsw %ax

gdtr:.word bla bla bla # limit.long bla bla bla # base address

.align 8gdt:

# the first entry of the GDT is not used by the processor.long 0.long 0

# kernel code segment descriptor (same for bootblock).word bla bla bla # limit.word bla bla bla # base 15:00.byte bla bla bla # base 23:16.word bla bla bla # flags.byte bla bla bla # base 31:24

# kernel data segment descriptor.word bla bla bla # limit.word bla bla bla # base 15:00.byte bla bla bla # base 23:16.word bla bla bla # flags.byte bla bla bla # base 31:24

Page 18: INF[34]151 – Operating Systems From Real Mode to Protected ... · (Brief description) ... .word bla bla bla # limit.long bla bla bla # base address.align 8 gdt: # the first entry

2007 Jørn Uno Myrvoll & Jon Anders SkorpenINF[34]151 – Operating Systems

What lies ahead?

Next week: Project 2 Precode Discussion Read and understand the precode No preparation = No discussion

Week after next: Interrupts PIC PIT

Page 19: INF[34]151 – Operating Systems From Real Mode to Protected ... · (Brief description) ... .word bla bla bla # limit.long bla bla bla # base address.align 8 gdt: # the first entry

Q&A

Questions?