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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

xv6 syscall实验

發布時間:2023/12/9 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 xv6 syscall实验 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Syscall

文章目錄

  • Syscall
    • 一、實驗要求
      • Part One: System call tracing
      • Part Two: Date system call
    • 二、實驗操作
      • Part one
      • Part Two

request

一、實驗要求

Part One: System call tracing

Your first task is to modify the xv6 kernel to print out a line for each system call invocation. It is enough to print the name of the system call and the return value; you don’t need to print the system call arguments.
When you’re done, you should see output like this when booting xv6:

... fork -> 2 exec -> 0 open -> 3 close -> 0 $write -> 1write -> 1

That’s init forking and execing sh, sh making sure only two file descriptors are open, and sh writing the $ prompt. (Note: the output of the shell and the system call trace are intermixed, because the shell uses the write syscall to print its output.)

Hint: modify the syscall() function in syscall.c.
Optional challenge: print the system call arguments.

Part Two: Date system call

Your second task is to add a new system call to xv6. The main point of the exercise is for you to see some of the different pieces of the system call machinery. Your new system call will get the current UTC time and return it to the user program. You may want to use the helper function, cmostime() (defined in lapic.c), to read the real time clock. date.h contains the definition of the struct rtcdate struct, which you will provide as an argument to cmostime() as a pointer.

You should create a user-level program that calls your new date system call; here’s some source you should put in date.c:

#include "types.h" #include "user.h" #include "date.h"int main(int argc, char *argv[]) {struct rtcdate r;if (date(&r)) {printf(2, "date failed\n");exit();}// your code to print the time in any format you like...exit(); }

In order to make your new date program available to run from the xv6 shell, add _date to the UPROGS definition in Makefile.

Your strategy for making a date system call should be to clone all of the pieces of code that are specific to some existing system call, for example the “uptime” system call. You should grep for uptime in all the source files, using *grep -n uptime .[chS].

When you’re done, typing date to an xv6 shell prompt should print the current UTC time.

Write down a few words of explanation for each of the files you had to modify in the process of creating your date system call.

Optional challenge: add a dup2() system call and modify the shell to use it.
*syscall.h:

二、實驗操作

Part one

要實現系統調調用時打印系統調用的名稱和參數,我們需要修改syscall.csyscalll.h文件

然后我們先看一下syscall.c的代碼

// System call numbers #define SYS_fork 1 #define SYS_exit 2 #define SYS_wait 3 #define SYS_pipe 4 #define SYS_read 5 #define SYS_kill 6 #define SYS_exec 7 #define SYS_fstat 8 #define SYS_chdir 9 #define SYS_dup 10 #define SYS_getpid 11 #define SYS_sbrk 12 #define SYS_sleep 13 #define SYS_uptime 14 #define SYS_open 15 #define SYS_write 16 #define SYS_mknod 17 #define SYS_unlink 18 #define SYS_link 19 #define SYS_mkdir 20 #define SYS_close 21

不難看出,這段代碼是對xv6 21個常見系統調用的宏定義,我們要想實現打印調用名稱和參數,可以在syscall.c設置和系統調用的相同的編號和名稱相對應的數組

#include "x86.h" #include "syscall.h"// 以下為添加的內容 static char SYS_call_names[][6] = {[SYS_fork] "fork",[SYS_exit] "exit",[SYS_wait] "wait",[SYS_pipe] "pipe",[SYS_read] "read",[SYS_kill] "kill",[SYS_exec] "exec",[SYS_fstat] "fstat",[SYS_chdir] "chdir",[SYS_dup] "dup",[SYS_getpid] "getpid",[SYS_sbrk] "sbrk",[SYS_sleep] "sleep",[SYS_uptime] "uptime",[SYS_open] "open",[SYS_write] "write",[SYS_mknod] "mknod",[SYS_unlink] "unlink",[SYS_link] "link",[SYS_mkdir] "mkdir",[SYS_close] "close"}; // 以上為添加的內容

然后除此之外還需要修改syscall()函數,使其實現當系統調用時打印對應的名稱和編號

$make qemu (或make qemu-nox) //make qemu-nox是將qemu固定在linux下,在串口終端中啟動Qemu

運行結果如下圖
[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-C5kxiRPK-1571208580659)(partone.png)]

void syscall(void) ····curproc ->tf->eax = syscall[numm](); // 以下為添加的內容cprintf("\tSYS_call: %s\tid: %d\n", SYS_call_names[num], num); // 以上為添加的內容 } else ···

到這里第一個小部分就完成了,這部分其實很簡單就是在syscall調用函數是加入了一句打印代碼使其實現功能

  • 在這沒學過c語言的可能會疑惑是printf的基本語法,我在下面簡單介紹一下:
    首先在這里的**cprintf()我認為和printf()**的基本用法是一樣的。
    printf()函數調用格式:printf(“格式化字符串”,輸出表列)。格式化字符串包含三種對象,為:
    (1)字符串常量
    (2)格式化控制字符串
    (3)轉義字符
    字符串常量原樣輸出,在顯示中起提示作用。輸出表列中給出了各個輸出項,要求格式控制字符串和各輸出項在數量和類型上應該一一對應。其中格式控制字符串是以%開頭的字符串,在%后面跟有各種格式控制符,以說明輸出數據的類型、寬度、精度等。
    格式化控制字符串:
    %[標志][最小寬度][.精度][類型長度]類型
    示例:

    printf("%5d\n",1000); //默認右對齊,左邊補空格output: ` `1000

    常用轉義字符:
    \n :回車符
    \t :橫向制表符
    \v:縱向制表符

Part Two

  • 在各種文件里添加第22個系統調用sys_date
    1.syscall.h:

    #define SYS_date 22

    2.syscall.c:

    [SYS_date] " date" };··· extern int sys_date(void);··· [SYS_date] sys_date

    3.user.h文件添加用戶態函數

    int sleep(int); int uptime(void); // 以下為添加內容 int date(struct rtcdate*); // 以上為添加內容

    4.usys.S添加用戶態函數的實現

    SYSCALL(date)

    5.sysproc.c添加系統調用函數

    int sys_date(struct rtcdate *r) {if (argptr(0, (void *)&r, sizeof(*r)) < 0)return -1;cmostime(r); //從cmos中獲取時間return 0;}

至此,就完成了添加系統調用函數 date()
最后,我們需要添加使用這個系統調用函數的方法
新建文件 date.c ,并添加一下內容

#include "types.h" #include "user.h" #include "date.h"int main(int argc, char *argv[]) {struct rtcdate r;if (date(&r)){printf(2, "date failed\n");exit();}// your code to print the time in any format you like...printf(1, "%d-%d %d %d:%d:%d\n", r.month, r.day, r.year, r.hour, r.minute, r.second);//輸出格式可以隨意定義exit(); }

6.最后不要忘了在MakeFile添加UPROGS對應的命令:

_big\ # 以下為添加內容_date\ # 以上為添加內容
  • 到此就完成了所有程序的修改,然后我們運行
make qemu //然后輸入date $date
  • 但是結果卻并不和預期一樣
    [外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-y0R4MoKv-1571208580662)(parttwo.png)]
    然后我們發現其實這是之前第一部分系統調用造成的,雖然沒有達到我們的預期但是卻能夠清晰的顯現每個輸出的系統調用命令
    然后我們把第一部分的系統調用注釋掉就好了
    [外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-dCvkrWaf-1571208580664)(partthree.png)]
    最后成功的實現了我們的預期!

總結

以上是生活随笔為你收集整理的xv6 syscall实验的全部內容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 无码国产精品一区二区色情男同 | 91精品国自产在线 | 三级国产视频 | 国产成人精品久久二区二区 | 伊人99re | 久久久久久久久一区 | 在线观看日韩中文字幕 | 国产美女福利视频 | 免费看的毛片 | 国产男女无遮挡猛进猛出 | 污网在线看 | 久久精品亚洲a | 在线免费看黄av | 国产精品一卡二卡在线观看 | 日韩美女视频一区 | 久草在| 一区二区三区中文视频 | 国产一区在线不卡 | 国产久草av | 亚洲aⅴ在线观看 | www欧美色| 日本一道本在线 | 国产视频69 | 色婷婷久久五月综合成人 | 亚洲精品一区二区三区四区 | 中文字幕在线播放日韩 | 毛片在哪看 | 亚洲天堂中文字幕在线观看 | 久久黄视频 | 被灌满精子的波多野结衣 | 91干视频| 欧美综合自拍亚洲综合图片区 | 久草91| 秋葵视频污 | 在线观看波多野结衣 | 爱爱15p| 国产做受高潮漫动 | 欧美激情 亚洲 | 狠狠干狠狠艹 | 黄视频免费在线看 | 五月天视频 | 两个人做羞羞的视频 | 鲁一鲁在线 | 呦呦视频在线观看 | 亚洲天堂2015 | 日本一区二区免费电影 | 黄色国产一区 | 免费看久久| 国产精品国产三级国产普通话蜜臀 | 美女扒开让男人桶爽 | 国产激情文学 | 国产一级视频在线 | 人妻天天爽夜夜爽一区二区三区 | 天天影视插插插 | 大香焦久久 | 亚洲人成无码网站久久99热国产 | 婷婷丁香在线 | 免费看成人毛片 | 色大师在线观看 | 东北老女人av | 91黄在线看 | 欧美黄页 | 爱逼av| 午夜999| 欧美日韩1区2区3区 亚洲日本精品视频 | 国产精品夜夜 | 在线免费看黄色片 | 日韩欧美在线免费 | 超碰免费av| 亚洲第9页| 国产三级日本三级在线播放 | 中文字幕亚洲高清 | 国产欧美一区二区三区四区 | 午夜肉伦伦 | 亚洲欧美网址 | 午夜嘿嘿| 国产一区二区在线电影 | 久99精品| 亚洲国产精品久久久久婷蜜芽 | 色播欧美| 日韩一区在线视频 | 欧美日韩性 | 交专区videossex另类 | 久久久久久艹 | 欧美成人免费高清视频 | 欧美成人aaa片一区国产精品 | 黄色a级片视频 | www.毛片.com | 小镇姑娘高清播放视频 | 国产一卡二 | 久久精品牌麻豆国产大山 | 不卡一区二区在线观看 | 国产手机精品视频 | 国产成人在线观看 | 爱逼av | av一级二级 | 三八激情网 | 成人在线不卡视频 | 青在线视频 |