+ All Categories
Home > Documents > Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax...

Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax...

Date post: 10-Jul-2020
Category:
Upload: others
View: 7 times
Download: 0 times
Share this document with a friend
30
Lecture 1 How to Boot a PC Andrei Pitis , Operating Systems Practical October 8, 2014 OSP Lecture 1, Booting 1/30
Transcript
Page 1: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

Lecture 1How to Boot a PC

Andrei Pitis,

Operating Systems Practical

October 8, 2014

OSP Lecture 1, Booting 1/30

Page 2: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

Table of Contents

Hardware

Processor

Memory

I/O subsystems

Boot Process

Keywords

Resources

Questions

OSP Lecture 1, Booting 2/30

Page 3: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

Outline

Hardware

Processor

Memory

I/O subsystems

Boot Process

Keywords

Resources

Questions

OSP Lecture 1, Booting 3/30

Page 4: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

Hardware

I ProcessorI Protected mode

I MemoryI Segmentation

I I/O subsystemsI Interrupt controller (8259)I Timer (8253/8254)I KeyboardI Display

OSP Lecture 1, Booting 4/30

Page 5: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

Outline

Hardware

Processor

Memory

I/O subsystems

Boot Process

Keywords

Resources

Questions

OSP Lecture 1, Booting 5/30

Page 6: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

Processor - x86

I Registers:I AX, BX, CX, DXI SI, DII CS, DS, ES, SSI SP, BP, IPI FlagsI GDTR, LDTR, IDTR

OSP Lecture 1, Booting 6/30

Page 7: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

Protected Mode

OSP Lecture 1, Booting 7/30

Page 8: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

Outline

Hardware

Processor

Memory

I/O subsystems

Boot Process

Keywords

Resources

Questions

OSP Lecture 1, Booting 8/30

Page 9: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

Segmentation

OSP Lecture 1, Booting 9/30

Page 10: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

LDT/GDT

LDT1 d e s c r i p t o r < , , , > ; dummy 07hd e s c r i p t o r <01000h , o f f s e t code1 , , 11111010b> ; code 0Fhd e s c r i p t o r <01000h , o f f s e t data1 , , 11110010b> ; data 17hd e s c r i p t o r < , , 2 , 11110110b> ; s t a c k 1Fhd e s c r i p t o r <00001h , o f f s e t shdata , , 11110010b> ; s ha r ed data 27h

GDT d e s c r i p t o r < , , , > ; dummy 0hd e s c r i p t o r <0FFFFh , , , 10011010b> ; code 8hd e s c r i p t o r <0FFFFh , , , 10010010b> ; data 10hd e s c r i p t o r < , , , 10010110b> ; s t a c k 18hd e s c r i p t o r <0FFFFh , 8000h , 0Bh , 11110010b> ; v i d e o 23h

d e s c r i p t o r <00007h , o f f s e t LDT0 , , 10000010b> ; LDT0 28hd e s c r i p t o r <0002Bh , o f f s e t TSS0 , , 10000001b> ; TSS0 30h

OSP Lecture 1, Booting 10/30

Page 11: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

Outline

Hardware

Processor

Memory

I/O subsystems

Boot Process

Keywords

Resources

Questions

OSP Lecture 1, Booting 11/30

Page 12: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

PIC - 8259

OSP Lecture 1, Booting 12/30

Page 13: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

8259 - cascade

I The original 8086 hadonly one PIC

I Needed more devices- cascaded a secondPIC

OSP Lecture 1, Booting 13/30

Page 14: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

Interrupts - real mode

I 00-01 - Exception handlers

I 02 - NMI

I 03-07 - Exception handlers

I 08-0F - IRQ0 - IRQ7

I 10-6F - Software interrupts

I 70-77 - IRQ8 - IRQ15

I 78-FF - Software interrupts

OSP Lecture 1, Booting 14/30

Page 15: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

Interrupts - protected mode

I IDT - Interrupt Descriptor Table

OSP Lecture 1, Booting 15/30

Page 16: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

init 8259

i n i t 8 2 5 9 proc near

mov a l , 11 h ; ICW1 : edge , c a l l a dd r e s s i n t e r v a l 8 , cascaded , sed ICW4out 20h , a lout 0A0h , a l

mov a l , 20 h ; ICW2 : f i r s t 8 IRQs s t a r t a t 20h a f t e r the r e s e r v e d e x c e p t i o n sout 21h , a l

mov a l , 28 h ; ICW2 : next 8 IRQS a r e immed i a t e l y a f t e rout 0A1h , a l

mov a l , 4 ; ICW3 : IRQ2 i s connected to a s l a v eout 21h , a l

mov a l , 2out 0A1h , a l ; ICW3 : S l a v e ID 2

mov a l , 1 ; ICW4 : 8086 Modeout 021h , a lout 0A1h , a l

mov a l , 0 FFhout 0A1h , a l ; OCW1: Mask a l l i n t s on PIC2mov a l , 0 FCh ; OCW1: mask a l l i n t s but t ime r and keyboard on PIC1out 021h , a l

r e t

endp

OSP Lecture 1, Booting 16/30

Page 17: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

Timer - 8253

OSP Lecture 1, Booting 17/30

Page 18: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

Timer - 8253

OSP Lecture 1, Booting 18/30

Page 19: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

Timer - 8253

i n i t 8 2 5 3 proc near

mov a l , 36 h ; LSB then MSB, mode 011out 43h , a lmov ax , 11932 ; c l o c k f r e q i s 1193181 .8181 . .Hz , 1/3 NTSC c o l o r s u b c a r r i e r f r e qjmp $ + 2jmp $ + 2out 40h , a ljmp $ + 2jmp $ + 2mov a l , ahout 40h , a lr e t s

endp

OSP Lecture 1, Booting 19/30

Page 20: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

Scheduler

c l k proc f a r ; Task s c h e d u l e r (100 Hz)

push axpush bxpush dsmov ax , 10 hmov ds , ax

add task , 18 hcmp task , 88 hj ne jmp fa rmov task , 40 hjmp jmp fa r

jmp fa r : mov bx , t a s kand GDT[ bx ] . r i g h t s , 0FDh

mov a l , 20 hout 20h , a l

pop dspop bxpop ax

db 0EAh ; jmp TSSi ( i = 1 , 2 , 3)dw 0

t a s k dw 40h

i r e t

OSP Lecture 1, Booting 20/30

Page 21: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

Outline

Hardware

Processor

Memory

I/O subsystems

Boot Process

Keywords

Resources

Questions

OSP Lecture 1, Booting 21/30

Page 22: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

Boot process

I POST

I Search boot device: floppy, HD, etc

I Load MBR at 0000:7C00

I Jump at that address

I Usually the code in the MBR looks for the active partition,loads its first sector also at 7C00 and jumps there

I We will instead load sectors from the disk and jump

OSP Lecture 1, Booting 22/30

Page 23: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

Boot sequence

OSP Lecture 1, Booting 23/30

Page 24: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

Bootstrap

s t a r t : c l i

xor ax , axmov ss , axmov sp , 7 C00hmov s i , spmov ds , axmov es , axs t ic l dmov di , 600 hmov cx , 100 hrepnz movswdb 0EAhdw 61Dh , 0 ; jmp f a r p t r 0000:061D

r e a l s t a r t :

OSP Lecture 1, Booting 24/30

Page 25: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

Outline

Hardware

Processor

Memory

I/O subsystems

Boot Process

Keywords

Resources

Questions

OSP Lecture 1, Booting 25/30

Page 26: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

Keywords

I processor

I memory

I i/o subsystems

I boot process

I bootstrap

I 0x7c00

I interrupts

I timer

I 8259

I 8253

OSP Lecture 1, Booting 26/30

Page 27: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

Outline

Hardware

Processor

Memory

I/O subsystems

Boot Process

Keywords

Resources

Questions

OSP Lecture 1, Booting 27/30

Page 28: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

Resources

I Use the source, Luke!

OSP Lecture 1, Booting 28/30

Page 29: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

Outline

Hardware

Processor

Memory

I/O subsystems

Boot Process

Keywords

Resources

Questions

OSP Lecture 1, Booting 29/30

Page 30: Lecture 1 - How to Boot a PCelf.cs.pub.ro/soa/res/lectures/slides/lecture-01-booting.pdf · mov ax ,10h mov ds , ax add task ,18h cmp task ,88h jne jmpfar mov task ,40h jmp jmpfar

Questions

?

OSP Lecture 1, Booting 30/30


Recommended