Messages in this thread Patch in this message | | | Date | Sat, 15 Jan 2000 11:48:10 -0500 (EST) | From | Chris Noe <> | Subject | Re: _syscall2 in PIC code on ix86 |
| |
On 14 Jan 2000, H. Peter Anvin wrote:
> We probably should add a set of macros that include PIC support > (_syscallX_pic)... it seems to me the obvious way to deal with this > seems to push/pop %ebx around the syscall. > > -hpa
That sounded easy enough to accomplish that I went ahead and did it; however, even after digging through the inline-asm info pages and such I still can't discover what the "last step" to fix it is. I still get compiler errors using the syscallX_pic versions.
// pic_sys.c #include "unistd.h" #include <errno.h> #include <sys/types.h> #include <sys/wait.h>
_syscall0_pic(pid_t, getpid) _syscall1_pic(pid_t, getsid, pid_t, pid) _syscall3_pic(pid_t, waitpid, pid_t, pid, int *, status, int, options) #if 0 _syscall2_pic() _syscall4_pic() _syscall5_pic() _syscall6_pic() #endif
int main (int argc, char ** argv) { int status; pid_t pid;
pid = getpid();
printf("0: %d\n", (int)pid); printf("1: %d\n", (int)getsid(pid)); printf("3: %d\n", (int)waitpid(pid, &status, WNOHANG)); } // end pic_sys.c
gcc pic_sys.c -fPIC -o pic_sys syscall.c: In function `getsid': syscall.c:7: fixed or forbidden register 3 (bx) was spilled for class BREG. This may be due to a compiler bug or to impossible asm statements or clauses.
I tried listing it in the clobbers, to no avail. I'm a bit more familiar with just gas, without all this C crap on top of it :) :)
btw, does it matter that I've split the "pushl %ebx / int 0x80" over two separate asm lines? I wouldn't think so because of the volatile, but I'm not 100% sure. The reason I did it was so that the pushl/popl would be consistent with one percent sign; if it were inside the asm with "int $0x80" then it'd need two percents.
Thanks! (diff attached, your thoughts?)
Chris Noe (stiker@northlink.com)
--- /usr/src/linux-2.3.39/include/asm/unistd.h Wed Jan 12 18:21:12 2000 +++ linux/include/asm/unistd.h Sat Jan 15 11:29:32 2000 @@ -311,6 +311,90 @@ __syscall_return(type,__res); \ } +/* PIC versions of the above (push/pop %ebx) */ + +/* no need to save %ebx for syscall0, as it isn't used */ +#define _syscall0_pic(type,name) _syscall0(type,name) + +#define _syscall1_pic(type,name,type1,arg1) \ +type name(type1 arg1) \ +{ \ +long __res; \ +__asm__ volatile ("pushl %ebx"); \ +__asm__ volatile ("int $0x80" \ + : "=a" (__res) \ + : "0" (__NR_##name),"b" ((long)(arg1))); \ +__asm__ volatile ("popl %ebx"); \ +__syscall_return(type,__res); \ +} + +#define _syscall2_pic(type,name,type1,arg1,type2,arg2) \ +type name(type1 arg1,type2 arg2) \ +{ \ +long __res; \ +__asm__ volatile ("pushl %ebx"); \ +__asm__ volatile ("int $0x80" \ + : "=a" (__res) \ + : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2))); \ +__asm__ volatile ("popl %ebx"); \ +__syscall_return(type,__res); \ +} + +#define _syscall3_pic(type,name,type1,arg1,type2,arg2,type3,arg3) \ +type name(type1 arg1,type2 arg2,type3 arg3) \ +{ \ +long __res; \ +__asm__ volatile ("pushl %ebx"); \ +__asm__ volatile ("int $0x80" \ + : "=a" (__res) \ + : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \ + "d" ((long)(arg3))); \ +__asm__ volatile ("popl %ebx"); \ +__syscall_return(type,__res); \ +} + +#define _syscall4_pic(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ +type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ +{ \ +long __res; \ +__asm__ volatile ("pushl %ebx"); \ +__asm__ volatile ("int $0x80" \ + : "=a" (__res) \ + : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \ + "d" ((long)(arg3)),"S" ((long)(arg4))); \ +__asm__ volatile ("popl %ebx"); \ +__syscall_return(type,__res); \ +} + +#define _syscall5_pic(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ + type5,arg5) \ +type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ +{ \ +long __res; \ +__asm__ volatile ("pushl %ebx"); \ +__asm__ volatile ("int $0x80" \ + : "=a" (__res) \ + : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \ + "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5))); \ +__asm__ volatile ("popl %ebx"); \ +__syscall_return(type,__res); \ +} + +#define _syscall6_pic(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ + type5,arg5,type6,arg6) \ +type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5,type6 arg6) \ +{ \ +long __res; \ +__asm__ volatile ("pushl %ebx"); \ +__asm__ volatile ("push %%ebp ; movl %%eax,%%ebp ; movl %1,%%eax ; int $0x80 ; pop %%ebp" \ + : "=a" (__res) \ + : "i" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \ + "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5)), \ + "0" ((long)(arg6))); \ +__asm__ volatile ("popl %ebx"); \ +__syscall_return(type,__res); \ +} + #ifdef __KERNEL_SYSCALLS__ /*
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |