aboutsummaryrefslogtreecommitdiff
path: root/kernel/features
diff options
context:
space:
mode:
authorMarvin Borner2021-03-12 17:27:01 +0100
committerMarvin Borner2021-03-12 17:27:01 +0100
commit0aef683b9d1e08555791426ba12223ed78051353 (patch)
tree324cbc61b7fb38f648a82041656f5fea48e53856 /kernel/features
parentf1751c121d48f2d8936c72bdc347777d1e7402d9 (diff)
Boots successfully...
Diffstat (limited to 'kernel/features')
-rw-r--r--kernel/features/load.c17
-rw-r--r--kernel/features/mm.c24
-rw-r--r--kernel/features/proc.c19
3 files changed, 24 insertions, 36 deletions
diff --git a/kernel/features/load.c b/kernel/features/load.c
index ec9a387..4ad2cbf 100644
--- a/kernel/features/load.c
+++ b/kernel/features/load.c
@@ -8,25 +8,16 @@
#define PROC_STACK_SIZE 0x4000
-/*void proc_load(struct proc *proc, u32 entry)
-{
- u32 stack = (u32)memory_alloc(proc->page_dir, PROC_STACK_SIZE, MEMORY_USER | MEMORY_CLEAR);
-
- proc->regs.ebp = stack;
- proc->regs.useresp = stack;
- proc->regs.eip = entry;
- proc->entry = entry;
-}*/
-
int bin_load(const char *path, struct proc *proc)
{
struct stat s = { 0 };
vfs_stat(path, &s);
- struct proc *current = proc_current();
- struct page_dir *prev = current ? current->page_dir : virtual_kernel_dir();
- u32 size = PAGE_ALIGN_UP(s.size);
+ struct page_dir *prev;
+ memory_backup_dir(&prev);
memory_switch_dir(proc->page_dir);
+
+ 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)) {
diff --git a/kernel/features/mm.c b/kernel/features/mm.c
index c39b8b7..5fe70fd 100644
--- a/kernel/features/mm.c
+++ b/kernel/features/mm.c
@@ -15,10 +15,10 @@ static struct page_table kernel_tables[256] ALIGNED(PAGE_SIZE) = { 0 };
* Lowlevel paging
*/
-static void paging_disable(void)
+/*static void paging_disable(void)
{
cr0_set(cr0_get() | 0x7fffffff);
-}
+}*/
static void paging_enable(void)
{
@@ -27,7 +27,6 @@ static void paging_enable(void)
static void paging_switch_dir(u32 dir)
{
- assert(dir);
cr3_set(dir);
}
@@ -154,7 +153,7 @@ struct memory_range physical_alloc(u32 size)
return memory_range(0, 0);
}
-static void physical_free(struct memory_range range)
+void physical_free(struct memory_range range)
{
assert(PAGE_ALIGNED(range.base) && PAGE_ALIGNED(range.size));
physical_set_free(range);
@@ -297,11 +296,6 @@ struct page_dir *virtual_create_dir(void)
return dir;
}
-struct page_dir *virtual_kernel_dir(void)
-{
- return &kernel_dir;
-}
-
void virtual_destroy_dir(struct page_dir *dir)
{
assert(dir != &kernel_dir);
@@ -326,6 +320,11 @@ void virtual_destroy_dir(struct page_dir *dir)
memory_free(&kernel_dir, memory_range((u32)dir, sizeof(*dir)));
}
+struct page_dir *virtual_kernel_dir(void)
+{
+ return &kernel_dir;
+}
+
/**
* Memory wrappers
*/
@@ -405,6 +404,13 @@ void memory_switch_dir(struct page_dir *dir)
paging_switch_dir(virtual_to_physical(&kernel_dir, (u32)dir));
}
+void memory_backup_dir(struct page_dir **backup)
+{
+ struct proc *proc = proc_current();
+ struct page_dir *dir = proc ? proc->page_dir : virtual_kernel_dir();
+ *backup = dir;
+}
+
struct memory_range memory_range_from(u32 base, u32 size)
{
u32 align = PAGE_SIZE - base % PAGE_SIZE;
diff --git a/kernel/features/proc.c b/kernel/features/proc.c
index 4d1311e..db2291c 100644
--- a/kernel/features/proc.c
+++ b/kernel/features/proc.c
@@ -76,12 +76,6 @@ void scheduler(struct regs *regs)
/* printf("{%d}", ((struct proc *)current->data)->pid); */
}
-static void kernel_idle(void)
-{
- while (1)
- ;
-}
-
void proc_print(void)
{
struct node *node = proc_list->head;
@@ -328,7 +322,7 @@ static s32 procfs_write(const char *path, void *buf, u32 offset, u32 count, stru
}
}
- printf("%s - off: %d, cnt: %d, buf: %x, dev %x\n", path, offset, count, buf, dev);
+ printf("ERR: %s - off: %d, cnt: %d, buf: %x, dev %x\n", path, offset, count, buf, dev);
return -1;
}
@@ -472,11 +466,10 @@ void proc_init(void)
vfs_mount(dev, "/proc/");
// Idle proc
- /* struct proc *kernel_proc = proc_make(PROC_PRIV_NONE); */
- /* proc_load(kernel_proc, (u32)kernel_idle); */
- /* strcpy(kernel_proc->name, "idle"); */
- /* kernel_proc->state = PROC_SLEEPING; */
- /* idle_proc = list_add(proc_list, kernel_proc); */
+ struct proc *kernel_proc = proc_make(PROC_PRIV_NONE);
+ bin_load("/bin/idle", kernel_proc);
+ kernel_proc->state = PROC_SLEEPING;
+ idle_proc = list_add(proc_list, kernel_proc);
// Init proc (root)
struct node *new = list_add(proc_list, proc_make(PROC_PRIV_ROOT));
@@ -496,9 +489,7 @@ void proc_init(void)
/* ((u32 *)_esp)[-1] = (u32)argv; // Second argument (argv) */
printf("Jumping to userspace!\n");
- /* printf("%x\n", ((u32 *)((struct proc *)new->data)->entry)[5]); */
memory_switch_dir(((struct proc *)new->data)->page_dir);
- /* printf("%x\n", ((u32 *)((struct proc *)new->data)->entry)[5]); */
proc_jump_userspace();
while (1) {
};