Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct IrqList {
- static const size_t length = 64;
- volatile uint32_t read;
- volatile uint32_t write;
- CpuState items[IrqList::length];
- } irqList {
- 0, 0, {}
- };
- extern "C" void vm_handle_interrupt(CpuState *state)
- {
- irqList.items[irqList.write] = *state;
- irqList.write += 1;
- if(irqList.write >= irqList.length) {
- die("irqList overflow.");
- }
- }
- [...]
- while(machine.step())
- {
- // check for IRQ requests
- do
- {
- // atomic checking for existing IRQ item
- irq_disable();
- bool hasItem = (irqList.read < irqList.write);
- irq_enable();
- if(hasItem == false) {
- break; // we don't have anything to read
- }
- CpuState *cpu = &irqList.items[irqList.read];
- auto *thread = irqService->createThread(irqRoutine);
- thread->start({ VMValue::Int32(cpu->intr), VMValue::Int32(cpu->eip) });
- irqList.read += 1;
- irq_disable();
- // When list is emptied, reset list pointers
- if(irqList.read == irqList.write) {
- irqList.read = 0;
- irqList.write = 0;
- }
- irq_enable();
- } while(true);
- }
Advertisement
Add Comment
Please, Sign In to add comment