<commit_before>//! Functions to read and write debug registers.
//!
//! * The dr{0,1,2,3} registers are used to set break points.
//! * The dr6 register contains debug conditions that were sampled at the time
//!   the last debug exception.
//! * The dr7 register enables or disables breakpoints and sets breakpoint
//!   conditions.
//!
//! See Intel Vol. 3a Chapter 17, "Debug, Branch, Profile, TSC ... Features"

use bit_field::BitField;
use bitflags::bitflags;

/// Read dr0.
///
/// # Safety
/// Needs CPL 0.
pub unsafe fn dr0() -> usize {
    let ret: usize;
    asm!("mov dr0, {}", out(reg) ret, options(att_syntax));
    ret
}

/// Write dr0.
///
/// # Safety
/// Needs CPL 0.
pub unsafe fn dr0_write(val: usize) {
    asm!("mov {}, dr0", in(reg) val, options(att_syntax));
}

/// Read dr1.
///
/// # Safety
/// Needs CPL 0.
pub unsafe fn dr1() -> usize {<commit_msg>Some more functionality for debugregs.<commit_after>//! Functions to read and write debug registers.
//!
//! * The dr{0,1,2,3} registers are used to set break points.
//! * The dr6 register contains debug conditions that were sampled at the time
//!   the last debug exception.
//! * The dr7 register enables or disables breakpoints and sets breakpoint
//!   conditions.
//!
//! See Intel Vol. 3a Chapter 17, "Debug, Branch, Profile, TSC ... Features"

use bit_field::BitField;
use bitflags::bitflags;

/// An array list of all available breakpoint registers.
pub const BREAKPOINT_REGS: [Breakpoint; 4] = [
    Breakpoint::Dr0,
    Breakpoint::Dr1,
    Breakpoint::Dr2,
    Breakpoint::Dr3,
];

/// Write dr{0-3} register based on provided `reg` enum.
pub unsafe fn dr_write(reg: Breakpoint, val: usize) {
    match reg {
        Breakpoint::Dr0 => dr0_write(val),
        Breakpoint::Dr1 => dr1_write(val),
        Breakpoint::Dr2 => dr2_write(val),
        Breakpoint::Dr3 => dr3_write(val),
    }
}

/// Read dr{0-3} register based on provided `reg` enum.
pub unsafe fn dr(reg: Breakpoint) -> usize {
    match reg {
        Breakpoint::Dr0 => dr0(),
        Breakpoint::Dr1 => dr1(),
        Breakpoint::Dr2 => dr2(),
        Breakpoint::Dr3 => dr3(),
    }
}

/// Read dr0.
///
/// # Safety
/// Needs CPL 0.
pub unsafe fn dr0() -> usize {
    let ret: usize;
    asm!("mov dr0, {}", out(reg) ret, options(att_syntax));
    ret
}

/// Write dr0.
///
/// # Safety
/// Needs CPL 0.
pub unsafe fn dr0_write(val: usize) {
    asm!("mov {}, dr0", in(reg) val, options(att_syntax));
}

/// Read dr1.
///
/// # Safety
/// Needs CPL 0.
pub unsafe fn dr1() -> usize {
{'fraction_non_alphanumeric': 0.1651556957035869, 'fraction_numerical': 0.025620811982656682, 'mean_word_length': 2.7378497790868925, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5032508', 'n_tokens_mistral': 875, 'n_tokens_neox': 846, 'n_words': 282}