usermode programs can take input using write syscall, made test shell
This commit is contained in:
parent
edcfd676bf
commit
89207af459
4
Makefile
4
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/
|
||||
|
|
19
src/kmain.c
19
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
15
test.a
15
test.a
|
@ -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
31
test.asm
Normal 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
|
Loading…
Reference in New Issue
Block a user