Register Guide

RISC-V tp / x4 Register: Thread Pointer and Unallocatable ABI Convention

tp is the thread pointer in the psABI and is marked unallocatable. Normal procedures should not modify tp; the standard ABI says this because signal handlers and similar runtime contexts may rely on its value.

psABI: x4 is named tp and means Thread pointer.
psABI: tp is unallocatable and should not be modified by normal procedures.
Beginner rule: do not treat tp like a temporary register such as t0 or t1.
Physical Name x4ABI Name tpSave Rule N/A
Role
Thread pointer for accessing thread-local storage (TLS); ordinary procedures should not modify it.
Convention
Unallocatable
Remember This First
The psABI marks tp as unallocatable.
psABI Reference

Unallocatable register

tp is marked unallocatable by the psABI. Normal procedures should not modify it because signal handlers, runtimes, or platform conventions may rely on its value.

Preserved across calls: Not applicable
RISC-V psABI integer register convention
Quick Understanding & Search Notes

tp / x4 is marked unallocatable by the psABI. Normal procedures should not modify it; it is not a normal caller-saved or callee-saved choice.

The psABI marks x4/tp as unallocatable.
Normal procedures should not modify gp/tp because signal handlers and similar runtime contexts may rely on their values.

When It Fits Best

  • - Recognize it as the psABI thread pointer, not a normal temporary register.
  • - When reading disassembly, first treat tp as a thread-related ABI reserved value.
  • - For details of a concrete TLS model, consult the target platform and toolchain ABI documentation.

When Not To Use It This Way

  • - Do not modify tp in normal procedures.
  • - Do not use tp as a general-purpose or temporary register.

What Happens Around A Call

1

The psABI marks tp as unallocatable.

2

The psABI says normal procedures should not modify tp because signal handlers may rely on it.

3

It is not a normal caller-saved/callee-saved choice; it should not be allocated to ordinary code.

Read tp As A Reserved ABI Value

Examples explain the rule, not a complete program
# Do not borrow tp in a normal function
# Concrete thread and TLS access forms depend on the target ABI/toolchain
# Use t0-t6 for temporaries, or save other registers according to the calling convention

FAQ

Can tp / x4 be used as an ordinary temporary?

It should not. The psABI marks it unallocatable, and normal procedures should not modify it.

Is tp caller-saved or callee-saved?

Neither in the usual sense; it is unallocatable, so ordinary code should not borrow it.