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.

Revisions

  1. folkertdev renamed this gist Jan 12, 2025. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. folkertdev created this gist Jan 12, 2025.
    9 changes: 9 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    [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"
    27 changes: 27 additions & 0 deletions lib.rs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    // 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
    }
    }