utest: rename utest to init
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
11bedfe3a8
commit
5a67532500
7 changed files with 7 additions and 5 deletions
1
usr.bin/init/.gitignore
vendored
Normal file
1
usr.bin/init/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
utest
|
||||
4
usr.bin/init/Makefile
Normal file
4
usr.bin/init/Makefile
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
OUT := init
|
||||
UOBJ := init.o syscall.o
|
||||
-include ../Makefile.common
|
||||
35
usr.bin/init/init.c
Normal file
35
usr.bin/init/init.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef uint64_t off_t;
|
||||
|
||||
int open(const char *path, int flags);
|
||||
int close(int fd);
|
||||
int read(int fd, void *buf, size_t nbyte);
|
||||
int write(int fd, void *buf, size_t nbyte);
|
||||
int pread(int fd, void *buf, size_t nbyte, off_t offset);
|
||||
int pwrite(int fd, void *buf, size_t nbyte, off_t offset);
|
||||
|
||||
size_t strlen(const char *c)
|
||||
{
|
||||
const char *b = c;
|
||||
while (*b)
|
||||
b++;
|
||||
return b - c;
|
||||
}
|
||||
|
||||
void _start()
|
||||
{
|
||||
int fd = open("/dev/broadcast", 0);
|
||||
if (fd < 0)
|
||||
while (1)
|
||||
;
|
||||
|
||||
char msg[] = "Hello, userspace!\n";
|
||||
write(fd, msg, strlen(msg));
|
||||
close(fd);
|
||||
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
22
usr.bin/init/syscall.S
Normal file
22
usr.bin/init/syscall.S
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
.intel_syntax noprefix
|
||||
|
||||
.macro syscall_define name no
|
||||
.global \name
|
||||
\name:
|
||||
mov rax, \no
|
||||
mov r10, rcx
|
||||
call syscall
|
||||
ret
|
||||
.endm
|
||||
|
||||
.global syscall
|
||||
syscall:
|
||||
mov r10, rcx
|
||||
syscall
|
||||
ret
|
||||
|
||||
syscall_define read 0
|
||||
syscall_define write 1
|
||||
syscall_define open 2
|
||||
syscall_define close 3
|
||||
|
||||
Loading…
Reference in a new issue