diff options
author | Marvin Borner | 2021-03-13 13:33:26 +0100 |
---|---|---|
committer | Marvin Borner | 2021-03-13 13:33:50 +0100 |
commit | 8176351e1a3d1598bedbc007897d530475942275 (patch) | |
tree | d7745b95abf8e7af9cee1fcfc387137f607c735f /kernel/features | |
parent | 606774e6b0e0a2d36139983b85c8675b2228a9ff (diff) |
Nicü
Diffstat (limited to 'kernel/features')
-rw-r--r-- | kernel/features/fs.c | 6 | ||||
-rw-r--r-- | kernel/features/load.c | 6 | ||||
-rw-r--r-- | kernel/features/mm.c | 11 | ||||
-rw-r--r-- | kernel/features/proc.c | 32 | ||||
-rw-r--r-- | kernel/features/syscall.c | 12 |
5 files changed, 34 insertions, 33 deletions
diff --git a/kernel/features/fs.c b/kernel/features/fs.c index 4d19dde..20d00e5 100644 --- a/kernel/features/fs.c +++ b/kernel/features/fs.c @@ -62,13 +62,15 @@ static struct mount_info *vfs_recursive_find(char *path) static struct mount_info *vfs_find_mount_info(const char *path) { - assert(path[0] == '/'); + if (path[0] != '/') + return NULL; return vfs_recursive_find(strdup(path)); } struct device *vfs_find_dev(const char *path) { - assert(path[0] == '/'); + if (path[0] != '/') + return NULL; struct mount_info *m = vfs_find_mount_info(path); if (m->dev->vfs->type == VFS_DEVFS) // TODO: ? return device_get_by_name(path + strlen(m->path) + 1); diff --git a/kernel/features/load.c b/kernel/features/load.c index 4ad2cbf..9e6db79 100644 --- a/kernel/features/load.c +++ b/kernel/features/load.c @@ -13,6 +13,8 @@ int bin_load(const char *path, struct proc *proc) struct stat s = { 0 }; vfs_stat(path, &s); + strcpy(proc->name, path); + struct page_dir *prev; memory_backup_dir(&prev); memory_switch_dir(proc->page_dir); @@ -20,13 +22,11 @@ int bin_load(const char *path, struct proc *proc) u32 size = PAGE_ALIGN_UP(s.size); u32 data = (u32)memory_alloc(proc->page_dir, size, MEMORY_USER | MEMORY_CLEAR); - if (!vfs_read(path, (void *)data, 0, s.size)) { + if (!vfs_read(proc->name, (void *)data, 0, s.size)) { memory_switch_dir(prev); return 1; } - strcpy(proc->name, path); - u32 stack = (u32)memory_alloc(proc->page_dir, PROC_STACK_SIZE, MEMORY_USER | MEMORY_CLEAR); proc->regs.ebp = stack; proc->regs.useresp = stack; diff --git a/kernel/features/mm.c b/kernel/features/mm.c index b5fd33c..bd32683 100644 --- a/kernel/features/mm.c +++ b/kernel/features/mm.c @@ -35,9 +35,9 @@ extern void paging_invalidate_tlb(void); static void page_fault(struct regs *r) { // Check error code - const char *type = (r->err_code & 4) ? "present" : "non-present"; + const char *type = (r->err_code & 1) ? "present" : "non-present"; const char *operation = (r->err_code & 2) ? "write" : "read"; - const char *super = (r->err_code & 1) ? "User" : "Super"; + const char *super = (r->err_code & 4) ? "User" : "Super"; // Check cr2 address u32 vaddr; @@ -446,7 +446,7 @@ static struct memory_range kernel_memory_range(void) return memory_range_around((u32)&kernel_start, (u32)&kernel_end - (u32)&kernel_start); } -void memory_install(struct mem_info *mem_info) +void memory_install(struct mem_info *mem_info, struct vid_info *vid_info) { for (struct mmap_boot *p = mem_info->start; (u32)(p - mem_info->start) < mem_info->size; p++) { @@ -484,8 +484,9 @@ void memory_install(struct mem_info *mem_info) memory_map_identity(&kernel_dir, memory_range_around(STACK_START - STACK_SIZE, STACK_SIZE), MEMORY_NONE); - // TODO: Triple fault prevention? Probably bootloader stuff or something - memory_map_identity(&kernel_dir, memory_range_around(0x7000, 0x1000), MEMORY_NONE); + // Map VBE data + memory_map_identity(&kernel_dir, memory_range_around((u32)vid_info->vbe, 0x1000), + MEMORY_NONE); // Unmap NULL byte/page struct memory_range zero = memory_range(0, PAGE_SIZE); diff --git a/kernel/features/proc.c b/kernel/features/proc.c index e7ddf4b..6bbe894 100644 --- a/kernel/features/proc.c +++ b/kernel/features/proc.c @@ -157,6 +157,9 @@ void proc_yield(struct regs *r) void proc_enable_waiting(u32 id, enum proc_wait_type type) { + struct page_dir *dir_bak; + memory_backup_dir(&dir_bak); + struct proc *proc_bak = proc_current(); if (!proc_bak) return; @@ -179,8 +182,11 @@ void proc_enable_waiting(u32 id, enum proc_wait_type type) struct regs *r = &p->regs; u32 (*func)(u32, u32, u32, u32) = (u32(*)(u32, u32, u32, u32))w->ids[i].func_ptr; - if (w->ids[i].func_ptr) + if (w->ids[i].func_ptr) { + memory_switch_dir(p->page_dir); r->eax = func(r->ebx, r->ecx, r->edx, r->esi); + memory_switch_dir(dir_bak); + } memset(&w->ids[i], 0, sizeof(w->ids[i])); p->wait.id_cnt--; p->state = PROC_RUNNING; @@ -252,6 +258,18 @@ struct proc *proc_make(enum proc_priv priv) return proc; } +void proc_stack_push(struct proc *proc, u32 data) +{ + struct page_dir *prev; + memory_backup_dir(&prev); + memory_switch_dir(proc->page_dir); + + proc->regs.useresp -= sizeof(data); + *(u32 *)proc->regs.useresp = data; + + memory_switch_dir(prev); +} + // TODO: Procfs needs a simpler interface structure (memcmp and everything sucks) static const char *procfs_parse_path(const char **path, u32 *pid) @@ -437,18 +455,6 @@ static u8 procfs_ready(const char *path, struct device *dev) return 1; } -static void proc_stack_push(struct proc *proc, u32 data) -{ - struct page_dir *prev; - memory_backup_dir(&prev); - memory_switch_dir(proc->page_dir); - - proc->regs.useresp -= sizeof(data); - *(u32 *)proc->regs.useresp = data; - - memory_switch_dir(prev); -} - extern void proc_jump_userspace(void); u32 _esp, _eip; diff --git a/kernel/features/syscall.c b/kernel/features/syscall.c index 31cdf5f..dc49d67 100644 --- a/kernel/features/syscall.c +++ b/kernel/features/syscall.c @@ -71,22 +71,14 @@ static void syscall_handler(struct regs *r) char *path = (char *)r->ebx; struct proc *proc = proc_make(PROC_PRIV_NONE); r->eax = (u32)bin_load(path, proc); - u32 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; + // TODO: Reimplement argc,argv + proc_stack_push(proc, 0); if (r->eax) proc_exit(proc, (int)r->eax); proc_yield(r); break; } case SYS_EXIT: { - print("EXIT!\n"); proc_exit(proc_current(), (int)r->ebx); break; } |