Bitwise Operations in Physical Memory Manager
Posted: Thu Feb 10, 2011 11:55 am
Hi, So I have been reading the articles over the last couple of weeks along with the osdev.org wiki and several other osdev resources. My main interest is to expand my knowledge in how lower level systems work.
While I am familiar with bitwise operations, its been about a year since ive done any work with them and im trying to break apart the operations for the set/unset functions for the memory map.
For example: The "void mmap_set (int bit)":
So, lets take I want to set the 23rd bit. and lets also say that...
If I break this down with my understanding:
bit = 23
i = 0 (map array index (23 / 32) )
map[0] |= (1 << (bit % 32 ) )
map[0] |= (1 << (23) )
Now, This is where I get confused.
(1 << 23) = 0000 0000 1000 0000 0000 0000 0000 0000 0000
but if you OR that with map[0]
You are effectively setting the 10th bit not the 23rd bit?
Could someone explain where I am misunderstanding this please?
By my understanding it should be a right shift (1 >> 23) to get
That would give you a mask for the 23rd bit?
Thanks for your time in reading.
Andy
While I am familiar with bitwise operations, its been about a year since ive done any work with them and im trying to break apart the operations for the set/unset functions for the memory map.
For example: The "void mmap_set (int bit)":
Code: Select all
inline void mmap_set (int bit)
{
_mmngr_memory_map[bit / 32] |= (1 << (bit % 32));
}
Code: Select all
map[0] = 1111 1111 0011 1100 0000 0000 0000 0000 0000
bit = 23
i = 0 (map array index (23 / 32) )
map[0] |= (1 << (bit % 32 ) )
map[0] |= (1 << (23) )
Now, This is where I get confused.
(1 << 23) = 0000 0000 1000 0000 0000 0000 0000 0000 0000
but if you OR that with map[0]
Code: Select all
0000 0000 0100 0000 0000 0000 0000 0000
1111 1111 0011 1100 0000 0000 0000 0000
Could someone explain where I am misunderstanding this please?
By my understanding it should be a right shift (1 >> 23) to get
Code: Select all
(1 >> 23) = 0000 0000 0000 0000 0000 0010 0000 0000
Thanks for your time in reading.
Andy