public inbox for sid@sourceware.org
 help / color / mirror / Atom feed
* New ro_value_control_register class
@ 2001-11-18 11:07 Ben Elliston
  2001-12-02 14:04 ` Ben Elliston
  0 siblings, 1 reply; 2+ messages in thread
From: Ben Elliston @ 2001-11-18 11:07 UTC (permalink / raw)
  To: sid

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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* New ro_value_control_register class
  2001-11-18 11:07 New ro_value_control_register class Ben Elliston
@ 2001-12-02 14:04 ` Ben Elliston
  0 siblings, 0 replies; 2+ messages in thread
From: Ben Elliston @ 2001-12-02 14:04 UTC (permalink / raw)
  To: sid

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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-12-02 22:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-18 11:07 New ro_value_control_register class Ben Elliston
2001-12-02 14:04 ` Ben Elliston

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).