ZXFoundation™ 26h2
Loading...
Searching...
No Matches
aste.cxxm
1/// SPDX-License-Identifier: Apache-2.0
2/// @file arch/s390x/cpu/aste_types.cxxm
3/// @brief z/Architecture ASTE/ALE/ALT type definitions
4
5export module arch.s390x.cpu.aste;
6export import arch.s390x.cpu.aste.consts;
7export import :common;
8import zxfoundation.base.types;
9
10export {
11
12namespace arch::s390x::cpu::aste {
13
14 /// @brief ASN Second Table Entry — 64 bytes, 64-byte aligned.
15 struct [[gnu::packed]] alignas(64) aste {
16 u64 words[8]{};
17
18 /// @brief Test the I-bit (invalid) in word 0.
19 [[nodiscard]] auto is_invalid() const noexcept -> bool;
20
21 /// @brief Set or clear the I-bit (invalid) in word 0.
22 auto set_invalid(bool inv) noexcept -> void;
23
24 /// @brief Return the target address space ASCE (word 1).
25 [[nodiscard]] auto asce() const noexcept -> u64;
26
27 /// @brief Set the target address space ASCE (word 1).
28 auto set_asce(u64 val) noexcept -> void;
29
30 /// @brief Return the Access-List Designation (word 2).
31 [[nodiscard]] auto ald() const noexcept -> u64;
32
33 /// @brief Set the Access-List Designation (word 2).
34 auto set_ald(u64 val) noexcept -> void;
35
36 /// @brief Return the Authorization Index (AX) from word 0 bits 32–47.
37 [[nodiscard]] auto authorization_index() const noexcept -> u16;
38
39 /// @brief Set the Authorization Index (AX) in word 0 bits 32–47.
40 auto set_authorization_index(u16 ax) noexcept -> void;
41
42 /// @brief Return the raw 32-bit Linkage-Table Designation (bytes 24-27).
43 [[nodiscard]] auto ltd_raw() const noexcept -> u32;
44
45 /// @brief Set the raw 32-bit Linkage-Table Designation (bytes 24-27).
46 auto set_ltd_raw(u32 ltd) noexcept -> void;
47
48 /// @brief Test the subsystem-linkage control bit (V, LTD bit 0).
49 /// Must be 1 for PC/PT instructions to proceed.
50 [[nodiscard]] auto ltd_valid() const noexcept -> bool;
51 /// @brief Set or clear the V bit in the LTD.
52 auto set_ltd_valid(bool v) noexcept -> void;
53
54 /// @brief Return the linkage-table origin as a 31-bit real address.
55 /// LTD bits 1-24 with 7 zeros appended on the right.
56 [[nodiscard]] auto ltd_origin() const noexcept -> u64;
57
58 /// @brief Set the linkage-table origin from a 128-byte-aligned real address.
59 /// @pre @p addr must be 128-byte aligned (low 7 bits zero).
60 auto set_ltd_origin(u64 addr) noexcept -> void;
61
62 /// @brief Return the linkage-table length (LTL, LTD bits 25-31, 7 bits).
63 /// Actual table length = (LTL + 1) × 128 bytes.
64 [[nodiscard]] auto ltd_length() const noexcept -> u8;
65
66 /// @brief Set the linkage-table length (LTL).
67 auto set_ltd_length(u8 ltl) noexcept -> void;
68
69 /// @brief Zero all words.
70 auto clear() noexcept -> void;
71 };
72
73 static_assert(sizeof(aste) == 64, "ASTE must be exactly 64 bytes (PoP §3.8.4)");
74 static_assert(alignof(aste) == 64, "ASTE must be 64-byte aligned");
75
76 /// @brief Access List Entry — 16 bytes.
77 struct [[gnu::packed]] ale {
78 u64 words[2]{};
79
80 /// @brief Test the I-bit (invalid) in word 0.
81 [[nodiscard]] auto is_invalid() const noexcept -> bool;
82
83 /// @brief Set or clear the I-bit (invalid) in word 0.
84 auto set_invalid(bool inv) noexcept -> void;
85
86 /// @brief Return the real address of the referenced ASTE.
87 [[nodiscard]] auto aste_origin() const noexcept -> u64;
88
89 /// @brief Set the ASTE origin (must be 64-byte aligned).
90 auto set_aste_origin(u64 addr) noexcept -> void;
91
92 /// @brief Return the ALE sequence number used to validate an ALET.
93 [[nodiscard]] auto sequence() const noexcept -> u8;
94
95 /// @brief Set the ALE sequence number used to validate an ALET.
96 auto set_sequence(u8 val) noexcept -> void;
97
98 /// @brief Set whether the ALE prohibits store access.
99 auto set_fetch_only(bool fetch_only) noexcept -> void;
100
101 /// @brief Set the ASTE sequence number checked after ALE lookup.
102 auto set_aste_sequence(u32 val) noexcept -> void;
103
104 /// @brief Zero all words.
105 auto clear() noexcept -> void;
106 };
107
108 static_assert(sizeof(ale) == 16, "ALE must be exactly 16 bytes (PoP §3.8.3)");
109
110 /// @brief Initialize the ASTE/ALE subsystem.
111 auto aste_subsystem_init() noexcept -> void;
112
113 /// @brief Allocate the DUCT and dispatchable-unit access list for one
114 /// domain. The caller owns @p context for the domain lifetime.
115 [[nodiscard]] auto art_context_init(art_context& context) noexcept
116 -> ::std::expected<void, ::lib::kernel_error>;
117
118 /// @brief Release per-domain DUCT and access-list backing after every ALE
119 /// referring to it has been revoked.
120 auto art_context_destroy(art_context& context) noexcept -> void;
121
122 /// @brief Install a domain's DUCT in CR2 on the current CPU.
123 auto art_context_load(const art_context& context) noexcept -> void;
124
125 /// @brief Allocate an ASTE slot and populate it with a target ASCE.
126 /// @param target_asce The Address Space Control Element of the target domain.
127 /// @param auth_index Authorization Index (AX) for this ASTE.
128 /// @return The ASTE index on success, or an error.
129 [[nodiscard]] auto aste_alloc(
130 u64 target_asce,
131 u16 auth_index
132 ) noexcept -> ::std::expected<u32, ::lib::kernel_error>;
133
134 /// @brief Free an ASTE slot, marking it as invalid.
135 ///
136 /// @param aste_index The ASTE slot index to release.
137 /// @return Success, or an error if the index is invalid.
138 [[nodiscard]] auto aste_free(
139 u32 aste_index
140 ) noexcept -> ::std::expected<void, ::lib::kernel_error>;
141
142 /// @brief Create an ALE in @p context that points to the given ASTE.
143 /// @param aste_index The ASTE slot that this ALE will reference.
144 /// @return The ALET value (ALE slot index) on success, or an error.
145 [[nodiscard]] auto ale_create(
146 art_context& context,
147 u32 aste_index
148 ) noexcept -> ::std::expected<u32, ::lib::kernel_error>;
149
150 /// @brief Invalidate an ALE and purge the ALB.
151 ///
152 /// @param alet The ALET value (ALE slot index) to destroy.
153 /// @return Success, or an error if the ALET is invalid.
154 [[nodiscard]] auto ale_destroy(
155 art_context& context,
156 u32 alet
157 ) noexcept -> ::std::expected<void, ::lib::kernel_error>;
158
159 /// @brief Return a pointer to the ASTE at the given index.
160 /// @param index The ASTE slot index (0 to MAX_ASTE_ENTRIES-1).
161 /// @return Pointer to the ASTE, or nullptr if the index is out of range
162 /// or the subsystem is not initialized.
163 [[nodiscard]] auto aste_find(u32 index) noexcept -> aste*;
164
165} // namespace arch::s390x::cpu::aste
166
167} // end export