其他分享
首页 > 其他分享> > Xv6 Operating System Organization

Xv6 Operating System Organization

作者:互联网

Meaning Unknown's Head Image

Operating System Organization

参考 xv6-riscv-book Chapter 2 Operating system organization

文章目录

Three requirements for OS:

Abstracting physical resources

Transparency: simplifies interaction

User mode, supervisor mode, and system calls

在这里插入图片描述

Kernel organization

OrganizationDescriptionUpsideDownside
monolithic kernelthe entire OS resides in the kernel with full privilegeconvenient,
easier for different parts of the OS to cooperate
complex interfaces,
easy to make a mistake,
a mistake is fatal
microkernelminimize the code that runs in supervisor mode,
execute the bulk of the OS in user mode
reduce the risk of mistakes in the kernel

在这里插入图片描述

(NOTE> OS services running as processes are called servers)

Xv6 organization

Xv6 kernel source files:

FileDescription
bio.cDisk block cache for the file system.
console.cConnect to the user keyboard and screen.
entry.SVery first boot instructions.
exec.cexec() system call.
file.cFile descriptor support.
fs.cFile system.
kalloc.cPhysical page allocator.
kernelvec.SHandle traps from kernel, and timer interrupts.
log.cFile system logging and crash recovery.
main.cControl initialization of other modules during boot.
pipe.cPipes.
plic.cRISC-V interrupt controller.
printf.cFormatted output to the console.
proc.cProcesses and scheduling.
sleeplock.cLocks that yield the CPU.
spinlock.cLocks that don’t yield the CPU.
start.cEarly machine-mode boot code.
string.cC string and byte-array library.
swtch.SThread switching.
syscall.cDispatch system calls to handling function.
sysfile.cFile-related system calls.
sysproc.cProcess-related system calls.
trampoline.SAssembly code to switch between user and kernel.
trap.c Ccode to handle and return from traps and interrupts.
uart.cSerial-port console device driver.
virtio_disk.cDisk device driver.
vm.cManage page tables and address spaces.

(From: pbpaste | awk '{ printf("| %s |", $1); for (i=2; i<=NF; i++) printf(" %s", $i); printf(" |\n"); }' | pbcopy)

The inter-module interfaces are defined in kernel/defs.h.

Process overview

Process

The unit of isolation: a process: an illusion to a program that it has its own private machine (private memory, CPU, file descriptors, etc.). Process is defined as struct proc (kernel/proc.h:86).

enum procstate { UNUSED, USED, SLEEPING, RUNNABLE, RUNNING, ZOMBIE };

Thread

Thread (of execution): executes the process’s instructions.

A thread can be suspended and later resumed.

Threads can “block” in the kernel to wait for I/O, and resume where it left off when the I/O has finished.

Virtual address

Virtual address: Isolation of memory: virtual address -- page tables --> physical address:

MAXVA
↑    trampoline
|    trapframe
|    Heap
|    Stack (user stack)
|    Global Variables (text and data)
|    Instructions
0

System call

ecall: a RISC-V instruction to make a system call:

  1. raises hardware privilege level
  2. change PC to a kernel-defined entry point, switches to a kernel stack
  3. executes the kernel instructions
  4. (system call completes) switches back to the user stack
  5. returns to user space by calling the sret instruction (lowers the hardware privilege level)
  6. resumes executing user instructions just after the system call instruction

Starting xv6 and the first process

  1. RISC-V computer powers on, self initializes
  2. runs a boot loader (stored in ROM): loads the xv6 kernel into memory at physical address 0x80000000 (range 0x0:0x80000000 contains I/O devices)
  3. (in machine mode) executes xv6 starting at _entry (kernel/entry.S:6), sets up a stack (stack0) for C code (sp = stack0 + (hartid * 4096))
  4. _entry calls into C code: function start (kernel/start.c:11)
  5. start performs configuration(page-table, interrupts…)
  6. switches to supervisor mode, PC change to main (kernel/main.c:11)
  7. main initializes several devices and subsystems
  8. creates the first process by calling userinit (kernel/proc.c:212)
  9. run initcode.S (user/initcode.S:1), do exec("/init")
  10. init (user/init.c:15) creates a console device file, opens it as file descriptors 0, 1, and 2
  11. starts a shell on the console
  12. The system is up.

EOF


// By CDFMLR 2021-02-27
printf("See you.\n");

顶部图片来自于小歪API,系随机选取的图片,仅用于检测屏幕显示的机械、光电性能,与文章的任何内容及观点无关,也并不代表本人局部或全部同意、支持或者反对其中的任何内容及观点。如有侵权,联系删除。

标签:kernel,process,system,System,Operating,user,address,Organization,mode
来源: https://blog.csdn.net/u012419550/article/details/114192498