diff options
-rw-r--r-- | apps/Makefile | 3 | ||||
-rw-r--r-- | apps/init.c | 9 | ||||
-rw-r--r-- | apps/wm.c | 9 | ||||
-rw-r--r-- | kernel/features/event.c | 1 | ||||
-rw-r--r-- | kernel/features/fs.c | 2 | ||||
-rw-r--r-- | kernel/features/load.c | 6 | ||||
-rw-r--r-- | kernel/features/proc.c | 15 | ||||
-rw-r--r-- | kernel/features/syscall.c | 17 | ||||
-rw-r--r-- | kernel/inc/proc.h | 2 | ||||
-rw-r--r-- | libc/crt/crt0.asm | 2 | ||||
-rw-r--r-- | libc/crt/crti.asm | 13 | ||||
-rw-r--r-- | libc/crt/crtn.asm | 9 |
12 files changed, 37 insertions, 51 deletions
diff --git a/apps/Makefile b/apps/Makefile index 17af36a..194d7df 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -7,7 +7,7 @@ OC = ../cross/opt/bin/i686-elf-objcopy # Flags to make the binary smaller TODO: Remove after indirect pointer support! # TODO: Fix optimization flags (relocation of functions) -CSFLAGS = -mpreferred-stack-boundary=2 -fno-asynchronous-unwind-tables -O0 +CSFLAGS = -mpreferred-stack-boundary=2 -fno-asynchronous-unwind-tables -Os CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -fno-builtin -mgeneral-regs-only -std=c99 -m32 -pedantic-errors -I../libc/inc/ -I../libgui/inc/ -fPIE -Duserspace @@ -18,6 +18,7 @@ all: $(COBJS) @$(CC) -c $(CFLAGS) $< -o $@ @$(LD) -o $(@:.o=.elf) -Tlink.ld -L../build/ $@ -lc -lgui @$(OC) -O binary $(@:.o=.elf) ../build/apps/$(@:.o=) +# @cp $(@:.o=.elf) ../build/apps/$(@:.o=.dbg) # %.o: %.c # @mkdir -p ../build/apps/ diff --git a/apps/init.c b/apps/init.c index 64fbde3..07977ee 100644 --- a/apps/init.c +++ b/apps/init.c @@ -10,12 +10,9 @@ int main(int argc, char **argv) { - (void)argc; - printf("ARGC: %d\n", argc); - printf("ARGV: %x\n", argv); - printf("%s loaded.\n", argv[0]); + printf("[%s loaded]\n", argv[0]); - exec("/wm", "wm", argv[1], NULL); - return 0; + int wm = exec("/wm", "wm", argv[1], NULL); + return wm; } @@ -18,10 +18,11 @@ void onkey(u32 scancode) int main(int argc, char **argv) { + printf("ARGC: %d\n", argc); + printf("[%s loaded]\n", argv[0]); + struct vbe *vbe = (struct vbe *)argv[1]; - printf("%x\n", argc); - printf("%s loaded.\n", argv[0]); printf("VBE: %dx%d\n", vbe->width, vbe->height); const u32 color[3] = { 0, 0, 0 }; @@ -30,8 +31,8 @@ int main(int argc, char **argv) gui_init("/font/spleen-16x32.psfu"); gui_write(vbe, 50, 50, text, "hallo"); - /* printf("onkey: %x\n", onkey); */ - /* map(EVENT_KEYBOARD, onkey); */ + printf("onkey: %x\n", onkey); + map(EVENT_KEYBOARD, onkey); while (1) { }; 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; diff --git a/libc/crt/crt0.asm b/libc/crt/crt0.asm index 4d473ec..5e3080f 100644 --- a/libc/crt/crt0.asm +++ b/libc/crt/crt0.asm @@ -9,7 +9,7 @@ global _start _start: call main - push edi + push eax push 6 call sys1 jmp $ diff --git a/libc/crt/crti.asm b/libc/crt/crti.asm deleted file mode 100644 index 394aaea..0000000 --- a/libc/crt/crti.asm +++ /dev/null @@ -1,13 +0,0 @@ -; MIT License, Copyright (c) 2020 Marvin Borner - -section .init -global _init -_init: - push ebp - mov ebp, esp - -section .fini -global _fini -fini: - push ebp - mov ebp, esp diff --git a/libc/crt/crtn.asm b/libc/crt/crtn.asm deleted file mode 100644 index f20ec6a..0000000 --- a/libc/crt/crtn.asm +++ /dev/null @@ -1,9 +0,0 @@ -; MIT License, Copyright (c) 2020 Marvin Borner - -section .init - pop ebp - ret - -section .fini - pop ebp - ret |