1#!/usr/bin/python
2#
3# Copyright (C) 2023 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18import json
19import sys
20
21
22def _print_header(arch):
23  print("""\
24/*
25 * Copyright (C) 2023 The Android Open Source Project
26 *
27 * Licensed under the Apache License, Version 2.0 (the "License");
28 * you may not use this file except in compliance with the License.
29 * You may obtain a copy of the License at
30 *
31 *      http://www.apache.org/licenses/LICENSE-2.0
32 *
33 * Unless required by applicable law or agreed to in writing, software
34 * distributed under the License is distributed on an "AS IS" BASIS,
35 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
36 * See the License for the specific language governing permissions and
37 * limitations under the License.
38 */
39
40#ifndef BERBERIS_GUEST_OS_PRIMITIVES_GEN_SYSCALL_NUMBERS_ARCH_H_
41#define BERBERIS_GUEST_OS_PRIMITIVES_GEN_SYSCALL_NUMBERS_ARCH_H_
42
43namespace berberis {""")
44
45
46def _print_footer(arch):
47  print("""\
48
49}  // namespace berberis
50
51#endif  // BERBERIS_GUEST_OS_PRIMITIVES_GEN_SYSCALL_NUMBERS_ARCH_H_""")
52
53
54def _print_enum(arch, kernel_syscalls):
55  print("""\
56
57enum {""")
58
59  for nr, syscall in sorted(kernel_syscalls.items()):
60    if arch in syscall:
61      assert nr.startswith('__')
62      print('  GUEST_%s = %s,' % (nr[2:], syscall[arch]['id']))
63
64  print('};')
65
66
67def main(argv):
68  src_arch = argv[1]
69  dst_arch = argv[2]
70
71  with open(argv[3]) as json_file:
72    kernel_syscalls = json.load(json_file)
73
74  # TODO(b/232598137): merge custom syscalls?
75
76  display_src_arch = src_arch.upper()
77
78  _print_header(display_src_arch)
79  _print_enum(src_arch, kernel_syscalls)
80  _print_footer(display_src_arch)
81
82  return 0
83
84
85if __name__ == '__main__':
86  sys.exit(main(sys.argv))
87