v2 initial commit
This commit is contained in:
parent
2c97dba9f7
commit
d2ef885e8d
118 changed files with 2420 additions and 9320 deletions
|
|
@ -1,36 +0,0 @@
|
|||
|
||||
|
||||
CC := x86_64-elf-gcc
|
||||
LD := x86_64-elf-ld
|
||||
|
||||
OUT := ftest.elf
|
||||
CSRC :=
|
||||
SSRC := ftest.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)"
|
||||
|
|
@ -1,103 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
|
||||
/* ftest/ftest.S
|
||||
*
|
||||
* Test the read and write system calls.
|
||||
*/
|
||||
|
||||
sys_read = 0
|
||||
sys_write = 1
|
||||
sys_open = 2
|
||||
sys_exit = 60
|
||||
|
||||
.macro print text text_size
|
||||
movl $sys_write, %eax
|
||||
movl $1, %edi
|
||||
movq $\text, %rsi
|
||||
movl $\text_size, %edx
|
||||
int $0x80
|
||||
.endm
|
||||
|
||||
.text
|
||||
.global _start
|
||||
_start:
|
||||
/* Open the file */
|
||||
movl $sys_open, %eax
|
||||
movq $filename, %rdi
|
||||
int $0x80
|
||||
|
||||
cmpl $-1, %eax
|
||||
je _error_open
|
||||
|
||||
/* Read the file */
|
||||
movq %rax, %rdi
|
||||
movl $sys_read, %eax
|
||||
movq $buf, %rsi
|
||||
movl $buf_size, %edx
|
||||
int $0x80
|
||||
|
||||
cmpl $-1, %eax
|
||||
je _error_read
|
||||
|
||||
/* Write the file */
|
||||
movl $sys_write, %eax
|
||||
movl $1, %edi
|
||||
movq $buf, %rsi
|
||||
movl $buf_size, %edx
|
||||
int $0x80
|
||||
|
||||
cmpl $-1, %eax
|
||||
je _error_write
|
||||
|
||||
print exit_message exit_message_size
|
||||
movl $0, %edi
|
||||
jmp _exit
|
||||
|
||||
_error_open:
|
||||
pushq %rax
|
||||
print error_open error_open_size
|
||||
popq %rdi
|
||||
jmp _exit
|
||||
|
||||
_error_read:
|
||||
pushq %rax
|
||||
print error_read error_read_size
|
||||
popq %rdi
|
||||
jmp _exit
|
||||
|
||||
_error_write:
|
||||
pushq %rax
|
||||
print error_write error_write_size
|
||||
popq %rdi
|
||||
jmp _exit
|
||||
|
||||
_exit:
|
||||
|
||||
/* Exit */
|
||||
movl $sys_exit, %eax
|
||||
int $0x80
|
||||
|
||||
.data
|
||||
filename:
|
||||
.asciz "test.txt"
|
||||
|
||||
error_open:
|
||||
.asciz "Error opening file\n"
|
||||
error_open_size = . - error_open
|
||||
|
||||
error_read:
|
||||
.asciz "Error reading file\n"
|
||||
error_read_size = . - error_read
|
||||
|
||||
error_write:
|
||||
.asciz "Error writing file\n"
|
||||
error_write_size = . - error_write
|
||||
|
||||
exit_message:
|
||||
.asciz "Exiting successfully\n"
|
||||
exit_message_size = . - exit_message
|
||||
|
||||
.bss
|
||||
buf:
|
||||
.skip 1024
|
||||
buf_size = . - buf
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
usrprog=('ftest' 'test1' 'vfs' 'shtest')
|
||||
|
||||
mkdir -p ../bin
|
||||
for prog in ${usrprog[@]}; do
|
||||
make -C $prog $1 --no-print-directory
|
||||
done
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
# shtest: simple userspace shell test
|
||||
|
||||
CC := x86_64-elf-gcc
|
||||
LD := x86_64-elf-ld
|
||||
|
||||
OUT := shtest.elf
|
||||
CSRC := shtest.c
|
||||
SSRC := syscall.S
|
||||
OBJ := $(CSRC:.c=.o) $(SSRC:.S=.o)
|
||||
DEP := $(OBJ:.o=.d)
|
||||
|
||||
CFLAGS := -Wall -ffreestanding -mno-mmx -mno-sse2 -mno-sse -m64 -MMD
|
||||
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)"
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
/* shtest: simple userland shell test */
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define S_IFIFO 0x1000
|
||||
|
||||
typedef int64_t ssize_t;
|
||||
typedef int64_t pid_t;
|
||||
|
||||
int open(const char *pathname, int flags);
|
||||
ssize_t read(int fd, void *buf, int count);
|
||||
ssize_t write(int fd, void *buf, int count);
|
||||
int close(int fd);
|
||||
pid_t fork();
|
||||
int exit(int status);
|
||||
int mknod(const char *pathname, int mode, int dev);
|
||||
|
||||
void promptfd(int fd)
|
||||
{
|
||||
write(fd, "shtest> ", 8);
|
||||
}
|
||||
|
||||
void _start()
|
||||
{
|
||||
int term = open("/dev/tty0", 0);
|
||||
if (term < 0)
|
||||
exit(1);
|
||||
|
||||
char buf[256];
|
||||
int n;
|
||||
|
||||
/* FIFOs!!!!!!!!! */
|
||||
write(term, "mknod\n", 5);
|
||||
mknod("/dev/pts", S_IFIFO, 0);
|
||||
write(term, "open\n", 5);
|
||||
int fifofd = open("/dev/pts", 0);
|
||||
|
||||
if (fifofd < 0)
|
||||
write(term, "open failed\n", 12);
|
||||
|
||||
/* write hello to fifo */
|
||||
write(term, "write\n", 6);
|
||||
int i = write(fifofd, "hello\n", 6);
|
||||
/* read back from fifo */
|
||||
write(term, "read\n", 5);
|
||||
i = read(fifofd, buf, 6);
|
||||
|
||||
/* print output to terminal */
|
||||
|
||||
write(term, "read back from fifo: ", 22);
|
||||
write(term, buf, i);
|
||||
promptfd(term);
|
||||
|
||||
/* fork test */
|
||||
while ((n = read(term, buf, 256)) > 0) {
|
||||
write(term, buf, n);
|
||||
|
||||
if (buf[0] == 'q')
|
||||
break;
|
||||
}
|
||||
|
||||
exit(1234);
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
/* syscall handler for simple userland shell test */
|
||||
|
||||
#define __ASM__
|
||||
|
||||
.macro _sc_define name, num
|
||||
.global \name
|
||||
\name:
|
||||
movq $\num, %rax
|
||||
movq %rcx, %r10
|
||||
int $0x80
|
||||
ret
|
||||
.endm
|
||||
|
||||
_sc_define read, 0
|
||||
_sc_define write, 1
|
||||
_sc_define open, 2
|
||||
_sc_define close, 3
|
||||
_sc_define fork, 57
|
||||
_sc_define exit, 60
|
||||
_sc_define mknod, 133
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
# 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 := test1.elf
|
||||
CSRC :=
|
||||
SSRC := start.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)"
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
|
||||
/* test1/start.S
|
||||
*
|
||||
* Test the basic functionality of the kernel loader
|
||||
*/
|
||||
|
||||
sys_write = 1
|
||||
sys_exit = 60
|
||||
|
||||
.global _start
|
||||
_start:
|
||||
movl $sys_write, %eax
|
||||
movl $1, %edi
|
||||
movq $test_string, %rsi
|
||||
movl $test_string_len, %edx
|
||||
int $0x80
|
||||
|
||||
movl $sys_exit, %eax
|
||||
movl $0xDEADC0DE, %edi
|
||||
int $0x80
|
||||
_no_exit:
|
||||
movq $0, %rbx
|
||||
jmp _no_exit
|
||||
|
||||
.data
|
||||
test_string:
|
||||
.ascii "hello, world\n\n"
|
||||
test_string_len = . - test_string
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
# 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)"
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
/* 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"
|
||||
Loading…
Reference in a new issue