89
|
1 # xv6にsystem callを追加する
|
|
2
|
|
3 参考:
|
|
4 https://www.geeksforgeeks.org/xv6-operating-system-adding-a-new-system-call/
|
|
5
|
|
6 ### syscall.cのsyscalls[]に追記
|
|
7 ```
|
|
8 [SYS_hoge] sys_hoge,
|
|
9 ```
|
|
10
|
|
11 ### syscall.cにexternを追記
|
|
12 ```
|
|
13 extern uint64 sys_hoge(void);
|
|
14 ```
|
|
15
|
|
16 ### syscall.hに追記
|
|
17 ```
|
|
18 #define SYS_hoge 22
|
|
19 ```
|
|
20
|
|
21 ### sysproc.cに実装を追記
|
|
22 ```
|
|
23 uint64 sys_hoge(void)
|
|
24 {
|
|
25 return 1;
|
|
26 }
|
|
27 ```
|
|
28
|
|
29 ### user.hに追記
|
|
30 ```
|
|
31 int hoge(void);
|
|
32 ```
|
|
33
|
|
34 ### usys.plに追記
|
|
35 ```
|
|
36 entry("hoge");
|
|
37 ```
|
|
38
|
|
39 ### rebuild & run
|
|
40
|
|
41 ```
|
|
42 $make clean
|
|
43 $make qemu
|
|
44 ```
|
|
45
|
|
46 if docker-compose
|
|
47
|
|
48 ```
|
|
49 $docker-compose down
|
|
50 $docker-compose build
|
|
51 $docker-compose run --name xv6 xv6
|
|
52 ```
|
|
53
|
|
54 # xv6にuser programを追加する
|
|
55
|
|
56 参考:
|
|
57 https://www.geeksforgeeks.org/xv6-operating-system-add-a-user-program/
|
|
58
|
|
59 ### user/hoge.c(プログラム例)
|
|
60 ```c
|
|
61 #include "kernel/types.h"
|
|
62 #include "kernel/stat.h"
|
|
63 #include "user/user.h"
|
|
64
|
|
65 int main(int argc, char *argv[])
|
|
66 {
|
|
67 fprintf(1, "hogehoge\n");
|
|
68 exit(0);
|
|
69 }
|
|
70 ```
|
|
71
|
|
72 ### MakefileのUPROGSに`$U/_hoge\`を追記
|
|
73 ```
|
|
74 UPROGS=\
|
|
75 $U/_cat\
|
|
76 $U/_echo\
|
|
77 $U/_forktest\
|
|
78 $U/_grep\
|
|
79 $U/_init\
|
|
80 $U/_kill\
|
|
81 $U/_ln\
|
|
82 $U/_ls\
|
|
83 $U/_mkdir\
|
|
84 $U/_rm\
|
|
85 $U/_sh\
|
|
86 $U/_stressfs\
|
|
87 $U/_usertests\
|
|
88 $U/_grind\
|
|
89 $U/_wc\
|
|
90 $U/_zombie\
|
|
91 $U/_hoge\
|
|
92 ```
|
|
93
|
|
94 ### rebuild & run
|
|
95
|
|
96 ```
|
|
97 $make clean
|
|
98 $make qemu
|
|
99 ```
|
|
100
|
|
101 if docker-compose
|
|
102
|
|
103 ```
|
|
104 $docker-compose down
|
|
105 $docker-compose build
|
|
106 $docker-compose run --name xv6 xv6
|
|
107 ``` |