xref: /dflybsd-src/contrib/binutils-2.27/gas/doc/c-sh.texi (revision e656dc90e3d65d744d534af2f5ea88cf8101ebcf)
1*a9fa9459Szrj@c Copyright (C) 1991-2016 Free Software Foundation, Inc.
2*a9fa9459Szrj@c This is part of the GAS manual.
3*a9fa9459Szrj@c For copying conditions, see the file as.texinfo.
4*a9fa9459Szrj@page
5*a9fa9459Szrj@node SH-Dependent
6*a9fa9459Szrj@chapter Renesas / SuperH SH Dependent Features
7*a9fa9459Szrj
8*a9fa9459Szrj@cindex SH support
9*a9fa9459Szrj@menu
10*a9fa9459Szrj* SH Options::              Options
11*a9fa9459Szrj* SH Syntax::               Syntax
12*a9fa9459Szrj* SH Floating Point::       Floating Point
13*a9fa9459Szrj* SH Directives::           SH Machine Directives
14*a9fa9459Szrj* SH Opcodes::              Opcodes
15*a9fa9459Szrj@end menu
16*a9fa9459Szrj
17*a9fa9459Szrj@node SH Options
18*a9fa9459Szrj@section Options
19*a9fa9459Szrj
20*a9fa9459Szrj@cindex SH options
21*a9fa9459Szrj@cindex options, SH
22*a9fa9459Szrj@code{@value{AS}} has following command-line options for the Renesas
23*a9fa9459Szrj(formerly Hitachi) / SuperH SH family.
24*a9fa9459Szrj
25*a9fa9459Szrj@table @code
26*a9fa9459Szrj@kindex --little
27*a9fa9459Szrj@kindex --big
28*a9fa9459Szrj@kindex --relax
29*a9fa9459Szrj@kindex --small
30*a9fa9459Szrj@kindex --dsp
31*a9fa9459Szrj@kindex --renesas
32*a9fa9459Szrj@kindex --allow-reg-prefix
33*a9fa9459Szrj
34*a9fa9459Szrj@item --little
35*a9fa9459SzrjGenerate little endian code.
36*a9fa9459Szrj
37*a9fa9459Szrj@item --big
38*a9fa9459SzrjGenerate big endian code.
39*a9fa9459Szrj
40*a9fa9459Szrj@item --relax
41*a9fa9459SzrjAlter jump instructions for long displacements.
42*a9fa9459Szrj
43*a9fa9459Szrj@item --small
44*a9fa9459SzrjAlign sections to 4 byte boundaries, not 16.
45*a9fa9459Szrj
46*a9fa9459Szrj@item --dsp
47*a9fa9459SzrjEnable sh-dsp insns, and disable sh3e / sh4 insns.
48*a9fa9459Szrj
49*a9fa9459Szrj@item --renesas
50*a9fa9459SzrjDisable optimization with section symbol for compatibility with
51*a9fa9459SzrjRenesas assembler.
52*a9fa9459Szrj
53*a9fa9459Szrj@item --allow-reg-prefix
54*a9fa9459SzrjAllow '$' as a register name prefix.
55*a9fa9459Szrj
56*a9fa9459Szrj@kindex --fdpic
57*a9fa9459Szrj@item --fdpic
58*a9fa9459SzrjGenerate an FDPIC object file.
59*a9fa9459Szrj
60*a9fa9459Szrj@item --isa=sh4 | sh4a
61*a9fa9459SzrjSpecify the sh4 or sh4a instruction set.
62*a9fa9459Szrj@item --isa=dsp
63*a9fa9459SzrjEnable sh-dsp insns, and disable sh3e / sh4 insns.
64*a9fa9459Szrj@item --isa=fp
65*a9fa9459SzrjEnable sh2e, sh3e, sh4, and sh4a insn sets.
66*a9fa9459Szrj@item --isa=all
67*a9fa9459SzrjEnable sh1, sh2, sh2e, sh3, sh3e, sh4, sh4a, and sh-dsp insn sets.
68*a9fa9459Szrj
69*a9fa9459Szrj@item -h-tick-hex
70*a9fa9459SzrjSupport H'00 style hex constants in addition to 0x00 style.
71*a9fa9459Szrj
72*a9fa9459Szrj@end table
73*a9fa9459Szrj
74*a9fa9459Szrj@node SH Syntax
75*a9fa9459Szrj@section Syntax
76*a9fa9459Szrj
77*a9fa9459Szrj@menu
78*a9fa9459Szrj* SH-Chars::                Special Characters
79*a9fa9459Szrj* SH-Regs::                 Register Names
80*a9fa9459Szrj* SH-Addressing::           Addressing Modes
81*a9fa9459Szrj@end menu
82*a9fa9459Szrj
83*a9fa9459Szrj@node SH-Chars
84*a9fa9459Szrj@subsection Special Characters
85*a9fa9459Szrj
86*a9fa9459Szrj@cindex line comment character, SH
87*a9fa9459Szrj@cindex SH line comment character
88*a9fa9459Szrj@samp{!} is the line comment character.
89*a9fa9459Szrj
90*a9fa9459Szrj@cindex line separator, SH
91*a9fa9459Szrj@cindex statement separator, SH
92*a9fa9459Szrj@cindex SH line separator
93*a9fa9459SzrjYou can use @samp{;} instead of a newline to separate statements.
94*a9fa9459Szrj
95*a9fa9459SzrjIf a @samp{#} appears as the first character of a line then the whole
96*a9fa9459Szrjline is treated as a comment, but in this case the line could also be
97*a9fa9459Szrja logical line number directive (@pxref{Comments}) or a preprocessor
98*a9fa9459Szrjcontrol command (@pxref{Preprocessing}).
99*a9fa9459Szrj
100*a9fa9459Szrj@cindex symbol names, @samp{$} in
101*a9fa9459Szrj@cindex @code{$} in symbol names
102*a9fa9459SzrjSince @samp{$} has no special meaning, you may use it in symbol names.
103*a9fa9459Szrj
104*a9fa9459Szrj@node SH-Regs
105*a9fa9459Szrj@subsection Register Names
106*a9fa9459Szrj
107*a9fa9459Szrj@cindex SH registers
108*a9fa9459Szrj@cindex registers, SH
109*a9fa9459SzrjYou can use the predefined symbols @samp{r0}, @samp{r1}, @samp{r2},
110*a9fa9459Szrj@samp{r3}, @samp{r4}, @samp{r5}, @samp{r6}, @samp{r7}, @samp{r8},
111*a9fa9459Szrj@samp{r9}, @samp{r10}, @samp{r11}, @samp{r12}, @samp{r13}, @samp{r14},
112*a9fa9459Szrjand @samp{r15} to refer to the SH registers.
113*a9fa9459Szrj
114*a9fa9459SzrjThe SH also has these control registers:
115*a9fa9459Szrj
116*a9fa9459Szrj@table @code
117*a9fa9459Szrj@item pr
118*a9fa9459Szrjprocedure register (holds return address)
119*a9fa9459Szrj
120*a9fa9459Szrj@item pc
121*a9fa9459Szrjprogram counter
122*a9fa9459Szrj
123*a9fa9459Szrj@item mach
124*a9fa9459Szrj@itemx macl
125*a9fa9459Szrjhigh and low multiply accumulator registers
126*a9fa9459Szrj
127*a9fa9459Szrj@item sr
128*a9fa9459Szrjstatus register
129*a9fa9459Szrj
130*a9fa9459Szrj@item gbr
131*a9fa9459Szrjglobal base register
132*a9fa9459Szrj
133*a9fa9459Szrj@item vbr
134*a9fa9459Szrjvector base register (for interrupt vectors)
135*a9fa9459Szrj@end table
136*a9fa9459Szrj
137*a9fa9459Szrj@node SH-Addressing
138*a9fa9459Szrj@subsection Addressing Modes
139*a9fa9459Szrj
140*a9fa9459Szrj@cindex addressing modes, SH
141*a9fa9459Szrj@cindex SH addressing modes
142*a9fa9459Szrj@code{@value{AS}} understands the following addressing modes for the SH.
143*a9fa9459Szrj@code{R@var{n}} in the following refers to any of the numbered
144*a9fa9459Szrjregisters, but @emph{not} the control registers.
145*a9fa9459Szrj
146*a9fa9459Szrj@table @code
147*a9fa9459Szrj@item R@var{n}
148*a9fa9459SzrjRegister direct
149*a9fa9459Szrj
150*a9fa9459Szrj@item @@R@var{n}
151*a9fa9459SzrjRegister indirect
152*a9fa9459Szrj
153*a9fa9459Szrj@item @@-R@var{n}
154*a9fa9459SzrjRegister indirect with pre-decrement
155*a9fa9459Szrj
156*a9fa9459Szrj@item @@R@var{n}+
157*a9fa9459SzrjRegister indirect with post-increment
158*a9fa9459Szrj
159*a9fa9459Szrj@item @@(@var{disp}, R@var{n})
160*a9fa9459SzrjRegister indirect with displacement
161*a9fa9459Szrj
162*a9fa9459Szrj@item @@(R0, R@var{n})
163*a9fa9459SzrjRegister indexed
164*a9fa9459Szrj
165*a9fa9459Szrj@item @@(@var{disp}, GBR)
166*a9fa9459Szrj@code{GBR} offset
167*a9fa9459Szrj
168*a9fa9459Szrj@item @@(R0, GBR)
169*a9fa9459SzrjGBR indexed
170*a9fa9459Szrj
171*a9fa9459Szrj@item @var{addr}
172*a9fa9459Szrj@itemx @@(@var{disp}, PC)
173*a9fa9459SzrjPC relative address (for branch or for addressing memory).  The
174*a9fa9459Szrj@code{@value{AS}} implementation allows you to use the simpler form
175*a9fa9459Szrj@var{addr} anywhere a PC relative address is called for; the alternate
176*a9fa9459Szrjform is supported for compatibility with other assemblers.
177*a9fa9459Szrj
178*a9fa9459Szrj@item #@var{imm}
179*a9fa9459SzrjImmediate data
180*a9fa9459Szrj@end table
181*a9fa9459Szrj
182*a9fa9459Szrj@node SH Floating Point
183*a9fa9459Szrj@section Floating Point
184*a9fa9459Szrj
185*a9fa9459Szrj@cindex floating point, SH (@sc{ieee})
186*a9fa9459Szrj@cindex SH floating point (@sc{ieee})
187*a9fa9459SzrjSH2E, SH3E and SH4 groups have on-chip floating-point unit (FPU). Other
188*a9fa9459SzrjSH groups can use @code{.float} directive to generate @sc{ieee}
189*a9fa9459Szrjfloating-point numbers.
190*a9fa9459Szrj
191*a9fa9459SzrjSH2E and SH3E support single-precision floating point calculations as
192*a9fa9459Szrjwell as entirely PCAPI compatible emulation of double-precision
193*a9fa9459Szrjfloating point calculations. SH2E and SH3E instructions are a subset of
194*a9fa9459Szrjthe floating point calculations conforming to the IEEE754 standard.
195*a9fa9459Szrj
196*a9fa9459SzrjIn addition to single-precision and double-precision floating-point
197*a9fa9459Szrjoperation capability, the on-chip FPU of SH4 has a 128-bit graphic
198*a9fa9459Szrjengine that enables 32-bit floating-point data to be processed 128
199*a9fa9459Szrjbits at a time. It also supports 4 * 4 array operations and inner
200*a9fa9459Szrjproduct operations. Also, a superscalar architecture is employed that
201*a9fa9459Szrjenables simultaneous execution of two instructions (including FPU
202*a9fa9459Szrjinstructions), providing performance of up to twice that of
203*a9fa9459Szrjconventional architectures at the same frequency.
204*a9fa9459Szrj
205*a9fa9459Szrj@node SH Directives
206*a9fa9459Szrj@section SH Machine Directives
207*a9fa9459Szrj
208*a9fa9459Szrj@cindex SH machine directives
209*a9fa9459Szrj@cindex machine directives, SH
210*a9fa9459Szrj@cindex @code{uaword} directive, SH
211*a9fa9459Szrj@cindex @code{ualong} directive, SH
212*a9fa9459Szrj@cindex @code{uaquad} directive, SH
213*a9fa9459Szrj
214*a9fa9459Szrj@table @code
215*a9fa9459Szrj@item uaword
216*a9fa9459Szrj@itemx ualong
217*a9fa9459Szrj@itemx uaquad
218*a9fa9459Szrj@code{@value{AS}} will issue a warning when a misaligned @code{.word},
219*a9fa9459Szrj@code{.long}, or @code{.quad} directive is used.  You may use
220*a9fa9459Szrj@code{.uaword}, @code{.ualong}, or @code{.uaquad} to indicate that the
221*a9fa9459Szrjvalue is intentionally misaligned.
222*a9fa9459Szrj@end table
223*a9fa9459Szrj
224*a9fa9459Szrj@node SH Opcodes
225*a9fa9459Szrj@section Opcodes
226*a9fa9459Szrj
227*a9fa9459Szrj@cindex SH opcode summary
228*a9fa9459Szrj@cindex opcode summary, SH
229*a9fa9459Szrj@cindex mnemonics, SH
230*a9fa9459Szrj@cindex instruction summary, SH
231*a9fa9459SzrjFor detailed information on the SH machine instruction set, see
232*a9fa9459Szrj@cite{SH-Microcomputer User's Manual} (Renesas) or
233*a9fa9459Szrj@cite{SH-4 32-bit CPU Core Architecture} (SuperH) and
234*a9fa9459Szrj@cite{SuperH (SH) 64-Bit RISC Series} (SuperH).
235*a9fa9459Szrj
236*a9fa9459Szrj@code{@value{AS}} implements all the standard SH opcodes.  No additional
237*a9fa9459Szrjpseudo-instructions are needed on this family.  Note, however, that
238*a9fa9459Szrjbecause @code{@value{AS}} supports a simpler form of PC-relative
239*a9fa9459Szrjaddressing, you may simply write (for example)
240*a9fa9459Szrj
241*a9fa9459Szrj@example
242*a9fa9459Szrjmov.l  bar,r0
243*a9fa9459Szrj@end example
244*a9fa9459Szrj
245*a9fa9459Szrj@noindent
246*a9fa9459Szrjwhere other assemblers might require an explicit displacement to
247*a9fa9459Szrj@code{bar} from the program counter:
248*a9fa9459Szrj
249*a9fa9459Szrj@example
250*a9fa9459Szrjmov.l  @@(@var{disp}, PC)
251*a9fa9459Szrj@end example
252*a9fa9459Szrj
253*a9fa9459Szrj@ifset SMALL
254*a9fa9459Szrj@c this table, due to the multi-col faking and hardcoded order, looks silly
255*a9fa9459Szrj@c except in smallbook.  See comments below "@set SMALL" near top of this file.
256*a9fa9459Szrj
257*a9fa9459SzrjHere is a summary of SH opcodes:
258*a9fa9459Szrj
259*a9fa9459Szrj@page
260*a9fa9459Szrj@smallexample
261*a9fa9459Szrj@i{Legend:}
262*a9fa9459SzrjRn        @r{a numbered register}
263*a9fa9459SzrjRm        @r{another numbered register}
264*a9fa9459Szrj#imm      @r{immediate data}
265*a9fa9459Szrjdisp      @r{displacement}
266*a9fa9459Szrjdisp8     @r{8-bit displacement}
267*a9fa9459Szrjdisp12    @r{12-bit displacement}
268*a9fa9459Szrj
269*a9fa9459Szrjadd #imm,Rn                    lds.l @@Rn+,PR
270*a9fa9459Szrjadd Rm,Rn                      mac.w @@Rm+,@@Rn+
271*a9fa9459Szrjaddc Rm,Rn                     mov #imm,Rn
272*a9fa9459Szrjaddv Rm,Rn                     mov Rm,Rn
273*a9fa9459Szrjand #imm,R0                    mov.b Rm,@@(R0,Rn)
274*a9fa9459Szrjand Rm,Rn                      mov.b Rm,@@-Rn
275*a9fa9459Szrjand.b #imm,@@(R0,GBR)           mov.b Rm,@@Rn
276*a9fa9459Szrjbf disp8                       mov.b @@(disp,Rm),R0
277*a9fa9459Szrjbra disp12                     mov.b @@(disp,GBR),R0
278*a9fa9459Szrjbsr disp12                     mov.b @@(R0,Rm),Rn
279*a9fa9459Szrjbt disp8                       mov.b @@Rm+,Rn
280*a9fa9459Szrjclrmac                         mov.b @@Rm,Rn
281*a9fa9459Szrjclrt                           mov.b R0,@@(disp,Rm)
282*a9fa9459Szrjcmp/eq #imm,R0                 mov.b R0,@@(disp,GBR)
283*a9fa9459Szrjcmp/eq Rm,Rn                   mov.l Rm,@@(disp,Rn)
284*a9fa9459Szrjcmp/ge Rm,Rn                   mov.l Rm,@@(R0,Rn)
285*a9fa9459Szrjcmp/gt Rm,Rn                   mov.l Rm,@@-Rn
286*a9fa9459Szrjcmp/hi Rm,Rn                   mov.l Rm,@@Rn
287*a9fa9459Szrjcmp/hs Rm,Rn                   mov.l @@(disp,Rn),Rm
288*a9fa9459Szrjcmp/pl Rn                      mov.l @@(disp,GBR),R0
289*a9fa9459Szrjcmp/pz Rn                      mov.l @@(disp,PC),Rn
290*a9fa9459Szrjcmp/str Rm,Rn                  mov.l @@(R0,Rm),Rn
291*a9fa9459Szrjdiv0s Rm,Rn                    mov.l @@Rm+,Rn
292*a9fa9459Szrjdiv0u                          mov.l @@Rm,Rn
293*a9fa9459Szrjdiv1 Rm,Rn                     mov.l R0,@@(disp,GBR)
294*a9fa9459Szrjexts.b Rm,Rn                   mov.w Rm,@@(R0,Rn)
295*a9fa9459Szrjexts.w Rm,Rn                   mov.w Rm,@@-Rn
296*a9fa9459Szrjextu.b Rm,Rn                   mov.w Rm,@@Rn
297*a9fa9459Szrjextu.w Rm,Rn                   mov.w @@(disp,Rm),R0
298*a9fa9459Szrjjmp @@Rn                        mov.w @@(disp,GBR),R0
299*a9fa9459Szrjjsr @@Rn                        mov.w @@(disp,PC),Rn
300*a9fa9459Szrjldc Rn,GBR                     mov.w @@(R0,Rm),Rn
301*a9fa9459Szrjldc Rn,SR                      mov.w @@Rm+,Rn
302*a9fa9459Szrjldc Rn,VBR                     mov.w @@Rm,Rn
303*a9fa9459Szrjldc.l @@Rn+,GBR                 mov.w R0,@@(disp,Rm)
304*a9fa9459Szrjldc.l @@Rn+,SR                  mov.w R0,@@(disp,GBR)
305*a9fa9459Szrjldc.l @@Rn+,VBR                 mova @@(disp,PC),R0
306*a9fa9459Szrjlds Rn,MACH                    movt Rn
307*a9fa9459Szrjlds Rn,MACL                    muls Rm,Rn
308*a9fa9459Szrjlds Rn,PR                      mulu Rm,Rn
309*a9fa9459Szrjlds.l @@Rn+,MACH                neg Rm,Rn
310*a9fa9459Szrjlds.l @@Rn+,MACL                negc Rm,Rn
311*a9fa9459Szrj@page
312*a9fa9459Szrjnop                            stc VBR,Rn
313*a9fa9459Szrjnot Rm,Rn                      stc.l GBR,@@-Rn
314*a9fa9459Szrjor #imm,R0                     stc.l SR,@@-Rn
315*a9fa9459Szrjor Rm,Rn                       stc.l VBR,@@-Rn
316*a9fa9459Szrjor.b #imm,@@(R0,GBR)            sts MACH,Rn
317*a9fa9459Szrjrotcl Rn                       sts MACL,Rn
318*a9fa9459Szrjrotcr Rn                       sts PR,Rn
319*a9fa9459Szrjrotl Rn                        sts.l MACH,@@-Rn
320*a9fa9459Szrjrotr Rn                        sts.l MACL,@@-Rn
321*a9fa9459Szrjrte                            sts.l PR,@@-Rn
322*a9fa9459Szrjrts                            sub Rm,Rn
323*a9fa9459Szrjsett                           subc Rm,Rn
324*a9fa9459Szrjshal Rn                        subv Rm,Rn
325*a9fa9459Szrjshar Rn                        swap.b Rm,Rn
326*a9fa9459Szrjshll Rn                        swap.w Rm,Rn
327*a9fa9459Szrjshll16 Rn                      tas.b @@Rn
328*a9fa9459Szrjshll2 Rn                       trapa #imm
329*a9fa9459Szrjshll8 Rn                       tst #imm,R0
330*a9fa9459Szrjshlr Rn                        tst Rm,Rn
331*a9fa9459Szrjshlr16 Rn                      tst.b #imm,@@(R0,GBR)
332*a9fa9459Szrjshlr2 Rn                       xor #imm,R0
333*a9fa9459Szrjshlr8 Rn                       xor Rm,Rn
334*a9fa9459Szrjsleep                          xor.b #imm,@@(R0,GBR)
335*a9fa9459Szrjstc GBR,Rn                     xtrct Rm,Rn
336*a9fa9459Szrjstc SR,Rn
337*a9fa9459Szrj@end smallexample
338*a9fa9459Szrj@end ifset
339*a9fa9459Szrj
340*a9fa9459Szrj@ifset Renesas-all
341*a9fa9459Szrj@ifclear GENERIC
342*a9fa9459Szrj@raisesections
343*a9fa9459Szrj@end ifclear
344*a9fa9459Szrj@end ifset
345*a9fa9459Szrj
346