From 89207af4591031eea08cc29cdd3dbc6689dd1aac Mon Sep 17 00:00:00 2001 From: rami Date: Mon, 27 May 2024 13:59:44 -0500 Subject: [PATCH] usermode programs can take input using write syscall, made test shell --- Makefile | 4 ++++ image.img | Bin 42 -> 96 bytes src/kmain.c | 19 +++++++++++++------ src/ps2.c | 4 +++- test.a | 15 --------------- test.asm | 31 +++++++++++++++++++++++++++++++ 6 files changed, 51 insertions(+), 22 deletions(-) delete mode 100644 test.a create mode 100644 test.asm diff --git a/Makefile b/Makefile index da31ff4..aa84f4f 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,10 @@ $(BUILDDIR)/%.o: */%.asm qemu: kernel qemu-system-i386 $(QEMUFLAGS) +test: kernel + rm image.img + nasm -fbin test.asm -o image.img + iso: kernel cp $(BUILDDIR)/kernel.bin iso/boot/kernel.bin grub-mkrescue -o $(BUILDDIR)/andewOS.iso iso/ diff --git a/image.img b/image.img index c4b85c4db49aaa60cccdc0e7492cf331fe99caa8..d7c664a2f6a99ad8c7bc4d5311793ddffcc41624 100644 GIT binary patch literal 96 zcmWITe7b{?fq`K^5HsxaOkiNx#SCPfZP)=4*bkE0=aT>wWncn}BGe*@zTWftpPd4O YV_r&Xxk7PvW>RKKrb0n}ZeAt>0L57wq5uE@ literal 42 wcmWITe7b{?fq`K^5Hsu(OJHC)+wl6IV_r&Xxk7PvW>RKKrb0n}ZeAt>05ru8*8l(j diff --git a/src/kmain.c b/src/kmain.c index cd67f6e..3614af1 100644 --- a/src/kmain.c +++ b/src/kmain.c @@ -31,14 +31,21 @@ struct stack_frame { void syscall_read(struct stack_frame regs) { uint32_t fd = regs.edi; - // char *buf = (char *)regs.esi; + char *buf = (char *)regs.esi; uint32_t count = regs.edx; - if (fd == FD_STDOUT) { - int pages = count / BLOCK_SIZE; - if (pages == 0) { -// memcpy(buf, stdout.data, count); - } + if (fd == FD_STDIN) { + extern char shell_buffer[512]; + extern int shell_index; + asm volatile ("sti" ::); + + while (shell_buffer[shell_index-1] != '\n') + asm volatile ("pause" ::); + asm volatile ("cli" ::); + + memcpy(buf, shell_buffer, count); + memset(shell_buffer, 0, 512); + shell_index = 0; } } diff --git a/src/ps2.c b/src/ps2.c index 2b1b172..9c29b96 100644 --- a/src/ps2.c +++ b/src/ps2.c @@ -171,6 +171,7 @@ void ps2_handler() { break; case KBD_ENTER: printf("\n"); + /* if (strcmp(shell_buffer, "PINGAS") == 0) { printf("andew pingas detected"); } else if (strcmp(shell_buffer, "HELLO") == 0) { @@ -188,7 +189,8 @@ void ps2_handler() { shell_buffer[i] = 0; } shell_index = 0; - printf("\n$ "); + */ + shell_buffer[shell_index++] = '\n'; break; case KBD_LCTRL: // Handle left control key diff --git a/test.a b/test.a deleted file mode 100644 index a0c3005..0000000 --- a/test.a +++ /dev/null @@ -1,15 +0,0 @@ -[org 0x6000] -[bits 32] -_start: - push ebp - mov ebp, esp - ; Syscall #1 = write - mov eax, 1 - ; File descriptor = stdout - mov edi, 0 - ; ESI = buffer - mov esi, buf - int 0x80 - jmp $ - -buf: db "Andew skibidi pomni", 0 diff --git a/test.asm b/test.asm new file mode 100644 index 0000000..3c50150 --- /dev/null +++ b/test.asm @@ -0,0 +1,31 @@ +[org 0x6000] +[bits 32] +_start: + push ebp + mov ebp, esp +.loop: + ; print shell prompt + mov eax, 1 + mov edi, 0 + mov esi, prompt + mov edx, 3 + int 0x80 + + ; read input + mov eax, 0 + mov edi, 1 + mov esi, buf + mov edx, 512 + int 0x80 + + ; echo what was wrote + mov eax, 1 + mov edi, 0 + mov esi, buf + mov edx, 512 + int 0x80 + + jmp .loop + jmp $ + +prompt: db "> ", 0