|
1 |
| -#[cfg(test)] |
2 |
| -mod tests { |
3 |
| - #[test] |
4 |
| - fn it_works() { |
5 |
| - assert_eq!(2 + 2, 4); |
| 1 | +#![no_std] |
| 2 | +#![feature(unsafe_block_in_unsafe_fn)] |
| 3 | +#![deny(unsafe_op_in_unsafe_fn)] |
| 4 | + |
| 5 | +use volatile::Volatile; |
| 6 | + |
| 7 | +pub mod registers; |
| 8 | + |
| 9 | +pub struct ApicRegisters { |
| 10 | + base_addr: *mut (), |
| 11 | +} |
| 12 | + |
| 13 | +impl ApicRegisters { |
| 14 | + pub fn id(&mut self) -> Volatile<&mut registers::Id> { |
| 15 | + unsafe { self.offset(Offset::Id) } |
| 16 | + } |
| 17 | + |
| 18 | + pub fn version(&mut self) -> Volatile<&mut registers::Version> { |
| 19 | + unsafe { self.offset(Offset::Version) } |
| 20 | + } |
| 21 | + |
| 22 | + pub fn extended_apic_feature(&mut self) -> Volatile<&mut registers::ExtendedApicFeature> { |
| 23 | + unsafe { self.offset(Offset::ExtendedApicFeature) } |
6 | 24 | }
|
| 25 | + |
| 26 | + pub fn extended_apic_control(&mut self) -> Volatile<&mut registers::ExtendedApicControl> { |
| 27 | + unsafe { self.offset(Offset::ExtendedApicControl) } |
| 28 | + } |
| 29 | + |
| 30 | + /* |
| 31 | + pub fn task_priority(&mut self) -> Volatile<&mut registers::TaskPriority> { |
| 32 | + unsafe { self.offset(Offset::TaskPriority) } |
| 33 | + } |
| 34 | +
|
| 35 | + pub fn arbitration_priority(&mut self) -> Volatile<&mut registers::ArbitrationPriority> { |
| 36 | + unsafe { self.offset(Offset::ArbitrationPriority) } |
| 37 | + } |
| 38 | +
|
| 39 | + pub fn processor_priority(&mut self) -> Volatile<&mut registers::ProcessorPriority> { |
| 40 | + unsafe { self.offset(Offset::ProcessorPriority) } |
| 41 | + } |
| 42 | +
|
| 43 | + pub fn end_of_interrupt(&mut self) -> Volatile<&mut registers::EndOfInterrupt> { |
| 44 | + unsafe { self.offset(Offset::EndOfInterrupt) } |
| 45 | + } |
| 46 | + */ |
| 47 | + |
| 48 | + unsafe fn offset<T>(&mut self, offset: Offset) -> Volatile<&mut T> { |
| 49 | + let ptr = self.base_addr.wrapping_add(offset as usize).cast(); |
| 50 | + Volatile::new(unsafe { &mut *ptr }) |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +#[repr(usize)] |
| 55 | +pub enum Offset { |
| 56 | + Id = 0x20, |
| 57 | + Version = 0x30, |
| 58 | + TaskPriority = 0x80, |
| 59 | + ArbitrationPriority = 0x90, |
| 60 | + ProcessorPriority = 0xa0, |
| 61 | + EndOfInterrupt = 0xb0, |
| 62 | + RemoteRead = 0xc0, |
| 63 | + LocalDestination = 0xd0, |
| 64 | + DestinationFormat = 0xe0, |
| 65 | + SpuriousInterruptVector = 0xf0, |
| 66 | + InService = 0x100, |
| 67 | + TriggerMode = 0x180, |
| 68 | + InterruptRequest = 0x200, |
| 69 | + ErrorStatus = 0x280, |
| 70 | + InterruptCommand = 0x300, |
| 71 | + TimerLocalVectorTableEntry = 0x320, |
| 72 | + ThermalLocalVectorTableEntry = 0x330, |
| 73 | + PerformanceCounterLocalVectorTableEntry = 0x340, |
| 74 | + LocalInterrupt0VectorTableEntry = 0x350, |
| 75 | + LocalInterrupt1VectorTableEntry = 0x360, |
| 76 | + ErrorVectorTableEntry = 0x370, |
| 77 | + TimerInitialCount = 0x380, |
| 78 | + TimerCurrentCount = 0x390, |
| 79 | + TimerDivideConfiguration = 0x3e0, |
| 80 | + ExtendedApicFeature = 0x400, |
| 81 | + ExtendedApicControl = 0x410, |
| 82 | + SpecificEndOfInterrupt = 0x420, |
| 83 | + InterruptEnable = 0x480, |
| 84 | + ExtendedInterruptLocalVectorTable = 0x500, |
7 | 85 | }
|
0 commit comments