DEV300: A Tiny CPU and OS in C# Scott Hanselman Technology Evangelist/Architect Corillian Corporation

Slides:



Advertisements
Similar presentations
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Advertisements

Part IV: Memory Management
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Memory Protection: Kernel and User Address Spaces  Background  Address binding  How memory protection is achieved.
Chapter 3 Process Description and Control
CSI 3120, Implementing subprograms, page 1 Implementing subprograms The environment in block-structured languages The structure of the activation stack.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 3 Memory Management Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Process Description and Control Module 1.0. Major Requirements of an Operating System Interleave the execution of several processes to maximize processor.
Processes CSCI 444/544 Operating Systems Fall 2008.
OS Fall ’ 02 Introduction Operating Systems Fall 2002.
CS 104 Introduction to Computer Science and Graphics Problems
1 Process Description and Control Chapter 3. 2 Process Management—Fundamental task of an OS The OS is responsible for: Allocation of resources to processes.
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
Embedded Real-time Systems The Linux kernel. The Operating System Kernel Resident in memory, privileged mode System calls offer general purpose services.
Process Management. External View of the OS Hardware fork() CreateProcess() CreateThread() close() CloseHandle() sleep() semctl() signal() SetWaitableTimer()
OS Spring’03 Introduction Operating Systems Spring 2003.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
Processes and Resources
Chapter 6 Implementing Processes, Threads, and Resources.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Protected Mode. Protected Mode (1 of 2) 4 GB addressable RAM –( to FFFFFFFFh) Each program assigned a memory partition which is protected from.
Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)
Process Description and Control A process is sometimes called a task, it is a program in execution.
OS Spring’04 Introduction Operating Systems Spring 2004.
Using Two Queues. Using Multiple Queues Suspended Processes Processor is faster than I/O so all processes could be waiting for I/O Processor is faster.
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
Processes CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
CSE378 Virtual memory.1 Evolution in memory management techniques In early days, single program ran on the whole machine –used all the memory available.
Computer Science 210 Computer Organization The Instruction Execution Cycle.
Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6.
Process Description and Control Chapter 3. Major Requirements of an OS Interleave the execution of several processes to maximize processor utilization.
OPERATING SYSTEM OVERVIEW. Contents Basic hardware elements.
Implementing Processes and Process Management Brian Bershad.
Chapter 3 Process Description and Control
Memory Management 3 Tanenbaum Ch. 3 Silberschatz Ch. 8,9.
OPERATING SYSTEMS Goals of the course Definitions of operating systems Operating system goals What is not an operating system Computer architecture O/S.
Chapter 4 Processes. Process: what is it? A program in execution A program in execution usually usually Can also have suspended or waiting processes Can.
CIS250 OPERATING SYSTEMS Memory Management Since we share memory, we need to manage it Memory manager only sees the address A program counter value indicates.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
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.
Multiprogramming. Readings r Silberschatz, Galvin, Gagne, “Operating System Concepts”, 8 th edition: Chapter 3.1, 3.2.
4P13 Week 3 Talking Points 1. Process State 2 Process Structure Catagories – Process identification: the PID and the parent PID – Signal state: signals.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
Module R3 Process Scheduling. Module R3 involves the creation of a simple “Round Robin” dispatcher. The successful completion of this module will require.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
Operating Systems CSE 411 CPU Management Sept Lecture 10 Instructor: Bhuvan Urgaonkar.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Process Description and Control Chapter 3. Source Modified slides from Missouri U. of Science and Tech.
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.
2 Processor(s)Main MemoryDevices Process, Thread & Resource Manager Memory Manager Device Manager File Manager.
Introduction Contain two or more CPU share common memory and peripherals. Provide greater system throughput. Multiple processor executing simultaneous.
Multiprogramming. Readings r Chapter 2.1 of the textbook.
Introduction to Operating Systems
Process Management Process Concept Why only the global variables?
Advanced OS Concepts (For OCR)
Operating Systems: A Modern Perspective, Chapter 6
Process Realization In OS
Lecture 1 Runtime environments.
Computer Organization & Compilation Process
Process Description and Control
Lecture Topics: 11/1 General Operating System Concepts Processes
Architectural Support for OS
Implementing Processes, Threads, and Resources
CS510 Operating System Foundations
Lecture 1 Runtime environments.
Architectural Support for OS
Evolution in memory management techniques
CSE 153 Design of Operating Systems Winter 2019
Computer Organization & Compilation Process
Presentation transcript:

DEV300: A Tiny CPU and OS in C# Scott Hanselman Technology Evangelist/Architect Corillian Corporation

-Lah

Tiny CPU and OS Design Goals Creation of an Abstract Machine Creation of an Abstract Machine Simulate Running and Scheduling of Processes Simulate Running and Scheduling of Processes Provide Paging, Virtual Memory, Memory Protection Provide Paging, Virtual Memory, Memory Protection Each Process scheduled independently Each Process scheduled independently Inter-process Communication Inter-process Communication

Tiny CPU and OS Disclaimer Goals Goals  Meant to teach C# and exercise libraries  Meant to teach basic OS/CPU concepts  Meant to simulate OS behaviors NOT GOALS NOT GOALS  Not meant to get any work done  Not meant as a “perfect” simulation

CPU and OS The CPU is a 32-bit machine The CPU is a 32-bit machine  all addresses and registers are 32-bits CPU CPU  10 registers 32-bits wide  IP – Instruction Pointer  SP – Stack Pointer OS OS  32 basic OpCodes  Each OpCode takes 1 clock cycle

Basic Design Object mapping to actual OS/CPU pieces Program Instruction Collection Instruction Instruction Instruction Instruction Process createProcess() 6 r4, $0 ;move 0 into r4 new Instruction(raw) new Instruction(raw) Program File on Disk Process in the OS

Basic Design Object mapping to actual OS/CPU pieces CPU Operating System (at run-time) Scheduler Loop Running Processes Collection ProcessProcessProcessProcess Each Process scheduled independently Each Process scheduled independently  Poorly behaved processes are terminated  Memory is protected unless shared

CPU and OS Executed like this from command-line: Executed like this from command-line:  C:> OS 2048 prog1.txt prog2.txt Many Configuration options Many Configuration options<configuration><appSettings> </appSettings></configuration>

Instruction Set Example Opcode#Format Sleep25Sleep r1; Sleep the # of clock cycles as indicated in r1. Another process or the idle process must be scheduled at this point. If the time to sleep is 0, the process sleeps infinitely. SetPriority26SetPriority r1; Set the priority of the current process to the value in register r1; See priorities discussion in Operating system design Exit27Exit. This opcode is executed by a process to exit and be unloaded. Another process or the idle process must now be scheduled. FreeMemory28FreeMemory r1; Free the memory allocated whose address is in r1. MapSharedMem29MapSharedMem r1, r2; Map the shared memory region identified by r1 and return the start address in r2. SignalEvent30SignalEvent r1; Signal the event indicated by the value in register r1. WaitEvent31WaitEvent r1; Wait for the event in register r1 to be triggered. This results in context-switches happening. Input32Input r1; read the next 32-bit value into register r1. MemoryClear33MemoryClear r1, r2; set the bytes starting at address r1 of length r2 bytes to zero.

Example Idle Loop 6r4, $0;move 0 into r4 26r4;lower priority TO 0 6r1, $20 ;move 20 into r1 11r1;print the number 20 6r2, $-19;back up the ip 19 13r2;loop (jump back 19) Like a “Tiny Assembly Language” Like a “Tiny Assembly Language” Instructions are fetched from memory by the CPU and routed to the OS object Instructions are fetched from memory by the CPU and routed to the OS object  No compilation necessary – possible future enhancement?

Demo: Basic Programs Manipulating Registers Manipulating Registers Moving Memory, using the Stack Moving Memory, using the Stack Small Functions Small Functions Inter-process Communication Inter-process Communication

Tiny OS Memory “Physical Memory” just array of bytes “Physical Memory” just array of bytes  internal static byte[] physicalMemory; Virtual Memory may be much larger! Virtual Memory may be much larger!  But each Process has it’s own “view” Virtual Memory hidden in code via [] Operator Overloading Virtual Memory hidden in code via [] Operator Overloading // Copy the code in one byte at a time Process p = new Process(++idPool, memSize); uint index = 0; foreach (byte b in processCode) memoryMgr[p.PCB.pid, index++] = b;

Tiny OS Memory PhysicalVirtualProcess … Of course, the OS can address more memory than it has physically. So, you might have 256 bytes of memory, but can address 1024!

All memory operations such as paging and swapping are hidden from the Process. Tiny OS Memory PhysicalVirtualProcess …

<xml/> pages on disk Tiny OS Memory with small physical memory and paging PhysicalVirtualProcess … For the Process, everything stays the same, except now parts of virtual memory map to disk!

Tiny OS Memory memory becomes fragmented

Major Elements (1 of 2) Typed Collections Typed Collections  Generated by Tool unsafe code unsafe code  Like “inline C” Delegates Delegates  Object-Oriented Function Pointers Object Serialization Object Serialization  Memory Pages serialized to disk

Major Elements (2 of 2) Custom Exceptions Custom Exceptions  Specific Derived Classes for each purpose Regular Expressions Regular Expressions  Simplifies Program Parsing IComparable IComparable  Custom Sorting in Collections

Demo: Changing the OS Changing Configuration Options Changing Configuration Options Modifying Virtual Memory Swapping! Modifying Virtual Memory Swapping! Adjusting Memory Page Size Adjusting Memory Page Size Analyzing Statistics and Profiling Analyzing Statistics and Profiling

Summary Tiny CPU and OS Learn C# and.NET Learn C# and.NET  Find a problem and solve it!  Make use of the.NET Framework Classes!  Imagine how you’d do it in other languages! What.NET can do will surprise you! What.NET can do will surprise you!

Additional Resources Get the Deep Technical Drill Down Get the Deep Technical Drill Down  DEV366:.NET Framework Under the Hood Learn how to Architect an application Learn how to Architect an application  DEV310: Architecting Enterprise Applications with Visual Studio.NET  DEV358: Architecting N-Tier.NET Applications  DEV402: Design Choices for Implementing Distributed Applications in.NET

© 2002 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.