/************************************************************************************** Copyright (c) 2002 The UbixOS Project All rights reserved. Redistribution and use in source and binary forms, with or without modification, are prohibited. $Id$ **************************************************************************************/ #include <ubixos/exec.h> #include <ubixos/schedule.h> #include <ubixos/elf.h> #include <ubixos/a.out.h> #include <vmm/paging.h> #include <ubixfs/file.h> int execFile(char *file) { int fd=0,i=0,x=0,eStart=0; char *binarySpace = (char *)0x7C0000; char *newLoc; elfHeader *binaryHeader = (elfHeader *)0x7C0000; elfProgramheader *programHeader; kprintf("Test [%s]",file); fd = fopen(file,1); kprintf("Test2"); for (i=0;feof(fd) == 0;i++) { binarySpace[i] = fgetc(fd); } kprintf("Test4"); programHeader = (elfProgramheader *)(0x7C0000 + binaryHeader->ePhoff); newLoc = (char *)programHeader->phVaddr; for (x=0;x<i;x++) { newLoc[x] = binarySpace[x]; } eStart = binaryHeader->eEntry; execThread((void *)eStart,0xCFFF,file); return(0); } void execThread(void (* tproc)(void),int stack,char *descr) { int pid = 0; pid = findTask(); taskList[pid].tss.back_link = 0x0; taskList[pid].tss.esp0 = stack; taskList[pid].tss.ss0 = 0x10; taskList[pid].tss.esp1 = 0x0; taskList[pid].tss.ss1 = 0x10; taskList[pid].tss.esp2 = 0x0; taskList[pid].tss.ss2 = 0x10; taskList[pid].tss.cr3 = (unsigned int)pageDirectory; taskList[pid].tss.eip = (unsigned int)tproc; taskList[pid].tss.eflags = 0x206; taskList[pid].tss.esp = stack; taskList[pid].tss.ebp = stack; taskList[pid].tss.esi = 0x0; taskList[pid].tss.edi = 0x0; taskList[pid].tss.es = 0x10; taskList[pid].tss.cs = 0x08; taskList[pid].tss.ss = 0x10; taskList[pid].tss.ds = 0x10; taskList[pid].tss.fs = 0x10; taskList[pid].tss.gs = 0x10; taskList[pid].tss.ldt = 0x18; taskList[pid].tss.trace_bitmap = 0x80000000; taskList[pid].status = RUNABLE; }