(原文章手抖 誤刪。。。重新發的)
大部分來自於洋大神哥的:http://yalongyang.com/2012/10/xv6-add-system-call/
題目一:爲系統調用添加輸出
在syscall.c中的,syscall函數改爲
- void
- syscall(void){
- int num;
- num= proc->tf->eax;
- if(num > 0 && num < NELEM(syscalls) &&syscalls[num]) {
- proc->tf->eax = syscalls[num]();
- char* name;
- switch(num){
- case 1:
- name= "fork";
- break;
- case 2:
- name= "exit";
- break;
- case 3:
- name= "wait";
- break;
- case 4:
- name= "pipe";
- break;
- case 5:
- name= "read";
- break;
- case 6:
- name= "kill";
- break;
- case 7:
- name= "exec";
- break;
- case 8:
- name= "fstat";
- break;
- case 9:
- name= "chdir";
- break;
- case 10:
- name= "dup";
- break;
- case 11:
- name= "getpid";
- break;
- case 12:
- name= "sbrk";
- break;
- case 13:
- name= "sleep";
- break;
- case 14:
- name= "uptime";
- break;
- case 15:
- name= "open";
- break;
- case 16:
- name= "write";
- break;
- case 17:
- name= "mknod";
- break;
- case 18:
- name= "unlink";
- break;
- case 19:
- name= "link";
- break;
- case 20:
- name= "medir";
- break;
- case 21:
- name= "close";
- break;
- case 22:
- name= "halt";
- break;
- default:
- panic("Wrong");
- }
- cprintf("%s -> %d\n", name, proc->tf->eax);
- }else {
- cprintf("%d %s: unknown sys call %d\n",
- proc->pid, proc->name, num);
- proc->tf->eax = -1;
- }
- }
輸出參數,
在fetchint和fetchStr的return正確數前
分別加入
- cprintf(”argu: %d\n”, *ip);
- cprintf(”argu: %s\n”, *pp);
題目二:爲系統添加halt系統調用
模仿uptime系統調用,在xv6 pdf 搜索。加入halt系統調用。
步驟:
1. syscall.h添加
- #define SYS_halt 22
2. syscall.c 添加
- extern int sys_halt(void);
並在static int (*syscalls[])(void)中添加
- [SYS_halt] sys_halt,
3. Makefile中的UPROGS 後添加 _halt\
4. usys.S中添加SYSCALL(halt)
5. sysproc.c中添加sys_halt定義
int
sys_halt(void)
{
char *p = "Shutdown";
for( ; *p; p++)
outb(0x8900, *p);
}
6. 添加halt.c文件,加一句 halt聲明
- #include"types.h"
- #include"stat.h"
- #include"user.h"
- int halt();
- int
- main(int argc,char *argv[])
- {
- halt();
-
return 0;
-
}