bump-allocated PID but kheap needs fix to kmalloc more than PAGE_SIZE
This commit is contained in:
@@ -2,10 +2,14 @@
|
||||
#include "process.h"
|
||||
#include "mem/heap/kheap.h"
|
||||
#include "kernel.h"
|
||||
#include "string/string.h"
|
||||
#include "mem/gdt/gdt.h"
|
||||
|
||||
struct process_t* processes_list;
|
||||
struct process_t* current_process;
|
||||
|
||||
size_t next_free_pid = 0;
|
||||
|
||||
void process_init()
|
||||
{
|
||||
processes_list = NULL;
|
||||
@@ -26,16 +30,35 @@ void process_display_list(struct process_t* processes_list)
|
||||
DEBUG("NULL");
|
||||
}
|
||||
|
||||
struct process_t* process_create()
|
||||
struct process_t* process_create(char* name, void(*function)(void*), void* arg)
|
||||
{
|
||||
CLEAR_INTERRUPTS;
|
||||
struct process_t* proc = (struct process_t*)kmalloc(sizeof(struct process_t));
|
||||
|
||||
struct cpu_status_t* ctx = (struct cpu_status_t*)kmalloc(sizeof(struct cpu_status_t));
|
||||
|
||||
// No more memory?
|
||||
if (!proc) return NULL;
|
||||
if (!ctx) return NULL;
|
||||
|
||||
proc->context = NULL;
|
||||
strncpy(proc->name, name, PROCESS_NAME_MAX);
|
||||
proc->pid = next_free_pid++;
|
||||
proc->status = READY;
|
||||
proc->next = NULL;
|
||||
|
||||
proc->context = ctx;
|
||||
proc->context->iret_ss = KERNEL_DATA_SEGMENT; // process will live in kernel mode
|
||||
proc->context->iret_rsp = (uint64_t)kalloc_stack();
|
||||
proc->context->iret_flags = 0x202; //bit 2 and 9 set (Interrupt Flag)
|
||||
proc->context->iret_cs = KERNEL_CODE_SEGMENT;
|
||||
proc->context->iret_rip = (uint64_t)function; // beginning of executable code
|
||||
proc->context->rdi = (uint64_t)arg; // 1st arg is in rdi (as per x64 calling convention)
|
||||
proc->context->rbp = 0;
|
||||
|
||||
proc->next = 0;
|
||||
|
||||
process_add(&processes_list, proc);
|
||||
|
||||
SET_INTERRUPTS;
|
||||
return proc;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user