c-msp430.texi 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. @c Copyright (C) 2002-2022 Free Software Foundation, Inc.
  2. @c This is part of the GAS manual.
  3. @c For copying conditions, see the file as.texinfo.
  4. @ifset GENERIC
  5. @page
  6. @node MSP430-Dependent
  7. @chapter MSP 430 Dependent Features
  8. @end ifset
  9. @ifclear GENERIC
  10. @node Machine Dependencies
  11. @chapter MSP 430 Dependent Features
  12. @end ifclear
  13. @cindex MSP 430 support
  14. @cindex 430 support
  15. @menu
  16. * MSP430 Options:: Options
  17. * MSP430 Syntax:: Syntax
  18. * MSP430 Floating Point:: Floating Point
  19. * MSP430 Directives:: MSP 430 Machine Directives
  20. * MSP430 Opcodes:: Opcodes
  21. * MSP430 Profiling Capability:: Profiling Capability
  22. @end menu
  23. @node MSP430 Options
  24. @section Options
  25. @cindex MSP 430 options (none)
  26. @cindex options for MSP430 (none)
  27. @table @code
  28. @item -mmcu
  29. selects the mcu architecture. If the architecture is 430Xv2 then this
  30. also enables NOP generation unless the @option{-mN} is also specified.
  31. @item -mcpu
  32. selects the cpu architecture. If the architecture is 430Xv2 then this
  33. also enables NOP generation unless the @option{-mN} is also specified.
  34. @item -msilicon-errata=@var{name}[,@var{name}@dots{}]
  35. Implements a fixup for named silicon errata. Multiple silicon errata
  36. can be specified by multiple uses of the @option{-msilicon-errata}
  37. option and/or by including the errata names, separated by commas, on
  38. an individual @option{-msilicon-errata} option. Errata names
  39. currently recognised by the assembler are:
  40. @table @code
  41. @item cpu4
  42. @code{PUSH #4} and @option{PUSH #8} need longer encodings on the
  43. MSP430. This option is enabled by default, and cannot be disabled.
  44. @item cpu8
  45. Do not set the @code{SP} to an odd value.
  46. @item cpu11
  47. Do not update the @code{SR} and the @code{PC} in the same instruction.
  48. @item cpu12
  49. Do not use the @code{PC} in a @code{CMP} or @code{BIT} instruction.
  50. @item cpu13
  51. Do not use an arithmetic instruction to modify the @code{SR}.
  52. @item cpu19
  53. Insert @code{NOP} after @code{CPUOFF}.
  54. @end table
  55. @item -msilicon-errata-warn=@var{name}[,@var{name}@dots{}]
  56. Like the @option{-msilicon-errata} option except that instead of
  57. fixing the specified errata, a warning message is issued instead.
  58. This option can be used alongside @option{-msilicon-errata} to
  59. generate messages whenever a problem is fixed, or on its own in order
  60. to inspect code for potential problems.
  61. @item -mP
  62. enables polymorph instructions handler.
  63. @item -mQ
  64. enables relaxation at assembly time. DANGEROUS!
  65. @item -ml
  66. indicates that the input uses the large code model.
  67. @item -mn
  68. enables the generation of a NOP instruction following any instruction
  69. that might change the interrupts enabled/disabled state. The
  70. pipelined nature of the MSP430 core means that any instruction that
  71. changes the interrupt state (@code{EINT}, @code{DINT}, @code{BIC #8,
  72. SR}, @code{BIS #8, SR} or @code{MOV.W <>, SR}) must be
  73. followed by a NOP instruction in order to ensure the correct
  74. processing of interrupts. By default it is up to the programmer to
  75. supply these NOP instructions, but this command-line option enables
  76. the automatic insertion by the assembler, if they are missing.
  77. @item -mN
  78. disables the generation of a NOP instruction following any instruction
  79. that might change the interrupts enabled/disabled state. This is the
  80. default behaviour.
  81. @item -my
  82. tells the assembler to generate a warning message if a NOP does not
  83. immediately follow an instruction that enables or disables
  84. interrupts. This is the default.
  85. Note that this option can be stacked with the @option{-mn} option so
  86. that the assembler will both warn about missing NOP instructions and
  87. then insert them automatically.
  88. @item -mY
  89. disables warnings about missing NOP instructions.
  90. @item -md
  91. mark the object file as one that requires data to copied from ROM to
  92. RAM at execution startup. Disabled by default.
  93. @item -mdata-region=@var{region}
  94. Select the region data will be placed in.
  95. Region placement is performed by the compiler and linker. The only effect this
  96. option will have on the assembler is that if @var{upper} or @var{either} is
  97. selected, then the symbols to initialise high data and bss will be defined.
  98. Valid @var{region} values are:
  99. @table @code
  100. @item none
  101. @item lower
  102. @item upper
  103. @item either
  104. @end table
  105. @end table
  106. @node MSP430 Syntax
  107. @section Syntax
  108. @menu
  109. * MSP430-Macros:: Macros
  110. * MSP430-Chars:: Special Characters
  111. * MSP430-Regs:: Register Names
  112. * MSP430-Ext:: Assembler Extensions
  113. @end menu
  114. @node MSP430-Macros
  115. @subsection Macros
  116. @cindex Macros, MSP 430
  117. @cindex MSP 430 macros
  118. The macro syntax used on the MSP 430 is like that described in the MSP
  119. 430 Family Assembler Specification. Normal @code{@value{AS}}
  120. macros should still work.
  121. Additional built-in macros are:
  122. @table @code
  123. @item llo(exp)
  124. Extracts least significant word from 32-bit expression 'exp'.
  125. @item lhi(exp)
  126. Extracts most significant word from 32-bit expression 'exp'.
  127. @item hlo(exp)
  128. Extracts 3rd word from 64-bit expression 'exp'.
  129. @item hhi(exp)
  130. Extracts 4rd word from 64-bit expression 'exp'.
  131. @end table
  132. They normally being used as an immediate source operand.
  133. @smallexample
  134. mov #llo(1), r10 ; == mov #1, r10
  135. mov #lhi(1), r10 ; == mov #0, r10
  136. @end smallexample
  137. @node MSP430-Chars
  138. @subsection Special Characters
  139. @cindex line comment character, MSP 430
  140. @cindex MSP 430 line comment character
  141. A semicolon (@samp{;}) appearing anywhere on a line starts a comment
  142. that extends to the end of that line.
  143. If a @samp{#} appears as the first character of a line then the whole
  144. line is treated as a comment, but it can also be a logical line number
  145. directive (@pxref{Comments}) or a preprocessor control command
  146. (@pxref{Preprocessing}).
  147. @cindex line separator, MSP 430
  148. @cindex statement separator, MSP 430
  149. @cindex MSP 430 line separator
  150. Multiple statements can appear on the same line provided that they are
  151. separated by the @samp{@{} character.
  152. @cindex identifiers, MSP 430
  153. @cindex MSP 430 identifiers
  154. The character @samp{$} in jump instructions indicates current location and
  155. implemented only for TI syntax compatibility.
  156. @node MSP430-Regs
  157. @subsection Register Names
  158. @cindex MSP 430 register names
  159. @cindex register names, MSP 430
  160. General-purpose registers are represented by predefined symbols of the
  161. form @samp{r@var{N}} (for global registers), where @var{N} represents
  162. a number between @code{0} and @code{15}. The leading
  163. letters may be in either upper or lower case; for example, @samp{r13}
  164. and @samp{R7} are both valid register names.
  165. @cindex special purpose registers, MSP 430
  166. Register names @samp{PC}, @samp{SP} and @samp{SR} cannot be used as register names
  167. and will be treated as variables. Use @samp{r0}, @samp{r1}, and @samp{r2} instead.
  168. @node MSP430-Ext
  169. @subsection Assembler Extensions
  170. @cindex MSP430 Assembler Extensions
  171. @table @code
  172. @item @@rN
  173. As destination operand being treated as @samp{0(rn)}
  174. @item 0(rN)
  175. As source operand being treated as @samp{@@rn}
  176. @item jCOND +N
  177. Skips next N bytes followed by jump instruction and equivalent to
  178. @samp{jCOND $+N+2}
  179. @end table
  180. Also, there are some instructions, which cannot be found in other assemblers.
  181. These are branch instructions, which has different opcodes upon jump distance.
  182. They all got PC relative addressing mode.
  183. @table @code
  184. @item beq label
  185. A polymorph instruction which is @samp{jeq label} in case if jump distance
  186. within allowed range for cpu's jump instruction. If not, this unrolls into
  187. a sequence of
  188. @smallexample
  189. jne $+6
  190. br label
  191. @end smallexample
  192. @item bne label
  193. A polymorph instruction which is @samp{jne label} or @samp{jeq +4; br label}
  194. @item blt label
  195. A polymorph instruction which is @samp{jl label} or @samp{jge +4; br label}
  196. @item bltn label
  197. A polymorph instruction which is @samp{jn label} or @samp{jn +2; jmp +4; br label}
  198. @item bltu label
  199. A polymorph instruction which is @samp{jlo label} or @samp{jhs +2; br label}
  200. @item bge label
  201. A polymorph instruction which is @samp{jge label} or @samp{jl +4; br label}
  202. @item bgeu label
  203. A polymorph instruction which is @samp{jhs label} or @samp{jlo +4; br label}
  204. @item bgt label
  205. A polymorph instruction which is @samp{jeq +2; jge label} or @samp{jeq +6; jl +4; br label}
  206. @item bgtu label
  207. A polymorph instruction which is @samp{jeq +2; jhs label} or @samp{jeq +6; jlo +4; br label}
  208. @item bleu label
  209. A polymorph instruction which is @samp{jeq label; jlo label} or @samp{jeq +2; jhs +4; br label}
  210. @item ble label
  211. A polymorph instruction which is @samp{jeq label; jl label} or @samp{jeq +2; jge +4; br label}
  212. @item jump label
  213. A polymorph instruction which is @samp{jmp label} or @samp{br label}
  214. @end table
  215. @node MSP430 Floating Point
  216. @section Floating Point
  217. @cindex floating point, MSP 430 (@sc{ieee})
  218. @cindex MSP 430 floating point (@sc{ieee})
  219. The MSP 430 family uses @sc{ieee} 32-bit floating-point numbers.
  220. @node MSP430 Directives
  221. @section MSP 430 Machine Directives
  222. @cindex machine directives, MSP 430
  223. @cindex MSP 430 machine directives
  224. @table @code
  225. @cindex @code{file} directive, MSP 430
  226. @item .file
  227. This directive is ignored; it is accepted for compatibility with other
  228. MSP 430 assemblers.
  229. @quotation
  230. @emph{Warning:} in other versions of the @sc{gnu} assembler, @code{.file} is
  231. used for the directive called @code{.app-file} in the MSP 430 support.
  232. @end quotation
  233. @cindex @code{line} directive, MSP 430
  234. @item .line
  235. This directive is ignored; it is accepted for compatibility with other
  236. MSP 430 assemblers.
  237. @cindex @code{arch} directive, MSP 430
  238. @item .arch
  239. Sets the target microcontroller in the same way as the @option{-mmcu}
  240. command-line option.
  241. @cindex @code{cpu} directive, MSP 430
  242. @item .cpu
  243. Sets the target architecture in the same way as the @option{-mcpu}
  244. command-line option.
  245. @cindex @code{profiler} directive, MSP 430
  246. @item .profiler
  247. This directive instructs assembler to add new profile entry to the object file.
  248. @cindex @code{refsym} directive, MSP 430
  249. @item .refsym
  250. This directive instructs assembler to add an undefined reference to
  251. the symbol following the directive. The maximum symbol name length is
  252. 1023 characters. No relocation is created for this symbol; it will
  253. exist purely for pulling in object files from archives. Note that
  254. this reloc is not sufficient to prevent garbage collection; use a
  255. KEEP() directive in the linker file to preserve such objects.
  256. @cindex @code{mspabi_attribute} directive, MSP430
  257. @item .mspabi_attribute
  258. This directive tells the assembler what the MSPABI build attributes for this
  259. file are. This is used for validating the command line options passed to
  260. the assembler against the options the original source file was compiled with.
  261. The expected format is:
  262. @samp{.mspabi_attribute tag_name, tag_value}
  263. For example, to set the tag @code{OFBA_MSPABI_Tag_ISA} to @code{MSP430X}:
  264. @samp{.mspabi_attribute 4, 2}
  265. See the @cite{MSP430 EABI, document slaa534} for the details on tag names and
  266. values.
  267. @end table
  268. @node MSP430 Opcodes
  269. @section Opcodes
  270. @cindex MSP 430 opcodes
  271. @cindex opcodes for MSP 430
  272. @code{@value{AS}} implements all the standard MSP 430 opcodes. No
  273. additional pseudo-instructions are needed on this family.
  274. For information on the 430 machine instruction set, see @cite{MSP430
  275. User's Manual, document slau049d}, Texas Instrument, Inc.
  276. @node MSP430 Profiling Capability
  277. @section Profiling Capability
  278. @cindex MSP 430 profiling capability
  279. @cindex profiling capability for MSP 430
  280. It is a performance hit to use gcc's profiling approach for this tiny target.
  281. Even more -- jtag hardware facility does not perform any profiling functions.
  282. However we've got gdb's built-in simulator where we can do anything.
  283. We define new section @samp{.profiler} which holds all profiling information.
  284. We define new pseudo operation @samp{.profiler} which will instruct assembler to
  285. add new profile entry to the object file. Profile should take place at the
  286. present address.
  287. Pseudo operation format:
  288. @samp{.profiler flags,function_to_profile [, cycle_corrector, extra]}
  289. where:
  290. @table @code
  291. @table @code
  292. @samp{flags} is a combination of the following characters:
  293. @item s
  294. function entry
  295. @item x
  296. function exit
  297. @item i
  298. function is in init section
  299. @item f
  300. function is in fini section
  301. @item l
  302. library call
  303. @item c
  304. libc standard call
  305. @item d
  306. stack value demand
  307. @item I
  308. interrupt service routine
  309. @item P
  310. prologue start
  311. @item p
  312. prologue end
  313. @item E
  314. epilogue start
  315. @item e
  316. epilogue end
  317. @item j
  318. long jump / sjlj unwind
  319. @item a
  320. an arbitrary code fragment
  321. @item t
  322. extra parameter saved (a constant value like frame size)
  323. @end table
  324. @item function_to_profile
  325. a function address
  326. @item cycle_corrector
  327. a value which should be added to the cycle counter, zero if omitted.
  328. @item extra
  329. any extra parameter, zero if omitted.
  330. @end table
  331. For example:
  332. @smallexample
  333. .global fxx
  334. .type fxx,@@function
  335. fxx:
  336. .LFrameOffset_fxx=0x08
  337. .profiler "scdP", fxx ; function entry.
  338. ; we also demand stack value to be saved
  339. push r11
  340. push r10
  341. push r9
  342. push r8
  343. .profiler "cdpt",fxx,0, .LFrameOffset_fxx ; check stack value at this point
  344. ; (this is a prologue end)
  345. ; note, that spare var filled with
  346. ; the farme size
  347. mov r15,r8
  348. ...
  349. .profiler cdE,fxx ; check stack
  350. pop r8
  351. pop r9
  352. pop r10
  353. pop r11
  354. .profiler xcde,fxx,3 ; exit adds 3 to the cycle counter
  355. ret ; cause 'ret' insn takes 3 cycles
  356. @end smallexample