Example #1
0
File: vm.c Project: sihida/essig
bool 
vm_interrupt(VMState *state, VMInterruptType type, ...)
{
    va_list args;
    VMInterruptItem *item;
    unsigned int cycles;
    
    if (state->interrupt_policy == VM_POLICY_INTERRUPT_NEVER)
            return true;
    
    va_start(args, type);
    item = NULL;
    
    switch (type) {
        case VM_INTERRUPT_TIMER:
            cycles = va_arg(args, unsigned int);
            item = vm_new_interrupt_item(VM_INTERRUPT_TIMER, 
                                         state->cycles + cycles);
            break;
        default:
            fputs("Only VM_INTERRUPT_TIMER is supported", stderr);
            exit(EXIT_FAILURE);
    }
    if(!item)
        return false;
    
    item->next = (VMIterable *) state->interrupts;
    state->interrupts = item;
    va_end(args);
    return true;
}
Example #2
0
bool
vm_interrupt(VMState *state, VMInterruptType type, ...)
{
    va_list args;
    VMInterruptItem *item;
    unsigned int cycles;

    if (state->interrupt_policy == VM_POLICY_INTERRUPT_NEVER)
        return true;

    va_start(args, type);
    item = NULL;

    switch (type) {
    case VM_INTERRUPT_TIMER:
        cycles = va_arg(args, unsigned int);
        item = vm_new_interrupt_item(VM_INTERRUPT_TIMER,
                                     state->cycles + cycles);
        break;
    default:
        vm_seterrno(VM_NO_SUCH_INTERRUPT_TYPE_SUPPORT_ERROR);
        return false;
    }
    if(!item)
        return false;

    item->next = state->interrupts;
    state->interrupts = item;
    va_end(args);
    return true;
}