Getting top 4 bytes of an unsigned long long

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Getting top 4 bytes of an unsigned long long

Post by pcmattman »

OK, I have a serious problem here :D. 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:

Code: Select all

#define HIINT( x ) ( x >> 32 )
Any ideas?
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Oops, sorry, forgot to say what I was trying to print :oops:

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)?
TomTom
Posts: 23
Joined: Tue May 01, 2007 2:03 am
Location: USA

Post 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))
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Re: Getting top 4 bytes of an unsigned long long

Post by os64dev »

pcmattman wrote:But I'm not sure about HIINT:

Code: Select all

#define HIINT( x ) ( x >> 32 )
Any ideas?
The next would do for HIINT, though the AND mask is optional.

#define HIINT( x ) (( x & 0xFFFF0000 ) >> 16)
Author of COBOS
Post Reply