MMgr v1.0.0
Zero-heap memory manager in C11. One borrowed buffer, carved by asserted offset.
Loading...
Searching...
No Matches
proximus_operor.h
Go to the documentation of this file.
1/* MMgr - Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2 * SPDX-License-Identifier: AGPL-3.0-or-later OR LicenseRef-Commercial OR LicenseRef-Educational
3 *
4 * Every use falls under AGPL-3.0-or-later unless you hold explicit permission, which is either a
5 * negotiated commercial licensing contract or an educator's license issued to you personally.
6 */
7/**
8 * @file proximus_operor.h
9 * @brief Typed loads and stores, and the proxim dispatch table.
10 * @author dstroy0 (Douglas Quigg) <dquigg123@gmail.com>
11 * @date 2026-08-29
12 *
13 * @note load16 through put64, load, put and read take any address.
14 * @note The four al_ entries need an address aligned for the type they carry.
15 */
16#ifndef MMGR_PROXIMUS_OPEROR_H
17#define MMGR_PROXIMUS_OPEROR_H
18
19#include "mmgr.h"
20
21EMBED_BEGIN_DECLS
22
23/**
24 * @brief Arguments for the proxim calls.
25 *
26 * @note The loads read at. The stores read dst and val. Only the read entry reads size.
27 */
28typedef struct
29{
30 void *const dst; /**< Destination for the stores and for read [BORROWS]. */
31 const void *const at; /**< Source for the loads and for read [BORROWS]. */
32 const uint64_t val; /**< Value the stores write, taken from its low bytes. */
33 const size_t size; /**< Bytes the read entry copies. */
35
36/**
37 * @brief Type of the proxim dispatch table.
38 *
39 * @note EMBED_TABLE_LAYOUT asserts the thirteen members sit at consecutive EMBED_FUNCTION_POINTER_BYTES offsets, with
40 * nothing else.
41 * @note Each member below states its own alignment requirement.
42 */
43typedef struct
44{
45 uint16_t (*load16)(const ProximusCfg *args); /**< Reads two bytes. */
46 uint32_t (*load32)(const ProximusCfg *args); /**< Reads four bytes. */
47 uint64_t (*load64)(const ProximusCfg *args); /**< Reads eight bytes. */
48 void (*put16)(const ProximusCfg *args); /**< Writes two bytes. */
49 void (*put32)(const ProximusCfg *args); /**< Writes four bytes. */
50 void (*put64)(const ProximusCfg *args); /**< Writes eight bytes. */
51 embed_word (*load)(const ProximusCfg *args); /**< Reads one word. */
52 void (*put)(const ProximusCfg *args); /**< Writes one word. */
53 embed_word (*al_load)(const ProximusCfg *args); /**< Reads one word from an aligned address. */
54 void (*al_put)(const ProximusCfg *args); /**< Writes one word to an aligned address. */
55 uint64_t (*al_load64)(const ProximusCfg *args); /**< Reads eight bytes from an aligned address. */
56 void (*al_put64)(const ProximusCfg *args); /**< Writes eight bytes to an aligned address. */
57 void (*read)(const ProximusCfg *args); /**< Copies size bytes, aligning the destination first. */
59EMBED_TABLE_LAYOUT(ProximusOperorNs, load16, load32, load64, put16, put32, put64, load, put, al_load, al_put, al_load64,
60 al_put64, read);
61
62/**
63 * @brief Reads two bytes from args->at in the target's own order.
64 *
65 * @param[in] args Address to read from [BORROWS].
66 * @return The two bytes as a uint16_t.
67 * @warning args->at must be readable for two bytes, at any alignment.
68 */
69uint16_t mmgr_proxim_load16(const ProximusCfg *args);
70
71/**
72 * @brief Reads four bytes from args->at in the target's own order.
73 *
74 * @param[in] args Address to read from [BORROWS].
75 * @return The four bytes as a uint32_t.
76 * @warning args->at must be readable for four bytes, at any alignment.
77 */
78uint32_t mmgr_proxim_load32(const ProximusCfg *args);
79
80/**
81 * @brief Reads eight bytes from args->at in the target's own order.
82 *
83 * @param[in] args Address to read from [BORROWS].
84 * @return The eight bytes as a uint64_t.
85 * @warning args->at must be readable for eight bytes, at any alignment.
86 */
87uint64_t mmgr_proxim_load64(const ProximusCfg *args);
88
89/**
90 * @brief Writes the low two bytes of args->val to args->dst in the target's own order.
91 *
92 * @param[in] args Destination and value [BORROWS].
93 * @note The upper six bytes of args->val take no part.
94 * @warning args->dst must be writable for two bytes, at any alignment.
95 */
97
98/**
99 * @brief Writes the low four bytes of args->val to args->dst in the target's own order.
100 *
101 * @param[in] args Destination and value [BORROWS].
102 * @note The upper four bytes of args->val take no part.
103 * @warning args->dst must be writable for four bytes, at any alignment.
104 */
106
107/**
108 * @brief Writes all eight bytes of args->val to args->dst in the target's own order.
109 *
110 * @param[in] args Destination and value [BORROWS].
111 * @warning args->dst must be writable for eight bytes, at any alignment.
112 */
114
115/**
116 * @brief Reads one word from args->at in the target's own order.
117 *
118 * @param[in] args Address to read from [BORROWS].
119 * @return The bytes as an embed_word.
120 * @warning args->at must be readable for a whole embed_word, at any alignment.
121 */
122embed_word mmgr_proxim_load(const ProximusCfg *args);
123
124/**
125 * @brief Writes the low word of args->val to args->dst in the target's own order.
126 *
127 * @param[in] args Destination and value [BORROWS].
128 * @warning args->dst must be writable for a whole embed_word, at any alignment.
129 */
130void mmgr_proxim_put(const ProximusCfg *args);
131
132/**
133 * @brief Reads one word from an aligned args->at, in the target's own order.
134 *
135 * @param[in] args Address to read from [BORROWS].
136 * @return The bytes as an embed_word.
137 * @note Reaches the same bytes as mmgr_proxim_load, through a type that keeps embed_word's alignment.
138 * @warning args->at must be readable for a whole embed_word and aligned for one.
139 */
140embed_word mmgr_aequus_load(const ProximusCfg *args);
141
142/**
143 * @brief Writes the low word of args->val to an aligned args->dst.
144 *
145 * @param[in] args Destination and value [BORROWS].
146 * @note Reaches the same bytes as mmgr_proxim_put, through a type that keeps embed_word's alignment.
147 * @warning args->dst must be writable for a whole embed_word and aligned for one.
148 */
149void mmgr_aequus_put(const ProximusCfg *args);
150
151/**
152 * @brief Reads eight bytes from an aligned args->at, in the target's own order.
153 *
154 * @param[in] args Address to read from [BORROWS].
155 * @return The eight bytes as a uint64_t.
156 * @note Reaches the same bytes as mmgr_proxim_load64, through a type that keeps uint64_t's alignment.
157 * @warning args->at must be readable for eight bytes and aligned for a uint64_t.
158 */
159uint64_t mmgr_aequus_load64(const ProximusCfg *args);
160
161/**
162 * @brief Writes all eight bytes of args->val to an aligned args->dst.
163 *
164 * @param[in] args Destination and value [BORROWS].
165 * @note Reaches the same bytes as mmgr_proxim_put64, through a type that keeps uint64_t's alignment.
166 * @warning args->dst must be writable for eight bytes and aligned for a uint64_t.
167 */
169
170/**
171 * @brief Copies args->size bytes from args->at to args->dst.
172 *
173 * @param[in] args Destination, source and count [BORROWS].
174 * @note Copies bytes until args->dst reaches a word boundary, then whole words, then the odd bytes left.
175 * @note This is the only entry that reads args->size.
176 * @warning Copies forward. An args->dst above args->at within one region would read bytes it has already written.
177 */
179
180/**
181 * @brief Dispatch table instance named proxim.
182 *
183 * @note The nine unaligned members call the mmgr_proxim_ functions.
184 * @note The four al_ members call the mmgr_aequus_ ones.
185 */
186EMBED_TABLE_STORAGE ProximusOperorNs proxim EMBED_UNUSED = {
187 .load16 = mmgr_proxim_load16,
188 .load32 = mmgr_proxim_load32,
189 .load64 = mmgr_proxim_load64,
190 .put16 = mmgr_proxim_put16,
191 .put32 = mmgr_proxim_put32,
192 .put64 = mmgr_proxim_put64,
193 .load = mmgr_proxim_load,
194 .put = mmgr_proxim_put,
195 .al_load = mmgr_aequus_load,
196 .al_put = mmgr_aequus_put,
197 .al_load64 = mmgr_aequus_load64,
198 .al_put64 = mmgr_aequus_put64,
199 .read = mmgr_proxim_read,
200};
201
202EMBED_END_DECLS
203
204#endif
The embedded_types headers every module builds on.
void mmgr_proxim_put16(const ProximusCfg *args)
Writes the low two bytes of args->val to args->dst in the target's own order.
uint64_t mmgr_aequus_load64(const ProximusCfg *args)
Reads eight bytes from an aligned args->at, in the target's own order.
uint64_t mmgr_proxim_load64(const ProximusCfg *args)
Reads eight bytes from args->at in the target's own order.
static const ProximusOperorNs proxim
Dispatch table instance named proxim.
void mmgr_proxim_put32(const ProximusCfg *args)
Writes the low four bytes of args->val to args->dst in the target's own order.
void mmgr_aequus_put64(const ProximusCfg *args)
Writes all eight bytes of args->val to an aligned args->dst.
uint32_t mmgr_proxim_load32(const ProximusCfg *args)
Reads four bytes from args->at in the target's own order.
embed_word mmgr_aequus_load(const ProximusCfg *args)
Reads one word from an aligned args->at, in the target's own order.
void mmgr_proxim_put64(const ProximusCfg *args)
Writes all eight bytes of args->val to args->dst in the target's own order.
uint16_t mmgr_proxim_load16(const ProximusCfg *args)
Reads two bytes from args->at in the target's own order.
void mmgr_proxim_put(const ProximusCfg *args)
Writes the low word of args->val to args->dst in the target's own order.
void mmgr_proxim_read(const ProximusCfg *args)
Copies args->size bytes from args->at to args->dst.
embed_word mmgr_proxim_load(const ProximusCfg *args)
Reads one word from args->at in the target's own order.
void mmgr_aequus_put(const ProximusCfg *args)
Writes the low word of args->val to an aligned args->dst.
Arguments for the proxim calls.
const uint64_t val
const void *const at
void *const dst
const size_t size
Type of the proxim dispatch table.
embed_word(*) al_load(const ProximusCfg *args)
void(*) put(const ProximusCfg *args)
void(*) al_put(const ProximusCfg *args)
void(*) read(const ProximusCfg *args)
void(*) put64(const ProximusCfg *args)
uint32_t(*) load32(const ProximusCfg *args)
uint16_t(*) load16(const ProximusCfg *args)
uint64_t(*) al_load64(const ProximusCfg *args)
uint64_t(*) load64(const ProximusCfg *args)
void(*) al_put64(const ProximusCfg *args)
void(*) put16(const ProximusCfg *args)
void(*) put32(const ProximusCfg *args)
embed_word(*) load(const ProximusCfg *args)