5export module arch.s390x.cpu.psw;
6import zxfoundation.base.types;
10namespace arch::s390x::cpu::psw {
13 constexpr u64 PSW_BIT_DAT = 0x0400000000000000ULL;
16 constexpr u64 PSW_BIT_IO = 0x0200000000000000ULL;
19 constexpr u64 PSW_BIT_EXT = 0x0100000000000000ULL;
22 constexpr u64 PSW_BIT_MCCK = 0x0004000000000000ULL;
25 constexpr u64 PSW_BIT_WAIT = 0x0002000000000000ULL;
28 constexpr u64 PSW_BIT_PSTATE = 0x0001000000000000ULL;
31 constexpr u64 PSW_BIT_EA = 0x0000000100000000ULL;
34 constexpr u64 PSW_BIT_BA = 0x0000000080000000ULL;
37 constexpr u64 PSW_ASC_PRIMARY = 0x0000000000000000ULL;
40 constexpr u64 PSW_ASC_SECONDARY = 0x0000800000000000ULL;
43 constexpr u64 PSW_ASC_ACCREG = 0x0000400000000000ULL;
46 constexpr u64 PSW_ASC_HOME = 0x0000C00000000000ULL;
49 constexpr u64 PSW_DEFAULT_KEY = 0ULL;
52 constexpr u64 PSW_ARCH_BITS = PSW_BIT_EA | PSW_BIT_BA;
55 constexpr u64 PSW_MASK_KERNEL = PSW_DEFAULT_KEY | PSW_ARCH_BITS | PSW_ASC_PRIMARY;
58 constexpr u64 PSW_MASK_KERNEL_DAT = PSW_DEFAULT_KEY | PSW_BIT_DAT | PSW_ARCH_BITS | PSW_ASC_HOME;
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;
66 constexpr u64 PSW_MASK_USER =
77 constexpr u32 PSW_KEY_SHIFT = 52;
80 constexpr u64 PSW_MASK_DISABLED_WAIT = PSW_DEFAULT_KEY | PSW_BIT_WAIT | PSW_ARCH_BITS;
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;
88 constexpr u64 PSW_STD_HALT_ADDR = 0x0000000000DEAD00ULL;
90 constexpr u64 PSW_LC_RESTART = 0x01A0ULL;
91 constexpr u64 PSW_LC_EXTERNAL = 0x01B0ULL;
92 constexpr u64 PSW_LC_SVC = 0x01C0ULL;
93 constexpr u64 PSW_LC_PROGRAM = 0x01D0ULL;
94 constexpr u64 PSW_LC_MCCK = 0x01E0ULL;
95 constexpr u64 PSW_LC_IO = 0x01F0ULL;
98 struct [[gnu::packed]]
alignas(8) zx_psw {
104 struct [[gnu::packed]]
alignas(u64) epsw_words {
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");
113 [[nodiscard]]
auto extract_psw()
noexcept -> zx_psw;
115 [[noreturn]]
auto load_psw(
const zx_psw& psw)
noexcept ->
void;
117 [[noreturn]]
auto disabled_wait()
noexcept ->
void;
120 auto enabled_wait()
noexcept ->
void;
122 auto write_psw_to_lowcore(u64 lc_offset, zx_psw psw)
noexcept ->
void;
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;