Page 2 of 2

Re:CR2 empty?

Posted: Fri Mar 25, 2005 3:49 am
by Poseidon
bochs says it's bogus memory... why don't i get an exception or something, or why doens't the kernel crash ???

Re:CR2 empty?

Posted: Fri Mar 25, 2005 4:01 am
by Pype.Clicker
AR wrote: On the x86, char and short are scaled up to int anyway
That sounds extremely scary to me. This is not an x86 thing. this is a compiler thing.

Char (same way as 'int') are _signed_ numbers. When you write

Code: Select all

char byte=0xff;
the compiler should warn you the constant will be too big for the storage type.

Natively, the computer can only compare words of the same width (e.g. chars and chars, shorts and shorts, ints and ints, longs and longs, etc). Whenever you attempt to compare/move values between variables of different width, the system will _cast_ the value to the target type (or to the largest type for the purpose of comparison -- Solar, hit me back if i'm wrong here, will you ?)

That means when you write

Code: Select all

int negative=-1;
if (byte == negative) 
what you actually tell the compiler to do is

Code: Select all

int negative=-1;
if ((int)byte == negative) ...
since the pattern "FF" is "-1" for a char, it will be converted to
an int of value "-1" before comparison occurs (e.g. "FFFFFFFF").

So the code will eventually be compiled as

Code: Select all

negative dd 0xffffffff
bite db 0xff
mov eax,[negative]
movsx ebx,byte [bite]
cmp eax, ebx
hope it makes it clearer.

Re:CR2 empty?

Posted: Fri Mar 25, 2005 4:19 am
by AR
You did query it after the kernel halted, not before? If you did then, yes the system should have page faulted.
Pype.Clicker wrote: That sounds extremely scary to me. This is not an x86 thing. this is a compiler thing.
I did clarify by saying "GCC 32bit aligns it to speed up access"

Re:CR2 empty?

Posted: Fri Mar 25, 2005 4:43 am
by Pype.Clicker
Poseidon wrote: it's always -1 ???. does anyone have a d*mn idea why this is happening, otherwise i'll post some code.
reading at inexistant physical memory usually returns "-1". under bochs, it also complains about "bogus memory". My guess is you *have* a page table entry for it (for some reason), but it's filled with garbage that sends the CPU to some memory that doesn't exist.

the best thing you could do is to cross-check the content of CR3, then of PDE and PTE accordingly to see if everything is *really* in place.

"x <addr>" inspect a virtual address and "xp <addr>" a physical address with bochs.

Re:CR2 empty?

Posted: Fri Mar 25, 2005 4:49 am
by Poseidon
it works! at last ;D ;D

the problem was that it used for the pagetable the latest physical address, what caused to be no memory there. thanks everyone ;D

Re:CR2 empty?

Posted: Fri Mar 25, 2005 9:32 am
by Solar
Pype.Clicker wrote: Char (same way as 'int') are _signed_ numbers.
Nope. char doesn't behave like int, in this regard. Whether 'char' is signed or unsigned is "implementation defined", which means you can set your compiler to do either. Assuming signed char is commonplace, but by no means mandatory.

(Said the language lawyer, and withdraws to his cave again, madly mumbling and scribbling away on standard things...)
Solar, hit me back if i'm wrong here, will you ?)
Just did so. You are right about the comparison thing though.

Note that the matter gets more tricky when variable parameter lists come into play. And:
since the pattern "FF" is "-1" for a char...
...is still an invalid assumption. ;)