forked from wrippin/xv6-udo
/
gensyscalls.pl
executable file
·102 lines (99 loc) · 2.34 KB
/
gensyscalls.pl
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/perl -w
# Generate syscall.h, syscalltable.h or usys.S. These are the header and assembly
# files for system calls.
#
# Generating these files from one script avoids them getting out of sync.
#
# Specify an argument of -h to generate syscall.h
# Specify an argument of -c to generate syscalltable.h
# Specify an argument of -a to generate usys.S
#
# Note that you also need to update user.h with the declarations for these functions that
# user programs will use. This ensures that the C compiler generates the correct code to
# push the parameters on to the stack.
my @syscalls = (
"fork",
"exit",
"wait",
"pipe",
"read",
"kill",
"exec",
"fstat",
"chdir",
"dup",
"getpid",
"sbrk",
"sleep",
"uptime",
"open",
"write",
"mknod",
"unlink",
"link",
"mkdir",
"close",
"getch"
);
my $i;
if ($#ARGV == -1)
{
print 'Error: No argument supplied to gensyscalls.pl';
exit(1);
}
if (($ARGV[0] ne '-h') && ($ARGV[0] ne '-a') && ($ARGV[0] ne '-c'))
{
print 'Error: Invalid argument to gensyscalls.pl';
exit(1);
}
if ($ARGV[0] eq '-h'|| $ARGV[0] eq '-c')
{
print "// Generated by gensyscalls.pl. Do not edit.\n";
print "// To change syscall numbers or add new syscalls, edit gensyscalls.pl\n";
print "\n";
}
else
{
print "# Generated by gensyscalls.pl. Do not edit.\n";
print "# To change syscall numbers or add new syscalls, edit gensyscalls.pl\n";
print "\n";
}
for ($i = 0; $i < scalar(@syscalls); $i++)
{
my $index = $i + 1;
if ($ARGV[0] eq '-h')
{
print "#define SYS_$syscalls[$i]\t\t$index\n";
}
elsif ($ARGV[0] eq '-c')
{
print "extern int sys_$syscalls[$i](void);\n";
}
}
if ($ARGV[0] eq '-a')
{
print "#include \"syscall.h\"\n";
print "#include \"traps.h\"\n";
print "\n";
print "#define SYSCALL(name) \\\n";
print ".globl name; \\\n";
print "name: \\\n";
print "\tmovl\t\$SYS_ ## name, \%eax; \\\n";
print "\tint\t\$T_SYSCALL; \\\n";
print "\tret\n";
print "\n";
for ($i = 0; $i < scalar(@syscalls); $i++)
{
print "SYSCALL($syscalls[$i])\n";
}
}
elsif ($ARGV[0] eq '-c')
{
print "\n";
print "static int(*syscalls[])(void) = {\n";
for ($i = 0; $i < scalar(@syscalls); $i++)
{
print "[SYS_$syscalls[$i]]\tsys_$syscalls[$i],\n";
}
print "};\n"
}