bpf_jit64.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * bpf_jit64.h: BPF JIT compiler for PPC64
  3. *
  4. * Copyright 2016 Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
  5. * IBM Corporation
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; version 2
  10. * of the License.
  11. */
  12. #ifndef _BPF_JIT64_H
  13. #define _BPF_JIT64_H
  14. #include "bpf_jit.h"
  15. /*
  16. * Stack layout:
  17. * Ensure the top half (upto local_tmp_var) stays consistent
  18. * with our redzone usage.
  19. *
  20. * [ prev sp ] <-------------
  21. * [ nv gpr save area ] 6*8 |
  22. * [ tail_call_cnt ] 8 |
  23. * [ local_tmp_var ] 8 |
  24. * fp (r31) --> [ ebpf stack space ] upto 512 |
  25. * [ frame header ] 32/112 |
  26. * sp (r1) ---> [ stack pointer ] --------------
  27. */
  28. /* for gpr non volatile registers BPG_REG_6 to 10 */
  29. #define BPF_PPC_STACK_SAVE (6*8)
  30. /* for bpf JIT code internal usage */
  31. #define BPF_PPC_STACK_LOCALS 16
  32. /* stack frame excluding BPF stack, ensure this is quadword aligned */
  33. #define BPF_PPC_STACKFRAME (STACK_FRAME_MIN_SIZE + \
  34. BPF_PPC_STACK_LOCALS + BPF_PPC_STACK_SAVE)
  35. #ifndef __ASSEMBLY__
  36. /* BPF register usage */
  37. #define TMP_REG_1 (MAX_BPF_JIT_REG + 0)
  38. #define TMP_REG_2 (MAX_BPF_JIT_REG + 1)
  39. /* BPF to ppc register mappings */
  40. static const int b2p[] = {
  41. /* function return value */
  42. [BPF_REG_0] = 8,
  43. /* function arguments */
  44. [BPF_REG_1] = 3,
  45. [BPF_REG_2] = 4,
  46. [BPF_REG_3] = 5,
  47. [BPF_REG_4] = 6,
  48. [BPF_REG_5] = 7,
  49. /* non volatile registers */
  50. [BPF_REG_6] = 27,
  51. [BPF_REG_7] = 28,
  52. [BPF_REG_8] = 29,
  53. [BPF_REG_9] = 30,
  54. /* frame pointer aka BPF_REG_10 */
  55. [BPF_REG_FP] = 31,
  56. /* eBPF jit internal registers */
  57. [BPF_REG_AX] = 2,
  58. [TMP_REG_1] = 9,
  59. [TMP_REG_2] = 10
  60. };
  61. /* PPC NVR range -- update this if we ever use NVRs below r27 */
  62. #define BPF_PPC_NVR_MIN 27
  63. #define SEEN_FUNC 0x1000 /* might call external helpers */
  64. #define SEEN_STACK 0x2000 /* uses BPF stack */
  65. #define SEEN_TAILCALL 0x4000 /* uses tail calls */
  66. struct codegen_context {
  67. /*
  68. * This is used to track register usage as well
  69. * as calls to external helpers.
  70. * - register usage is tracked with corresponding
  71. * bits (r3-r10 and r27-r31)
  72. * - rest of the bits can be used to track other
  73. * things -- for now, we use bits 16 to 23
  74. * encoded in SEEN_* macros above
  75. */
  76. unsigned int seen;
  77. unsigned int idx;
  78. unsigned int stack_size;
  79. };
  80. #endif /* !__ASSEMBLY__ */
  81. #endif