| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * bpf_jit32.h: BPF JIT compiler for PPC |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright 2011 Matt Evans <matt@ozlabs.org>, IBM Corporation |
|---|
| 5 | 6 | * |
|---|
| 6 | 7 | * Split from bpf_jit.h |
|---|
| 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 |
|---|
| 10 | | - * as published by the Free Software Foundation; version 2 |
|---|
| 11 | | - * of the License. |
|---|
| 12 | 8 | */ |
|---|
| 13 | 9 | #ifndef _BPF_JIT32_H |
|---|
| 14 | 10 | #define _BPF_JIT32_H |
|---|
| .. | .. |
|---|
| 76 | 72 | DECLARE_LOAD_FUNC(sk_load_byte); |
|---|
| 77 | 73 | DECLARE_LOAD_FUNC(sk_load_byte_msh); |
|---|
| 78 | 74 | |
|---|
| 79 | | -#define PPC_LBZ_OFFS(r, base, i) do { if ((i) < 32768) PPC_LBZ(r, base, i); \ |
|---|
| 80 | | - else { PPC_ADDIS(r, base, IMM_HA(i)); \ |
|---|
| 81 | | - PPC_LBZ(r, r, IMM_L(i)); } } while(0) |
|---|
| 75 | +#define PPC_LBZ_OFFS(r, base, i) do { if ((i) < 32768) EMIT(PPC_RAW_LBZ(r, base, i)); \ |
|---|
| 76 | + else { EMIT(PPC_RAW_ADDIS(r, base, IMM_HA(i))); \ |
|---|
| 77 | + EMIT(PPC_RAW_LBZ(r, r, IMM_L(i))); } } while(0) |
|---|
| 82 | 78 | |
|---|
| 83 | | -#define PPC_LD_OFFS(r, base, i) do { if ((i) < 32768) PPC_LD(r, base, i); \ |
|---|
| 84 | | - else { PPC_ADDIS(r, base, IMM_HA(i)); \ |
|---|
| 85 | | - PPC_LD(r, r, IMM_L(i)); } } while(0) |
|---|
| 79 | +#define PPC_LD_OFFS(r, base, i) do { if ((i) < 32768) EMIT(PPC_RAW_LD(r, base, i)); \ |
|---|
| 80 | + else { EMIT(PPC_RAW_ADDIS(r, base, IMM_HA(i))); \ |
|---|
| 81 | + EMIT(PPC_RAW_LD(r, r, IMM_L(i))); } } while(0) |
|---|
| 86 | 82 | |
|---|
| 87 | | -#define PPC_LWZ_OFFS(r, base, i) do { if ((i) < 32768) PPC_LWZ(r, base, i); \ |
|---|
| 88 | | - else { PPC_ADDIS(r, base, IMM_HA(i)); \ |
|---|
| 89 | | - PPC_LWZ(r, r, IMM_L(i)); } } while(0) |
|---|
| 83 | +#define PPC_LWZ_OFFS(r, base, i) do { if ((i) < 32768) EMIT(PPC_RAW_LWZ(r, base, i)); \ |
|---|
| 84 | + else { EMIT(PPC_RAW_ADDIS(r, base, IMM_HA(i))); \ |
|---|
| 85 | + EMIT(PPC_RAW_LWZ(r, r, IMM_L(i))); } } while(0) |
|---|
| 90 | 86 | |
|---|
| 91 | | -#define PPC_LHZ_OFFS(r, base, i) do { if ((i) < 32768) PPC_LHZ(r, base, i); \ |
|---|
| 92 | | - else { PPC_ADDIS(r, base, IMM_HA(i)); \ |
|---|
| 93 | | - PPC_LHZ(r, r, IMM_L(i)); } } while(0) |
|---|
| 87 | +#define PPC_LHZ_OFFS(r, base, i) do { if ((i) < 32768) EMIT(PPC_RAW_LHZ(r, base, i)); \ |
|---|
| 88 | + else { EMIT(PPC_RAW_ADDIS(r, base, IMM_HA(i))); \ |
|---|
| 89 | + EMIT(PPC_RAW_LHZ(r, r, IMM_L(i))); } } while(0) |
|---|
| 94 | 90 | |
|---|
| 95 | 91 | #ifdef CONFIG_PPC64 |
|---|
| 96 | 92 | #define PPC_LL_OFFS(r, base, i) do { PPC_LD_OFFS(r, base, i); } while(0) |
|---|
| .. | .. |
|---|
| 101 | 97 | #ifdef CONFIG_SMP |
|---|
| 102 | 98 | #ifdef CONFIG_PPC64 |
|---|
| 103 | 99 | #define PPC_BPF_LOAD_CPU(r) \ |
|---|
| 104 | | - do { BUILD_BUG_ON(FIELD_SIZEOF(struct paca_struct, paca_index) != 2); \ |
|---|
| 100 | + do { BUILD_BUG_ON(sizeof_field(struct paca_struct, paca_index) != 2); \ |
|---|
| 105 | 101 | PPC_LHZ_OFFS(r, 13, offsetof(struct paca_struct, paca_index)); \ |
|---|
| 106 | 102 | } while (0) |
|---|
| 107 | 103 | #else |
|---|
| 108 | 104 | #define PPC_BPF_LOAD_CPU(r) \ |
|---|
| 109 | | - do { BUILD_BUG_ON(FIELD_SIZEOF(struct thread_info, cpu) != 4); \ |
|---|
| 110 | | - PPC_LHZ_OFFS(r, (1 & ~(THREAD_SIZE - 1)), \ |
|---|
| 111 | | - offsetof(struct thread_info, cpu)); \ |
|---|
| 105 | + do { BUILD_BUG_ON(sizeof_field(struct task_struct, cpu) != 4); \ |
|---|
| 106 | + PPC_LHZ_OFFS(r, 2, offsetof(struct task_struct, cpu)); \ |
|---|
| 112 | 107 | } while(0) |
|---|
| 113 | 108 | #endif |
|---|
| 114 | 109 | #else |
|---|
| 115 | | -#define PPC_BPF_LOAD_CPU(r) do { PPC_LI(r, 0); } while(0) |
|---|
| 110 | +#define PPC_BPF_LOAD_CPU(r) do { EMIT(PPC_RAW_LI(r, 0)); } while(0) |
|---|
| 116 | 111 | #endif |
|---|
| 117 | 112 | |
|---|
| 118 | 113 | #define PPC_LHBRX_OFFS(r, base, i) \ |
|---|
| 119 | | - do { PPC_LI32(r, i); PPC_LHBRX(r, r, base); } while(0) |
|---|
| 114 | + do { PPC_LI32(r, i); EMIT(PPC_RAW_LHBRX(r, r, base)); } while(0) |
|---|
| 120 | 115 | #ifdef __LITTLE_ENDIAN__ |
|---|
| 121 | 116 | #define PPC_NTOHS_OFFS(r, base, i) PPC_LHBRX_OFFS(r, base, i) |
|---|
| 122 | 117 | #else |
|---|
| 123 | 118 | #define PPC_NTOHS_OFFS(r, base, i) PPC_LHZ_OFFS(r, base, i) |
|---|
| 124 | 119 | #endif |
|---|
| 125 | 120 | |
|---|
| 126 | | -#define PPC_BPF_LL(r, base, i) do { PPC_LWZ(r, base, i); } while(0) |
|---|
| 127 | | -#define PPC_BPF_STL(r, base, i) do { PPC_STW(r, base, i); } while(0) |
|---|
| 128 | | -#define PPC_BPF_STLU(r, base, i) do { PPC_STWU(r, base, i); } while(0) |
|---|
| 121 | +#define PPC_BPF_LL(r, base, i) do { EMIT(PPC_RAW_LWZ(r, base, i)); } while(0) |
|---|
| 122 | +#define PPC_BPF_STL(r, base, i) do { EMIT(PPC_RAW_STW(r, base, i)); } while(0) |
|---|
| 123 | +#define PPC_BPF_STLU(r, base, i) do { EMIT(PPC_RAW_STWU(r, base, i)); } while(0) |
|---|
| 129 | 124 | |
|---|
| 130 | 125 | #define SEEN_DATAREF 0x10000 /* might call external helpers */ |
|---|
| 131 | 126 | #define SEEN_XREG 0x20000 /* X reg is used */ |
|---|