aboutsummaryrefslogtreecommitdiff
blob: 0bb53b12cd11cfe10135e06ad2980444dd7a53bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Read the symbols list and create regexs to use for processing readelf output.
function read_symbols() {
	COUNT = 0;
	while ((getline line < SYMBOLS_FILE) > 0) {
		if (line ~ /^ *#/ || line ~ /^$/)
			continue;
		nfields = split(line, fields);
		symbol = fields[1];
		syscall = nfields > 1 ? fields[2] : symbol;

		c = ++COUNT
		SYMBOLS[c] = symbol;
		SYSCALLS[c] = syscall;
	}
}

BEGIN {
	read_symbols();

	if (MODE == "gen") {
		for (x in SYSCALLS) {
			print "SB_" SYMBOLS[x] " = SYS_" SYSCALLS[x];
		}
		exit(0);
	}
}

function out(name, syscall, val)
{
	uname = toupper(name)
	syscall_define = "SB_SYS" syscall_prefix "_" uname
	print "#define " syscall_define " " val;
	if (name == syscall)
		print "S(" uname ")";
	else
		print "{ " syscall_define ", SB_NR_" uname ", \"" uname "\" },";
}

{
	# found:     SB_func = <something>
	# not found: SB_func = SYS_func
	if ($1 !~ /^SB_/)
		next;
	if ($3 ~ /^SYS_/)
		next;

	sub(/^SB_/, "", $1);
	name = $1
	# accept everything after the "=" in case it's either
	# a straight number or an expression (a syscall base)
	sub(/^[^=]*= /, "");

	syscall = "<awk_script_error>";
	for (i = 1; i <= COUNT; ++i) {
		if (SYMBOLS[i] == name) {
			FOUND[i] = 1;
			syscall = SYSCALLS[i];
			break;
		}
	}

	out(name, syscall, $0);
}

END {
	if (MODE != "gen") {
		for (x in SYMBOLS) {
			if (!FOUND[x])
				out(SYMBOLS[x], SYSCALLS[x], "SB_NR_UNDEF");
		}
	}
}