xref: /openbsd-src/gnu/usr.bin/binutils-2.17/gas/doc/c-sh.texi (revision 3d8817e467ea46cf4772788d6804dd293abfb01a)
1*3d8817e4Smiod@c Copyright 1991, 1992, 1993, 1994, 1995, 1997, 2001, 2003, 2004, 2005
2*3d8817e4Smiod@c Free Software Foundation, Inc.
3*3d8817e4Smiod@c This is part of the GAS manual.
4*3d8817e4Smiod@c For copying conditions, see the file as.texinfo.
5*3d8817e4Smiod@page
6*3d8817e4Smiod@node SH-Dependent
7*3d8817e4Smiod@chapter Renesas / SuperH SH Dependent Features
8*3d8817e4Smiod
9*3d8817e4Smiod@cindex SH support
10*3d8817e4Smiod@menu
11*3d8817e4Smiod* SH Options::              Options
12*3d8817e4Smiod* SH Syntax::               Syntax
13*3d8817e4Smiod* SH Floating Point::       Floating Point
14*3d8817e4Smiod* SH Directives::           SH Machine Directives
15*3d8817e4Smiod* SH Opcodes::              Opcodes
16*3d8817e4Smiod@end menu
17*3d8817e4Smiod
18*3d8817e4Smiod@node SH Options
19*3d8817e4Smiod@section Options
20*3d8817e4Smiod
21*3d8817e4Smiod@cindex SH options
22*3d8817e4Smiod@cindex options, SH
23*3d8817e4Smiod@code{@value{AS}} has following command-line options for the Renesas
24*3d8817e4Smiod(formerly Hitachi) / SuperH SH family.
25*3d8817e4Smiod
26*3d8817e4Smiod@table @code
27*3d8817e4Smiod@kindex --little
28*3d8817e4Smiod@kindex --big
29*3d8817e4Smiod@kindex --relax
30*3d8817e4Smiod@kindex --small
31*3d8817e4Smiod@kindex --dsp
32*3d8817e4Smiod@kindex --renesas
33*3d8817e4Smiod@kindex --allow-reg-prefix
34*3d8817e4Smiod
35*3d8817e4Smiod@item --little
36*3d8817e4SmiodGenerate little endian code.
37*3d8817e4Smiod
38*3d8817e4Smiod@item --big
39*3d8817e4SmiodGenerate big endian code.
40*3d8817e4Smiod
41*3d8817e4Smiod@item --relax
42*3d8817e4SmiodAlter jump instructions for long displacements.
43*3d8817e4Smiod
44*3d8817e4Smiod@item --small
45*3d8817e4SmiodAlign sections to 4 byte boundaries, not 16.
46*3d8817e4Smiod
47*3d8817e4Smiod@item --dsp
48*3d8817e4SmiodEnable sh-dsp insns, and disable sh3e / sh4 insns.
49*3d8817e4Smiod
50*3d8817e4Smiod@item --renesas
51*3d8817e4SmiodDisable optimization with section symbol for compatibility with
52*3d8817e4SmiodRenesas assembler.
53*3d8817e4Smiod
54*3d8817e4Smiod@item --allow-reg-prefix
55*3d8817e4SmiodAllow '$' as a register name prefix.
56*3d8817e4Smiod
57*3d8817e4Smiod@item --isa=sh4 | sh4a
58*3d8817e4SmiodSpecify the sh4 or sh4a instruction set.
59*3d8817e4Smiod@item --isa=dsp
60*3d8817e4SmiodEnable sh-dsp insns, and disable sh3e / sh4 insns.
61*3d8817e4Smiod@item --isa=fp
62*3d8817e4SmiodEnable sh2e, sh3e, sh4, and sh4a insn sets.
63*3d8817e4Smiod@item --isa=all
64*3d8817e4SmiodEnable sh1, sh2, sh2e, sh3, sh3e, sh4, sh4a, and sh-dsp insn sets.
65*3d8817e4Smiod
66*3d8817e4Smiod@end table
67*3d8817e4Smiod
68*3d8817e4Smiod@node SH Syntax
69*3d8817e4Smiod@section Syntax
70*3d8817e4Smiod
71*3d8817e4Smiod@menu
72*3d8817e4Smiod* SH-Chars::                Special Characters
73*3d8817e4Smiod* SH-Regs::                 Register Names
74*3d8817e4Smiod* SH-Addressing::           Addressing Modes
75*3d8817e4Smiod@end menu
76*3d8817e4Smiod
77*3d8817e4Smiod@node SH-Chars
78*3d8817e4Smiod@subsection Special Characters
79*3d8817e4Smiod
80*3d8817e4Smiod@cindex line comment character, SH
81*3d8817e4Smiod@cindex SH line comment character
82*3d8817e4Smiod@samp{!} is the line comment character.
83*3d8817e4Smiod
84*3d8817e4Smiod@cindex line separator, SH
85*3d8817e4Smiod@cindex statement separator, SH
86*3d8817e4Smiod@cindex SH line separator
87*3d8817e4SmiodYou can use @samp{;} instead of a newline to separate statements.
88*3d8817e4Smiod
89*3d8817e4Smiod@cindex symbol names, @samp{$} in
90*3d8817e4Smiod@cindex @code{$} in symbol names
91*3d8817e4SmiodSince @samp{$} has no special meaning, you may use it in symbol names.
92*3d8817e4Smiod
93*3d8817e4Smiod@node SH-Regs
94*3d8817e4Smiod@subsection Register Names
95*3d8817e4Smiod
96*3d8817e4Smiod@cindex SH registers
97*3d8817e4Smiod@cindex registers, SH
98*3d8817e4SmiodYou can use the predefined symbols @samp{r0}, @samp{r1}, @samp{r2},
99*3d8817e4Smiod@samp{r3}, @samp{r4}, @samp{r5}, @samp{r6}, @samp{r7}, @samp{r8},
100*3d8817e4Smiod@samp{r9}, @samp{r10}, @samp{r11}, @samp{r12}, @samp{r13}, @samp{r14},
101*3d8817e4Smiodand @samp{r15} to refer to the SH registers.
102*3d8817e4Smiod
103*3d8817e4SmiodThe SH also has these control registers:
104*3d8817e4Smiod
105*3d8817e4Smiod@table @code
106*3d8817e4Smiod@item pr
107*3d8817e4Smiodprocedure register (holds return address)
108*3d8817e4Smiod
109*3d8817e4Smiod@item pc
110*3d8817e4Smiodprogram counter
111*3d8817e4Smiod
112*3d8817e4Smiod@item mach
113*3d8817e4Smiod@itemx macl
114*3d8817e4Smiodhigh and low multiply accumulator registers
115*3d8817e4Smiod
116*3d8817e4Smiod@item sr
117*3d8817e4Smiodstatus register
118*3d8817e4Smiod
119*3d8817e4Smiod@item gbr
120*3d8817e4Smiodglobal base register
121*3d8817e4Smiod
122*3d8817e4Smiod@item vbr
123*3d8817e4Smiodvector base register (for interrupt vectors)
124*3d8817e4Smiod@end table
125*3d8817e4Smiod
126*3d8817e4Smiod@node SH-Addressing
127*3d8817e4Smiod@subsection Addressing Modes
128*3d8817e4Smiod
129*3d8817e4Smiod@cindex addressing modes, SH
130*3d8817e4Smiod@cindex SH addressing modes
131*3d8817e4Smiod@code{@value{AS}} understands the following addressing modes for the SH.
132*3d8817e4Smiod@code{R@var{n}} in the following refers to any of the numbered
133*3d8817e4Smiodregisters, but @emph{not} the control registers.
134*3d8817e4Smiod
135*3d8817e4Smiod@table @code
136*3d8817e4Smiod@item R@var{n}
137*3d8817e4SmiodRegister direct
138*3d8817e4Smiod
139*3d8817e4Smiod@item @@R@var{n}
140*3d8817e4SmiodRegister indirect
141*3d8817e4Smiod
142*3d8817e4Smiod@item @@-R@var{n}
143*3d8817e4SmiodRegister indirect with pre-decrement
144*3d8817e4Smiod
145*3d8817e4Smiod@item @@R@var{n}+
146*3d8817e4SmiodRegister indirect with post-increment
147*3d8817e4Smiod
148*3d8817e4Smiod@item @@(@var{disp}, R@var{n})
149*3d8817e4SmiodRegister indirect with displacement
150*3d8817e4Smiod
151*3d8817e4Smiod@item @@(R0, R@var{n})
152*3d8817e4SmiodRegister indexed
153*3d8817e4Smiod
154*3d8817e4Smiod@item @@(@var{disp}, GBR)
155*3d8817e4Smiod@code{GBR} offset
156*3d8817e4Smiod
157*3d8817e4Smiod@item @@(R0, GBR)
158*3d8817e4SmiodGBR indexed
159*3d8817e4Smiod
160*3d8817e4Smiod@item @var{addr}
161*3d8817e4Smiod@itemx @@(@var{disp}, PC)
162*3d8817e4SmiodPC relative address (for branch or for addressing memory).  The
163*3d8817e4Smiod@code{@value{AS}} implementation allows you to use the simpler form
164*3d8817e4Smiod@var{addr} anywhere a PC relative address is called for; the alternate
165*3d8817e4Smiodform is supported for compatibility with other assemblers.
166*3d8817e4Smiod
167*3d8817e4Smiod@item #@var{imm}
168*3d8817e4SmiodImmediate data
169*3d8817e4Smiod@end table
170*3d8817e4Smiod
171*3d8817e4Smiod@node SH Floating Point
172*3d8817e4Smiod@section Floating Point
173*3d8817e4Smiod
174*3d8817e4Smiod@cindex floating point, SH (@sc{ieee})
175*3d8817e4Smiod@cindex SH floating point (@sc{ieee})
176*3d8817e4SmiodSH2E, SH3E and SH4 groups have on-chip floating-point unit (FPU). Other
177*3d8817e4SmiodSH groups can use @code{.float} directive to generate @sc{ieee}
178*3d8817e4Smiodfloating-point numbers.
179*3d8817e4Smiod
180*3d8817e4SmiodSH2E and SH3E support single-precision floating point calculations as
181*3d8817e4Smiodwell as entirely PCAPI compatible emulation of double-precision
182*3d8817e4Smiodfloating point calculations. SH2E and SH3E instructions are a subset of
183*3d8817e4Smiodthe floating point calculations conforming to the IEEE754 standard.
184*3d8817e4Smiod
185*3d8817e4SmiodIn addition to single-precision and double-precision floating-point
186*3d8817e4Smiodoperation capability, the on-chip FPU of SH4 has a 128-bit graphic
187*3d8817e4Smiodengine that enables 32-bit floating-point data to be processed 128
188*3d8817e4Smiodbits at a time. It also supports 4 * 4 array operations and inner
189*3d8817e4Smiodproduct operations. Also, a superscalar architecture is employed that
190*3d8817e4Smiodenables simultaneous execution of two instructions (including FPU
191*3d8817e4Smiodinstructions), providing performance of up to twice that of
192*3d8817e4Smiodconventional architectures at the same frequency.
193*3d8817e4Smiod
194*3d8817e4Smiod@node SH Directives
195*3d8817e4Smiod@section SH Machine Directives
196*3d8817e4Smiod
197*3d8817e4Smiod@cindex SH machine directives
198*3d8817e4Smiod@cindex machine directives, SH
199*3d8817e4Smiod@cindex @code{uaword} directive, SH
200*3d8817e4Smiod@cindex @code{ualong} directive, SH
201*3d8817e4Smiod
202*3d8817e4Smiod@table @code
203*3d8817e4Smiod@item uaword
204*3d8817e4Smiod@itemx ualong
205*3d8817e4Smiod@code{@value{AS}} will issue a warning when a misaligned @code{.word} or
206*3d8817e4Smiod@code{.long} directive is used.  You may use @code{.uaword} or
207*3d8817e4Smiod@code{.ualong} to indicate that the value is intentionally misaligned.
208*3d8817e4Smiod@end table
209*3d8817e4Smiod
210*3d8817e4Smiod@node SH Opcodes
211*3d8817e4Smiod@section Opcodes
212*3d8817e4Smiod
213*3d8817e4Smiod@cindex SH opcode summary
214*3d8817e4Smiod@cindex opcode summary, SH
215*3d8817e4Smiod@cindex mnemonics, SH
216*3d8817e4Smiod@cindex instruction summary, SH
217*3d8817e4SmiodFor detailed information on the SH machine instruction set, see
218*3d8817e4Smiod@cite{SH-Microcomputer User's Manual} (Renesas) or
219*3d8817e4Smiod@cite{SH-4 32-bit CPU Core Architecture} (SuperH) and
220*3d8817e4Smiod@cite{SuperH (SH) 64-Bit RISC Series} (SuperH).
221*3d8817e4Smiod
222*3d8817e4Smiod@code{@value{AS}} implements all the standard SH opcodes.  No additional
223*3d8817e4Smiodpseudo-instructions are needed on this family.  Note, however, that
224*3d8817e4Smiodbecause @code{@value{AS}} supports a simpler form of PC-relative
225*3d8817e4Smiodaddressing, you may simply write (for example)
226*3d8817e4Smiod
227*3d8817e4Smiod@example
228*3d8817e4Smiodmov.l  bar,r0
229*3d8817e4Smiod@end example
230*3d8817e4Smiod
231*3d8817e4Smiod@noindent
232*3d8817e4Smiodwhere other assemblers might require an explicit displacement to
233*3d8817e4Smiod@code{bar} from the program counter:
234*3d8817e4Smiod
235*3d8817e4Smiod@example
236*3d8817e4Smiodmov.l  @@(@var{disp}, PC)
237*3d8817e4Smiod@end example
238*3d8817e4Smiod
239*3d8817e4Smiod@ifset SMALL
240*3d8817e4Smiod@c this table, due to the multi-col faking and hardcoded order, looks silly
241*3d8817e4Smiod@c except in smallbook.  See comments below "@set SMALL" near top of this file.
242*3d8817e4Smiod
243*3d8817e4SmiodHere is a summary of SH opcodes:
244*3d8817e4Smiod
245*3d8817e4Smiod@page
246*3d8817e4Smiod@smallexample
247*3d8817e4Smiod@i{Legend:}
248*3d8817e4SmiodRn        @r{a numbered register}
249*3d8817e4SmiodRm        @r{another numbered register}
250*3d8817e4Smiod#imm      @r{immediate data}
251*3d8817e4Smioddisp      @r{displacement}
252*3d8817e4Smioddisp8     @r{8-bit displacement}
253*3d8817e4Smioddisp12    @r{12-bit displacement}
254*3d8817e4Smiod
255*3d8817e4Smiodadd #imm,Rn                    lds.l @@Rn+,PR
256*3d8817e4Smiodadd Rm,Rn                      mac.w @@Rm+,@@Rn+
257*3d8817e4Smiodaddc Rm,Rn                     mov #imm,Rn
258*3d8817e4Smiodaddv Rm,Rn                     mov Rm,Rn
259*3d8817e4Smiodand #imm,R0                    mov.b Rm,@@(R0,Rn)
260*3d8817e4Smiodand Rm,Rn                      mov.b Rm,@@-Rn
261*3d8817e4Smiodand.b #imm,@@(R0,GBR)           mov.b Rm,@@Rn
262*3d8817e4Smiodbf disp8                       mov.b @@(disp,Rm),R0
263*3d8817e4Smiodbra disp12                     mov.b @@(disp,GBR),R0
264*3d8817e4Smiodbsr disp12                     mov.b @@(R0,Rm),Rn
265*3d8817e4Smiodbt disp8                       mov.b @@Rm+,Rn
266*3d8817e4Smiodclrmac                         mov.b @@Rm,Rn
267*3d8817e4Smiodclrt                           mov.b R0,@@(disp,Rm)
268*3d8817e4Smiodcmp/eq #imm,R0                 mov.b R0,@@(disp,GBR)
269*3d8817e4Smiodcmp/eq Rm,Rn                   mov.l Rm,@@(disp,Rn)
270*3d8817e4Smiodcmp/ge Rm,Rn                   mov.l Rm,@@(R0,Rn)
271*3d8817e4Smiodcmp/gt Rm,Rn                   mov.l Rm,@@-Rn
272*3d8817e4Smiodcmp/hi Rm,Rn                   mov.l Rm,@@Rn
273*3d8817e4Smiodcmp/hs Rm,Rn                   mov.l @@(disp,Rn),Rm
274*3d8817e4Smiodcmp/pl Rn                      mov.l @@(disp,GBR),R0
275*3d8817e4Smiodcmp/pz Rn                      mov.l @@(disp,PC),Rn
276*3d8817e4Smiodcmp/str Rm,Rn                  mov.l @@(R0,Rm),Rn
277*3d8817e4Smioddiv0s Rm,Rn                    mov.l @@Rm+,Rn
278*3d8817e4Smioddiv0u                          mov.l @@Rm,Rn
279*3d8817e4Smioddiv1 Rm,Rn                     mov.l R0,@@(disp,GBR)
280*3d8817e4Smiodexts.b Rm,Rn                   mov.w Rm,@@(R0,Rn)
281*3d8817e4Smiodexts.w Rm,Rn                   mov.w Rm,@@-Rn
282*3d8817e4Smiodextu.b Rm,Rn                   mov.w Rm,@@Rn
283*3d8817e4Smiodextu.w Rm,Rn                   mov.w @@(disp,Rm),R0
284*3d8817e4Smiodjmp @@Rn                        mov.w @@(disp,GBR),R0
285*3d8817e4Smiodjsr @@Rn                        mov.w @@(disp,PC),Rn
286*3d8817e4Smiodldc Rn,GBR                     mov.w @@(R0,Rm),Rn
287*3d8817e4Smiodldc Rn,SR                      mov.w @@Rm+,Rn
288*3d8817e4Smiodldc Rn,VBR                     mov.w @@Rm,Rn
289*3d8817e4Smiodldc.l @@Rn+,GBR                 mov.w R0,@@(disp,Rm)
290*3d8817e4Smiodldc.l @@Rn+,SR                  mov.w R0,@@(disp,GBR)
291*3d8817e4Smiodldc.l @@Rn+,VBR                 mova @@(disp,PC),R0
292*3d8817e4Smiodlds Rn,MACH                    movt Rn
293*3d8817e4Smiodlds Rn,MACL                    muls Rm,Rn
294*3d8817e4Smiodlds Rn,PR                      mulu Rm,Rn
295*3d8817e4Smiodlds.l @@Rn+,MACH                neg Rm,Rn
296*3d8817e4Smiodlds.l @@Rn+,MACL                negc Rm,Rn
297*3d8817e4Smiod@page
298*3d8817e4Smiodnop                            stc VBR,Rn
299*3d8817e4Smiodnot Rm,Rn                      stc.l GBR,@@-Rn
300*3d8817e4Smiodor #imm,R0                     stc.l SR,@@-Rn
301*3d8817e4Smiodor Rm,Rn                       stc.l VBR,@@-Rn
302*3d8817e4Smiodor.b #imm,@@(R0,GBR)            sts MACH,Rn
303*3d8817e4Smiodrotcl Rn                       sts MACL,Rn
304*3d8817e4Smiodrotcr Rn                       sts PR,Rn
305*3d8817e4Smiodrotl Rn                        sts.l MACH,@@-Rn
306*3d8817e4Smiodrotr Rn                        sts.l MACL,@@-Rn
307*3d8817e4Smiodrte                            sts.l PR,@@-Rn
308*3d8817e4Smiodrts                            sub Rm,Rn
309*3d8817e4Smiodsett                           subc Rm,Rn
310*3d8817e4Smiodshal Rn                        subv Rm,Rn
311*3d8817e4Smiodshar Rn                        swap.b Rm,Rn
312*3d8817e4Smiodshll Rn                        swap.w Rm,Rn
313*3d8817e4Smiodshll16 Rn                      tas.b @@Rn
314*3d8817e4Smiodshll2 Rn                       trapa #imm
315*3d8817e4Smiodshll8 Rn                       tst #imm,R0
316*3d8817e4Smiodshlr Rn                        tst Rm,Rn
317*3d8817e4Smiodshlr16 Rn                      tst.b #imm,@@(R0,GBR)
318*3d8817e4Smiodshlr2 Rn                       xor #imm,R0
319*3d8817e4Smiodshlr8 Rn                       xor Rm,Rn
320*3d8817e4Smiodsleep                          xor.b #imm,@@(R0,GBR)
321*3d8817e4Smiodstc GBR,Rn                     xtrct Rm,Rn
322*3d8817e4Smiodstc SR,Rn
323*3d8817e4Smiod@end smallexample
324*3d8817e4Smiod@end ifset
325*3d8817e4Smiod
326*3d8817e4Smiod@ifset Renesas-all
327*3d8817e4Smiod@ifclear GENERIC
328*3d8817e4Smiod@raisesections
329*3d8817e4Smiod@end ifclear
330*3d8817e4Smiod@end ifset
331*3d8817e4Smiod
332