This is the mail archive of the sid@sources.redhat.com mailing list for the SID project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

New ro_value_control_register class


The following patch adds a new sidutil:: "ro_value_control_register"
class which can be used to implement proper read-only registers where
the underlying value may be changed programmatically, but not via bus
accesses.  Does this look okay to commit?


2001-11-30  Ben Elliston  <bje@redhat.com>

	* sidbusutil.h (class ro_value_control_register): New class.
	(value_control_register::shift_amount): Make protected.

Index: sidbusutil.h
===================================================================
RCS file: /cvs/src/sid/include/sidbusutil.h,v
retrieving revision 1.53
diff -u -c -r1.53 sidbusutil.h
*** sidbusutil.h	2001/09/20 17:15:18	1.53
--- sidbusutil.h	2001/12/02 22:00:24
***************
*** 788,806 ****
  					 const value_control_register<DataType>& it);
      friend std::istream& operator >> <> (std::istream& i, 
  					 value_control_register<DataType>& it);
-   
- private:
-     DataType field_value;
      
      // return index of mask LSB
      unsigned shift_amount() const
        {
! 	DataType mask = this->get_mask ();
! 	for (unsigned i=0; i<sizeof(DataType)*8; i++)
! 	  if (mask & (1 << i))
! 	    return i;
! 	assert(0);
        }
    };
  
    // This is a type of control register whose value never changes.
--- 788,841 ----
  					 const value_control_register<DataType>& it);
      friend std::istream& operator >> <> (std::istream& i, 
  					 value_control_register<DataType>& it);
      
+   protected:
      // return index of mask LSB
      unsigned shift_amount() const
+     {
+       DataType mask = this->get_mask ();
+       for (unsigned i=0; i<sizeof(DataType)*8; i++)
+ 	if (mask & (1 << i))
+ 	  return i;
+       assert(0);
+     }
+     
+   private:
+     DataType field_value;
+   };
+ 
+   // This is a read-only value control register.  Its underlying value
+   // may be changed programmatically, but as far as a bus accessor is
+   // concerned, writing to the register has no effect.
+   template <typename DataType>
+   class ro_value_control_register: public value_control_register<DataType>
+   {
+   public:
+     ro_value_control_register(control_register_bank<DataType>* b,
+ 			      sid::host_int_4 o,
+ 			      DataType m,
+ 			      DataType v):
+       value_control_register<DataType>(b,o,m,true,true,v)
+     {}
+     
+     ro_value_control_register(control_register_bank<DataType>* b,
+ 			      sid::host_int_4 o,
+ 			      DataType m):
+       value_control_register<DataType>(b,o,m,true,true,0)
+     {}
+ 
+     // Some convenience operators for accessing register fields
+     void operator = (const DataType& v)
        {
! 	DataType shifted_v = v << this->shift_amount();
! 	value_control_register<DataType>::set (shifted_v, this->get_mask()); 
        }
+ 
+   protected:
+     void set (DataType set_value, DataType set_mask)
+     {
+       // do nothing
+     }
    };
  
    // This is a type of control register whose value never changes.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]