Page 1 of 1

Pointer and binary issues

Posted: Fri Apr 11, 2008 12:47 pm
by pacman
Hi

Im getting really annoying messages from DJGPP (gcc) concerning the following code:

Code: Select all

unsigned int *pageTable;
pageTable = virtualBlock.startingEntry.pageDirectory[i];
pageTable = pageTable & 0xFFFFF000;
GCC keeps throwing:

Code: Select all

error: invalid operands to binary &
Also, for this code...

Code: Select all

     void *returnAddress = (void *) virtualBlock.startingEntry.pageDirectoryEntry * 1024 * 4096;
I get...

Code: Select all

error: invalid operands to binary *
What am I doing wrong?

Posted: Fri Apr 11, 2008 1:42 pm
by AJ
Hi,

You are attempting normal maths with pointers - try casting the pointers to integers before attempting the binary operations (you will, of course need to cast back to a pointer for the assignment back to the pointer variable).

Cheers,
Adam

Posted: Fri Apr 11, 2008 5:43 pm
by zerosum
I might point out that your paging structures need to be page-aligned anyway. If they were, doing a bitwise AND with 0xFFFFF000 would have no effect at all, since the least significant 12 bits would already be zero. If they're not [page-aligned], then you're going to have problems when you try to load them into cr3.

Cheers,
Lee

Posted: Sat Apr 12, 2008 5:35 am
by Korona
I guess they are page aligned and the op wants to get rid of the flags by doing a binary and operation.