当前位置:网站首页>[mit 6.s081] LEC 6: isolation & system call entry/exit notes
[mit 6.s081] LEC 6: isolation & system call entry/exit notes
2022-07-27 18:27:00 【PeakCrosser】
Lec 6: Isolation & system call entry/exit
- Ref: https://github.com/huihongxiao/MIT6.S081/tree/master/lec06-isolation-and-system-call-entry-exit-robert
- Preparation: xv6 book Chapter 4 except 4.6
Trap
- trap: Switching between user space and kernel space
- Switch timing :
- system call
- abnormal Exception, In case of page missing error (page fault), Divide by zero error
- Device triggered interrupt
- Important registers :
- STVEC(Supervisor Trap Vector Base Address Register): Point to processing in the kernel trap The first address of the instruction ( According to the user or kernel , The code will be different )
- SEPC(Supervisor Exception Program Counter): trap Save the value of the program counter in the process
- SSRATCH(Supervisor Scratch Register): To hold trapframe Page virtual address
- Operations to be completed during switching :
- preservation 32 User registers
- Save program counter PC
- Transfer mode MODE Switch from user state to kernel state
- take SATP The register points from the user page table to the kernel page table
- You need a stack to call the kernel C function , And make SP Point to
- Jump into kernel C Code
- Kernel mode (supervisor mode) The privilege of :
- Reading and writing SATP register , Yes STVEC, SEPC, SSCRATCH Wait for the register to operate
- have access to PTE_U Sign bit is 0 Of PTE
Trap Code execution process
- System call through ECALL Instructions switch to the kernel ( This instruction does not switch page tables , There is no user page table at this time )
- The kernel executes assembly functions
uservec, yestrampoline.SintrampolinePart of . This function switches SSCRATCH and a0 Register value , after a0 The value is trapframe The address of , And then 32 The values of user registers and other registers are stored inp->trapframein ; Then the kernel stack frame pointer will be loaded (kernel_sp), And load the address of the kernel page table to SATP register Complete the switching of the kernel page table . Finally jump to C Codetrap.cOfusertrap() usertrap()First of all, will STVEC The register is made up ofusertrapChange tokerneltrap( Because sending interrupts again at this time belongs to having interrupts from the kernel trap). Then, if it is a system call, callsyscall()Function to find the function of the corresponding system function from the system call tablesys_xxx()To perform , Go back tosyscall(); If it is an interrupt from the device, executedevintr. In the end, it will callusertrapret().- perform
trap.cMediumusertrapret(). First of all, I willp->trapframeSet the values of the fields related to the kernel , For the next time trap. Set up SSTATUS User mode flag bit . Finally, call the assembly functionuserret. - perform
trampoline.SMediumuserretfunction . First switch back to the user page table , And then from trapframe Load the value into the register , The final will be trapframe The address is stored in the register SSCRATCH in . - Back to user space .

- ECALL effect :
- Change the code from user mode to kernel mode
- take PC To preserve with SEPC
- Jump to STVEC Register points to ( Handle trap Of ) Instructions
- How to save user registers :
- The kernel will trapframe Mapped to each user page table
- Before entering user space ( The operating system starts in kernel mode ), The kernel will trapframe The address is saved at SSCRATCH register , coordination
csrrwInstruction registera0andsscratchContent exchange .
边栏推荐
- Lotcode dynamic array exercise (724118766)
- [MIT 6.S081] Lab 11: networking
- 深度学习:安装包记录
- [MIT 6.S081] Lab8: locks
- 【学习笔记】Redis中有序集合zset的实现原理——跳表
- 深度学习:GAN优化方法-DCGAN案例
- JDBC学习 Day1:JDBC
- 又一个时代的终结!
- 邮件安全运营难?Coremail携手云商店打造企业邮箱办公新生态!
- Guoju spent $1.8 billion to acquire its competitor KEMET, and the transaction may be completed in the second half of next year
猜你喜欢
随机推荐
Together with Samsung, vivo will promote exynos980 dual-mode 5g mobile phone!
What every Salesforce developer should know about Dates and Times in Apex
[MIT 6.S081] Lab8: locks
Dynamic linked list 4 one-way circular linked list (loopsingle Implementation)
2. 改变颜色空间及颜色检测
@DateTimeFormat 接收不到时分秒,转换时报类型异常
[MIT 6.S081] Lec 5: Calling conventions and stack frames RISC-V 笔记
1542. 找出最长的超赞子字符串 哈希+状态压缩
Golang waits for a group of goroutines to complete with the return value (2)
[MIT 6.S081] Lab 5: xv6 lazy page allocation
深度学习:GAN案例练习-minst手写数字
Lotcode dynamic array exercise (724118766)
《华为是谁》纪录短片集登陆BBC:曝光大量任正非不为人知经历
黑客用激光攻击,百米外就能激活语音助手
[learning notes] Lombok's @builder annotation
多表查询
江苏华存首发PCIe 5.0 SSD主控:台积电12nm工艺,2020年量产
嘉楠耘智已完成预路演,预计11月20日登陆纳斯达克
深度学习:GAT
LootCode动态数组练习(724,118,766)



![[MIT 6.S081] Lec 3: OS organization and system calls 笔记](/img/34/073d00245eb39844bbe1740f65fe07.png)
![[MIT 6.S081] Lab 11: networking](/img/9d/cca59a662412f3c3c57c26c5987a24.png)


