OSDev.org

The Place to Start for Operating System Developers
It is currently Wed May 15, 2024 4:28 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 21 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re:CR2 empty?
PostPosted: Fri Mar 25, 2005 3:49 am 
bochs says it's bogus memory... why don't i get an exception or something, or why doens't the kernel crash ???


Top
  
 
 Post subject: Re:CR2 empty?
PostPosted: Fri Mar 25, 2005 4:01 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 2:31 am
Posts: 5964
Location: In a galaxy, far, far away
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:
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:
int negative=-1;
if (byte == negative)

what you actually tell the compiler to do is
Code:
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:
negative dd 0xffffffff
bite db 0xff
mov eax,[negative]
movsx ebx,byte [bite]
cmp eax, ebx


hope it makes it clearer.

_________________
Image May the source be with you.


Top
 Profile  
 
 Post subject: Re:CR2 empty?
PostPosted: Fri Mar 25, 2005 4:19 am 
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"


Top
  
 
 Post subject: Re:CR2 empty?
PostPosted: Fri Mar 25, 2005 4:43 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 2:31 am
Posts: 5964
Location: In a galaxy, far, far away
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.

_________________
Image May the source be with you.


Top
 Profile  
 
 Post subject: Re:CR2 empty?
PostPosted: Fri Mar 25, 2005 4:49 am 
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


Top
  
 
 Post subject: Re:CR2 empty?
PostPosted: Fri Mar 25, 2005 9:32 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7615
Location: Germany
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...)

Quote:
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:

Quote:
since the pattern "FF" is "-1" for a char...


...is still an invalid assumption. ;)

_________________
Every good solution is obvious once you've found it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page Previous  1, 2

All times are UTC - 6 hours


Who is online

Users browsing this forum: MichaelPetch and 72 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group