2 # Copyright (c) 2020 Peter Hsu. All Rights Reserved. See LICENCE file for details.
8 PKpattern
= re
.compile(r
'#define\s+SYS_(\S+)\s+(\d+)')
9 RVpattern
= re
.compile(r
'#define\s+TARGET_NR_(\S+)\s+(\d+)')
11 # Algorith is we make table of RISC-V system call names and record
12 # their numbers, create a C file of names, include the host x86
13 # 'asm/unistd_64.h' file to get the correct mapping.
18 rv
= open('../include/pk-syscall.h', 'r')
20 m
= PKpattern
.match(line
)
22 name
, num
= m
.groups()
26 highest
= max(num
, highest
)
29 rv
= open('../include/syscall64_nr.h', 'r')
31 m
= RVpattern
.match(line
)
33 name
, num
= m
.groups()
35 if num
in ecall
and name
!= ecall
[num
]:
36 print('libc {:s} override pk {:s} ecall'.format(name
, ecall
[num
]))
39 highest
= max(num
, highest
)
41 en
= open('ecall_nums.h', 'w')
43 for name
in sorted(enames
.keys()):
44 en
.write('#ifndef __NR_{:s}\n'.format(name
))
45 en
.write('#define __NR_{:s} -2\n'.format(name
))
55 for n
in range(0, highest
+1):
58 en
.write(' /* {:5d} */ {{ __NR_{:s}, "{:s}" }},\n'.format(n
, name
, name
))
60 en
.write(' /* {:5d} */ {{ -1, 0 }},\n'.format(n
))
63 en
.write('const int rv_syscall_entries = {:d};\n\n'.format(highest
+1))