Magellan Linux

Annotation of /trunk/mkinitrd-magellan/klibc/usr/klibc/socketcalls.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 532 - (hide annotations) (download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 9 months ago) by niro
File MIME type: text/plain
File size: 2105 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd

1 niro 532 #!/usr/bin/perl
2    
3     $v = $ENV{'KBUILD_VERBOSE'};
4     $quiet = defined($v) ? !$v : 0;
5    
6     @args = ();
7     for $arg ( @ARGV ) {
8     if ( $arg =~ /^-/ ) {
9     if ( $arg eq '-q' ) {
10     $quiet = 1;
11     } else {
12     die "$0: Unknown option: $arg\n";
13     }
14     } else {
15     push(@args, $arg);
16     }
17     }
18     ($file, $arch, $outputdir) = @args;
19    
20     if (!open(FILE, "< $file")) {
21     die "$file: $!\n";
22     }
23    
24     print "socketcall-objs := ";
25     while ( defined($line = <FILE>) ) {
26     chomp $line;
27     $line =~ s/\s*(|\#.*|\/\/.*)$//; # Strip comments and trailing blanks
28     next unless $line;
29    
30     if ( $line =~ /^\s*\<\?\>\s*(.*)\s+([_a-zA-Z][_a-zA-Z0-9]+)\s*\((.*)\)\s*\;$/ ) {
31     $type = $1;
32     $name = $2;
33     $argv = $3;
34    
35     @args = split(/\s*\,\s*/, $argv);
36     @cargs = ();
37    
38     $i = 0;
39     for $arg ( @args ) {
40     push(@cargs, "$arg a".$i++);
41     }
42     $nargs = $i;
43     print " \\\n\t${name}.o";
44    
45     if ( $arch eq 'i386' ) {
46     open(OUT, "> ${outputdir}/${name}.S")
47     or die "$0: Cannot open ${outputdir}/${name}.S\n";
48    
49     print OUT "#include <sys/socketcalls.h>\n";
50     print OUT "\n";
51     print OUT "\t.text\n";
52     print OUT "\t.align 4\n";
53     print OUT "\t.globl ${name}\n";
54     print OUT "\t.type ${name},\@function\n";
55     print OUT "${name}:\n";
56     print OUT "\tpushl \$SYS_\U${name}\n";
57     print OUT "\tjmp __socketcall_common\n";
58     print OUT "\t.size ${name},.-${name}\n";
59     close(OUT);
60     } else {
61     open(OUT, "> ${outputdir}/${name}.c")
62     or die "$0: Cannot open ${outputdir}/${name}.c\n";
63    
64     print OUT "#include \"socketcommon.h\"\n";
65     print OUT "\n";
66     print OUT "#ifndef __NR_${name}\n\n";
67    
68     print OUT "extern long __socketcall(int, const unsigned long *);\n\n";
69    
70     print OUT "$type $name (", join(', ', @cargs), ")\n";
71     print OUT "{\n";
72     print OUT " unsigned long args[$nargs];\n";
73     for ( $i = 0 ; $i < $nargs ; $i++ ) {
74     print OUT " args[$i] = (unsigned long)a$i;\n";
75     }
76     print OUT " return ($type) __socketcall(SYS_\U${name}\E, args);\n";
77     print OUT "}\n\n";
78    
79     print OUT "#endif\n";
80    
81     close(OUT);
82     }
83     } else {
84     die "$file:$.: Could not parse input\n";
85     }
86     }
87    
88     print "\n";