1 @c Copyright (C) 2016-2018 Free Software Foundation, Inc.
2 @c This is part of the GAS anual.
3 @c For copying conditions, see the file as.texinfo
9 @chapter RISC-V Dependent Features
12 @node Machine Dependencies
13 @chapter RISC-V Dependent Features
16 @cindex RISC-V support
18 * RISC-V-Options:: RISC-V Options
19 * RISC-V-Directives:: RISC-V Directives
20 * RISC-V-Formats:: RISC-V Instruction Formats
24 @section RISC-V Options
26 The following table lists all available RISC-V specific options.
31 @cindex @samp{-fpic} option, RISC-V
34 Generate position-independent code
36 @cindex @samp{-fno-pic} option, RISC-V
38 Don't generate position-independent code (default)
40 @cindex @samp{-march=ISA} option, RISC-V
42 Select the base isa, as specified by ISA. For example -march=rv32ima.
44 @cindex @samp{-mabi=ABI} option, RISC-V
46 Selects the ABI, which is either "ilp32" or "lp64", optionally followed
47 by "f", "d", or "q" to indicate single-precision, double-precision, or
48 quad-precision floating-point calling convention, or none to indicate
49 the soft-float calling convention. Also, "ilp32" can optionally be followed
50 by "e" to indicate the RVE ABI, which is always soft-float.
52 @cindex @samp{-mrelax} option, RISC-V
54 Take advantage of linker relaxations to reduce the number of instructions
55 required to materialize symbol addresses. (default)
57 @cindex @samp{-mno-relax} option, RISC-V
59 Don't do linker relaxations.
64 @node RISC-V-Directives
65 @section RISC-V Directives
66 @cindex machine directives, RISC-V
67 @cindex RISC-V machine directives
69 The following table lists all available RISC-V specific directives.
73 @cindex @code{align} directive
74 @item .align @var{size-log-2}
75 Align to the given boundary, with the size given as log2 the number of bytes to
78 @cindex Data directives
79 @item .half @var{value}
80 @itemx .word @var{value}
81 @itemx .dword @var{value}
82 Emits a half-word, word, or double-word value at the current position.
84 @cindex DTP-relative data directives
85 @item .dtprelword @var{value}
86 @itemx .dtpreldword @var{value}
87 Emits a DTP-relative word (or double-word) at the current position. This is
88 meant to be used by the compiler in shared libraries for DWARF debug info for
89 thread local variables.
93 Sets the current section to the BSS section.
95 @cindex LEB128 directives
96 @item .uleb128 @var{value}
97 @itemx .sleb128 @var{value}
98 Emits a signed or unsigned LEB128 value at the current position. This only
99 accepts constant expressions, because symbol addresses can change with
100 relaxation, and we don't support relocations to modify LEB128 values at link
103 @cindex Option directive
104 @cindex @code{option} directive
105 @item .option @var{argument}
106 Modifies RISC-V specific assembler options inline with the assembly code.
107 This is used when particular instruction sequences must be assembled with a
108 specific set of options. For example, since we relax addressing sequences to
109 shorter GP-relative sequences when possible the initial load of GP must not be
110 relaxed and should be emitted as something like
115 la gp, __global_pointer$
119 in order to produce after linker relaxation the expected
122 auipc gp, %pcrel_hi(__global_pointer$)
123 addi gp, gp, %pcrel_lo(__global_pointer$)
132 It's not expected that options are changed in this manner during regular use,
133 but there are a handful of esoteric cases like the one above where users need
134 to disable particular features of the assembler for particular code sequences.
135 The complete list of option arguments is shown below:
140 Pushes or pops the current option stack. These should be used whenever
141 changing an option in line with assembly code in order to ensure the user's
142 command-line options are respected for the bulk of the file being assembled.
146 Enables or disables the generation of compressed instructions. Instructions
147 are opportunistically compressed by the RISC-V assembler when possible, but
148 sometimes this behavior is not desirable.
152 Enables or disables position-independent code generation. Unless you really
153 know what you're doing, this should only be at the top of a file.
157 Enables or disables relaxation. The RISC-V assembler and linker
158 opportunistically relax some code sequences, but sometimes this behavior is not
162 @cindex INSN directives
163 @item .insn @var{value}
164 @itemx .insn @var{value}
165 This directive permits the numeric representation of an instructions
166 and makes the assembler insert the operands according to one of the
167 instruction formats for @samp{.insn} (@ref{RISC-V-Formats}).
168 For example, the instruction @samp{add a0, a1, a2} could be written as
169 @samp{.insn r 0x33, 0, 0, a0, a1, a2}.
174 @section Instruction Formats
175 @cindex instruction formats, risc-v
176 @cindex RISC-V instruction formats
178 The RISC-V Instruction Set Manual Volume I: User-Level ISA lists 12
179 instruction formats where some of the formats have multiple variants.
180 For the @samp{.insn} pseudo directive the assembler recognizes some
182 Typically, the most general variant of the instruction format is used
183 by the @samp{.insn} directive.
185 The following table lists the abbreviations used in the table of
189 @multitable @columnfractions .15 .40
190 @item opcode @tab Unsigned immediate or opcode name for 7-bits opcode.
191 @item opcode2 @tab Unsigned immediate or opcode name for 2-bits opcode.
192 @item func7 @tab Unsigned immediate for 7-bits function code.
193 @item func4 @tab Unsigned immediate for 4-bits function code.
194 @item func3 @tab Unsigned immediate for 3-bits function code.
195 @item func2 @tab Unsigned immediate for 2-bits function code.
196 @item rd @tab Destination register number for operand x, can be GPR or FPR.
197 @item rd' @tab Destination register number for operand x,
198 only accept s0-s1, a0-a5, fs0-fs1 and fa0-fa5.
199 @item rs1 @tab First source register number for operand x, can be GPR or FPR.
200 @item rs1' @tab First source register number for operand x,
201 only accept s0-s1, a0-a5, fs0-fs1 and fa0-fa5.
202 @item rs2 @tab Second source register number for operand x, can be GPR or FPR.
203 @item rs2' @tab Second source register number for operand x,
204 only accept s0-s1, a0-a5, fs0-fs1 and fa0-fa5.
205 @item simm12 @tab Sign-extended 12-bit immediate for operand x.
206 @item simm20 @tab Sign-extended 20-bit immediate for operand x.
207 @item simm6 @tab Sign-extended 6-bit immediate for operand x.
208 @item uimm8 @tab Unsigned 8-bit immediate for operand x.
209 @item symbol @tab Symbol or lable reference for operand x.
213 The following table lists all available opcode name:
219 Opcode space for compressed instructions.
222 Opcode space for load instructions.
225 Opcode space for floating-point load instructions.
228 Opcode space for store instructions.
231 Opcode space for floating-point store instructions.
234 Opcode space for auipc instruction.
237 Opcode space for lui instruction.
240 Opcode space for branch instructions.
243 Opcode space for jal instruction.
246 Opcode space for jalr instruction.
249 Opcode space for ALU instructions.
252 Opcode space for 32-bits ALU instructions.
255 Opcode space for ALU with immediate instructions.
258 Opcode space for 32-bits ALU with immediate instructions.
261 Opcode space for floating-point operation instructions.
264 Opcode space for madd instruction.
267 Opcode space for msub instruction.
270 Opcode space for nmadd instruction.
273 Opcode space for msub instruction.
276 Opcode space for atomic memory operation instructions.
279 Opcode space for misc instructions.
282 Opcode space for system instructions.
288 Opcode space for customize instructions.
292 An instruction is two or four bytes in length and must be aligned
293 on a 2 byte boundary. The first two bits of the instruction specify the
294 length of the instruction, 00, 01 and 10 indicates a two byte instruction,
295 11 indicates a four byte instruction.
297 The following table lists the RISC-V instruction formats that are available
298 with the @samp{.insn} pseudo directive:
301 @item R type: .insn r opcode, func3, func7, rd, rs1, rs2
303 +-------+-----+-----+-------+----+-------------+
304 | func7 | rs2 | rs1 | func3 | rd | opcode |
305 +-------+-----+-----+-------+----+-------------+
309 @item R type with 4 register operands: .insn r opcode, func3, func2, rd, rs1, rs2, rs3
311 +-----+-------+-----+-----+-------+----+-------------+
312 | rs3 | func2 | rs2 | rs1 | func3 | rd | opcode |
313 +-----+-------+-----+-----+-------+----+-------------+
314 31 27 25 20 15 12 7 0
317 @item I type: .insn i opcode, func3, rd, rs1, simm12
319 +-------------+-----+-------+----+-------------+
320 | simm12 | rs1 | func3 | rd | opcode |
321 +-------------+-----+-------+----+-------------+
325 @item S type: .insn s opcode, func3, rd, rs1, simm12
327 +--------------+-----+-----+-------+-------------+-------------+
328 | simm12[11:5] | rs2 | rs1 | func3 | simm12[4:0] | opcode |
329 +--------------+-----+-----+-------+-------------+-------------+
333 @item SB type: .insn sb opcode, func3, rd, rs1, symbol
334 @itemx SB type: .insn sb opcode, func3, rd, simm12(rs1)
336 +--------------+-----+-----+-------+-------------+-------------+
337 | simm21[11:5] | rs2 | rs1 | func3 | simm12[4:0] | opcode |
338 +--------------+-----+-----+-------+-------------+-------------+
342 @item U type: .insn u opcode, rd, simm20
344 +---------------------------+----+-------------+
345 | simm20 | rd | opcode |
346 +---------------------------+----+-------------+
350 @item UJ type: .insn uj opcode, rd, symbol
352 +------------+--------------+------------+---------------+----+-------------+
353 | simm20[20] | simm20[10:1] | simm20[11] | simm20[19:12] | rd | opcode |
354 +------------+--------------+------------+---------------+----+-------------+
358 @item CR type: .insn cr opcode2, func4, rd, rs1
360 +---------+--------+-----+---------+
361 | func4 | rd/rs1 | rs2 | opcode2 |
362 +---------+--------+-----+---------+
366 @item CI type: .insn ci opcode2, func3, rd, simm6
368 +---------+-----+--------+-----+---------+
369 | func3 | imm | rd/rs1 | imm | opcode2 |
370 +---------+-----+--------+-----+---------+
374 @item CIW type: .insn ciw opcode2, func3, rd, uimm8
376 +---------+--------------+-----+---------+
377 | func3 | imm | rd' | opcode2 |
378 +---------+--------------+-----+---------+
382 @item CB type: .insn cb opcode2, func3, rs1, symbol
384 +---------+--------+------+--------+---------+
385 | func3 | offset | rs1' | offset | opcode2 |
386 +---------+--------+------+--------+---------+
390 @item CJ type: .insn cj opcode2, symbol
392 +---------+--------------------+---------+
393 | func3 | jump target | opcode2 |
394 +---------+--------------------+---------+
401 For the complete list of all instruction format variants see
402 The RISC-V Instruction Set Manual Volume I: User-Level ISA.