libk  Check-in [9dd8bab2ac]

Overview
Comment:improve syscall collection mechanism
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 9dd8bab2ac00edcb2cdfe587d65add881c347c5369d5027f6fcd1fa23d68ddf2
User & Date: lexi on 2019-08-20 04:04:24
Other Links: manifest | tags
Context
2019-08-20
22:54
reorganize posix assembly code check-in: f85e6a07dd user: lexi tags: trunk
04:04
improve syscall collection mechanism check-in: 9dd8bab2ac user: lexi tags: trunk
03:04
address case where syscall numbers in header derive from deeper includes check-in: 09a1767049 user: lexi tags: trunk
Changes

Modified build.sh from [81c1265d8b] to [5f22a34160].

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
..
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
...
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
...
209
210
211
212
213
214
215











216
217
218
219
220
221

222
223
224
225
226
227

228

229
230
231
232
233
234
235
# APIs depending on the operating system.
# presumably if the user is running a bash
# script there is some degree of posix
# support available, but we might still be
# building for windows from within cygwin
# or whatever
case $os in
	lin|?bsd|and|dar|osx) posix=yes; unix=yes;;
	hai) posix=yes; unix=no;;
	*) posix=no; unix=no;;
esac

case $os.$bits in
	win.32) bin_fmt=win32;;
	win.64) bin_fmt=win64;;
................................................................................

check cc "your C compiler of choice"
check asm "an assembler that takes Intel syntax and nasm-style-macros"
check m4 "the path to your m4 installation"

export build=$(global/build-id.sh)

if test "$p_headers_syscall" = ""; then
	case $os in
		lin) headers_syscall_search=(
				/usr/include/asm/unistd_${bits}.h
				/usr/include/asm-generic/unistd.h
				/usr/include/*-linux-gnu/asm/unistd_${bits}.h
			);;

		fbsd) p_headers_syscall_search=(
				/usr/include/sys/syscall.h
			);;
	esac
fi

if test "$p_headers_errno" = ""; then
	case $os in
		lin) p_headers_errno="${p_headers_errno:-/usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h}";;

		fbsd) p_headers_errno="${p_headers_errno:-/usr/include/errno.h}";;
	esac
fi

for f in "${headers_syscall_search[@]}"; do
	test -e "$f" || continue
	p_headers_syscall="$f"
	say "using syscall headers at $f"
	break;
done

check p_headers_syscall \
	'the location of a header defining your syscall numbers'
check p_headers_errno \
	'the location of a header defining the values of each errno symbol'

macro_compile_env="-Datom_target_arch=$arch -Datom_target_os=$os -Dtarget_posix=$posix -Dtarget_unix=$unix"

if test "$bits" != ""; then
	macro_compile_env="$macro_compile_env -Datom_target_bits=$bits"
fi


if test "$COLORTERM" != ""; then
	announce() {
		test "$verbose" = "silent" && return
		color="$1" cmd="$2"; shift 2;
		printf " → [38;5;$color;1m$cmd"
		for a in "$@"; do
................................................................................
comp_mac() {
	local src=$1
	local output=$2
	local flags=$3
	if test -e "$output"; then
		if test ! "$output" -ot "$src"; then
			return
		fi
	fi
	         $m4 $macro_compile_env -I "$gen" $flags "$src"  > "$output"
	announce 207 $m4 $macro_compile_env -I "$gen" $flags "$src" \> "$output"
	# yes, this is incredibly stupid. if you know a better way, feel
	# free to submit a fix. the problem is there's no way to pass >
	# to report in such a way that it'll do the right thing, and if
	# you just write > it redirects *report's* output, instead of
	# m4's. piece of shit that it is, m4 doesn't have any way to emit
	# output into a fille - stdout only apparently. tl;dr i hate bash.
................................................................................

# get type data
mkdir -p $gen
$cc -D_emit_m4_include arch/typesize.c -o $gen/typesize 
$gen/typesize > gen/typesize.m

# generate syscall tables











case $os in
	lin) grep -h "#define __NR_" $p_headers_syscall | sed 's;^#define __NR_;;' > $gen/calls.tbl;;
	fbsd) grep -h "#define	SYS_" $p_headers_syscall | sed 's;^#define	SYS_;;' | sed 's;[\t ]\+; ;' > $gen/calls.tbl;;
	*) noimpl 'system call table generation';;
esac


cat $p_headers_syscall $gen/calls.tbl | cpp -P |
	awk -f arch/syscall.awk -v out=s >$gen/system_calls.s
cat $p_headers_syscall $gen/calls.tbl | cpp -P |
	awk -f arch/syscall.awk -v out=h >$gen/system_calls.h

# generate errno tables

grep -h "#[ 	]*define[ 	]\+E" $p_headers_errno | sed 's;^#[\t ]*define[\t ]\+\(E[A-Z0-9]\+\).*$;k_platform_error_\1 \1;' > $gen/error_names.tbl

cat $p_headers_errno $gen/error_names.tbl | cpp -P >$gen/error_numbers.tbl
awk -f arch/errtbl.awk <$gen/error_numbers.tbl >$gen/error_table.h

# generate symbol tables for error handling functions
mkdir -p "$out/k"
awk -f global/gen-conds.awk <global/modules >$out/k/internal.egroup.h
awk -f global/gen-ident.awk <global/modules >$gen/internal.ident.c







|







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<








<
<
<
<
<
<
<
<
<








<







 







|

|







 







>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
<
>
|
|
|
|


>
|
>







38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
..
91
92
93
94
95
96
97














98
99
100
101
102
103
104
105









106
107
108
109
110
111
112
113

114
115
116
117
118
119
120
...
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
...
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207

208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# APIs depending on the operating system.
# presumably if the user is running a bash
# script there is some degree of posix
# support available, but we might still be
# building for windows from within cygwin
# or whatever
case $os in
	lin|?bsd|and|dar|osx|nix) posix=yes; unix=yes;;
	hai) posix=yes; unix=no;;
	*) posix=no; unix=no;;
esac

case $os.$bits in
	win.32) bin_fmt=win32;;
	win.64) bin_fmt=win64;;
................................................................................

check cc "your C compiler of choice"
check asm "an assembler that takes Intel syntax and nasm-style-macros"
check m4 "the path to your m4 installation"

export build=$(global/build-id.sh)















if test "$p_headers_errno" = ""; then
	case $os in
		lin) p_headers_errno="${p_headers_errno:-/usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h}";;

		fbsd) p_headers_errno="${p_headers_errno:-/usr/include/errno.h}";;
	esac
fi










check p_headers_errno \
	'the location of a header defining the values of each errno symbol'

macro_compile_env="-Datom_target_arch=$arch -Datom_target_os=$os -Dtarget_posix=$posix -Dtarget_unix=$unix"

if test "$bits" != ""; then
	macro_compile_env="$macro_compile_env -Datom_target_bits=$bits"
fi


if test "$COLORTERM" != ""; then
	announce() {
		test "$verbose" = "silent" && return
		color="$1" cmd="$2"; shift 2;
		printf " → [38;5;$color;1m$cmd"
		for a in "$@"; do
................................................................................
comp_mac() {
	local src=$1
	local output=$2
	local flags=$3
	if test -e "$output"; then
		if test ! "$output" -ot "$src"; then
			return
		fi 
	fi
	             $m4 $macro_compile_env -I "$gen" $flags "$src"  > "$output"
	announce 207 $m4 $macro_compile_env -I "$gen" $flags "$src" \> "$output"
	# yes, this is incredibly stupid. if you know a better way, feel
	# free to submit a fix. the problem is there's no way to pass >
	# to report in such a way that it'll do the right thing, and if
	# you just write > it redirects *report's* output, instead of
	# m4's. piece of shit that it is, m4 doesn't have any way to emit
	# output into a fille - stdout only apparently. tl;dr i hate bash.
................................................................................

# get type data
mkdir -p $gen
$cc -D_emit_m4_include arch/typesize.c -o $gen/typesize 
$gen/typesize > gen/typesize.m

# generate syscall tables
if test $posix = yes; then
	# on posix, we simply abuse CPP to garner a list of syscalls;
	# the file arch/posix_syscalls contains a list of syscalls
	# we wish to import; we use sed to transform this into a form
	# that cpp will fill out for us, producing a table that the
	# awk scripts can handle and turn into a list of constants.
	echo '#include <sys/syscall.h>' > $gen/system_calls.t.1 # this is the magic part
	cat arch/posix_syscalls > $gen/system_calls.t.2
	sed -e 's;^\(.*\)$;\1 SYS_\1;' -i $gen/system_calls.t.2
	cat $gen/system_calls.t.1 $gen/system_calls.t.2 | cpp -P >$gen/system_calls.tbl
else
	case $os in
		# lin) grep -h "#define __NR_" $p_headers_syscall | sed 's;^#define __NR_;;' > $gen/system_calls.tbl;;
		# fbsd) grep -h "#define	SYS_" $p_headers_syscall | sed 's;^#define	SYS_;;' | sed 's;[\t ]\+; ;' > $gen/system_calls.tbl;;
		*) noimpl 'system call table generation';;
	esac

fi
# cat $p_headers_syscall $gen/system_calls.tbl | cpp -P |
awk -f arch/syscall.awk -v out=s <$gen/system_calls.tbl>$gen/system_calls.s
# cat $p_headers_syscall $gen/system_calls.tbl | cpp -P |
awk -f arch/syscall.awk -v out=h <$gen/system_calls.tbl>$gen/system_calls.h

# generate errno tables
grep -h "#[ 	]*define[ 	]\+E" $p_headers_errno |
	sed 's;^#[\t ]*define[\t ]\+\(E[A-Z0-9]\+\).*$;k_platform_error_\1 \1;' >\
	$gen/error_names.tbl
cat $p_headers_errno $gen/error_names.tbl | cpp -P >$gen/error_numbers.tbl
awk -f arch/errtbl.awk <$gen/error_numbers.tbl >$gen/error_table.h

# generate symbol tables for error handling functions
mkdir -p "$out/k"
awk -f global/gen-conds.awk <global/modules >$out/k/internal.egroup.h
awk -f global/gen-ident.awk <global/modules >$gen/internal.ident.c