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();
}
相关推荐
Root_Smile8 小时前
【Python】pip freeze用法
开发语言·python·pip
csbysj20208 小时前
XML与HTML:结构化数据的基石
开发语言
比奇堡派星星8 小时前
Linux 平台设备驱动框架详解
linux·开发语言·驱动开发
2501_941878748 小时前
从限流策略到系统节奏感的互联网工程语法设计与多语言实践随笔分享
java·开发语言
钱多多_qdd8 小时前
springboot注解(四)
java·spring boot·后端
wniuniu_8 小时前
ceph的osd
java·前端·ceph
Data_agent8 小时前
Eastmallbuy模式淘宝/1688代购系统搭建指南
java·运维·数据库
yangpipi-8 小时前
《C++并发编程实战》第6章 设计基于锁的并发数据结构
开发语言·数据结构·c++
SimonKing8 小时前
神了,WebSocket竟然可以这么设计!
java·后端·程序员
allione8 小时前
Java设计模式-工厂模式
java·开发语言·设计模式