Lecture 6 Isolation & System Call Entry

文章目录

  • [一 重要的函数清单](#一 重要的函数清单)
    • [1 write(user/usys.s)](#1 write(user/usys.s))
  • [一 usertrap函数(C code)](#一 usertrap函数(C code))

Lecture6 Isolation & System Call Entry视频链接

对应XV6 Book Chapter 4 Traps and device drivers

一 重要的函数清单

1 write(user/usys.s)

cpp 复制代码
.global write
write:
 li a7, SYS_write
 ecall
 ret

一 usertrap函数(C code)

cpp 复制代码
//
// handle an interrupt, exception, or system call from user space.
// called from trampoline.S
//
void
usertrap(void)
{
  int which_dev = 0;

  if((r_sstatus() & SSTATUS_SPP) != 0)
    panic("usertrap: not from user mode");

  // send interrupts and exceptions to kerneltrap(),
  // since we're now in the kernel.
  w_stvec((uint64)kernelvec);

  struct proc *p = myproc();
  
  // save user program counter.
  p->trapframe->epc = r_sepc();
  
  if(r_scause() == 8){
    // system call

    if(p->killed)
      exit(-1);

    // sepc points to the ecall instruction,
    // but we want to return to the next instruction.
    p->trapframe->epc += 4;

    // an interrupt will change sstatus &c registers,
    // so don't enable until done with those registers.
    intr_on();

    syscall();
  } else if((which_dev = devintr()) != 0){
    // ok
  } else {
    printf("usertrap(): unexpected scause %p pid=%d\n", r_scause(), p->pid);
    printf("            sepc=%p stval=%p\n", r_sepc(), r_stval());
    p->killed = 1;
  }

  if(p->killed)
    exit(-1);

  // give up the CPU if this is a timer interrupt.
  if(which_dev == 2)
    yield();

  usertrapret();
}
相关推荐
wjs20246 小时前
JavaScript for 循环详解
开发语言
东华万里6 小时前
第十五讲 指针 从本质吃透 C 语言指针(上)
c语言·开发语言
雨雨雨雨雨别下啦6 小时前
Spring AOP概念
java·后端·spring
on the way 1236 小时前
day04-Spring之Bean的生命周期
java·后端·spring
代码笔耕6 小时前
面向对象开发实践之消息中心设计(二)
java·后端·架构
moxiaoran57536 小时前
Go 语言指针
开发语言·golang
爱吃大芒果6 小时前
Flutter 网络请求完全指南:Dio 封装与拦截器实战
开发语言·javascript·flutter·华为·harmonyos
云水木石6 小时前
Rust 语言开发的 Linux 桌面来了
linux·运维·开发语言·后端·rust
要开心吖ZSH6 小时前
应用集成平台-系统之间的桥梁-思路分享
java·kafka·交互