日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

xv6 System Call

發布時間:2023/12/9 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。