console: rename console_write to console_putchar

This commit is contained in:
Michael Shaw 2023-11-29 19:33:56 -05:00
commit e2d9609bf7
7 changed files with 109 additions and 11 deletions

View file

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

View file

@ -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;
}

View file

@ -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_ */

View file

@ -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];

View file

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

36
usr.bin/iotest/Makefile Normal file
View file

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

62
usr.bin/iotest/iotest.S Normal file
View file

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