という問題が解けません。下記は、glibc を介さずようにwrite関数を使うためにカーネルシステムを直接叩いてみたものです。ほぼ本から持ってきたのであんま理解していません。
%powerpc-linux-gnu-gcc -m32 -Os -fno-builtin -fomit-frame-pointer -fno-ident -c hello_4.c
でビルドしたところ、
hello_4.c: In function 'write':
hello_4.c:28:erroe: impossible constract in 'asm'
とエラーが出ました。エラーを出なくする方法もしくは、全く違う方法で、glibc を介さずに標準出力に出力する方法を教えて頂けたらと思います。
#include <asm/unistd.h>
#define __syscall_return(type, res) (type)(res)
#define _syscall1(type,name,type1,arg1) ¥ type name(type1 arg1) ¥
{ ¥
long __res; ¥
__asm__ volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" ¥
: "=a" (__res) ¥
: "0" (__NR_##name),"ri" ((long)(arg1)) : "memory"); ¥ __syscall_return(type,__res);¥
}
#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) ¥ type name(type1 arg1,type2 arg2,type3 arg3) ¥
{ ¥
long __res; ¥
__asm__ volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" ¥
: "=a" (__res) ¥
: "0" (__NR_##name),"ri" ((long)(arg1)),"c" ((long)(arg2)), ¥
"d" ((long)(arg3)) : "memory"); ¥ __syscall_return(type,__res); ¥
}
inline _syscall1(int, exit, int, status);
inline _syscall3(int, write, int, fd, const void*, buf, unsigned long, count);
void hello()
{
write(1, "Hello World¥n", 12);
exit(0);
}