当前位置:网站首页>[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 .
边栏推荐
- Technology sharing | quick intercom integrated dispatching system
- Deep learning: Gan case exercise -minst handwritten digits
- Software installation related
- 荣耀、小米发双十一战报:都称自己是冠军
- [MIT 6.S081] Lec 5: Calling conventions and stack frames RISC-V 笔记
- Prevent SQL injection
- @Scheduled and quartz
- 3. Opencv geometric transformation
- 英特尔发布新一代Movidius VPU:性能提升10倍,功耗仅30W
- [MIT 6.S081] Lab 4: traps
猜你喜欢
随机推荐
1542. Find the longest super substring hash + state compression
@Convert 注解在jpa中进行查询的注意事项
Disassembly of Xiaomi cc9 Pro: the cost of rear five shots is several times that of Xiaolong 855!
深度学习:安装包记录
Golang concurrent cache breakdown or merge request
LootCode动态数组练习(724,118,766)
宣布收购文晔30%股份,大联大意欲何为?
Zhanrui fresh seedlings: enable full scene applications, and massive data needs the integration of AI and IOT
Common commands of database 1
What every Salesforce developer should know about Dates and Times in Apex
Common commands of database 2
[MIT 6.S081] Lec 3: OS organization and system calls 笔记
Deep learning: GCN diagram classification case
How do corporate giants such as Schneider Electric and L'Oreal make open innovation? Uncover secrets of demo World Innovation Summit
Deep learning: installation package records
Marvell公布旗下Arm服务器芯片路线图,下一代性能将比ThunderX2高两倍
Nowcoder (5 choices)
3. Opencv geometric transformation
CFA exam registration instructions
[MIT 6.S081] Lab 5: xv6 lazy page allocation








![[MIT 6.S081] Lab 3: page tables](/img/ea/94cdb4379733994adf3aa31cf2e826.png)