diff options
author | Maciej Żenczykowski <maze@google.com> | 2024-03-11 21:59:57 -0700 |
---|---|---|
committer | Yuyang Huang <yuyanghuang@google.com> | 2024-03-12 05:49:55 +0000 |
commit | 2e94acc4d7a7ac91f8d9a4d54f1568aaa9fdbdea (patch) | |
tree | d044c079ff8d528099a8980545c9d5383044970e | |
parent | a0b290774b36d49c704d7c3b04c34bb90f8cb90e (diff) | |
download | apf-2e94acc4d7a7ac91f8d9a4d54f1568aaa9fdbdea.tar.gz |
v5: use a memory slot to save apf_version()
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I9ab60d1be0e24de39f06d41b1835941b91cd7b1a
-rw-r--r-- | v5/apf.h | 6 | ||||
-rw-r--r-- | v5/apf_interpreter.c | 9 | ||||
-rw-r--r-- | v5/apf_interpreter_source.c | 3 |
3 files changed, 12 insertions, 6 deletions
@@ -93,7 +93,8 @@ * When the APF program begins execution, six of the sixteen memory slots * are pre-filled by the interpreter with values that may be useful for * programs: - * #0 to #8 are zero initialized. + * #0 to #7 are zero initialized. + * Slot #8 is initialized with apf version (on APF >4). * Slot #9 this is slot #15 with greater resolution (1/16384ths of a second) * Slot #10 starts at zero, implicitly used as tx buffer output pointer. * Slot #11 contains the size (in bytes) of the APF program. @@ -138,7 +139,8 @@ typedef union { struct { - u32 pad[9]; // 0..8 + u32 pad[8]; // 0..7 + u32 apf_version; // 8: Initialized with apf_version() u32 filter_age_16384ths; // 9: Age since filter installed in 1/16384 seconds. u32 tx_buf_offset; // 10: Offset in tx_buf where next byte will be written u32 program_size; // 11: Size of program (in bytes) diff --git a/v5/apf_interpreter.c b/v5/apf_interpreter.c index 68d2f6b..7bdf53e 100644 --- a/v5/apf_interpreter.c +++ b/v5/apf_interpreter.c @@ -165,7 +165,8 @@ typedef enum { * When the APF program begins execution, six of the sixteen memory slots * are pre-filled by the interpreter with values that may be useful for * programs: - * #0 to #8 are zero initialized. + * #0 to #7 are zero initialized. + * Slot #8 is initialized with apf version (on APF >4). * Slot #9 this is slot #15 with greater resolution (1/16384ths of a second) * Slot #10 starts at zero, implicitly used as tx buffer output pointer. * Slot #11 contains the size (in bytes) of the APF program. @@ -210,7 +211,8 @@ typedef enum { typedef union { struct { - u32 pad[9]; /* 0..8 */ + u32 pad[8]; /* 0..7 */ + u32 apf_version; /* 8: Initialized with apf_version() */ u32 filter_age_16384ths; /* 9: Age since filter installed in 1/16384 seconds. */ u32 tx_buf_offset; /* 10: Offset in tx_buf where next byte will be written */ u32 program_size; /* 11: Size of program (in bytes) */ @@ -592,7 +594,7 @@ extern void APF_TRACE_HOOK(u32 pc, const u32* regs, const u8* program, #define ENFORCE_UNSIGNED(c) ((c)==(u32)(c)) u32 apf_version(void) { - return 20240226; + return 20240312; } typedef struct { @@ -1032,6 +1034,7 @@ int apf_run(void* ctx, u32* const program, const u32 program_len, apf_ctx.mem.named.program_size = program_len; apf_ctx.mem.named.ram_len = ram_len; apf_ctx.mem.named.packet_size = packet_len; + apf_ctx.mem.named.apf_version = apf_version(); apf_ctx.mem.named.filter_age = filter_age_16384ths >> 14; apf_ctx.mem.named.filter_age_16384ths = filter_age_16384ths; diff --git a/v5/apf_interpreter_source.c b/v5/apf_interpreter_source.c index 24dbbca..636d679 100644 --- a/v5/apf_interpreter_source.c +++ b/v5/apf_interpreter_source.c @@ -61,7 +61,7 @@ extern void APF_TRACE_HOOK(u32 pc, const u32* regs, const u8* program, #define ENFORCE_UNSIGNED(c) ((c)==(u32)(c)) u32 apf_version(void) { - return 20240226; + return 20240312; } typedef struct { @@ -501,6 +501,7 @@ int apf_run(void* ctx, u32* const program, const u32 program_len, apf_ctx.mem.named.program_size = program_len; apf_ctx.mem.named.ram_len = ram_len; apf_ctx.mem.named.packet_size = packet_len; + apf_ctx.mem.named.apf_version = apf_version(); apf_ctx.mem.named.filter_age = filter_age_16384ths >> 14; apf_ctx.mem.named.filter_age_16384ths = filter_age_16384ths; |