2024-08-05 00:59:07 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <debugging.h>
|
|
|
|
#include <kernel/tty.h>
|
|
|
|
#include <kernel/gdt.h>
|
2024-08-08 21:34:30 +02:00
|
|
|
#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;
|
|
|
|
}
|
2024-08-05 00:59:07 +02:00
|
|
|
|
|
|
|
void run_program(uint8_t* program, size_t length)
|
|
|
|
{
|
2024-08-08 21:34:30 +02:00
|
|
|
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");
|
2024-08-05 00:59:07 +02:00
|
|
|
}
|