Mercurial > hg > Document > Growi
changeset 89:171fc32d9b07
backup 2021-09-20
author | autobackup |
---|---|
date | Mon, 20 Sep 2021 00:10:04 +0900 |
parents | fd9f5bb6fb3d |
children | 3126bf6d9978 |
files | user/matac42/xv6-add-call.md |
diffstat | 1 files changed, 107 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/user/matac42/xv6-add-call.md Mon Sep 20 00:10:04 2021 +0900 @@ -0,0 +1,107 @@ +# xv6にsystem callを追加する + +参考: +https://www.geeksforgeeks.org/xv6-operating-system-adding-a-new-system-call/ + +### syscall.cのsyscalls[]に追記 +``` +[SYS_hoge] sys_hoge, +``` + +### syscall.cにexternを追記 +``` +extern uint64 sys_hoge(void); +``` + +### syscall.hに追記 +``` +#define SYS_hoge 22 +``` + +### sysproc.cに実装を追記 +``` +uint64 sys_hoge(void) +{ + return 1; +} +``` + +### user.hに追記 +``` +int hoge(void); +``` + +### usys.plに追記 +``` +entry("hoge"); +``` + +### rebuild & run + +``` +$make clean +$make qemu +``` + +if docker-compose + +``` +$docker-compose down +$docker-compose build +$docker-compose run --name xv6 xv6 +``` + +# xv6にuser programを追加する + +参考: +https://www.geeksforgeeks.org/xv6-operating-system-add-a-user-program/ + +### user/hoge.c(プログラム例) +```c +#include "kernel/types.h" +#include "kernel/stat.h" +#include "user/user.h" + +int main(int argc, char *argv[]) +{ + fprintf(1, "hogehoge\n"); + exit(0); +} +``` + +### MakefileのUPROGSに`$U/_hoge\`を追記 +``` +UPROGS=\ + $U/_cat\ + $U/_echo\ + $U/_forktest\ + $U/_grep\ + $U/_init\ + $U/_kill\ + $U/_ln\ + $U/_ls\ + $U/_mkdir\ + $U/_rm\ + $U/_sh\ + $U/_stressfs\ + $U/_usertests\ + $U/_grind\ + $U/_wc\ + $U/_zombie\ + $U/_hoge\ +``` + +### rebuild & run + +``` +$make clean +$make qemu +``` + +if docker-compose + +``` +$docker-compose down +$docker-compose build +$docker-compose run --name xv6 xv6 +``` \ No newline at end of file