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();
}
相关推荐
背太阳的牧羊人6 分钟前
RAG检索中使用一个 长上下文重排序器(Long Context Reorder) 对检索到的文档进行进一步的处理和排序,优化输出顺序
开发语言·人工智能·python·langchain·rag
ITPUB-微风8 分钟前
美团MTSQL特性解析:技术深度与应用广度的完美结合
java·服务器·开发语言
WeiLai111217 分钟前
面试基础--微服务架构:如何拆分微服务、数据一致性、服务调用
java·分布式·后端·微服务·中间件·面试·架构
Want59519 分钟前
C/C++跳动的爱心
c语言·开发语言·c++
水瓶丫头站住19 分钟前
Qt中QDockWidget的使用方式
开发语言·qt
laimaxgg25 分钟前
Qt常用控件之数字显示控件QLCDNumber
开发语言·c++·qt·qt5·qt6.3
蓝天扶光29 分钟前
c++贪心系列
开发语言·c++
奔跑吧邓邓子1 小时前
【Python爬虫(44)】分布式爬虫:筑牢安全防线,守护数据之旅
开发语言·分布式·爬虫·python·安全
非 白1 小时前
【Java】单例模式
java·笔记·单例模式
C#Thread1 小时前
C#上位机--流程控制(IF语句)
开发语言·javascript·ecmascript