Esempio n. 1
0
def check_frequency(p_splice_vm, p_header):
    header = unpack32to4x8(p_header)
    group_id = header[0]
    task_id = header[1]
    interval_code = header[2]
    interval_value = 0
    if interval_code == FREQ_TMAX:
        return VM_TASK_IS_READY
    # check if we have at least attempted to run the task
    if interval_code == FREQ_ONCE:
        task_status = get_vram_content(p_splice_vm, "TASK_CONTEXT_STATUS",
                                       p_header)
        if task_status == TASK_COMPLETED:
            return VM_TASK_FINISHED
        else:
            return VM_TASK_IS_READY
    else:
        if interval_code < FREQ_1MIN:
            interval_value = interval_code
        if (interval_code >= FREQ_1MIN) and (interval_code < FREQ_HOUR):
            interval_value = (interval_code - 59) * 60
        if (interval_code >= FREQ_HOUR) and (interval_code < FREQ_TMAX):
            interval_value = (interval_code - 118) * 3600
        last_run_time = get_vram_content(p_splice_vm, "TASK_CONTEXT_WASRUN",
                                         p_header)
        time_delta = get_vm_time(p_splice_vm) - last_run_time
        if time_delta >= interval_value:
            return VM_TASK_IS_READY
        else:
            return VM_TASK_NOTREADY
Esempio n. 2
0
 def test_unpack32to8(self):
     i = 0
     while i < len(self.test_opcodes):
         item = self.test_opcodes[i]
         result = unpack32to4x8(item)
         # print(result)
         assert (result == self.test_decoded[i])
         i = i + 1
Esempio n. 3
0
def opcode_lea(p_splice_vm, p_reg_id, p_source_id, p_addr, p_group_id,
               p_task_id, p_offset):
    # determine global data location
    if p_source_id == p_task_id:
        target_offset = p_offset
    else:
        if p_source_id not in p_splice_vm["VRAM"]["PROGRAM_CODE_MEMORY"][
                p_group_id]:
            return p_splice_vm, EX_BAD_OPERAND
        else:
            target_header = unpack32to4x8(
                p_splice_vm["VRAM"]["PROGRAM_CODE_MEMORY"][p_group_id]
                [p_source_id][0])
            target_offset = target_header[3]
    # load data
    data = p_splice_vm["VRAM"]["PROGRAM_CODE_MEMORY"][p_group_id][p_source_id][
        p_addr + target_offset]
    if (p_reg_id < 0x10):
        p_splice_vm["VCPU"]["ALU_REGISTERS"][p_reg_id] = data
        return p_splice_vm, EX_OPCODE_FINE
    elif (p_reg_id > 0x0F) and (p_reg_id < 0x20):
        data_float = unpack_float_from_int(data)
        p_splice_vm["VCPU"]["FPU_REGISTERS"][p_reg_id] = data_float
        return p_splice_vm, EX_OPCODE_FINE
Esempio n. 4
0
def vm_execute(p_splice_vm, p_task):
    decoded_header = unpack32to4x8(p_task[0])
    group_id = decoded_header[0]
    task_id = decoded_header[1]
    offset = decoded_header[3]
    ip = 1
    next_opcode = OP_NOP
    task_info = "%s:%s:" % (group_id, task_id)
    while (next_opcode != OP_HLT) and (ip < len(p_task)):
        word = unpack32to4x8(p_task[ip])
        p_splice_vm = log_message(
            p_splice_vm, "%s%s" % (task_info, "{:x}".format(p_task[ip])),
            LOG_LEVEL_DEBUG)
        next_opcode = word[0]
        op_a = word[1]
        op_b = word[2]
        op_c = word[3]
        opc_result = EX_OPC_UNKNOWN
        if next_opcode == OP_NOP:
            opc_result = EX_OPCODE_FINE
        if next_opcode == OP_HLT:
            p_splice_vm = set_vram_content(p_splice_vm, "TASK_CONTEXT_STATUS",
                                           p_task[0], TASK_COMPLETED)
            return p_splice_vm
        if next_opcode == OP_MOV:
            p_splice_vm, opcode_result = opcode_mov(p_splice_vm, op_a, op_b,
                                                    op_c, group_id, task_id,
                                                    offset)
        if next_opcode == OP_LEA:
            p_splice_vm, opcode_result = opcode_lea(p_splice_vm, op_a, op_b,
                                                    op_c, group_id, task_id,
                                                    offset)
        if next_opcode == OP_STR:
            p_splice_vm, opcode_result = opcode_str(p_splice_vm, op_a, op_c,
                                                    task_info)
        if next_opcode == OP_CMP:
            opcode_result = opcode_cmp(p_splice_vm, op_a, op_b, op_c, group_id)
        if next_opcode == OP_GET:
            p_splice_vm, opcode_result = opcode_get(p_splice_vm, op_a, op_b,
                                                    op_c)
        if next_opcode == OP_SET:
            p_splice_vm, opcode_result = opcode_set(p_splice_vm, op_a, op_b,
                                                    op_c)
        if next_opcode == OP_ACT:
            p_splice_vm, opcode_result = opcode_act(p_splice_vm, op_a, op_b,
                                                    op_c)
        if next_opcode == OP_FMA:
            p_splice_vm, opcode_result = opcode_fma(p_splice_vm, op_a, op_b,
                                                    op_c)
        if next_opcode == OP_FSD:
            p_splice_vm, opcode_result = opcode_fsd(p_splice_vm, op_a, op_b,
                                                    op_c)
        if next_opcode in [OP_SIN, OP_COS, OP_TAN]:
            p_splice_vm, opcode_result = opcode_trg(p_splice_vm, next_opcode,
                                                    op_a, op_b, op_c)
        if next_opcode == OP_POW:
            p_splice_vm, opcode_result = opcode_pow(p_splice_vm, op_a, op_b,
                                                    op_c)
        if next_opcode == OP_NOR:
            p_splice_vm, opcode_result = opcode_nor(p_splice_vm, op_a, op_b,
                                                    op_c)
        if opcode_result == EX_BAD_OPERAND:
            message_string = "%s%s" % (task_info,
                                       "ERROR - Bad operand in command word!")
            p_splice_vm = log_message(p_splice_vm, message_string,
                                      LOG_LEVEL_ERROR)
            p_splice_vm = set_vram_content(p_splice_vm, "TASK_CONTEXT_STATUS",
                                           p_task[0], TASK_ERROR_OPC)
            return p_splice_vm
        if opcode_result == EX_OPC_UNKNOWN:
            message_string = "%s%s" % (task_info,
                                       "ERROR - Undecodable opcode!")
            p_splice_vm = log_message(p_splice_vm, message_string,
                                      LOG_LEVEL_ERROR)
            p_splice_vm = set_vram_content(p_splice_vm, "TASK_CONTEXT_STATUS",
                                           p_task[0], TASK_ERROR_OPC)
            return p_splice_vm
        if opcode_result == EX_CHECK_FALSE:
            message_string = "%s%s" % (
                task_info, "Terminating task - execution conditions not met ")
            p_splice_vm = log_message(p_splice_vm, message_string,
                                      LOG_LEVEL_INFO)
            p_splice_vm = set_vram_content(p_splice_vm, "TASK_CONTEXT_STATUS",
                                           p_task[0], TASK_CON_UNMET)
            return p_splice_vm
        ip = ip + 1
    return p_splice_vm
Esempio n. 5
0
def get_task_header_ids(p_header):
    header = unpack32to4x8(p_header)
    return header[0], header[1]