RISC-V: Add .insn support.
[deliverable/binutils-gdb.git] / gas / doc / c-riscv.texi
CommitLineData
219d1afa 1@c Copyright (C) 2016-2018 Free Software Foundation, Inc.
e23eba97
NC
2@c This is part of the GAS anual.
3@c For copying conditions, see the file as.texinfo
4@c man end
5
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
15
16@cindex RISC-V support
17@menu
b57e49f7
JW
18* RISC-V-Options:: RISC-V Options
19* RISC-V-Directives:: RISC-V Directives
0e35537d 20* RISC-V-Formats:: RISC-V Instruction Formats
e23eba97
NC
21@end menu
22
b57e49f7
JW
23@node RISC-V-Options
24@section RISC-V Options
e23eba97 25
b57e49f7 26The following table lists all available RISC-V specific options.
e23eba97
NC
27
28@c man begin OPTIONS
29@table @gcctabopt
e23eba97 30
19683c04
PD
31@cindex @samp{-fpic} option, RISC-V
32@item -fpic
b57e49f7 33@itemx -fPIC
19683c04
PD
34Generate position-independent code
35
36@cindex @samp{-fno-pic} option, RISC-V
37@item -fno-pic
38Don't generate position-independent code (default)
39
4f7eddc4
PD
40@cindex @samp{-march=ISA} option, RISC-V
41@item -march=ISA
2922d21d
AW
42Select the base isa, as specified by ISA. For example -march=rv32ima.
43
44@cindex @samp{-mabi=ABI} option, RISC-V
45@item -mabi=ABI
46Selects the ABI, which is either "ilp32" or "lp64", optionally followed
47by "f", "d", or "q" to indicate single-precision, double-precision, or
48quad-precision floating-point calling convention, or none to indicate
49the soft-float calling convention.
e23eba97
NC
50
51@end table
52@c man end
b57e49f7
JW
53
54@node RISC-V-Directives
fed44c60 55@section RISC-V Directives
b57e49f7
JW
56@cindex machine directives, RISC-V
57@cindex RISC-V machine directives
58
b57e49f7
JW
59The following table lists all available RISC-V specific directives.
60
61@table @code
62
63@cindex @code{align} directive
64@item .align @var{size-log-2}
65Align to the given boundary, with the size given as log2 the number of bytes to
66align to.
67
68@cindex Data directives
69@item .half @var{value}
70@itemx .word @var{value}
71@itemx .dword @var{value}
72Emits a half-word, word, or double-word value at the current position.
73
74@cindex DTP-relative data directives
75@item .dtprelword @var{value}
76@itemx .dtpreldword @var{value}
77Emits a DTP-relative word (or double-word) at the current position. This is
78meant to be used by the compiler in shared libraries for DWARF debug info for
79thread local variables.
80
81@cindex BSS directive
82@item .bss
83Sets the current section to the BSS section.
84
85@cindex LEB128 directives
86@item .uleb128 @var{value}
87@itemx .sleb128 @var{value}
88Emits a signed or unsigned LEB128 value at the current position. This only
89accepts constant expressions, because symbol addresses can change with
90relaxation, and we don't support relocations to modify LEB128 values at link
91time.
92
93@cindex Option directive
94@cindex @code{option} directive
95@item .option @var{argument}
96Modifies RISC-V specific assembler options inline with the assembly code.
97This is used when particular instruction sequences must be assembled with a
98specific set of options. For example, since we relax addressing sequences to
99shorter GP-relative sequences when possible the initial load of GP must not be
100relaxed and should be emitted as something like
101
102@smallexample
103 .option push
104 .option norelax
105 la gp, __global_pointer$
106 .option pop
107@end smallexample
108
109in order to produce after linker relaxation the expected
110
111@smallexample
112 auipc gp, %pcrel_hi(__global_pointer$)
113 addi gp, gp, %pcrel_lo(__global_pointer$)
114@end smallexample
115
116instead of just
117
118@smallexample
119 addi gp, gp, 0
120@end smallexample
121
122It's not expected that options are changed in this manner during regular use,
123but there are a handful of esoteric cases like the one above where users need
124to disable particular features of the assembler for particular code sequences.
125The complete list of option arguments is shown below:
126
127@table @code
128@item push
129@itemx pop
130Pushes or pops the current option stack. These should be used whenever
131changing an option in line with assembly code in order to ensure the user's
132command-line options are respected for the bulk of the file being assembled.
133
134@item rvc
135@itemx norvc
136Enables or disables the generation of compressed instructions. Instructions
137are opportunistically compressed by the RISC-V assembler when possible, but
138sometimes this behavior is not desirable.
139
140@item pic
141@itemx nopic
142Enables or disables position-independent code generation. Unless you really
143know what you're doing, this should only be at the top of a file.
144
145@item relax
146@itemx norelax
147Enables or disables relaxation. The RISC-V assembler and linker
148opportunistically relax some code sequences, but sometimes this behavior is not
149desirable.
150@end table
151
0e35537d
JW
152@cindex INSN directives
153@item .insn @var{value}
154@itemx .insn @var{value}
155This directive permits the numeric representation of an instructions
156and makes the assembler insert the operands according to one of the
157instruction formats for @samp{.insn} (@ref{RISC-V-Formats}).
158For example, the instruction @samp{add a0, a1, a2} could be written as
159@samp{.insn r 0x33, 0, 0, a0, a1, a2}.
160
b57e49f7 161@end table
0e35537d
JW
162
163@node RISC-V-Formats
164@section Instruction Formats
165@cindex instruction formats, risc-v
166@cindex RISC-V instruction formats
167
168The RISC-V Instruction Set Manual Volume I: User-Level ISA lists 12
169instruction formats where some of the formats have multiple variants.
170For the @samp{.insn} pseudo directive the assembler recognizes some
171of the formats.
172Typically, the most general variant of the instruction format is used
173by the @samp{.insn} directive.
174
175The following table lists the abbreviations used in the table of
176instruction formats:
177
178@display
179@multitable @columnfractions .15 .40
180@item opcode @tab Unsigned immediate or opcode name for 7-bits opcode.
181@item opcode2 @tab Unsigned immediate or opcode name for 2-bits opcode.
182@item func7 @tab Unsigned immediate for 7-bits function code.
183@item func4 @tab Unsigned immediate for 4-bits function code.
184@item func3 @tab Unsigned immediate for 3-bits function code.
185@item func2 @tab Unsigned immediate for 2-bits function code.
186@item rd @tab Destination register number for operand x, can be GPR or FPR.
187@item rd' @tab Destination register number for operand x,
188only accept s0-s1, a0-a5, fs0-fs1 and fa0-fa5.
189@item rs1 @tab First source register number for operand x, can be GPR or FPR.
190@item rs1' @tab First source register number for operand x,
191only accept s0-s1, a0-a5, fs0-fs1 and fa0-fa5.
192@item rs2 @tab Second source register number for operand x, can be GPR or FPR.
193@item rs2' @tab Second source register number for operand x,
194only accept s0-s1, a0-a5, fs0-fs1 and fa0-fa5.
195@item simm12 @tab Sign-extended 12-bit immediate for operand x.
196@item simm20 @tab Sign-extended 20-bit immediate for operand x.
197@item simm6 @tab Sign-extended 6-bit immediate for operand x.
198@item uimm8 @tab Unsigned 8-bit immediate for operand x.
199@item symbol @tab Symbol or lable reference for operand x.
200@end multitable
201@end display
202
203The following table lists all available opcode name:
204
205@table @code
206@item C0
207@item C1
208@item C2
209Opcode space for compressed instructions.
210
211@item LOAD
212Opcode space for load instructions.
213
214@item LOAD_FP
215Opcode space for floating-point load instructions.
216
217@item STORE
218Opcode space for store instructions.
219
220@item STORE_FP
221Opcode space for floating-point store instructions.
222
223@item AUIPC
224Opcode space for auipc instruction.
225
226@item LUI
227Opcode space for lui instruction.
228
229@item BRANCH
230Opcode space for branch instructions.
231
232@item JAL
233Opcode space for jal instruction.
234
235@item JALR
236Opcode space for jalr instruction.
237
238@item OP
239Opcode space for ALU instructions.
240
241@item OP_32
242Opcode space for 32-bits ALU instructions.
243
244@item OP_IMM
245Opcode space for ALU with immediate instructions.
246
247@item OP_IMM_32
248Opcode space for 32-bits ALU with immediate instructions.
249
250@item OP_FP
251Opcode space for floating-point operation instructions.
252
253@item MADD
254Opcode space for madd instruction.
255
256@item MSUB
257Opcode space for msub instruction.
258
259@item NMADD
260Opcode space for nmadd instruction.
261
262@item NMSUB
263Opcode space for msub instruction.
264
265@item AMO
266Opcode space for atomic memory operation instructions.
267
268@item MISC_IMM
269Opcode space for misc instructions.
270
271@item SYSTEM
272Opcode space for system instructions.
273
274@item CUSTOM_0
275@item CUSTOM_1
276@item CUSTOM_2
277@item CUSTOM_3
278Opcode space for customize instructions.
279
280@end table
281
282An instruction is two or four bytes in length and must be aligned
283on a 2 byte boundary. The first two bits of the instruction specify the
284length of the instruction, 00, 01 and 10 indicates a two byte instruction,
28511 indicates a four byte instruction.
286
287The following table lists the RISC-V instruction formats that are available
288with the @samp{.insn} pseudo directive:
289
290@table @code
291@item R type: .insn r opcode, func3, func7, rd, rs1, rs2
292@verbatim
293+-------+-----+-----+-------+----+-------------+
294| func7 | rs2 | rs1 | func3 | rd | opcode |
295+-------+-----+-----+-------+----+-------------+
29631 25 20 15 12 7 0
297@end verbatim
298
299@item R type with 4 register operands: .insn r opcode, func3, func2, rd, rs1, rs2, rs3
300@verbatim
301+-----+-------+-----+-----+-------+----+-------------+
302| rs3 | func2 | rs2 | rs1 | func3 | rd | opcode |
303+-----+-------+-----+-----+-------+----+-------------+
30431 27 25 20 15 12 7 0
305@end verbatim
306
307@item I type: .insn i opcode, func3, rd, rs1, simm12
308@verbatim
309+-------------+-----+-------+----+-------------+
310| simm12 | rs1 | func3 | rd | opcode |
311+-------------+-----+-------+----+-------------+
31231 20 15 12 7 0
313@end verbatim
314
315@item S type: .insn s opcode, func3, rd, rs1, simm12
316@verbatim
317+--------------+-----+-----+-------+-------------+-------------+
318| simm12[11:5] | rs2 | rs1 | func3 | simm12[4:0] | opcode |
319+--------------+-----+-----+-------+-------------+-------------+
32031 25 20 15 12 7 0
321@end verbatim
322
323@item SB type: .insn sb opcode, func3, rd, rs1, symbol
324@itemx SB type: .insn sb opcode, func3, rd, simm12(rs1)
325@verbatim
326+--------------+-----+-----+-------+-------------+-------------+
327| simm21[11:5] | rs2 | rs1 | func3 | simm12[4:0] | opcode |
328+--------------+-----+-----+-------+-------------+-------------+
32931 25 20 15 12 7 0
330@end verbatim
331
332@item U type: .insn u opcode, rd, simm20
333@verbatim
334+---------------------------+----+-------------+
335| simm20 | rd | opcode |
336+---------------------------+----+-------------+
33731 12 7 0
338@end verbatim
339
340@item UJ type: .insn uj opcode, rd, symbol
341@verbatim
342+------------+--------------+------------+---------------+----+-------------+
343| simm20[20] | simm20[10:1] | simm20[11] | simm20[19:12] | rd | opcode |
344+------------+--------------+------------+---------------+----+-------------+
34531 30 21 20 12 7 0
346@end verbatim
347
348@item CR type: .insn cr opcode2, func4, rd, rs1
349@verbatim
350+---------+--------+-----+---------+
351| func4 | rd/rs1 | rs2 | opcode2 |
352+---------+--------+-----+---------+
35315 12 7 2 0
354@end verbatim
355
356@item CI type: .insn ci opcode2, func3, rd, simm6
357@verbatim
358+---------+-----+--------+-----+---------+
359| func3 | imm | rd/rs1 | imm | opcode2 |
360+---------+-----+--------+-----+---------+
36115 13 12 7 2 0
362@end verbatim
363
364@item CIW type: .insn ciw opcode2, func3, rd, uimm8
365@verbatim
366+---------+--------------+-----+---------+
367| func3 | imm | rd' | opcode2 |
368+---------+--------------+-----+---------+
36915 13 7 2 0
370@end verbatim
371
372@item CB type: .insn cb opcode2, func3, rs1, symbol
373@verbatim
374+---------+--------+------+--------+---------+
375| func3 | offset | rs1' | offset | opcode2 |
376+---------+--------+------+--------+---------+
37715 13 10 7 2 0
378@end verbatim
379
380@item CJ type: .insn cj opcode2, symbol
381@verbatim
382+---------+--------------------+---------+
383| func3 | jump target | opcode2 |
384+---------+--------------------+---------+
38515 13 7 2 0
386@end verbatim
387
388
389@end table
390
391For the complete list of all instruction format variants see
392The RISC-V Instruction Set Manual Volume I: User-Level ISA.
This page took 0.101065 seconds and 4 git commands to generate.