aboutsummaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorMarvin Borner2020-08-21 23:08:16 +0200
committerMarvin Borner2020-08-21 23:08:16 +0200
commit94de27efb7f9f97d162c1cd6b0a2bb89e3fe555f (patch)
treeb2ae93419138cd0af46559b0b1f1a03862d62242 /kernel
parentf700ba6668dbdb91a03b2c5aa387eb4cabae8fcd (diff)
Finished proper return of processes
Diffstat (limited to 'kernel')
-rw-r--r--kernel/features/event.c1
-rw-r--r--kernel/features/fs.c2
-rw-r--r--kernel/features/load.c6
-rw-r--r--kernel/features/proc.c15
-rw-r--r--kernel/features/syscall.c17
-rw-r--r--kernel/inc/proc.h2
6 files changed, 26 insertions, 17 deletions
diff --git a/kernel/features/event.c b/kernel/features/event.c
index 8fafb05..9fd6da2 100644
--- a/kernel/features/event.c
+++ b/kernel/features/event.c
@@ -48,6 +48,7 @@ void event_unmap(enum event id, u32 *func)
u32 event_trigger(enum event id, u32 *data)
{
+ (void)data;
assert(id < sizeof(event_table) / sizeof(*event_table));
struct node *iterator = ((struct list *)event_table[id])->head;
diff --git a/kernel/features/fs.c b/kernel/features/fs.c
index 3c1b849..c328f04 100644
--- a/kernel/features/fs.c
+++ b/kernel/features/fs.c
@@ -116,7 +116,7 @@ void *read_file(char *path)
}
u32 inode = find_inode(path, current_inode);
- if (inode == 0)
+ if ((signed)inode <= 0)
return 0;
return read_inode(get_inode(inode));
diff --git a/kernel/features/load.c b/kernel/features/load.c
index 2f3f65f..1f1c898 100644
--- a/kernel/features/load.c
+++ b/kernel/features/load.c
@@ -13,16 +13,16 @@ int bin_load(char *path, struct proc *proc)
{
char *data = read_file(path);
if (!data)
- return 0;
+ return 1;
- u32 stack = (u32)malloc(0x1000) + 0x1000;
+ u32 stack = (u32)malloc(0x2000) + 0x1000;
proc->regs.ebp = (u32)stack;
proc->regs.esp = (u32)stack;
proc->regs.useresp = (u32)stack;
proc->regs.eip = (u32)data;
strcpy(proc->name, path + 1);
- return 1;
+ return 0;
}
int elf_verify(struct elf_header *h)
diff --git a/kernel/features/proc.c b/kernel/features/proc.c
index 7eb6832..d5c2895 100644
--- a/kernel/features/proc.c
+++ b/kernel/features/proc.c
@@ -30,7 +30,7 @@ void scheduler(struct regs *regs)
while (current->state == PROC_ASLEEP) {
if (!current->next) {
- assert(root->state == PROC_RUNNING || pid > 1);
+ assert(root->state != PROC_ASLEEP || pid > 1);
current = root;
} else {
current = current->next;
@@ -121,15 +121,18 @@ void proc_init()
proc_print();
_eip = root->regs.eip;
- _esp = root->regs.esp;
+ _esp = root->regs.useresp;
- char *args[] = { "init", (char *)boot_passed->vbe, NULL };
+ int argc = 2;
+ char **argv = malloc(sizeof(*argv) * (argc + 1));
+ argv[0] = "init";
+ argv[1] = (char *)boot_passed->vbe;
+ argv[2] = NULL;
- ((u32 *)_esp)[0] = 2; // First argument (argc)
- ((u32 *)_esp)[1] = (u32)args; // Second argument (argv)
+ ((u32 *)_esp)[0] = argc; // First argument (argc)
+ ((u32 *)_esp)[1] = (u32)argv; // Second argument (argv)
proc_jump_userspace();
- printf("Returned!\n");
while (1) {
};
}
diff --git a/kernel/features/syscall.c b/kernel/features/syscall.c
index 02b17e5..ac79fc1 100644
--- a/kernel/features/syscall.c
+++ b/kernel/features/syscall.c
@@ -47,13 +47,18 @@ void syscall_handler(struct regs *r)
printf("exec\n");
char *path = (char *)r->ebx;
struct proc *proc = proc_make();
-
r->eax = bin_load(path, proc);
- ((u32 *)proc->regs.useresp)[0] = 42;
- ((char *)proc->regs.useresp)[1] = r->ecx;
- ((char *)proc->regs.useresp)[2] = r->edx;
- ((char *)proc->regs.useresp)[3] = r->esi;
- ((char *)proc->regs.useresp)[4] = r->edi;
+ int argc = 3; // TODO: Add argc evaluator
+ char **argv = malloc(sizeof(*argv) * (argc + 1));
+ argv[0] = (char *)r->ecx;
+ argv[1] = (char *)r->edx;
+ argv[2] = (char *)r->esi;
+ argv[3] = (char *)r->edi;
+ argv[4] = NULL;
+ ((u32 *)proc->regs.useresp)[0] = argc;
+ ((u32 *)proc->regs.useresp)[1] = (u32)argv;
+ if (r->eax)
+ proc->state = PROC_ERROR;
break;
}
case SYS_EXIT: {
diff --git a/kernel/inc/proc.h b/kernel/inc/proc.h
index 4c6ffaf..b2743a6 100644
--- a/kernel/inc/proc.h
+++ b/kernel/inc/proc.h
@@ -12,7 +12,7 @@
#define GDT_USER_CODE_OFFSET 0x1b // User code segment offset in GDT (with ring3 mask)
#define GDT_USER_DATA_OFFSET 0x23 // User data segment offset in GDT (with ring3 mask)
-enum state { PROC_RUNNING, PROC_ASLEEP };
+enum state { PROC_RUNNING, PROC_ASLEEP, PROC_ERROR };
struct proc {
u32 pid;