ZXFoundation™ 26h2
Loading...
Searching...
No Matches
psw.cxxm
1/// SPDX-License-Identifier: Apache-2.0
2/// @file arch/s390x/cpu/psw_types.cxxm
3/// @brief z/Architecture PSW (Program Status Word) bit definitions.
4
5export module arch.s390x.cpu.psw;
6import zxfoundation.base.types;
7
8export {
9
10namespace arch::s390x::cpu::psw {
11
12 /// @brief DAT (Dynamic Address Translation) enable bit
13 constexpr u64 PSW_BIT_DAT = 0x0400000000000000ULL;
14
15 /// @brief I/O interrupt enable bit
16 constexpr u64 PSW_BIT_IO = 0x0200000000000000ULL;
17
18 /// @brief External interrupt enable bit
19 constexpr u64 PSW_BIT_EXT = 0x0100000000000000ULL;
20
21 /// @brief Machine-check interrupt enable bit
22 constexpr u64 PSW_BIT_MCCK = 0x0004000000000000ULL;
23
24 /// @brief Wait state bit
25 constexpr u64 PSW_BIT_WAIT = 0x0002000000000000ULL;
26
27 /// @brief Problem state (user mode) bit
28 constexpr u64 PSW_BIT_PSTATE = 0x0001000000000000ULL;
29
30 /// @brief Extended addressing (EA) bit
31 constexpr u64 PSW_BIT_EA = 0x0000000100000000ULL;
32
33 /// @brief Basic addressing (BA) bit
34 constexpr u64 PSW_BIT_BA = 0x0000000080000000ULL;
35
36 /// @brief Primary Space Mode (ASC = 00) — no bits set.
37 constexpr u64 PSW_ASC_PRIMARY = 0x0000000000000000ULL;
38
39 /// @brief Secondary Space Mode (ASC = 01).
40 constexpr u64 PSW_ASC_SECONDARY = 0x0000800000000000ULL;
41
42 /// @brief Access register mode (ASC = 10).
43 constexpr u64 PSW_ASC_ACCREG = 0x0000400000000000ULL;
44
45 /// @brief Home Space Mode (ASC = 11) — CR13 is the effective ASCE.
46 constexpr u64 PSW_ASC_HOME = 0x0000C00000000000ULL;
47
48 /// @brief Default PSW storage key (key 0 — master key, unrestricted).
49 constexpr u64 PSW_DEFAULT_KEY = 0ULL;
50
51 /// @brief 64-bit mode bits that MUST be present in every valid z/Arch PSW.
52 constexpr u64 PSW_ARCH_BITS = PSW_BIT_EA | PSW_BIT_BA;
53
54 /// @brief Kernel execution mask: supervisor, DAT off, all interrupts disabled, 64-bit.
55 constexpr u64 PSW_MASK_KERNEL = PSW_DEFAULT_KEY | PSW_ARCH_BITS | PSW_ASC_PRIMARY;
56
57 /// @brief Kernel DAT-on mask: supervisor, DAT on, all interrupts disabled, 64-bit.
58 constexpr u64 PSW_MASK_KERNEL_DAT = PSW_DEFAULT_KEY | PSW_BIT_DAT | PSW_ARCH_BITS | PSW_ASC_HOME;
59
60 /// @brief Kernel DAT-on mask with interrupts enabled (normal execution).
61 constexpr u64 PSW_MASK_KERNEL_ENABLED =
62 PSW_DEFAULT_KEY | PSW_BIT_DAT | PSW_BIT_IO | PSW_BIT_EXT | PSW_BIT_MCCK |
63 PSW_ARCH_BITS | PSW_ASC_HOME;
64
65 /// @brief User-mode PSW mask for entering a domain in problem state.
66 constexpr u64 PSW_MASK_USER =
67 PSW_DEFAULT_KEY |
68 PSW_BIT_PSTATE |
69 PSW_BIT_DAT |
70 PSW_BIT_IO |
71 PSW_BIT_EXT |
72 PSW_BIT_MCCK |
73 PSW_ARCH_BITS |
74 PSW_ASC_PRIMARY;
75
76 /// @brief PSW key field shift — bits 8–11 of the PSW mask word.
77 constexpr u32 PSW_KEY_SHIFT = 52;
78
79 /// @brief Disabled-wait PSW mask: wait state, no interrupts, 64-bit.
80 constexpr u64 PSW_MASK_DISABLED_WAIT = PSW_DEFAULT_KEY | PSW_BIT_WAIT | PSW_ARCH_BITS;
81
82 /// @brief Enabled-wait PSW mask.
83 constexpr u64 PSW_MASK_ENABLED_WAIT =
84 PSW_DEFAULT_KEY | PSW_BIT_DAT | PSW_BIT_IO | PSW_BIT_EXT | PSW_BIT_MCCK |
85 PSW_BIT_WAIT | PSW_ARCH_BITS | PSW_ASC_HOME;
86
87 /// @brief Standard halt address (appears in disabled-wait PSW during normal shutdown).
88 constexpr u64 PSW_STD_HALT_ADDR = 0x0000000000DEAD00ULL;
89
90 constexpr u64 PSW_LC_RESTART = 0x01A0ULL; ///< Restart new PSW
91 constexpr u64 PSW_LC_EXTERNAL = 0x01B0ULL; ///< External new PSW.
92 constexpr u64 PSW_LC_SVC = 0x01C0ULL; ///< Supervisor-call new PSW.
93 constexpr u64 PSW_LC_PROGRAM = 0x01D0ULL; ///< Program-check new PSW.
94 constexpr u64 PSW_LC_MCCK = 0x01E0ULL; ///< Machine-check new PSW.
95 constexpr u64 PSW_LC_IO = 0x01F0ULL; ///< I/O new PSW.
96
97 /// @brief 64-bit z/Architecture PSW (16 bytes, 8-byte aligned per PoP §4.2).
98 struct [[gnu::packed]] alignas(8) zx_psw {
99 u64 mask{}; ///< PSW mask word (bits 0–63 per PoP Figure 4-1).
100 u64 addr{}; ///< Instruction address (bits 64–127).
101 };
102
103 // Two u32 registers from EPSW packed into irqflags (u64).
104 struct [[gnu::packed]] alignas(u64) epsw_words {
105 u32 hi;
106 u32 lo;
107 };
108
109 static_assert(sizeof(zx_psw) == 16, "zx_psw must be exactly 16 bytes");
110 static_assert(alignof(zx_psw) == 8, "zx_psw must be 8-byte aligned");
111
112 /// @brief Extract the current PSW mask via EPSW. addr is unavailable; set to 0.
113 [[nodiscard]] auto extract_psw() noexcept -> zx_psw;
114
115 [[noreturn]] auto load_psw(const zx_psw& psw) noexcept -> void;
116
117 [[noreturn]] auto disabled_wait() noexcept -> void;
118
119 /// @brief Enter enabled-wait state — the z/Architecture idle primitive.
120 auto enabled_wait() noexcept -> void;
121
122 auto write_psw_to_lowcore(u64 lc_offset, zx_psw psw) noexcept -> void;
123
124 [[nodiscard]] auto make_handler_psw(u64 entry_virt) noexcept -> zx_psw;
125 [[nodiscard]] auto make_ap_restart_psw(u64 entry_phys) noexcept -> zx_psw;
126
127} // namespace arch::s390x::cpu::psw
128
129} // end export