ZXFoundation™ 26h2
Loading...
Searching...
No Matches
processor.cxxm
Go to the documentation of this file.
1/// SPDX-License-Identifier: Apache-2.0
2/// @file arch/s390x/cpu/processor.cxxm
3/// @brief some miscellaneous srtuff
4
5export module arch.s390x.cpu.processor;
6export import arch.s390x.cpu.types;
7import zxfoundation.base.types;
8import arch.s390x.cpu.ctlreg;
9import arch.s390x.cpu.diag;
10import lib.bit;
11
12export {
13
14namespace arch::s390x::cpu::processor {
15
16 /// @brief cpuid structure (STIDP result).
17 struct alignas(8) [[gnu::packed]] cpuid {
18 u32 version:8;
19 u32 ident:24;
20 u32 machine:16;
21 u32 unused:16;
22 };
23
24 auto get_cpuid(cpuid *id) -> void {
25 __asm__ volatile("stidp %0" : "=m" (*id));
26 }
27
28 /// @brief Probe whether the kernel is running under a hypervisor.
29 /// @return true if the kernel is running under a hypervisor.
30 auto is_hypervisor() noexcept -> bool {
31 cpuid id{};
32 get_cpuid(&id);
33 return id.version == 0xff;
34 }
35
36 /// @brief Read the current stack pointer (r15).
37 [[nodiscard]] inline auto get_current_sp() noexcept -> u64 {
38 u64 sp;
39 __asm__ volatile ("stg %%r15, %0" : "=Q"(sp));
40 return sp;
41 }
42
43 /// @brief Store Prefix (STPX) — returns the physical address in the Prefix Register.
44 /// @return Physical base address of the current CPU's lowcore.
45 [[deprecated("STPX is expensive — use lowcore::get_current() on the hot path")]]
46 [[gnu::no_stack_protector]] auto get_prefix() noexcept -> u32 {
47 u32 prefix;
48 __asm__ volatile ("stpx %0" : "=Q"(prefix) : : "memory");
49 return prefix;
50 }
51
52 /// @brief Set Prefix (SPX) — loads a new value into the Prefix Register.
53 /// @param prefix New physical base address (must be 4 KB aligned).
54 auto set_prefix(const u32 prefix) noexcept -> void {
55 __asm__ volatile ("spx %0" :: "m" (prefix) : "memory");
56 }
57
58 /// @brief Store CPU Address (STAP) — returns the hardware CPU address.
59 /// @return The hardware CPU address used with SIGP instructions.
60 auto cpu_addr() noexcept -> u16 {
61 u16 addr;
62 __asm__ volatile ("stap %0" : "=m" (addr));
63 return addr;
64 }
65
66} // namespace arch::s390x::cpu::processor
67
68} // end export