@@ -58,6 +58,16 @@ impl Pic {
5858 unsafe fn end_of_interrupt ( & mut self ) {
5959 self . command . write ( CMD_END_OF_INTERRUPT ) ;
6060 }
61+
62+ /// Reads the interrupt mask of this PIC.
63+ unsafe fn read_mask ( & mut self ) -> u8 {
64+ self . data . read ( )
65+ }
66+
67+ /// Writes the interrupt mask of this PIC.
68+ unsafe fn write_mask ( & mut self , mask : u8 ) {
69+ self . data . write ( mask)
70+ }
6171}
6272
6373/// A pair of chained PIC controllers. This is the standard setup on x86.
@@ -81,7 +91,7 @@ impl ChainedPics {
8191 command : cpuio:: UnsafePort :: new ( 0xA0 ) ,
8292 data : cpuio:: UnsafePort :: new ( 0xA1 ) ,
8393 } ,
84- ]
94+ ] ,
8595 }
8696 }
8797
@@ -97,13 +107,12 @@ impl ChainedPics {
97107 // allegedly takes long enough to make everything work on most
98108 // hardware. Here, `wait` is a closure.
99109 let mut wait_port: cpuio:: Port < u8 > = cpuio:: Port :: new ( 0x80 ) ;
100- let mut wait = || { wait_port. write ( 0 ) } ;
110+ let mut wait = || wait_port. write ( 0 ) ;
101111
102112 // Save our original interrupt masks, because I'm too lazy to
103113 // figure out reasonable values. We'll restore these when we're
104114 // done.
105- let saved_mask1 = self . pics [ 0 ] . data . read ( ) ;
106- let saved_mask2 = self . pics [ 1 ] . data . read ( ) ;
115+ let saved_masks = self . read_masks ( ) ;
107116
108117 // Tell each PIC that we're going to send it a three-byte
109118 // initialization sequence on its data port.
@@ -131,8 +140,23 @@ impl ChainedPics {
131140 wait ( ) ;
132141
133142 // Restore our saved masks.
134- self . pics [ 0 ] . data . write ( saved_mask1) ;
135- self . pics [ 1 ] . data . write ( saved_mask2) ;
143+ self . write_masks ( saved_masks[ 0 ] , saved_masks[ 1 ] )
144+ }
145+
146+ /// Reads the interrupt masks of both PICs.
147+ pub unsafe fn read_masks ( & mut self ) -> [ u8 ; 2 ] {
148+ [ self . pics [ 0 ] . read_mask ( ) , self . pics [ 1 ] . read_mask ( ) ]
149+ }
150+
151+ /// Writes the interrupt masks of both PICs.
152+ pub unsafe fn write_masks ( & mut self , mask1 : u8 , mask2 : u8 ) {
153+ self . pics [ 0 ] . write_mask ( mask1) ;
154+ self . pics [ 1 ] . write_mask ( mask2) ;
155+ }
156+
157+ /// Disables both PICs by masking all interrupts.
158+ pub unsafe fn disable ( & mut self ) {
159+ self . write_masks ( u8:: MAX , u8:: MAX )
136160 }
137161
138162 /// Do we handle this interrupt?
0 commit comments