diff options
-rw-r--r-- | src/kernel/fs/elf.c | 22 | ||||
-rw-r--r-- | src/kernel/fs/elf.h | 3 | ||||
-rw-r--r-- | src/kernel/gdt/gdt.c | 5 | ||||
-rw-r--r-- | src/kernel/tasks/process.c | 21 | ||||
-rw-r--r-- | src/kernel/tasks/userspace.asm | 1 |
5 files changed, 28 insertions, 24 deletions
diff --git a/src/kernel/fs/elf.c b/src/kernel/fs/elf.c index f6cdecb..ec4bcc0 100644 --- a/src/kernel/fs/elf.c +++ b/src/kernel/fs/elf.c @@ -12,7 +12,7 @@ #include <system.h> #include <tasks/process.h> -int is_elf(struct elf_header *header) +int elf_verify(struct elf_header *header) { if (header->ident[0] == ELF_MAG && header->ident[1] == 'E' && header->ident[2] == 'L' && header->ident[3] == 'F' && header->ident[4] == ELF_32 && @@ -35,7 +35,7 @@ struct process *elf_load(char *path) struct elf_header *header = (struct elf_header *)file; - if (!is_elf(header)) { + if (!elf_verify(header)) { warn("File not valid: %s", path); return NULL; } else { @@ -49,14 +49,19 @@ struct process *elf_load(char *path) u32 image_high = 0; // Parse ELF + u32 j = 0; for (u32 i = 0; i < header->shentsize * header->shnum; i += header->shentsize) { struct elf_section_header *sh = (void *)header + (header->shoff + i); if (sh->addr != 0) { log("%x", sh->addr); - for (u32 j = 0; j < sh->size; j += PAGE_SIZE) { + /* for (u32 j = 0; j < sh->size; j += PAGE_SIZE) { */ + /* paging_frame_alloc(paging_get_page(sh->addr + j, proc->cr3)); */ + /* invlpg(sh->addr + j); */ + /* } */ + while (j < sh->size) { paging_frame_alloc(paging_get_page(sh->addr + j, proc->cr3)); invlpg(sh->addr + j); - j += PAGE_SIZE; + j += 0x1000; } if (sh->type == 8) // Is .bss @@ -73,16 +78,17 @@ struct process *elf_load(char *path) } // Stack - struct page_table_entry *stack_page = paging_get_page(0x400000, proc->cr3); + struct page_table_entry *stack_page = paging_get_page(USER_STACK_LOW, proc->cr3); paging_frame_alloc(stack_page); stack_page->writable = 1; - invlpg(0x400000); + invlpg(USER_STACK_LOW); strcpy(proc->name, path); proc->brk = image_high; + proc->regs.useresp = USER_STACK_HIGH; + proc->regs.ebp = proc->regs.useresp; + proc->regs.esp = proc->regs.useresp; proc->regs.eip = header->entry; - proc->regs.esp = 0x401000; - proc->regs.useresp = 0x401000; return proc; }
\ No newline at end of file diff --git a/src/kernel/fs/elf.h b/src/kernel/fs/elf.h index f9a3562..94a3863 100644 --- a/src/kernel/fs/elf.h +++ b/src/kernel/fs/elf.h @@ -28,6 +28,9 @@ #define PF_W 0x2 #define PF_R 0x4 +#define USER_STACK_LOW 0x00400000 +#define USER_STACK_HIGH 0x00401000 + struct elf_priv_data { u32 sig; }; diff --git a/src/kernel/gdt/gdt.c b/src/kernel/gdt/gdt.c index 8014756..f201f19 100644 --- a/src/kernel/gdt/gdt.c +++ b/src/kernel/gdt/gdt.c @@ -18,7 +18,7 @@ struct gdt_ptr { void *base; } __attribute__((packed)); -struct gdt_entry gdt[8]; +struct gdt_entry gdt[6]; struct gdt_ptr gp; struct tss_entry_struct { @@ -95,9 +95,6 @@ void gdt_install() // Write TSS tss_write(5, 0x10, stack_hold); - gdt_set_gate(6, 0, 0xFFFFF, 0x92, 0x0); - gdt_set_gate(7, 0, 0xFFFFF, 0x9A, 0x0); - // Remove old GDT and install the new changes! gdt_flush(); tss_flush(); diff --git a/src/kernel/tasks/process.c b/src/kernel/tasks/process.c index a4c1c79..ee657c4 100644 --- a/src/kernel/tasks/process.c +++ b/src/kernel/tasks/process.c @@ -24,15 +24,14 @@ void scheduler(struct regs *regs) static int locked = 0; spinlock(&locked); - serial_put('.'); - if (quantum == 0 || current_proc->state != PROC_RUNNING) { - quantum = 42; // For next process - } else { - quantum--; - locked = 0; - sti(); - return; - } + /* serial_put('.'); */ + /* if (quantum == 0 || current_proc->state != PROC_RUNNING) { */ + /* quantum = 42; // For next process */ + /* } else { */ + /* quantum--; */ + /* locked = 0; */ + /* return; */ + /* } */ serial_put('+'); memcpy(¤t_proc->regs, regs, sizeof(struct regs)); @@ -56,6 +55,7 @@ void scheduler(struct regs *regs) memcpy(regs, ¤t_proc->regs, sizeof(struct regs)); paging_switch_dir(current_proc->cr3); + log("%x", regs->cs); if (regs->cs != 0x1B) { regs->gs = 0x23; regs->fs = 0x23; @@ -75,7 +75,6 @@ void process_force_switch() //scheduler(regs); } -u32 hl_cr3; u32 hl_eip; u32 hl_esp; void process_init(struct process *proc) @@ -91,7 +90,7 @@ void process_init(struct process *proc) hl_eip = proc->regs.eip; hl_esp = proc->regs.esp; - //paging_switch_dir(proc->cr3); + paging_switch_dir(proc->cr3); debug("Jumping to userspace!"); extern void userspace_jump(); diff --git a/src/kernel/tasks/userspace.asm b/src/kernel/tasks/userspace.asm index 6881bdf..eec6cff 100644 --- a/src/kernel/tasks/userspace.asm +++ b/src/kernel/tasks/userspace.asm @@ -1,5 +1,4 @@ global userspace_jump -extern hl_cr3 extern hl_esp extern hl_eip |