No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

hace 3 años
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- This file documents the GNU Assembler "as".
  4. Copyright (C) 1991-2020 Free Software Foundation, Inc.
  5. Permission is granted to copy, distribute and/or modify this document
  6. under the terms of the GNU Free Documentation License, Version 1.3
  7. or any later version published by the Free Software Foundation;
  8. with no Invariant Sections, with no Front-Cover Texts, and with no
  9. Back-Cover Texts. A copy of the license is included in the
  10. section entitled "GNU Free Documentation License".
  11. -->
  12. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  13. <head>
  14. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  15. <title>BPF Opcodes (Using as)</title>
  16. <meta name="description" content="BPF Opcodes (Using as)">
  17. <meta name="keywords" content="BPF Opcodes (Using as)">
  18. <meta name="resource-type" content="document">
  19. <meta name="distribution" content="global">
  20. <meta name="Generator" content="makeinfo">
  21. <link href="index.html#Top" rel="start" title="Top">
  22. <link href="AS-Index.html#AS-Index" rel="index" title="AS Index">
  23. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  24. <link href="BPF_002dDependent.html#BPF_002dDependent" rel="up" title="BPF-Dependent">
  25. <link href="CR16_002dDependent.html#CR16_002dDependent" rel="next" title="CR16-Dependent">
  26. <link href="BPF-Directives.html#BPF-Directives" rel="prev" title="BPF Directives">
  27. <style type="text/css">
  28. <!--
  29. a.summary-letter {text-decoration: none}
  30. blockquote.indentedblock {margin-right: 0em}
  31. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  32. blockquote.smallquotation {font-size: smaller}
  33. div.display {margin-left: 3.2em}
  34. div.example {margin-left: 3.2em}
  35. div.lisp {margin-left: 3.2em}
  36. div.smalldisplay {margin-left: 3.2em}
  37. div.smallexample {margin-left: 3.2em}
  38. div.smalllisp {margin-left: 3.2em}
  39. kbd {font-style: oblique}
  40. pre.display {font-family: inherit}
  41. pre.format {font-family: inherit}
  42. pre.menu-comment {font-family: serif}
  43. pre.menu-preformatted {font-family: serif}
  44. pre.smalldisplay {font-family: inherit; font-size: smaller}
  45. pre.smallexample {font-size: smaller}
  46. pre.smallformat {font-family: inherit; font-size: smaller}
  47. pre.smalllisp {font-size: smaller}
  48. span.nolinebreak {white-space: nowrap}
  49. span.roman {font-family: initial; font-weight: normal}
  50. span.sansserif {font-family: sans-serif; font-weight: normal}
  51. ul.no-bullet {list-style: none}
  52. -->
  53. </style>
  54. </head>
  55. <body lang="en">
  56. <a name="BPF-Opcodes"></a>
  57. <div class="header">
  58. <p>
  59. Previous: <a href="BPF-Directives.html#BPF-Directives" accesskey="p" rel="prev">BPF Directives</a>, Up: <a href="BPF_002dDependent.html#BPF_002dDependent" accesskey="u" rel="up">BPF-Dependent</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="AS-Index.html#AS-Index" title="Index" rel="index">Index</a>]</p>
  60. </div>
  61. <hr>
  62. <a name="Opcodes-5"></a>
  63. <h4 class="subsection">9.7.4 Opcodes</h4>
  64. <a name="index-BPF-opcodes"></a>
  65. <a name="index-opcodes-for-BPF"></a>
  66. <p>In the instruction descriptions below the following field descriptors
  67. are used:
  68. </p>
  69. <dl compact="compact">
  70. <dt><code>%d</code></dt>
  71. <dd><p>Destination general-purpose register whose role is to be destination
  72. of an operation.
  73. </p></dd>
  74. <dt><code>%s</code></dt>
  75. <dd><p>Source general-purpose register whose role is to be the source of an
  76. operation.
  77. </p></dd>
  78. <dt><code>disp16</code></dt>
  79. <dd><p>16-bit signed PC-relative offset, measured in number of 64-bit words,
  80. minus one.
  81. </p></dd>
  82. <dt><code>disp32</code></dt>
  83. <dd><p>32-bit signed PC-relative offset, measured in number of 64-bit words,
  84. minus one.
  85. </p></dd>
  86. <dt><code>offset16</code></dt>
  87. <dd><p>Signed 16-bit immediate.
  88. </p></dd>
  89. <dt><code>imm32</code></dt>
  90. <dd><p>Signed 32-bit immediate.
  91. </p></dd>
  92. <dt><code>imm64</code></dt>
  93. <dd><p>Signed 64-bit immediate.
  94. </p></dd>
  95. </dl>
  96. <a name="Arithmetic-instructions"></a>
  97. <h4 class="subsubsection">9.7.4.1 Arithmetic instructions</h4>
  98. <p>The destination register in these instructions act like an
  99. accumulator.
  100. </p>
  101. <dl compact="compact">
  102. <dt><code>add %d, (%s|imm32)</code></dt>
  103. <dd><p>64-bit arithmetic addition.
  104. </p></dd>
  105. <dt><code>sub %d, (%s|imm32)</code></dt>
  106. <dd><p>64-bit arithmetic subtraction.
  107. </p></dd>
  108. <dt><code>mul %d, (%s|imm32)</code></dt>
  109. <dd><p>64-bit arithmetic multiplication.
  110. </p></dd>
  111. <dt><code>div %d, (%s|imm32)</code></dt>
  112. <dd><p>64-bit arithmetic integer division.
  113. </p></dd>
  114. <dt><code>mod %d, (%s|imm32)</code></dt>
  115. <dd><p>64-bit integer remainder.
  116. </p></dd>
  117. <dt><code>and %d, (%s|imm32)</code></dt>
  118. <dd><p>64-bit bit-wise &ldquo;and&rdquo; operation.
  119. </p></dd>
  120. <dt><code>or %d, (%s|imm32)</code></dt>
  121. <dd><p>64-bit bit-wise &ldquo;or&rdquo; operation.
  122. </p></dd>
  123. <dt><code>xor %d, (%s|imm32)</code></dt>
  124. <dd><p>64-bit bit-wise exclusive-or operation.
  125. </p></dd>
  126. <dt><code>lsh %d, (%s|imm32)</code></dt>
  127. <dd><p>64-bit left shift, by <code>%s</code> or <code>imm32</code> bits.
  128. </p></dd>
  129. <dt><code>rsh %d, (%s|imm32)</code></dt>
  130. <dd><p>64-bit right logical shift, by <code>%s</code> or <code>imm32</code> bits.
  131. </p></dd>
  132. <dt><code>arsh %d, (%s|imm32)</code></dt>
  133. <dd><p>64-bit right arithmetic shift, by <code>%s</code> or <code>imm32</code> bits.
  134. </p></dd>
  135. <dt><code>neg %d</code></dt>
  136. <dd><p>64-bit arithmetic negation.
  137. </p></dd>
  138. <dt><code>mov %d, (%s|imm32)</code></dt>
  139. <dd><p>Move the 64-bit value of <code>%s</code> in <code>%d</code>, or load <code>imm32</code>
  140. in <code>%d</code>.
  141. </p></dd>
  142. </dl>
  143. <a name="g_t32_002dbit-arithmetic-instructions"></a>
  144. <h4 class="subsubsection">9.7.4.2 32-bit arithmetic instructions</h4>
  145. <p>The destination register in these instructions act as an accumulator.
  146. </p>
  147. <dl compact="compact">
  148. <dt><code>add32 %d, (%s|imm32)</code></dt>
  149. <dd><p>32-bit arithmetic addition.
  150. </p></dd>
  151. <dt><code>sub32 %d, (%s|imm32)</code></dt>
  152. <dd><p>32-bit arithmetic subtraction.
  153. </p></dd>
  154. <dt><code>mul32 %d, (%s|imm32)</code></dt>
  155. <dd><p>32-bit arithmetic multiplication.
  156. </p></dd>
  157. <dt><code>div32 %d, (%s|imm32)</code></dt>
  158. <dd><p>32-bit arithmetic integer division.
  159. </p></dd>
  160. <dt><code>mod32 %d, (%s|imm32)</code></dt>
  161. <dd><p>32-bit integer remainder.
  162. </p></dd>
  163. <dt><code>and32 %d, (%s|imm32)</code></dt>
  164. <dd><p>32-bit bit-wise &ldquo;and&rdquo; operation.
  165. </p></dd>
  166. <dt><code>or32 %d, (%s|imm32)</code></dt>
  167. <dd><p>32-bit bit-wise &ldquo;or&rdquo; operation.
  168. </p></dd>
  169. <dt><code>xor32 %d, (%s|imm32)</code></dt>
  170. <dd><p>32-bit bit-wise exclusive-or operation.
  171. </p></dd>
  172. <dt><code>lsh32 %d, (%s|imm32)</code></dt>
  173. <dd><p>32-bit left shift, by <code>%s</code> or <code>imm32</code> bits.
  174. </p></dd>
  175. <dt><code>rsh32 %d, (%s|imm32)</code></dt>
  176. <dd><p>32-bit right logical shift, by <code>%s</code> or <code>imm32</code> bits.
  177. </p></dd>
  178. <dt><code>arsh32 %d, (%s|imm32)</code></dt>
  179. <dd><p>32-bit right arithmetic shift, by <code>%s</code> or <code>imm32</code> bits.
  180. </p></dd>
  181. <dt><code>neg32 %d</code></dt>
  182. <dd><p>32-bit arithmetic negation.
  183. </p></dd>
  184. <dt><code>mov32 %d, (%s|imm32)</code></dt>
  185. <dd><p>Move the 32-bit value of <code>%s</code> in <code>%d</code>, or load <code>imm32</code>
  186. in <code>%d</code>.
  187. </p></dd>
  188. </dl>
  189. <a name="Endianness-conversion-instructions"></a>
  190. <h4 class="subsubsection">9.7.4.3 Endianness conversion instructions</h4>
  191. <dl compact="compact">
  192. <dt><code>endle %d, (8|16|32)</code></dt>
  193. <dd><p>Convert the 8-bit, 16-bit or 32-bit value in <code>%d</code> to
  194. little-endian.
  195. </p></dd>
  196. <dt><code>endbe %d, (8|16|32)</code></dt>
  197. <dd><p>Convert the 8-bit, 16-bit or 32-bit value in <code>%d</code> to big-endian.
  198. </p></dd>
  199. </dl>
  200. <a name="g_t64_002dbit-load-and-pseudo-maps"></a>
  201. <h4 class="subsubsection">9.7.4.4 64-bit load and pseudo maps</h4>
  202. <dl compact="compact">
  203. <dt><code>lddw %d, imm64</code></dt>
  204. <dd><p>Load the given signed 64-bit immediate, or pseudo map descriptor, to
  205. the destination register <code>%d</code>.
  206. </p></dd>
  207. <dt><code>lddw %d, %map_fd(N)</code></dt>
  208. <dd><p>Load the address of the given pseudo map fd <em>N</em> to the
  209. destination register <code>%d</code>.
  210. </p></dd>
  211. </dl>
  212. <a name="Load-instructions-for-socket-filters"></a>
  213. <h4 class="subsubsection">9.7.4.5 Load instructions for socket filters</h4>
  214. <p>The following instructions are intended to be used in socket filters,
  215. and are therefore not general-purpose: they make assumptions on the
  216. contents of several registers. See the file
  217. <samp>Documentation/networking/filter.txt</samp> in the Linux kernel source
  218. tree for more information.
  219. </p>
  220. <p>Absolute loads:
  221. </p>
  222. <dl compact="compact">
  223. <dt><code>ldabsdw imm32</code></dt>
  224. <dd><p>Absolute 64-bit load.
  225. </p></dd>
  226. <dt><code>ldabsw imm32</code></dt>
  227. <dd><p>Absolute 32-bit load.
  228. </p></dd>
  229. <dt><code>ldabsh imm32</code></dt>
  230. <dd><p>Absolute 16-bit load.
  231. </p></dd>
  232. <dt><code>ldabsb imm32</code></dt>
  233. <dd><p>Absolute 8-bit load.
  234. </p></dd>
  235. </dl>
  236. <p>Indirect loads:
  237. </p>
  238. <dl compact="compact">
  239. <dt><code>ldinddw %s, imm32</code></dt>
  240. <dd><p>Indirect 64-bit load.
  241. </p></dd>
  242. <dt><code>ldindw %s, imm32</code></dt>
  243. <dd><p>Indirect 32-bit load.
  244. </p></dd>
  245. <dt><code>ldindh %s, imm32</code></dt>
  246. <dd><p>Indirect 16-bit load.
  247. </p></dd>
  248. <dt><code>ldindb %s, imm32</code></dt>
  249. <dd><p>Indirect 8-bit load.
  250. </p></dd>
  251. </dl>
  252. <a name="Generic-load_002fstore-instructions"></a>
  253. <h4 class="subsubsection">9.7.4.6 Generic load/store instructions</h4>
  254. <p>General-purpose load and store instructions are provided for several
  255. word sizes.
  256. </p>
  257. <p>Load to register instructions:
  258. </p>
  259. <dl compact="compact">
  260. <dt><code>ldxdw %d, [%s+offset16]</code></dt>
  261. <dd><p>Generic 64-bit load.
  262. </p></dd>
  263. <dt><code>ldxw %d, [%s+offset16]</code></dt>
  264. <dd><p>Generic 32-bit load.
  265. </p></dd>
  266. <dt><code>ldxh %d, [%s+offset16]</code></dt>
  267. <dd><p>Generic 16-bit load.
  268. </p></dd>
  269. <dt><code>ldxb %d, [%s+offset16]</code></dt>
  270. <dd><p>Generic 8-bit load.
  271. </p></dd>
  272. </dl>
  273. <p>Store from register instructions:
  274. </p>
  275. <dl compact="compact">
  276. <dt><code>stxdw [%d+offset16], %s</code></dt>
  277. <dd><p>Generic 64-bit store.
  278. </p></dd>
  279. <dt><code>stxw [%d+offset16], %s</code></dt>
  280. <dd><p>Generic 32-bit store.
  281. </p></dd>
  282. <dt><code>stxh [%d+offset16], %s</code></dt>
  283. <dd><p>Generic 16-bit store.
  284. </p></dd>
  285. <dt><code>stxb [%d+offset16], %s</code></dt>
  286. <dd><p>Generic 8-bit store.
  287. </p></dd>
  288. </dl>
  289. <p>Store from immediates instructions:
  290. </p>
  291. <dl compact="compact">
  292. <dt><code>stddw [%d+offset16], imm32</code></dt>
  293. <dd><p>Store immediate as 64-bit.
  294. </p></dd>
  295. <dt><code>stdw [%d+offset16], imm32</code></dt>
  296. <dd><p>Store immediate as 32-bit.
  297. </p></dd>
  298. <dt><code>stdh [%d+offset16], imm32</code></dt>
  299. <dd><p>Store immediate as 16-bit.
  300. </p></dd>
  301. <dt><code>stdb [%d+offset16], imm32</code></dt>
  302. <dd><p>Store immediate as 8-bit.
  303. </p></dd>
  304. </dl>
  305. <a name="Jump-instructions"></a>
  306. <h4 class="subsubsection">9.7.4.7 Jump instructions</h4>
  307. <p>eBPF provides the following compare-and-jump instructions, which
  308. compare the values of the two given registers, or the values of a
  309. register and an immediate, and perform a branch in case the comparison
  310. holds true.
  311. </p>
  312. <dl compact="compact">
  313. <dt><code>ja %d,(%s|imm32),disp16</code></dt>
  314. <dd><p>Jump-always.
  315. </p></dd>
  316. <dt><code>jeq %d,(%s|imm32),disp16</code></dt>
  317. <dd><p>Jump if equal.
  318. </p></dd>
  319. <dt><code>jgt %d,(%s|imm32),disp16</code></dt>
  320. <dd><p>Jump if greater.
  321. </p></dd>
  322. <dt><code>jge %d,(%s|imm32),disp16</code></dt>
  323. <dd><p>Jump if greater or equal.
  324. </p></dd>
  325. <dt><code>jlt %d,(%s|imm32),disp16</code></dt>
  326. <dd><p>Jump if lesser.
  327. </p></dd>
  328. <dt><code>jle %d,(%s|imm32),disp16</code></dt>
  329. <dd><p>Jump if lesser or equal.
  330. </p></dd>
  331. <dt><code>jset %d,(%s|imm32),disp16</code></dt>
  332. <dd><p>Jump if signed equal.
  333. </p></dd>
  334. <dt><code>jne %d,(%s|imm32),disp16</code></dt>
  335. <dd><p>Jump if not equal.
  336. </p></dd>
  337. <dt><code>jsgt %d,(%s|imm32),disp16</code></dt>
  338. <dd><p>Jump if signed greater.
  339. </p></dd>
  340. <dt><code>jsge %d,(%s|imm32),disp16</code></dt>
  341. <dd><p>Jump if signed greater or equal.
  342. </p></dd>
  343. <dt><code>jslt %d,(%s|imm32),disp16</code></dt>
  344. <dd><p>Jump if signed lesser.
  345. </p></dd>
  346. <dt><code>jsle %d,(%s|imm32),disp16</code></dt>
  347. <dd><p>Jump if signed lesser or equal.
  348. </p></dd>
  349. </dl>
  350. <p>A call instruction is provided in order to perform calls to other eBPF
  351. functions, or to external kernel helpers:
  352. </p>
  353. <dl compact="compact">
  354. <dt><code>call (disp32|imm32)</code></dt>
  355. <dd><p>Jump and link to the offset <em>disp32</em>, or to the kernel helper
  356. function identified by <em>imm32</em>.
  357. </p></dd>
  358. </dl>
  359. <p>Finally:
  360. </p>
  361. <dl compact="compact">
  362. <dt><code>exit</code></dt>
  363. <dd><p>Terminate the eBPF program.
  364. </p></dd>
  365. </dl>
  366. <a name="Atomic-instructions"></a>
  367. <h4 class="subsubsection">9.7.4.8 Atomic instructions</h4>
  368. <p>Atomic exchange-and-add instructions are provided in two flavors: one
  369. for swapping 64-bit quantities and another for 32-bit quantities.
  370. </p>
  371. <dl compact="compact">
  372. <dt><code>xadddw [%d+offset16],%s</code></dt>
  373. <dd><p>Exchange-and-add a 64-bit value at the specified location.
  374. </p></dd>
  375. <dt><code>xaddw [%d+offset16],%s</code></dt>
  376. <dd><p>Exchange-and-add a 32-bit value at the specified location.
  377. </p></dd>
  378. </dl>
  379. <hr>
  380. <div class="header">
  381. <p>
  382. Previous: <a href="BPF-Directives.html#BPF-Directives" accesskey="p" rel="prev">BPF Directives</a>, Up: <a href="BPF_002dDependent.html#BPF_002dDependent" accesskey="u" rel="up">BPF-Dependent</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="AS-Index.html#AS-Index" title="Index" rel="index">Index</a>]</p>
  383. </div>
  384. </body>
  385. </html>