usr.bin: add vfs test for device files

This commit is contained in:
Michael Shaw 2024-02-13 00:30:19 -05:00
commit ab1989c965
3 changed files with 78 additions and 1 deletions

View file

@ -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))

42
usr.bin/vfs/Makefile Normal file
View file

@ -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)"

35
usr.bin/vfs/vfs.S Normal file
View file

@ -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"