What You Need to Know for Project Three Steve Muckle Wednesday, February 19 th 2003 15-412 Spring 2003.

Slides:



Advertisements
Similar presentations
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 3 Memory Management Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Advertisements

Computer Organization and Assembly Languages Yung-Yu Chuang
16.317: Microprocessor System Design I
Intel MP.
OS Memory Addressing.
Chapter 6 Limited Direct Execution
Chapter 1 Background System Software Chih-Shun Hsu
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
Context Switch Animation Another one by Anastasia.
Vacuum tubes Transistor 1948 ICs 1960s Microprocessors 1970s.
X86 segmentation, page tables, and interrupts 3/17/08 Frans Kaashoek MIT
© 2006 Pearson Education, Upper Saddle River, NJ All Rights Reserved.Brey: The Intel Microprocessors, 7e Chapter 2 The Microprocessor and its Architecture.
PC hardware and x86 3/3/08 Frans Kaashoek MIT
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
Assembly Language for Intel-Based Computers Chapter 2: IA-32 Processor Architecture Kip Irvine.
Microprocessors Introduction to ia32 Architecture Jan 31st, 2002.
ICS312 Set 3 Pentium Registers. Intel 8086 Family of Microprocessors All of the Intel chips from the 8086 to the latest pentium, have similar architectures.
Microprocessor Systems Design I Instructor: Dr. Michael Geiger Spring 2012 Lecture 2: 80386DX Internal Architecture & Data Organization.
Microprocessor Systems Design I Instructor: Dr. Michael Geiger Fall 2012 Lecture 15: Protected mode intro.
Microprocessor Systems Design I Instructor: Dr. Michael Geiger Spring 2014 Lecture 4: x86 memory.
UNIT 2 Memory Management Unit and Segment Description and Paging
80386DX.
6.828: PC hardware and x86 Frans Kaashoek
CS1550 Assignment 5 Multiprogramming Implementation notes Matt Craven.
CSC 501 Lecture 2: Processes. Process Process is a running program a program in execution an “instantiation” of a program Program is a bunch of instructions.
Multitasking Mr. Mahendra B. Salunke Asst. Prof. Dept. of Computer Engg., STES SITS, Narhe, Pune-41 STES Sinhgad Institute of Tech. & Science Dept. of.
Intel Pentium II Processor Brent Perry Pat Reagan Brian Davis Umesh Vemuri.
Fall 2012 Chapter 2: x86 Processor Architecture. Irvine, Kip R. Assembly Language for x86 Processors 6/e, Chapter Overview General Concepts IA-32.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
Lecture 11 Page 1 CS 111 Online Memory Management: Paging and Virtual Memory CS 111 On-Line MS Program Operating Systems Peter Reiher.
1 i386 Memory Management Professor Ching-Chi Hsu 1998 年 4 月.
Virtual 8086 Mode  The supports execution of one or more 8086, 8088, 80186, or programs in an protected-mode environment.  An 8086.
15-410, S’ Hardware Overview Jan. 19, 2004 Dave Eckhardt Bruce Maggs L04_Hardware “Dude, what were you thinking?”
LINUX System : Lecture 7 Process Bong-Soo Sohn Lecture notes acknowledgement : The design of UNIX Operating System.
Microprocessor system architectures – IA32 tasks Jakub Yaghob.
80386DX. Programming Model The basic programming model consists of the following aspects: – Registers – Instruction Set – Addressing Modes – Data Types.
Chapter 2 Parts of a Computer System. 2.1 PC Hardware: Memory.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
Chapter 2 The Microprocessor Architecture Microprocessors prepared by Dr. Mohamed A. Shohla.
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.
What You Need to Know for Project One Joey Echeverria Friday, August 29, Fall 2003.
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures.
OS Memory Addressing. Architecture CPU – Processing units – Caches – Interrupt controllers – MMU Memory Interconnect North bridge South bridge PCI, etc.
Information Security - 2. CISC Vs RISC X86 is CISC while ARM is RISC CISC is Compiler’s heaven while RISC is Architecture’s heaven Orthogonal ISA in RISC.
The Microprocessor & Its Architecture A Course in Microprocessor Electrical Engineering Department Universitas 17 Agustus 1945 Jakarta.
What You Need to Know for Project Three Dave Eckhardt Steve Muckle.
What You Need to Know for Project Three
Chapter Overview General Concepts IA-32 Processor Architecture
Assembly language.
Operating Systems Engineering
CSE 120 Principles of Operating
Outline Paging Swapping and demand paging Virtual memory.
Anton Burtsev February, 2017
Mechanism: Limited Direct Execution
Other Processors.
Anton Burtsev February, 2017
143A: Principles of Operating Systems Lecture 5: Address translation
Aaron Miller David Cohen Spring 2011
Basic Microprocessor Architecture
x86 segmentation, page tables, and interrupts
CS 301 Fall 2002 Computer Organization
The Microprocessor & Its Architecture
Lecture Topics: 11/1 General Operating System Concepts Processes
System Calls David Ferry CSCI 3500 – Operating Systems
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Low-Level Thread Dispatching on the x86
Computer Architecture and System Programming Laboratory
Presentation transcript:

What You Need to Know for Project Three Steve Muckle Wednesday, February 19 th Spring 2003

Carnegie Mellon University2 Overview Introduction to the Kernel Project Mundane Details in x86 registers, paging, the life of a memory access, context switching, system calls, kernel stacks Loading Executables A Quick Debug Story Style Recommendations (or pleas) Attack Strategy

Carnegie Mellon University3 Introduction to the Kernel Project P3 is the most conceptually challenging You will need to adjust how you think about program execution P1 introduced you to programming without making commonly made assumptions In P3 you need to provide assumptions to users

Carnegie Mellon University4 Introduction to the Kernel Project: Kernel Features Your kernels will feature: - preemptive multitasking - multiple virtual address spaces - a “small” selection of useful system calls - robustness (hopefully)

Carnegie Mellon University5 Introduction to the Kernel Project: Preemptive Multitasking Preemptive multitasking is forcing multiple user processes to share the CPU You will use the timer interrupt to do this Reuse your timer code from P1 if possible

Carnegie Mellon University6 Introduction to the Kernel Project: Preemptive Multitasking Simple round robin scheduling will suffice Context switching is tricky but cool

Carnegie Mellon University7 Introduction to the Kernel Project: Multiple Virtual Address Spaces The x86 architecture supports paging You will use this to provide a virtual address space for each user process Each user process will be isolated from other user processes We will also use paging to provide protection for the kernel

Carnegie Mellon University8 Introduction to the Kernel Project: System Calls You used them in P2 Now you get to implement them Examples include fork, exec, and of course, minclone There are easier ones like getpid

Carnegie Mellon University9 Mundane Details in x86 We looked at some of these for P1 Now it is time to get the rest of the story How do we control processor features? What does an x86 page table look like? What route does a memory access take? How do you switch from one process to another?

Carnegie Mellon University10 Mundane Details in x86: Registers General purpose regs (not interesting) - %eax, %ebx, %ecx, etc… Segment Selectors (somewhat interesting) - %cs, %ss, %ds, %es, %fs, %gs %eip (interesting) EFLAGS (interesting) Control Registers (very interesting) - %cr0, %cr1, %cr2, %cr3, %cr4

Carnegie Mellon University11 Mundane Details in x86: General Purpose Registers The most boring kind of register %eax, %ebx, %ecx, %edx, %edi, %esi, %ebp, %esp %eax, %ebp, and %esp are exceptions, they are slightly interesting - %eax is used for return values - %esp is the stack pointer - %ebp is the base pointer

Carnegie Mellon University12 Mundane Details in x86: Segment Selector Registers Slightly more interesting %cs specifies the segment used to access code (also specifies privilege level) %ss specifies the segment used for stack related operations (pushl, popl, etc) %ds, %es, %fs, %gs specify segments used to access regular data Mind these during context switches…

Carnegie Mellon University13 Mundane Details in x86: The Instruction Pointer (%eip) It’s interesting Cannot be read from or written to Controls what instructions get executed ‘nuf said.

Carnegie Mellon University14 Mundane Details in x86: The EFLAGS Register It’s interesting Contains a bunch of flags, including interrupt- enable, arithmetic flags

Carnegie Mellon University15 Mundane Details in x86: Control Registers Very interesting! An assortment of important flags and values %cr0 contains powerful system flags that control things like paging, protected mode %cr1 is reserved (now that’s really interesting) %cr2 contains the address that caused the last page fault

Carnegie Mellon University16 Mundane Details in x86: Control Registers, cont’ %cr3 contains the address of the current page directory, as well as a couple paging related flags %cr4 contains… more flags (not as interesting though) - protected mode virtual interrupts? - virtual-8086 mode extensions? - No thanks

Carnegie Mellon University17 Mundane Details in x86: Registers How do you write to a special register? Most of them can simply be written to using the movl instruction Some (like CRs) you need PL0 to access We will provide inline assembly wrappers EFLAGS is a little different, but you will not be writing to it anyway

Carnegie Mellon University18 Mundane Details in x86: Paging The x86 offers several page sizes We will use 4k pages The x86 uses a two level paging scheme The top of the paging structure is called a page directory The second level structures are called page tables

Carnegie Mellon University19 Mundane Details in x86: Page Directories and Tables CR3 Page Directory Page Table Page Table Page Table Current Process’ Page Directory Address

Carnegie Mellon University20 Mundane Details in x86: Page Directory The page directory is 4k in size Contains pointers to page tables Not all entries have to be valid Figure from page 87 of intel-sys.pdf

Carnegie Mellon University21 Mundane Details in x86: Page Table The page table is also 4k in size Contains pointers to pages Not all entries have to be valid Figure from page 87 of intel-sys.pdf

Carnegie Mellon University22 Mundane Details in x86: The Life of a Memory Access Logical Address Linear Address Physical Address Segmentation Paging (consists of 16 bit segment selector, 32 bit offset) (32 bit offset)

Carnegie Mellon University23 Mundane Details in x86: The Life of a Memory Access Logical Address Linear Address Segmentation (consists of 16 bit segment selector, 32 bit offset) (32 bit offset) The 16 bit segment selector comes from a segment register The 32 bit offset is added to the base address of the segment That gives us a 32 bit offset into the virtual address space

Carnegie Mellon University24 Mundane Details in x86: Segmentation Segments need not be backed by physical memory and can overlap Segments defined for these projects: Kernel CodeKernel DataUser CodeUser Data 0xFFFFFFFF 0x

Carnegie Mellon University25 Mundane Details in x86: The Life of a Memory Access Linear Address Physical Address Paging (32 bit offset) Top 10 bits index into page directory, point us to a page table The next 10 bits index into page table, point us to a page The last 12 bits are an offset into that page

Carnegie Mellon University26 Mundane Details in x86: The Life of a Memory Access Whoa there slick… what if the page directory entry isn’t there? What happens if the page table entry isn’t there? It’s called a page fault, it’s an exception, and it lives in IDT entry 13 You will have to write a handler for this exception and do something intelligent

Carnegie Mellon University27 Mundane Details in x86: The Life of a Memory Access Logical Address Linear Address Physical Address Segmentation Paging (consists of 16 bit segment selector, 32 bit offset) (32 bit offset)

Carnegie Mellon University28 Mundane Details in x86: Context Switching We all know that processes take turns running on the CPU This means they have to be stopped and started over and over How does this occur?

Carnegie Mellon University29 Mundane Details in x86: Context Switching The x86 architecture provides a hardware mechanism for “tasks” This makes context switching easy It is actually faster to manage processes in software We can also tailor our process abstraction to our particular needs You must have at least one hardware task defined, OSKit takes care of this for you

Carnegie Mellon University30 Mundane Details in x86: Context Switching Context switching is a very delicate procedure Great care must be taken so that when the process is started, it does not know it ever stopped Registers must be exactly the same (%cr3 is the only control register you have to update) It’s stack must be exactly the same It’s page directory must be in place

Carnegie Mellon University31 Mundane Details in x86: Context Switching Hints on context switching: - use the stack, it is a convenient place to store things - if you do all your switching in one location, you have eliminated one thing you have to save (%eip) - new processes will require some special care

Carnegie Mellon University32 Mundane Details in x86: System Calls System calls use software interrupts Install a handler just as you did for the timer, keyboard Use one software interrupt to implement all of your system calls If you are rusty on the IDT refer back to P1

Carnegie Mellon University33 Mundane Details in x86: Kernel Stacks User processes should have a separate stack for their kernel activities It should be located in kernel space How does the stack pointer get switched to the kernel stack? User-Level Stack Kernel StackPCB

Carnegie Mellon University34 Mundane Details in x86: Kernel Stacks When the CPU switches from user mode to kernel mode the stack pointer is changed The new stack pointer is stored in the configuration of the CPU hardware task We provide a function to change this value set_esp0(void* ptr)

Carnegie Mellon University35 Loading Executables You are probably expecting a file system But… you have not written one yet We have cooked up a small utility to help you

Carnegie Mellon University36 Loading Executables: exec2obj Takes a file as input Spits out a.c file containing a char array initialized to the contents of the input file You can compile this into your kernel

Carnegie Mellon University37 Loading Executables: The Loader You have access to the bytes You need to load them into the process’ address space Guess what… you get to write a loader! Don’t worry, it’s not hard The executables will be in NMAGIC a.out format References to resources are in the handout

Carnegie Mellon University38 A Quick Debug Story Ha! You’ll have to have been to lecture to hear this story.

Carnegie Mellon University39 A Quick Debug Story The moral is, please start early.

Carnegie Mellon University40 Style Recommendations Do not use a global when a local would do. Comment where comments are needed - not “comment everywhere” - not “do not comment” Do NOT hand in your project in one file called kernel.c - Do not hand in your project in one file called anything, actually - Dave might bite your kneecaps

Carnegie Mellon University41 Attack Strategy There is an attack strategy in the handout It represents where we think you should be in each of the four weeks You WILL have to turn in checkpoint two

Carnegie Mellon University42 Attack Strategy Please read the handout a couple times over the next few days Then start writing pseudocode!

Carnegie Mellon University43 Good Luck on Project 2!