Exemplo n.º 1
0
 def execute(self, processor):
     if processor.condition_passed():
         rotated = ror(processor.registers.get(self.m), 32, self.rotation)
         temp_rd = set_substring(0, 15, 0, substring(rotated, 7, 0))
         temp_rd = set_substring(temp_rd, 31, 16,
                                 substring(rotated, 23, 16))
         processor.registers.set(self.d, temp_rd)
Exemplo n.º 2
0
 def execute(self, processor):
     if processor.condition_passed():
         n = processor.registers.get(self.n)
         m = processor.registers.get(self.m)
         diff1 = substring(n, 15, 0) - substring(m, 15, 0)
         diff2 = substring(n, 31, 16) - substring(m, 31, 16)
         d = set_substring(0, 15, 0, unsigned_sat(diff1, 16))
         d = set_substring(d, 31, 16, unsigned_sat(diff2, 16))
         processor.registers.set(self.d, d)
Exemplo n.º 3
0
 def execute(self, processor):
     if processor.condition_passed():
         n = processor.registers.get(self.n)
         m = processor.registers.get(self.m)
         sum_ = substring(n, 15, 0) + substring(m, 31, 16)
         diff = substring(n, 31, 16) - substring(m, 15, 0)
         d = set_substring(0, 15, 0, substring(sum_, 16, 1))
         d = set_substring(d, 31, 16, substring(diff, 16, 1))
         processor.registers.set(self.d, d)
Exemplo n.º 4
0
 def execute(self, processor):
     if processor.condition_passed():
         result = 0
         m = processor.registers.get(self.m)
         result = set_substring(result, 31, 24, substring(m, 7, 0))
         result = set_substring(result, 23, 16, substring(m, 15, 8))
         result = set_substring(result, 15, 8, substring(m, 23, 16))
         result = set_substring(result, 7, 0, substring(m, 31, 24))
         processor.registers.set(self.d, result)
Exemplo n.º 5
0
 def execute(self, processor):
     if processor.condition_passed():
         n = processor.registers.get(self.n)
         m = processor.registers.get(self.m)
         diff = to_signed(substring(n, 15, 0), 16) - to_signed(substring(m, 31, 16), 16)
         sum_ = to_signed(substring(n, 31, 16), 16) + to_signed(substring(m, 15, 0), 16)
         d = set_substring(0, 15, 0, to_unsigned(diff, 17) >> 1)
         d = set_substring(d, 31, 16, to_unsigned(sum_, 17) >> 1)
         processor.registers.set(self.d, d)
Exemplo n.º 6
0
 def execute(self, processor):
     if processor.condition_passed():
         rotated = ror(processor.registers.get(self.m), 32, self.rotation)
         n = processor.registers.get(self.n)
         lower_half = add(substring(n, 15, 0), substring(rotated, 7, 0), 16)
         temp_rd = set_substring(0, 15, 0, lower_half)
         upper_half = add(substring(n, 31, 16), substring(rotated, 23, 16),
                          16)
         temp_rd = set_substring(temp_rd, 31, 16, upper_half)
         processor.registers.set(self.d, temp_rd)
Exemplo n.º 7
0
 def execute(self, processor):
     if processor.condition_passed():
         n = processor.registers.get(self.n)
         m = processor.registers.get(self.m)
         sum1 = to_signed(substring(n, 15, 0), 16) + to_signed(
             substring(m, 15, 0), 16)
         sum2 = to_signed(substring(n, 31, 16), 16) + to_signed(
             substring(m, 31, 16), 16)
         d = set_substring(0, 15, 0, signed_sat(sum1, 16))
         d = set_substring(d, 31, 16, signed_sat(sum2, 16))
         processor.registers.set(self.d, d)
Exemplo n.º 8
0
 def execute(self, processor):
     if processor.condition_passed():
         n = processor.registers.get(self.n)
         m = processor.registers.get(self.m)
         sum_ = to_signed(substring(n, 15, 0), 16) + to_signed(substring(m, 31, 16), 16)
         diff = to_signed(substring(n, 31, 16), 16) - to_signed(substring(m, 15, 0), 16)
         d = set_substring(0, 15, 0, to_unsigned(sum_, 16))
         d = set_substring(d, 31, 16, to_unsigned(diff, 16))
         processor.registers.set(self.d, d)
         ge = 0b11 if sum_ >= 0 else 00
         ge = set_substring(ge, 3, 2, 0b11 if diff >= 0 else 00)
         processor.registers.cpsr.ge = ge
Exemplo n.º 9
0
 def execute(self, processor):
     if processor.condition_passed():
         n = processor.registers.get(self.n)
         m = processor.registers.get(self.m)
         sum_ = substring(n, 15, 0) + substring(m, 31, 16)
         diff = substring(n, 31, 16) - substring(m, 15, 0)
         d = set_substring(0, 15, 0, lower_chunk(sum_, 16))
         d = set_substring(d, 31, 16, lower_chunk(diff, 16))
         processor.registers.set(self.d, d)
         ge = 0b11 if sum_ >= 0x10000 else 00
         ge = set_substring(ge, 3, 2, 0b11 if diff >= 0 else 00)
         processor.registers.cpsr.ge = ge
Exemplo n.º 10
0
 def execute(self, processor):
     if processor.condition_passed():
         n = processor.registers.get(self.n)
         m = processor.registers.get(self.m)
         diff1 = to_signed(substring(n, 7, 0), 8) - to_signed(substring(m, 7, 0), 8)
         diff2 = to_signed(substring(n, 15, 8), 8) - to_signed(substring(m, 15, 8), 8)
         diff3 = to_signed(substring(n, 23, 16), 8) - to_signed(substring(m, 23, 16), 8)
         diff4 = to_signed(substring(n, 31, 24), 8) - to_signed(substring(m, 31, 24), 8)
         d = set_substring(0, 7, 0, to_unsigned(diff1, 9) >> 1)
         d = set_substring(d, 15, 8, to_unsigned(diff2, 9) >> 1)
         d = set_substring(d, 23, 16, to_unsigned(diff3, 9) >> 1)
         d = set_substring(d, 31, 24, to_unsigned(diff4, 9) >> 1)
         processor.registers.set(self.d, d)
Exemplo n.º 11
0
 def execute(self, processor):
     if processor.condition_passed():
         n = processor.registers.get(self.n)
         m = processor.registers.get(self.m)
         diff1 = substring(n, 7, 0) - substring(m, 7, 0)
         diff2 = substring(n, 15, 8) - substring(m, 15, 8)
         diff3 = substring(n, 23, 16) - substring(m, 23, 16)
         diff4 = substring(n, 31, 24) - substring(m, 31, 24)
         d = set_substring(0, 7, 0, substring(diff1, 8, 1))
         d = set_substring(d, 15, 8, substring(diff2, 8, 1))
         d = set_substring(d, 23, 16, substring(diff3, 8, 1))
         d = set_substring(d, 31, 24, substring(diff4, 8, 1))
         processor.registers.set(self.d, d)
Exemplo n.º 12
0
 def execute(self, processor):
     if processor.condition_passed():
         n = processor.registers.get(self.n)
         m = processor.registers.get(self.m)
         sum1 = substring(n, 7, 0) + substring(m, 7, 0)
         sum2 = substring(n, 15, 8) + substring(m, 15, 8)
         sum3 = substring(n, 23, 16) + substring(m, 23, 16)
         sum4 = substring(n, 31, 24) + substring(m, 31, 24)
         d = set_substring(0, 7, 0, substring(sum1, 8, 1))
         d = set_substring(d, 15, 8, substring(sum2, 8, 1))
         d = set_substring(d, 23, 16, substring(sum3, 8, 1))
         d = set_substring(d, 31, 24, substring(sum4, 8, 1))
         processor.registers.set(self.d, d)
Exemplo n.º 13
0
 def cpsr_write_by_instr(self, value, bytemask, is_excp_return):
     privileged = self.current_mode_is_not_user()
     nmfi = self.sctlr.nmfi
     if bit_at(bytemask, 3):
         self.cpsr.value = set_substring(self.cpsr.value, 31, 27,
                                         substring(value, 31, 27))
         if is_excp_return:
             self.cpsr.value = set_substring(self.cpsr.value, 26, 24,
                                             substring(value, 26, 24))
     if bit_at(bytemask, 2):
         self.cpsr.value = set_substring(self.cpsr.value, 19, 16,
                                         substring(value, 19, 16))
     if bit_at(bytemask, 1):
         if is_excp_return:
             self.cpsr.value = set_substring(self.cpsr.value, 15, 10,
                                             substring(value, 15, 10))
         self.cpsr.value = set_bit_at(self.cpsr.value, 9, bit_at(value, 9))
         if privileged and (self.is_secure() or self.scr.aw
                            or have_virt_ext()):
             self.cpsr.value = set_bit_at(self.cpsr.value, 8,
                                          bit_at(value, 8))
     if bit_at(bytemask, 0):
         if privileged:
             self.cpsr.value = set_bit_at(self.cpsr.value, 7,
                                          bit_at(value, 7))
         if (privileged and (not nmfi or not bit_at(value, 6))
                 and (self.is_secure() or self.scr.fw or have_virt_ext())):
             self.cpsr.value = set_bit_at(self.cpsr.value, 6,
                                          bit_at(value, 6))
         if is_excp_return:
             self.cpsr.value = set_bit_at(self.cpsr.value, 5,
                                          bit_at(value, 5))
         if privileged:
             value_mode = substring(value, 4, 0)
             if self.bad_mode(value_mode):
                 print('unpredictable')
             else:
                 if not self.is_secure() and value_mode == 0b10110:
                     print('unpredictable')
                 elif not self.is_secure(
                 ) and value_mode == 0b10001 and self.nsacr.rfr:
                     print('unpredictable')
                 elif not self.scr.ns and value_mode == 0b11010:
                     print('unpredictable')
                 elif not self.is_secure(
                 ) and self.cpsr.m != 0b11010 and value_mode == 0b11010:
                     print('unpredictable')
                 elif self.cpsr.m == 0b11010 and value_mode != 0b11010 and not is_excp_return:
                     print('unpredictable')
                 else:
                     self.cpsr.m = value_mode
Exemplo n.º 14
0
 def execute(self, processor):
     if processor.condition_passed():
         ge = processor.registers.cpsr.ge
         n = processor.registers.get(self.n)
         m = processor.registers.get(self.m)
         temp_rd = set_substring(0, 7, 0,
                                 substring(n if bit_at(ge, 0) else m, 7, 0))
         temp_rd = set_substring(
             temp_rd, 15, 8, substring(n if bit_at(ge, 1) else m, 15, 8))
         temp_rd = set_substring(
             temp_rd, 23, 16, substring(n if bit_at(ge, 2) else m, 23, 16))
         temp_rd = set_substring(
             temp_rd, 31, 24, substring(n if bit_at(ge, 3) else m, 31, 24))
         processor.registers.set(self.d, temp_rd)
Exemplo n.º 15
0
 def execute(self, processor):
     if processor.condition_passed():
         if self.msbit >= self.lsbit:
             temp_rd = processor.registers.get(self.d)
             processor.registers.set(
                 self.d, set_substring(temp_rd, self.msbit, self.lsbit, 0))
         else:
             print('unpredictable')
Exemplo n.º 16
0
 def execute(self, processor):
     if processor.condition_passed():
         n = processor.registers.get(self.n)
         m = processor.registers.get(self.m)
         sum1 = to_signed(substring(n, 7, 0), 8) + to_signed(
             substring(m, 7, 0), 8)
         sum2 = to_signed(substring(n, 15, 8), 8) + to_signed(
             substring(m, 15, 8), 8)
         sum3 = to_signed(substring(n, 23, 16), 8) + to_signed(
             substring(m, 23, 16), 8)
         sum4 = to_signed(substring(n, 31, 24), 8) + to_signed(
             substring(m, 31, 24), 8)
         d = set_substring(0, 7, 0, signed_sat(sum1, 8))
         d = set_substring(d, 15, 8, signed_sat(sum2, 8))
         d = set_substring(d, 23, 16, signed_sat(sum3, 8))
         d = set_substring(d, 31, 24, signed_sat(sum4, 8))
         processor.registers.set(self.d, d)
Exemplo n.º 17
0
 def spsr_write_by_instr(self, value, bytemask):
     if self.current_mode_is_user_or_system():
         print('unpredictable')
     spsr = self.get_spsr()
     if bit_at(bytemask, 3):
         spsr = set_substring(spsr, 31, 27, substring(value, 31, 27))
     if bit_at(bytemask, 2):
         spsr = set_substring(spsr, 19, 16, substring(value, 19, 16))
     if bit_at(bytemask, 1):
         spsr = set_substring(spsr, 15, 8, substring(value, 15, 8))
     if bit_at(bytemask, 0):
         spsr = set_substring(spsr, 7, 5, substring(value, 7, 5))
         if self.bad_mode(substring(value, 4, 0)):
             print('unpredictable')
         else:
             spsr = set_substring(spsr, 4, 0, substring(value, 4, 0))
     self.set_spsr(spsr)
Exemplo n.º 18
0
 def it_advance(self):
     if bits_ops.lower_chunk(self.cpsr.it, 3) == 0b000:
         self.cpsr.it = 0
     else:
         itstate = self.cpsr.it
         mask, carry = shift.lsl_c(bits_ops.lower_chunk(itstate, 4), 4, 1)
         condition_state = chain(carry, mask, 4)
         self.cpsr.it = set_substring(itstate, 4, 0, condition_state)
Exemplo n.º 19
0
 def execute(self, processor):
     if processor.condition_passed():
         n = processor.registers.get(self.n)
         m = processor.registers.get(self.m)
         diff1 = substring(n, 7, 0) - substring(m, 7, 0)
         diff2 = substring(n, 15, 8) - substring(m, 15, 8)
         diff3 = substring(n, 23, 16) - substring(m, 23, 16)
         diff4 = substring(n, 31, 24) - substring(m, 31, 24)
         d = set_substring(0, 7, 0, lower_chunk(diff1, 8))
         d = set_substring(d, 15, 8, lower_chunk(diff2, 8))
         d = set_substring(d, 23, 16, lower_chunk(diff3, 8))
         d = set_substring(d, 31, 24, lower_chunk(diff4, 8))
         processor.registers.set(self.d, d)
         ge = set_bit_at(0, 0, 0b1 if diff1 >= 0 else 0b0)
         ge = set_bit_at(ge, 1, 0b1 if diff2 >= 0 else 0b0)
         ge = set_bit_at(ge, 2, 0b1 if diff3 >= 0 else 0b0)
         ge = set_bit_at(ge, 3, 0b1 if diff4 >= 0 else 0b0)
         processor.registers.cpsr.ge = ge
Exemplo n.º 20
0
 def execute(self, processor):
     if processor.condition_passed():
         n = processor.registers.get(self.n)
         m = processor.registers.get(self.m)
         sum1 = substring(n, 7, 0) + substring(m, 7, 0)
         sum2 = substring(n, 15, 8) + substring(m, 15, 8)
         sum3 = substring(n, 23, 16) + substring(m, 23, 16)
         sum4 = substring(n, 31, 24) + substring(m, 31, 24)
         d = set_substring(0, 7, 0, lower_chunk(sum1, 8))
         d = set_substring(d, 15, 8, lower_chunk(sum2, 8))
         d = set_substring(d, 23, 16, lower_chunk(sum3, 8))
         d = set_substring(d, 31, 24, lower_chunk(sum4, 8))
         processor.registers.set(self.d, d)
         ge = set_bit_at(0, 0, 0b1 if sum1 >= 0x100 else 0b0)
         ge = set_bit_at(ge, 1, 0b1 if sum2 >= 0x100 else 0b0)
         ge = set_bit_at(ge, 2, 0b1 if sum3 >= 0x100 else 0b0)
         ge = set_bit_at(ge, 3, 0b1 if sum4 >= 0x100 else 0b0)
         processor.registers.cpsr.ge = ge
Exemplo n.º 21
0
 def execute(self, processor):
     if processor.condition_passed():
         n = processor.registers.get(self.n)
         m = processor.registers.get(self.m)
         sum1 = to_signed(substring(n, 7, 0), 8) + to_signed(substring(m, 7, 0), 8)
         sum2 = to_signed(substring(n, 15, 8), 8) + to_signed(substring(m, 15, 8), 8)
         sum3 = to_signed(substring(n, 23, 16), 8) + to_signed(substring(m, 23, 16), 8)
         sum4 = to_signed(substring(n, 31, 24), 8) + to_signed(substring(m, 31, 24), 8)
         d = set_substring(0, 7, 0, to_unsigned(sum1, 8))
         d = set_substring(d, 15, 8, to_unsigned(sum2, 8))
         d = set_substring(d, 23, 16, to_unsigned(sum3, 8))
         d = set_substring(d, 31, 24, to_unsigned(sum4, 8))
         processor.registers.set(self.d, d)
         ge = set_bit_at(0, 0, 0b1 if sum1 >= 0 else 0b0)
         ge = set_bit_at(ge, 1, 0b1 if sum2 >= 0 else 0b0)
         ge = set_bit_at(ge, 2, 0b1 if sum3 >= 0 else 0b0)
         ge = set_bit_at(ge, 3, 0b1 if sum4 >= 0 else 0b0)
         processor.registers.cpsr.ge = ge
Exemplo n.º 22
0
 def execute(self, processor):
     if processor.condition_passed():
         if self.read_spsr:
             if processor.registers.current_mode_is_user_or_system():
                 print('unpredictable')
             else:
                 processor.registers.set(self.d,
                                         processor.registers.get_spsr())
         else:
             processor.registers.set(
                 self.d, processor.registers.cpsr.value
                 & 0b11111000111111110000001111011111)
             if not processor.registers.current_mode_is_not_user():
                 temp_register = processor.registers.get(self.d)
                 temp_register = set_substring(temp_register, 4, 0,
                                               0)  # unknown
                 temp_register = set_substring(temp_register, 9, 6,
                                               0)  # unknown
                 processor.registers.set(self.d, temp_register)
Exemplo n.º 23
0
 def execute(self, processor):
     if processor.condition_passed():
         a = set_substring(processor.registers.get(self.d_lo), 63, 32, processor.registers.get(self.d_hi))
         result = processor.registers.get(self.n) * processor.registers.get(self.m) + a
         processor.registers.set(self.d_hi, substring(result, 63, 32))
         processor.registers.set(self.d_lo, substring(result, 31, 0))
         if self.setflags:
             processor.registers.cpsr.n = bit_at(result, 63)
             processor.registers.cpsr.z = 0 if result else 1
             if arch_version() == 4:
                 processor.registers.cpsr.c = 0  # unknown
                 processor.registers.cpsr.v = 0  # unknown
Exemplo n.º 24
0
 def execute(self, processor):
     if processor.condition_passed():
         operand2 = ror(processor.registers.get(self.m), 32,
                        16) if self.m_swap else processor.registers.get(
                            self.m)
         n = processor.registers.get(self.n)
         product1 = to_signed(substring(n, 15, 0), 16) * to_signed(
             substring(operand2, 15, 0), 16)
         product2 = to_signed(substring(n, 31, 16), 16) * to_signed(
             substring(operand2, 31, 16), 16)
         d_total = to_signed(
             set_substring(processor.registers.get(self.d_lo), 63, 32,
                           processor.registers.get(self.d_hi)), 64)
         result = to_unsigned(product1 - product2 + d_total, 64)
         processor.registers.set(self.d_hi, substring(result, 63, 32))
         processor.registers.set(self.d_lo, substring(result, 31, 0))
Exemplo n.º 25
0
 def execute(self, processor):
     if processor.condition_passed():
         n = processor.registers.get(self.n)
         operand1 = substring(n, 31, 16) if self.n_high else substring(
             n, 15, 0)
         m = processor.registers.get(self.m)
         operand2 = substring(m, 31, 16) if self.m_high else substring(
             m, 15, 0)
         d_total = to_signed(
             set_substring(processor.registers.get(self.d_lo), 63, 32,
                           processor.registers.get(self.d_hi)), 64)
         result = to_unsigned(
             to_signed(operand1, 16) * to_signed(operand2, 16) + d_total,
             64)
         processor.registers.set(self.d_hi, substring(result, 63, 32))
         processor.registers.set(self.d_lo, substring(result, 31, 0))
Exemplo n.º 26
0
 def execute(self, processor):
     if processor.condition_passed():
         a = to_signed(
             set_substring(processor.registers.get(self.d_lo), 63, 32,
                           processor.registers.get(self.d_hi)), 64)
         result = to_signed(
             processor.registers.get(self.n), 32) * to_signed(
                 processor.registers.get(self.m), 32) + a
         f_result = to_unsigned(result, 64)
         processor.registers.set(self.d_hi, substring(f_result, 63, 32))
         processor.registers.set(self.d_lo, substring(f_result, 31, 0))
         if self.setflags:
             processor.registers.cpsr.n = bit_at(f_result, 63)
             processor.registers.cpsr.z = 0 if f_result else 1
             if arch_version() == 4:
                 processor.registers.cpsr.c = 0  # unknown
                 processor.registers.cpsr.v = 0  # unknown
Exemplo n.º 27
0
 def execute(self, processor):
     if processor.registers.current_mode_is_not_user():
         cpsr_val = processor.registers.cpsr.value
         if self.enable:
             if self.affect_a:
                 cpsr_val = set_bit_at(cpsr_val, 8, 0)
             if self.affect_i:
                 cpsr_val = set_bit_at(cpsr_val, 7, 0)
             if self.affect_f:
                 cpsr_val = set_bit_at(cpsr_val, 6, 0)
         if self.disable:
             if self.affect_a:
                 cpsr_val = set_bit_at(cpsr_val, 8, 1)
             if self.affect_i:
                 cpsr_val = set_bit_at(cpsr_val, 7, 1)
             if self.affect_f:
                 cpsr_val = set_bit_at(cpsr_val, 6, 1)
         if self.change_mode:
             cpsr_val = set_substring(cpsr_val, 4, 0, self.mode)
         processor.registers.cpsr_write_by_instr(cpsr_val, 0b1111, False)
Exemplo n.º 28
0
 def execute(self, processor):
     if processor.condition_passed():
         m = processor.registers.get(self.m)
         result = set_substring(0, 31, 8, sign_extend(lower_chunk(m, 8), 8, 24))
         result = set_substring(result, 7, 0, substring(m, 15, 8))
         processor.registers.set(self.d, result)
Exemplo n.º 29
0
 def __setitem__(self, item, value):
     if isinstance(item, int):
         self.value = set_bit_at(self.value, item, value)
         return
     self.value = set_substring(self.value, item.start, item.stop, value)
Exemplo n.º 30
0
 def execute(self, processor):
     if processor.condition_passed():
         processor.registers.set(
             self.d,
             set_substring(processor.registers.get(self.d), 31, 16,
                           self.imm16))