removed pdclib, strange things were happening..., user shell kinda works now
This commit is contained in:
@@ -4,22 +4,18 @@
|
||||
#include "memory/mm.h"
|
||||
#include "process.h"
|
||||
#include "scheduler.h"
|
||||
#include "kbd.h"
|
||||
|
||||
#include <drivers/vga/vga.h>
|
||||
|
||||
#include <lib/print.h>
|
||||
|
||||
typedef struct registers {
|
||||
uint32_t gs, fs, es, ds; // Pushed manually
|
||||
uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax; // Pushed by pusha
|
||||
uint32_t int_no, err_code; // Pushed manually
|
||||
uint32_t eip, cs, eflags, useresp, ss; // Pushed automatically by CPU
|
||||
} registers_t;
|
||||
|
||||
|
||||
static int32_t sys_exit(int status) {
|
||||
asm volatile("cli");
|
||||
asm volatile("hlt");
|
||||
process_t* task = current_task();
|
||||
task->state = STATE_DEAD;
|
||||
kprintf("Process %d exited with status %d\n", task->pid, status);
|
||||
exit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -35,13 +31,18 @@ static int32_t sys_write(int fd, const void* buf, size_t count) {
|
||||
}
|
||||
|
||||
static int32_t sys_read(int fd, void* buf, size_t count) {
|
||||
if (fd == 0) { // stdin
|
||||
if (fd == 0) {
|
||||
char* cbuf = (char*)buf;
|
||||
size_t bytes_read = 0;
|
||||
|
||||
while (bytes_read < count) {
|
||||
char c = 'r';
|
||||
cbuf[bytes_read++] = c;
|
||||
if (c == '\n') break;
|
||||
kbd_wait();
|
||||
|
||||
if (kbd_ready()) {
|
||||
char c = kbd_read();
|
||||
cbuf[bytes_read++] = c;
|
||||
if (c == '\n') break;
|
||||
}
|
||||
}
|
||||
return bytes_read;
|
||||
}
|
||||
@@ -83,6 +84,12 @@ static int32_t sys_brk(uint32_t new_break) {
|
||||
return current->heap_end;
|
||||
}
|
||||
|
||||
typedef struct registers {
|
||||
uint32_t gs, fs, es, ds; // Pushed manually
|
||||
uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax; // Pushed by pusha
|
||||
uint32_t int_no, err_code; // Pushed manually
|
||||
uint32_t eip, cs, eflags, useresp, ss; // Pushed automatically by CPU
|
||||
} registers_t;
|
||||
int32_t syscall(registers_t* regs) {
|
||||
switch(regs->eax) {
|
||||
case 1: return sys_exit(regs->ebx);
|
||||
|
||||
Reference in New Issue
Block a user