Move platform-specific code for process loading/init for AMD64 to amd64/
All checks were successful
Build documentation / build-and-deploy (push) Successful in 49s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 49s
This commit is contained in:
@@ -15,20 +15,13 @@
|
||||
#include <sys/mm.h>
|
||||
#include <sys/sched.h>
|
||||
#include <sys/smp.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/spin.h>
|
||||
|
||||
#if defined(__x86_64__)
|
||||
#include <amd64/intr_defs.h>
|
||||
#include <amd64/msr.h>
|
||||
#include <amd64/msr-index.h>
|
||||
#endif
|
||||
|
||||
struct elf_aux {
|
||||
uint64_t entry;
|
||||
uint64_t phdr;
|
||||
uint64_t phent;
|
||||
uint64_t phnum;
|
||||
};
|
||||
|
||||
static struct procw* procs;
|
||||
static spin_lock_t procs_lock = SPIN_LOCK_INIT;
|
||||
|
||||
@@ -59,7 +52,7 @@ void proc_map (struct proc* proc, uintptr_t start_paddr, uintptr_t start_vaddr,
|
||||
spin_unlock (&proc->pd.lock);
|
||||
}
|
||||
|
||||
static struct elf_aux proc_load_segments (struct proc* proc, uint8_t* elf) {
|
||||
struct elf_aux proc_load_segments (struct proc* proc, uint8_t* elf) {
|
||||
struct elf_aux aux;
|
||||
|
||||
Elf64_Ehdr* ehdr = (Elf64_Ehdr*)elf;
|
||||
@@ -112,53 +105,7 @@ static struct proc* proc_spawn_rd (char* name) {
|
||||
if (!ok)
|
||||
return NULL;
|
||||
|
||||
struct proc* proc = malloc (sizeof (*proc));
|
||||
if (proc == NULL)
|
||||
return NULL;
|
||||
|
||||
memset (proc, 0, sizeof (*proc));
|
||||
|
||||
#if defined(__x86_64__)
|
||||
proc->pd.lock = SPIN_LOCK_INIT;
|
||||
proc->pd.cr3_paddr = mm_alloc_user_pd_phys ();
|
||||
if (proc->pd.cr3_paddr == 0) {
|
||||
free (proc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
proc->pdata.syscall_stack = pmm_alloc (KSTACK_SIZE / PAGE_SIZE);
|
||||
if (proc->pdata.syscall_stack == PMM_ALLOC_ERR) {
|
||||
free (proc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
proc->pdata.user_stack = pmm_alloc (USTACK_SIZE / PAGE_SIZE);
|
||||
if (proc->pdata.user_stack == PMM_ALLOC_ERR) {
|
||||
free (proc);
|
||||
pmm_free (proc->pdata.syscall_stack, USTACK_SIZE / PAGE_SIZE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uintptr_t user_stack = proc->pdata.user_stack;
|
||||
|
||||
proc->pdata.syscall_stack += KSTACK_SIZE;
|
||||
proc->pdata.user_stack += USTACK_SIZE;
|
||||
|
||||
proc_map (proc, user_stack, PROC_USTACK_TOP - USTACK_SIZE, USTACK_SIZE / PAGE_SIZE,
|
||||
MM_PG_USER | MM_PG_PRESENT | MM_PG_RW);
|
||||
|
||||
struct elf_aux aux = proc_load_segments (proc, rd_file->content);
|
||||
|
||||
proc->pdata.regs.ss = 0x20 | 0x03;
|
||||
proc->pdata.regs.rsp = (uint64_t)PROC_USTACK_TOP;
|
||||
proc->pdata.regs.rflags = 0x202;
|
||||
proc->pdata.regs.cs = 0x18 | 0x03;
|
||||
proc->pdata.regs.rip = aux.entry;
|
||||
proc->lock = SPIN_LOCK_INIT;
|
||||
atomic_store (&proc->state, PROC_READY);
|
||||
#endif
|
||||
|
||||
return proc;
|
||||
return proc_from_elf (rd_file->content);
|
||||
}
|
||||
|
||||
static void proc_register (struct proc* proc) {
|
||||
@@ -228,11 +175,7 @@ void proc_sched (void) {
|
||||
}
|
||||
|
||||
idle:
|
||||
#if defined(__x86_64__)
|
||||
extern void amd64_spin (void);
|
||||
|
||||
amd64_spin ();
|
||||
#endif
|
||||
spin ();
|
||||
}
|
||||
|
||||
void proc_kill (struct proc* proc) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define _KERNEL_PROC_PROC_H
|
||||
|
||||
#include <aux/compiler.h>
|
||||
#include <aux/elf.h>
|
||||
#include <libk/std.h>
|
||||
#include <sync/spin_lock.h>
|
||||
#include <sys/mm.h>
|
||||
@@ -51,6 +52,9 @@ struct procw {
|
||||
|
||||
void proc_sched (void);
|
||||
void proc_kill (struct proc* proc);
|
||||
void proc_map (struct proc* proc, uintptr_t start_paddr, uintptr_t start_vaddr, size_t pages,
|
||||
uint32_t flags);
|
||||
struct elf_aux proc_load_segments (struct proc* proc, uint8_t* elf);
|
||||
void proc_init (void);
|
||||
|
||||
#endif // _KERNEL_PROC_PROC_H
|
||||
|
||||
Reference in New Issue
Block a user