void DGLDebugeeQTProcess::pollReady() { if (m_Loaded) { if (waitForSocket(true)) { m_PollTimer->stop(); emit processReady(); } } else { if (m_SemLoader.try_wait()) { m_Loaded = true; pollReady(); } } }
Error ATAController::read(s8 *buffer, Size size, Size offset) { u8 sectors = CEIL(size, 512); u16 block[256]; u32 lba = offset / 512; Size result = 0; /* Verify LBA. */ if (!drives.head() || drives.head()->identity.sectors28 < lba) { return EIO; } /* Perform ATA Read Command. */ outb(ATA_BASE_CMD0 + ATA_REG_SELECT, ATA_SEL_MASTER_28); outb(ATA_BASE_CMD0 + ATA_REG_COUNT, sectors); outb(ATA_BASE_CMD0 + ATA_REG_ADDR0, (lba) & 0xff); outb(ATA_BASE_CMD0 + ATA_REG_ADDR1, (lba >> 8) & 0xff); outb(ATA_BASE_CMD0 + ATA_REG_ADDR2, (lba >> 16) & 0xff); outb(ATA_BASE_CMD0 + ATA_REG_CMD, ATA_CMD_READ); /* * Read out all requested sectors. */ while(result < size) { /* Poll the status register. */ pollReady(true); /* Read out bytes. */ for (int i = 0; i < 256; i++) { block[i] = inw(ATA_BASE_CMD0 + ATA_REG_DATA); } /* Calculate maximum bytes. */ Size bytes = (size - result) < 512 - (offset % 512) ? (size - result) : 512 - (offset % 512); /* Copy to buffer. */ memcpy(buffer + result, ((u8 *)block) + (offset % 512), bytes); /* Update state. */ result += bytes; offset += bytes; } return result; }
DGLDebugeeQTProcess::DGLDebugeeQTProcess(int port, bool modeEGL) : m_Port(port), m_Loaded(false), m_ModeEGL(modeEGL), m_PortStr(boost::lexical_cast<std::string>(getPort())), m_SemLoaderStr("sem_loader_" + m_PortStr), m_SemOpenGLStr("sem_" + m_PortStr), m_SemLoader(boost::interprocess::open_or_create, m_SemLoaderStr.c_str(), 0), m_SemOpenGL(boost::interprocess::open_or_create, m_SemOpenGLStr.c_str(), 0), m_PollTimer(new QTimer(this)) { CONNASSERT(m_PollTimer, SIGNAL(timeout()), this, SLOT(pollReady())); CONNASSERT(getProcess(), SIGNAL(started()), this, SLOT(startPolling())); CONNASSERT(getProcess(), SIGNAL(error(QProcess::ProcessError)), this, SLOT(handleProcessError(QProcess::ProcessError))); CONNASSERT(getProcess(), SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(handleProcessFinished(int, QProcess::ExitStatus))); }
u32int* sys_call(context *registers) { if (cop == NULL) { copContext = registers; } else { if (params.op_code == IDLE) { cop->stackTop = (u32int*)registers; cop->readyState = 0; addReady(cop); cop = NULL; } else if (params.op_code == EXIT) { FreePCB(cop); cop = NULL; } } if (peekReady() != NULL) { cop = pollReady(); cop->readyState = 1; return cop->stackTop; } else { return (u32int*)copContext; } }
Error ATAController::initialize() { ATADrive *drive; /* * Request ATA Control I/O port. */ ProcessCtl(SELF, AllowIO, ATA_BASE_CTL0); /* * Request ATA Command I/O ports. */ for (Size i = 0; i <= ATA_REG_CMD; i++) { ProcessCtl(SELF, AllowIO, ATA_BASE_CMD0 + i); } /* Detect ATA Controller. */ if (ReadByte(ATA_BASE_CMD0 + ATA_REG_STATUS) == 0xff) { exit(EXIT_FAILURE); } pollReady(true); /* Attempt to detect first drive. */ WriteByte(ATA_BASE_CMD0 + ATA_REG_SELECT, ATA_SEL_MASTER); pollReady(true); WriteByte(ATA_BASE_CMD0 + ATA_REG_CMD, ATA_CMD_IDENTIFY); switch (ReadByte(ATA_BASE_CMD0 + ATA_REG_STATUS)) { case 0: syslog(LOG_INFO, "No ATA drive(s) detected"); break; default: /* Wait until the command completed. */ pollReady(); /* Allocate a new drive. */ drive = new ATADrive; drives.append(drive); /* Read IDENTIFY data. */ for (int i = 0; i < 256; i++) { ((u16 *) &drive->identity)[i] = ReadWord(ATA_BASE_CMD0 + ATA_REG_DATA); } /* Fixup ASCII bytes. */ IDENTIFY_TEXT_SWAP(drive->identity.firmware, 8); IDENTIFY_TEXT_SWAP(drive->identity.serial, 20); IDENTIFY_TEXT_SWAP(drive->identity.model, 40); /* Print out information. */ syslog(LOG_INFO, "ATA drive detected: SERIAL=%20s FIRMWARE=%8s " "MODEL=%40s MAJOR=%x MINOR=%x SECTORS=%x", drive->identity.serial, drive->identity.firmware, drive->identity.model, drive->identity.majorRevision, drive->identity.minorRevision, drive->identity.sectors28); break; } return ESUCCESS; }