| It is currently Sun May 19, 2013 11:00 am |
|
All times are UTC |
|
Page 1 of 1 |
[ 5 posts ] |
| Print view | Previous topic | Next topic |
| Author | Message |
|---|---|
|
Joined: Wed Jul 22, 2009 6:44 am Posts: 63 |
I have implemented the following code with a ASM file inside my project...
but I would like to use your way... it is more easy to keep track... The Case: I'm building my own OS with C++, based in "classes"/not linear C... however, when I need to some low-level instructions, I have included "in project" assembly files... for example: Code: class definition _GDT { protected struct record for IDTR member functions Install(); } Code: _GDT::Install() { call my low-level asm code to perform the lidt... } How do I use this beauty code? Code: _asm lidt [_idtr] The problem is that _idtr, in my case, is inside class capsule... Code: _asm lidt [this->_idtr] does not work Is there any way to take the physical address of that structure that reside inside the class? _________________ _____________ Think it, build it, bit by bit... |
| Tue Oct 26, 2010 6:11 pm |
|
|
Moderator
Joined: Tue Oct 23, 2007 10:05 am Posts: 387 Location: 127.0.0.1 |
Which build environment are you using? MSVC based or GCC based?
There is no standard way to do this, but there are ways to get it working in both. ~Andrew _________________
|
| Wed Oct 27, 2010 6:03 pm |
|
|
Joined: Wed Jul 22, 2009 6:44 am Posts: 63 |
Visual C++ under Visual Studio
I solved the problem using this: Code: _asm push eax _asm mov eax, dword ptr [this] ;the pa of the class _asm lgdt [eax] ;because the struct is the first declaration inside the class _asm pop eax if the struct is not the first declaration we will need to add eax the correct displacement Code: _asm push eax _asm mov eax, dword ptr [this] ;the pa of the class _asm add eax, ???? ;where is the location of the struct inside the class _asm lgdt [eax] _asm pop eax Its working.... But is there any other way? _________________ _____________ Think it, build it, bit by bit... |
| Wed Oct 27, 2010 11:26 pm |
|
|
Moderator
Joined: Tue Oct 23, 2007 10:05 am Posts: 387 Location: 127.0.0.1 |
Unfortunatly that is not safe. It assumes that no extra fields are inserted at the top of the structure, which is not the case if you are doing debugging, or if you are using virtual base classes.
Anyway, the proper way to reference fields in data structure is as so: Code: _asm { lea eax,<object_name> ; Load Effective Address mov ecx, [eax]<object_name>.<field_name> } This will move the field value into ecx. For reference, see http://msdn.microsoft.com/en-us/library/fabdxz08.aspx Anyway, for your specific problem, you have to ensure that your GDT is a packed structure. then your code can be as simple as: Code: lea eax,<GDT object name> lgdt [eax] It is safe to assume that eax is fine - all other registers are not safe to assume anything about. (Typically, ecx is the 'this' pointer) ~Andrew _________________
|
| Wed Oct 27, 2010 11:53 pm |
|
|
Joined: Wed Jul 22, 2009 6:44 am Posts: 63 |
Thanks...
Code: __asm { mov eax, [this]_IDT._idtr lidt [eax] } Thanks anyway... _________________ _____________ Think it, build it, bit by bit... |
| Thu Oct 28, 2010 2:25 am |
|
|
Page 1 of 1 |
[ 5 posts ] |
Who is online |
Users browsing this forum: No registered users and 1 guest |
| You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum |