annotate user/matac42/xv6-add-call.md @ 120:d03247694a4b

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