Skip to content

Commit 4e61353

Browse files
committed
Add more description for those function attributes
We have few RISC-V specific function attributes like naked and interrupt, they are implmented on both LLVM and GCC for a while. But we don't have well described here.
1 parent 426001d commit 4e61353

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

riscv-c-api.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,32 @@ For example:
164164

165165
## Function Attributes
166166

167-
* `__attribute__((naked))`
168-
* `__attribute__((interrupt))`
169-
* `__attribute__((interrupt("user")))`
170-
* `__attribute__((interrupt("supervisor")))`
171-
* `__attribute__((interrupt("machine")))`
167+
### `__attribute__((naked))`
168+
169+
The compiler won't generate the prologue/epilogue for those functions with
170+
`naked` attributes. This attribute is usually used when you want to write a
171+
function with an inline assembly body.
172+
173+
This attribute is incompatible with the `interrupt` attribute.
174+
175+
NOTE: Be aware that compilers might have further restrictions on naked
176+
functions. Please consult your compiler's manual for more information.
177+
178+
### `__attribute__((interrupt))`, `__attribute__((interrupt("user")))`, `__attribute__((interrupt("supervisor")))` `__attribute__((interrupt("machine")))`
179+
180+
The interrupt attribute specifies that a function is an interrupt handler.
181+
The compiler will save/restore all used registers in the prologue/epilogue
182+
regardless of the ABI, all used registers including floating point
183+
register/vector register if `F` extension/vector extension is enabled.
184+
185+
The interrupt attribute can have an optional parameter to specify the mode.
186+
The possible values are `user`, `supervisor`, or `machine`.
187+
The default value `machine` is used, if the mode is not specified.
188+
189+
The function can specify only one mode; the compiler should raise an error if a
190+
function declares more than one mode or an undefined mode.
191+
192+
This attribute is incompatible with the `naked` attribute.
172193

173194
## Intrinsic Functions
174195

0 commit comments

Comments
 (0)