os/kernel/elf.c

38 lines
1 KiB
C

#include <stdint.h>
#include <stddef.h>
#include <debugging.h>
#include <kernel/tty.h>
#include <kernel/gdt.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;
}
void run_program(uint8_t* program, size_t length)
{
uint8_t* userland_code = (uint8_t*) 0x0;
memcpy(userland_code, program, length);
print_hex_bytes(userland_code, 1);
terminal_putchar('\n');
asm ("\
mov $0x20 | 0x3, %%ax;\
movw %%ax, %%ds;\
movw %%ax, %%es;\
movw %%ax, %%fs;\
movw %%ax, %%gs;\
pushl $0x20 | 0x3; /* SS selector */ \
pushl $0x00c00100; /* ESP */ \
pushf; /* EFLAGS */ \
popl %%eax; orl $0x200, %%eax; pushl %%eax; /* Set interrupts in USERPACE */\
pushl $0x18 | 0x3; /* CS selector */\
pushl $0x0; /* EIP */ \
iret;":::"eax");
}