Day-3
Device
In common, devices can be separated to FS, Net, Dispaly.
1 | /// A structure that contains all device drivers, organized by their category. |
Devices will be initiated in axruntime
, where axdriver
module will be loaded to seek each device and mount drivers.
In qemu, virtio-mmio
will send request to probe driver response otherwise return 0 as non-driver.
Block Driver
Block driver provide interface to write and read block providing IO operations and perennial storage.
Aceros use module axfs
, with definition of interface vfs
, and concrete implementation of ramfs
and devfs
.
Monolith
In U-Level, we will separate kernel memory and user memory, allowing user context used for process.
The basic logic would be construct new user space,load file to it and initiate user stack, then spawn user task with app_entry.
The top of page root would be shared as kernel space, and below would be independent as user space.
In user space separation, many kinds of resources can’t be shared as global resources, rather the demand of TaskExt
as a reference to those independent resources owned by each user apps.
In TaskInner
, we store the ptr of TaskExt
by macro declaration of such type.
1 | struct AxTask { |
1 | /// Task extended data for the monolithic kernel. |
NameSpace
To reuse resources, we will construct a axns_resource
section in compilation to form a global namespace. Each will be shared by Arc::new()
.
If there’s a demand of uniqueness, we will allocate space and copy them.
Page Fault
We could implement lazy allocation of user space memory. We register PAGE_FAULT
for our function and call handle_page_fault
for AddrSpace
.
1 | impl AddrSpace |
MemoryArea
has two way:
- Linear: direct construct map relation of memory based on physical contiguous mmemory.
- Alloc: only construct null-map, and call
handle_page_fault
to really allocate memory.
User App
ELF is the default format of many apps. Kernel take the responsibility to load app to correct region.
Notice the offset of file and virtual space may be different due to optimization of ELF.
In order to load apps from linux, we will construct a Posix Api given interface mimic to linux.