Program Status Word: Difference between revisions

From OSDev.wiki
Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content added Content deleted
No edit summary
m (Bot: Replace deprecated source tag with syntaxhighlight)
 
(One intermediate revision by one other user not shown)
Line 69: Line 69:


=== Structure (S390) ===
=== Structure (S390) ===
<source lang="c">
<syntaxhighlight lang="c">
struct s390_psw {
struct s390_psw {
uint32_t flags;
uint32_t flags;
uint32_t address;
uint32_t address;
} __attribute__((packed, aligned(8)));
} __attribute__((packed, aligned(8)));
</syntaxhighlight>
</source>


=== Structure (z/Arch) ===
=== Structure (z/Arch) ===
<source lang="c">
<syntaxhighlight lang="c">
struct s390x_psw {
struct s390x_psw {
uint32_t hi_flags;
uint32_t hi_flags;
Line 84: Line 84:
uint32_t lo_address;
uint32_t lo_address;
} __attribute__((packed, aligned(8)));
} __attribute__((packed, aligned(8)));
</syntaxhighlight>
</source>


=== Portable PSW declaration ===
=== Portable PSW declaration ===
<source lang="c">
<syntaxhighlight lang="c">
/* Helper function to create a PSW adjusted to the current machine */
/* Helper function to create a PSW adjusted to the current machine */
#if (MACHINE >= M_ZARCH)
#if (MACHINE >= M_ZARCH)
Line 108: Line 108:
S390_PSW_ENABLE_ARCHMODE | S390_PSW_ENABLE_MCI | S390_PSW_WAIT_STATE| S390_PSW_IO_INT | S390_PSW_DAT
S390_PSW_ENABLE_ARCHMODE | S390_PSW_ENABLE_MCI | S390_PSW_WAIT_STATE| S390_PSW_IO_INT | S390_PSW_DAT
);
);
</syntaxhighlight>
</source>


=== Service Interrupt handler ===
=== Service Interrupt handler ===
<source lang="asm">
<syntaxhighlight lang="asm">
.globl s390_supervisor_call_handler_stub
.globl s390_supervisor_call_handler_stub
s390_supervisor_call_handler_stub:
s390_supervisor_call_handler_stub:
Line 122: Line 122:
lm %r0, %r15, S390_FLCGRSAV
lm %r0, %r15, S390_FLCGRSAV
lpsw S390_FLCSOPSW
lpsw S390_FLCSOPSW
</syntaxhighlight>
</source>


== See also ==
== See also ==
=== External links ===
=== External links ===
* https://www.kernel.org/doc/html/v5.3/s390/debugging390.html Contains the structure of the PSW (in MSB order)
* [https://www.kernel.org/doc/html/v5.3/s390/debugging390.html Contains the structure of the PSW (in MSB order)]


=== Source code ===
=== Source code ===
* https://sourceforge.net/p/pdos/gitcode/ci/master/tree/pdpclib/sapsupa.asm#l720 Example I/O PSWs (HLASM)
* [https://sourceforge.net/p/pdos/gitcode/ci/master/tree/pdpclib/sapsupa.asm#l720 Example I/O PSWs (HLASM)]
* https://github.com/udos-project/UDOS/blob/3f446f4117d78fddf181f1df2927a9437fb08035/kernel/s390/int_handler.S Handlers for different interrupts and exceptions
* [https://github.com/udos-project/UDOS/blob/3f446f4117d78fddf181f1df2927a9437fb08035/kernel/s390/int_handler.S Handlers for different interrupts and exceptions (GAS)]


[[Category:S390]]
[[Category:S390]]

Latest revision as of 04:46, 9 June 2024

The PSW (Program Status Word) describes the current configuration for the context. It control whenever DAT is enabled or not, which allows virtual spaces. It also controls several flags such as the Wait state, Problem state, interrupt masking and other essential execution parameters.

While the 390 documentation lists the PSW in Most-Significant-Bit order, the PSW listed here will be in Least-Significant-Bit order for simplicity.

Bits Name
0 Extended addressing mode (z/Arch only)
1-7 Reserved
8 Unknown (?)
9 Enable exception for Exponent Underflow
10 Enable exception for Decimal Overflow
11 Enable exception for Fixed Point Overflow
12-13 Condition code
14-15 Address space control
16 Problem state (1=Disables unprivileged instruction execution)
17 Wait state (Wait for interrupt)
18 Machine Check Interrupt mask
19 1=S390, 0=z/Arch
20-23 PSW Key for complex memory protection
24 External Interrupt mask
25 Input/Output Interrupt mask
26 Enable DAT
27-29 Reserved
30 Enable program event recording
31 Reserved and must be 0

Examples

Structure (S390)

struct s390_psw {
    uint32_t flags;
    uint32_t address;
} __attribute__((packed, aligned(8)));

Structure (z/Arch)

struct s390x_psw {
    uint32_t hi_flags;
    uint32_t lo_flags; /* It's all zero except for the MSB (in S/390 order) */
    uint32_t hi_address;
    uint32_t lo_address;
} __attribute__((packed, aligned(8)));

Portable PSW declaration

/* Helper function to create a PSW adjusted to the current machine */
#if (MACHINE >= M_ZARCH)
#   define S390_PSW_DEFAULT_TYPE struct s390x_psw
#   define S390_PSW_DECL(name, address, flags)\
 S390_PSW_DEFAULT_TYPE name = {\
    (flags) | S390_PSW_AM64, S390_PSW_AM31, 0, (uint32_t)(address)\
}
#else
#   define S390_PSW_DEFAULT_TYPE struct s390_psw
#   define S390_PSW_DECL(name, address, flags)\
 S390_PSW_DEFAULT_TYPE name = {\
    (flags), (uint32_t)(address) + S390_PSW_DEFAULT_AMBIT\
}
#endif

const S390_PSW_DECL(
    wait_io_psw,
    0,
    S390_PSW_ENABLE_ARCHMODE | S390_PSW_ENABLE_MCI | S390_PSW_WAIT_STATE| S390_PSW_IO_INT | S390_PSW_DAT
);

Service Interrupt handler

.globl s390_supervisor_call_handler_stub
s390_supervisor_call_handler_stub:
    stm %r0, %r15, S390_FLCGRSAV
    lm %r0, %r15, S390_FLCCRSAV

    larl %r15, int_stack_bottom
    brasl %r14, s390_supervisor_call_handler

    lm %r0, %r15, S390_FLCGRSAV
    lpsw S390_FLCSOPSW

See also

External links

Source code