Guest User

Untitled

a guest
Oct 7th, 2015
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. struct IrqList {
  2.     static const size_t length = 64;
  3.     volatile uint32_t read;
  4.     volatile uint32_t write;
  5.     CpuState items[IrqList::length];
  6. } irqList {
  7.     0, 0, {}
  8. };
  9.  
  10. extern "C" void vm_handle_interrupt(CpuState *state)
  11. {
  12.     irqList.items[irqList.write] = *state;
  13.     irqList.write += 1;
  14.     if(irqList.write >= irqList.length) {
  15.         die("irqList overflow.");
  16.     }
  17. }
  18.  
  19.  
  20. [...]
  21.  
  22. while(machine.step())
  23.     {
  24.         // check for IRQ requests
  25.         do
  26.         {
  27.             // atomic checking for existing IRQ item
  28.             irq_disable();
  29.             bool hasItem = (irqList.read < irqList.write);
  30.             irq_enable();
  31.  
  32.             if(hasItem == false) {
  33.                 break; // we don't have anything to read
  34.             }
  35.  
  36.             CpuState *cpu = &irqList.items[irqList.read];
  37.  
  38.             auto *thread = irqService->createThread(irqRoutine);
  39.             thread->start({ VMValue::Int32(cpu->intr), VMValue::Int32(cpu->eip) });
  40.  
  41.             irqList.read += 1;
  42.  
  43.             irq_disable();
  44.             // When list is emptied, reset list pointers
  45.             if(irqList.read == irqList.write) {
  46.                 irqList.read = 0;
  47.                 irqList.write = 0;
  48.             }
  49.             irq_enable();
  50.         } while(true);
  51.     }
Advertisement
Add Comment
Please, Sign In to add comment