[gdb/testsuite] Fix unterminated string in gdb.objc/basicclass.exp
[deliverable/binutils-gdb.git] / cpu / bpf.cpu
CommitLineData
ea195bb0
JM
1;; Linux BPF CPU description -*- Scheme -*-
2;; Copyright (C) 2019 Free Software Foundation, Inc.
3;;
4;; Contributed by Oracle Inc.
5;;
6;; This file is part of the GNU Binutils and of GDB.
7;;
8;; This program is free software; you can redistribute it and/or
9;; modify it under the terms of the GNU General Public License as
10;; published by the Free Software Foundation; either version 3 of the
11;; License, or (at your option) any later version.
12;;
13;; This program is distributed in the hope that it will be useful, but
14;; WITHOUT ANY WARRANTY; without even the implied warranty of
15;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16;; General Public License for more details.
17;;
18;; You should have received a copy of the GNU General Public License
19;; along with this program; if not, write to the Free Software
20;; Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
21;; 02110-1301, USA.
22
23;; This file contains a CGEN CPU description for the Linux kernel eBPF
24;; instruction set. eBPF is documented in the linux kernel source
25;; tree. See linux/Documentation/networking/filter.txt, and also the
26;; sources in the networking subsystem, notably
27;; linux/net/core/filter.c.
28
29(include "simplify.inc")
30
31(define-arch
32 (name bpf)
33 (comment "Linux kernel BPF")
34 (insn-lsb0? #t)
35 (machs bpf)
36 (isas ebpfle ebpfbe))
37
38;;;; The ISAs
39
40;; Logically, eBPF comforms a single instruction set featuring two
41;; kind of instructions: 64-bit instructions and 128-bit instructions.
42;;
43;; The 64-bit instructions have the form:
44;;
45;; code:8 regs:8 offset:16 imm:32
46;;
47;; Whereas the 128-bit instructions (at the moment there is only one
48;; of such instructions, lddw) have the form:
49;;
50;; code:8 regs:8 offset:16 imm:32 imm:32 unused:32
51;;
52;; In both formats `regs' is itself composed by two fields:
53;;
54;; dst:4 src:4
55;;
56;; The ISA is supposed to be orthogonal to endianness: the endianness
57;; of the instruction fields follow the endianness of the host running
58;; the eBPF program, and that's all. However, this is not entirely
59;; true. The definition of an eBPF code in the Linux kernel is:
60;;
61;; struct bpf_insn {
62;; __u8 code; /* opcode */
63;; __u8 dst_reg:4; /* dest register */
64;; __u8 src_reg:4; /* source register */
65;; __s16 off; /* signed offset */
66;; __s32 imm; /* signed immediate constant */
67;; };
68;;
69;; Since the ordering of fields in C bitmaps is defined by the
70;; implementation, the impact of endianness in the encoding of eBPF
71;; instructions is effectively defined by GCC. In particular, GCC
72;; places dst_reg before src_reg in little-endian code, and the other
73;; way around in big-endian code.
74;;
75;; So, in reality, eBPF comprises two instruction sets: one for
76;; little-endian with instructions like:
77;;
78;; code:8 src:4 dst:4 offset:16 imm:32 [unused:32 imm:32]
79;;
80;; and another for big-endian with instructions like:
81;;
82;; code:8 dst:4 src:4 offset:16 imm:32 [unused:32 imm:32]
83;;
84;; where `offset' and the immediate fields are encoded in
85;; little-endian and big-endian byte-order, respectively.
86
87(define-pmacro (define-bpf-isa x-endian)
88 (define-isa
89 (name (.sym ebpf x-endian))
90 (comment "The eBPF instruction set")
91 ;; Default length to record in ifields. This is used in
92 ;; calculations involving bit numbers.
93 (default-insn-word-bitsize 64)
94 ;; Length of an unknown instruction. Used by disassembly and by the
95 ;; simulator's invalid insn handler.
96 (default-insn-bitsize 64)
97 ;; Number of bits of insn that can be initially fetched. XXX this
98 ;; should be 64 (the size of the smallest insn) but until CGEN
99 ;; gets fixed to place constant fields in their own words, we have
100 ;; to use this workaround to avoid the opcode byte to be placed at
101 ;; the wrong side of the instruction when assembling in
102 ;; big-endian.
103 (base-insn-bitsize 8)))
104
105(define-bpf-isa le)
106(define-bpf-isa be)
107
108(define-pmacro all-isas () (ISA ebpfle,ebpfbe))
109
110;;;; Hardware Hierarchy
111
112;;
113;; bpf architecture
114;; |
115;; bpfbf cpu-family
116;; |
117;; bpf machine
118;; |
119;; bpf-def model
120
121(define-cpu
122 (name bpfbf)
123 (comment "Linux kernel eBPF virtual CPU")
124 (word-bitsize 32))
125
126(define-mach
127 (name bpf)
128 (comment "Linux eBPF")
129 (cpu bpfbf)
130 (isas ebpfle ebpfbe))
131
132(define-model
133 (name bpf-def)
134 (comment "Linux eBPF default model")
135 (mach bpf)
136 (unit u-exec "execution unit" ()
137 1 ; issue
138 1 ; done
139 () ; state
140 () ; inputs
141 () ; outputs
142 () ; profile action (default)
143 ))
144
145;;;; Hardware Elements
146
147;; eBPF programs can access 10 general-purpose registers which are
148;; 64-bit.
149
150(define-hardware
151 (name h-gpr)
152 (comment "General Purpose Registers")
153 (attrs all-isas (MACH bpf))
154 (type register DI (16))
155 (indices keyword "%"
156 ;; XXX the frame pointer fp is read-only, so it should
157 ;; go in a different hardware.
158 (;; ABI names. Take priority when disassembling.
159 (a 0) (r1 1) (r2 2) (r3 3) (r4 4) (r5 5) (ctx 6)
160 (r7 7) (r8 8) (r9 9) (fp 10)
161 ;; Additional names recognized when assembling.
162 (r0 0) (r6 6) (r10 10))))
163
164;; The program counter. CGEN requires it, even if it is not visible
165;; to eBPF programs.
166
167(dnh h-pc "program counter" (PC PROFILE) (pc) () () ())
168
169;; A 64-bit h-sint to be used by the imm64 operand below. XXX this
170;; shouldn't be needed, as h-sint is supposed to be able to hold
171;; 64-bit values. However, in practice CGEN limits h-sint to 32 bits
172;; in 32-bit hosts. To be fixed in CGEN.
173
174(dnh h-sint64 "signed 64-bit integer" (all-isas) (immediate DI)
175 () () ())
176
177;;;; The Instruction Sets
178
179;;; Fields and Opcodes
180
181;; Convenience macro to shorten the definition of the fields below.
182(define-pmacro (dwf x-name x-comment x-attrs
183 x-word-offset x-word-length x-start x-length
184 x-mode)
185 "Define a field including its containing word."
186 (define-ifield
187 (name x-name)
188 (comment x-comment)
189 (.splice attrs (.unsplice x-attrs))
190 (word-offset x-word-offset)
191 (word-length x-word-length)
192 (start x-start)
193 (length x-length)
194 (mode x-mode)))
195
196;; For arithmetic and jump instructions the 8-bit code field is
197;; subdivided in:
198;;
199;; op-code:4 op-src:1 op-class:3
200
201(dwf f-op-code "eBPF opcode code" (all-isas) 0 8 7 4 UINT)
202(dwf f-op-src "eBPF opcode source" (all-isas) 0 8 3 1 UINT)
203(dwf f-op-class "eBPF opcode instruction class" (all-isas) 0 8 2 3 UINT)
204
205(define-normal-insn-enum insn-op-code-alu "eBPF instruction codes"
206 (all-isas) OP_CODE_ f-op-code
207 (;; Codes for OP_CLASS_ALU and OP_CLASS_ALU64
208 (ADD #x0) (SUB #x1) (MUL #x2) (DIV #x3) (OR #x4) (AND #x5)
209 (LSH #x6) (RSH #x7) (NEG #x8) (MOD #x9) (XOR #xa) (MOV #xb)
210 (ARSH #xc) (END #xd)
211 ;; Codes for OP_CLASS_JMP
212 (JA #x0) (JEQ #x1) (JGT #x2) (JGE #x3) (JSET #x4)
213 (JNE #x5) (JSGT #x6) (JSGE #x7) (CALL #x8) (EXIT #x9)
214 (JLT #xa) (JLE #xb) (JSLT #xc) (JSLE #xd)))
215
216(define-normal-insn-enum insn-op-src "eBPF instruction source"
217 (all-isas) OP_SRC_ f-op-src
218 ;; X => use `src' as source operand.
219 ;; K => use `imm32' as source operand.
220 ((K #b0) (X #b1)))
221
222(define-normal-insn-enum insn-op-class "eBPF instruction class"
223 (all-isas) OP_CLASS_ f-op-class
224 ((LD #b000) (LDX #b001) (ST #b010) (STX #b011)
225 (ALU #b100) (JMP #b101) (ALU64 #b111)))
226
227;; For load/store instructions, the 8-bit code field is subdivided in:
228;;
229;; op-mode:3 op-size:2 op-class:3
230
231(dwf f-op-mode "eBPF opcode mode" (all-isas) 0 8 7 3 UINT)
232(dwf f-op-size "eBPF opcode size" (all-isas) 0 8 4 2 UINT)
233
234(define-normal-insn-enum insn-op-mode "eBPF load/store instruction modes"
235 (all-isas) OP_MODE_ f-op-mode
236 ((IMM #b000) (ABS #b001) (IND #b010) (MEM #b011)
237 ;; #b100 and #b101 are used in classic BPF only, reserved in eBPF.
238 (XADD #b110)))
239
240(define-normal-insn-enum insn-op-size "eBPF load/store instruction sizes"
241 (all-isas) OP_SIZE_ f-op-size
242 ((W #b00) ;; Word: 4 byte
243 (H #b01) ;; Half-word: 2 byte
244 (B #b10) ;; Byte: 1 byte
245 (DW #b11))) ;; Double-word: 8 byte
246
247;; The fields for the source and destination registers are a bit
248;; tricky. Due to the bizarre nibble swap between little-endian and
249;; big-endian ISAs we need to keep different variants of the fields.
250;;
251;; Note that f-regs is used in the format spec of instructions that do
252;; NOT use registers, where endianness is irrelevant i.e. f-regs is a
253;; constant 0 opcode.
254
255(dwf f-dstle "eBPF dst register field" ((ISA ebpfle)) 8 8 3 4 UINT)
256(dwf f-srcle "eBPF source register field" ((ISA ebpfle)) 8 8 7 4 UINT)
257
258(dwf f-dstbe "eBPF dst register field" ((ISA ebpfbe)) 8 8 7 4 UINT)
259(dwf f-srcbe "eBPF source register field" ((ISA ebpfbe)) 8 8 3 4 UINT)
260
261(dwf f-regs "eBPF registers field" (all-isas) 8 8 7 8 UINT)
262
263;; Finally, the fields for the immediates.
264;;
265;; The 16-bit offsets and 32-bit immediates do not present any special
266;; difficulty: we put them in their own instruction word so the
267;; byte-endianness will be properly applied.
268
269(dwf f-offset16 "eBPF offset field" (all-isas) 16 16 15 16 INT)
270(dwf f-imm32 "eBPF 32-bit immediate field" (all-isas) 32 32 31 32 INT)
271
272;; For the disjoint 64-bit signed immediate, however, we need to use a
273;; multi-ifield.
274
275(dwf f-imm64-a "eBPF 64-bit immediate a" (all-isas) 32 32 31 32 UINT)
276(dwf f-imm64-b "eBPF 64-bit immediate b" (all-isas) 64 32 31 32 UINT)
277(dwf f-imm64-c "eBPF 64-bit immediate c" (all-isas) 96 32 31 32 UINT)
278
279(define-multi-ifield
280 (name f-imm64)
281 (comment "eBPF 64-bit immediate field")
282 (attrs all-isas)
283 (mode DI)
284 (subfields f-imm64-a f-imm64-b f-imm64-c)
285 (insert (sequence ()
286 (set (ifield f-imm64-b) (const 0))
287 (set (ifield f-imm64-c) (srl (ifield f-imm64) (const 32)))
288 (set (ifield f-imm64-a) (and (ifield f-imm64) (const #xffffffff)))))
289 (extract (sequence ()
290 (set (ifield f-imm64)
291 (or (sll DI (zext DI (ifield f-imm64-c)) (const 32))
292 (zext DI (ifield f-imm64-a)))))))
293
294;;; Operands
295
296;; A couple of source and destination register operands are defined
297;; for each ISA: ebpfle and ebpfbe.
298
299(dno dstle "destination register" ((ISA ebpfle)) h-gpr f-dstle)
300(dno srcle "source register" ((ISA ebpfle)) h-gpr f-srcle)
301
302(dno dstbe "destination register" ((ISA ebpfbe)) h-gpr f-dstbe)
303(dno srcbe "source register" ((ISA ebpfbe)) h-gpr f-srcbe)
304
305;; Jump instructions have a 16-bit PC-relative address.
306;; CALL instructions have a 32-bit PC-relative address.
307
308(dno disp16 "16-bit PC-relative address" (all-isas PCREL-ADDR) h-sint
309 f-offset16)
310(dno disp32 "32-bit PC-relative address" (all-isas PCREL-ADDR) h-sint
311 f-imm32)
312
313;; Immediate operands in eBPF are signed, and we want the disassembler
314;; to print negative values in a sane way. Therefore we use the macro
315;; below to register a printer, which is itself defined as a C
316;; function in bpf.opc.
317
318;; define-normal-signed-immediate-operand
319(define-pmacro (dnsio x-name x-comment x-attrs x-type x-index)
320 (define-operand
321 (name x-name)
322 (comment x-comment)
323 (.splice attrs (.unsplice x-attrs))
324 (type x-type)
325 (index x-index)
326 (handlers (print "immediate"))))
327
328(dnsio imm32 "32-bit immediate" (all-isas) h-sint f-imm32)
329(dnsio offset16 "16-bit offset" (all-isas) h-sint f-offset16)
330
331;; The 64-bit immediate cannot use the default
332;; cgen_parse_signed_integer, because it assumes operands are at much
333;; 32-bit wide. Use our own.
334
335(define-operand
336 (name imm64)
337 (comment "64-bit immediate")
338 (attrs all-isas)
339 (type h-sint64)
340 (index f-imm64)
341 (handlers (parse "imm64") (print "immediate")))
342
343;; The endle/endbe instructions take an operand to specify the word
344;; width in endianness conversions. We use both a parser and printer,
345;; which are defined as C functions in bpf.opc.
346
347(define-operand
348 (name endsize)
349 (comment "endianness size immediate: 16, 32 or 64")
350 (attrs all-isas)
351 (type h-uint)
352 (index f-imm32)
353 (handlers (parse "endsize") (print "endsize")))
354
355;;; ALU instructions
356
357;; For each opcode in insn-op-code-alu representing and integer
358;; arithmetic instruction (ADD, SUB, etc) we define a bunch of
359;; instruction variants:
360;;
361;; ADD[32]{i,r}le for the little-endian ISA
362;; ADD[32]{i,r}be for the big-endian ISA
363;;
364;; The `i' variants perform `src OP dst -> dst' operations.
365;; The `r' variants perform `dst OP imm32 -> dst' operations.
366;;
367;; The variants with 32 in their name are of ALU class. Otherwise
368;; they are ALU64 class.
369
370(define-pmacro (define-alu-insn-un x-basename x-suffix x-op-class x-op-code x-endian)
371 (dni (.sym x-basename x-suffix x-endian)
372 (.str x-basename x-suffix)
373 ((ISA (.sym ebpf x-endian)))
374 (.str x-basename x-suffix " $dst" x-endian)
375 (+ (f-imm32 0) (f-offset16 0) ((.sym f-src x-endian) 0) (.sym dst x-endian)
376 x-op-class OP_SRC_X x-op-code) () ()))
377
378(define-pmacro (define-alu-insn-bin x-basename x-suffix x-op-class x-op-code x-endian)
379 (begin
380 (dni (.sym x-basename x-suffix "i" x-endian)
381 (.str x-basename x-suffix " immediate")
382 ((ISA (.sym ebpf x-endian)))
383 (.str x-basename x-suffix " $dst" x-endian ",$imm32")
384 (+ imm32 (f-offset16 0) ((.sym f-src x-endian) 0) (.sym dst x-endian)
385 x-op-class OP_SRC_K x-op-code) () ())
386 (dni (.sym x-basename x-suffix "r" x-endian)
387 (.str x-basename x-suffix " register")
388 ((ISA (.sym ebpf x-endian)))
389 (.str x-basename x-suffix " $dst" x-endian ",$src" x-endian)
390 (+ (f-imm32 0) (f-offset16 0) (.sym src x-endian) (.sym dst x-endian)
391 x-op-class OP_SRC_X x-op-code) () ())))
392
393(define-pmacro (daiu x-basename x-op-code x-endian)
394 (begin
395 (define-alu-insn-un x-basename "" OP_CLASS_ALU64 x-op-code x-endian)
396 (define-alu-insn-un x-basename "32" OP_CLASS_ALU x-op-code x-endian)))
397
398(define-pmacro (daib x-basename x-op-code x-endian)
399 (begin
400 (define-alu-insn-bin x-basename "" OP_CLASS_ALU64 x-op-code x-endian)
401 (define-alu-insn-bin x-basename "32" OP_CLASS_ALU x-op-code x-endian)))
402
403(define-pmacro (define-alu-instructions x-endian)
404 (begin
405 (daib add OP_CODE_ADD x-endian)
406 (daib sub OP_CODE_SUB x-endian)
407 (daib mul OP_CODE_MUL x-endian)
408 (daib div OP_CODE_DIV x-endian)
409 (daib or OP_CODE_OR x-endian)
410 (daib and OP_CODE_AND x-endian)
411 (daib lsh OP_CODE_LSH x-endian)
412 (daib rsh OP_CODE_RSH x-endian)
413 (daib mod OP_CODE_MOD x-endian)
414 (daib xor OP_CODE_XOR x-endian)
415 (daib mov OP_CODE_MOV x-endian)
416 (daib arsh OP_CODE_ARSH x-endian)
417 (daiu neg OP_CODE_NEG x-endian)))
418
419(define-alu-instructions le)
420(define-alu-instructions be)
421
422;;; Endianness conversion instructions
423
424;; The endianness conversion instructions come in several variants:
425;;
426;; END{le,be}le for the little-endian ISA
427;; END{le,be}be for the big-endian ISA
428;;
429;; Please do not be confused by the repeated `be' and `le' here. Each
430;; ISA has both endle and endbe instructions. It is the disposition
431;; of the source and destination register fields that change between
432;; ISAs, not the semantics of the instructions themselves (see section
433;; "The ISAs" above in this very file.)
434
435(define-pmacro (define-endian-insn x-suffix x-op-src x-endian)
436 (dni (.sym "end" x-suffix x-endian)
437 (.str "end" x-suffix " register")
438 ((ISA (.sym ebpf x-endian)))
439 (.str "end" x-suffix " $dst" x-endian ",$endsize")
440 (+ (f-offset16 0) ((.sym f-src x-endian) 0) (.sym dst x-endian) endsize
441 OP_CLASS_ALU x-op-src OP_CODE_END) () ()))
442
443(define-endian-insn "le" OP_SRC_K le)
444(define-endian-insn "be" OP_SRC_X le)
445(define-endian-insn "le" OP_SRC_K be)
446(define-endian-insn "be" OP_SRC_X be)
447
448;;; Load/Store instructions
449
450;; The lddw instruction takes a 64-bit immediate as an operand. Since
451;; this instruction also takes a `dst' operand, we need to define a
452;; variant for each ISA:
453;;
454;; LDDWle for the little-endian ISA
455;; LDDWbe for the big-endian ISA
456
457(define-pmacro (define-lddw x-endian)
458 (dni (.sym lddw x-endian)
459 (.str "lddw" x-endian)
460 ((ISA (.sym ebpf x-endian)))
461 (.str "lddw $dst" x-endian ",$imm64")
462 (+ imm64 (f-offset16 0) ((.sym f-src x-endian) 0)
463 (.sym dst x-endian)
464 OP_CLASS_LD OP_SIZE_DW OP_MODE_IMM) () ()))
465
466(define-lddw le)
467(define-lddw be)
468
469;; The absolute/indirect load instructions are non-generic loads
470;; designed to be used in socket filters. They come in several
471;; variants:
472;;
473;; LD{abs,ind}{w,h,b,dw}le for the little-endian ISA
474;; LD{abs,ind}[w,h,b,dw}be for the big-endian ISA
475
476(define-pmacro (dlsi x-basename x-suffix x-class x-size x-mode x-endian)
477 (dni (.sym x-basename x-suffix x-endian)
478 (.str x-basename x-suffix)
479 ((ISA (.sym ebpf x-endian)))
480 (.str x-basename x-suffix " $dst" x-endian ",$src" x-endian ",$imm32")
481 (+ imm32 (f-offset16 0) (.sym src x-endian) (.sym dst x-endian)
482 (.sym OP_CLASS_ x-class) (.sym OP_SIZE_ x-size)
483 (.sym OP_MODE_ x-mode)) () ()))
484
485(define-pmacro (define-ldabsind x-endian)
486 (begin
487 (dlsi "ldabs" "w" LD W ABS x-endian)
488 (dlsi "ldabs" "h" LD H ABS x-endian)
489 (dlsi "ldabs" "b" LD B ABS x-endian)
490 (dlsi "ldabs" "dw" LD DW ABS x-endian)
491
492 (dlsi "ldind" "w" LD W IND x-endian)
493 (dlsi "ldind" "h" LD H IND x-endian)
494 (dlsi "ldind" "b" LD B IND x-endian)
495 (dlsi "ldind" "dw" LD DW IND x-endian)))
496
497(define-ldabsind le)
498(define-ldabsind be)
499
500;; Generic load and store instructions are provided for several word
501;; sizes. They come in several variants:
502;;
503;; LDX{b,h,w,dw}le, STX{b,h,w,dw}le for the little-endian ISA
504;;
505;; LDX{b,h,w,dw}be, STX{b,h,w,dw}be for the big-endian ISA
506;;
507;; Loads operate on [$SRC+-OFFSET] -> $DST
508;; Stores operate on $SRC -> [$DST+-OFFSET]
509
510(define-pmacro (dxli x-basename x-suffix x-size x-endian)
511 (dni (.sym x-basename x-suffix x-endian)
512 (.str x-basename x-suffix)
513 ((ISA (.sym ebpf x-endian)))
514 (.str x-basename x-suffix " $dst" x-endian ",[$src" x-endian "+$offset16]")
515 (+ (f-imm32 0) offset16 (.sym src x-endian) (.sym dst x-endian)
516 OP_CLASS_LDX (.sym OP_SIZE_ x-size) OP_MODE_MEM)
517 () ()))
518
519(define-pmacro (dxsi x-basename x-suffix x-size x-endian)
520 (dni (.sym x-basename x-suffix x-endian)
521 (.str x-basename x-suffix)
522 ((ISA (.sym ebpf x-endian)))
523 (.str x-basename x-suffix " [$dst" x-endian "+$offset16],$src" x-endian)
524 (+ (f-imm32 0) offset16 (.sym src x-endian) (.sym dst x-endian)
525 OP_CLASS_STX (.sym OP_SIZE_ x-size) OP_MODE_MEM)
526 () ()))
527
528(define-pmacro (define-ldstx-insns x-endian)
529 (begin
530 (dxli "ldx" "w" W x-endian)
531 (dxli "ldx" "h" H x-endian)
532 (dxli "ldx" "b" B x-endian)
533 (dxli "ldx" "dw" DW x-endian)
534
535 (dxsi "stx" "w" W x-endian)
536 (dxsi "stx" "h" H x-endian)
537 (dxsi "stx" "b" B x-endian)
538 (dxsi "stx" "dw" DW x-endian)))
539
540(define-ldstx-insns le)
541(define-ldstx-insns be)
542
543;; Generic store instructions of the form IMM32 -> [$DST+OFFSET] are
544;; provided in several variants:
545;;
546;; ST{b,h,w,dw}le for the little-endian ISA
547;; ST{b,h,w,dw}be for the big-endian ISA
548
549(define-pmacro (dsti x-suffix x-size x-endian)
550 (dni (.sym "st" x-suffix x-endian)
551 (.str "st" x-suffix)
552 ((ISA (.sym ebpf x-endian)))
553 (.str "st" x-suffix " [$dst" x-endian "+$offset16],$imm32")
554 (+ imm32 offset16 ((.sym f-src x-endian) 0) (.sym dst x-endian)
555 OP_CLASS_ST (.sym OP_SIZE_ x-size) OP_MODE_MEM) () ()))
556
557(define-pmacro (define-st-insns x-endian)
558 (begin
559 (dsti "b" B x-endian)
560 (dsti "h" H x-endian)
561 (dsti "w" W x-endian)
562 (dsti "dw" DW x-endian)))
563
564(define-st-insns le)
565(define-st-insns be)
566
567;;; Jump instructions
568
569;; Compare-and-jump instructions, on the other hand, make use of
570;; registers. Therefore, we need to define several variants in both
571;; ISAs:
572;;
573;; J{eq,gt,ge,lt,le,set,ne,sgt,sge,slt,sle}{i,r}le for the
574;; little-endian ISA.
575;; J{eq,gt,ge,lt,le,set,ne.sgt,sge,slt,sle}{i,r}be for the
576;; big-endian ISA.
577
578(define-pmacro (dcji x-cond x-op-code x-endian)
579 (begin
580 (dni (.sym j x-cond i x-endian)
581 (.str j x-cond "i")
582 ((ISA (.sym ebpf x-endian)))
583 (.str "j" x-cond " $dst" x-endian ",$imm32,$disp16")
584 (+ imm32 disp16 ((.sym f-src x-endian) 0) (.sym dst x-endian)
585 OP_CLASS_JMP OP_SRC_K (.sym OP_CODE_ x-op-code)) () ())
586 (dni (.sym j x-cond r x-endian)
587 (.str j x-cond "r")
588 ((ISA (.sym ebpf x-endian)))
589 (.str "j" x-cond " $dst" x-endian ",$src" x-endian ",$disp16")
590 (+ (f-imm32 0) disp16 (.sym src x-endian) (.sym dst x-endian)
591 OP_CLASS_JMP OP_SRC_X (.sym OP_CODE_ x-op-code)) () ())))
592
593(define-pmacro (define-condjump-insns x-endian)
594 (begin
595 (dcji "eq" JEQ x-endian)
596 (dcji "gt" JGT x-endian)
597 (dcji "ge" JGE x-endian)
598 (dcji "lt" JLT x-endian)
599 (dcji "le" JLE x-endian)
600 (dcji "set" JSET x-endian)
601 (dcji "ne" JNE x-endian)
602 (dcji "sgt" JSGT x-endian)
603 (dcji "sge" JSGE x-endian)
604 (dcji "slt" JSLT x-endian)
605 (dcji "sle" JSLE x-endian)))
606
607(define-condjump-insns le)
608(define-condjump-insns be)
609
610;; The jump-always, `call' and `exit' instructions dont make use of
611;; either source nor destination registers, so only one variant per
612;; instruction is defined.
613
614(dni ja "ja" (all-isas) "ja $disp16"
615 (+ (f-imm32 0) disp16 (f-regs 0)
616 OP_CLASS_JMP OP_SRC_K OP_CODE_JA) () ())
617
618(dni call "call" (all-isas) "call $disp32"
619 (+ disp32 (f-offset16 0) (f-regs 0)
620 OP_CLASS_JMP OP_SRC_K OP_CODE_CALL) () ())
621
622(dni "exit" "exit" (all-isas) "exit"
623 (+ (f-imm32 0) (f-offset16 0) (f-regs 0)
624 OP_CLASS_JMP (f-op-src 0) OP_CODE_EXIT) () ())
625
626;;; Atomic instructions
627
628;; The atomic exchange-and-add instructions come in two flavors: one
629;; for swapping 64-bit quantities and another for 32-bit quantities.
630
631(define-pmacro (define-atomic-insns x-endian)
632 (begin
633 (dni (.str "xadddw" x-endian)
634 "xadddw"
635 ((ISA (.sym ebpf x-endian)))
636 (.str "xadddw [$dst" x-endian "+$offset16],$src" x-endian)
637 (+ (f-imm32 0) (.sym src x-endian) (.sym dst x-endian)
638 offset16 OP_MODE_XADD OP_SIZE_DW OP_CLASS_STX) () ())
639 (dni (.str "xaddw" x-endian)
640 "xaddw"
641 ((ISA (.sym ebpf x-endian)))
642 (.str "xaddw [$dst" x-endian "+$offset16],$src" x-endian)
643 (+ (f-imm32 0) (.sym src x-endian) (.sym dst x-endian)
644 offset16 OP_MODE_XADD OP_SIZE_W OP_CLASS_STX) () ())))
645
646(define-atomic-insns le)
647(define-atomic-insns be)
This page took 0.051042 seconds and 4 git commands to generate.