提交 7770d60c 创建 作者: Austin Clements's avatar Austin Clements

Generate syscall numbers and remove hand-written numbers

Now the only thing you need to do to create a new syscall is write the kernel function and put "//SYSCALL" immediately before it. There are only two places we depended on these #defines: forkt and initcode. We now declare symbolic constants for the syscall numbers in sysstubs, which makes forkt just work (though it gets filled in at link time instead of by the preprocessor). For initcode, we now link initcode against sysstubs so it can get these constants.
上级 5ca8b8e0
......@@ -3,7 +3,6 @@
#include "user.h"
#include "fs.h"
#include "fcntl.h"
#include "syscall.h"
#include "traps.h"
#include "pthread.h"
......
// System call numbers
#define SYS_fork 1
#define SYS_exit 2
#define SYS_wait 3
#define SYS_pipe 4
#define SYS_write 5
#define SYS_read 6
#define SYS_close 7
#define SYS_kill 8
#define SYS_exec 9
#define SYS_openat 10
#define SYS_mknod 11
#define SYS_unlink 12
#define SYS_fstat 13
#define SYS_link 14
#define SYS_mkdirat 15
#define SYS_chdir 16
#define SYS_dup 17
#define SYS_getpid 18
#define SYS_sbrk 19
#define SYS_nsleep 20
#define SYS_uptime 21
#define SYS_map 22
#define SYS_unmap 23
#define SYS_halt 24
#define SYS_socket 25
#define SYS_bind 26
#define SYS_listen 27
#define SYS_accept 28
#define SYS_pread 29
#define SYS_async 30
#define SYS_script 31
#define SYS_setfs 32
#define SYS_wqwait 33
#define SYS_setaffinity 34
#define SYS_futex 35
#define SYS_ncount 36 /* total number of system calls */
......@@ -115,13 +115,18 @@ $(O)/kernel/%.o: lib/%.cc
$(O)/kernel/incbin.o: ASFLAGS+=-DMAKE_OUT=$(O)
$(O)/kernel/incbin.o: $(O)/kernel/initcode $(O)/kernel/bootother $(O)/fs.img
# link initcode against sysstubs to get syscall numbers
$(O)/kernel/initcode: TTEXT = 0x1000
$(O)/kernel/initcode: LDEXTRA = $(O)/lib/sysstubs.o
$(O)/kernel/initcode: $(O)/lib/sysstubs.o
$(O)/kernel/bootother: TTEXT = 0x7000
$(O)/kernel/%: kernel/%.S
@echo " CC $@"
$(Q)mkdir -p $(@D)
$(Q)$(CC) $(CFLAGS) -nostdinc -I. -c $< -o $@.o
$(Q)$(LD) $(LDFLAGS) -N -e start -Ttext $(TTEXT) -o $@.out $@.o
$(Q)$(LD) $(LDFLAGS) -N -e start -Ttext $(TTEXT) -o $@.out $@.o $(LDEXTRA)
$(Q)$(OBJCOPY) -S -O binary $@.out $@
$(O)/kernel/asmdefines.S: kernel/asmdefines.c
......
# Initial process execs /init.
#include "syscall.h"
#include "traps.h"
# exec(init, argv)
......
......@@ -6,7 +6,6 @@
#include "queue.h"
#include "proc.hh"
#include "amd64.h"
#include "syscall.h"
#include "cpu.hh"
#include "kmtrace.hh"
......
#include "syscall.h"
#include "traps.h"
# We assume that the kernel follows the amd64 ABI, but not
# that it saves caller-saved registers.
.globl forkt
......
......@@ -20,10 +20,9 @@ def main():
for fname in args:
syscalls.extend(parse(file(fname, "r")))
# Parse syscall numbers
nums = dict(re.findall("#define SYS_([^ ]*) +([0-9]+)", file("include/syscall.h").read()))
for syscall in syscalls:
syscall.num = int(nums[syscall.basename])
# Generate syscall numbers
for n, syscall in enumerate(syscalls):
syscall.num = n + 1
# Output
if options.kvectors:
......@@ -51,6 +50,9 @@ def main():
print
for syscall in syscalls:
print """\
.globl SYS_%(uname)s
SYS_%(uname)s = %(num)d
.globl %(uname)s
%(uname)s:
movq $%(num)d, %%rax""" % syscall.__dict__
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论