blob: b58754bda07d9408de33366f57295067591271df [file] [log] [blame]
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -07001#!/usr/bin/python
2#
3# this tool is used to generate the syscall assmbler templates
4# to be placed into arch-x86/syscalls, as well as the content
5# of arch-x86/linux/_syscalls.h
6#
7
The Android Open Source Project4e468ed2008-12-17 18:03:48 -08008import sys, os.path, glob, re, commands, filecmp, shutil
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -07009
10from bionic_utils import *
11
12# set this to 1 if you want to generate thumb stubs
13gen_thumb_stubs = 0
14
15# set this to 1 if you want to generate ARM EABI stubs
16gen_eabi_stubs = 1
17
18# get the root Bionic directory, simply this script's dirname
19#
20bionic_root = find_bionic_root()
21if not bionic_root:
22 print "could not find the Bionic root directory. aborting"
23 sys.exit(1)
24
25if bionic_root[-1] != '/':
26 bionic_root += "/"
27
28print "bionic_root is %s" % bionic_root
29
30# temp directory where we store all intermediate files
31bionic_temp = "/tmp/bionic_gensyscalls/"
32
33# all architectures, update as you see fit
Shin-ichiro KAWASAKIce0595d2009-09-01 19:03:06 +090034all_archs = [ "arm", "x86", "sh" ]
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070035
36def make_dir( path ):
37 if not os.path.exists(path):
38 parent = os.path.dirname(path)
39 if parent:
40 make_dir(parent)
41 os.mkdir(path)
42
43def create_file( relpath ):
44 dir = os.path.dirname( bionic_temp + relpath )
45 make_dir(dir)
46 return open( bionic_temp + relpath, "w" )
47
48# x86 assembler templates for each syscall stub
49#
50
51x86_header = """/* autogenerated by gensyscalls.py */
52#include <sys/linux-syscalls.h>
53
54 .text
55 .type %(fname)s, @function
56 .globl %(fname)s
57 .align 4
58
59%(fname)s:
60"""
61
62x86_registers = [ "%ebx", "%ecx", "%edx", "%esi", "%edi", "%ebp" ]
63
64x86_call = """ movl $%(idname)s, %%eax
65 int $0x80
66 cmpl $-129, %%eax
67 jb 1f
68 negl %%eax
69 pushl %%eax
70 call __set_errno
71 addl $4, %%esp
72 orl $-1, %%eax
731:
74"""
75
76x86_return = """ ret
77"""
78
79# ARM assembler templates for each syscall stub
80#
81arm_header = """/* autogenerated by gensyscalls.py */
82#include <sys/linux-syscalls.h>
83
84 .text
85 .type %(fname)s, #function
86 .globl %(fname)s
87 .align 4
88 .fnstart
89
90%(fname)s:
91"""
92
93arm_call_default = arm_header + """\
94 swi #%(idname)s
95 movs r0, r0
96 bxpl lr
97 b __set_syscall_errno
98 .fnend
99"""
100
101arm_call_long = arm_header + """\
102 .save {r4, r5, lr}
103 stmfd sp!, {r4, r5, lr}
104 ldr r4, [sp, #12]
105 ldr r5, [sp, #16]
106 swi # %(idname)s
107 ldmfd sp!, {r4, r5, lr}
108 movs r0, r0
109 bxpl lr
110 b __set_syscall_errno
111 .fnend
112"""
113
114arm_eabi_call_default = arm_header + """\
115 .save {r4, r7}
116 stmfd sp!, {r4, r7}
117 ldr r7, =%(idname)s
118 swi #0
119 ldmfd sp!, {r4, r7}
120 movs r0, r0
121 bxpl lr
122 b __set_syscall_errno
123 .fnend
124"""
125
126arm_eabi_call_long = arm_header + """\
127 mov ip, sp
128 .save {r4, r5, r6, r7}
129 stmfd sp!, {r4, r5, r6, r7}
130 ldmfd ip, {r4, r5, r6}
131 ldr r7, =%(idname)s
132 swi #0
133 ldmfd sp!, {r4, r5, r6, r7}
134 movs r0, r0
135 bxpl lr
136 b __set_syscall_errno
137 .fnend
138"""
139
140# ARM thumb assembler templates for each syscall stub
141#
142thumb_header = """/* autogenerated by gensyscalls.py */
143 .text
144 .type %(fname)s, #function
145 .globl %(fname)s
146 .align 4
147 .thumb_func
148 .fnstart
149
150#define __thumb__
151#include <sys/linux-syscalls.h>
152
153
154%(fname)s:
155"""
156
157thumb_call_default = thumb_header + """\
158 .save {r7,lr}
159 push {r7,lr}
160 ldr r7, =%(idname)s
161 swi #0
162 tst r0, r0
163 bmi 1f
164 pop {r7,pc}
1651:
166 neg r0, r0
167 ldr r1, =__set_errno
168 blx r1
169 pop {r7,pc}
170 .fnend
171"""
172
173thumb_call_long = thumb_header + """\
174 .save {r4,r5,r7,lr}
175 push {r4,r5,r7,lr}
176 ldr r4, [sp,#16]
177 ldr r5, [sp,#20]
178 ldr r7, =%(idname)s
179 swi #0
180 tst r0, r0
181 bmi 1f
182 pop {r4,r5,r7,pc}
1831:
184 neg r0, r0
185 ldr r1, =__set_errno
186 blx r1
187 pop {r4,r5,r7,pc}
188 .fnend
189"""
190
Shin-ichiro KAWASAKIce0595d2009-09-01 19:03:06 +0900191# SuperH assembler templates for each syscall stub
192#
193superh_header = """/* autogenerated by gensyscalls.py */
194#include <sys/linux-syscalls.h>
195
196 .text
197 .type %(fname)s, @function
198 .globl %(fname)s
199 .align 4
200
201%(fname)s:
202"""
203
204superh_call_default = """
205 /* invoke trap */
206 mov.l 0f, r3 /* trap num */
207 trapa #(%(numargs)s + 0x10)
208
209 /* check return value */
210 cmp/pz r0
211 bt %(idname)s_end
212
213 /* keep error number */
214 sts.l pr, @-r15
215 mov.l 1f, r1
216 jsr @r1
217 mov r0, r4
218 lds.l @r15+, pr
219
220%(idname)s_end:
221 rts
222 nop
223
224 .align 2
2250: .long %(idname)s
2261: .long __set_syscall_errno
227"""
228
229superh_5args_header = """
230 /* get ready for additonal arg */
231 mov.l @r15, r0
232"""
233
234superh_6args_header = """
235 /* get ready for additonal arg */
236 mov.l @r15, r0
237 mov.l @(4, r15), r1
238"""
239
240superh_7args_header = """
241 /* get ready for additonal arg */
242 mov.l @r15, r0
243 mov.l @(4, r15), r1
244 mov.l @(8, r15), r2
245"""
246
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700247
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100248def param_uses_64bits(param):
249 """Returns True iff a syscall parameter description corresponds
250 to a 64-bit type."""
251 param = param.strip()
252 # First, check that the param type begins with one of the known
253 # 64-bit types.
254 if not ( \
255 param.startswith("int64_t") or param.startswith("uint64_t") or \
256 param.startswith("loff_t") or param.startswith("off64_t") or \
257 param.startswith("long long") or param.startswith("unsigned long long") or
258 param.startswith("signed long long") ):
259 return False
260
261 # Second, check that there is no pointer type here
262 if param.find("*") >= 0:
263 return False
264
265 # Ok
266 return True
267
268def count_arm_param_registers(params):
269 """This function is used to count the number of register used
270 to pass parameters when invoking a thumb or ARM system call.
271 This is because the ARM EABI mandates that 64-bit quantities
272 must be passed in an even+odd register pair. So, for example,
273 something like:
274
275 foo(int fd, off64_t pos)
276
277 would actually need 4 registers:
278 r0 -> int
279 r1 -> unused
280 r2-r3 -> pos
281 """
282 count = 0
283 for param in params:
284 if param_uses_64bits(param):
285 if (count & 1) != 0:
286 count += 1
287 count += 2
288 else:
289 count += 1
290 return count
291
292def count_generic_param_registers(params):
293 count = 0
294 for param in params:
295 if param_uses_64bits(param):
296 count += 2
297 else:
298 count += 1
299 return count
300
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700301class State:
302 def __init__(self):
303 self.old_stubs = []
304 self.new_stubs = []
305 self.other_files = []
306 self.syscalls = []
307
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800308 def x86_genstub(self, fname, numparams, idname):
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700309 t = { "fname" : fname,
310 "idname" : idname }
311
312 result = x86_header % t
313 stack_bias = 4
314 for r in range(numparams):
315 result += " pushl " + x86_registers[r] + "\n"
316 stack_bias += 4
317
318 for r in range(numparams):
319 result += " mov %d(%%esp), %s" % (stack_bias+r*4, x86_registers[r]) + "\n"
320
321 result += x86_call % t
322
323 for r in range(numparams):
324 result += " popl " + x86_registers[numparams-r-1] + "\n"
325
326 result += x86_return
327 return result
328
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800329 def x86_genstub_cid(self, fname, numparams, idname, cid):
330 # We'll ignore numparams here because in reality, if there is a
331 # dispatch call (like a socketcall syscall) there are actually
332 # only 2 arguments to the syscall and 2 regs we have to save:
333 # %ebx <--- Argument 1 - The call id of the needed vectored
334 # syscall (socket, bind, recv, etc)
335 # %ecx <--- Argument 2 - Pointer to the rest of the arguments
336 # from the original function called (socket())
337 t = { "fname" : fname,
338 "idname" : idname }
339
340 result = x86_header % t
341 stack_bias = 4
342
343 # save the regs we need
344 result += " pushl %ebx" + "\n"
345 stack_bias += 4
346 result += " pushl %ecx" + "\n"
347 stack_bias += 4
348
349 # set the call id (%ebx)
350 result += " mov $%d, %%ebx" % (cid) + "\n"
351
352 # set the pointer to the rest of the args into %ecx
353 result += " mov %esp, %ecx" + "\n"
354 result += " addl $%d, %%ecx" % (stack_bias) + "\n"
355
356 # now do the syscall code itself
357 result += x86_call % t
358
359 # now restore the saved regs
360 result += " popl %ecx" + "\n"
361 result += " popl %ebx" + "\n"
362
363 # epilog
364 result += x86_return
365 return result
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700366
367 def arm_genstub(self,fname, flags, idname):
368 t = { "fname" : fname,
369 "idname" : idname }
370 if flags:
371 numargs = int(flags)
372 if numargs > 4:
373 return arm_call_long % t
374 return arm_call_default % t
375
376
377 def arm_eabi_genstub(self,fname, flags, idname):
378 t = { "fname" : fname,
379 "idname" : idname }
380 if flags:
381 numargs = int(flags)
382 if numargs > 4:
383 return arm_eabi_call_long % t
384 return arm_eabi_call_default % t
385
386
387 def thumb_genstub(self,fname, flags, idname):
388 t = { "fname" : fname,
389 "idname" : idname }
390 if flags:
391 numargs = int(flags)
392 if numargs > 4:
393 return thumb_call_long % t
394 return thumb_call_default % t
395
396
Shin-ichiro KAWASAKIce0595d2009-09-01 19:03:06 +0900397 def superh_genstub(self, fname, flags, idname):
398 numargs = int(flags)
399 t = { "fname" : fname,
400 "idname" : idname,
401 "numargs" : numargs }
402 superh_call = superh_header
403 if flags:
404 if numargs == 5:
405 superh_call += superh_5args_header
406 if numargs == 6:
407 superh_call += superh_6args_header
408 if numargs == 7:
409 superh_call += superh_7args_header
410 superh_call += superh_call_default
411 return superh_call % t
412
413
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700414 def process_file(self,input):
415 parser = SysCallsTxtParser()
416 parser.parse_file(input)
417 self.syscalls = parser.syscalls
418 parser = None
419
420 for t in self.syscalls:
421 syscall_func = t["func"]
422 syscall_params = t["params"]
423 syscall_name = t["name"]
424
425 if t["id"] >= 0:
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100426 num_regs = count_arm_param_registers(syscall_params)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700427 if gen_thumb_stubs:
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100428 t["asm-thumb"] = self.thumb_genstub(syscall_func,num_regs,"__NR_"+syscall_name)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700429 else:
430 if gen_eabi_stubs:
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100431 t["asm-arm"] = self.arm_eabi_genstub(syscall_func,num_regs,"__NR_"+syscall_name)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700432 else:
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100433 t["asm-arm"] = self.arm_genstub(syscall_func,num_regs,"__NR_"+syscall_name)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700434
435 if t["id2"] >= 0:
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100436 num_regs = count_generic_param_registers(syscall_params)
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800437 if t["cid"] >= 0:
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100438 t["asm-x86"] = self.x86_genstub_cid(syscall_func, num_regs, "__NR_"+syscall_name, t["cid"])
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800439 else:
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100440 t["asm-x86"] = self.x86_genstub(syscall_func, num_regs, "__NR_"+syscall_name)
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800441 elif t["cid"] >= 0:
442 E("cid for dispatch syscalls is only supported for x86 in "
443 "'%s'" % syscall_name)
444 return
Shin-ichiro KAWASAKIce0595d2009-09-01 19:03:06 +0900445 if t["id3"] >= 0:
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100446 num_regs = count_generic_param_registers(syscall_params)
447 t["asm-sh"] = self.superh_genstub(syscall_func,num_regs,"__NR_"+syscall_name)
Shin-ichiro KAWASAKIce0595d2009-09-01 19:03:06 +0900448
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800449
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700450
451 def gen_NR_syscall(self,fp,name,id):
452 fp.write( "#define __NR_%-25s (__NR_SYSCALL_BASE + %d)\n" % (name,id) )
453
454 # now dump the content of linux/_syscalls.h
455 def gen_linux_syscalls_h(self):
456 path = "include/sys/linux-syscalls.h"
457 D( "generating "+path )
458 fp = create_file( path )
459 fp.write( "/* auto-generated by gensyscalls.py, do not touch */\n" )
460 fp.write( "#ifndef _BIONIC_LINUX_SYSCALLS_H_\n\n" )
461 fp.write( "#if !defined __ASM_ARM_UNISTD_H && !defined __ASM_I386_UNISTD_H\n" )
462 fp.write( "#if defined __arm__ && !defined __ARM_EABI__ && !defined __thumb__\n" )
463 fp.write( " # define __NR_SYSCALL_BASE 0x900000\n" )
464 fp.write( " #else\n" )
465 fp.write( " # define __NR_SYSCALL_BASE 0\n" )
466 fp.write( " #endif\n\n" )
467
468 # first, all common syscalls
469 for sc in self.syscalls:
470 sc_id = sc["id"]
471 sc_id2 = sc["id2"]
472 sc_name = sc["name"]
473 if sc_id == sc_id2 and sc_id >= 0:
474 self.gen_NR_syscall( fp, sc_name, sc_id )
475
476 # now, all arm-specific syscalls
477 fp.write( "\n#ifdef __arm__\n" );
478 for sc in self.syscalls:
479 sc_id = sc["id"]
480 sc_id2 = sc["id2"]
481 sc_name = sc["name"]
482 if sc_id != sc_id2 and sc_id >= 0:
483 self.gen_NR_syscall( fp, sc_name, sc_id )
484 fp.write( "#endif\n" );
485
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800486 gen_syscalls = {}
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700487 # finally, all i386-specific syscalls
488 fp.write( "\n#ifdef __i386__\n" );
489 for sc in self.syscalls:
490 sc_id = sc["id"]
491 sc_id2 = sc["id2"]
492 sc_name = sc["name"]
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800493 if sc_id != sc_id2 and sc_id2 >= 0 and sc_name not in gen_syscalls:
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700494 self.gen_NR_syscall( fp, sc_name, sc_id2 )
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800495 gen_syscalls[sc_name] = True
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700496 fp.write( "#endif\n" );
497
Shin-ichiro KAWASAKIce0595d2009-09-01 19:03:06 +0900498 # all superh-specific syscalls
499 fp.write( "\n#if defined(__SH3__) || defined(__SH4__) \n" );
500 for sc in self.syscalls:
501 sc_id = sc["id"]
502 sc_id2 = sc["id2"]
503 sc_id3 = sc["id3"]
504 sc_name = sc["name"]
505 if sc_id2 != sc_id3 and sc_id3 >= 0:
506 self.gen_NR_syscall( fp, sc_name, sc_id3 )
507 else:
508 if sc_id != sc_id2 and sc_id2 >= 0:
509 self.gen_NR_syscall( fp, sc_name, sc_id2 )
510 fp.write( "#endif\n" );
511
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700512 fp.write( "\n#endif\n" )
513 fp.write( "\n#endif /* _BIONIC_LINUX_SYSCALLS_H_ */\n" );
514 fp.close()
515 self.other_files.append( path )
516
517
518 # now dump the content of linux/_syscalls.h
519 def gen_linux_unistd_h(self):
520 path = "include/sys/linux-unistd.h"
521 D( "generating "+path )
522 fp = create_file( path )
523 fp.write( "/* auto-generated by gensyscalls.py, do not touch */\n" )
524 fp.write( "#ifndef _BIONIC_LINUX_UNISTD_H_\n\n" );
525 fp.write( "#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n" )
526
527 for sc in self.syscalls:
528 fp.write( sc["decl"]+"\n" )
529
530 fp.write( "#ifdef __cplusplus\n}\n#endif\n" )
531 fp.write( "\n#endif /* _BIONIC_LINUX_UNISTD_H_ */\n" );
532 fp.close()
533 self.other_files.append( path )
534
535 # now dump the contents of syscalls.mk
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800536 def gen_arch_syscalls_mk(self, arch):
537 path = "arch-%s/syscalls.mk" % arch
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700538 D( "generating "+path )
539 fp = create_file( path )
540 fp.write( "# auto-generated by gensyscalls.py, do not touch\n" )
541 fp.write( "syscall_src := \n" )
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800542 arch_test = {
543 "arm": lambda x: x.has_key("asm-arm") or x.has_key("asm-thumb"),
Shin-ichiro KAWASAKIce0595d2009-09-01 19:03:06 +0900544 "x86": lambda x: x.has_key("asm-x86"),
545 "sh": lambda x: x.has_key("asm-sh")
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800546 }
547
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700548 for sc in self.syscalls:
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800549 if arch_test[arch](sc):
550 fp.write("syscall_src += arch-%s/syscalls/%s.S\n" %
551 (arch, sc["func"]))
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700552 fp.close()
553 self.other_files.append( path )
554
555 # now generate each syscall stub
556 def gen_syscall_stubs(self):
557 for sc in self.syscalls:
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800558 if sc.has_key("asm-arm") and 'arm' in all_archs:
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700559 fname = "arch-arm/syscalls/%s.S" % sc["func"]
David 'Digit' Turnerfc269312010-10-11 22:11:06 +0200560 D2( ">>> generating "+fname )
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700561 fp = create_file( fname )
562 fp.write(sc["asm-arm"])
563 fp.close()
564 self.new_stubs.append( fname )
565
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800566 if sc.has_key("asm-thumb") and 'arm' in all_archs:
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700567 fname = "arch-arm/syscalls/%s.S" % sc["func"]
David 'Digit' Turnerfc269312010-10-11 22:11:06 +0200568 D2( ">>> generating "+fname )
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700569 fp = create_file( fname )
570 fp.write(sc["asm-thumb"])
571 fp.close()
572 self.new_stubs.append( fname )
573
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800574 if sc.has_key("asm-x86") and 'x86' in all_archs:
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700575 fname = "arch-x86/syscalls/%s.S" % sc["func"]
David 'Digit' Turnerfc269312010-10-11 22:11:06 +0200576 D2( ">>> generating "+fname )
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700577 fp = create_file( fname )
578 fp.write(sc["asm-x86"])
579 fp.close()
580 self.new_stubs.append( fname )
581
Shin-ichiro KAWASAKIce0595d2009-09-01 19:03:06 +0900582 if sc.has_key("asm-sh"):
583 fname = "arch-sh/syscalls/%s.S" % sc["func"]
David 'Digit' Turnerfc269312010-10-11 22:11:06 +0200584 D2( ">>> generating "+fname )
Shin-ichiro KAWASAKIce0595d2009-09-01 19:03:06 +0900585 fp = create_file( fname )
586 fp.write(sc["asm-sh"])
587 fp.close()
588 self.new_stubs.append( fname )
589
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700590
591 def regenerate(self):
592 D( "scanning for existing architecture-specific stub files" )
593
594 bionic_root_len = len(bionic_root)
595
596 for arch in all_archs:
597 arch_path = bionic_root + "arch-" + arch
598 D( "scanning " + arch_path )
599 files = glob.glob( arch_path + "/syscalls/*.S" )
600 for f in files:
601 self.old_stubs.append( f[bionic_root_len:] )
602
603 D( "found %d stub files" % len(self.old_stubs) )
604
605 if not os.path.exists( bionic_temp ):
606 D( "creating %s" % bionic_temp )
607 os.mkdir( bionic_temp )
608
609# D( "p4 editing source files" )
610# for arch in all_archs:
611# commands.getoutput( "p4 edit " + arch + "/syscalls/*.S " )
612# commands.getoutput( "p4 edit " + arch + "/syscalls.mk" )
613# commands.getoutput( "p4 edit " + bionic_root + "include/sys/linux-syscalls.h" )
614
615 D( "re-generating stubs and support files" )
616
617 self.gen_linux_syscalls_h()
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800618 for arch in all_archs:
619 self.gen_arch_syscalls_mk(arch)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700620 self.gen_linux_unistd_h()
621 self.gen_syscall_stubs()
622
623 D( "comparing files" )
624 adds = []
625 edits = []
626
627 for stub in self.new_stubs + self.other_files:
628 if not os.path.exists( bionic_root + stub ):
David 'Digit' Turnerfc269312010-10-11 22:11:06 +0200629 # new file, git add it
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700630 D( "new file: " + stub)
631 adds.append( bionic_root + stub )
632 shutil.copyfile( bionic_temp + stub, bionic_root + stub )
633
634 elif not filecmp.cmp( bionic_temp + stub, bionic_root + stub ):
635 D( "changed file: " + stub)
636 edits.append( stub )
637
638 deletes = []
639 for stub in self.old_stubs:
640 if not stub in self.new_stubs:
641 D( "deleted file: " + stub)
642 deletes.append( bionic_root + stub )
643
644
645 if adds:
David 'Digit' Turnerfc269312010-10-11 22:11:06 +0200646 commands.getoutput("git add " + " ".join(adds))
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700647 if deletes:
David 'Digit' Turnerfc269312010-10-11 22:11:06 +0200648 commands.getoutput("git rm " + " ".join(deletes))
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700649 if edits:
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700650 for file in edits:
651 shutil.copyfile( bionic_temp + file, bionic_root + file )
David 'Digit' Turnerfc269312010-10-11 22:11:06 +0200652 commands.getoutput("git add " +
653 " ".join((bionic_root + file) for file in edits))
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700654
David 'Digit' Turnerfc269312010-10-11 22:11:06 +0200655 commands.getoutput("git add %s%s" % (bionic_root,"SYSCALLS.TXT"))
656
657 if (not adds) and (not deletes) and (not edits):
658 D("no changes detected!")
659 else:
660 D("ready to go!!")
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700661
662D_setlevel(1)
663
664state = State()
665state.process_file(bionic_root+"SYSCALLS.TXT")
666state.regenerate()