CoreServer::CoreServer() : ChannelServer<CoreServer, FileSystemMessage>(this) { /* * TODO: * discover other CPUs with libarch APIC. Determine the memory * splitup. Claim the memory for that CPU. Fill the boot struct with various argument * inside the cpu1 memory so that IntelBoot.S can find its base. * start new kernel with /boot/kernel (or any other kernel, depending on configuration) * introduce a IntelGeometry, which uses APIC. CoreServer uses the Arch::Geometry to discover CPUs here. * once CPU1 is up & running, we can implement libmpi! :-) */ m_numRegions = 0; m_kernel = ZERO; m_kernelImage = ZERO; m_coreInfo = ZERO; #ifdef INTEL m_cores = ZERO; m_toMaster = ZERO; m_fromMaster = ZERO; m_toSlave = ZERO; m_fromSlave = ZERO; #endif // Register IPC handlers addIPCHandler(ReadFile, &CoreServer::getCoreCount); // TODO: hack: because of waitpid() we must send the reply manually before waitpid(). addIPCHandler(CreateFile, &CoreServer::createProcess, false); }
FileSystem::FileSystem(const char *path) : IPCServer<FileSystem, FileSystemMessage>(this) { // Set members m_root = 0; m_mountPath = path; m_requests = new List<FileSystemRequest *>(); // Register message handlers addIPCHandler(CreateFile, &FileSystem::pathHandler, false); addIPCHandler(StatFile, &FileSystem::pathHandler, false); addIPCHandler(DeleteFile, &FileSystem::pathHandler, false); addIPCHandler(ReadFile, &FileSystem::pathHandler, false); addIPCHandler(WriteFile, &FileSystem::pathHandler, false); }
ProcessServer::ProcessServer() : IPCServer<ProcessServer, ProcessMessage>(this) { MemoryMessage mem; /* Register message handlers. */ addIPCHandler(ReadProcess, &ProcessServer::readProcessHandler); addIPCHandler(ExitProcess, &ProcessServer::exitProcessHandler, false); addIPCHandler(SpawnProcess, &ProcessServer::spawnProcessHandler); addIPCHandler(CloneProcess, &ProcessServer::cloneProcessHandler, false); addIPCHandler(WaitProcess, &ProcessServer::waitProcessHandler, false); addIPCHandler(SetCurrentDirectory, &ProcessServer::setCurrentDirectory); /* Load shared objects. */ procs.load(USER_PROCESS_KEY, MAX_PROCS); files = new Array<Shared<FileDescriptor> >(MAX_PROCS); }
CoreServer::CoreServer() : IPCServer<CoreServer, CoreMessage>(this) { SystemInformation info; Memory::Range range; BootImage *image; BootSymbol *symbol; /* Register message handlers. */ addIPCHandler(CreatePrivate, &CoreServer::createPrivate); addIPCHandler(ReleasePrivate, &CoreServer::releasePrivate); addIPCHandler(ReadProcess, &CoreServer::readProcessHandler); addIPCHandler(GetMounts, &CoreServer::getMountsHandler); addIPCHandler(SetMount, &CoreServer::setMountHandler); addIPCHandler(ExitProcess, &CoreServer::exitProcessHandler, false); addIPCHandler(SpawnProcess, &CoreServer::spawnProcessHandler); addIPCHandler(WaitProcess, &CoreServer::waitProcessHandler, false); /* Allocate a user process table. */ procs = new UserProcess[MAX_PROCS]; memset(procs, 0, sizeof(UserProcess) * MAX_PROCS); /* Allocate FileSystemMounts table. */ mounts = new FileSystemMount[FILESYSTEM_MAXMOUNTS]; memset(mounts, 0, sizeof(FileSystemMount) * FILESYSTEM_MAXMOUNTS); /* We only guarantee that / and /dev, /proc are mounted. */ strlcpy(mounts[0].path, "/dev", PATHLEN); strlcpy(mounts[1].path, "/", PATHLEN); strlcpy(mounts[2].path, "/proc", PATHLEN); mounts[0].procID = DEVSRV_PID; mounts[0].options = ZERO; mounts[1].procID = ROOTSRV_PID; mounts[1].options = ZERO; mounts[2].procID = 13; mounts[2].options = ZERO; // Attempt to load the boot image range.virt = ZERO; range.phys = info.bootImageAddress; range.access = Arch::Memory::Present | Arch::Memory::User | Arch::Memory::Readable; range.size = info.bootImageSize; VMCtl(SELF, Map, &range); image = (BootImage *) range.virt; /* Loop all embedded programs. */ for (Size j = 0; j < image->symbolTableCount; j++) { /* Read out the next program. */ symbol = (BootSymbol *)(((Address)image) + image->symbolTableOffset); symbol += j; if (symbol->type != BootProgram) continue; /* Write commandline. */ snprintf(procs[j].command, COMMANDLEN, "[%s]", symbol->name); /* Set user and group identities. */ procs[j].userID = 0; procs[j].groupID = 0; } }
MemoryServer::MemoryServer() : IPCServer<MemoryServer, MemoryMessage>(this) { SystemInformation info; MemoryRange range; BootImage *image; BootProgram *program; /* Register message handlers. */ addIPCHandler(CreatePrivate, &MemoryServer::createPrivate); addIPCHandler(ReservePrivate, &MemoryServer::reservePrivate); addIPCHandler(ReleasePrivate, &MemoryServer::releasePrivate); addIPCHandler(CreateShared, &MemoryServer::createShared); addIPCHandler(SystemMemory, &MemoryServer::systemMemory); /* Allocate a user process table. */ insertShared(SELF, USER_PROCESS_KEY, sizeof(UserProcess) * MAX_PROCS, &range); /* Clear it. */ procs = (UserProcess *) range.virtualAddress; memset(procs, 0, sizeof(UserProcess) * MAX_PROCS); /* Allocate FileSystemMounts table. */ insertShared(SELF, FILE_SYSTEM_MOUNT_KEY, sizeof(FileSystemMount) * MAX_MOUNTS, &range); /* Also Clear it. */ mounts = (FileSystemMount *) range.virtualAddress; memset(mounts, 0, sizeof(FileSystemMount) * MAX_MOUNTS); /* We only guarantee that / and /dev are mounted. */ strlcpy(mounts[0].path, "/dev", PATHLEN); strlcpy(mounts[1].path, "/", PATHLEN); mounts[0].procID = DEVSRV_PID; mounts[0].options = ZERO; mounts[1].procID = ROOTSRV_PID; mounts[1].options = ZERO; /* Attempt to load the boot image. */ for (Size i = 0; i < info.moduleCount; i++) { if (strcmp(info.modules[i].string, "/boot/boot.img.gz") == 0) { range.virtualAddress = findFreeRange(SELF, PAGESIZE * 2); range.physicalAddress = info.modules[i].modStart; range.access = Memory::Present | Memory::User | Memory::Readable; #warning Dangerous value for bytes here? range.bytes = PAGESIZE * 2; VMCtl(SELF, Map, &range); image = (BootImage *) range.virtualAddress; break; } } /* Loop all embedded programs. */ for (Size j = 0; j < image->programsTableCount; j++) { /* Read out the next program. */ program = (BootProgram *)(((Address)image) + image->programsTableOffset); program += j; /* Write commandline. */ snprintf(procs[j].command, COMMANDLEN, "[%s]", program->path); /* Set current directory. */ snprintf(procs[j].currentDirectory, PATHLEN, "/"); /* Set user and group identities. */ procs[j].userID = 0; procs[j].groupID = 0; } }