|
19 | 19 | # limitations under the License. |
20 | 20 | # |
21 | 21 |
|
22 | | -if [ $# -ne 1 ] || [ ! -e "$1" -o -d "$1" ]; then |
23 | | - echo "USAGE: $0 [linux_with_debugging_symbols]" |
24 | | - exit 1 |
25 | | -fi |
| 22 | +# Start of functions |
26 | 23 |
|
27 | | -export LANG=C |
| 24 | +generate_syscall_file() |
| 25 | +{ |
| 26 | + # $1 - linux file ($linux) |
| 27 | + # $2 - architecture ($arch) |
| 28 | + # $3 - (optional) syscall table symbol name (sys_call_table) |
| 29 | + # $4 - (optional) syscall bit (0 or _X32_SYSCALL_BIT) |
28 | 30 |
|
29 | | -linux="$1" |
30 | | -arch="$(readelf -h "$linux" | sed -ne '/Machine:/{s/^[[:space:]]*Machine:[[:space:]]*//;P}')" |
31 | | -if [ "$arch" = "Advanced Micro Devices X86-64" ]; then |
32 | | - arch="AMD64" |
33 | | -fi |
34 | | -outname="${arch,,}_syscalls.c" |
| 31 | + linux="$1" |
| 32 | + arch="$2" |
| 33 | + SYSCALLTABLENAME="$3" |
| 34 | + SYSCALLBIT="$4" |
| 35 | + |
| 36 | + [ -z "$SYSCALLTABLENAME" ] && SYSCALLTABLENAME="sys_call_table" |
| 37 | + [ -z "$SYSCALLBIT" ] && SYSCALLBIT=0 |
35 | 38 |
|
36 | | -echo -n "Generating syscalls for $arch... " |
| 39 | + echo -n "Generating syscalls for $arch ... " |
| 40 | + outname="${arch,,}_syscalls.c" |
37 | 41 |
|
38 | | -year=$(date +%Y) |
39 | | -cat > "$outname" <<HEADER |
| 42 | + year=$(date +%Y) |
| 43 | + cat > "$outname" <<HEADER |
40 | 44 | /* |
41 | 45 | Kafel - syscalls ($arch) |
42 | 46 | ----------------------------------------- |
@@ -71,26 +75,75 @@ cat > "$outname" <<HEADER |
71 | 75 | const struct syscall_descriptor ${arch,,}_syscall_list[] = { |
72 | 76 | HEADER |
73 | 77 |
|
74 | | -case "$arch" in |
75 | | -ARM) |
76 | | - gdb --batch -ex 'set gnutarget elf32-littlearm' -ex "file $linux" -x extract.py |
77 | | - ;; |
78 | | -*) |
79 | | - gdb --batch -ex "file $linux" -x extract.py |
80 | | - ;; |
81 | | -esac |
82 | | - |
83 | | -if [ -f "missing/${arch,,}.c" ]; then |
84 | | - cat "missing/${arch,,}.c" >> output_syscalls.c |
85 | | -fi |
| 78 | + echo -n "" > output_syscalls.c |
| 79 | + |
| 80 | + |
| 81 | + case "$arch" in |
| 82 | + ARM) |
| 83 | + SYSCALLTABLENAME="$SYSCALLTABLENAME" \ |
| 84 | + SYSCALLBIT=$SYSCALLBIT \ |
| 85 | + "$GDB" --batch \ |
| 86 | + -ex 'set gnutarget elf32-littlearm' \ |
| 87 | + -ex "file $linux" \ |
| 88 | + -x extract.py |
| 89 | + ;; |
| 90 | + *) |
| 91 | + SYSCALLTABLENAME="$SYSCALLTABLENAME" \ |
| 92 | + SYSCALLBIT=$SYSCALLBIT \ |
| 93 | + "$GDB" --batch \ |
| 94 | + -ex "file $linux" \ |
| 95 | + -x extract.py |
| 96 | + ;; |
| 97 | + esac |
86 | 98 |
|
87 | | -cat output_syscalls.c | sort -k1,1 --unique --stable -t',' >> "$outname" |
88 | | -rm output_syscalls.c |
| 99 | + if [ -f "missing/${arch,,}.c" ]; then |
| 100 | + cat "missing/${arch,,}.c" >> output_syscalls.c |
| 101 | + fi |
89 | 102 |
|
90 | | -cat >> "$outname" <<FOOTER |
| 103 | + cat output_syscalls.c | sort -k1,1 --unique --stable -t',' >> "$outname" |
| 104 | + |
| 105 | + rm output_syscalls.c |
| 106 | + |
| 107 | + cat >> "$outname" <<FOOTER |
91 | 108 | }; |
92 | 109 |
|
93 | 110 | const size_t ${arch,,}_syscall_list_size = sizeof(${arch,,}_syscall_list)/sizeof(${arch,,}_syscall_list[0]); |
94 | 111 | FOOTER |
95 | 112 |
|
96 | | -echo "DONE" |
| 113 | + echo "DONE" |
| 114 | +} |
| 115 | + |
| 116 | +# End of functions |
| 117 | + |
| 118 | +# Start of script |
| 119 | + |
| 120 | +if [ $# -ne 1 ] || [ ! -e "$1" -o -d "$1" ]; then |
| 121 | + echo "USAGE: $0 [linux_with_debugging_symbols]" |
| 122 | + exit 1 |
| 123 | +fi |
| 124 | + |
| 125 | +export LANG=C |
| 126 | + |
| 127 | +# For gdb-multiarch or toolchain-provided gdb |
| 128 | + |
| 129 | +[ -z "$GDB" ] && GDB="gdb" |
| 130 | + |
| 131 | +linux="$1" |
| 132 | +arch="$(readelf -h "$linux" | sed -ne '/Machine:/{s/^[[:space:]]*Machine:[[:space:]]*//;P}')" |
| 133 | +class="$(readelf -h "$linux" | sed -ne '/Class:/{s/^[[:space:]]*Class:[[:space:]]*//;P}')" |
| 134 | + |
| 135 | +if [ "$arch" = "Advanced Micro Devices X86-64" ]; then |
| 136 | + arch="AMD64" |
| 137 | +elif [ "$arch" = "Intel 80386" ]; then |
| 138 | + arch="i386" |
| 139 | +elif [ "$arch" = "MIPS R3000" ]; then |
| 140 | + [ "$class" = "ELF32" ] && arch="mipso32" || arch="mips64" |
| 141 | +fi |
| 142 | + |
| 143 | +if [ "$arch" = "AMD64" ]; then |
| 144 | + generate_syscall_file "$linux" amd64 |
| 145 | + generate_syscall_file "$linux" i386 ia32_sys_call_table 0 |
| 146 | + generate_syscall_file "$linux" x32 x32_sys_call_table 1073741824 |
| 147 | +else |
| 148 | + generate_syscall_file "$linux" "$arch" |
| 149 | +fi |
0 commit comments