Page 1 of 1

Canonical address?

Posted: Tue Jun 24, 2008 9:27 pm
by sngskunk
I am a little confused on canonical addresses? Can someone please explain, i am having trouble with my interrupts in long mode and I think that might be why.

Re: Canonical address?

Posted: Tue Jun 24, 2008 11:07 pm
by Brendan
Hi,
sngskunk wrote:I am a little confused on canonical addresses? Can someone please explain, i am having trouble with my interrupts in long mode and I think that might be why.
For long mode linear addresses are 48-bits wide and not 64-bits wide. In theory this means the highest 16-bits of a 64-bit address would be ignored, and that 65536 possible 64-bit values would refer to the same 48-bit address.

So that CPU manufacturers can introduce support for larger linear address sizes later on (e.g. true 64-bit linear addresses) they don't let you use most of the 65536 possible 64-bit values that refer to the same 48-bit address. Instead they only let you use one of these 64-bit values to refer to the 48-bit address. This is the 64-bit canonical address.

To figure out what the canonical 64-bit address is from a "non-canonical" 64-bit address, you'd mask it with 0x0000FFFFFFFF and then duplicate the 47th bit into all higher bits, as if the 48-bit address is sign extended. For example the address 0xABCDEF0123456789 would be masked to become 0x0000EF0123456789 and then "sign extended" to become the canonical address 0xFFFFEF0123456789.

IMHO this is all just a silly and confusing way to look at it. It's better to forget about all of this and imagine a 64-bit linear address space where the middle doesn't exist - you'd have a usable area (of canonical addresses) from 0x0000000000000000 to 0x00007FFFFFFFFFFF, an unusable area (of non-canonical addresses) from 0x0000800000000000 to 0xFFFF7FFFFFFFFFFF, and another usable area (of canonical addresses) from 0xFFFF800000000000 to 0xFFFFFFFFFFFFFFFF.


Cheers,

Brendan