==> include/mesh/abi/snapshot.h <==1/* @ajax/mesh-abi-snapshot: The snapshot v3 format (SN_*, SC_*): header, per-slot sections, host block.
2 *
3 * Part of alpha-c-mesh, a C port of alpha-rust-mesh (README.md says from where). */
4#ifndef MESH_ABI_SNAPSHOT_H
5#define MESH_ABI_SNAPSHOT_H
6
7#include <stdbool.h>
8#include <stddef.h>
9#include <stdint.h>
10#include "mesh/abi/program_table.h"
11#include "mesh/abi/node.h"
12#include "mesh/abi/ext.h"
13
14/* ---------------------------------------------------------------- snapshot v3 */
15/* v3: the host block grew to 0x3000 for the load regions (S_LOAD ..). */
16#define MESH_SNAP_VERSION 3u
17/* Variable length, little-endian:
18 * SN_HEAD_BYTES header: SN_TOTAL u32 (all bytes), SN_COUNT u32 (sections),
19 * SN_VERSION u32 (= SNAP_VERSION), SN_HOST_AT u32 (offset of the host block)
20 * H_BYTES: mailbox [0, H_BYTES) (the header)
21 * SN_COUNT sections, ascending slot, one per non-empty slot:
22 * SC_HEAD_BYTES: SC_SLOT u32, SC_BYTES u32 (the whole section), SC_NODES u32
23 * (node records copied), SC_VIEW u32 (view bytes copied = snap_bytes)
24 * PT_BYTES the program-table entry
25 * SC_CTL_BYTES the control block's first 4 lines (P_SHUTDOWN .. P_COUNTERS)
26 * PX_BYTES the manifest extension
27 * SC_NODES x NODE_STRIDE node records
28 * SC_VIEW bytes of view, zero padded to a multiple of 4
29 * SNAP_HOST bytes: the host status block (S_*) */
30#define MESH_SN_TOTAL 0x0
31#define MESH_SN_COUNT 0x4
32#define MESH_SN_VERSION 0x8
33#define MESH_SN_HOST_AT 0xc
34#define MESH_SN_HEAD_BYTES 0x10
35#define MESH_SC_SLOT 0x0
36#define MESH_SC_BYTES 0x4
37#define MESH_SC_NODES 0x8
38#define MESH_SC_VIEW 0xc
39#define MESH_SC_HEAD_BYTES 0x10
40#define MESH_SC_CTL_BYTES 0x200
41/* Offsets within a section. */
42#define MESH_SC_ENTRY (MESH_SC_HEAD_BYTES)
43#define MESH_SC_CTL (MESH_SC_ENTRY + MESH_PT_BYTES)
44#define MESH_SC_EXT (MESH_SC_CTL + MESH_SC_CTL_BYTES)
45#define MESH_SC_NODE_RECS (MESH_SC_EXT + MESH_PX_BYTES)
46#define MESH_SNAP_HOST 0x3000
47
48/* A section's bytes: its head, entry, control lines, extension, `nodes`
49 * node records and `view` view bytes rounded up to a multiple of 4. */
50static inline size_t mesh_section_bytes(uint32_t nodes, uint32_t view) {
51 return MESH_SC_NODE_RECS + MESH_NODE_STRIDE * (size_t)nodes + ((size_t)view + 3) / 4 * 4;
52}
53
54/* The Rust const asserts that only involve this package. */
55_Static_assert((MESH_SC_NODE_RECS % 8 == 0), "SC_NODE_RECS.is_multiple_of(8)");
56
57#endif