blob: fa5420bc5f5a18c553867ac92e2ca462ceb64819 [file] [log] [blame]
Stephen Crane77bb5642017-08-31 15:08:26 -07001#!/usr/bin/env python
Pavel Chupinf12a18b2012-12-12 13:11:48 +04002
3# This tool is used to generate the assembler system call stubs,
4# the header files listing all available system calls, and the
5# makefiles used to build all the stubs.
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -07006
Christopher Ferris01bd32e2014-08-05 12:19:27 -07007import atexit
Elliott Hughes103ccde2013-10-16 14:27:59 -07008import commands
9import filecmp
10import glob
Elliott Hughes103ccde2013-10-16 14:27:59 -070011import re
12import shutil
13import stat
Elliott Hughesdc1fb702014-08-20 11:16:11 -070014import string
Elliott Hughes103ccde2013-10-16 14:27:59 -070015import sys
Christopher Ferris01bd32e2014-08-05 12:19:27 -070016import tempfile
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070017
Elliott Hughesdc1fb702014-08-20 11:16:11 -070018
Elliott Hughesc2faf232020-02-03 17:56:06 -080019SupportedArchitectures = [ "arm", "arm64", "x86", "x86_64" ]
Elliott Hughesdc1fb702014-08-20 11:16:11 -070020
Elliott Hughesd67b0372019-04-15 14:18:26 -070021syscall_stub_header = \
Elliott Hughes103ccde2013-10-16 14:27:59 -070022"""
Elliott Hughes0437f3f2013-10-07 23:53:13 -070023ENTRY(%(func)s)
Pavel Chupinf12a18b2012-12-12 13:11:48 +040024"""
25
Elliott Hughes0437f3f2013-10-07 23:53:13 -070026
Elliott Hughes0437f3f2013-10-07 23:53:13 -070027#
28# ARM assembler templates for each syscall stub
29#
30
31arm_eabi_call_default = syscall_stub_header + """\
32 mov ip, r7
Christopher Ferrisf5a91232016-04-27 18:31:02 -070033 .cfi_register r7, ip
Elliott Hughes0437f3f2013-10-07 23:53:13 -070034 ldr r7, =%(__NR_name)s
35 swi #0
36 mov r7, ip
Christopher Ferrisf5a91232016-04-27 18:31:02 -070037 .cfi_restore r7
Elliott Hughes0437f3f2013-10-07 23:53:13 -070038 cmn r0, #(MAX_ERRNO + 1)
39 bxls lr
40 neg r0, r0
Elliott Hughes011e1112014-09-08 15:25:01 -070041 b __set_errno_internal
Elliott Hughes0437f3f2013-10-07 23:53:13 -070042END(%(func)s)
43"""
44
45arm_eabi_call_long = syscall_stub_header + """\
46 mov ip, sp
Elliott Hughes0437f3f2013-10-07 23:53:13 -070047 stmfd sp!, {r4, r5, r6, r7}
Christopher Ferrised459702013-12-02 17:44:53 -080048 .cfi_def_cfa_offset 16
49 .cfi_rel_offset r4, 0
50 .cfi_rel_offset r5, 4
51 .cfi_rel_offset r6, 8
52 .cfi_rel_offset r7, 12
Elliott Hughes0437f3f2013-10-07 23:53:13 -070053 ldmfd ip, {r4, r5, r6}
54 ldr r7, =%(__NR_name)s
55 swi #0
56 ldmfd sp!, {r4, r5, r6, r7}
Christopher Ferrised459702013-12-02 17:44:53 -080057 .cfi_def_cfa_offset 0
Elliott Hughes0437f3f2013-10-07 23:53:13 -070058 cmn r0, #(MAX_ERRNO + 1)
59 bxls lr
60 neg r0, r0
Elliott Hughes011e1112014-09-08 15:25:01 -070061 b __set_errno_internal
Elliott Hughes0437f3f2013-10-07 23:53:13 -070062END(%(func)s)
63"""
64
65
66#
Elliott Hughesd67b0372019-04-15 14:18:26 -070067# Arm64 assembler template for each syscall stub
Colin Crossd1973ca2014-01-21 19:50:58 -080068#
69
70arm64_call = syscall_stub_header + """\
Colin Crossd1973ca2014-01-21 19:50:58 -080071 mov x8, %(__NR_name)s
72 svc #0
73
Colin Crossd1973ca2014-01-21 19:50:58 -080074 cmn x0, #(MAX_ERRNO + 1)
75 cneg x0, x0, hi
Elliott Hughes011e1112014-09-08 15:25:01 -070076 b.hi __set_errno_internal
Colin Crossd1973ca2014-01-21 19:50:58 -080077
78 ret
79END(%(func)s)
80"""
81
82
83#
Elliott Hughesd67b0372019-04-15 14:18:26 -070084# MIPS assembler template for each syscall stub
Elliott Hughes0437f3f2013-10-07 23:53:13 -070085#
86
Elliott Hughes9abbbdc2014-02-19 14:54:31 -080087mips_call = syscall_stub_header + """\
Elliott Hughes0437f3f2013-10-07 23:53:13 -070088 .set noreorder
Elliott Hughesd4ca2312017-10-11 22:27:45 -070089 .cpload $t9
90 li $v0, %(__NR_name)s
Elliott Hughes0437f3f2013-10-07 23:53:13 -070091 syscall
Elliott Hughesd4ca2312017-10-11 22:27:45 -070092 bnez $a3, 1f
93 move $a0, $v0
94 j $ra
Elliott Hughes0437f3f2013-10-07 23:53:13 -070095 nop
961:
Elliott Hughesd4ca2312017-10-11 22:27:45 -070097 la $t9,__set_errno_internal
98 j $t9
Elliott Hughes0437f3f2013-10-07 23:53:13 -070099 nop
100 .set reorder
Elliott Hughes9abbbdc2014-02-19 14:54:31 -0800101END(%(func)s)
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700102"""
103
104
Elliott Hughescd6780b2013-02-07 14:07:00 -0800105#
Elliott Hughesd67b0372019-04-15 14:18:26 -0700106# MIPS64 assembler template for each syscall stub
Chris Dearman50432122014-02-05 16:59:23 -0800107#
108
Elliott Hughes9abbbdc2014-02-19 14:54:31 -0800109mips64_call = syscall_stub_header + """\
Chris Dearman50432122014-02-05 16:59:23 -0800110 .set push
111 .set noreorder
Elliott Hughesab413c52017-10-13 13:22:24 -0700112 li $v0, %(__NR_name)s
Chris Dearman50432122014-02-05 16:59:23 -0800113 syscall
Elliott Hughesab413c52017-10-13 13:22:24 -0700114 bnez $a3, 1f
115 move $a0, $v0
116 j $ra
Chris Dearman50432122014-02-05 16:59:23 -0800117 nop
1181:
Elliott Hughesab413c52017-10-13 13:22:24 -0700119 move $t0, $ra
120 bal 2f
Chris Dearman50432122014-02-05 16:59:23 -0800121 nop
1222:
Elliott Hughesab413c52017-10-13 13:22:24 -0700123 .cpsetup $ra, $t1, 2b
124 LA $t9, __set_errno_internal
Chris Dearman50432122014-02-05 16:59:23 -0800125 .cpreturn
Elliott Hughesab413c52017-10-13 13:22:24 -0700126 j $t9
127 move $ra, $t0
Chris Dearman50432122014-02-05 16:59:23 -0800128 .set pop
Elliott Hughes9abbbdc2014-02-19 14:54:31 -0800129END(%(func)s)
Chris Dearman50432122014-02-05 16:59:23 -0800130"""
131
132
133#
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700134# x86 assembler templates for each syscall stub
135#
136
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800137x86_registers = [ "ebx", "ecx", "edx", "esi", "edi", "ebp" ]
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700138
Mingwei Shibe910522015-11-12 07:02:14 +0000139x86_call_prepare = """\
140
141 call __kernel_syscall
142 pushl %eax
143 .cfi_adjust_cfa_offset 4
144 .cfi_rel_offset eax, 0
145
146"""
147
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700148x86_call = """\
149 movl $%(__NR_name)s, %%eax
Mingwei Shibe910522015-11-12 07:02:14 +0000150 call *(%%esp)
151 addl $4, %%esp
152
Elliott Hughes9aceab52013-03-12 14:57:30 -0700153 cmpl $-MAX_ERRNO, %%eax
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700154 jb 1f
155 negl %%eax
156 pushl %%eax
Elliott Hughes011e1112014-09-08 15:25:01 -0700157 call __set_errno_internal
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700158 addl $4, %%esp
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -07001591:
160"""
161
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700162x86_return = """\
163 ret
164END(%(func)s)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700165"""
166
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700167
Elliott Hughescd6780b2013-02-07 14:07:00 -0800168#
Elliott Hughesd67b0372019-04-15 14:18:26 -0700169# x86_64 assembler template for each syscall stub
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400170#
171
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700172x86_64_call = """\
173 movl $%(__NR_name)s, %%eax
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400174 syscall
175 cmpq $-MAX_ERRNO, %%rax
176 jb 1f
177 negl %%eax
178 movl %%eax, %%edi
Elliott Hughes011e1112014-09-08 15:25:01 -0700179 call __set_errno_internal
Pavel Chupinf12a18b2012-12-12 13:11:48 +04001801:
181 ret
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700182END(%(func)s)
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400183"""
184
Raghu Gandham1fa0d842012-01-27 17:51:42 -0800185
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100186def param_uses_64bits(param):
187 """Returns True iff a syscall parameter description corresponds
188 to a 64-bit type."""
189 param = param.strip()
190 # First, check that the param type begins with one of the known
191 # 64-bit types.
192 if not ( \
193 param.startswith("int64_t") or param.startswith("uint64_t") or \
194 param.startswith("loff_t") or param.startswith("off64_t") or \
195 param.startswith("long long") or param.startswith("unsigned long long") or
196 param.startswith("signed long long") ):
197 return False
198
199 # Second, check that there is no pointer type here
200 if param.find("*") >= 0:
201 return False
202
203 # Ok
204 return True
205
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700206
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100207def count_arm_param_registers(params):
208 """This function is used to count the number of register used
Elliott Hughescd6780b2013-02-07 14:07:00 -0800209 to pass parameters when invoking an ARM system call.
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100210 This is because the ARM EABI mandates that 64-bit quantities
211 must be passed in an even+odd register pair. So, for example,
212 something like:
213
214 foo(int fd, off64_t pos)
215
216 would actually need 4 registers:
217 r0 -> int
218 r1 -> unused
219 r2-r3 -> pos
220 """
221 count = 0
222 for param in params:
223 if param_uses_64bits(param):
224 if (count & 1) != 0:
225 count += 1
226 count += 2
227 else:
228 count += 1
229 return count
230
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700231
David 'Digit' Turner95d751f2010-12-16 16:47:14 +0100232def count_generic_param_registers(params):
233 count = 0
234 for param in params:
235 if param_uses_64bits(param):
236 count += 2
237 else:
238 count += 1
239 return count
240
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700241
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400242def count_generic_param_registers64(params):
243 count = 0
244 for param in params:
245 count += 1
246 return count
247
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700248
Elliott Hughescda62092013-03-22 13:50:44 -0700249# This lets us support regular system calls like __NR_write and also weird
250# ones like __ARM_NR_cacheflush, where the NR doesn't come at the start.
251def make__NR_name(name):
Christopher Ferris01bd32e2014-08-05 12:19:27 -0700252 if name.startswith("__ARM_NR_"):
Elliott Hughescda62092013-03-22 13:50:44 -0700253 return name
254 else:
255 return "__NR_%s" % (name)
256
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700257
Elliott Hughesfff6e272013-10-24 17:03:20 -0700258def add_footer(pointer_length, stub, syscall):
259 # Add any aliases for this syscall.
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700260 aliases = syscall["aliases"]
261 for alias in aliases:
Christopher Ferrisfa5faa02015-03-24 16:50:46 -0700262 stub += "\nALIAS_SYMBOL(%s, %s)\n" % (alias, syscall["func"])
Elliott Hughesfff6e272013-10-24 17:03:20 -0700263
Nick Kralevich00490ae2015-02-03 11:27:25 -0800264 # Use hidden visibility on LP64 for any functions beginning with underscores.
Elliott Hughes50080a22019-06-19 12:47:53 -0700265 if pointer_length == 64 and syscall["func"].startswith("__"):
Elliott Hughesd465eb42014-02-19 18:59:19 -0800266 stub += '.hidden ' + syscall["func"] + '\n'
Elliott Hughesfff6e272013-10-24 17:03:20 -0700267
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700268 return stub
269
270
271def arm_eabi_genstub(syscall):
272 num_regs = count_arm_param_registers(syscall["params"])
273 if num_regs > 4:
274 return arm_eabi_call_long % syscall
275 return arm_eabi_call_default % syscall
276
277
Colin Crossd1973ca2014-01-21 19:50:58 -0800278def arm64_genstub(syscall):
279 return arm64_call % syscall
280
281
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700282def mips_genstub(syscall):
283 return mips_call % syscall
284
285
Chris Dearman50432122014-02-05 16:59:23 -0800286def mips64_genstub(syscall):
287 return mips64_call % syscall
288
289
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700290def x86_genstub(syscall):
291 result = syscall_stub_header % syscall
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700292
293 numparams = count_generic_param_registers(syscall["params"])
Mingwei Shibe910522015-11-12 07:02:14 +0000294 stack_bias = numparams*4 + 8
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800295 offset = 0
296 mov_result = ""
Christopher Ferris15b91e92014-05-29 18:17:09 -0700297 first_push = True
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800298 for register in x86_registers[:numparams]:
299 result += " pushl %%%s\n" % register
Christopher Ferris15b91e92014-05-29 18:17:09 -0700300 if first_push:
301 result += " .cfi_def_cfa_offset 8\n"
302 result += " .cfi_rel_offset %s, 0\n" % register
303 first_push = False
304 else:
305 result += " .cfi_adjust_cfa_offset 4\n"
306 result += " .cfi_rel_offset %s, 0\n" % register
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800307 mov_result += " mov %d(%%esp), %%%s\n" % (stack_bias+offset, register)
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800308 offset += 4
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700309
Mingwei Shibe910522015-11-12 07:02:14 +0000310 result += x86_call_prepare
Christopher Ferris15b91e92014-05-29 18:17:09 -0700311 result += mov_result
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700312 result += x86_call % syscall
313
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800314 for register in reversed(x86_registers[:numparams]):
315 result += " popl %%%s\n" % register
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700316
317 result += x86_return % syscall
318 return result
319
Serban Constantinescufeaa89a2013-10-07 16:49:09 +0100320
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700321def x86_genstub_socketcall(syscall):
322 # %ebx <--- Argument 1 - The call id of the needed vectored
323 # syscall (socket, bind, recv, etc)
324 # %ecx <--- Argument 2 - Pointer to the rest of the arguments
325 # from the original function called (socket())
326
327 result = syscall_stub_header % syscall
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700328
329 # save the regs we need
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800330 result += " pushl %ebx\n"
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800331 result += " .cfi_def_cfa_offset 8\n"
332 result += " .cfi_rel_offset ebx, 0\n"
Christopher Ferris15b91e92014-05-29 18:17:09 -0700333 result += " pushl %ecx\n"
334 result += " .cfi_adjust_cfa_offset 4\n"
335 result += " .cfi_rel_offset ecx, 0\n"
Mingwei Shibe910522015-11-12 07:02:14 +0000336 stack_bias = 16
337
338 result += x86_call_prepare
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700339
340 # set the call id (%ebx)
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800341 result += " mov $%d, %%ebx\n" % syscall["socketcall_id"]
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700342
343 # set the pointer to the rest of the args into %ecx
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800344 result += " mov %esp, %ecx\n"
345 result += " addl $%d, %%ecx\n" % (stack_bias)
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700346
347 # now do the syscall code itself
348 result += x86_call % syscall
349
350 # now restore the saved regs
Christopher Ferrise4bc7562014-01-06 16:39:10 -0800351 result += " popl %ecx\n"
352 result += " popl %ebx\n"
Elliott Hughes0437f3f2013-10-07 23:53:13 -0700353
354 # epilog
355 result += x86_return % syscall
356 return result
357
358
359def x86_64_genstub(syscall):
360 result = syscall_stub_header % syscall
361 num_regs = count_generic_param_registers64(syscall["params"])
362 if (num_regs > 3):
363 # rcx is used as 4th argument. Kernel wants it at r10.
364 result += " movq %rcx, %r10\n"
365
366 result += x86_64_call % syscall
367 return result
368
369
Elliott Hughesdc1fb702014-08-20 11:16:11 -0700370class SysCallsTxtParser:
371 def __init__(self):
372 self.syscalls = []
373 self.lineno = 0
374
375 def E(self, msg):
376 print "%d: %s" % (self.lineno, msg)
377
378 def parse_line(self, line):
379 """ parse a syscall spec line.
380
381 line processing, format is
382 return type func_name[|alias_list][:syscall_name[:socketcall_id]] ( [paramlist] ) architecture_list
383 """
384 pos_lparen = line.find('(')
385 E = self.E
386 if pos_lparen < 0:
387 E("missing left parenthesis in '%s'" % line)
388 return
389
390 pos_rparen = line.rfind(')')
391 if pos_rparen < 0 or pos_rparen <= pos_lparen:
392 E("missing or misplaced right parenthesis in '%s'" % line)
393 return
394
395 return_type = line[:pos_lparen].strip().split()
396 if len(return_type) < 2:
397 E("missing return type in '%s'" % line)
398 return
399
400 syscall_func = return_type[-1]
401 return_type = string.join(return_type[:-1],' ')
402 socketcall_id = -1
403
404 pos_colon = syscall_func.find(':')
405 if pos_colon < 0:
406 syscall_name = syscall_func
407 else:
408 if pos_colon == 0 or pos_colon+1 >= len(syscall_func):
409 E("misplaced colon in '%s'" % line)
410 return
411
412 # now find if there is a socketcall_id for a dispatch-type syscall
413 # after the optional 2nd colon
414 pos_colon2 = syscall_func.find(':', pos_colon + 1)
415 if pos_colon2 < 0:
416 syscall_name = syscall_func[pos_colon+1:]
417 syscall_func = syscall_func[:pos_colon]
418 else:
419 if pos_colon2+1 >= len(syscall_func):
420 E("misplaced colon2 in '%s'" % line)
421 return
422 syscall_name = syscall_func[(pos_colon+1):pos_colon2]
423 socketcall_id = int(syscall_func[pos_colon2+1:])
424 syscall_func = syscall_func[:pos_colon]
425
426 alias_delim = syscall_func.find('|')
427 if alias_delim > 0:
428 alias_list = syscall_func[alias_delim+1:].strip()
429 syscall_func = syscall_func[:alias_delim]
430 alias_delim = syscall_name.find('|')
431 if alias_delim > 0:
432 syscall_name = syscall_name[:alias_delim]
433 syscall_aliases = string.split(alias_list, ',')
434 else:
435 syscall_aliases = []
436
437 if pos_rparen > pos_lparen+1:
438 syscall_params = line[pos_lparen+1:pos_rparen].split(',')
439 params = string.join(syscall_params,',')
440 else:
441 syscall_params = []
442 params = "void"
443
444 t = {
445 "name" : syscall_name,
446 "func" : syscall_func,
447 "aliases" : syscall_aliases,
448 "params" : syscall_params,
449 "decl" : "%-15s %s (%s);" % (return_type, syscall_func, params),
450 "socketcall_id" : socketcall_id
451 }
452
453 # Parse the architecture list.
454 arch_list = line[pos_rparen+1:].strip()
455 if arch_list == "all":
Elliott Hughesae03b122019-09-17 16:37:05 -0700456 for arch in SupportedArchitectures:
Elliott Hughesdc1fb702014-08-20 11:16:11 -0700457 t[arch] = True
Elliott Hughes8251d442018-11-09 13:55:21 -0800458 elif arch_list == "lp32":
Elliott Hughesae03b122019-09-17 16:37:05 -0700459 for arch in SupportedArchitectures:
Elliott Hughes8251d442018-11-09 13:55:21 -0800460 if "64" not in arch:
461 t[arch] = True
462 elif arch_list == "lp64":
Elliott Hughesae03b122019-09-17 16:37:05 -0700463 for arch in SupportedArchitectures:
Elliott Hughes8251d442018-11-09 13:55:21 -0800464 if "64" in arch:
465 t[arch] = True
Elliott Hughesdc1fb702014-08-20 11:16:11 -0700466 else:
467 for arch in string.split(arch_list, ','):
Elliott Hughesae03b122019-09-17 16:37:05 -0700468 if arch in SupportedArchitectures:
Elliott Hughesdc1fb702014-08-20 11:16:11 -0700469 t[arch] = True
Elliott Hughesc2faf232020-02-03 17:56:06 -0800470 elif arch in ['mips', 'mips64']:
471 # Unused.
472 pass
Elliott Hughesdc1fb702014-08-20 11:16:11 -0700473 else:
474 E("invalid syscall architecture '%s' in '%s'" % (arch, line))
475 return
476
477 self.syscalls.append(t)
478
Paul Lawrence7ea40902017-02-14 13:32:23 -0800479 def parse_open_file(self, fp):
480 for line in fp:
Elliott Hughesdc1fb702014-08-20 11:16:11 -0700481 self.lineno += 1
482 line = line.strip()
483 if not line: continue
484 if line[0] == '#': continue
485 self.parse_line(line)
486
Paul Lawrence7ea40902017-02-14 13:32:23 -0800487 def parse_file(self, file_path):
Paul Lawrence7ea40902017-02-14 13:32:23 -0800488 with open(file_path) as fp:
Alessio Balsini93d4f8b2017-04-11 18:27:29 +0200489 self.parse_open_file(fp)
Elliott Hughesdc1fb702014-08-20 11:16:11 -0700490
491
John Catere86e5052019-09-26 14:47:03 -0400492def main(arch, syscall_file):
Elliott Hughes782c4852019-04-16 12:31:00 -0700493 parser = SysCallsTxtParser()
John Catere86e5052019-09-26 14:47:03 -0400494 parser.parse_file(syscall_file)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700495
Elliott Hughes782c4852019-04-16 12:31:00 -0700496 for syscall in parser.syscalls:
497 syscall["__NR_name"] = make__NR_name(syscall["name"])
Pavel Chupinf12a18b2012-12-12 13:11:48 +0400498
Elliott Hughes782c4852019-04-16 12:31:00 -0700499 if syscall.has_key("arm"):
500 syscall["asm-arm"] = add_footer(32, arm_eabi_genstub(syscall), syscall)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700501
Elliott Hughes782c4852019-04-16 12:31:00 -0700502 if syscall.has_key("arm64"):
503 syscall["asm-arm64"] = add_footer(64, arm64_genstub(syscall), syscall)
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700504
Elliott Hughes782c4852019-04-16 12:31:00 -0700505 if syscall.has_key("x86"):
506 if syscall["socketcall_id"] >= 0:
507 syscall["asm-x86"] = add_footer(32, x86_genstub_socketcall(syscall), syscall)
508 else:
509 syscall["asm-x86"] = add_footer(32, x86_genstub(syscall), syscall)
510 elif syscall["socketcall_id"] >= 0:
511 E("socketcall_id for dispatch syscalls is only supported for x86 in '%s'" % t)
512 return
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700513
Elliott Hughes782c4852019-04-16 12:31:00 -0700514 if syscall.has_key("mips"):
515 syscall["asm-mips"] = add_footer(32, mips_genstub(syscall), syscall)
Colin Crossd1973ca2014-01-21 19:50:58 -0800516
Elliott Hughes782c4852019-04-16 12:31:00 -0700517 if syscall.has_key("mips64"):
518 syscall["asm-mips64"] = add_footer(64, mips64_genstub(syscall), syscall)
Elliott Hughescd6780b2013-02-07 14:07:00 -0800519
Elliott Hughes782c4852019-04-16 12:31:00 -0700520 if syscall.has_key("x86_64"):
521 syscall["asm-x86_64"] = add_footer(64, x86_64_genstub(syscall), syscall)
The Android Open Source Project4e468ed2008-12-17 18:03:48 -0800522
Elliott Hughes782c4852019-04-16 12:31:00 -0700523 print("/* Generated by gensyscalls.py. Do not edit. */\n")
524 print("#include <private/bionic_asm.h>\n")
525 for syscall in parser.syscalls:
526 if syscall.has_key("asm-%s" % arch):
527 print(syscall["asm-%s" % arch])
Chris Dearman50432122014-02-05 16:59:23 -0800528
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700529
Paul Lawrenceeabc3522016-11-11 11:33:42 -0800530if __name__ == "__main__":
John Catere86e5052019-09-26 14:47:03 -0400531 if len(sys.argv) < 2:
532 print "Usage: gensyscalls.py ARCH SOURCE_FILE"
533 sys.exit(1)
534
535 arch = sys.argv[1]
536 syscall_file = sys.argv[2]
537 main(arch, syscall_file)