osom_encoders_x86_64/encoders/encoding_funcs/
enc.rs

1//! # Content
2//!
3//! Holds encoders for instructions valid in 64-bit X86 instruction set.
4//! Manually handled file.
5#![allow(clippy::wildcard_imports)]
6use crate::models::EncodedX86_64Instruction;
7
8/// Holds encoders not directly defined in the Intel's manual.
9pub mod miscellaneous {
10    use super::*;
11
12    /// No operation for given length. It is guaranteed that the returned
13    /// value is of the passed `length`.
14    ///
15    /// Uses Intel's recommended multi-byte NOP sequences. Note that
16    /// [`encode_nop_with_length(1)`][encode_nop_with_length] call
17    /// is equivalent to [`encode_nop()`][crate::encoders::singleton::encode_nop],
18    /// although slightly less efficient.
19    ///
20    /// # Panics
21    ///
22    /// The caller *must* ensure that `length` is in the `1..=9` range.
23    /// Otherwise the function panics.
24    #[inline]
25    pub const fn encode_nop_with_length(length: u8) -> EncodedX86_64Instruction {
26        unsafe {
27            match length {
28                1 => EncodedX86_64Instruction::from_array([0x90]),
29                2 => EncodedX86_64Instruction::from_array([0x66, 0x90]),
30                3 => EncodedX86_64Instruction::from_array([0x0F, 0x1F, 0x00]),
31                4 => EncodedX86_64Instruction::from_array([0x0F, 0x1F, 0x40, 0x00]),
32                5 => EncodedX86_64Instruction::from_array([0x0F, 0x1F, 0x44, 0x00, 0x00]),
33                6 => EncodedX86_64Instruction::from_array([0x66, 0x0F, 0x1F, 0x44, 0x00, 0x00]),
34                7 => EncodedX86_64Instruction::from_array([0x0F, 0x1F, 0x80, 0x00, 0x00, 0x00, 0x00]),
35                8 => EncodedX86_64Instruction::from_array([0x0F, 0x1F, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00]),
36                9 => EncodedX86_64Instruction::from_array([0x66, 0x0F, 0x1F, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00]),
37                _ => panic!("Invalid length for encode_nop_with_length call. Expected u8 in 1..=9 range."),
38            }
39        }
40    }
41}