xv6にsystem callを追加する

xv6にsystem callを追加する

参考: https://www.geeksforgeeks.org/xv6-operating-system-adding-a-new-system-call/

# syscall.cのsyscalls[]に追記

1
[SYS_hoge] sys_hoge,

# syscall.cにexternを追記

1
extern uint64 sys_hoge(void);

# syscall.hに追記

1
#define SYS_hoge 22

# sysproc.cに実装を追記

1
2
3
4
uint64 sys_hoge(void)
{
  return 1;
}

# user.hに追記

1
int hoge(void);

# usys.plに追記

1
entry("hoge");

# rebuild & run

1
2
$make clean
$make qemu

if docker-compose

1
2
3
$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(プログラム例)

1
2
3
4
5
6
7
8
9
#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\を追記

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
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

1
2
$make clean
$make qemu

if docker-compose

1
2
3
$docker-compose down
$docker-compose build
$docker-compose run --name xv6 xv6
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy