Skip to content

Instantly share code, notes, and snippets.

@folkertdev
Created January 12, 2025 16:00
Show Gist options
  • Select an option

  • Save folkertdev/0fdd8a0ba7d43198bfb8a1300ca2a23c to your computer and use it in GitHub Desktop.

Select an option

Save folkertdev/0fdd8a0ba7d43198bfb8a1300ca2a23c to your computer and use it in GitHub Desktop.
use of the `stfle` instruction for s390x targets, to get the extended facility list
[build]
target = "s390x-unknown-linux-gnu"
[target.s390x-unknown-linux-gnu]
# runner = "qemu-s390x -cpu max -L /usr/s390x-linux-gnu"
runner = "qemu-s390x -cpu qemu,vx=on,vxeh=on,vxeh2=off -L /usr/s390x-linux-gnu"
# runner = "qemu-s390x -cpu z10EC -L /usr/s390x-linux-gnu"
linker = "s390x-linux-gnu-gcc"
// https://www.ibm.com/support/pages/sites/default/files/2021-05/SA22-7871-10.pdf
// https://www.ibm.com/docs/en/SSQ2R2_15.0.0/com.ibm.tpf.toolkit.hlasm.doc/dz9zr006.pdf
// https://github.com/lucab/s390-tools/blob/7217903ce44909a230003a3d4dd38c8ddf6bdb9d/include/boot/s390.h#L476
struct ExtendedFacilityList([u64; 4]);
impl ExtendedFacilityList {
fn new() -> Self {
let mut result: [u64; 4] = [0; 4];
unsafe {
core::arch::asm!(
"lgr %r0, {0}", // Load reg0 with size - 1
// equivalently ".insn s, 0xb2b00000, 0({1})",
"stfle 0({1})",
in(reg) result.len() as u64 - 1,
in(reg_addr) result.as_mut_ptr() ,
options(nostack, preserves_flags )
);
}
Self(result)
}
const fn get(&self, n: usize) -> bool {
// of course they number bits from the left...
self.0[n / 64] & (1 << (63 - (n % 64))) != 0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment