00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <ubixos/fork.h>
00031 #include <ubixos/types.h>
00032 #include <ubixos/sched.h>
00033 #include <ubixos/tty.h>
00034 #include <ubixos/vitals.h>
00035 #include <vmm/vmm.h>
00036 #include <string.h>
00037 #include <assert.h>
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 int fork_copyProcess(struct taskStruct *newProcess,long ebp,long edi,long esi,long none,long ebx,long ecx,long edx,long eip,long cs,long eflags,long esp,long ss) {
00051 volatile struct taskStruct * tmpProcPtr = newProcess;
00052 assert(newProcess);
00053 assert(_current);
00054
00055
00056 memcpy(newProcess->oInfo.cwd,_current->oInfo.cwd,1024);
00057
00058 newProcess->tss.eip = eip;
00059 newProcess->oInfo.vmStart = _current->oInfo.vmStart;
00060 newProcess->term = _current->term;
00061 newProcess->term->owner = newProcess->id;
00062 newProcess->uid = _current->uid;
00063 newProcess->gid = _current->gid;
00064 newProcess->tss.back_link = 0x0;
00065 newProcess->tss.esp0 = _current->tss.esp0;
00066 newProcess->tss.ss0 = 0x10;
00067 newProcess->tss.esp1 = 0x0;
00068 newProcess->tss.ss1 = 0x0;
00069 newProcess->tss.esp2 = 0x0;
00070 newProcess->tss.ss2 = 0x0;
00071 newProcess->tss.eflags = eflags;
00072 newProcess->tss.eax = 0x0;
00073 newProcess->tss.ebx = ebx;
00074 newProcess->tss.ecx = ecx;
00075 newProcess->tss.edx = edx;
00076 newProcess->tss.esi = esi;
00077 newProcess->tss.edi = edi;
00078 newProcess->tss.ebp = ebp;
00079 newProcess->tss.esp = esp;
00080 newProcess->tss.cs = cs & 0xFF;
00081 newProcess->tss.ss = ss & 0xFF;
00082 newProcess->tss.ds = _current->tss.ds & 0xFF;
00083 newProcess->tss.fs = _current->tss.fs & 0xFF;
00084 newProcess->tss.gs = _current->tss.gs & 0xFF;
00085 newProcess->tss.es = _current->tss.es & 0xFF;
00086 newProcess->tss.ldt = 0x18;
00087 newProcess->tss.trace_bitmap = 0x0000;
00088 newProcess->tss.io_map = 0x8000;
00089
00090 newProcess->tss.cr3 = (uInt32)vmmCopyVirtualSpace(newProcess->id);
00091 newProcess->state = FORK;
00092
00093
00094 while (tmpProcPtr->state == FORK) sched_yield();
00095
00096
00097 return(newProcess->id);
00098 }
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 asm(
00113 ".globl sysFork \n"
00114 "sysFork: \n"
00115 " xor %eax,%eax \n"
00116 " call schedNewTask \n"
00117 " testl %eax,%eax \n"
00118 " je fork_ret \n"
00119 " pushl %esi \n"
00120 " pushl %edi \n"
00121 " pushl %ebp \n"
00122 " pushl %eax \n"
00123 " call fork_copyProcess \n"
00124 " movl %eax,(%ebx) \n"
00125 " addl $16,%esp \n"
00126 "fork_ret: \n"
00127 " ret \n"
00128 );
00129
00130
00131
00132
00133