Update release-README after completing the 2.43 release.
[binutils-gdb.git] / gas / doc / c-riscv.texi
blobd3966692625e0e99aec97025c9ed16f0c85175ab
1 @c Copyright (C) 2016-2024 Free Software Foundation, Inc.
2 @c This is part of the GAS manual.
3 @c For copying conditions, see the file as.texinfo
4 @c man end
6 @ifset GENERIC
7 @page
8 @node RISC-V-Dependent
9 @chapter RISC-V Dependent Features
10 @end ifset
11 @ifclear GENERIC
12 @node Machine Dependencies
13 @chapter RISC-V Dependent Features
14 @end ifclear
16 @cindex RISC-V support
17 @menu
18 * RISC-V-Options::        RISC-V Options
19 * RISC-V-Directives::     RISC-V Directives
20 * RISC-V-Modifiers::      RISC-V Assembler Modifiers
21 * RISC-V-Floating-Point:: RISC-V Floating Point
22 * RISC-V-Formats::        RISC-V Instruction Formats
23 * RISC-V-ATTRIBUTE::      RISC-V Object Attribute
24 * RISC-V-CustomExts::     RISC-V Custom (Vendor-Defined) Extensions
25 @end menu
27 @node RISC-V-Options
28 @section RISC-V Options
30 The following table lists all available RISC-V specific options.
32 @c man begin OPTIONS
33 @table @gcctabopt
35 @cindex @samp{-fpic} option, RISC-V
36 @item -fpic
37 @itemx -fPIC
38 Generate position-independent code
40 @cindex @samp{-fno-pic} option, RISC-V
41 @item -fno-pic
42 Don't generate position-independent code (default)
44 @cindex @samp{-march=ISA} option, RISC-V
45 @item -march=ISA
46 Select the base isa, as specified by ISA.  For example -march=rv32ima.
47 If this option and the architecture attributes aren't set, then assembler
48 will check the default configure setting --with-arch=ISA.
50 @cindex @samp{-misa-spec=ISAspec} option, RISC-V
51 @item -misa-spec=ISAspec
52 Select the default isa spec version.  If the version of ISA isn't set
53 by -march, then assembler helps to set the version according to
54 the default chosen spec.  If this option isn't set, then assembler will
55 check the default configure setting --with-isa-spec=ISAspec.
57 @cindex @samp{-mpriv-spec=PRIVspec} option, RISC-V
58 @item -mpriv-spec=PRIVspec
59 Select the privileged spec version.  We can decide whether the CSR is valid or
60 not according to the chosen spec.  If this option and the privilege attributes
61 aren't set, then assembler will check the default configure setting
62 --with-priv-spec=PRIVspec.
64 @cindex @samp{-mabi=ABI} option, RISC-V
65 @item -mabi=ABI
66 Selects the ABI, which is either "ilp32" or "lp64", optionally followed
67 by "f", "d", or "q" to indicate single-precision, double-precision, or
68 quad-precision floating-point calling convention, or none or "e" to indicate
69 the soft-float calling convention ("e" indicates a soft-float RVE ABI).
71 @cindex @samp{-mrelax} option, RISC-V
72 @item -mrelax
73 Take advantage of linker relaxations to reduce the number of instructions
74 required to materialize symbol addresses. (default)
76 @cindex @samp{-mno-relax} option, RISC-V
77 @item -mno-relax
78 Don't do linker relaxations.
80 @cindex @samp{-march-attr} option, RISC-V
81 @item -march-attr
82 Generate the default contents for the riscv elf attribute section if the
83 .attribute directives are not set.  This section is used to record the
84 information that a linker or runtime loader needs to check compatibility.
85 This information includes ISA string, stack alignment requirement, unaligned
86 memory accesses, and the major, minor and revision version of privileged
87 specification.
89 @cindex @samp{-mno-arch-attr} option, RISC-V
90 @item -mno-arch-attr
91 Don't generate the default riscv elf attribute section if the .attribute
92 directives are not set.
94 @cindex @samp{-mcsr-check} option, RISC-V
95 @item -mcsr-check
96 Enable the CSR checking for the ISA-dependent CRS and the read-only CSR.
97 The ISA-dependent CSR are only valid when the specific ISA is set.  The
98 read-only CSR can not be written by the CSR instructions.
100 @cindex @samp{-mno-csr-check} option, RISC-V
101 @item -mno-csr-check
102 Don't do CSR checking.
104 @cindex @samp{-mlittle-endian} option, RISC-V
105 @item -mlittle-endian
106 Generate code for a little endian machine.
108 @cindex @samp{-mbig-endian} option, RISC-V
109 @item -mbig-endian
110 Generate code for a big endian machine.
111 @end table
112 @c man end
114 @node RISC-V-Directives
115 @section RISC-V Directives
116 @cindex machine directives, RISC-V
117 @cindex RISC-V machine directives
119 The following table lists all available RISC-V specific directives.
121 @table @code
123 @cindex @code{align} directive
124 @item .align @var{size-log-2}
125 Align to the given boundary, with the size given as log2 the number of bytes to
126 align to.
128 @cindex Data directives
129 @item .half @var{value}
130 @itemx .word @var{value}
131 @itemx .dword @var{value}
132 Emits a half-word, word, or double-word value at the current position.
134 @cindex DTP-relative data directives
135 @item .dtprelword @var{value}
136 @itemx .dtpreldword @var{value}
137 Emits a DTP-relative word (or double-word) at the current position.  This is
138 meant to be used by the compiler in shared libraries for DWARF debug info for
139 thread local variables.
141 @cindex LEB128 directives
142 @item .uleb128 @var{value}
143 @itemx .sleb128 @var{value}
144 Emits a signed or unsigned LEB128 value at the current position.  This only
145 accepts constant expressions, because symbol addresses can change with
146 relaxation, and we don't support relocations to modify LEB128 values at link
147 time.
149 @cindex Option directive
150 @cindex @code{option} directive
151 @item .option @var{argument}
152 Modifies RISC-V specific assembler options inline with the assembly code.
153 This is used when particular instruction sequences must be assembled with a
154 specific set of options.  For example, since we relax addressing sequences to
155 shorter GP-relative sequences when possible the initial load of GP must not be
156 relaxed and should be emitted as something like
158 @smallexample
159         .option push
160         .option norelax
161         la gp, __global_pointer$
162         .option pop
163 @end smallexample
165 in order to produce after linker relaxation the expected
167 @smallexample
168         auipc gp, %pcrel_hi(__global_pointer$)
169         addi gp, gp, %pcrel_lo(__global_pointer$)
170 @end smallexample
172 instead of just
174 @smallexample
175         addi gp, gp, 0
176 @end smallexample
178 It's not expected that options are changed in this manner during regular use,
179 but there are a handful of esoteric cases like the one above where users need
180 to disable particular features of the assembler for particular code sequences.
181 The complete list of option arguments is shown below:
183 @table @code
184 @item push
185 @itemx pop
186 Pushes or pops the current option stack.  These should be used whenever
187 changing an option in line with assembly code in order to ensure the user's
188 command-line options are respected for the bulk of the file being assembled.
190 @item rvc
191 @itemx norvc
192 Enables or disables the generation of compressed instructions.  Instructions
193 are opportunistically compressed by the RISC-V assembler when possible, but
194 sometimes this behavior is not desirable, especially when handling alignments.
196 @item pic
197 @itemx nopic
198 Enables or disables position-independent code generation.  Unless you really
199 know what you're doing, this should only be at the top of a file.
201 @item relax
202 @itemx norelax
203 Enables or disables relaxation.  The RISC-V assembler and linker
204 opportunistically relax some code sequences, but sometimes this behavior is not
205 desirable.
207 @item csr-check
208 @itemx no-csr-check
209 Enables or disables the CSR checking.
211 @item arch, @var{+extension[version]} [,...,@var{+extension_n[version_n]}]
212 @itemx arch, @var{-extension} [,...,@var{-extension_n}]
213 @itemx arch, @var{ISA}
214 Enables or disables the extensions for specific code region.  For example,
215 @samp{.option arch, +m2p0} means add m extension with version 2.0, and
216 @samp{.option arch, -f, -d} means remove extensions, f and d, from the
217 architecture string.  Note that, @samp{.option arch, +c, -c} have the same
218 behavior as @samp{.option rvc, norvc}.  However, they are also undesirable
219 sometimes.  Besides, @samp{.option arch, -i} is illegal, since we cannot
220 remove the base i extension anytime.  If you want to reset the whole ISA
221 string, you can also use @samp{.option arch, rv32imac} to overwrite the
222 previous settings.
223 @end table
225 @cindex INSN directives
226 @item .insn @var{type}, @var{operand} [,...,@var{operand_n}]
227 @itemx .insn @var{insn_length}, @var{value}
228 @itemx .insn @var{value}
229 This directive permits the numeric representation of an instructions
230 and makes the assembler insert the operands according to one of the
231 instruction formats for @samp{.insn} (@ref{RISC-V-Formats}).
232 For example, the instruction @samp{add a0, a1, a2} could be written as
233 @samp{.insn r 0x33, 0, 0, a0, a1, a2}.  But in fact, the instruction
234 formats are difficult to use for some users, so most of them are using
235 @samp{.word} to encode the instruction directly, rather than using
236 @samp{.insn}.  It is fine for now, but will be wrong when the mapping
237 symbols are supported, since @samp{.word} will not be shown as an
238 instruction, it should be shown as data.  Therefore, we also support
239 two more formats of the @samp{.insn}, the instruction @samp{add a0, a1, a2}
240 could also be written as @samp{.insn 0x4, 0xc58533} or @samp{.insn 0xc58533}.
241 When the @var{insn_length} is set, then assembler will check if the
242 @var{value} is a valid @var{insn_length} bytes instruction.
244 @cindex @code{.attribute} directive, RISC-V
245 @item .attribute @var{tag}, @var{value}
246 Set the object attribute @var{tag} to @var{value}.
248 The @var{tag} is either an attribute number, or one of the following:
249 @code{Tag_RISCV_arch}, @code{Tag_RISCV_stack_align},
250 @code{Tag_RISCV_unaligned_access}, @code{Tag_RISCV_priv_spec},
251 @code{Tag_RISCV_priv_spec_minor}, @code{Tag_RISCV_priv_spec_revision}.
253 @end table
255 @node RISC-V-Modifiers
256 @section RISC-V Assembler Modifiers
258 The RISC-V assembler supports following modifiers for relocatable addresses
259 used in RISC-V instruction operands.  However, we also support some pseudo
260 instructions that are easier to use than these modifiers.
262 @table @code
263 @item %lo(@var{symbol})
264 The low 12 bits of absolute address for @var{symbol}.
266 @item %hi(@var{symbol})
267 The high 20 bits of absolute address for @var{symbol}.  This is usually
268 used with the %lo modifier to represent a 32-bit absolute address.
270 @smallexample
271         lui        a0, %hi(@var{symbol})     // R_RISCV_HI20
272         addi       a0, a0, %lo(@var{symbol}) // R_RISCV_LO12_I
274         lui        a0, %hi(@var{symbol})     // R_RISCV_HI20
275         load/store a0, %lo(@var{symbol})(a0) // R_RISCV_LO12_I/S
276 @end smallexample
278 @item %pcrel_lo(@var{label})
279 The low 12 bits of relative address between pc and @var{symbol}.
280 The @var{symbol} is related to the high part instruction which is marked
281 by @var{label}.
283 @item %pcrel_hi(@var{symbol})
284 The high 20 bits of relative address between pc and @var{symbol}.
285 This is usually used with the %pcrel_lo modifier to represent a +/-2GB
286 pc-relative range.
288 @smallexample
289 @var{label}:
290         auipc      a0, %pcrel_hi(@var{symbol})    // R_RISCV_PCREL_HI20
291         addi       a0, a0, %pcrel_lo(@var{label}) // R_RISCV_PCREL_LO12_I
293 @var{label}:
294         auipc      a0, %pcrel_hi(@var{symbol})    // R_RISCV_PCREL_HI20
295         load/store a0, %pcrel_lo(@var{label})(a0) // R_RISCV_PCREL_LO12_I/S
296 @end smallexample
298 Or you can use the pseudo lla/lw/sw/... instruction to do this.
300 @smallexample
301         lla  a0, @var{symbol}
302 @end smallexample
304 @item %got_pcrel_hi(@var{symbol})
305 The high 20 bits of relative address between pc and the GOT entry of
306 @var{symbol}.  This is usually used with the %pcrel_lo modifier to access
307 the GOT entry.
309 @smallexample
310 @var{label}:
311         auipc      a0, %got_pcrel_hi(@var{symbol}) // R_RISCV_GOT_HI20
312         addi       a0, a0, %pcrel_lo(@var{label})  // R_RISCV_PCREL_LO12_I
314 @var{label}:
315         auipc      a0, %got_pcrel_hi(@var{symbol}) // R_RISCV_GOT_HI20
316         load/store a0, %pcrel_lo(@var{label})(a0)  // R_RISCV_PCREL_LO12_I/S
317 @end smallexample
319 Also, the pseudo la instruction with PIC has similar behavior.
321 @item %tprel_add(@var{symbol})
322 This is used purely to associate the R_RISCV_TPREL_ADD relocation for
323 TLS relaxation.  This one is only valid as the fourth operand to the normally
324 3 operand add instruction.
326 @item %tprel_lo(@var{symbol})
327 The low 12 bits of relative address between tp and @var{symbol}.
329 @item %tprel_hi(@var{symbol})
330 The high 20 bits of relative address between tp and @var{symbol}.  This is
331 usually used with the %tprel_lo and %tprel_add modifiers to access the thread
332 local variable @var{symbol} in TLS Local Exec.
334 @smallexample
335         lui        a5, %tprel_hi(@var{symbol})          // R_RISCV_TPREL_HI20
336         add        a5, a5, tp, %tprel_add(@var{symbol}) // R_RISCV_TPREL_ADD
337         load/store t0, %tprel_lo(@var{symbol})(a5)      // R_RISCV_TPREL_LO12_I/S
338 @end smallexample
340 @item %tls_ie_pcrel_hi(@var{symbol})
341 The high 20 bits of relative address between pc and GOT entry.  It is
342 usually used with the %pcrel_lo modifier to access the thread local
343 variable @var{symbol} in TLS Initial Exec.
345 @smallexample
346         la.tls.ie  a5, @var{symbol}
347         add        a5, a5, tp
348         load/store t0, 0(a5)
349 @end smallexample
351 The pseudo la.tls.ie instruction can be expended to
353 @smallexample
354 @var{label}:
355         auipc a5, %tls_ie_pcrel_hi(@var{symbol}) // R_RISCV_TLS_GOT_HI20
356         load  a5, %pcrel_lo(@var{label})(a5)     // R_RISCV_PCREL_LO12_I
357 @end smallexample
359 @item %tls_gd_pcrel_hi(@var{symbol})
360 The high 20 bits of relative address between pc and GOT entry.  It is
361 usually used with the %pcrel_lo modifier to access the thread local variable
362 @var{symbol} in TLS Global Dynamic.
364 @smallexample
365         la.tls.gd  a0, @var{symbol}
366         call       __tls_get_addr@@plt
367         mv         a5, a0
368         load/store t0, 0(a5)
369 @end smallexample
371 The pseudo la.tls.gd instruction can be expended to
373 @smallexample
374 @var{label}:
375         auipc a0, %tls_gd_pcrel_hi(@var{symbol}) // R_RISCV_TLS_GD_HI20
376         addi  a0, a0, %pcrel_lo(@var{label})     // R_RISCV_PCREL_LO12_I
377 @end smallexample
379 @end table
381 @node RISC-V-Floating-Point
382 @section RISC-V Floating Point
383 @cindex floating point, risc-v (@sc{ieee})
384 @cindex RISC-V floating point (@sc{ieee})
386 The RISC-V architecture uses @sc{ieee} floating-point numbers.
388 The RISC-V Zfa extension includes a load-immediate instruction
389 for floating-point registers, which allows specifying the immediate
390 (from a pool of 32 predefined values defined in the specification)
391 as operand.
392 E.g. to load the value @code{0.0625} as single-precision FP value into
393 the FP register @code{ft1} one of the following instructions can be used:
395         fli.s ft1, 0.0625 # dec floating-point literal
396         fli.s ft1, 0x1p-4 # hex floating-point literal
397         fli.s ft1, 0x0.8p-3
398         fli.s ft1, 0x1.0p-4
399         fli.s ft1, 0x2p-5
400         fli.s ft1, 0x4p-6
401         ...
403 As can be seen, many valid ways exist to express a floating-point value.
404 This is realized by parsing the value operand using strtof() and
405 comparing the parsed value against built-in float-constants that
406 are written as hex floating-point literals.
408 This approach works on all machines that use IEEE 754.
409 However, there is a chance that this fails on other machines
410 with the following error message:
412         Error: improper fli value operand
413         Error: illegal operands `fli.s ft1,0.0625
415 The error indicates that parsing @samp{0x1p-4} and @samp{0.0625}
416 to single-precision floating point numbers will not result
417 in two equal values on that machine.
419 If you encounter this problem, then please report it.
421 @node RISC-V-Formats
422 @section RISC-V Instruction Formats
423 @cindex instruction formats, risc-v
424 @cindex RISC-V instruction formats
426 The RISC-V Instruction Set Manual Volume I: User-Level ISA lists 15
427 instruction formats where some of the formats have multiple variants.
428 For the @samp{.insn} pseudo directive the assembler recognizes some
429 of the formats.
430 Typically, the most general variant of the instruction format is used
431 by the @samp{.insn} directive.
433 The following table lists the abbreviations used in the table of
434 instruction formats:
436 @display
437 @multitable @columnfractions .15 .40
438 @item opcode7 @tab Unsigned immediate or opcode name for 7-bits opcode.
439 @item opcode2 @tab Unsigned immediate or opcode name for 2-bits opcode.
440 @item func7 @tab Unsigned immediate for 7-bits function code.
441 @item func6 @tab Unsigned immediate for 6-bits function code.
442 @item func4 @tab Unsigned immediate for 4-bits function code.
443 @item func3 @tab Unsigned immediate for 3-bits function code.
444 @item func2 @tab Unsigned immediate for 2-bits function code.
445 @item rd @tab Destination register number for operand x, can be GPR or FPR.
446 @item rd' @tab Destination register number for operand x,
447 only accept s0-s1, a0-a5, fs0-fs1 and fa0-fa5.
448 @item rs1 @tab First source register number for operand x, can be GPR or FPR.
449 @item rs1' @tab First source register number for operand x,
450 only accept s0-s1, a0-a5, fs0-fs1 and fa0-fa5.
451 @item rs2 @tab Second source register number for operand x, can be GPR or FPR.
452 @item rs2' @tab Second source register number for operand x,
453 only accept s0-s1, a0-a5, fs0-fs1 and fa0-fa5.
454 @item simm12 @tab Sign-extended 12-bit immediate for operand x.
455 @item simm20 @tab Sign-extended 20-bit immediate for operand x.
456 @item simm6 @tab Sign-extended 6-bit immediate for operand x.
457 @item uimm5 @tab Unsigned 5-bit immediate for operand x.
458 @item uimm6 @tab Unsigned 6-bit immediate for operand x.
459 @item uimm8 @tab Unsigned 8-bit immediate for operand x.
460 @item symbol @tab Symbol or label reference for operand x.
461 @end multitable
462 @end display
464 The following table lists all available opcode name:
466 @table @code
467 @item C0
468 @item C1
469 @item C2
470 Opcode space for compressed instructions.
472 @item LOAD
473 Opcode space for load instructions.
475 @item LOAD_FP
476 Opcode space for floating-point load instructions.
478 @item STORE
479 Opcode space for store instructions.
481 @item STORE_FP
482 Opcode space for floating-point store instructions.
484 @item AUIPC
485 Opcode space for auipc instruction.
487 @item LUI
488 Opcode space for lui instruction.
490 @item BRANCH
491 Opcode space for branch instructions.
493 @item JAL
494 Opcode space for jal instruction.
496 @item JALR
497 Opcode space for jalr instruction.
499 @item OP
500 Opcode space for ALU instructions.
502 @item OP_32
503 Opcode space for 32-bits ALU instructions.
505 @item OP_IMM
506 Opcode space for ALU with immediate instructions.
508 @item OP_IMM_32
509 Opcode space for 32-bits ALU with immediate instructions.
511 @item OP_FP
512 Opcode space for floating-point operation instructions.
514 @item MADD
515 Opcode space for madd instruction.
517 @item MSUB
518 Opcode space for msub instruction.
520 @item NMADD
521 Opcode space for nmadd instruction.
523 @item NMSUB
524 Opcode space for msub instruction.
526 @item AMO
527 Opcode space for atomic memory operation instructions.
529 @item MISC_MEM
530 Opcode space for misc instructions.
532 @item SYSTEM
533 Opcode space for system instructions.
535 @item CUSTOM_0
536 @item CUSTOM_1
537 @item CUSTOM_2
538 @item CUSTOM_3
539 Opcode space for customize instructions.
541 @end table
543 An instruction is two or four bytes in length and must be aligned
544 on a 2 byte boundary. The first two bits of the instruction specify the
545 length of the instruction, 00, 01 and 10 indicates a two byte instruction,
546 11 indicates a four byte instruction.
548 The following table lists the RISC-V instruction formats that are available
549 with the @samp{.insn} pseudo directive:
551 @table @code
552 @item R type: .insn r opcode7, func3, func7, rd, rs1, rs2
553 @verbatim
554 +-------+-----+-----+-------+----+---------+
555 | func7 | rs2 | rs1 | func3 | rd | opcode7 |
556 +-------+-----+-----+-------+----+---------+
557 31      25    20    15      12   7        0
558 @end verbatim
560 @item R type with 4 register operands: .insn r opcode7, func3, func2, rd, rs1, rs2, rs3
561 @itemx R4 type: .insn r4 opcode7, func3, func2, rd, rs1, rs2, rs3
562 @verbatim
563 +-----+-------+-----+-----+-------+----+---------+
564 | rs3 | func2 | rs2 | rs1 | func3 | rd | opcode7 |
565 +-----+-------+-----+-----+-------+----+---------+
566 31    27      25    20    15      12   7         0
567 @end verbatim
569 @item I type: .insn i opcode7, func3, rd, rs1, simm12
570 @itemx I type: .insn i opcode7, func3, rd, simm12(rs1)
571 @verbatim
572 +--------------+-----+-------+----+---------+
573 | simm12[11:0] | rs1 | func3 | rd | opcode7 |
574 +--------------+-----+-------+----+---------+
575 31             20    15      12   7         0
576 @end verbatim
578 @item S type: .insn s opcode7, func3, rs2, simm12(rs1)
579 @verbatim
580 +--------------+-----+-----+-------+-------------+---------+
581 | simm12[11:5] | rs2 | rs1 | func3 | simm12[4:0] | opcode7 |
582 +--------------+-----+-----+-------+-------------+---------+
583 31             25    20    15      12            7         0
584 @end verbatim
586 @item B type: .insn s opcode7, func3, rs1, rs2, symbol
587 @itemx SB type: .insn sb opcode7, func3, rs1, rs2, symbol
588 @verbatim
589 +-----------------+-----+-----+-------+----------------+---------+
590 | simm12[12|10:5] | rs2 | rs1 | func3 | simm12[4:1|11] | opcode7 |
591 +-----------------+-----+-----+-------+----------------+---------+
592 31                25    20    15      12               7         0
593 @end verbatim
595 @item U type: .insn u opcode7, rd, simm20
596 @verbatim
597 +--------------+----+---------+
598 | simm20[19:0] | rd | opcode7 |
599 +--------------+----+---------+
600 31             12   7         0
601 @end verbatim
603 @item J type: .insn j opcode7, rd, symbol
604 @itemx UJ type: .insn uj opcode7, rd, symbol
605 @verbatim
606 +------------+--------------+------------+---------------+----+---------+
607 | simm20[20] | simm20[10:1] | simm20[11] | simm20[19:12] | rd | opcode7 |
608 +------------+--------------+------------+---------------+----+---------+
609 31           30             21           20              12   7         0
610 @end verbatim
612 @item CR type: .insn cr opcode2, func4, rd, rs2
613 @verbatim
614 +-------+--------+-----+---------+
615 | func4 | rd/rs1 | rs2 | opcode2 |
616 +-------+--------+-----+---------+
617 15      12       7     2        0
618 @end verbatim
620 @item CI type: .insn ci opcode2, func3, rd, simm6
621 @verbatim
622 +-------+----------+--------+------------+---------+
623 | func3 | simm6[5] | rd/rs1 | simm6[4:0] | opcode2 |
624 +-------+----------+--------+------------+---------+
625 15      13         12       7            2         0
626 @end verbatim
628 @item CIW type: .insn ciw opcode2, func3, rd', uimm8
629 @verbatim
630 +-------+------------+-----+---------+
631 | func3 | uimm8[7:0] | rd' | opcode2 |
632 +-------+-------- ---+-----+---------+
633 15      13           5     2         0
634 @end verbatim
636 @item CSS type: .insn css opcode2, func3, rd, uimm6
637 @verbatim
638 +-------+------------+----+---------+
639 | func3 | uimm6[5:0] | rd | opcode2 |
640 +-------+------------+----+---------+
641 15      13           7    2         0
642 @end verbatim
644 @item CL type: .insn cl opcode2, func3, rd', uimm5(rs1')
645 @verbatim
646 +-------+------------+------+------------+------+---------+
647 | func3 | uimm5[4:2] | rs1' | uimm5[1:0] |  rd' | opcode2 |
648 +-------+------------+------+------------+------+---------+
649 15      13           10     7            5      2         0
650 @end verbatim
652 @item CS type: .insn cs opcode2, func3, rs2', uimm5(rs1')
653 @verbatim
654 +-------+------------+------+------------+------+---------+
655 | func3 | uimm5[4:2] | rs1' | uimm5[1:0] | rs2' | opcode2 |
656 +-------+------------+------+------------+------+---------+
657 15      13           10     7            5      2         0
658 @end verbatim
660 @item CA type: .insn ca opcode2, func6, func2, rd', rs2'
661 @verbatim
662 +-- ----+----------+-------+------+---------+
663 | func6 | rd'/rs1' | func2 | rs2' | opcode2 |
664 +-------+----------+-------+------+---------+
665 15      10         7       5      2         0
666 @end verbatim
668 @item CB type: .insn cb opcode2, func3, rs1', symbol
669 @verbatim
670 +-------+--------------+------+------------------+---------+
671 | func3 | simm8[8|4:3] | rs1' | simm8[7:6|2:1|5] | opcode2 |
672 +-------+--------------+------+------------------+---------+
673 15      13             10     7                  2         0
674 @end verbatim
676 @item CJ type: .insn cj opcode2, func3, symbol
677 @verbatim
678 +-------+-------------------------------+---------+
679 | func3 | simm11[11|4|9:8|10|6|7|3:1|5] | opcode2 |
680 +-------+-------------------------------+---------+
681 15      13                              2         0
682 @end verbatim
685 @end table
687 For the complete list of all instruction format variants see
688 The RISC-V Instruction Set Manual Volume I: User-Level ISA.
690 @node RISC-V-ATTRIBUTE
691 @section RISC-V Object Attribute
692 @cindex Object Attribute, RISC-V
694 RISC-V attributes have a string value if the tag number is odd and an integer
695 value if the tag number is even.
697 @table @r
698 @item Tag_RISCV_stack_align (4)
699 Tag_RISCV_strict_align records the N-byte stack alignment for this object.  The
700 default value is 16 for RV32I or RV64I, and 4 for RV32E.
702 The smallest value will be used if object files with different
703 Tag_RISCV_stack_align values are merged.
705 @item Tag_RISCV_arch (5)
706 Tag_RISCV_arch contains a string for the target architecture taken from the
707 option @option{-march}.  Different architectures will be integrated into a
708 superset when object files are merged.
710 Note that the version information of the target architecture must be presented
711 explicitly in the attribute and abbreviations must be expanded.  The version
712 information, if not given by @option{-march}, must be in accordance with the
713 default specified by the tool.  For example, the architecture @code{RV32I} has
714 to be recorded in the attribute as @code{RV32I2P0} in which @code{2P0} stands
715 for the default version of its base ISA.  On the other hand, the architecture
716 @code{RV32G} has to be presented as @code{RV32I2P0_M2P0_A2P0_F2P0_D2P0} in
717 which the abbreviation @code{G} is expanded to the @code{IMAFD} combination
718 with default versions of the standard extensions.
720 @item Tag_RISCV_unaligned_access (6)
721 Tag_RISCV_unaligned_access is 0 for files that do not allow any unaligned
722 memory accesses, and 1 for files that do allow unaligned memory accesses.
724 @item Tag_RISCV_priv_spec (8)
725 @item Tag_RISCV_priv_spec_minor (10)
726 @item Tag_RISCV_priv_spec_revision (12)
727 Tag_RISCV_priv_spec contains the major/minor/revision version information of
728 the privileged specification.  It will report errors if object files of
729 different privileged specification versions are merged.
731 @end table
733 @node RISC-V-CustomExts
734 @section RISC-V Custom (Vendor-Defined) Extensions
735 @cindex custom (vendor-defined) extensions, RISC-V
736 @cindex RISC-V custom (vendor-defined) extensions
738 The following table lists the custom (vendor-defined) RISC-V
739 extensions supported and provides the location of their
740 publicly-released documentation:
742 @table @r
743 @item XCvMac
744 The XCvMac extension provides instructions for multiply-accumulate operations.
746 It is documented in @url{https://docs.openhwgroup.org/projects/cv32e40p-user-manual/en/latest/instruction_set_extensions.html}
748 @item XCvAlu
749 The XCvAlu extension provides instructions for general ALU operations.
751 It is documented in @url{https://docs.openhwgroup.org/projects/cv32e40p-user-manual/en/latest/instruction_set_extensions.html}
753 @item XCvElw
754 The XCvElw extension provides instructions for event load word operations.
756 It is documented in @url{https://docs.openhwgroup.org/projects/cv32e40p-user-manual/en/latest/instruction_set_extensions.html}
758 @item XCvBi
759 The XCvBi extension provides instructions for branch immediate operations.
761 It is documented in @url{https://docs.openhwgroup.org/projects/cv32e40p-user-manual/en/latest/instruction_set_extensions.html}
763 @item XCvMem
764 The XCvMem extension provides instructions for post inc load/store operations.
766 It is documented in @url{https://docs.openhwgroup.org/projects/cv32e40p-user-manual/en/latest/instruction_set_extensions.html}
768 @item XTheadBa
769 The XTheadBa extension provides instructions for address calculations.
771 It is documented in @url{https://github.com/T-head-Semi/thead-extension-spec/releases/download/2.0.0/xthead-2022-09-05-2.0.0.pdf}.
773 @item XTheadBb
774 The XTheadBb extension provides instructions for basic bit-manipulation
776 It is documented in @url{https://github.com/T-head-Semi/thead-extension-spec/releases/download/2.0.0/xthead-2022-09-05-2.0.0.pdf}.
778 @item XTheadBs
779 The XTheadBs extension provides single-bit instructions.
781 It is documented in @url{https://github.com/T-head-Semi/thead-extension-spec/releases/download/2.0.0/xthead-2022-09-05-2.0.0.pdf}.
783 @item XTheadCmo
784 The XTheadCmo extension provides instructions for cache management.
786 It is documented in @url{https://github.com/T-head-Semi/thead-extension-spec/releases/download/2.0.0/xthead-2022-09-05-2.0.0.pdf}.
788 @item XTheadCondMov
789 The XTheadCondMov extension provides instructions for conditional moves.
791 It is documented in @url{https://github.com/T-head-Semi/thead-extension-spec/releases/download/2.0.0/xthead-2022-09-05-2.0.0.pdf}.
793 @item XTheadFMemIdx
794 The XTheadFMemIdx extension provides floating-point memory operations.
796 It is documented in @url{https://github.com/T-head-Semi/thead-extension-spec/releases/download/2.0.0/xthead-2022-09-05-2.0.0.pdf}.
798 @item XTheadFmv
799 The XTheadFmv extension provides access to the upper 32 bits of a doulbe-precision floating point register.
801 It is documented in @url{https://github.com/T-head-Semi/thead-extension-spec/releases/download/2.1.0/xthead-2022-11-07-2.1.0.pdf}.
803 @item XTheadInt
804 The XTheadInt extension provides access to ISR stack management instructions.
806 It is documented in @url{https://github.com/T-head-Semi/thead-extension-spec/releases/download/2.1.0/xthead-2022-11-07-2.1.0.pdf}.
808 @item XTheadMac
809 The XTheadMac extension provides multiply-accumulate instructions.
811 It is documented in @url{https://github.com/T-head-Semi/thead-extension-spec/releases/download/2.0.0/xthead-2022-09-05-2.0.0.pdf}.
813 @item XTheadMemIdx
814 The XTheadMemIdx extension provides GPR memory operations.
816 It is documented in @url{https://github.com/T-head-Semi/thead-extension-spec/releases/download/2.0.0/xthead-2022-09-05-2.0.0.pdf}.
818 @item XTheadMemPair
819 The XTheadMemPair extension provides two-GP-register memory operations.
821 It is documented in @url{https://github.com/T-head-Semi/thead-extension-spec/releases/download/2.0.0/xthead-2022-09-05-2.0.0.pdf}.
823 @item XTheadSync
824 The XTheadSync extension provides instructions for multi-processor synchronization.
826 It is documented in @url{https://github.com/T-head-Semi/thead-extension-spec/releases/download/2.0.0/xthead-2022-09-05-2.0.0.pdf}.
828 @item XTheadVector
829 The XTheadVector extension provides instructions for thead vector.
831 It is documented in @url{https://github.com/T-head-Semi/thead-extension-spec/releases/download/2.3.0/xthead-2023-11-10-2.3.0.pdf}.
833 @item XTheadZvamo
834 The XTheadZvamo extension is a subextension of the XTheadVector extension,
835 and it provides AMO instructions for the T-Head VECTOR vendor extension.
837 It is documented in @url{https://github.com/T-head-Semi/thead-extension-spec/releases/download/2.3.0/xthead-2023-11-10-2.3.0.pdf}.
839 @item XVentanaCondOps
840 XVentanaCondOps extension provides instructions for branchless
841 sequences that perform conditional arithmetic, conditional
842 bitwise-logic, and conditional select operations.
844 It is documented in @url{https://github.com/ventanamicro/ventana-custom-extensions/releases/download/v1.0.0/ventana-custom-extensions-v1.0.0.pdf}.
846 @item XSfVcp
847 The XSfVcp (VCIX) extension provides flexible instructions for extending
848 vector coprocessor.  To accelerate performance, system designers may use
849 VCIX as a low-latency, high-throughput interface to a coprocessor.
851 It is documented in @url{https://sifive.cdn.prismic.io/sifive/c3829e36-8552-41f0-a841-79945784241b_vcix-spec-software.pdf}.
853 @item XSfCease
854 XSfCease provides an instruction to instigates power-down sequence.
856 It is documented in @url{https://sifive.cdn.prismic.io/sifive/767804da-53b2-4893-97d5-b7c030ae0a94_s76mc_core_complex_manual_21G3.pdf}.
858 @end table