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. Standard ABI procedures should not modify tp because signal handlers may rely on its value.

psABI: x4 is named tp and means Thread pointer.
psABI: tp is unallocatable and standard ABI procedures should not modify it.
Beginner rule: do not treat tp like a temporary register such as t0 or t1.
Physical Name x4ABI Name tpSave Rule Unallocatable
Role
Thread pointer; unallocatable and not modified by standard ABI procedures.
Convention
Unallocatable
Remember This First
The psABI marks tp as unallocatable.
psABI Reference

Unallocatable register

tp is marked unallocatable by the psABI. Procedures should not modify it because signal handlers 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. Standard ABI procedures should not modify it; it is not a normal caller-saved or callee-saved choice.

The psABI marks x4/tp as unallocatable.
Standard ABI procedures should not modify gp/tp because signal handlers 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 an unallocatable psABI register.
  • - For environment-specific conventions beyond the psABI table, consult that environment's official ABI documentation.

When Not To Use It This Way

  • - Do not modify tp in standard ABI 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 standard ABI 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 standard ABI function
# This page does not define a concrete thread model or access form
# 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 standard ABI 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.