Transcript Slide 1

http://proglit.com/
hardware
and
operating systems
basics
SA
BY
•
•
•
•
•
•
client/workstation (PC)
server (responds to requests from network)
hand-held (phone, audio player)
embedded system (toaster, car)
mainframe (a big server)
supercomputer (a many-processor system)
RAM (Random Access Memory)
• addressable by the CPU
• volatile
• faster than storage
• code and data of
running programs
http://proglit.com/
programming model
(simplified conception of a processor
for sake of programmers)
instruction
(a sequence of bits understood by the
processor to signal a certain action)
•
•
•
•
copy bytes
arithmetic
bit logic
jumps
register
(a small memory area in a processor)
•
•
status
general purpose
ISA (Instruction Set Architecture)
x86 (IA-32, x86-64)
ARM
MIPS
Motorola 68k
http://proglit.com/
code
program memory
call stack
(local variables)
heap
(everything else)
 top of stack
frame of lama
 top of stack
frame of bird
stack space
 top of stack
frame of fish
 top of stack
frame of dog
frame of cat
frame of main
 top of stack
 top of stack
• local variables
• argument values
 top of stack
frame of moose
 top of stack
frame of bird
stack space
frame of fish
frame of dog
frame of cat
frame of main
• local variables
• argument values
• return address
big-endian vs. little-endian
(the order in which the bytes of a register are copied
from registers to memory and vice versa)
big-endian vs. little-endian
(the order in which the bytes of a register are copied
from registers to memory and vice versa)
http://proglit.com/
capacity
processor registers
processor cache
random access memory
hard drives
speed, cost
http://proglit.com/
device
registers
CPU
port-mapped I/O vs.
memory-mapped I/O
output register 2 to port 0x44 98
copy register 5 to address 0x66 2C 1A 32
0xFF FF FF FF
byte n
memory
addresses
RAM
byte 0
0x00 00 00 00
port n
ports
port 0
devices
0xFF FF FF FF
byte n
RAM
memory
addresses
byte 0
0x00 01 00 00
0x00 00 FF FF
devices
0x00 00 00 00
polling
(code periodically checks device registers to see if the
device needs the CPU to do something)
interrupt line
device
registers
CPU
polling
(code periodically checks device registers to see if they
need the CPU to do something)
interrupt
1. device sends interrupt signal to CPU
2. CPU saves state of whatever it was currently doing
3. CPU jumps to address corresponding to interrupt
number in the interrupt table
…
…
interrupt 7
0xFF 31 01 11
interrupt 6
0xFF 90 44 44
interrupt 5
0xFF 31 01 11
interrupt 4
0xFF 31 21 14
interrupt 3
0xA2 22 00 10
interrupt 2
0x82 87 95 94
interrupt 1
0x20 15 10 00
interrupt 0
0x76 00 00 00
polling
(code periodically checks device registers to see if they
need the CPU to do something)
interrupt
1.
2.
3.
4.
device sends interrupt signal to CPU
CPU saves state of whatever it was currently doing
CPU jumps to address corresponding to interrupt number in
the interrupt table
CPU returns to whatever it was doing before the interrupt
hardware exception
(a condition which causes the CPU to jump to a pre-determined address)
…
…
exception 4
0xFF 31 21 14
exception 3
0xA2 22 00 10
exception 2
0x82 87 95 94
exception 1
0x20 15 10 00
exception 0
0x76 00 00 00
http://proglit.com/
•
•
•
•
•
•
•
•
Instruction Set Architecture
byte size
word size
address size
cache speeds and sizes
big-endian vs. little-endian
ports vs. memory-mapped i/o
number of processors/cores
boot firmware
BIOS
registers
CPU
http://proglit.com/
boot firmware
BIOS
registers
CPU
operating system
(manages the hardware and running programs)
•
•
•
•
load and manage processes
provide “interfaces” to hardware via system calls
provide a filesystem
provide a basic user interface
Windows
(series of OS’s from Microsoft)
•
•
•
Windows 7
Windows Server 2008
Windows CE
Unix
(a family of OS’s)
•
•
•
Linux
BSD
OS X
http://proglit.com/
device driver
(plug-in to the OS to control a particular device)
OS
software
hardware
driver
driver
driver
device
device
device
process
OS
CPU
B
A
B
A
B
A
B
C
C
time
CPU 2
A
C
C
C
C
B
A
B
pre-emptive multitasking
1.
2.
3.
4.
5.
6.
7.
CPU receives interrupt
interrupt stores state of currently running code
interrupt invokes handler
interrupt handler invokes the scheduler
scheduler selects a process
scheduler “configures” CPU for that process
scheduler jumps execution to that process
http://proglit.com/
0xFF FF FF FF
Process A
Process B
Process C
OS
0x00 00 00 00
0x FF FF FF FF
stack
byte n
heap
RAM
heap
heap
0x 00 00 00 00
code
byte 0
0x FF FF FF FF
stack
byte n
heap
RAM
heap
byte 0
heap
HD
0x 00 00 00 00
code
http://proglit.com/
Process A
Process B
jump to system call code via
special instruction
Process C
OS
RAM
…
…
system call 7
0xFF 31 01 11
system call 6
0xFF 90 44 44
system call 5
0xFF 31 01 11
system call 4
0xFF 31 21 14
system call 3
0xA2 22 00 10
system call 2
0x82 87 95 94
system call 1
0x20 15 10 00
system call 0
0x76 00 00 00
0x FF FF FF FF
stack
allocated with system call
heap
allocated with system call
heap
allocated with system call
heap
allocated with system call
heap
0x 00 00 00 00
code
0x FF FF FF FF
stack
heap
 deallocated with system call
heap
heap
0x 00 00 00 00
code
0x FF FF FF FF
stack
stack boundary 
heap
heap
heap
0x 00 00 00 00
code
 top of stack
0x FF FF FF FF
stack
 top of stack
stack boundary 
heap
heap
heap
0x 00 00 00 00
code
created
terminated
waiting
running
blocked
http://proglit.com/
HD
HD
partition 1
flash drive
CD-ROM
partition 5
partition 4
partition 6
partition 2
partition 7
partition 3
file 35
directory 21
file 3
directory 86
file 7
root directory
file 61
partition 1
partition 2
C:
H:
C:/
H:/
D:/
partition 3
D:
partition 1
C:
partition 2
partition 3
H:
C:/adams/nixon
H:/taylor/polk/hayes
D:/garfield
D:
partition 1
partition 2
/banana
/
partition 3
/lemon/apple
partition 1
partition 2
/banana
/
partition 3
/lemon/apple
/banana/adams/nixon
/taylor/polk/hayes
/lemon/apple/garfield
IPC (Interprocess
Communication)
files
pipes
sockets
signals
shared memory
http://proglit.com/