xv6 System Call
生活随笔
收集整理的這篇文章主要介紹了
xv6 System Call
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
xv6系統實現System call,本文所實現的功能基于Vmware ubuntu14.04虛擬機
1、配置環境:
[1]安裝虛擬機
[2]sudo apt-get install git
[3]git clone git://github.com/mit-pdos/xv6-public.git
[4]sudo apt-get install libsdl1.2-dev
[5]sudo apt-get install qemu
[6]cd xv6-public
[7]make qemu
運行結果如下圖所示:
2、要求:在進行系統調用時,打印出系統調用的名字和返回值。
??系統調用函數syscall()在syscall.c文件中,只需要修改syscall()函數即可,即在syscall()函數內添加對應的printf語句。 void syscall(void) {int num;num = proc->tf->eax;if(num > 0 && num < NELEM(syscalls) && syscalls[num]) {proc->tf->eax = syscalls[num]();switch (num) {case SYS_fork:cprintf("fork -> ");break;case SYS_exit:cprintf("exit -> ");break;case SYS_wait:cprintf("wait -> ");break;case SYS_pipe:cprintf("pipe -> ");break;case SYS_read:cprintf("read -> ");break;case SYS_kill:cprintf("kill -> ");break;case SYS_exec:cprintf("exec -> ");break;case SYS_fstat:cprintf("fstat -> ");break;case SYS_chdir:cprintf("chdir -> ");break;case SYS_dup:cprintf("dup -> ");break;case SYS_getpid:cprintf("getpid -> ");break;case SYS_sbrk:cprintf("sbrk -> ");break;case SYS_sleep:cprintf("sleep -> ");break;case SYS_uptime:cprintf("uptime -> ");break;case SYS_open:cprintf("open -> ");break;case SYS_write:cprintf("write -> ");break;case SYS_mknod:cprintf("mknod -> ");break;case SYS_unlink:cprintf("unlink -> ");break;case SYS_link:cprintf("link -> ");break;\case SYS_mkdir:cprintf("mkdir -> ");break;case SYS_close:cprintf("close -> ");break;default:panic("should never get here\n");}cprintf("%d\n", proc->tf->eax);} else {cprintf("%d %s: unknown sys call %d\n",proc->pid, proc->name, num);proc->tf->eax = -1;} }
再次運行qemu,出現如圖所示結果:
3、要求:在xv6系統中添加并實現一個date系統調用,用以輸出當前的UTC時間。
??要實現date系統調用主要是添加系統調用號和添加對應的系統調用函數,具體過程可以仿照uptime系統調用的實現。
1) 使用grep命令篩選出出現uptime字樣的文件和文件中所在行號,以便仿照uptime系統調用實現date系統調用:
2) 在syscall.c中添加系統調用函數的外部聲明,共有兩處地方需要添加:
3) 在syscall.h中添加系統調用號:
4) 在sysproc.c中添加系統調用函數sys_date()的實現:
5) 在user.h中添加用戶態函數的定義:
6) 在usys.S中添加用戶態函數的實現:
7) 由于我們還需要在用戶空間來對內核提供的系統命令進行調用,新建用戶程序date.c文件,寫入以下代碼:
8) 修改Makefile:
運行qemu ,調用date:
總結
以上是生活随笔為你收集整理的xv6 System Call的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用RestTemplate时报错jav
- 下一篇: 计算机应用基础案例教程总结,计算机应用基