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();
}
相关推荐
NMIXX爻8 分钟前
线程控制 下
java·开发语言·jvm
Howrun77710 分钟前
C++ 类间交互
开发语言·c++
2401_8576835425 分钟前
C++代码静态检测
开发语言·c++·算法
时艰.30 分钟前
JVM 垃圾收集器(G1&ZGC)
java·jvm·算法
2401_8384725130 分钟前
内存泄漏自动检测系统
开发语言·c++·算法
开发者小天35 分钟前
python中的class类
开发语言·python
2501_933329551 小时前
Infoseek数字公关AI中台技术解析:如何构建企业级舆情监测与智能处置系统
开发语言·人工智能
m0_706653231 小时前
基于C++的爬虫框架
开发语言·c++·算法
梵刹古音1 小时前
【C语言】 数据类型的分类
c语言·开发语言
iRuriCatt1 小时前
智慧景区管理系统 | 计算机毕设项目
java·前端·spring boot·vue·毕设