Skip to content

Commit 2c41683

Browse files
committed
Add conformance test for callx instruction
Signed-off-by: Dave Thaler <[email protected]>
1 parent 583758e commit 2c41683

File tree

6 files changed

+26
-3
lines changed

6 files changed

+26
-3
lines changed

include/bpf_conformance.h

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ typedef enum class _bpf_conformance_test_cpu_version
2323
v2 = 2,
2424
v3 = 3,
2525
v4 = 4,
26+
vnext = 100,
2627
unknown = -1,
2728
} bpf_conformance_test_cpu_version_t;
2829

src/bpf_assembler.cc

+9-2
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,15 @@ typedef class _bpf_assembler
309309
auto target = operands[1];
310310
// Mode determines if this is a helper function, a local call, or a call to a runtime function.
311311
if (mode == "helper") {
312-
inst.imm = _decode_imm32(target);
313-
inst.src = 0;
312+
if (target.starts_with('%')) {
313+
inst.opcode |= EBPF_SRC_REG;
314+
inst.imm = 0;
315+
inst.src = _decode_register(target);
316+
} else {
317+
inst.opcode |= EBPF_SRC_IMM;
318+
inst.imm = _decode_imm32(target);
319+
inst.src = 0;
320+
}
314321
} else if (mode == "local") {
315322
inst.imm = _decode_jump_target(target);
316323
inst.src = 1;

src/bpf_conformance.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ bpf_conformance_options(
213213
instructions_used.insert(bpf_conformance_instruction_t(required_cpu_version, inst));
214214
}
215215

216-
// If the caller requires this as a XDP program, then add the prolog instructions.
216+
// If the caller requires this as an XDP program, then add the prolog instructions.
217217
if (options.xdp_prolog && input_memory.size() > 0) {
218218
auto prolog_instructions = _generate_xdp_prolog(input_memory.size());
219219
byte_code.insert(byte_code.begin(), prolog_instructions.begin(), prolog_instructions.end());

src/opcode_names.h

+1
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ static const std::set<bpf_conformance_instruction_t, InstCmp> instructions_from_
291291
{bpf_conformance_test_cpu_version_t::v3, 0x85, 0x01},
292292
{bpf_conformance_test_cpu_version_t::v3, 0x85, 0x02},
293293
{bpf_conformance_test_cpu_version_t::v1, 0x87},
294+
{bpf_conformance_test_cpu_version_t::vnext, 0x8d, 0x00},
294295
{bpf_conformance_test_cpu_version_t::v1, 0x94, 0x00, 0x00, 0x00},
295296
{bpf_conformance_test_cpu_version_t::v4, 0x94, 0x00, 0x00, 0x01},
296297
{bpf_conformance_test_cpu_version_t::v1, 0x95},

src/runner.cc

+2
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ main(int argc, char** argv)
123123
cpu_version = bpf_conformance_test_cpu_version_t::v3;
124124
} else if (cpu_version_string == "v4") {
125125
cpu_version = bpf_conformance_test_cpu_version_t::v4;
126+
} else if (cpu_version_string == "vnext") {
127+
cpu_version = bpf_conformance_test_cpu_version_t::vnext;
126128
} else {
127129
std::cout << "Invalid CPU version" << std::endl;
128130
return 1;

tests/callx.data

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright (c) Big Switch Networks, Inc
2+
# SPDX-License-Identifier: Apache-2.0
3+
-- asm
4+
mov %r1, -1
5+
mov %r2, 5
6+
call %r2
7+
mov %r0, 2
8+
exit
9+
-- result
10+
0x2
11+
-- no register offset
12+
call instruction

0 commit comments

Comments
 (0)