SE350: Operating Systems
Lecture 2: OS Concepts
SE350: Operating Systems Lecture 2: OS Concepts Outline Brief - - PowerPoint PPT Presentation
SE350: Operating Systems Lecture 2: OS Concepts Outline Brief history of OSs Four fundamental OS concepts Thread Address space Process Dual-mode operation/protection Very Brief History of OS Several distinct phases:
Lecture 2: OS Concepts
Thomas Watson was often called “the worlds greatest salesman” by the time
“I think there is a world market for maybe five computers.” – Thomas Watson, chairman of IBM, 1943
XP ÞVista Þ 7 Þ 8 Þ 10 Þ …
Threa ead
Address ess sp space ce (with transl slation
Process ess
Dual-mo mode operati ation/prote tecti tion
program virtual addresses to machine physical addresses
executable file into memory
Heap Stack O S L
d s Memory 0x000… 0xFFF… Instructions Data OS
Executable Image
Data Instructions
Compiler
Source Code
Edits Processor Registers
PC
OS Starts Execution
learnworthy.net
PC
Memory Instructions Data Decode Instruction fetch ALU Registers
Execute
Next
PC
Memory Instructions Data Decode ALU Registers Next
Next instruction or jump to new address …
state associated with them
Heap Stack 0x000… Instructions Data 0xFFF…
#include <stdio.h> #include <stdlib.h> int x; int y = 15; int main(int argc, char *argv[]) { int *values; int I; values = (int *)malloc(sizeof(int)*5); for (i = 0; i < 5; i++) values[i] = i; return 0; } Binary Code Initialized Data Uninitialized Data Heap Command line args and environment vars Stack
Code Data Heap Stack Code Data Heap Stack Code Data Heap Stack
OS Proc 1 Proc n Proc 2
…
Code Data Heap Stack
, and rest of registers (integer, floating point, …)
, and registers in current state block
, and registers from new state block
vCPU3 vCPU2 vCPU1 Shared Memory vCPU1 vCPU2 vCPU3 vCPU1 vCPU2 Time
shared resources
(good for sharing, bad for protection)
(good for sharing, bad for protection)
physical memory space
Full HW access Limited HW access exec syscall exit rtn interrupt rfi exception
Code Data Heap Stack
0x000… 0x010… 0x000… 0xFFF…
+
Base Bound
Code Data Heap Stack
0x100… 0x110…
Virtual Address
0x001… 0x101…
Physical Address
0x100… 0x110…
>
Raise Exception
Memory Processor
physical memory space of machine
0x000… 0xFFF… Translator Virtual Address Physical Address
int staticVar = 0; // a static variable int main() { staticVar += 1; usleep(5000000); // sleep for 5 seconds printf("static address: %x, value: %d\n", &staticVar, staticVar); }
same time?
two copies of the same program running at the same time?
Code Data Heap Stack Code Data Heap Stack Code Data Heap Stack
OS Proc 1 Proc 2 0x0000… 0xFFFF…
Base Bound uPC Regs 1 sysmode … PC
0x1000… 0x1100… 0x3000… 0x3080…
SP
Code Data Heap Stack Code Data Heap Stack Code Data Heap Stack
OS Proc 1 Proc 2 0x0000… 0xFFFF…
Base 0x1000… 0x1100… Bound 0x0001 uPC 0x00FF Regs 1 sysmode … PC
0x1000… 0x1100… 0x3000… 0x3080…
SP
special registers
Code Data Heap Stack Code Data Heap Stack Code Data Heap Stack
OS Proc 1 Proc 2 0x0000… 0xFFFF…
Base 0x1000… 0x1100… Bound uPC 0x00FF Regs sysmode … 0x0001 PC
0x1000… 0x1100… 0x3000… 0x3080…
SP
switch between processes?
to return to OS?
violation (segmentation fault), divide by zero, …
Interrupt Vector Table Processor Register
h a n d l e Ti m e r I n t e r r u p t ( ) { . . . } h a n d l e D i v i d e B y Z e r o ( ) { . . . } h a n d l e S y s t e m C a l l ( ) { . . . }
Code Data Heap Stack Code Data Heap Stack Code Data Heap Stack
OS Proc 1 Proc 2 0x0000… 0xFFFF…
Base 0x1000… 0x1100… Bound uPC 0x00FF… … … Regs sysmode … 0x00001234 PC
0x1000… 0x1100… 0x3000… 0x3080…
SP
Code Data Heap Stack Code Data Heap Stack Code Data Heap Stack
OS Proc 1 Proc 2 0x0000… 0xFFFF…
Base 0x1000… 0x1100… Bound 0x00001234 uPC 0x00FF… … … Regs 1 sysmode … IntrpVector[i] PC
0x1000… 0x1100… 0x3000… 0x3080…
SP
registers and set up system stack?
0x1000… 0x1100… 0x00001234 0x00FF… … … …
OS stores copy
its memory
Threa ead
Address ess sp space ce (with transl slation
Process ess
Dual-mo mode operati ation/prote tecti tion
program virtual addresses to machine physical addresses
globaldigitalcitizen.org