Skip to content

Commit

Permalink
Clarify that x86-interrupt only saves registers that are overwritten
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-opp committed Feb 7, 2020
1 parent 536a37a commit a3eeb1d
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions blog/content/second-edition/posts/05-cpu-exceptions/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ In contrast to function calls, exceptions can occur on _any_ instruction. In mos

Since we don't know when an exception occurs, we can't backup any registers before. This means that we can't use a calling convention that relies on caller-saved registers for exception handlers. Instead, we need a calling convention means that preserves _all registers_. The `x86-interrupt` calling convention is such a calling convention, so it guarantees that all register values are restored to their original values on function return.

Note that this does not mean that all registers are saved to the stack at function entry. Instead, the compiler only backs up the registers that are overwritten by the function. This way, very efficient code can be generated for short functions that only use a few registers.

### The Interrupt Stack Frame
On a normal function call (using the `call` instruction), the CPU pushes the return address before jumping to the target function. On function return (using the `ret` instruction), the CPU pops this return address and jumps to it. So the stack frame of a normal function call looks like this:

Expand Down

0 comments on commit a3eeb1d

Please sign in to comment.