a toy level unix like kernel writtern for raspberry pi 3 I build it just for exploring and understanding some key point in kernel developement
before we dive into kernal dev, big picture must established in our mind.
- cpu can only execute one process's code at one time
- intterupt happened indepently
- we can use interrupt to jump into kernel code
- in kernel code we can call scheduler , allocate memory for new process, deallocate memory for killed process .......
- cpu execute process for a short time, when interrupt happpened , start execute kernel ,do some management, and then execute process code again.
in below diagram
sequenceDiagram
process1->>kernel: system call
kernel->>process2: scheduler switch
process2->>kernel: interrupt
kernel->>process1: scheduler switch
the kernel code in charge of all cpu resource management.
the core concet of virtual address is page.
assume a tiny tiny memory which size is 8 byte.
a 3 bit number can address all the space. because
we can divide it into 2 pages(
memory still the same memory but we change a view of it.by using page.
now consider a more wide range of memory which size is
from now we found basic page system provide another way for us to orgnize our memory. it's elegant , it is an art.
we compile 2 process. each process will plan to read some data from memory 0x1F and 0x9C.(0x1F and 0x9C is already a virtual address, because compiler don't know the current status of OS/PC,they can only assign to a fixed memory) but how could we allow them to access the same memory? wow , we know page system is elegant. but if see each page is a indepedent world. we can assign differrent page to to different process's same virtual memory.
A 1 level page table is easy to understand. In real world a typical address range is 32 bit. and page size is 4k(2^12=4K) which means we can index 2^20 pages(20=32-12). if we manage process's page table(we need memory to store them right?),we need consume huge memory in our kernel