The relation between privileged instructions, traps and system calls

前端 未结 2 1709
梦如初夏
梦如初夏 2021-01-30 15:23

I am trying to understand how a virtual machine monitor (VMM) virtualizes the CPU.

My understanding right now is that the CPU issues a protection fault interrupt when a

2条回答
  •  既然无缘
    2021-01-30 15:43

    I'm not an expert on computer architecture. But I have several opinions for your consideration:

    1. The CPU has two kinds of instructions
      • normal instructions, e.g., add, sub, etc.
      • privileged instructions, e.g., initiate I/O, load/store from protected memory etc.
    2. The machine (CPU) has two kinds of modes (set by status bit in a protected register):
      • user mode: processor executes normal instructions in the user’s program
      • kernel mode: processor executes both normal and privileged instructions (OS == kernel)
    3. Operating systems hide privileged instructions as system calls. And if user program calls them, it will cause an exception (throws a software interrupt), which vectors to a kernel handler, trap to kernel modes and switch contexts.
    4. Upon encountering a privileged instruction in user mode, processor trap to kernel mode. Depending on what happened it would be one of several traps, such as a memory access violation, an illegal instruction violation, or a register access violation. The trap switches the processor’s execution to kernel mode and switches control to the operating system, which then decides on a course of action. The address is defined by the trap vector, which is set up when the operating system starts up.

提交回复
热议问题