Пример #1
0
/**
 * Remaps the PIC.
 *
 * Initially, in real mode, the first 32 positions of the IDT are occupied by the exceptions
 * and the PIC's interrupts, IRQs. This function moves the IRQs in the IDT, so they
 *  don't overlap with the exceptions.
 *
 * @param offset1 The offset of the position where the IRQ0 was.
 * @param offset2 The offset of the position where the IRQ0 will be moved.
 */
void reMapPIC(int offset1,int offset2){
    unsigned char mask1,mask2;

    // Saving masks
    mask1 = inB(PIC1_DATA);
    mask2 = inB(PIC2_DATA);

    // Starting initialization
    outB(PIC1_COMMAND,0x11);
    outB(PIC2_COMMAND,0x11);

    // Setting PIC offset
    outB(PIC1_DATA,offset1);
    outB(PIC2_DATA,offset2);

    // Continuing initialization
    outB(PIC1_DATA,4);
    outB(PIC2_DATA,2);

    outB(PIC1_DATA,ICW4_8086);
    outB(PIC2_DATA,ICW4_8086);

    // Restore masks
    outB(PIC1_DATA,mask1);
    outB(PIC2_DATA,mask2);
}
Пример #2
0
/**
 * Initializes the Interrupt Descriptor Table.
 *
 * Remaps the PIC, and loads the interrput and exceptions handlers.
 */
void setupIDT(void) {

    idt = allocPages(1);

    // We don't actually have to keep this in memory, so it's safe to have it as a local.
    InterruptDescriptorTableRegister idtr;

    // Disabling interrupts to make sure we're in absolute control.
    reMapPIC(PIC1_BASE_OFFSET,PIC2_BASE_OFFSET);

    setIdtEntry(idt, 0x80, 0x08, (dword)&_int80Handler, 0xEE);
    setIdtEntry(idt, 0x20, 0x08, (dword)&_int20Handler, ACS_INT);
    setIdtEntry(idt, 0x21, 0x08, (dword)&_int21Handler, ACS_INT);

    setIdtEntry(idt, 0x00, 0x08, (dword)&_int00Handler, ACS_INT);
    setIdtEntry(idt, 0x01, 0x08, (dword)&_int01Handler, ACS_INT);
    setIdtEntry(idt, 0x02, 0x08, (dword)&_int02Handler, ACS_INT);
    setIdtEntry(idt, 0x03, 0x08, (dword)&_int03Handler, ACS_INT);
    setIdtEntry(idt, 0x04, 0x08, (dword)&_int04Handler, ACS_INT);
    setIdtEntry(idt, 0x05, 0x08, (dword)&_int05Handler, ACS_INT);
    setIdtEntry(idt, 0x06, 0x08, (dword)&_int06Handler, ACS_INT);
    setIdtEntry(idt, 0x07, 0x08, (dword)&_int07Handler, ACS_INT);
    setIdtEntry(idt, 0x08, 0x08, (dword)&_int08Handler, ACS_INT);
    setIdtEntry(idt, 0x09, 0x08, (dword)&_int09Handler, ACS_INT);
    setIdtEntry(idt, 0x0A, 0x08, (dword)&_int0AHandler, ACS_INT);
    setIdtEntry(idt, 0x0B, 0x08, (dword)&_int0BHandler, ACS_INT);
    setIdtEntry(idt, 0x0C, 0x08, (dword)&_int0CHandler, ACS_INT);
    setIdtEntry(idt, 0x0D, 0x08, (dword)&_int0DHandler, ACS_INT);
    setIdtEntry(idt, 0x0E, 0x08, (dword)&_int0EHandler, ACS_INT);
    setIdtEntry(idt, 0x0F, 0x08, (dword)&_int0FHandler, ACS_INT);
    setIdtEntry(idt, 0x10, 0x08, (dword)&_int10Handler, ACS_INT);
    setIdtEntry(idt, 0x11, 0x08, (dword)&_int11Handler, ACS_INT);
    setIdtEntry(idt, 0x12, 0x08, (dword)&_int12Handler, ACS_INT);
    setIdtEntry(idt, 0x13, 0x08, (dword)&_int13Handler, ACS_INT);
    setIdtEntry(idt, 0x14, 0x08, (dword)&_int14Handler, ACS_INT);
    setIdtEntry(idt, 0x15, 0x08, (dword)&_int15Handler, ACS_INT);
    setIdtEntry(idt, 0x16, 0x08, (dword)&_int16Handler, ACS_INT);
    setIdtEntry(idt, 0x17, 0x08, (dword)&_int17Handler, ACS_INT);
    setIdtEntry(idt, 0x18, 0x08, (dword)&_int18Handler, ACS_INT);
    setIdtEntry(idt, 0x19, 0x08, (dword)&_int19Handler, ACS_INT);
    setIdtEntry(idt, 0x1A, 0x08, (dword)&_int1AHandler, ACS_INT);
    setIdtEntry(idt, 0x1B, 0x08, (dword)&_int1BHandler, ACS_INT);
    setIdtEntry(idt, 0x1C, 0x08, (dword)&_int1CHandler, ACS_INT);
    setIdtEntry(idt, 0x1D, 0x08, (dword)&_int1DHandler, ACS_INT);
    setIdtEntry(idt, 0x1E, 0x08, (dword)&_int1EHandler, ACS_INT);
    setIdtEntry(idt, 0x1F, 0x08, (dword)&_int1FHandler, ACS_INT);

    idtr.base = (dword) idt;
    idtr.limit = sizeof(InterruptDescriptor) * 256 - 1;

    __asm__ volatile("lidt (%%eax)"::"A"(&idtr):);

    setInterruptHandlerTable();

    /* Enable the interrupts we need in the PIC. */
    outB(0x21,0xFC);
    outB(0xA1,0xFF);
}
Пример #3
0
void signalPIC(void) {

    if (intNum >= PIC_MIN_INTNUM && intNum < PIC_MIN_INTNUM + PIC_IRQS) {
        if (intNum - PIC_MIN_INTNUM >= 8) {
            // Tell the slave PIC we're done
            outB(0xA0, PIC_EOI);
        }

        // Tell the master PIC we're done
        outB(0x20, PIC_EOI);
    }
}
void place::savePlacement(const std::vector<const place::posInfo *> &minima,
                          const std::string &outName,
                          const std::vector<Eigen::Vector2i> &zeroZero) {
  constexpr int maxToSave = 500;

  std::ofstream out(outName, std::ios::out);
  std::ofstream outB(outName.substr(0, outName.find(".")) + ".dat",
                     std::ios::out | std::ios::binary);

  const int num = minima.size();

  out << "Score x y rotation" << std::endl;
  outB.write(reinterpret_cast<const char *>(&num), sizeof(num));
  for (int i = 0; i < std::min(maxToSave, num); ++i) {
    place::posInfo minScore = *minima[i];
    minScore.x += zeroZero[minScore.rotation][0];
    minScore.y += zeroZero[minScore.rotation][1];
    out << minScore.score << " " << minScore.x << " " << minScore.y << " "
        << minScore.rotation << std::endl;

    outB.write(reinterpret_cast<const char *>(&minScore), sizeof(minScore));
  }
  out.close();
  outB.close();
}
Пример #5
0
/**
 * Read the registers from the Real Time Clock.
 *
 * It reads the registers from the RTC and stores the data in the struct which
 * pointer it receives. It handles the different types of format in which the data
 * is stored in the RTC registers.
 *
 * @param regs Pointer to struct where the data from RTC registers will be stored.
 *
 */
void readRTCRegisters(RTCRegisters *regs){
    int format;

    // Getting format register
    outB(RTCADDRESS, 11);
    format = inB(RTCDATA);

    // Getting seconds
    regs->seconds = readSeconds();

    // Getting minutes
    regs->minutes = readMinutes();

    // Getting hours (value may be 12hs o 24hs format)
    regs->hours = readHours();

    // Getting day of the month
    regs->day = readDay();

    // Getting month
    regs->month = readMonth();

    // Getting year
    regs->year = readYear();

    // Getting century
    regs->century = readCentury();

    // If in BCD mode, convert to binary
    if ((format & 0x02) ==  0x02 ) {
       regs->seconds = BCDTOBINARY(regs->seconds);
       regs->minutes = BCDTOBINARY( regs->minutes);
       regs->hours = BCDTOBINARY(regs->hours);
       regs->day = BCDTOBINARY(regs->day );
       regs->month = BCDTOBINARY(regs->month);
       regs->year = BCDTOBINARY(regs->year);
       regs->century = BCDTOBINARY(regs->century);
    }

    // If in 12 hs mode, convert to 24 hs mode
    if ((format & 0x04) == 0x04) {
      // Masking off the pm/am bit
        if ( (regs->hours & 0x80) == 0x80 ) {
            regs->hours &= 0x7F;
            // Setting 12 pm as 0 regs->hours and adjusting the rest
            regs->hours = (regs->hours == 12)? 0 : regs->hours + 12;
        }
    }
}
Пример #6
0
/**
 * Read the RTC century register.
 *
 * @return An integer representing the data stored in the register (different formats).
 */
int readCentury(void) {
    outB(RTCADDRESS, CENTURYREGISTER);
    return inB(RTCDATA);
}
Пример #7
0
/**
 * Read the RTC year register.
 *
 * @return An integer representing the data stored in the register (different formats).
 */
int readYear(void) {
    outB(RTCADDRESS, YEARREGISTER);
    return inB(RTCDATA);
}
Пример #8
0
/**
 * Read the RTC month register.
 *
 * @return An integer representing the data stored in the register (different formats).
 */
int readMonth(void) {
    outB(RTCADDRESS, MONTHREGISTER);
    return  inB(RTCDATA);
}
Пример #9
0
/**
 * Read the RTC day of the month register.
 *
 * @return An integer representing the data stored in the register (different formats).
 */
int readDay(void) {
    outB(RTCADDRESS, DAYREGISTER);
    return  inB(RTCDATA);
}
Пример #10
0
/**
 * Read the RTC hours register.
 *
 * @return An integer representing the data stored in the register (different formats).
 */
int readHours(void) {
    outB(RTCADDRESS, HOURSREGISTER);
    return inB(RTCDATA);
}
Пример #11
0
/**
 * Read the RTC minutes register.
 *
 * @return An integer representing the data stored in the register (different formats).
 */
int readMinutes(void) {
    outB(RTCADDRESS, MINUTESREGISTER);
    return  inB(RTCDATA);
}
Пример #12
0
/**
 * Read the RTC seconds register.
 *
 * @return An integer representing the data stored in the register (different formats).
 */
int readSeconds(void) {
    outB(RTCADDRESS, SECONDSREGISTER);
    return  inB(RTCDATA);
}