Passing a C/C++ Pointer to a Different Segment Register (ES/
Passing a C/C++ Pointer to a Different Segment Register (ES/
..
Last edited by Perica on Sun Dec 03, 2006 8:48 pm, edited 2 times in total.
- Pype.Clicker
- Member

- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Passing a C/C++ Pointer to a Different Segment Register (
It can be accomplished through a "farptr" structure you have to declare that will look likePerica Senjak wrote: Hey,
What i want to do is Pass a C/C++ Pointer using a Different Segment Register other than "DS";
Can this be accomplished easily in C/C++??The problem is that the compiler will not let you do *farX = 1 in C, but in C++, overloading every operator for the far class, maybe you could handle it ...Code: Select all
struct farptr { void *offset; selector_t segment; }
I'm afraid i don't see what you mean, but i guess you wonder if you can access memory by its virtual address *and* with its physical address. In that case the answer is no.Also, when paging maps a Certain Area Of Memory - Is it Possible to Acess the Memory from Both Addresses: The Pages Address and the Normal One (If you know what i mean)??
The reason is every memory reference will go through the paging chip once paging is enabled (bit 31 in cR0 set) --> if you want to access physical frame #x with paging enabled, you have to
- find out a free page and map it to #x,
- flush the TLB cache for #x,
- do your access,
- unmap the page,
- flush the TLB for #x again.
This is what Clicker's Page Frame Viewer (code here) is about ...
Cya.
Re:Passing a C/C++ Pointer to a Different Segment Register (
..
Last edited by Perica on Sun Dec 03, 2006 8:48 pm, edited 1 time in total.
- Pype.Clicker
- Member

- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Passing a C/C++ Pointer to a Different Segment Register (
eeek! i would not do it that way, if i were you ... because it will mean that every byte access will require a function call that the processor will never be able to optimize.I'll write a Linked Assembler Function that Simply writes a Specified Byte/Word/dWord/qWord of Data to a Specified Register, and a Specified Selector:Offset - Something like this: bool WriteFS_dWord(unsigned int Selector, unsigned int Offset, unsigned short Data);
i'd rather declare WriteFs_dword(...) as a __inline__ function holding one inlined-assembly command. That way, the processor can optimize the generation of the offset and the register that will receive the result ...
Also i would opt for setFS(selector) getFS() that will alter a specific segment descriptor and assume the selector is set in writeFS_dword(offset,value) -- so that you don't have to do some mov <segment>,<selector> everytime (which would slow down your code because of re-loading of the GDT/LDT content at every memory access ...)
Re:Passing a C/C++ Pointer to a Different Segment Register (
..
Last edited by Perica on Sun Dec 03, 2006 8:49 pm, edited 1 time in total.
- Pype.Clicker
- Member

- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Passing a C/C++ Pointer to a Different Segment Register (
from info gcc :
The main reason i use them is simply to remind me of their presence and of the evil fact they'll be inlined only when optimizations are turned on ...
The alternate keywords `__asm__', `__extension__', `__inline__'
and `__typeof__' continue to work despite `-ansi'. You would not
want to use them in an ANSI C program, of course, but it is useful
to put them in header files that might be included in compilations
done with `-ansi'. Alternate predefined macros such as `__unix__'
and `__vax__' are also available, with or without `-ansi'.
