Hi guys!
I was curious a function is doing the following bit operations:
Code:
/**********************************************************************
Function : hw_update_pageref
Description : when a memory access occurs, the hardware update the reference
and dirty bits for the appropriate page. We simulate this by an
update when the page is found (in TLB or page table).
Inputs : page - page number
op - read (0) or write (1)
Outputs : 0 if successful, -1 otherwise
***********************************************************************/
int hw_update_pageref( ptentry_t *ptentry, int op )
{
ptentry->bits |= REFBIT;
ptentry->bits |= WSREFBIT;
if ( op ) { /* write */
ptentry->bits |= DIRTYBIT;
}
return 0;
}
bits is an int by the way.
And Here are the following constants I'm working with:
Code:
/* bitmasks */
#define VALIDBIT 0x1
#define REFBIT 0x2
#define DIRTYBIT 0x4
#define WSBITS 0x38 /* 3 bits for working set references -- highest is set at ref */
#define WSREFBIT 0x20
Basically that "bits" field is keeping track of all of those things, validbit, refbit, dirtybit, and working set bits, and workingrefbit.
So what I want to do is ONLY change the VALID BIT, from 0x1 to 0x0, to show its not valid.
Can I see if BITS has the valid bet set by simply doing:
Code:
int result = ptentry->bits & VALIDBIT; //should return 0x1 or 0x0 right?
if(result == VALIDBIT)
{
ptentry->bits = ptentry->bits ^ VALIDBIT //bit XOR operator so if it was 0x1 ^ 0x1 == 0x0 right?
}
basically if i have 0x1 I want to switch it to 0x0,
also it would be nice to know how to switch it back to 0x1, so i can make it valid again if I need to.
One other bit question, if I want to shift certian bits to the right (only the working set bits WSBITS), can I do the following:
Code:
/* if the page is valid, age the 3 working set bits (shift them right) */
if (( wsbits = ( ptentry->bits & WSBITS ))) {
wset++; /* a page is in working set */
/* age the wsbits */
/* BIT AGING HERE */
wsbits = wsbits >> 1;
//now add back into ptentry->bits
ptentry->bits = ptentry->bits | wsbits;
}
Thanks!