#include #include #include #include #include #include #include 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(void* code, size_t code_length, void* data, size_t data_length, struct Heap_Block* code_block, struct Heap_Block* data_block) { // TODO: Replace following lines with malloc calls and paging calls memcpy(code_block->data, code, code_length); memcpy(data_block->data, data, data_length); struct CPUState target = { .eip = (size_t) 0x00400000, .esp = (size_t) 0x00801000, .eax = (size_t) 0x00800000, .ebx = data_length, .ecx = 0x00400000, .edx = 0, .cs = 0x18 | 0x3, .ds = 0x20 | 0x3, /// .cs = 0x08, // .ds = 0x10, .eflags = 0x0200, .ebp = 0, }; struct Task task = { .state = target, .needs_pages = true, .code = code_block, .data = data_block, }; add_task(task); }