usermode programs can take input using write syscall, made test shell

This commit is contained in:
rami 2024-05-27 13:59:44 -05:00
parent edcfd676bf
commit 89207af459
6 changed files with 51 additions and 22 deletions

View File

@ -36,6 +36,10 @@ $(BUILDDIR)/%.o: */%.asm
qemu: kernel qemu: kernel
qemu-system-i386 $(QEMUFLAGS) qemu-system-i386 $(QEMUFLAGS)
test: kernel
rm image.img
nasm -fbin test.asm -o image.img
iso: kernel iso: kernel
cp $(BUILDDIR)/kernel.bin iso/boot/kernel.bin cp $(BUILDDIR)/kernel.bin iso/boot/kernel.bin
grub-mkrescue -o $(BUILDDIR)/andewOS.iso iso/ grub-mkrescue -o $(BUILDDIR)/andewOS.iso iso/

BIN
image.img

Binary file not shown.

View File

@ -31,14 +31,21 @@ struct stack_frame {
void syscall_read(struct stack_frame regs) { void syscall_read(struct stack_frame regs) {
uint32_t fd = regs.edi; uint32_t fd = regs.edi;
// char *buf = (char *)regs.esi; char *buf = (char *)regs.esi;
uint32_t count = regs.edx; uint32_t count = regs.edx;
if (fd == FD_STDOUT) { if (fd == FD_STDIN) {
int pages = count / BLOCK_SIZE; extern char shell_buffer[512];
if (pages == 0) { extern int shell_index;
// memcpy(buf, stdout.data, count); 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;
} }
} }

View File

@ -171,6 +171,7 @@ void ps2_handler() {
break; break;
case KBD_ENTER: case KBD_ENTER:
printf("\n"); printf("\n");
/*
if (strcmp(shell_buffer, "PINGAS") == 0) { if (strcmp(shell_buffer, "PINGAS") == 0) {
printf("andew pingas detected"); printf("andew pingas detected");
} else if (strcmp(shell_buffer, "HELLO") == 0) { } else if (strcmp(shell_buffer, "HELLO") == 0) {
@ -188,7 +189,8 @@ void ps2_handler() {
shell_buffer[i] = 0; shell_buffer[i] = 0;
} }
shell_index = 0; shell_index = 0;
printf("\n$ "); */
shell_buffer[shell_index++] = '\n';
break; break;
case KBD_LCTRL: case KBD_LCTRL:
// Handle left control key // Handle left control key

15
test.a
View File

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

31
test.asm Normal file
View File

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