CR2 empty?
Re:CR2 empty?
bochs says it's bogus memory... why don't i get an exception or something, or why doens't the kernel crash ???
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:CR2 empty?
That sounds extremely scary to me. This is not an x86 thing. this is a compiler thing.AR wrote: On the x86, char and short are scaled up to int anyway
Char (same way as 'int') are _signed_ numbers. When you write
Code: Select all
char byte=0xff;
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)
Code: Select all
int negative=-1;
if ((int)byte == negative) ...
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
Re:CR2 empty?
You did query it after the kernel halted, not before? If you did then, yes the system should have page faulted.
I did clarify by saying "GCC 32bit aligns it to speed up access"Pype.Clicker wrote: That sounds extremely scary to me. This is not an x86 thing. this is a compiler thing.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:CR2 empty?
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.Poseidon wrote: it's always -1 ???. does anyone have a d*mn idea why this is happening, otherwise i'll post some code.
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?
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
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?
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.Pype.Clicker wrote: Char (same way as 'int') are _signed_ numbers.
(Said the language lawyer, and withdraws to his cave again, madly mumbling and scribbling away on standard things...)
Just did so. You are right about the comparison thing though.Solar, hit me back if i'm wrong here, will you ?)
Note that the matter gets more tricky when variable parameter lists come into play. And:
...is still an invalid assumption.since the pattern "FF" is "-1" for a char...
Every good solution is obvious once you've found it.