Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1)

Delta Between Two Patch Sets: src/pkg/syscall/mksyscall.pl

Issue 3816043: code review 3816043: syscall: Plan 9 support for x86. (Closed)
Left Patch Set: code review 3816043: syscall, os: Plan 9 support for x86. Created 14 years, 1 month ago
Right Patch Set: diff -r a15522fba283 https://go.googlecode.com/hg/ Created 13 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/syscall/mkall.sh ('k') | src/pkg/syscall/mksysnum_plan9.sh » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 #!/usr/bin/perl 1 #!/usr/bin/perl
2 # Copyright 2009 The Go Authors. All rights reserved. 2 # Copyright 2009 The Go Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style 3 # Use of this source code is governed by a BSD-style
4 # license that can be found in the LICENSE file. 4 # license that can be found in the LICENSE file.
5 5
6 # This program reads a file containing function prototypes 6 # This program reads a file containing function prototypes
7 # (like syscall_darwin.go) and generates system call bodies. 7 # (like syscall_darwin.go) and generates system call bodies.
8 # The prototypes are marked by lines beginning with "//sys" 8 # The prototypes are marked by lines beginning with "//sys"
9 # and read like func declarations if //sys is replaced by func, but: 9 # and read like func declarations if //sys is replaced by func, but:
10 # * The parameter lists must give a name for each argument. 10 # * The parameter lists must give a name for each argument.
11 # This includes return parameters. 11 # This includes return parameters.
12 # * The parameter lists must give a type for each argument: 12 # * The parameter lists must give a type for each argument:
13 # the (x, y, z int) shorthand is not allowed. 13 # the (x, y, z int) shorthand is not allowed.
14 # * If the return parameter is an error number, it must be named errno. 14 # * If the return parameter is an error number, it must be named errno.
15 15
16 # A line beginning with //sysnb is like //sys, except that the 16 # A line beginning with //sysnb is like //sys, except that the
17 # goroutine will not be suspended during the execution of the system 17 # goroutine will not be suspended during the execution of the system
18 # call. This must only be used for system calls which can never 18 # call. This must only be used for system calls which can never
19 # block, as otherwise the system call could cause all goroutines to 19 # block, as otherwise the system call could cause all goroutines to
20 # hang. 20 # hang.
21 21
22 $cmdline = "mksyscall.pl " . join(' ', @ARGV); 22 $cmdline = "mksyscall.pl " . join(' ', @ARGV);
23 $errors = 0; 23 $errors = 0;
24 $_32bit = ""; 24 $_32bit = "";
25 $nacl = 0; 25 $nacl = 0;
26 $plan9 = 0;
26 27
27 if($ARGV[0] eq "-b32") { 28 if($ARGV[0] eq "-b32") {
28 $_32bit = "big-endian"; 29 $_32bit = "big-endian";
29 shift; 30 shift;
30 } elsif($ARGV[0] eq "-l32") { 31 } elsif($ARGV[0] eq "-l32") {
31 $_32bit = "little-endian"; 32 $_32bit = "little-endian";
32 shift; 33 shift;
33 } 34 }
34 if($ARGV[0] eq "-nacl") { 35 if($ARGV[0] eq "-nacl") {
35 $nacl = 1; 36 $nacl = 1;
37 shift;
38 }
39 if($ARGV[0] eq "-plan9") {
40 $plan9 = 1;
36 shift; 41 shift;
37 } 42 }
38 43
39 if($ARGV[0] =~ /^-/) { 44 if($ARGV[0] =~ /^-/) {
40 print STDERR "usage: mksyscall.pl [-b32 | -l32] [file ...]\n"; 45 print STDERR "usage: mksyscall.pl [-b32 | -l32] [file ...]\n";
41 exit 1; 46 exit 1;
42 } 47 }
43 48
44 sub parseparamlist($) { 49 sub parseparamlist($) {
45 my ($list) = @_; 50 my ($list) = @_;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 my $args = join(', ', @args); 158 my $args = join(', ', @args);
154 my $call = "$asm($sysname, $args)"; 159 my $call = "$asm($sysname, $args)";
155 160
156 # Assign return values. 161 # Assign return values.
157 my $body = ""; 162 my $body = "";
158 my @ret = ("_", "_", "_"); 163 my @ret = ("_", "_", "_");
159 for(my $i=0; $i<@out; $i++) { 164 for(my $i=0; $i<@out; $i++) {
160 my $p = $out[$i]; 165 my $p = $out[$i];
161 my ($name, $type) = parseparam($p); 166 my ($name, $type) = parseparam($p);
162 my $reg = ""; 167 my $reg = "";
163 » » if($name eq "errno") { 168 » » if($name eq "errno" && !$plan9) {
164 $reg = "e1"; 169 $reg = "e1";
165 $ret[2] = $reg; 170 $ret[2] = $reg;
171 } elsif ($name eq "err" && $plan9) {
172 $ret[0] = "r0";·················
173 $ret[2] = "e1";
174 next;
166 } else { 175 } else {
167 $reg = sprintf("r%d", $i); 176 $reg = sprintf("r%d", $i);
168 $ret[$i] = $reg; 177 $ret[$i] = $reg;
169 } 178 }
170 if($type eq "bool") { 179 if($type eq "bool") {
171 $reg = "$reg != 0"; 180 $reg = "$reg != 0";
172 } 181 }
173 if($type eq "int64" && $_32bit ne "") { 182 if($type eq "int64" && $_32bit ne "") {
174 # 64-bit number in r1:r0 or r0:r1. 183 # 64-bit number in r1:r0 or r0:r1.
175 if($i+2 > @out) { 184 if($i+2 > @out) {
176 print STDERR "$ARGV:$.: not enough registers for int64 return\n"; 185 print STDERR "$ARGV:$.: not enough registers for int64 return\n";
177 } 186 }
178 if($_32bit eq "big-endian") { 187 if($_32bit eq "big-endian") {
179 $reg = sprintf("int64(r%d)<<32 | int64(r%d)", $i , $i+1); 188 $reg = sprintf("int64(r%d)<<32 | int64(r%d)", $i , $i+1);
180 } else { 189 } else {
181 $reg = sprintf("int64(r%d)<<32 | int64(r%d)", $i +1, $i); 190 $reg = sprintf("int64(r%d)<<32 | int64(r%d)", $i +1, $i);
182 } 191 }
183 $ret[$i] = sprintf("r%d", $i); 192 $ret[$i] = sprintf("r%d", $i);
184 $ret[$i+1] = sprintf("r%d", $i+1); 193 $ret[$i+1] = sprintf("r%d", $i+1);
185 } 194 }
186 $body .= "\t$name = $type($reg)\n"; 195 $body .= "\t$name = $type($reg)\n";
187 } 196 }
188 if ($ret[0] eq "_" && $ret[1] eq "_" && $ret[2] eq "_") { 197 if ($ret[0] eq "_" && $ret[1] eq "_" && $ret[2] eq "_") {
189 $text .= "\t$call\n"; 198 $text .= "\t$call\n";
190 } else { 199 } else {
191 $text .= "\t$ret[0], $ret[1], $ret[2] := $call\n"; 200 $text .= "\t$ret[0], $ret[1], $ret[2] := $call\n";
192 } 201 }
193 $text .= $body; 202 $text .= $body;
203 ········
204 if ($plan9 && $ret[2] eq "e1") {
205 $text .= "\terr = nil\n";
206 $text .= "\tif int(r0) == -1 {\n";
207 $text .= "\t\t err = NewError(e1)\n";
208 $text .= "\t}\n";
209 }
194 210
195 $text .= "\treturn\n"; 211 $text .= "\treturn\n";
196 $text .= "}\n\n"; 212 $text .= "}\n\n";
197 } 213 }
198 214
199 chomp $text; 215 chomp $text;
200 chomp $text; 216 chomp $text;
201 217
202 if($errors) { 218 if($errors) {
203 exit 1; 219 exit 1;
204 } 220 }
205 221
206 print <<EOF; 222 print <<EOF;
207 // $cmdline 223 // $cmdline
208 // MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT 224 // MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
209 225
210 package syscall 226 package syscall
211 227
212 import "unsafe" 228 import "unsafe"
213 229
214 $text 230 $text
215 EOF 231 EOF
216 exit 0; 232 exit 0;
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b