| 1 |
# Copyright (C) 1995-1997 Robert de Bath <[email protected]> |
| 2 |
# This file is part of the Linux-8086 C library and is distributed |
| 3 |
# under the GNU Library General Public License. |
| 4 |
# |
| 5 |
# This script generates the 'simple' system calls for the 386 |
| 6 |
# |
| 7 |
# Each call is put into it's own object file, if the semantics of the |
| 8 |
# call are not correct UNIX then the 4th field in the dat file has a |
| 9 |
# marker and the function is generated with a __ prefix. |
| 10 |
# |
| 11 |
# |
| 12 |
# Different levels of squeeze |
| 13 |
# 0 = each is complete |
| 14 |
# 1 = Short codes calling common function |
| 15 |
|
| 16 |
rm -f syscall.c syscall.mak |
| 17 |
|
| 18 |
tr '[A-Z]' '[a-z]' < syscall.dat | \ |
| 19 |
awk 'BEGIN{ |
| 20 |
print "# Copyright (C) 1995-1997 Robert de Bath <[email protected]>" > "syscall.mak"; |
| 21 |
print "# This file is part of the Linux-8086 C library and is distributed" > "syscall.mak"; |
| 22 |
print "# under the GNU Library General Public License." > "syscall.mak"; |
| 23 |
print "# " > "syscall.mak"; |
| 24 |
print "# This file is automatically generated\n" > "syscall.mak" |
| 25 |
|
| 26 |
print "# Copyright (C) 1995-1997 Robert de Bath <[email protected]>"; |
| 27 |
print "# This file is part of the Linux-8086 C library and is distributed"; |
| 28 |
print "# under the GNU Library General Public License."; |
| 29 |
print "# "; |
| 30 |
print "# This file is automatically generated */\n" |
| 31 |
obj="OBJ="; |
| 32 |
|
| 33 |
print "# Standard start\n\n" |
| 34 |
printf("#ifndef __MSDOS__\n"); |
| 35 |
printf("#ifdef __AS386_32__\n"); |
| 36 |
printf(" .text\n"); |
| 37 |
printf(" .align 16\n"); |
| 38 |
|
| 39 |
COMPACT=0; |
| 40 |
} |
| 41 |
/^[ ]*#/ { next; } |
| 42 |
/^[ ]*$/ { next; } |
| 43 |
{ |
| 44 |
if( $2 > max_call ) max_call = $2; |
| 45 |
|
| 46 |
if( $3 == "x" || $3 == "" ) next; |
| 47 |
else if( $4 == "-" ) next; |
| 48 |
else if( $4 == "*" ) funcname="__" $1; |
| 49 |
else funcname=$1; |
| 50 |
|
| 51 |
if( length(obj) > 60 ) |
| 52 |
{ |
| 53 |
printf("%s\t\\\n", obj) > "syscall.mak"; |
| 54 |
obj=" "; |
| 55 |
} |
| 56 |
obj=obj funcname ".o "; |
| 57 |
|
| 58 |
printf "# CALL %s\n\n", $0; |
| 59 |
|
| 60 |
printf(".ifdef L_%s\n", funcname); |
| 61 |
printf(".globl %s\n", funcname); |
| 62 |
printf(".type %s,@function\n", funcname); |
| 63 |
printf("%s:\n", funcname); |
| 64 |
|
| 65 |
# Inline assembler max to 5 args (20 bytes) |
| 66 |
if( $3 != 4 && $3 != 5 && ( COMPACT || $3 > 5 )) |
| 67 |
{ |
| 68 |
printf(" mov %%eax,#%d\n", $2); |
| 69 |
printf(" br sys_call%d\n", $3); |
| 70 |
} |
| 71 |
else |
| 72 |
{ |
| 73 |
printf(" pushl %%ebp\n"); |
| 74 |
printf(" movl %%esp,%%ebp\n"); |
| 75 |
printf(" pushl %%ebx\n"); |
| 76 |
if( $3 >= 1 ) printf(" mov 8(%%ebp),%%ebx\n"); |
| 77 |
if( $3 >= 2 ) printf(" mov 12(%%ebp),%%ecx\n"); |
| 78 |
if( $3 >= 3 ) printf(" mov 16(%%ebp),%%edx\n"); |
| 79 |
if( $3 >= 4 ) printf(" push %%esi\n"); |
| 80 |
if( $3 >= 4 ) printf(" mov 20(%%ebp),%%esi\n"); |
| 81 |
if( $3 >= 5 ) printf(" push %%edi\n"); |
| 82 |
if( $3 >= 5 ) printf(" mov 24(%%ebp),%%edi\n"); |
| 83 |
printf(" mov $%d,%%eax\n", $2); |
| 84 |
printf(" int $0x80\n"); |
| 85 |
|
| 86 |
if( $3 >= 5 ) printf(" pop %%edi\n"); |
| 87 |
if( $3 >= 4 ) printf(" pop %%esi\n"); |
| 88 |
printf(" pop %%ebx\n"); |
| 89 |
|
| 90 |
printf(" test %%eax,%%eax\n"); |
| 91 |
printf(" jge syscall_ok\n"); |
| 92 |
printf(" neg %%eax\n"); |
| 93 |
printf(" mov %%eax,errno\n"); |
| 94 |
printf(" mov $-1,%%eax\n"); |
| 95 |
printf("syscall_ok:\n"); |
| 96 |
printf(" movl %%ebp,%%esp\n"); |
| 97 |
printf(" popl %%ebp\n"); |
| 98 |
printf(" ret\n"); |
| 99 |
} |
| 100 |
printf(".endif\n\n"); |
| 101 |
} |
| 102 |
END{ |
| 103 |
|
| 104 |
printf("#endif /* __AS386_32__ */\n\n"); |
| 105 |
printf("#endif /* __MSDOS__ */\n\n"); |
| 106 |
printf("%s\n", obj) > "syscall.mak"; |
| 107 |
printf "\n" > "syscall.mak"; |
| 108 |
|
| 109 |
}' > syscall.s |
| 110 |
|
| 111 |
cat >> syscall.mak <<\! |
| 112 |
|
| 113 |
CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS) |
| 114 |
|
| 115 |
all: $(LIBC)($(OBJ)) |
| 116 |
@$(RM) $(OBJ) |
| 117 |
|
| 118 |
$(LIBC)($(OBJ)): syscall.dat mksyscall |
| 119 |
$(AS) --defsym L_$*=0 syscall.s -o $*.o |
| 120 |
$(AR) $(ARFLAGS) $@ $*.o |
| 121 |
! |
| 122 |
|
| 123 |
exit $? |