diff --git a/usr.bin/utest/Makefile b/usr.bin/utest/Makefile index ee77b57..41fecd5 100644 --- a/usr.bin/utest/Makefile +++ b/usr.bin/utest/Makefile @@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only OUT := utest -UOBJ := utest.o +UOBJ := utest.o syscall.o -include ../Makefile.common diff --git a/usr.bin/utest/syscall.S b/usr.bin/utest/syscall.S new file mode 100644 index 0000000..51d902b --- /dev/null +++ b/usr.bin/utest/syscall.S @@ -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 + diff --git a/usr.bin/utest/utest.c b/usr.bin/utest/utest.c index 24cfbd9..61a134b 100644 --- a/usr.bin/utest/utest.c +++ b/usr.bin/utest/utest.c @@ -1,6 +1,34 @@ /* SPDX-License-Identifier: GPL-2.0-only */ +#include +#include + +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/ttyS0", 0); + if (fd < 0) + goto loop; + + char msg[] = "Hello, userspace!\n"; + write(fd, msg, strlen(msg)); + +loop: while (1) - (void)0; + continue; }