1 / 40 Implementation of Paging in uCOS-II 20100422 Ke, Dian Chia.

Slides:



Advertisements
Similar presentations
1/1/ / faculty of Electrical Engineering eindhoven university of technology Memory Management and Protection Part 3:Virtual memory, mode switching,
Advertisements

Copyright © 2001, Daniel W. Lewis. All Rights Reserved. CHAPTER 11 SYSTEM INITIALIZATION.
PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)
Unit 4 Chapter-1 Multitasking. The Task State Segment.
Genesis: from raw hardware to processes System booting sequence: how does a machine come into life.
16.317: Microprocessor System Design I
Intel MP.
Microprocessors system architectures – IA32 real and virtual-8086 mode Jakub Yaghob.
OS Memory Addressing.
Set 20 Interrupts. INTERRUPTS The Pentium has a mechanism whereby external devices can interrupt it. Devices such as the keyboard, the monitor, hard disks.
Operating Systems: Segments 1 Segmentation Hardware Support single user program system: – wish somehow to relocate address 0 to after operating system.
1 Operating Systems and Protection CS Goals of Today’s Lecture How multiple programs can run at once  Processes  Context switching  Process.
IA-32 Processor Architecture
1 Hardware and Software Architecture Chapter 2 n The Intel Processor Architecture n History of PC Memory Usage (Real Mode)
CSS 372 Lecture 1 Course Overview: CSS 372 Web page Syllabus Lab Ettiquette Lab Report Format Review of CSS 371: Simple Computer Architecture Traps Interrupts.
X86 segmentation, page tables, and interrupts 3/17/08 Frans Kaashoek MIT
PC hardware and x86 3/3/08 Frans Kaashoek MIT
1 Operating Systems and Protection Professor Jennifer Rexford CS 217.
CS2422 Assembly Language & System Programming November 2, 2006.
Chapter 7 Interupts DMA Channels Context Switching.
Midterm Tuesday October 23 Covers Chapters 3 through 6 - Buses, Clocks, Timing, Edge Triggering, Level Triggering - Cache Memory Systems - Internal Memory.
Hardware Support for Operating Systems Sunny Gleason Vivek Uppal COM S 414
Computer System Structures memory memory controller disk controller disk controller printer controller printer controller tape-drive controller tape-drive.
CS2422 Assembly Language & System Programming September 22, 2005.
Microprocessor Systems Design I Instructor: Dr. Michael Geiger Fall 2012 Lecture 15: Protected mode intro.
Administrative Overview 6 Projects Design Review: Monday before 6:30pm Lab Friend Center 010 (“Fishbowl”)
UNIT 2 Memory Management Unit and Segment Description and Paging
General System Architecture and I/O.  I/O devices and the CPU can execute concurrently.  Each device controller is in charge of a particular device.
Lecture 2. General-Purpose (GP) Computer Systems Prof. Taeweon Suh Computer Science Education Korea University ECM586 Special Topics in Embedded Systems.
80386DX.
6.828: PC hardware and x86 Frans Kaashoek
OPERATING SYSTEM OVERVIEW. Contents Basic hardware elements.
The Pentium Processor.
The Pentium Processor Chapter 3 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
The Intel Microprocessors. Real Mode Memory Addressing Real mode, also called real address mode, is an operating mode of and later x86-compatible.
Laface Operating System Design Booting a PC to run a kernel from Low memory VGA display.
Chapter 2 Instruction Addressing and Execution. Lesson plan Review some concepts in the first week First assembly program with EMU8086 Related concepts.
Virtual Memory Review Goal: give illusion of a large memory Allow many processes to share single memory Strategy Break physical memory up into blocks (pages)
SAPC Hardware Pentium CPU (or 486) 4M usable memory no hard disk; boot from floppy no keyboard or monitor or mouse COM2 serial port: used for console i/o.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
Microprocessor system architectures – IA32 tasks Jakub Yaghob.
3. 32-Bits Protected Mode ENGI 3655 Lab Sessions.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
10. Epilogue ENGI 3655 Lab Sessions.  We took control of the computer as early as possible, right after the end of the BIOS  Our multi-stage bootloader.
OS Memory Addressing. Architecture CPU – Processing units – Caches – Interrupt controllers – MMU Memory Interconnect North bridge South bridge PCI, etc.
File System Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki CS 314.
Lecture 2. General-Purpose Computer Systems Prof. Taeweon Suh Computer Science Education Korea University ECM586 Special Topics in Embedded Systems.
Chapter 2 Instruction Addressing and Execution. Lesson plan Review some concepts in the first week First assembly program with EMU8086 Related concepts.
Homework Reading Machine Projects Labs
Homework / Exam Return and Review Exam #1 Reading Machine Projects
An Interrupt is either a Hardware generated CALL (externally derived from a hardware signal) OR A Software-generated CALL (internally derived from.
143A: Principles of Operating Systems Lecture 7: System boot
Anton Burtsev February, 2017
Modeling Page Replacement Algorithms
Anton Burtsev February, 2017
Homework Reading Labs S&S Extracts ,
Computer Organization & Assembly Language Chapter 3
143A: Principles of Operating Systems Lecture 5: Address translation
x86 segmentation, page tables, and interrupts
Page Replacement Implementation Issues
SAPC Hardware Pentium CPU (or 486) 4M usable memory
Computer-System Architecture
Module 2: Computer-System Structures
CS 301 Fall 2002 Computer Organization
Page Replacement Implementation Issues
Modeling Page Replacement Algorithms
Lecture 13 Harvard architecture Coccone OS demonstrator
Module 2: Computer-System Structures
Department of Computer Science
CS444/544 Operating Systems II Virtual Memory
Presentation transcript:

1 / 40 Implementation of Paging in uCOS-II Ke, Dian Chia

2 / 40 Outline uCOS-II Application Model uCOS-II Application Model x86 Operating Mode x86 Operating Mode x86 Interrupt x86 Interrupt Disk I/O Disk I/O Testing Result Testing Result Q & A Q & A Appendix Appendix

3 / 40 uCOS-II Application Model (1 / 2) OS_STK TaskStk[N_TASKS][STK_SIZE]; … main(){ … OSInit(); … OSTaskCreate(task, (void *)0, &TaskStk[0][STK_SIZE - 1], 0); OSStart(); } task(){ … } OS_InitTCBList(); OS_MemInit(); … OS_TCB OSTCBTbl[] in os_core.c OSTCBStkPtr OSTCBFreeList OSTCBPrio

4 / 40 uCOS-II Application Model (2 / 2) ……… tick 1 10 TaskStart ready main starts main ends TaskStart starts tick ISR and rate set other tasks ready ………..

5 / 40 x86 Operating Mode (1 / 11) real mode real mode All start up in real mode at power-on; and earlier had only real mode. All start up in real mode at power-on; and earlier had only real mode. protected mode protected mode The foundation for all subsequent enhancements to the x86 architecture. The foundation for all subsequent enhancements to the x86 architecture. virtual 8086 mode virtual 8086 mode and later, virtual real mode, V86-mode or VM86 is whereby the CPU (in protected mode) is running an “ emulated" 16bit “ segmented ” model (real mode) machine and later, virtual real mode, V86-mode or VM86 is whereby the CPU (in protected mode) is running an “ emulated" 16bit “ segmented ” model (real mode) machine.

6 / 40 x86 Operating Mode (2 / 11) unreal mode unreal mode unreal mode, big real mode, huge real mode, or flat real mode, is a variant of real mode in which one or more data segment registers have been loaded with 32-bit addresses and limits. unreal mode, big real mode, huge real mode, or flat real mode, is a variant of real mode in which one or more data segment registers have been loaded with 32-bit addresses and limits. system management mode system management mode First released with 386SL, a mode in which all normal execution (including OS) is suspended, and special separate software (firmware or hardware-assisted debugger) is executed in high-privilege mode. First released with 386SL, a mode in which all normal execution (including OS) is suspended, and special separate software (firmware or hardware-assisted debugger) is executed in high-privilege mode. long mode long mode x86-64 x86-64

7 / 40 x86 Operating Mode (3 / 11) real mode 20 bit segmented memory address space, 2 20 = 1 MB of addressable memory 20 bit segmented memory address space, 2 20 = 1 MB of addressable memory direct software access to BIOS routines and peripheral hardware direct software access to BIOS routines and peripheral hardware no memory protection, multi-tasking or code privilege levels no memory protection, multi-tasking or code privilege levels A20 line A20 line Gate-A20 of IBM Personal Computer AT Gate-A20 of IBM Personal Computer AT

8 / 40 x86 Operating Mode (4 / 11) real mode

9 / 40 x86 Operating Mode (5 / 11) protected mode virtual memory, paging, multi-tasking, … virtual memory, paging, multi-tasking, … first released with first released with bit offset, 64KB segments 16-bit offset, 64KB segments 24-bit address bus, 16MB 24-bit address bus, 16MB only resetting to enter real mode only resetting to enter real mode extended with extended with bit offset, 4GB segments 32-bit offset, 4GB segments 32-bit address bus, 4GB 32-bit address bus, 4GB security and stability security and stability

10 / 40 x86 Operating Mode (6 / 11) protected mode entering entering GDT created with a minimum of three entries: null, code and data segment descriptor GDT created with a minimum of three entries: null, code and data segment descriptor load GDT load GDT disable interrupt disable interrupt 21st address line (A20) enabled 21st address line (A20) enabled ; set PE bit mov eax, cr0 or eax, 1 mov cr0, eax ; set PE bit mov eax, cr0 or eax, 1 mov cr0, eax ; far jump (cs = selector of code segment) ; Now we are in PM. ; far jump (cs = selector of code segment) ; Now we are in PM. exiting exiting loading segment registers with real mode values, disabling A20 line, clearing PE bit in the CR0 register loading segment registers with real mode values, disabling A20 line, clearing PE bit in the CR0 register

11 / 40 x86 Operating Mode (7 / 11) protected mode privilege levels privilege levels

12 / 40 x86 Operating Mode (8 / 11) protected mode segment addressing segment addressing

13 / 40 x86 Operating Mode (9 / 11) protected mode segment descriptor entry segment descriptor entry G = 0 G = 1 limit granularity 1 byte 4KB

14 / 40 x86 Operating Mode (10 / 11) unreal mode 64 K CS Too big object Where to put ?

15 / 40 x86 Operating Mode (11 / 11) unreal mode cli; interrupts off push ds; save segment lgdt [gdtinfo]; load gdt mov eax, cr0; switch to pmode by or al, 1; set pmode bit mov cr0, eax mov bx, 0x08; some descriptor mov ds, bx; cache set and al, 0xFE; back to real mode mov cr0, eax; by toggling bit again pop ds; get back old segment sti; interrupts on mov bx, 0x0f01; attrib/char of smiley mov eax, 0x0b8000; note 32 bit offset mov word [ds: eax], bx cached 8 Bytes

16 / 40 x86 Interrupt (1 / 4) ISR stores information about interrupts that are being serviced. IRR saves information about all interrupt requests to be serviced. IMR stores the information which interrupt request to be masked. PR resolves which interrupt request has the highest priority.

17 / 40 x86 Interrupt (2 / 4) system timer keyboard serial port 2 or 4 serial port 1 or 3 LPT port 2 or sound card floppy disk controller LPT port 1 or sound card real-time clock primary ATA channel secondary ATA channel PS/2 connector mouse

18 / 40 x86 Interrupt (3 / 4)

19 / 40 x86 Interrupt (4 / 4)

20 / 40 Disk I/O (1 / 2) PortRead/WriteMisc f0r/wdata register, the bytes are written/read here 1f1rerror register (look these values up yourself) 1f2r/wsector count, how many sectors to read/write 1f3r/wsector number, the actual sector wanted 1f4r/wcylinder low, cylinders is f5r/wcylinder high, this makes up the rest of the f6r/wdrive/head bit 7 = 1 bit 6 = 0 bit 5 = 1 bit 4 = 0drive 0 select = 1drive 1 select bit 3-0head select bits

21 / 40 PortRead/WriteMisc f7rstatus register bit 7 = 1controller is executing a command bit 6 = 1drive is ready bit 5 = 1write fault bit 4 = 1seek complete bit 3 = 1sector buffer requires servicing bit 2 = 1disk data read corrected bit 1 = 1index - set to 1 each revolution bit 0 = 1previous command ended in an error 1f7wcommand register 50hformat track 20hread sectors with retry 21hread sectors without retry 22hread long with retry 23hread long without retry 30hwrite sectors with retry 31hwrite sectors without retry 32hwrite long with retry 33hwrite long without retry

22 / 40 Testing Result (1 / 3) OS tick rate100 #tasks8 OTimeDly1 attempts range0x1000 #attempts per tick5 sw/sec902

23 / 40 Testing Result (2 / 3)

24 / 40 Testing Result (3 / 3)

25 / 40 Q & A

26 / 40 Appendix Linux Booting Involved (1 / 5) hardware RESET hardware RESET BIOS POST … BIOS POST … boot device chosen, copy MBR (512 Bytes, stage 1 LILO) into memory 0x7c00 (also check /arch/i386/boot/bootsect.S) boot device chosen, copy MBR (512 Bytes, stage 1 LILO) into memory 0x7c00 (also check /arch/i386/boot/bootsect.S) visible selector 0xf000 hidden base addr. 0xffff0000 0xffff xfff0 = 0xfffffff0 (BIOS, mapped by hardware into RAM)

27 / 40 Appendix Linux Booting Involved (2 / 5) cs: ip = 0x7c0: 0x0 = 0x7c00 cs: ip = 0x7c0: 0x0 = 0x7c00 ss = es = ds = cs, sp = 0x7c00 ss = es = ds = cs, sp = 0x7c00 MBR 512 Bytes First 512 Bytes of kernel 512 Bytes stage 2 LILO decompressed kernel 0x7c00 0x x x96a00 0x969ff 0x96c00 0x x (1 M) move jump real mode stack

28 / 40 Appendix Linux Booting Involved (3 / 5) setup() (/arch/i386/boot/setup.S) setup() (/arch/i386/boot/setup.S) reinitialize all hardware reinitialize all hardware set A20 line set A20 line switch to protected mode with a temp GDT switch to protected mode with a temp GDT cs = 0x9020  cs = a 4G code segment cs = 0x9020  cs = a 4G code segment

29 / 40 Appendix Linux Booting Involved (4 / 5) startup_32() (start of compressed image, /arch/i386/boot/compressed/he ad.S) startup_32() (start of compressed image, /arch/i386/boot/compressed/he ad.S) decompress kernel to 0x decompress kernel to 0x ljmp $(__BOOT_CS), $0x ljmp $(__BOOT_CS), $0x100000

30 / 40 Appendix Linux Booting Involved (5 / 5) startup32() (uncompressed, /arch/i386/kernel/head.S) startup32() (uncompressed, /arch/i386/kernel/head.S) initialize segment reg. initialize segment reg. fill bss segment of kernel with zeros fill bss segment of kernel with zeros set page directory into cr3, enable paging set page directory into cr3, enable paging lgdt and lidt with the final GDT lgdt and lidt with the final GDT

31 / 40 Appendix A Simple Segmentation Sample (1 / 3)

32 / 40 Appendix A Simple Segmentation Sample (2 / 3) ecx = original esp + 4 original esp espebp original esp original ebp especx esp 20 j = 0 8 k = &j 12points to

33 / 40 Appendix A Simple Segmentation Sample (3 / 3)

34 / 40 Appendix Process Address Space (1 / 6)

35 / 40 Appendix Process Address Space (2 / 6) pgd_t * pgd

36 / 40 Appendix Process Address Space (3 / 6)

37 / 40 Appendix Process Address Space (4 / 6)

38 / 40 Appendix Process Address Space (5 / 6) text 0x x80bd482 0x80be000 0x80be484 0x80bec20 0x80bf000 0x80e3000 0xb xb xb xbf xbf data 0x80c1000 0xbf8180e0 stack mmap bss

39 / 40 Appendix Process Address Space (6 / 6)

40 / 40 0x80be46c = DirTableOffset 0 0x80be46c gloInitData 0x2fe4b067 pgd at 0xeff3a080 pte at 0xefe4b2f8 0x1def0067 __USER_DS, 0x7b CR3 0xeff3a000 0x2fe4b000 0x1def0000 0x1def046c content in 0x1def046c is 0x1e