A very simple kernel Anders P. Ravn April 2005. A kernel specification /* kernel.h Interface to a lightweight kernel that implements concurrent processes.

Slides:



Advertisements
Similar presentations
1.1 T5-multithreading SO-Grade Q Processes vs. Threads Thread libraries Communication based on shared memory Race condition Critical section.
Advertisements

Process Management.
Machine-Level Programming III: Procedures Feb. 8, 2000 Topics IA32 stack Stack-based languages Stack frames Register saving conventions Creating pointers.
Calling sequence ESP.
CS 4284 Systems Capstone Godmar Back Processes and Threads.
University of Washington Procedures and Stacks II The Hardware/Software Interface CSE351 Winter 2013.
Concurrency. Motivation Operating systems (and application programs) often need to be able to handle multiple things happening at the same time – Process.
Dynamic Memory Management CAS CS210 Ying Ye Boston University.
The ‘system-call’ interface We see how an application program can invoke privileged kernel services.
Software Engineering Lecture 5 Multiprogramming and Scheduling ASPI8-4 Anders P. Ravn March 2004.
Context Switch Animation Another one by Anastasia.
Machine-Level Programming III: Procedures Apr. 17, 2006 Topics IA32 stack discipline Register saving conventions Creating pointers to local variables CS213.
Project 2 Roadmap. Background – Context Switching One processor and multiple threads running concurrently – How?!! Give each thread a small time quantum.
PC hardware and x86 3/3/08 Frans Kaashoek MIT
1 Function Calls Professor Jennifer Rexford COS 217 Reading: Chapter 4 of “Programming From the Ground Up” (available online from the course Web site)
– 1 – , F’02 ICS05 Instructor: Peter A. Dinda TA: Bin Lin Recitation 4.
Low-level Programming TSW November 2009 Anders P. Ravn Aalborg University.
A very simple kernel ITV Multiprogramming and Real-Time Programs Anders P. Ravn May 2009.
Stack Activation Records Topics IA32 stack discipline Register saving conventions Creating pointers to local variables February 6, 2003 CSCE 212H Computer.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 7 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Fall 2008CS 334: Computer SecuritySlide #1 Smashing The Stack A detailed look at buffer overflows as described in Smashing the Stack for Fun and Profit.
1 Carnegie Mellon Stacks : Introduction to Computer Systems Recitation 5: September 24, 2012 Joon-Sup Han Section F.
Multiprogramming CSE451 Andrew Whitaker. Overview Multiprogramming: Running multiple programs “at the same time”  Requires multiplexing (sharing) the.
1 Linux Operating System 許 富 皓. 2 Processes Switch.
Goals: To gain an understanding of assembly To get your hands dirty in GDB.
Fabián E. Bustamante, Spring 2007 Machine-Level Programming III - Procedures Today IA32 stack discipline Register saving conventions Creating pointers.
Lecture 8: Buffer Overflow CS 436/636/736 Spring 2013 Nitesh Saxena *Adopted from a previous lecture by Aleph One (Smashing the Stack for Fun and Profit)
Carnegie Mellon 1 Odds and Ends Intro to x86-64 Memory Layout.
Chapter 4 Process Abstraction Chien-Chung Shen CIS, UD
Low Level Programming Lecturer: Duncan Smeed The Interface Between High-Level and Low-Level Languages.
Machine-level Programming III: Procedures Topics –IA32 stack discipline –Register saving conventions –Creating pointers to local variables.
Functions/Methods in Assembly
Introduction to Assembly II Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2014/2015.
1 Assembly Language: Function Calls Jennifer Rexford.
Carnegie Mellon About the New Slides for Introduction to Computer Systems /18-243, spring 2009 Markus Püschel Electrical and Computer Engineering.
Discussions on hw3 Objective –To implement multitasking of 3 Tiny-UNIX processes on the SAPC –Each process tries to output data to the COM2 output port.
IA32 Stack –Region of memory managed with stack discipline –Grows toward lower addresses –Register %esp indicates lowest stack address address of top element.
Virtualizing the CPU: Processes 1. How to provide the illusion of many CPUs? CPU virtualizing – The OS can promote the illusion that many virtual CPUs.
Assembly function call convention
Instruction Set Architecture
Homework / Exam Return and Review Exam #1 Reading Machine Projects
Assembly Language Programming IV: shift, struct, recursion
Credits and Disclaimers
C function call conventions and the stack
Processes.
CS 5204 Operating Systems Processes and Threads Godmar Back.
CS-401 Computer Architecture & Assembly Language Programming
Conditional Branch Example
Anton Burtsev February, 2017
ICS143A: Principles of Operating Systems Lecture 13: Context switching
Homework Reading Machine Projects Labs PAL, pp ,
Threading and Project 2 (Some slides taken from Sec. 3 Winter 2006)
Exploiting & Defense Day 2 Recap
Aaron Miller David Cohen Spring 2011
Homework In-line Assembly Code Machine Language
High-Level Language Interface
Machine-Level Programming 4 Procedures
Assembly Language Programming II: C Compiler Calling Sequences
Discussions on HW2 Objectives
The Runtime Environment
Multi-modules programming
System Calls David Ferry CSCI 3500 – Operating Systems
Discussions on HW2 Objectives
C structures and Compilation to IA32
Low-Level Thread Dispatching on the x86
“Way easier than when we were students”
Credits and Disclaimers
ICS51 Introductory Computer Organization
Presentation transcript:

A very simple kernel Anders P. Ravn April 2005

A kernel specification /* kernel.h Interface to a lightweight kernel that implements concurrent processes and a release primitive `pause'. Anders P. Ravn, DTU, Denmark 24 April 1998 */ typedef void (*Program)(void); /* A program text is a function without parameters*/ typedef void * Thread; /* identifier for a process */ extern Thread create(Program p,unsigned int stacksize); /* creates a process with a stack of the specified size and starts it executing the program. If there is insufficient memory, the result is NULL */ extern void pause(void); /* release the processor */

Multiprogramming #include ”kernel.h” void process() { /* do something */ pause(); /* do something */ } void main() { Thread p1, p2; p1 = create(&process,2000); /* p1 is started */ p2 = create(&process,1000); /* p2 is started */ /* the kernel will see to it that main is left when both p1 and p2 has exited */ }

A kernel implementation I typedef unsigned long Register; typedef struct x {struct x* next; Register esp;} Threaddescriptor; static Threaddesriptor* ready; /* queue of threads linked cyclically; ready points to last, the first is current */ #define current ready->next esp1esp2esp3 ready: current

A kernel implementation II void pause() { Register sp; __asm__(” pushal movl %esp,%sp"); /* sp -> |saved registers... | eip return from call */ DISABLE; /* scheduling */ current->esp = sp; ready = current; sp = current->esp; __asm__(" movl %sp,%esp popal" ); ENABLE; } esp1esp2esp3 ready: current stack1 stack2

A kernel implementation III pause:pushl %ebp movl %esp,%ebp pushal movl %esp,%ecx sp = esp movl ready,%eax movl (%eax),%edx current->esp movl %ecx,4(%edx) = sp movl %edx,ready ready = current movl (%edx),%edx movl 4(%edx),%ecx sp = current->esp movl %ecx,%esp popal leave ret

A kernel implementation IV pause: pushal movl ready,%eax movl (%eax),%edx current->esp movl %esp,4(%edx) = esp movl %edx,ready ready = current movl (%edx),%edx movl 4(%edx),%esp esp = current->esp popal ret