# 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](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](trap-home-page)
{% endcontent-ref %}

