Page 1 of 1
Getting top 4 bytes of an unsigned long long
Posted: Mon Apr 30, 2007 6:41 pm
by pcmattman
OK, I have a serious problem here
. My printf() function won't print more than 4 bytes of an integer. The way I see it, I can either re-write it, fix it, or figure out how to get those four bytes.
I need something like a HIINT() and LOINT() macro, I know this would work for LOINT:
Code: Select all
#define LOINT( x ) ( x & 0x0000FFFF )
But I'm not sure about HIINT:
Any ideas?
Posted: Mon Apr 30, 2007 6:50 pm
by pcmattman
Oops, sorry, forgot to say what I was trying to print
I'm trying to print an unsigned long long (ie. 64 bits) as it's an entry in my GDT and I'm trying to figure out how to add my own entries (because I followed the kernel development tutorial at osdever.net).
Another question, for v8086 mode do I need to run it in DPL3, or can it run in DPL0 (ie. same as kernel)?
Posted: Tue May 01, 2007 2:07 am
by TomTom
Try this to get the lowest 2 bytes:
Code: Select all
#define LOWORD(val) (unsigned short int)((val) & 0xFFFF)
And this to get the highest 2 bytes independently (should theoretically work for both 32 and 64 bit types):
Code: Select all
#define HIWORD(val) (unsigned short int)((val) >> ((sizeof(val) - 2) * 8))
Re: Getting top 4 bytes of an unsigned long long
Posted: Tue May 01, 2007 2:54 am
by os64dev
pcmattman wrote:But I'm not sure about HIINT:
Any ideas?
The next would do for HIINT, though the AND mask is optional.
#define HIINT( x ) (( x & 0xFFFF0000 ) >> 16)