示例#1
0
 def execute(self, processor):
     if processor.condition_passed():
         if processor.registers.current_mode_is_hyp():
             raise UndefinedInstructionException()
         elif (not processor.registers.current_mode_is_not_user() or
               processor.registers.current_instr_set() == InstrSet.THUMB_EE):
             print('unpredictable')
         else:
             address = (processor.registers.get(self.n)
                        if self.increment else sub(processor.registers.get(self.n), 8, 32))
             if self.word_higher:
                 address = add(address, 4, 32)
             new_pc_value = processor.mem_a_get(address, 4)
             spsr_value = processor.mem_a_get(add(address, 4, 32), 4)
             if self.wback:
                 processor.registers.set(
                     self.n,
                     (add(processor.registers.get(self.n), 8, 32)
                      if self.increment else sub(processor.registers.get(self.n), 8, 32))
                 )
             processor.registers.cpsr_write_by_instr(spsr_value, 0b1111, True)
             if (processor.registers.cpsr.m == 0b11010 and
                     processor.registers.cpsr.j and
                     processor.registers.cpsr.t):
                 print('unpredictable')
             else:
                 processor.branch_write_pc(new_pc_value)
示例#2
0
 def execute(self, processor):
     if processor.condition_passed():
         if processor.registers.current_mode_is_hyp():
             raise UndefinedInstructionException()
         elif (processor.registers.current_mode_is_user_or_system()
               or processor.registers.current_instr_set()
               == InstrSet.THUMB_EE):
             print('unpredictable')
         else:
             length = (4 * bit_count(self.registers, 1, 16)) + 4
             address = processor.registers.get(
                 self.n) if self.increment else sub(
                     processor.registers.get(self.n), length, 32)
             if self.word_higher:
                 address = add(address, 4, 32)
             for i in range(15):
                 if bit_at(self.registers, i):
                     processor.registers.set(
                         i, processor.mem_a_get(address, 4))
                     address = add(address, 4, 32)
             new_pc_value = processor.mem_a_get(address, 4)
             if self.wback and not bit_at(self.registers, self.n):
                 processor.registers.set(
                     self.n, (add(processor.registers.get(
                         self.n), length, 32) if self.increment else sub(
                             processor.registers.get(self.n), length, 32)))
             if self.wback and bit_at(self.registers, self.n):
                 processor.registers.set(self.n, 0x00000000)  # unknown
             processor.registers.cpsr_write_by_instr(
                 processor.registers.get_spsr(), 0b1111, True)
             if processor.registers.cpsr.m == 0b11010 and processor.registers.cpsr.j and processor.registers.cpsr.t:
                 print('unpredictable')
             else:
                 processor.branch_write_pc(new_pc_value)
示例#3
0
 def execute(self, processor):
     if processor.condition_passed():
         if processor.registers.current_mode_is_hyp():
             raise UndefinedInstructionException()
         elif (not processor.registers.current_mode_is_not_user() or
               processor.registers.current_instr_set() == InstrSet.InstrSet_ThumbEE):
             print "unpredictable"
         else:
             address = (processor.registers.get(self.n)
                        if self.increment
                        else sub(processor.registers.get(self.n), BitArray(bin="1000"), 32))
             if self.word_higher:
                 address = add(address, BitArray(bin="100"), 32)
             new_pc_value = processor.mem_a_get(address, 4)
             spsr_value = processor.mem_a_get(add(address, BitArray(bin="100"), 32), 4)
             if self.wback:
                 processor.registers.set(
                     self.n,
                     (add(processor.registers.get(self.n), BitArray(bin="1000"), 32)
                      if self.increment
                      else sub(processor.registers.get(self.n), BitArray(bin="1000"), 32))
                 )
             processor.registers.cpsr_write_by_instr(spsr_value, BitArray(bin="1111"), True)
             if (processor.registers.cpsr.get_m() == "0b11010" and
                     processor.registers.cpsr.get_j() and
                     processor.registers.cpsr.get_t()):
                 print "unpredictable"
             else:
                 processor.branch_write_pc(new_pc_value)
示例#4
0
 def execute(self, processor):
     if processor.condition_passed():
         if processor.registers.current_mode_is_hyp():
             raise UndefinedInstructionException()
         elif processor.registers.current_mode_is_user_or_system():
             print('unpredictable')
         elif self.mode == 0b11010:
             print('unpredictable')
         else:
             if not processor.registers.is_secure():
                 if self.mode == 0b10110 or (self.mode == 0b10001 and
                                             processor.registers.nsacr.rfr):
                     print('unpredictable')
             base = processor.registers.get_rmode(13, self.mode)
             address = base if self.increment else sub(base, 8, 32)
             if self.word_higher:
                 address = add(address, 0b100, 32)
             processor.mem_a_set(address, 4, processor.registers.get_lr())
             processor.mem_a_set(add(address, 4, 32), 4,
                                 processor.registers.get_spsr())
             if self.wback:
                 processor.registers.set_rmode(
                     13, self.mode,
                     add(base, 8, 32) if self.increment else sub(
                         base, 8, 32))
示例#5
0
 def from_bitarray(instr, processor):
     coproc = substring(instr, 11, 8)
     rt = substring(instr, 15, 12)
     if substring(coproc, 3, 1) == 0b101:
         raise UndefinedInstructionException()
     else:
         return MrcMrc2A2(instr, cp=coproc, t=rt)
示例#6
0
 def execute(self, processor):
     if self.is_enterx:
         if processor.registers.current_mode_is_hyp():
             raise UndefinedInstructionException()
         else:
             processor.registers.select_instr_set(InstrSet.THUMB_EE)
     else:
         processor.registers.select_instr_set(InstrSet.THUMB)
 def from_bitarray(instr, processor):
     n = 14
     imm32 = substring(instr, 7, 0)
     if processor.registers.current_mode_is_hyp():
         raise UndefinedInstructionException()
     elif ((processor.in_it_block() and not processor.last_in_it_block())
           or processor.registers.current_instr_set() == InstrSet.THUMB_EE):
         print('unpredictable')
     else:
         return SubsPcLrThumbT1(instr, imm32=imm32, n=n)
示例#8
0
 def from_bitarray(instr, processor):
     coproc = substring(instr, 11, 8)
     rt = substring(instr, 15, 12)
     rt2 = substring(instr, 19, 16)
     if substring(coproc, 3, 1) == 0b101:
         raise UndefinedInstructionException()
     elif rt == 15 or rt2 == 15 or (rt == 13 or rt2 == 13):
         print('unpredictable')
     else:
         return McrrMcrr2T2(instr, cp=coproc, t=rt, t2=rt2)
 def from_bitarray(instr, processor):
     imm8 = substring(instr, 7, 0)
     coproc = substring(instr, 11, 8)
     rn = substring(instr, 19, 16)
     wback = bit_at(instr, 21)
     add = bit_at(instr, 23)
     index = bit_at(instr, 24)
     imm32 = imm8 << 2
     if substring(instr, 24, 21) == 0b0000:
         raise UndefinedInstructionException()
     else:
         return LdcLdc2ImmediateT1(instr, cp=coproc, n=rn, add=add, imm32=imm32, index=index, wback=wback)
示例#10
0
 def from_bitarray(instr, processor):
     imm32 = substring(instr, 7, 0)
     rt = substring(instr, 15, 12)
     rn = substring(instr, 19, 16)
     add = True
     post_index = False
     if rn == 0b1111:
         raise UndefinedInstructionException()
     elif rt in (13, 15):
         print('unpredictable')
     else:
         return StrtT1(instr, register_form=False, add=add, post_index=post_index, t=rt, n=rn, imm32=imm32)
示例#11
0
 def execute(self, processor):
     if processor.condition_passed():
         if processor.registers.current_mode_is_hyp():
             raise UndefinedInstructionException()
         elif processor.registers.current_mode_is_user_or_system():
             print('unpredictable')
         else:
             operand2 = shift(processor.registers.get(
                 self.m), 32, self.shift_t, self.shift_n,
                              processor.registers.cpsr.c
                              ) if self.register_form else self.imm32
             if self.opcode == 0b0000:
                 result = processor.registers.get(self.n) & operand2
             elif self.opcode == 0b0001:
                 result = processor.registers.get(self.n) ^ operand2
             elif self.opcode == 0b0010:
                 result = add_with_carry(processor.registers.get(self.n),
                                         bit_not(operand2, 32), 1)[0]
             elif self.opcode == 0b0011:
                 result = add_with_carry(
                     bit_not(processor.registers.get(self.n), 32), operand2,
                     1)[0]
             elif self.opcode == 0b0100:
                 result = add_with_carry(processor.registers.get(self.n),
                                         operand2, 0)[0]
             elif self.opcode == 0b0101:
                 result = add_with_carry(processor.registers.get(self.n),
                                         operand2,
                                         processor.registers.cpsr.c)[0]
             elif self.opcode == 0b0110:
                 result = add_with_carry(processor.registers.get(self.n),
                                         bit_not(operand2, 32),
                                         processor.registers.cpsr.c)[0]
             elif self.opcode == 0b0111:
                 result = add_with_carry(
                     bit_not(processor.registers.get(self.n), 32), operand2,
                     processor.registers.cpsr.c)[0]
             elif self.opcode == 0b1100:
                 result = processor.registers.get(self.n) | operand2
             elif self.opcode == 0b1101:
                 result = operand2
             elif self.opcode == 0b1110:
                 result = processor.registers.get(self.n) & bit_not(
                     operand2, 32)
             elif self.opcode == 0b1111:
                 result = bit_not(operand2, 32)
             processor.registers.cpsr_write_by_instr(
                 processor.registers.get_spsr(), 0b1111, True)
             if processor.registers.cpsr.m == 0b11010 and processor.registers.cpsr.j and processor.registers.cpsr.t:
                 print('unpredictable')
             else:
                 processor.branch_write_pc(result)
 def from_bitarray(instr, processor):
     imm32 = substring(instr, 7, 0)
     wback = bit_at(instr, 8)
     add = bit_at(instr, 9)
     index = bit_at(instr, 10)
     rt = substring(instr, 15, 12)
     rn = substring(instr, 19, 16)
     if not index and not wback:
         raise UndefinedInstructionException()
     elif (wback and rn == rt) or (rt == 15 and processor.in_it_block() and not processor.last_in_it_block()):
         print('unpredictable')
     else:
         return LdrImmediateThumbT4(instr, add=add, wback=wback, index=index, t=rt, n=rn, imm32=imm32)
示例#13
0
 def from_bitarray(instr, processor):
     imm8 = substring(instr, 7, 0)
     coproc = substring(instr, 11, 8)
     index = bit_at(instr, 24)
     add = bit_at(instr, 23)
     wback = bit_at(instr, 21)
     if substring(coproc, 3, 1) == 0b101:
         raise UndefinedInstructionException()
     elif wback:
         print('unpredictable')
     else:
         imm32 = imm8 << 2
         return LdcLdc2LiteralA2(instr, cp=coproc, add=add, imm32=imm32, index=index)
示例#14
0
 def from_bitarray(instr, processor):
     imm8 = substring(instr, 7, 0)
     coproc = substring(instr, 11, 8)
     w = bit_at(instr, 21)
     add = bit_at(instr, 23)
     index = bit_at(instr, 24)
     d = bit_at(instr, 22)
     if not index and not add and not d and not w:
         raise UndefinedInstructionException()
     elif w:
         print('unpredictable')
     else:
         imm32 = imm8 << 2
         return LdcLdc2LiteralA1(instr, cp=coproc, add=add, imm32=imm32, index=index)
示例#15
0
 def from_bitarray(instr, processor):
     imm8 = substring(instr, 7, 0)
     coproc = substring(instr, 11, 8)
     rn = substring(instr, 19, 16)
     wback = bit_at(instr, 21)
     add = bit_at(instr, 23)
     index = bit_at(instr, 24)
     imm32 = imm8 << 2
     if substring(instr, 24, 21) == 0b0000:
         raise UndefinedInstructionException()
     elif rn == 15:
         print('unpredictable')
     else:
         return StcStc2T1(instr, cp=coproc, n=rn, add=add, imm32=imm32, index=index, wback=wback)
示例#16
0
 def execute(self, processor):
     if processor.condition_passed():
         if processor.registers.current_mode_is_hyp():
             raise UndefinedInstructionException()
         elif processor.registers.current_mode_is_user_or_system():
             print "unpredictable"
         else:
             length = 4 * self.registers.count(1)
             address = processor.registers.get(self.n) if self.increment else sub(
                     processor.registers.get(self.n),
                     BitArray(uint=length, length=32), 32)
             if self.word_higher:
                 address = add(address, BitArray(bin="100"), 32)
             for i in xrange(15):
                 if self.registers[15 - i]:
                     processor.registers.set_rmode(i, BitArray(bin="10000"), processor.mem_a_get(address, 4))
                     address = add(address, BitArray(bin="100"), 32)
示例#17
0
 def from_bitarray(instr, processor):
     imm8 = substring(instr, 7, 0)
     coproc = substring(instr, 11, 8)
     add = bit_at(instr, 23)
     index = bit_at(instr, 24)
     imm32 = imm8 << 2
     if substring(instr, 23, 21) == 0b0000:
         raise UndefinedInstructionException()
     elif bit_at(instr, 21) or (
             not index
             and processor.registers.current_instr_set() != InstrSet.ARM):
         print('unpredictable')
     else:
         return LdcLdc2LiteralT1(instr,
                                 cp=coproc,
                                 add=add,
                                 imm32=imm32,
                                 index=index)
示例#18
0
 def execute(self, processor):
     if processor.condition_passed():
         if processor.registers.current_mode_is_hyp():
             raise UndefinedInstructionException()
         elif processor.registers.current_mode_is_user_or_system():
             print('unpredictable')
         else:
             length = 4 * bit_count(self.registers, 1, 16)
             address = processor.registers.get(
                 self.n) if self.increment else sub(
                     processor.registers.get(self.n), length, 32)
             if self.word_higher:
                 address = add(address, 4, 32)
             for i in range(15):
                 if bit_at(self.registers, i):
                     processor.registers.set_rmode(
                         i, 0b10000, processor.mem_a_get(address, 4))
                     address = add(address, 4, 32)
 def from_bitarray(instr, processor):
     imm32 = substring(instr, 11, 0)
     rt = substring(instr, 15, 12)
     rn = substring(instr, 19, 16)
     index = True
     add = True
     wback = False
     if rn == 0b1111:
         raise UndefinedInstructionException()
     elif rt in (13, 15):
         print('unpredictable')
     else:
         return StrhImmediateThumbT2(instr,
                                     add=add,
                                     wback=wback,
                                     index=index,
                                     t=rt,
                                     n=rn,
                                     imm32=imm32)
示例#20
0
 def from_bitarray(instr, processor):
     imm8 = substring(instr, 7, 0)
     coproc = substring(instr, 11, 8)
     rn = substring(instr, 19, 16)
     wback = bit_at(instr, 21)
     add = bit_at(instr, 23)
     index = bit_at(instr, 24)
     d = bit_at(instr, 22)
     if not index and not add and not d and not wback:
         raise UndefinedInstructionException()
     else:
         imm32 = imm8 << 2
         return LdcLdc2ImmediateA1(instr,
                                   cp=coproc,
                                   n=rn,
                                   add=add,
                                   imm32=imm32,
                                   index=index,
                                   wback=wback)
示例#21
0
 def execute(self, processor):
     if processor.condition_passed():
         if processor.registers.current_mode_is_hyp():
             raise UndefinedInstructionException()
         elif (processor.registers.current_mode_is_user_or_system()
               or processor.registers.current_instr_set()
               == InstrSet.InstrSet_ThumbEE):
             print "unpredictable"
         else:
             length = 4 * self.registers.count(1) + 4
             address = processor.registers.get(
                 self.n) if self.increment else sub(
                     processor.registers.get(self.n),
                     BitArray(uint=length, length=32), 32)
             if self.word_higher:
                 address = add(address, BitArray(bin="100"), 32)
             for i in xrange(15):
                 if self.registers[15 - i]:
                     processor.registers.set(
                         i, processor.mem_a_get(address, 4))
                     address = add(address, BitArray(bin="100"), 32)
             new_pc_value = processor.mem_a_get(address, 4)
             if self.wback and not self.registers[15 - self.n]:
                 processor.registers.set(
                     self.n, (add(processor.registers.get(self.n),
                                  BitArray(uint=length, length=32), 32)
                              if self.increment else sub(
                                  processor.registers.get(self.n),
                                  BitArray(uint=length, length=32), 32)))
             if self.wback and self.registers[15 - self.n]:
                 processor.registers.set(self.n,
                                         BitArray(length=32))  # unknown
             processor.registers.cpsr_write_by_instr(
                 processor.registers.get_spsr(), BitArray(bin="1111"), True)
             if (processor.registers.cpsr.get_m() == "0b11010"
                     and processor.registers.cpsr.get_j()
                     and processor.registers.cpsr.get_t()):
                 print "unpredictable"
             else:
                 processor.branch_write_pc(new_pc_value)