[Novalug] Linux, asm, hardware, protected mode
Ed James
edjames at greenbelt.com
Mon Feb 18 17:37:16 EST 2008
A Tip Of The Hat goes to Paul Bohme for his advice on using ioperm()
to grant my program permission to read/write to hardware ports. I
now can do in 57 lines of code what everyone else does in 1 line.
Next problem worthy of a TOTH...
There is a lot of info on doing asm coding, and tons of stuff on doing
C coding. But I'm stuck at the interface between C and asm.
As an example, consider a main() C/C++ program calling a function
called AddIt, as in:
int a = 1, b = 2;
int c = AddIt(a,b);
where AddIt looks like:
int AddIt (int x, int y) {
int z;
asm(".intel_syntax noprefix");
asm("mov al, x???"); // Move the value of variable x into register a
asm("add al, y???"); // Add the value of variable y to register a
asm("mov z???, al"); // Move the contents of register a to variable z
asm(".att_syntax noprefix");
return z;
}
I really can't find docs, faqs, tutorials, kernel code, etc that show how
to pass parms into inline assembly code, and pull it back out, as in the
above snippit, hence the ".???"'s. So, the questions are:
1 - Is passing parms like this doable? I can "cheat" by using global
variables, but I'm trying to avoid this.
2 - Is there a site I can go to that has info on this type of code? I've
really done a bunch of searching, but just ain't found it (yet?). I do
find lots and lots of examples that just...don't...work.
Ed James
More information about the Novalug
mailing list