Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.3 KiB

  1. // $Header: G:/SwDev/WDM/Video/bt848/rcs/Regfield.cpp 1.3 1998/04/29 22:43:36 tomz Exp $
  2. #include "regfield.h"
  3. /* Method: RegField::MakeAMask
  4. * Purpose: Computes a mask used to isolate a field withing a register based
  5. * on the width of a field
  6. */
  7. inline DWORD RegField::MakeAMask()
  8. {
  9. // compute the mask to apply to the owner register to reset
  10. // all bits that are part of a field. Mask is based on the size of a field
  11. return ::MakeAMask( FieldWidth_ );
  12. }
  13. /* Method: RegField::operator DWORD()
  14. * Purpose: Performs the read from a field of register
  15. */
  16. RegField::operator DWORD()
  17. {
  18. // if write-only, get the shadow
  19. if ( GetRegisterType() == WO )
  20. return GetShadow();
  21. // for RO and RW do the actual read
  22. // get the register data and move it to the right position
  23. DWORD dwValue = ( Owner_ >> StartBit_ );
  24. DWORD dwMask = MakeAMask();
  25. return dwValue & dwMask;
  26. }
  27. /* Method: RegField::operator=
  28. * Purpose: performs the assignment to a field of register
  29. * Note:
  30. This function computes the mask to apply to the owner register to reset
  31. all bits that are part of a field. Mask is based on the start position and size
  32. Then it calculates the proper value from the passed argument ( moves the size
  33. number of bits to the starting position ) and ORs these bits in the owner register.
  34. */
  35. DWORD RegField::operator=( DWORD dwValue )
  36. {
  37. // if a register is read-only nothing is done. This is an error
  38. if ( GetRegisterType() == RO )
  39. return ReturnAllFs();
  40. SetShadow( dwValue );
  41. // get a mask
  42. DWORD dwMask = MakeAMask();
  43. // move mask to a proper position
  44. dwMask = dwMask << StartBit_;
  45. // calculate the proper value from the passed argument ( move the size
  46. // number of bits to the starting position )
  47. DWORD dwFieldValue = dwValue << StartBit_;
  48. dwFieldValue &= dwMask;
  49. // do not perform intermediate steps on the owner; rather use a temp and update
  50. // the owner at once
  51. DWORD dwRegContent = Owner_;
  52. // reset the relevant bits
  53. if ( GetRegisterType() == RR )
  54. dwRegContent = 0;
  55. else
  56. dwRegContent &= ~dwMask;
  57. // OR these bits in the owner register.
  58. dwRegContent |= dwFieldValue;
  59. Owner_ = dwRegContent;
  60. return dwValue;
  61. }