inline assambly error?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
amirsadig

inline assambly error?

Post by amirsadig »

I try to write my syscalls, therefore I make fisrt some test.
the below code will be called when the Interrupt 0x80 occure.
but when I complie it the ld bring me the error "undefined reference to `write' ". but its in another file which has been linked with this code!!.

what the error ?

void syscall(regs_t *regs)
{
__asm__ __volatile__(
   "mov %0, %%ebx;
mov %1, %%ecx;
pushl %%ecx ;
pushl %%ebx ;
call write ;"
   ::"r"(regs->ebx), "r"(regs->ecx)
);
}
Therx

Re:inline assambly error?

Post by Therx »

I'm not sure but maybe the 'write' should be '_write' if its in a C file
Tim

Re:inline assambly error?

Post by Tim »

Why does this need to be written in inline assembly at all? It's equivalent to this:

Code: Select all

write(regs->ebx, regs->ecx);
In fact, your code will crash because it doesn't adjust the stack after the call (you need add %%esp, $8).
amirsadig

Re:inline assambly error?

Post by amirsadig »

I have found the error:
the function write was static function in the others file. after I declare it as non static the program work.

Tim:
I know what you have written, but that code was only for test purpose and I will recode it so that it call the syscall from table. so I kept my syscall like linux sys_call, so that I can port GNU Libc easy and what you have seen is only the syscall service routine. the interrupt handdler does the return from syscall and it work when I passed the parameter to my rapper function, which call the interrupt (int 0x80) after passing the parameter to register ( eax, ebx ..)
Post Reply