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