/// Use HPET to figure Local APIC Timer freq
Use HPET to figure Local APIC Timer freq
Use HPET to figure Local APIC Timer freq
fn init_hpet(
    mapper: &mut impl Mapper<Size4KiB>,
    frame_allocator: &mut impl FrameAllocator<Size4KiB>,
    hpet_info: &HpetInfo,
) {
    let addr = hpet_info.base_address as u64;
    alloc_phys(mapper, frame_allocator, addr, addr, None);
    let gen_caps = unsafe { read_volatile(addr as *const u64) };
    assert!(gen_caps.get_bit(13));
    println!(
        "Found HPET at {:x}, rev. id: {:x}, vendor id: {:x}",
        addr,
        gen_caps.get_bits(0..=7),
        gen_caps.get_bits(16..=31)
    );
    return;
    let period = gen_caps.get_bits(32..=63);
    let freq = 10u64.pow(15) / period;
    let ticks = freq / 1000; // ticks for 1ms
    // Timer 0
    let cmp_addr = (hpet_info.base_address + 0x108 + 0x20 * 0) as *mut u64;
    unsafe { write_volatile(cmp_addr, ticks * HPET_INTERVAL as u64) }
    // Main Counter
    let cmp_addr = (hpet_info.base_address + 0x0F0) as *mut u64;
    unsafe { write_volatile(cmp_addr, 0) }
    /* let nums = gen_caps.get_bits(8..=15);
    for i in 0..nums {
        let addr = addr + 0x100 + 0x20 * i;
        let n_caps = unsafe { read_volatile(addr as *const u64) };
        assert!(n_caps.get_bit(5));
    } */
    // Enable HPET
    let addr = (hpet_info.base_address + 0x10) as *mut u64;
    let mut gen_config = unsafe { read_volatile(addr) };
    gen_config.set_bit(0, true); // enable "legacy replacement" mapping
    gen_config.set_bit(1, true); // enable timer interrupts
    unsafe { write_volatile(addr, gen_config) }
    // Config timer 0
    let cfg_addr = (hpet_info.base_address + 0x100 + 0x20 * 0) as *mut u64;
    let mut cfg = unsafe { read_volatile(cfg_addr) };
    cfg.set_bit(2, true); // enable triggering of interrupts
    cfg.set_bit(3, false); // enable non-periodic mode
    unsafe { write_volatile(cfg_addr, cfg) }
}
fn init_hpet ( mapper : & mut impl Mapper < Size4KiB > , frame_allocator : & mut impl FrameAllocator < Size4KiB > , hpet_info : & HpetInfo , ) { let addr = hpet_info . base_address as u64 ; alloc_phys ( mapper , frame_allocator , addr , addr , None ) ; let gen_caps = unsafe { read_volatile ( addr as * const u64 ) } ; assert ! ( gen_caps get_bit ( 13 ) ) ; println ! ( " " addr gen_caps get_bits ( 0 7 ) gen_caps get_bits ( 16 31 ) ) ; return ; let period = gen_caps . get_bits ( 32 ..= 63 ) ; let freq = 10u64 . pow ( 15 ) / period ; let ticks = freq / 1000 ; // ticks for 1ms // Timer 0 let cmp_addr = ( hpet_info . base_address + 0x108 + 0x20 * 0 ) as * mut u64 ; unsafe { write_volatile ( cmp_addr , ticks * HPET_INTERVAL as u64 ) } // Main Counter let cmp_addr = ( hpet_info . base_address + 0x0F0 ) as * mut u64 ; unsafe { write_volatile ( cmp_addr , 0 ) } /* let nums = gen_caps.get_bits(8..=15);
    for i in 0..nums {
        let addr = addr + 0x100 + 0x20 * i;
        let n_caps = unsafe { read_volatile(addr as *const u64) };
        assert!(n_caps.get_bit(5));
    } */ // Enable HPET let addr = ( hpet_info . base_address + 0x10 ) as * mut u64 ; let mut gen_config = unsafe { read_volatile ( addr ) } ; gen_config . set_bit ( 0 , true ) ; // enable "legacy replacement" mapping gen_config . set_bit ( 1 , true ) ; // enable timer interrupts unsafe { write_volatile ( addr , gen_config ) } // Config timer 0 let cfg_addr = ( hpet_info . base_address + 0x100 + 0x20 * 0 ) as * mut u64 ; let mut cfg = unsafe { read_volatile ( cfg_addr ) } ; cfg . set_bit ( 2 , true ) ; // enable triggering of interrupts cfg . set_bit ( 3 , false ) ; // enable non-periodic mode unsafe { write_volatile ( cfg_addr , cfg ) } }
Use HPET to figure Local APIC Timer freq
Use HPET to figure Local APIC Timer freq
mapper
&mut impl Mapper<Size4KiB>
frame_allocator
&mut impl FrameAllocator<Size4KiB>
hpet_info
&HpetInfo