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();
}
相关推荐
T.Ree.2 分钟前
cpp_list
开发语言·数据结构·c++·list
laocooon5238578865 分钟前
C++ 图片加背景音乐的处理
开发语言·c++
爱编程的鱼15 分钟前
C# var 关键字详解:从入门到精通
开发语言·c#·solr
MATLAB代码顾问18 分钟前
MATLAB实现TCN神经网络数值预测
开发语言·matlab
2301_7965125240 分钟前
Rust编程学习 - 如何利用代数类型系统做错误处理的另外一大好处是可组合性(composability)
java·学习·rust
南汐汐月1 小时前
重生归来,我要成功 Python 高手--day33 决策树
开发语言·python·决策树
清水1 小时前
Spring Boot企业级开发入门
java·spring boot·后端
一个不称职的程序猿1 小时前
高并发场景下的缓存利器
java·缓存
星释1 小时前
Rust 练习册 :Proverb与字符串处理
开发语言·后端·rust
2301_801252221 小时前
Tomcat的基本使用作用
java·tomcat