11//! Code for the *Vector Base Address Register*
22
3+ use crate :: register:: { SysReg , SysRegRead , SysRegWrite } ;
4+
35/// The *Vector Base Address Register* (VBAR)
46///
57/// There is no `modify` method because this register holds a single 32-bit address.
68#[ derive( Clone , Copy , PartialEq , Eq ) ]
79#[ repr( transparent) ]
810pub struct Vbar ( pub * mut u32 ) ;
911
12+ impl SysReg for Vbar {
13+ const CP : u32 = 15 ;
14+ const CRN : u32 = 12 ;
15+ const OP1 : u32 = 0 ;
16+ const CRM : u32 = 0 ;
17+ const OP2 : u32 = 0 ;
18+ }
19+
20+ impl SysRegRead for Vbar { }
21+
22+ impl SysRegWrite for Vbar { }
23+
1024impl Vbar {
1125 /// Reads the *Vector Base Address Register*
1226 #[ inline]
1327 pub fn read ( ) -> Vbar {
14- let r: usize ;
15- #[ cfg( target_arch = "arm" ) ]
16- unsafe {
17- core:: arch:: asm!( "mrc p15, 0, {}, c12, c0, 0" , out( reg) r, options( nomem, nostack, preserves_flags) ) ;
18- }
19- #[ cfg( not( target_arch = "arm" ) ) ]
20- {
21- r = 0 ;
22- }
23- Self ( r as * mut u32 )
28+ // Safety: Reading this register has no side-effects and is atomic
29+ unsafe { Self ( <Self as SysRegRead >:: read_raw ( ) as * mut u32 ) }
2430 }
2531
2632 /// Write to the *Vector Base Address Register*
@@ -30,12 +36,11 @@ impl Vbar {
3036 /// You must supply a correctly-aligned address of a valid Arm Cortex-R
3137 /// Vector Table.
3238 #[ inline]
33- pub unsafe fn write ( _value : Self ) {
39+ pub unsafe fn write ( value : Self ) {
3440 // Safety: Writing this register is atomic
35- #[ cfg( target_arch = "arm" ) ]
3641 unsafe {
37- core :: arch :: asm! ( "mcr p15, 0, {}, c12, c0, 0" , in ( reg ) _value . 0 , options ( nomem , nostack , preserves_flags ) ) ;
38- } ;
42+ < Self as SysRegWrite > :: write_raw ( value . 0 as u32 ) ;
43+ }
3944 }
4045}
4146
0 commit comments