quick look at pdp-11 cpu
DESCRIPTION
제 24 강 : Process Image. Quick look at pdp-11 CPU. Chapter Two CPU registers. Two kinds of stack Case: Fixed size Case: Variable size SP : Stack Pointer SP : Stack Pointer EP : Environment Pointer (boundary or size) Stack & Function call frame - PowerPoint PPT PresentationTRANSCRIPT
1
Quick look at pdp-11 CPU
제 24 강 : Process Image
2
Chapter Two
CPU registers• Two kinds of stack
– Case: Fixed size Case: Variable size
• SP: Stack Pointer SP: Stack Pointer EP: Environment Pointer (boundary or size)
• Stack & Function call frameCall argument Local variableReturn address Register save
bottom
top - SP
bottom
top - SP
EPmain(){ x= sin (arg); - - - y= sin (arg);}
sin (arg);{ local var; expression; return;}
pop this portion
3
pdp-11 CPU has 2 SP’s main()
do_a()
do_b()
read()
read()
do_p()
do_q()
do_r()
kernel
lsmain()do_a()do_b()read()
read()do_p()do_q()do_r()
sys call
user stack
kernel stack
SP
SP
Base
Base
4
Protection (multi-user) prevent R/W/Jump to other process’ image confine memory access intercept faulty accessScattered Allocation image can be scatteredAllow Relocation during swapping, not on-demand paging
Why pdp-11 needs MMU(memory management
unit)
CPU Memory
CPU MemoryMMU
Physical Address
VA
loc 0
PA
loc 2000
PAR: Page Address Register (maps VA to PA)
PAR2000
30002500
Mapping Tablefor a.out
5
• Physical memory was divided up into 8K byte pages• memory space/process = 64Kbytes = 8 pages• Max 8 PAR’s per process• Access mode (R|W|...) per page PDR (Page Description Register) & PAR Pair
• Allocate contiguous chunk of physical memory for each process
Split up this chunk into 3 pieces text data areas stack
• Unix may have used just three PAR|PDR’s
stack
data
text
XX
WW
W
W
W
01
23
4
5
7
6
PAGES
PDRreadwrite
PAR2000
30002500
con
tig
uou
s
pag
es
6
PAR PDR
<active USER >
PAR PDR
< KERNEL>
sha.out
via.out
kernela.out
Memory
2 sets of memory mapping registers
7
CPU
PCB
mem disk
user
PCB
tty
sh vi mail
CPU mem disk tty
Kernel a.out
Hardware
proc
K-stack
Remember?Kernel has PCB for each
application
8
Kernel’s PCB in detail
sh
vi
kernel
PCB(sh)PCB(vi)PCB(ls)
logicaladdress
ls
user
proc
K-stack
proc [NPROC]
user
kernel
stack
struct user & k-stackshare single page
1 page / process“ppda”
(per process data area)
sh
ls vi
user
proc
K-stack
9
Kernel’s PCB layout
sh
vi
kernelproc[ ]
ls
u stack
u stack
u stack
logicaladdress
1 page per each process (ppda)
1 global array for all processes
user
kernel
stack
10
scatter ppda in physical address space
sh
vi
kernelproc
ls
u stack
u stack
u stack
logicaladdress
sh
vi
kernelproc
ls
u stack
u stack
u stack
physicaladdress
logically contiguousphysically scattered adjacent to application’s image
(ppda)1 page
perprocess
11
each proc[ ] points to application’s ppda
sh
vi
kernelproc
ls
u stack
u stack
u stack
kernelproc
struct proc { p_addr; p_size; }
sh
vi
ls
u stack
u stack
u stack
ppdaaddress
logicaladdress
physicaladdress
sizeof
swappable
12
sha.out
via.out
kernela.out
proc[0]proc[i]proc[k]
kernel
a.outproc[0]proc[i]proc[k]
= 10000
= 20000
= 30000
20000 loc. 0
loc. 0Physical AddressLogical Address
30000 ppda
ppda
sh
vi
ls
u stack
u stack
u stack ppda
50000
13
PAR PDR
<Active USER >
PAR PDR
< KERNEL>
sha.out
via.out
u--stack
u--stack
Kernel
a.out
struct user k-stack
struct user k-stack
struct user k-stack
2 sets of {PAR|PDR}
14
PAR PDR
< KERNEL>
sha.out
via.out
u--stack
u--stack
Kernel
a.out
struct user k-stack
struct user k-stack
struct user k-stack
kernel 7th mapping register
Points to active process ppda (7-3-1-b)
Hence, in Lion’s code
“u ” always points to struct user ofthe current active process
(cf. proc[PID])
Kernel’s 7th PAR active user’s ppda
PAR PDR
<Active USER >
15
main, icode
16
PAR PDR
< USER >
PAR PDR
< KERNEL>
sha.out
via.out
u--stack
u--stack
Kernel
Proc[0]Proc[i]Proc[k]
struct user k-stack
struct user k-stack
struct user k-stack
proc[i].p_addr is
address of process i’s
ppda
struct user
image
7-th reg == ppda of active process
17
sh(parent)
ls(child)
At this point, context switch: Kernel 7th PAR points to new ppda
--------User PAR/PDR also changes
estabur() sureg()
PAR PDR
< USER >
PAR PDR
lsa.out
sha.out
u--stack
u--stack
Kernel
a.out
struct user k-stack
struct user k-stack
struct user k-stack
18
CPU mem disk
user
Process sh Process vi Process ls
CPU mem disk
User a.out
Kernel a.out
K-stack
“ppda”(per processdata area)
kernel space7-th kernel page
Data Segment(swappable)
* (7-2, 7-3)
address of 7-th kernel page (ppda) address of active process
user
proc
K-stack
proc PROC[ ]
PPDA (7-th page)user
K-stack
proc
user
kernel
stack
7-th page
19
text
data
bss
p_addr
(7-th kernel page)
p_size
Process Image
bss: allocated at load time, init to zero
struct user: located adjacent to program segment
but is part of kernel address space
proc[i]
u-stack
struct user
k-stack
a.out
ppdaSwappable
Image
(data segment)
Process
Image
20
• data segment (swappable image) (7-3)• allocated as one single segment (physically contiguous – for swap)
• ppda (per process data area) (7-3)• 7th page of kernel • lower end -- struct "user“• higher end -- kernel mode stack
• proc[PID].p_addr, p_size (7-2)• address of process (swappable image) (whether in core or disk)
• 7-th kernel (segmentation address) register points to <= proc[i].p_addr (address of the process)
user
kernel
stack
7-th page
21
PAR PDR
< KERNEL>
sha.out
via.out
kernela.out
proc[0]proc[i]proc[k]
ppda pda(sh) (vi)
loc. 0
sha.out
via.out
kernel
a.outproc[0]proc[i]proc[k]
struct userk-stack(sh)
struct user k-stack(vi)
= 10000
= 20000
= 30000
30000
10000
20000
loc. 0
loc. 0
Physical AddressLogical Address
ppda (sh)
ppda (vi)
7-th page p p d a of Active
processowned bykernel
adjacent toapplication, for swapping
22
PAR PDR
< KERNEL>
sha.out
via.out
kernela.out
proc[0]proc[i]proc[k]
ppda pda(sh) (vi)
loc. 0
sha.out
via.out
kernel
a.outproc[0]proc[i]proc[k]
struct user k-stack(sh)
struct user k-stack(vi)
= 10000
= 20000
= 30000
30000
10000
20000
loc. 0
loc. 0
Physical AddressLogical Address
ppda
ppda
7-th page
SwappableImage
“data segment”(7-3)
a.out
PAR PDR
< USER >
23
a.out
u-stack
proc[i] proc[j] proc[k] …
userk-stack
a.out
u-stack
userk-stack
a.out u-stack
userk-stack
PAR PDR
USER
PAR PDR
KERNEL
sh vi sim
Adjacent
Belongs
p_addr p_addr
24
CPU state3 types of CPU registers
• with address– memory mapping PAR|PDR– instruction address PC– stack SP EP
• with data – R0 R1 R2 R3 …
• with others (status)– PSW (ZNCOM ..)
CPU
R0 R1 | SP E P PC
PAR PDR
USER
PAR PDR
KERNEL
< CPU State >
25
PAR PDR
KERNEL
7
7th Register
R0R1 |R4EPSPPC
k sha.out
via.out
u--stack
u--stack
Kernel
a.out
struct user k-stack
Physical Address
struct userk-stack (vi)
struct userk-stack (sh)
points to p.p.d.a. ofactive process
(base of kernel stack)
top of kernel st
ack
kernel stack fra
me boundary
U
user stack
CPU Registers
Mapping Registers
7-th kernel mapping register (6-2)
26
PAR PDR
< USER >
PAR PDR
< KERNEL>
Kernel
Proc[0]
struct user k-stack
proc[i].p_addr is
address of process i’s struct user
ppda
image
7-th ksar == ppda of active process
After the boot/init,
7-th ksar = proc #0 (kernel process)
(1589) (6-3-1-b) (6-3-3-b)