From ab1989c9658a86eb12be478075ed7ce6b5ca85e3 Mon Sep 17 00:00:00 2001 From: Michael Shaw Date: Tue, 13 Feb 2024 00:30:19 -0500 Subject: [PATCH] usr.bin: add `vfs` test for device files --- usr.bin/Makefile | 2 +- usr.bin/vfs/Makefile | 42 ++++++++++++++++++++++++++++++++++++++++++ usr.bin/vfs/vfs.S | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 usr.bin/vfs/Makefile create mode 100644 usr.bin/vfs/vfs.S diff --git a/usr.bin/Makefile b/usr.bin/Makefile index a642946..c8857fb 100644 --- a/usr.bin/Makefile +++ b/usr.bin/Makefile @@ -4,7 +4,7 @@ # # Compile all user programs. -UPRG := test1 ftest +UPRG := test1 ftest vfs UPRGCLEAN := $(addsuffix clean,$(UPRG)) UPRGBUILD := $(addsuffix build,$(UPRG)) UPRGINSTALL := $(addsuffix install,$(UPRG)) diff --git a/usr.bin/vfs/Makefile b/usr.bin/vfs/Makefile new file mode 100644 index 0000000..c2310a8 --- /dev/null +++ b/usr.bin/vfs/Makefile @@ -0,0 +1,42 @@ +# SPDX-License-Identifier: GPL-2.0-only + +# usr.bin/test1/Makefile +# +# test1 is the first test program, to be removed later. +# +# This Makefile also serves as a template for other user programs. + +CC := x86_64-elf-gcc +LD := x86_64-elf-ld + +OUT := vfs.elf +CSRC := +SSRC := vfs.S +OBJ := $(CSRC:.c=.o) $(SSRC:.S=.o) +DEP := $(OBJ:.o=.d) + +CFLAGS := -Wall -ffreestanding -mno-mmx -mno-sse2 -mno-sse -m64 -MMD -g +LDFLAGS := -nostdlib -static -m elf_x86_64 + +CURDIR := $(shell pwd | awk -F '/' '{print $$(NF-1),"/",$$NF}' | sed 's/ //g') + +$(OUT): $(OBJ) + @$(LD) $^ $(LDFLAGS) -o $@ + @echo " USR.LD $(CURDIR)/$@" + +-include $(DEP) + +%.o: %.S + @$(CC) $(CFLAGS) -c $< -o $@ + @echo " USR.CC $(CURDIR)/$@" + +%.o: %.c + @$(CC) $(CFLAGS) -c $< -o $@ + @echo " USR.CC $(CURDIR)/$@" + +clean: + @rm -rf $(OUT) $(OBJ) $(DEP) + +install: $(OUT) + @cp $(OUT) ../../bin + @echo " INSTALL $(CURDIR)/$(OUT)" diff --git a/usr.bin/vfs/vfs.S b/usr.bin/vfs/vfs.S new file mode 100644 index 0000000..85ae623 --- /dev/null +++ b/usr.bin/vfs/vfs.S @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +sys_write = 1 +sys_open = 2 +sys_exit = 60 + +.global _start +_start: + movq $sys_open, %rax + movq $tty_file, %rdi + movq $0, %rsi + movq $0, %rdx + int $0x80 + + movq %rax, %rbx + + movq $sys_write, %rax + movq %rbx, %rdi + leaq test_string(%rip), %rsi + movq $test_string_len, %rdx + int $0x80 + + movq $sys_exit, %rax + movq $0, %rdi + int $0x80 +_no_exit: + movq $0, %rbx + jmp _no_exit + +.data +test_string: + .ascii "hello, world\n\n" +test_string_len = . - test_string + +tty_file: + .asciz "/dev/tty"