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();
}
相关推荐
不懒不懒1 分钟前
【基于 CNN 的食物图片分类:数据增强、最优模型保存与学习率调整实战】
开发语言·python
木井巳4 分钟前
【多线程】常见的锁策略及 synchronized 的原理
java·开发语言
代码改善世界5 分钟前
【C++初阶】类和对象(二):默认成员函数详解与日期类完整实现
开发语言·c++
专注VB编程开发20年6 分钟前
VS2026调试TS用的解析/运行引擎:确实是 ChakraCore.dll(微软自研 JS 引擎)
开发语言·javascript·microsoft
郝学胜-神的一滴9 分钟前
深入理解Python生成器:从基础到斐波那契实战
开发语言·前端·python·程序人生
南梦浅14 分钟前
网站redis从开发到部署方案
java·jvm·redis
问水っ14 分钟前
Qt Creator快速入门 第三版 第6章 事件系统
开发语言·qt
cm65432015 分钟前
C++中的空对象模式
开发语言·c++·算法
吴声子夜歌15 分钟前
JavaScript——异常处理
开发语言·javascript·ecmascript
2401_8512729915 分钟前
C++代码规范化工具
开发语言·c++·算法