diff --git a/dev/console.c b/dev/console.c index e07e5b9..b4fd698 100644 --- a/dev/console.c +++ b/dev/console.c @@ -66,14 +66,14 @@ void console_input(char c) { if (!console.resizemode) { if (is_printable(c)) { - console_write(c); + console_putchar(c); if (console.l_line < (sizeof(console.line) - 1)) { console.line[console.l_line] = c; console.l_line++; } } else if (c == '\n' || c == '\r') { - console_write('\n'); + console_putchar('\n'); if (strlen(console.line) >= 4 && !memcmp("exec", console.line, 4)) { /* because this one doesn't return. i know it's bad, it will be changed later */ void lapic_eoi(); @@ -90,9 +90,9 @@ void console_input(char c) console.l_line = 0; } else if (c == 0x7F || c == '\b') { if (console.l_line > 0) { - console_write('\b'); - console_write(' '); - console_write('\b'); + console_putchar('\b'); + console_putchar(' '); + console_putchar('\b'); console.l_line--; console.line[console.l_line] = 0; } @@ -127,13 +127,13 @@ void console_input(char c) } } -void console_write(char c) +void console_putchar(char c) { if (!console.resizemode) { if (c == '\n') console.cursorpos = 0; if (console.cursorpos == console.cols && c != '\n') - console_write('\n'); + console_putchar('\n'); console.cursorpos++; } serial_write(c); diff --git a/fs/stdio_ops.c b/fs/stdio_ops.c index 2172972..10763ad 100644 --- a/fs/stdio_ops.c +++ b/fs/stdio_ops.c @@ -9,7 +9,7 @@ int stdout_write(struct file_descriptor *fdesc, void *buf, size_t len) { int i; for (i = 0; i < len; i++) { - console_write(((char *)buf)[i]); + console_putchar(((char *)buf)[i]); } return i; } diff --git a/include/dev/console.h b/include/dev/console.h index b9868dc..13e7c12 100644 --- a/include/dev/console.h +++ b/include/dev/console.h @@ -10,7 +10,7 @@ void console_resize(); void console_input(char c); void console_clear(); bool console_ready(); -void console_write(char c); +void console_putchar(char c); #endif /* __ASM__ */ #endif /* _CONSOLE_H_ */ diff --git a/init/cmd.c b/init/cmd.c index 57225cc..e933ae8 100644 --- a/init/cmd.c +++ b/init/cmd.c @@ -99,7 +99,7 @@ int kcmd_cat(int argc, char **argv) } for (int i = 0; i < n; i++) { - console_write(buf[i]); + console_putchar(buf[i]); } lastchar = buf[n - 1]; diff --git a/lib/stdio.c b/lib/stdio.c index 0e3f4c7..3c268e6 100644 --- a/lib/stdio.c +++ b/lib/stdio.c @@ -8,7 +8,7 @@ spinlock_t printf_lock = 0; static inline void printf_out(char c) { - console_write(c); + console_putchar(c); } static int printf_write(const char *restrict s) diff --git a/usr.bin/iotest/Makefile b/usr.bin/iotest/Makefile new file mode 100644 index 0000000..3ab003b --- /dev/null +++ b/usr.bin/iotest/Makefile @@ -0,0 +1,36 @@ +# SPDX-License-Identifier: GPL-2.0-only + +CC := x86_64-elf-gcc +LD := x86_64-elf-ld + +OUT := iotest.elf +CSRC := +SSRC := iotest.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/iotest/iotest.S b/usr.bin/iotest/iotest.S new file mode 100644 index 0000000..db7e0fc --- /dev/null +++ b/usr.bin/iotest/iotest.S @@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +/* ftest/ftest.S + * + * Test the read and write system calls. + */ + +sys_read = 0 +sys_write = 1 +sys_exit = 60 + +STDIN_FILENO = 0 +STDOUT_FILENO = 1 + +.macro print text text_size + movl $sys_write, %eax + movl $STDOUT_FILENO, %edi + movq $\text, %rsi + movl $\text_size, %edx + int $0x80 +.endm + +.text +.global _start +_start: +_exit: + print entry_message entry_message_size + + movl $sys_read, %eax + movl $STDIN_FILENO, %edi + movq $buf, %rsi + movl $buf_size, %edx + int $0x80 + + movq %rax, %rdx + movl $sys_write, %eax + movl $STDOUT_FILENO, %edi + movq $buf, %rsi + int $0x80 + + movq %rax, %rdx + movl $sys_write, %eax + movl $STDOUT_FILENO, %edi + movq $buf, %rsi + int $0x80 + + movl $sys_exit, %eax + movl $0, %edi + int $0x80 +.data +entry_message: + .ascii "Please enter your text: " +entry_message_size = . - entry_message + +exit_message: + .ascii "Exiting successfully\n" +exit_message_size = . - exit_message + +.bss +buf: + .skip 1024 +buf_size = . - buf