os/kernel/elf.c

43 lines
989 B
C

#include <stdint.h>
#include <stddef.h>
#include <debugging.h>
#include <kernel/tty.h>
#include <kernel/gdt.h>
#include <kernel/task.h>
#include <debugging.h>
static void* memcpy(void* restrict dstptr, const void* restrict srcptr, size_t size) {
unsigned char* dst = (unsigned char*) dstptr;
const unsigned char* src = (const unsigned char*) srcptr;
for (size_t i = 0; i < size; i++)
dst[i] = src[i];
return dstptr;
}
extern void jump_to_userspace();
void run_program(uint8_t* program, size_t length)
{
uint8_t* userland_code = (uint8_t*) 0x00800000;
memcpy(userland_code, program, length);
struct CPUState target = {
.eip = (size_t) userland_code,
.esp = 0x00c00100,
.eax = 0,
.ebx = 0,
.ecx = 0,
.edx = 0,
.cs = 0x18 | 0x3,
.ds = 0x20 | 0x3,
.eflags = 0x0200,
.ebp = 0x00c00100,
};
struct Task task = {
.state = target,
};
add_task(task);
}