Skip to content

Commit

Permalink
Merge pull request #1267 from TomHarte/EOI
Browse files Browse the repository at this point in the history
Support 8259 PIC specific EOIs.
  • Loading branch information
TomHarte authored Dec 12, 2023
2 parents 02b2b9d + a49a3da commit b12ae26
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions Machines/PCCompatible/PIC.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,28 @@ class PIC {

// b7, b6, b5: EOI type.
// b2, b1, b0: interrupt level to acknowledge.
if((value >> 5) == 0b001) {
// Non-specific EOI.
awaiting_eoi_ = false;
switch(value >> 5) {
default:
printf("PIC: TODO EOI type %d\n", value >> 5);
case 0b010: // No-op.
break;

case 0b001: // Non-specific EOI.
awaiting_eoi_ = false;
break;

case 0b011: { // Specific EOI.
if((value & 3) == eoi_target_) {
awaiting_eoi_ = false;
}
} break;

// TODO:
// 0b000 = rotate in auto EOI mode (clear)
// 0b100 = rotate in auto EOI mode (set)
// 0b101 = rotate on nonspecific EOI command
// 0b110 = set primary command
// 0b111 = rotate on specific EOI command
}
}
}
Expand All @@ -93,7 +112,7 @@ class PIC {

template <int input>
void apply_edge(bool final_level) {
const uint8_t input_mask = 1 << input;
constexpr uint8_t input_mask = 1 << input;

// Guess: level triggered means the request can be forwarded only so long as the
// relevant input is actually high. Whereas edge triggered implies capturing state.
Expand All @@ -111,8 +130,6 @@ class PIC {
}

int acknowledge() {
awaiting_eoi_ = true;

in_service_ = 0x01;
int id = 0;
while(!(in_service_ & requests_) && in_service_) {
Expand All @@ -121,6 +138,8 @@ class PIC {
}

if(in_service_) {
eoi_target_ = id;
awaiting_eoi_ = true;
requests_ &= ~in_service_;
return vector_base_ + id;
}
Expand All @@ -138,6 +157,7 @@ class PIC {
uint8_t vector_base_ = 0;
uint8_t mask_ = 0;
bool awaiting_eoi_ = false;
int eoi_target_ = 0;

uint8_t requests_ = 0;
uint8_t in_service_ = 0;
Expand Down

0 comments on commit b12ae26

Please sign in to comment.