xv6修改之輸出系統調用名稱&添加halt系統調用

(原文章手抖 誤刪。。。重新發的)
大部分來自於洋大神哥的:http://yalongyang.com/2012/10/xv6-add-system-call/

題目一:爲系統調用添加輸出

在syscall.c中的,syscall函數改爲

  1. void  
  2. syscall(void){  
  3.    
  4.   int num;  
  5.   num= proc->tf->eax;  
  6.  if(num > 0 && num < NELEM(syscalls) &&syscalls[num]) {  
  7.    proc->tf->eax = syscalls[num]();  
  8.    char* name;  
  9.    switch(num){  
  10.        case 1:  
  11.               name= "fork";  
  12.               break;  
  13.        case 2:  
  14.               name= "exit";  
  15.               break;  
  16.        case 3:  
  17.               name= "wait";  
  18.               break;  
  19.        case 4:  
  20.               name= "pipe";  
  21.               break;  
  22.        case 5:  
  23.               name= "read";  
  24.               break;  
  25.        case 6:  
  26.               name= "kill";  
  27.               break;  
  28.        case 7:  
  29.               name= "exec";  
  30.               break;  
  31.        case 8:  
  32.               name= "fstat";        
  33.               break;  
  34.        case 9:  
  35.               name= "chdir";      
  36.               break;  
  37.        case 10:  
  38.               name= "dup";  
  39.               break;  
  40.        case 11:  
  41.               name= "getpid";     
  42.               break;  
  43.        case 12:  
  44.               name= "sbrk";        
  45.               break;  
  46.        case 13:  
  47.               name= "sleep";       
  48.               break;  
  49.        case 14:  
  50.               name= "uptime";  
  51.               break;  
  52.        case 15:  
  53.               name= "open";      
  54.               break;  
  55.        case 16:  
  56.               name= "write";      
  57.               break;  
  58.        case 17:  
  59.               name= "mknod";    
  60.               break;    
  61.        case 18:  
  62.               name= "unlink";     
  63.               break;    
  64.        case 19:  
  65.               name= "link";        
  66.               break;    
  67.        case 20:  
  68.               name= "medir";     
  69.               break;  
  70.        case 21:  
  71.               name= "close";       
  72.               break;  
  73.        case 22:  
  74.               name= "halt";  
  75.               break;  
  76.        default:  
  77.               panic("Wrong");  
  78.     }  
  79.    cprintf("%s -> %d\n", name, proc->tf->eax);  
  80.   }else {  
  81.    cprintf("%d %s: unknown sys call %d\n",  
  82.            proc->pid, proc->name, num);  
  83.    proc->tf->eax = -1;  
  84.   }  
  85. }  


 

輸出參數,

在fetchint和fetchStr的return正確數前

分別加入

  1. cprintf(”argu: %d\n”, *ip);      

  1. cprintf(”argu: %s\n”, *pp);   

題目二:爲系統添加halt系統調用

模仿uptime系統調用,在xv6 pdf 搜索。加入halt系統調用。

步驟:

1.      syscall.h添加

  1. #define SYS_halt 22  


2.      syscall.c 添加

  1. extern int sys_halt(void);  


並在static int (*syscalls[])(void)中添加

  1. [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聲明

  1. #include"types.h"  
  2. #include"stat.h"  
  3. #include"user.h"  
  4. int halt();  
  5.    
  6. int  
  7. main(int argc,char *argv[])  
  8. {  
  9.   halt();  
  10.   return 0; 
  11. }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章