> For the complete documentation index, see [llms.txt](https://xiayingp.gitbook.io/build_a_os/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://xiayingp.gitbook.io/build_a_os/traps-and-interrupts/untitled-3.md).

# What is trampoline

### What is it?

Trampoline page stores code to switch between user and kernel space. The code is mapped at the same virtual address (TRAMPOLINE) in user and kernel space so that it continues to work when it switches page tables.

Note: the pointers, page table, sp, etc are stored in `trapframe`.&#x20;

{% content-ref url="/pages/-M4f4uBfm2Ua8uXLmsWU" %}
[What is trapframe](/build_a_os/traps-and-interrupts/untitled-2.md)
{% endcontent-ref %}

In trampoline, we just store plain assembly source code.

### Where does trampoline page store?

RISC-V hardware doesn’t switch page tables during a trap, we need the user page table to include a mapping for the trap vector instructions that **stvec** points to. Further, the trap vector must switch satp to point to the kernel page table. In order to avoid a crash, the vector instructions (stored in trampoline page) must be **mapped at the same address in the kernel page table as in the user page table.**

![](/files/-M4f9T6DU2BqnEh-Ax2I)

![](/files/-M4f9WL_V23wpMkkaW22)

In this way, after switching page table root in `satp` register, virtual memory is still the same, so it can continue to execute.

{% content-ref url="/pages/-M4f4tZ2YMuVakQBmWSJ" %}
[Trap Home Page](/build_a_os/traps-and-interrupts/trap-home-page.md)
{% endcontent-ref %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://xiayingp.gitbook.io/build_a_os/traps-and-interrupts/untitled-3.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
