]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/bpf/bpf.h
Update copyright years.
[thirdparty/gcc.git] / gcc / config / bpf / bpf.h
CommitLineData
91dfef96 1/* Definition of the eBPF target for GCC.
8d9254fc 2 Copyright (C) 2019-2020 Free Software Foundation, Inc.
91dfef96
JM
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
10
11 GCC is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
19
20#ifndef GCC_BPF_H
21#define GCC_BPF_H
22
23/**** Controlling the Compilation Driver. */
24
25#define ASM_SPEC "%{mbig-endian:-EB} %{!mbig-endian:-EL}"
26#define LINK_SPEC "%{mbig-endian:-EB} %{!mbig-endian:-EL}"
27#define LIB_SPEC ""
28#define STARTFILE_SPEC ""
29
30/**** Run-time Target Specification. */
31
32#define TARGET_CPU_CPP_BUILTINS() bpf_target_macros (pfile)
33
34/**** Storage Layout. */
35
36/* Endianness and word size. */
37#define BITS_BIG_ENDIAN 0
38#define BYTES_BIG_ENDIAN (TARGET_BIG_ENDIAN)
39#define WORDS_BIG_ENDIAN (TARGET_BIG_ENDIAN)
40#define BITS_PER_WORD 64
41#define UNITS_PER_WORD 8
42
43/* When storing an integer whose size is less than 64-bit in a
44 register, promote it to a DImode. */
45#define PROMOTE_MODE(M, UNSIGNEDP, TYPE) \
46 do \
47 { \
48 if (GET_MODE_CLASS (M) == MODE_INT \
49 && GET_MODE_SIZE (M) < 8) \
50 M = DImode; \
51 } while (0)
52
53/* Biggest alignment supported by the object file format of this
54 machine. In this case this is ELF. Use the same definition than
55 in elfos.h */
56#define MAX_OFILE_ALIGNMENT (((unsigned int) 1 << 28) * 8)
57
58/* Align argument parameters on the stack to 64-bit, at a minimum. */
59#define PARM_BOUNDARY 64
60
61/* The hardware enforces that the stack pointer should be aligned to
62 64-bit at any time. */
63#define STACK_BOUNDARY 64
64
65/* Function entry points are aligned to 128 bits. */
66#define FUNCTION_BOUNDARY 128
67
68/* Maximum alignment required by data of any type. */
69#define BIGGEST_ALIGNMENT 64
70
71/* The best alignment to use in cases where we have a choice. */
72#define FASTEST_ALIGNMENT 64
73
74/* Use a fast alignment when storing arrays of chars in a local. */
75#define LOCAL_ALIGNMENT(TYPE, ALIGN) \
76 (TREE_CODE (TYPE) == ARRAY_TYPE \
77 && TYPE_MODE (TREE_TYPE (TYPE)) == QImode \
78 && (ALIGN) < FASTEST_ALIGNMENT ? FASTEST_ALIGNMENT : (ALIGN))
79
80/* The load and store instructions won't work if the data is not in
81 it's expected alignment. */
82#define STRICT_ALIGNMENT 1
83
84/* We use Pmode as the mode of the size increment operand in an
85 `allocate_stack' pattern. */
86#define STACK_SIZE_MODE Pmode
87
88/**** Layout of Source Language Data Types. */
89
90#define INT_TYPE_SIZE 32
91#define SHORT_TYPE_SIZE 16
92#define LONG_TYPE_SIZE 64
93#define LONG_LONG_TYPE_SIZE 64
94#define CHAR_TYPE_SIZE 8
95#define FLOAT_TYPE_SIZE 32
96#define DOUBLE_TYPE_SIZE 64
97#define LONG_DOUBLE_TYPE_SIZE 64
98
99#define INTPTR_TYPE "long int"
100#define UINTPTR_TYPE "long unsigned int"
101#define SIZE_TYPE "long unsigned int"
102#define PTRDIFF_TYPE "long int"
103
104#define SIG_ATOMIC_TYPE "char"
105
106#define INT8_TYPE "char"
107#define INT16_TYPE "short int"
108#define INT32_TYPE "int"
109#define INT64_TYPE "long int"
110#define UINT8_TYPE "unsigned char"
111#define UINT16_TYPE "short unsigned int"
112#define UINT32_TYPE "unsigned int"
113#define UINT64_TYPE "long unsigned int"
114
115#define INT_LEAST8_TYPE INT8_TYPE
116#define INT_LEAST16_TYPE INT16_TYPE
117#define INT_LEAST32_TYPE INT32_TYPE
118#define INT_LEAST64_TYPE INT64_TYPE
119#define UINT_LEAST8_TYPE UINT8_TYPE
120#define UINT_LEAST16_TYPE UINT16_TYPE
121#define UINT_LEAST32_TYPE UINT32_TYPE
122#define UINT_LEAST64_TYPE UINT64_TYPE
123
124#define INT_FAST8_TYPE INT8_TYPE
125#define INT_FAST16_TYPE INT16_TYPE
126#define INT_FAST32_TYPE INT32_TYPE
127#define INT_FAST64_TYPE INT64_TYPE
128#define UINT_FAST8_TYPE UINT8_TYPE
129#define UINT_FAST16_TYPE UINT16_TYPE
130#define UINT_FAST32_TYPE UINT32_TYPE
131#define UINT_FAST64_TYPE UINT64_TYPE
132
133/* `char' is signed by default, like in x86. */
134#define DEFAULT_SIGNED_CHAR 1
135
136/* `wchar_t' is a signed 32-bit type. The second constant is used by
137 cpp, which can't use WCHAR_TYPE. */
138#define WCHAR_TYPE "int"
139#define WCHAR_TYPE_SIZE 32
140
141/* `wint_t' is a signed 32-bit type. */
142#define WINT_TYPE "int"
143#define WINT_TYPE_SIZE 32
144
145/**** Register Usage. */
146
147/*** Basic Characteristics of Registers. */
148
149#define BPF_R0 0
150#define BPF_R1 1
151#define BPF_R2 2
152#define BPF_R3 3
153#define BPF_R4 4
154#define BPF_R5 5
155#define BPF_R6 6
156#define BPF_CTX BPF_R6
157#define BPF_R7 7
158#define BPF_R8 8
159#define BPF_R9 9
160#define BPF_SP BPF_R9
161#define BPF_R10 10
162#define BPF_FP BPF_R10
163/* 11 is not a real eBPF hard register and is eliminated or not used
164 in the final assembler. See below. */
165
166#define FIRST_PSEUDO_REGISTER 12
167
168/* The registers %r0..%r8 are available for general allocation.
169 %r9 is the pseudo-stack pointer.
170 %r10 is the stack frame, which is read-only.
171 %r11 (__arg__) is a fake register that always gets eliminated. */
172#define FIXED_REGISTERS \
173 {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1}
174
175/* %r0..%r5 are clobbered by function calls. */
176#define CALL_USED_REGISTERS \
177 {1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1}
178
179/**** Register Classes. */
180
181enum reg_class
182{
183 NO_REGS, /* no registers in set. */
184 ALL_REGS, /* all registers. */
185 LIM_REG_CLASSES /* max value + 1. */
186};
187
188#define N_REG_CLASSES (int) LIM_REG_CLASSES
189#define GENERAL_REGS ALL_REGS
190
191/* An initializer containing the names of the register classes as C
192 string constants. These names are used in writing some of the
193 debugging dumps. */
194#define REG_CLASS_NAMES \
195{ \
196 "NO_REGS", \
197 "ALL_REGS" \
198}
199
200/* An initializer containing the contents of the register classes, as
201 integers which are bit masks. The Nth integer specifies the
202 contents of class N. The way the integer MASK is interpreted is
203 that register R is in the class if `MASK & (1 << R)' is 1.
204
205 In eBPF all the hard registers are considered general-purpose
206 integer registers. */
207#define REG_CLASS_CONTENTS \
208{ \
209 0x00000000, /* NO_REGS */ \
210 0x00000fff, /* ALL_REGS */ \
211}
212
213/* A C expression whose value is a register class containing hard
214 register REGNO. In general there is more that one such class;
215 choose a class which is "minimal", meaning that no smaller class
216 also contains the register. */
217#define REGNO_REG_CLASS(REGNO) GENERAL_REGS
218
219/* A macro whose definition is the name of the class to which a
220 valid base register must belong. A base register is one used in
221 an address which is the register value plus a displacement. */
222#define BASE_REG_CLASS GENERAL_REGS
223
224/* A macro whose definition is the name of the class to which a
225 valid index register must belong. An index register is one used
226 in an address where its value is either multiplied by a scale
227 factor or added to another register (as well as added to a
228 displacement). */
229#define INDEX_REG_CLASS NO_REGS
230
231/* C expression which is nonzero if register number REGNO is suitable
232 for use as a base register in operand addresses. In eBPF every
233 hard register can be used for this purpose. */
234#define REGNO_OK_FOR_BASE_P(REGNO) \
235 ((REGNO) < FIRST_PSEUDO_REGISTER)
236
237/* C expression which is nonzero if register number REGNO is suitable
238 for use as an index register in operand addresses. */
239#define REGNO_OK_FOR_INDEX_P(REGNO) false
240
241/**** Debugging Info ****/
242
243/* We cannot support DWARF2 because of the limitations of eBPF. */
244#define DBX_DEBUGGING_INFO
245
246/**** Stack Layout and Calling Conventions. */
247
248/*** Basic Stack Layout. */
249
250#define STACK_GROWS_DOWNWARD 1
251#define FRAME_GROWS_DOWNWARD 1
252
253/* The argument pointer always points to the first argument. */
254#define FIRST_PARM_OFFSET(FNDECL) 0
255
256/* Unsupported. */
257#define RETURN_ADDR_RTX(count, frame) const0_rtx
258
259/*** Registers That Address the Stack Frame. */
260
261#define FRAME_POINTER_REGNUM 10
262#define STACK_POINTER_REGNUM 9
263#define ARG_POINTER_REGNUM 11
264#define STATIC_CHAIN_REGNUM 8
265
266/*** Registers elimination. */
267
268#define ELIMINABLE_REGS \
269 {{ ARG_POINTER_REGNUM, FRAME_POINTER_REGNUM }, \
270 { ARG_POINTER_REGNUM, STACK_POINTER_REGNUM }}
271
272/* Define the offset between two registers, one to be eliminated, and
273 the other its replacement, at the start of a routine. */
274#define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET) \
275 do \
276 { \
277 (OFFSET) = bpf_initial_elimination_offset ((FROM), (TO)); \
278 } while (0)
279
280/*** Passing Function Arguments on the Stack. */
281
282/* The eBPF ABI doesn't support passing arguments on the stack. Only
283 in the first five registers. Code in bpf.c assures the stack is
284 never used when passing arguments. However, we still have to
285 define the constants below. */
286
287/* If nonzero, push insns will be used to pass outgoing arguments. */
288#define PUSH_ARGS 0
289
290/* If nonzero, function arguments will be evaluated from last to
291 first, rather than from first to last. */
292#define PUSH_ARGS_REVERSED 1
293
294/* Allocate stack space for arguments at the beginning of each
295 function. */
296#define ACCUMULATE_OUTGOING_ARGS 1
297
298/*** Passing Arguments in Registers. */
299
300/* Use an integer in order to keep track of the number of arguments
301 passed to a function in integer registers, up to
302 MAX_ARGS_IN_REGISTERS. */
303#define CUMULATIVE_ARGS int
304
305/* INIT_CUMULATIVE_ARGS initializes a variable CUM of type
306 CUMULATIVE_ARGS for a call to a function whose data type is FNTYPE.
307 For a library call, FNTYPE is 0. */
308#define INIT_CUMULATIVE_ARGS(CUM,FNTYPE,LIBNAME,FNDECL,N_NAMED_ARGS) \
309 memset (&(CUM), 0, sizeof (CUM))
310
311/* Nonzero if N is the number of a hard register in which function
312 arguments are sometimes passed. */
313#define FUNCTION_ARG_REGNO_P(N) ((N) >= 1 && (N) <= 5)
314
315/*** How Scalar Function Values are Returned. */
316
317/* Define how to find the value returned by a library function
318 assuming the value has mode MODE. This is always %r0 for eBPF. */
319#define LIBCALL_VALUE(MODE) \
320 gen_rtx_REG ((MODE), 0)
321
322/*** Generating Code for Profiling. */
323
324/* We do not support profiling yet, so do not call `mcount'. */
325#define FUNCTION_PROFILER(FILE, LABELNO) do { } while (0)
326
327/*** Function Entry and Exit. */
328
329/* We do not require an accurate stack pointer at function return.
330 This is because the stack pointer's original value is initialized
331 from the frame pointer, rather than decreased, to satisfy the
332 kernel's verifier. Thus, we have to save the stack pointer in
333 function prologue and restore it in function epilogue. If
334 EXIT_IGNORE_STACK is not set, then superfluous instructions are
335 generated to save and restore the stack pointer after and before
336 the function epilogue, respectively. */
337#define EXIT_IGNORE_STACK 1
338
339/**** Support for Nested Functions. */
340
341/* We have to define TRAMPOLINE_SIZE even if we don't ever generate
342 them. Set to 64 arbitrarily. */
343#define TRAMPOLINE_SIZE 64
344
345/**** Addressing Modes. */
346
347/* Maximum number of registers that can appear in a valid memory
348 address. */
349#define MAX_REGS_PER_ADDRESS 1
350
351/* 1 if X is an rtx for a constant that is a valid address. */
352
353#define CONSTANT_ADDRESS_P(X) 0
354
355/**** Describing Relative Costs of Operations. */
356
357/* Cost of a branch instruction. A value of 1 is the default. */
358#define BRANCH_COST(SPEED_P,PREDICTABLE_P) 1
359
360/* The SPARC port says: Nonzero if access to memory by bytes is slow
361 and undesirable. For RISC chips, it means that access to memory by
362 bytes is no better than access by words when possible, so grab a
363 whole word and maybe make use of that. */
364#define SLOW_BYTE_ACCESS 1
365
366/* Threshold of number of scalar memory-to-memory move instructions,
367 _below_ which a sequence of insns should be generated instead of a
368 string move insn or a library call. */
369#define MOVE_RATIO(speed) 128
370
371/* Threshold of number of scalar move instructions, _below_ which a
372 sequence of insns should be generated to clear memory instead of a
373 string clear insn or a library call. */
374#define CLEAR_RATIO(speed) 128
375
376/* Threshold of number of scalar move instructions, _below_ which a
377 sequence of insns should be generated to set memory to a constant
378 value, instead of a block set insn or a library call. */
379#define SET_RATIO(speed) 128
380
381/* True if it is as good or better to call a constant function address
382 than to call an address kept in a register. */
383#define NO_FUNCTION_CSE 1
384
385/**** Dividing the Output into Sections. */
386
387#define TEXT_SECTION_ASM_OP "\t.text"
388#define DATA_SECTION_ASM_OP "\t.data"
389#define BSS_SECTION_ASM_OP "\t.bss"
390#define COMMON_ASM_OP "\t.common\t"
391
392/**** Defining the Output Assembler Language. */
393
394/*** The Overall Framework of an Assembler File. */
395
396#define ASM_COMMENT_START ";"
397
398/* Output to assembler file text saying following lines
399 may contain character constants, extra white space, comments, etc. */
400
401#ifndef ASM_APP_ON
402#define ASM_APP_ON " #APP\n"
403#endif
404
405/* Output to assembler file text saying following lines
406 no longer contain unusual constructs. */
407
408#ifndef ASM_APP_OFF
409#define ASM_APP_OFF " #NO_APP\n"
410#endif
411
412/*** Output of Data. */
413
414/*** Output of Uninitialized Variables. */
415
416/* How to output an assembler line to define a local common
417 symbol. */
418
419#define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN) \
420 do \
421 { \
422 fprintf ((FILE), "%s", COMMON_ASM_OP); \
423 assemble_name ((FILE), (NAME)); \
424 fprintf ((FILE), ",%u,%u\n", (int)(SIZE), (ALIGN) / (BITS_PER_UNIT)); \
425 } \
426 while (0)
427
428/* A C statement (sans semicolon) to output to the stdio stream
429 FILE the assembler definition of uninitialized global DECL named
430 NAME whose size is SIZE bytes and alignment is ALIGN bytes.
431 Try to use asm_output_aligned_bss to implement this macro. */
432
433#define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
434 do { \
435 ASM_OUTPUT_ALIGNED_LOCAL (FILE, NAME, SIZE, ALIGN); \
436 } while (0)
437
438/* This says how to output an assembler line to define a local common
439 symbol. */
440
441#define ASM_OUTPUT_ALIGNED_LOCAL(FILE,NAME,SIZE,ALIGN) \
442 ( fputs ("\t.lcomm ", (FILE)), \
443 assemble_name ((FILE), (NAME)), \
444 fprintf ((FILE), "," HOST_WIDE_INT_PRINT_UNSIGNED "\n", \
445 (SIZE), ((ALIGN) / BITS_PER_UNIT)))
446
447/*** Output and Generation of Labels. */
448
449/* Globalizing directive for a label. */
450#define GLOBAL_ASM_OP "\t.global\t"
451
452/* This is how to store into the string LABEL
453 the symbol_ref name of an internal numbered label where
454 PREFIX is the class of label and NUM is the number within the class.
455 This is suitable for output with `assemble_name'. */
456
457#undef ASM_GENERATE_INTERNAL_LABEL
458#define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM) \
459 sprintf ((LABEL), "*%s%s%ld", (LOCAL_LABEL_PREFIX), (PREFIX), (long)(NUM))
460
461/*** Macros Controlling Initialization Routines. */
462
463#define INIT_SECTION_ASM_OP "\t.init"
464#define FINI_SECTION_ASM_OP "\t.fini"
465
466/*** Output of Assembler Instructions. */
467
468#define REGISTER_NAMES \
469 { "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7", \
470 "%r8", "%r9", "%fp", "__arg__" }
471
472#define ADDITIONAL_REGISTER_NAMES \
473 { { "%a", 0 }, { "%ctx", 6 }, { "%r10" , 10 } }
474
475#define LOCAL_LABEL_PREFIX "."
476#define USER_LABEL_PREFIX ""
477
478#define PRINT_OPERAND(STREAM,X,CODE) \
479 bpf_print_operand ((STREAM),(X),(CODE))
480
481#define PRINT_OPERAND_ADDRESS(STREAM,X) \
482 bpf_print_operand_address ((STREAM), (X))
483
484/*** Assembler Commands for Alignment. */
485
486/* This is how to output an assembler line that says to advance the
487 location counter to a multiple of 2**LOG bytes. */
488#define ASM_OUTPUT_ALIGN(STREAM,LOG) \
489 fprintf (STREAM, "\t.align\t%d\n", (LOG))
490
491/* This is how to output an assembler line
492 that says to advance the location counter by SIZE bytes. */
493#define ASM_OUTPUT_SKIP(FILE,SIZE) \
494 fprintf (FILE, "\t.skip\t" HOST_WIDE_INT_PRINT_UNSIGNED "\n", (SIZE))
495
496/**** Miscellaneous Parameters. */
497
498/* Specify the machine mode that this machine uses for the index in
499 the tablejump instruction. */
500#define CASE_VECTOR_MODE DImode
501
502/* Define if operations between registers with integral mode smaller
503 than a word are always performed on the entire register. */
504#define WORD_REGISTER_OPERATIONS 1
505
506/* C expression indicating when insns that read memory in MEM_MODE, an
507 integral mode narrower than a word, set the bits outsize of
508 MEM_MODE to be either the sign-extension or the zero-extension of
509 the data read. */
510#define LOAD_EXTEND_OP(MODE) ZERO_EXTEND
511
512/* The maximum number of bytes that a single instruction can move
513 quickly between memory and registers or between two memory
514 locations. */
515#define MOVE_MAX 8
516
517/* An alias for the machine mode for pointers. */
518#define Pmode DImode
519
520/* An alias for the machine mode used for memory references to
521 functions being called, in 'call' RTL expressions. */
522#define FUNCTION_MODE Pmode
523
524/* No libm on eBPF (for now.) */
525#define MATH_LIBRARY ""
526
527/**** libgcc settings. */
528
529/* Iterating over the global constructors and destructors and
530 executing them requires the ability of doing indirect calls.
531
532 eBPF doesn't support indirect calls, so no chance of supporting
533 constructors and destructors. */
534#define DO_GLOBAL_CTORS_BODY \
535 do { } while (0)
536#define DO_GLOBAL_DTORS_BODY \
537 do { } while (0)
538
539#endif /* ! GCC_BPF_H */