Does anyone knows how to get a variable's segment and offset address using c... I need the information for a VESA driver that I am writing.
Does anyone knows how to get a variable's segment and offset address using c... I need the information for a VESA driver that I am writing.
Is this Linux kernel? If so, the segment is irrelevant, because all segments are based at physical address 0. I assume you have a variable and you want to obtain its physical address. If the variable has been allocated by kmalloc(), or is a static variable, you can use the __pa() macro.
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}
No this is a home brewed kernel....
Is this an allocated black of memory, something setting on the stack, a static global, or something else?No this is a home brewed kernel....
You aren't going to get any answers if you don't give more information.
O_oNow it's VESA graphics that died along with 320 x 200 ega resolutions and 8 bit processors.
Swing and a miss.
Soma
Well, then if you would like to write drivers of all the 100s upon 100s of video cards for me, by all means go for it....
Not sure, but what about....
Code:#include <stdio.h> /* * Assuming 32-bit (adjust as necessary for 64-bit) * $ gcc -m32 main.c * $ ./a.out * Address of aVariable: 0xbffff2ac * Segment of aVariable: bfff * Offset of aVariable: f2ac */ int main( void ) { unsigned aVariable = 1; printf( "Address of aVariable: %p\n", &aVariable ); printf( "Segment of aVariable: %x\n", ( ( unsigned )&aVariable & 0xFFFF0000 ) >> 16 ); printf( "Offset of aVariable: %x\n", ( unsigned )&aVariable & 0x0000FFFF ); return 0; }
Last edited by kmess; 04-20-2011 at 04:56 PM. Reason: Correct code formatting
This is 25 year old technology, hearalding back before the 386 chip. Way back then Chips only had 20 bits of address buss and memory was addressed in segments and offsets... the segment register set up a 64k block of memory and the 16 bit address register gave you an address inside the segment... These registers don't even exist any more and since the indtroduction of the 386 processor memory is addressed as a continuous block starting at 0.
Even the desire for this speaks to technological understanding 25 years behind the times.
Er, strike that. I doubt that will work. I'm guessing you might need to do some inline assembly...
Every video card has (at least) 3 default modes built in... 720x400 text mode, 640x480 ega graphics and 800 x 600 vga graphics. If you look at documentation *from this millenium* you will discover the configuration codes for setting these three modes and the memory addresses of the buffers... no segments, no offsets... just a 32 or 64 bit memory address.
And, oh boy are you gonna have a cow when you discover Plug and Play...
Last edited by CommonTater; 04-20-2011 at 05:08 PM.
Bah, don't listen to those guys.
Are you writing a real-mode or protected-mode operating system?
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}
One source is the Microsoft Driver SDK which is freely dowloadable.
Google is your friend.
What I'm mostly interested in is where you're getting this grossly outdated information from...
There was another guy on here today asking about TSR programming which hasn't existed since MS-DOS was abandoned.
What you're talking about is the functional equivalent of HIMEM.SYS, also part of MS-DOS and well and truly dead along with t.We are also beseiged at times by people using 16 bit compilers (usually Borland's TurboC) and wondering why their stuff isn't working correctly.
Taking this along with several other messages over the past while --one wanting help with 8080 processors-- I'm starting to think there's some school someplace with a teacher that is disastrously behind the times and still teaching with tools and currucula from at least 20 years ago. That anyone is still teaching this stuff is a very scary idea, leaves me wonding how many perfectly good programmers chances this teacher has ruined.
Look for PCI interface manuals, or whatever the bus specifications are, that your video adapter is connected. You probably will not have access to the stdio routines if you are working in kernel mode since until the kernel is initialized you may not have any input or output ports initialized.Well then where do I find this mythical documentation of yours?
Jim