in & outportb in c++ and intel asm
in & outportb in c++ and intel asm
hi
could anyone point me to a tutorial or tell me how to create the inportb() and outportb() methods using microsoft visual c++ 2005 and/or intel syntax
could anyone point me to a tutorial or tell me how to create the inportb() and outportb() methods using microsoft visual c++ 2005 and/or intel syntax
.................................. um what should i put here .............................?..........................................
..... ................
..... ................
hehe... I actually just written one for my new kernel, along with a few other usefull instructions... Im not at my computer right now, so I cannot post it.
Either way, this is surprisingly simple. Do you have experience with inline assemby? All you need to do is store the parameters in the correct registers, and read/write from the port...
Either way, this is surprisingly simple. Do you have experience with inline assemby? All you need to do is store the parameters in the correct registers, and read/write from the port...
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Here you go (from my OS):
Code: Select all
inline unsigned char _cdecl inportb (unsigned short portid) {
unsigned char res=0;
_asm {
mov dx, portid
in ax, dx
mov [res], al
}
return res;
}
inline void _cdecl outportb (unsigned short portid, unsigned char value) {
_asm {
mov al, [value]
mov dx, [portid]
out dx, al
}
}
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
- kataklinger
- Member
- Posts: 381
- Joined: Fri Nov 04, 2005 12:00 am
- Location: Serbia
And other useful information about using inline assembly in VC++:
Code: Select all
http://msdn2.microsoft.com/en-us/library/4ks26t93(VS.71).aspx
I just wanted to add that MSVC++ inline assembler supports every opcode (including lgdt, lidt, et al.). As long as the code being executed is less then or equal to the Current Protection Level (CPL), the code will execute just fine.
Windows applications run at a greater protection level (ring 3) then the required ring 0 protection level, hence it will not work under windows, but it will work just fine under a ring 0 kernel.
Windows applications run at a greater protection level (ring 3) then the required ring 0 protection level, hence it will not work under windows, but it will work just fine under a ring 0 kernel.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
hmmm you destroyed an old deed i thought that there is two kinds of compilers ...some that can't make a separate programs because they add their optimizations and so on and others like gcc that can make it !
i am reading thw wiki right now !
http://www.osdev.org/wiki/Visual_Studio
i am reading thw wiki right now !
http://www.osdev.org/wiki/Visual_Studio
I'm not sure what you mean by different types of compiliers... All C++ compiliers produce object code for a specific platform or architecture.
Several members on this board in fact (Including me) is using MSVC++ for their compilier
Several members on this board in fact (Including me) is using MSVC++ for their compilier
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}