Page 1 of 2
in & outportb in c++ and intel asm
Posted: Sun Sep 23, 2007 3:29 am
by HJED
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
Posted: Sun Sep 23, 2007 4:42 am
by pcmattman
Perhaps using the inb and outb instructions?
Posted: Sun Sep 23, 2007 4:49 am
by neon
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...
Posted: Sun Sep 23, 2007 6:06 am
by neon
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
}
}
Posted: Sun Sep 23, 2007 2:29 pm
by HJED
thank you for the help
Posted: Sun Sep 23, 2007 4:29 pm
by kataklinger
And other useful information about using inline assembly in VC++:
Code: Select all
http://msdn2.microsoft.com/en-us/library/4ks26t93(VS.71).aspx
Posted: Sun Sep 23, 2007 7:04 pm
by mohammed
do you think that such a code will work probably in vc++ ?? i think under windows you can't do that because of the protection levels ...right?
Posted: Sun Sep 23, 2007 7:09 pm
by pcmattman
mohammed wrote:do you think that such a code will work probably in vc++ ?? i think under windows you can't do that because of the protection levels ...right?
Under windows you can't... But this is under his OS, unless I am greatly mistaken.
Posted: Sun Sep 23, 2007 9:31 pm
by neon
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.
Posted: Sun Sep 23, 2007 9:41 pm
by mohammed
they can develop their oses with vc++ ?? how come ? i think this compiler can't produce an independent software you know what ? even when i was working in console applications my programs never worked under pure dos it can work only under windows although it is in text mode !!
Posted: Sun Sep 23, 2007 9:48 pm
by pcmattman
You compiled with the CLR (common language runtime).
Look at the command line options and you can create "native" software.
In fact, there is information on how to make an OS with VC++ as your compiler in the wiki.
Posted: Sun Sep 23, 2007 9:52 pm
by mohammed
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
Posted: Sun Sep 23, 2007 10:26 pm
by neon
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
Posted: Sun Sep 23, 2007 10:38 pm
by mohammed
i thought that every body here is using gcc !! another deed changed : ) )
Posted: Mon Sep 24, 2007 12:09 am
by OrOS
Several members on this board in fact
Me now as well, since I like the IDE and its got great support once I add the runtime functions.