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

backup 2023-05-09
author autobackup
date Tue, 09 May 2023 00:10:03 +0900 (2023-05-08)
parents 171fc32d9b07
children
line wrap: on
line source
# 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
```