# 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="untitled-2" %}
[untitled-2](https://xiayingp.gitbook.io/build_a_os/traps-and-interrupts/untitled-2)
{% 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.**

![](https://1274781047-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M13JlZNu0b_edmxHTQk%2F-M4f57i3Srvueo4sghjY%2F-M4f9T6DU2BqnEh-Ax2I%2Fimage.png?alt=media\&token=96a026b4-f1a5-44b1-9b7c-f3a5a9a11fee)

![](https://1274781047-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M13JlZNu0b_edmxHTQk%2F-M4f57i3Srvueo4sghjY%2F-M4f9WL_V23wpMkkaW22%2Fimage.png?alt=media\&token=de549a64-ad4f-4fee-910e-9bc3b32a71f7)

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="trap-home-page" %}
[trap-home-page](https://xiayingp.gitbook.io/build_a_os/traps-and-interrupts/trap-home-page)
{% endcontent-ref %}


---

# Agent Instructions: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
