aboutsummaryrefslogtreecommitdiff
path: root/kernel/features/load.c
blob: 8a4aae30ce9d7b2dc51759107a8239bc7a8c9a33 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// MIT License, Copyright (c) 2020 Marvin Borner

#include <fs.h>
#include <load.h>
#include <mem.h>
#include <str.h>

void proc_load(struct proc *proc, void *data)
{
	u32 stack = (u32)malloc(0x2000) + 0x1000;

	proc->regs.ebp = (u32)stack;
	proc->regs.useresp = (u32)stack;
	proc->regs.eip = (u32)data;
	proc->entry = (u32)data;
}

int bin_load(const char *path, struct proc *proc)
{
	struct stat s = { 0 };
	vfs_stat(path, &s);
	char *data = malloc(s.size);
	if (!vfs_read(path, data, 0, s.size))
		return 1;

	strcpy(proc->name, path);
	proc_load(proc, data);

	return 0;
}