| 74 | |
| 75 | |
| 76 | class M6502(Architecture): |
| 77 | name = "6502" |
| 78 | address_size = 2 |
| 79 | default_int_size = 1 |
| 80 | instr_alignment = 1 |
| 81 | max_instr_length = 3 |
| 82 | regs:Dict[RegisterName, RegisterInfo] = { |
| 83 | a_reg: RegisterInfo(a_reg, 1), x_reg: RegisterInfo(x_reg, 1), |
| 84 | y_reg: RegisterInfo(y_reg, 1), s_reg: RegisterInfo(s_reg, 1) |
| 85 | } |
| 86 | stack_pointer = "s" |
| 87 | flags = [c_flag, z_flag, i_flag, d_flag, b_flag, v_flag, s_flag] |
| 88 | flag_write_types = [FlagWriteTypeName("*"), FlagWriteTypeName("czs"), FlagWriteTypeName("zvs"),FlagWriteTypeName( "zs")] |
| 89 | flag_roles = { |
| 90 | c_flag: FlagRole.CarryFlagWithInvertedSubtractRole, |
| 91 | z_flag: FlagRole.ZeroFlagRole, v_flag: FlagRole.OverflowFlagRole, s_flag: FlagRole.NegativeSignFlagRole |
| 92 | } |
| 93 | flags_required_for_flag_condition = { |
| 94 | LowLevelILFlagCondition.LLFC_UGE: [c_flag], LowLevelILFlagCondition.LLFC_ULT: [c_flag], |
| 95 | LowLevelILFlagCondition.LLFC_E: [z_flag], LowLevelILFlagCondition.LLFC_NE: [z_flag], |
| 96 | LowLevelILFlagCondition.LLFC_NEG: [s_flag], LowLevelILFlagCondition.LLFC_POS: [s_flag] |
| 97 | } |
| 98 | flags_written_by_flag_write_type = { |
| 99 | "*": ["c", "z", "v", "s"], "czs": ["c", "z", "s"], "zvs": ["z", "v", "s"], "zs": ["z", "s"] |
| 100 | } |
| 101 | |
| 102 | InstructionIL:Dict[Mnemonic, Callable[[LowLevelILFunction, Optional[ExpressionIndex]], Optional[ExpressionIndex]]] = { |
| 103 | Mnemonic("adc"):lambda il, operand: il.set_reg(1, a_reg, il.add_carry(1, il.reg(1, a_reg), operand, il.flag(c_flag), flags=FlagName("*"))), |
| 104 | Mnemonic("asl"):lambda il, operand: il.store(1, operand, il.shift_left(1, il.load(1, operand), il.const(1, 1), flags=FlagName("czs"))), |
| 105 | Mnemonic("asl@"):lambda il, operand: il.set_reg(1, a_reg, il.shift_left(1, operand, il.const(1, 1), flags=FlagName("czs"))), |
| 106 | Mnemonic("and"):lambda il, operand: il.set_reg(1, a_reg, il.and_expr(1, il.reg(1, a_reg), operand, flags=FlagName("zs"))), |
| 107 | Mnemonic("bcc"):lambda il, operand: M6502.cond_branch(il, il.flag_condition(LowLevelILFlagCondition.LLFC_ULT), operand), |
| 108 | Mnemonic("bcs"):lambda il, operand: M6502.cond_branch(il, il.flag_condition(LowLevelILFlagCondition.LLFC_UGE), operand), |
| 109 | Mnemonic("beq"):lambda il, operand: M6502.cond_branch(il, il.flag_condition(LowLevelILFlagCondition.LLFC_E), operand), |
| 110 | Mnemonic("bit"):lambda il, operand: il.and_expr(1, il.reg(1, a_reg), operand, flags=FlagName("czs")), |
| 111 | Mnemonic("bmi"):lambda il, operand: M6502.cond_branch(il, il.flag_condition(LowLevelILFlagCondition.LLFC_NEG), operand), |
| 112 | Mnemonic("bne"):lambda il, operand: M6502.cond_branch(il, il.flag_condition(LowLevelILFlagCondition.LLFC_NE), operand), |
| 113 | Mnemonic("bpl"):lambda il, operand: M6502.cond_branch(il, il.flag_condition(LowLevelILFlagCondition.LLFC_POS), operand), |
| 114 | Mnemonic("brk"):lambda il, operand: il.system_call(), |
| 115 | Mnemonic("bvc"):lambda il, operand: M6502.cond_branch(il, il.not_expr(0, il.flag(v_flag)), operand), |
| 116 | Mnemonic("bvs"):lambda il, operand: M6502.cond_branch(il, il.flag(v_flag), operand), |
| 117 | Mnemonic("clc"):lambda il, operand: il.set_flag(c_flag, il.const(0, 0)), |
| 118 | Mnemonic("cld"):lambda il, operand: il.set_flag(d_flag, il.const(0, 0)), |
| 119 | Mnemonic("cli"):lambda il, operand: il.set_flag(i_flag, il.const(0, 0)), |
| 120 | Mnemonic("clv"):lambda il, operand: il.set_flag(v_flag, il.const(0, 0)), |
| 121 | Mnemonic("cmp"):lambda il, operand: il.sub(1, il.reg(1, a_reg), operand, flags=FlagName("czs")), |
| 122 | Mnemonic("cpx"):lambda il, operand: il.sub(1, il.reg(1, x_reg), operand, flags=FlagName("czs")), |
| 123 | Mnemonic("cpy"):lambda il, operand: il.sub(1, il.reg(1, y_reg), operand, flags=FlagName("czs")), |
| 124 | Mnemonic("dec"):lambda il, operand: il.store(1, operand, il.sub(1, il.load(1, operand), il.const(1, 1), flags=FlagName("zs"))), |
| 125 | Mnemonic("dex"):lambda il, operand: il.set_reg(1, x_reg, il.sub(1, il.reg(1, x_reg), il.const(1, 1), flags=FlagName("zs"))), |
| 126 | Mnemonic("dey"):lambda il, operand: il.set_reg(1, y_reg, il.sub(1, il.reg(1, y_reg), il.const(1, 1), flags=FlagName("zs"))), |
| 127 | Mnemonic("eor"):lambda il, operand: il.set_reg(1, a_reg, il.xor_expr(1, il.reg(1, a_reg), operand, flags=FlagName("zs"))), |
| 128 | Mnemonic("inc"):lambda il, operand: il.store(1, operand, il.add(1, il.load(1, operand), il.const(1, 1), flags=FlagName("zs"))), |
| 129 | Mnemonic("inx"):lambda il, operand: il.set_reg(1, x_reg, il.add(1, il.reg(1, x_reg), il.const(1, 1), flags=FlagName("zs"))), |
| 130 | Mnemonic("iny"):lambda il, operand: il.set_reg(1, y_reg, il.add(1, il.reg(1, y_reg), il.const(1, 1), flags=FlagName("zs"))), |
| 131 | Mnemonic("jmp"):lambda il, operand: M6502.jump(il, operand), |
| 132 | Mnemonic("jsr"):lambda il, operand: il.call(operand), |
| 133 | Mnemonic("lda"):lambda il, operand: il.set_reg(1, a_reg, operand, flags=FlagName("zs")), |
nothing calls this directly
no test coverage detected