115 unsigned char res = rd + rr +
status->
C;
141 unsigned char res = rd + rr;
175 status->
V = ~(rdh >> 7 & 0x1) & (res >> 15 & 0x1);
178 status->
Z = (res & 0xffff) == 0;
179 status->
C = ~(res >> 15 & 0x1) & (rdh >> 7 & 0x1);
214 unsigned char res = rd &
K;
233 unsigned char res = (rd >> 1) + (rd & 0x80);
270 res = rd & ~(1 <<
Kbit);
272 res = rd | (1 <<
Kbit);
349 int k = (
KH << 16) + K_lsb;
380 byte res = 0xff - rd;
432 bool Z = (res & 0xff) == 0;
536 unsigned char rampz = 0;
553 unsigned char rampz = 0;
575 unsigned char rampz = 0;
611 unsigned char xaddr = 0;
640 word res = resp << 1;
642 status->
Z = (res & 0xffff) == 0;
664 word res = resp << 1;
666 status->
Z = (res & 0xffff) == 0;
667 status->
C = (resp >> 15) & 0x1;
688 word res = resp << 1;
690 status->
Z = (res & 0xffff) == 0;
691 status->
C = (resp >> 15) & 0x1;
703 unsigned int pc =
core->
PC;
765 core->
PC = (
K << 16) + K_lsb - 1;
845 if (
Rd == 26 ||
Rd == 27)
846 avr_error(
"Result of operation is undefined" );
864 if (
Rd == 26 ||
Rd == 27)
865 avr_error(
"Result of operation is undefined" );
883 if (
Rd == 28 ||
Rd == 29)
884 avr_error(
"Result of operation is undefined" );
902 if (
Rd == 28 ||
Rd == 29)
903 avr_error(
"Result of operation is undefined" );
921 if (
Rd == 30 ||
Rd == 31)
922 avr_error(
"Result of operation is undefined" );
940 if (
Rd == 30 ||
Rd == 31)
941 avr_error(
"Result of operation is undefined" );
1004 byte res = (rd >> 1) & 0x7f;
1010 status->
Z = (res & 0xff) == 0;
1030 Rs((
get_rr_4(opcode) - 16) << 1) {}
1043 status(c->status) {}
1051 status->
Z = (res & 0xffff) == 0;
1052 status->
C = (res >> 15) & 0x1;
1071 sword res = rd * rr;
1073 status->
Z = (res & 0xffff) == 0;
1074 status->
C = (res >> 15) & 0x1;
1093 sword res = rd * rr;
1095 status->
Z = (res & 0xffff) == 0;
1096 status->
C = (res >> 15) & 0x1;
1113 byte res = (0x0 - rd) & 0xff;
1115 status->
H = ((res >> 3) | (rd >> 3)) & 0x1;
1138 status(c->status) {}
1231 status(c->status) {}
1255 status(c->status) {}
1295 if((res & 0xff) != 0)
1323 if((res & 0xff) != 0)
1401 status(c->status) {}
1413 word rd = (rdh << 8) + rdl;
1416 status->
V = (rdh >> 7 & 0x1) & ~(res >> 15 & 0x1);
1417 status->
N = (res >> 15) & 0x1;
1419 status->
Z = (res & 0xffff) == 0;
1420 status->
C = (res >> 15 & 0x1) & ~(rdh >> 7 & 0x1);
1479 MCUCR *mcucr = (MCUCR *)avr_core_get_vdev_by_name(
core,
"MCUCR" );
1482 avr_error(
"MCUCR register not installed" );
1485 if ( mcucr_get_bit(mcucr, bit_SE) )
1487 if ( mcucr_get_bit(mcucr, bit_SM) == 0 )
1490 avr_core_set_sleep_mode(
core, SLEEP_MODE_IDLE);
1495 avr_core_set_sleep_mode(
core, SLEEP_MODE_PWR_DOWN);
1506 unsigned char xaddr = 0;
1580 if (
R1 == 26 ||
R1 == 27)
1581 avr_error(
"Result of operation is undefined" );
1599 if (
R1 == 26 ||
R1 == 27)
1600 avr_error(
"Result of operation is undefined" );
1619 if (
R1 == 28 ||
R1 == 29)
1620 avr_error(
"Result of operation is undefined" );
1638 if (
R1 == 28 ||
R1 == 29)
1639 avr_error(
"Result of operation is undefined" );
1658 if (
R1 == 30 ||
R1 == 31)
1659 avr_error(
"Result of operation is undefined" );
1677 if (
R1 == 30 ||
R1 == 31)
1678 avr_error(
"Result of operation is undefined" );
1694 status(c->status) {}
1709 status->
Z = (res & 0xff) == 0;
1734 status->
Z = (res & 0xff) == 0;
1748 byte res = ((rd << 4) & 0xf0) | ((rd >> 4) & 0x0f);
1776 avr_error(
"Illegal opcode '%02x %02x' executed at PC=0x%x (%d)! Simulation terminated!",
1783 byte resb = res >> b & 0x1;
1784 byte rdb = rd >> b & 0x1;
1785 byte rrb = rr >> b & 0x1;
1786 return (rdb & rrb) | (rrb & ~resb) | (~resb & rdb);
1791 byte res7 = res >> 7 & 0x1;
1792 byte rd7 = rd >> 7 & 0x1;
1793 byte rr7 = rr >> 7 & 0x1;
1794 return (rd7 & rr7 & ~res7) | (~rd7 & ~rr7 & res7);
1799 byte resb = res >> b & 0x1;
1800 byte rdb = rd >> b & 0x1;
1801 byte rrb = rr >> b & 0x1;
1802 return (~rdb & rrb) | (rrb & resb) | (resb & ~rdb);
1807 byte res7 = res >> 7 & 0x1;
1808 byte rd7 = rd >> 7 & 0x1;
1809 byte rr7 = rr >> 7 & 0x1;
1810 return (rd7 & ~rr7 & ~res7) | (~rd7 & rr7 & res7);
1815 byte resb = res >> b & 0x1;
1816 byte rdb = rd >> b & 0x1;
1817 byte rrb = rr >> b & 0x1;
1818 return (~rdb & rrb) | (rrb & resb) | (resb & ~rdb);
1823 byte res7 = res >> 7 & 0x1;
1824 byte rd7 = rd >> 7 & 0x1;
1825 byte rr7 = rr >> 7 & 0x1;
1828 return (rd7 & ~rr7 & ~res7) | (~rd7 & rr7 & res7);
1835 if ( (val & (1 << (n-1))) == 0)
1839 mask = (1 << n) - 1;
1840 return -1 * ((~val & mask) + 1);
1846 int reg = ((opcode &
mask_Rd_2) >> 4) & 0x3;
1847 return (reg * 2) + 24;
1853 return ((reg >> 4) & 0x7) + 16;
1859 return ((reg >> 4) & 0xf) + 16;
1865 return ((reg >> 4) & 0x1f);
1881 return (reg & 0xf) + ((reg >> 5) & 0x10);
1887 return ((K >> 4) & 0xf0) + (K & 0xf);
1893 return ((K >> 2) & 0x0030) + (K & 0xf);
1898 return (((opcode &
mask_k_7) >> 3) & 0x7f);
1914 return ((k >> 3) & 0x003e) + (k & 0x1);
1931 int qq = ( ((q >> 1) & 0x1000) + (q & 0x0c00) ) >> 7;
1932 return (qq & 0x0038) + (q & 0x7);
1943 return ((A >> 5) & 0x0030) + (A & 0xf);
1991 case 0x0000:
return new avr_op_NOP(opcode, core);
1992 case 0x9508:
return new avr_op_RET(opcode, core);
1993 case 0x9518:
return new avr_op_RETI(opcode, core);
2000 case 0x95A8:
return new avr_op_WDR(opcode, core);
2007 case 0x1C00:
return new avr_op_ADC(opcode, core);
2008 case 0x0C00:
return new avr_op_ADD(opcode, core);
2009 case 0x2000:
return new avr_op_AND(opcode, core);
2010 case 0x1400:
return new avr_op_CP(opcode, core);
2011 case 0x0400:
return new avr_op_CPC(opcode, core);
2012 case 0x1000:
return new avr_op_CPSE(opcode, core);
2013 case 0x2400:
return new avr_op_EOR(opcode, core);
2014 case 0x2C00:
return new avr_op_MOV(opcode, core);
2020 case 0x2800:
return new avr_op_OR(opcode, core);
2021 case 0x0800:
return new avr_op_SBC(opcode, core);
2022 case 0x1800:
return new avr_op_SUB(opcode, core);
2028 case 0x9405:
return new avr_op_ASR(opcode, core);
2029 case 0x9400:
return new avr_op_COM(opcode, core);
2030 case 0x940A:
return new avr_op_DEC(opcode, core);
2041 case 0x9403:
return new avr_op_INC(opcode, core);
2042 case 0x9000:
return new avr_op_LDS(opcode, core);
2094 case 0x9406:
return new avr_op_LSR(opcode, core);
2095 case 0x9401:
return new avr_op_NEG(opcode, core);
2106 case 0x9407:
return new avr_op_ROR(opcode, core);
2107 case 0x9200:
return new avr_op_STS(opcode, core);
2147 case 0x9402:
return new avr_op_SWAP(opcode, core);
2153 case 0x7000:
return new avr_op_ANDI(opcode, core);
2154 case 0x3000:
return new avr_op_CPI(opcode, core);
2155 case 0xE000:
return new avr_op_LDI(opcode, core);
2156 case 0x6000:
return new avr_op_ORI(opcode, core);
2157 case 0x4000:
return new avr_op_SBCI(opcode, core);
2158 case 0x5000:
return new avr_op_SUBI(opcode, core);
2164 case 0xF800:
return new avr_op_BLD(opcode, core);
2165 case 0xFA00:
return new avr_op_BST(opcode, core);
2166 case 0xFC00:
return new avr_op_SBRC(opcode, core);
2167 case 0xFE00:
return new avr_op_SBRS(opcode, core);
2173 case 0xF400:
return new avr_op_BRBC(opcode, core);
2174 case 0xF000:
return new avr_op_BRBS(opcode, core);
2208 case 0x9488:
return new avr_op_BCLR(opcode, core);
2209 case 0x9408:
return new avr_op_BSET(opcode, core);
2230 case 0x9800:
return new avr_op_CBI(opcode, core);
2231 case 0x9A00:
return new avr_op_SBI(opcode, core);
2232 case 0x9900:
return new avr_op_SBIC(opcode, core);
2233 case 0x9B00:
return new avr_op_SBIS(opcode, core);
2239 case 0xB000:
return new avr_op_IN(opcode, core);
2240 case 0xB800:
return new avr_op_OUT(opcode, core);
2247 case 0xC000:
return new avr_op_RJMP(opcode, core);
int operator()()
Performs instruction.
avr_op_CPC(word opcode, AvrDevice *c)
Basic AVR device, contains the core functionality.
int operator()()
Performs instruction.
int operator()()
Performs instruction.
int operator()()
Performs instruction.
avr_op_LPM(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
virtual unsigned char GetModifiedRHi() const
If this instruction modifies a pair of R0-R31 registers then ...
int operator()()
Performs instruction.
int operator()()
Performs instruction.
avr_op_BRBC(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
static int get_compare_carry(byte res, byte rd, byte rr, int b)
avr_op_CBI(word opcode, AvrDevice *c)
avr_op_SPM(word opcode, AvrDevice *c)
avr_op_ORI(word opcode, AvrDevice *c)
virtual unsigned char GetModifiedR() const
If this instruction modifies a R0-R31 register then return its number, otherwise -1.
avr_op_ST_Z_incr(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
int operator()()
Performs instruction.
bool flagEIJMPInstructions
EICALL and EIJMP instructions are available (only on some devices with bigger flash) ...
int operator()()
Performs instruction.
avr_op_SBIW(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
int operator()()
Performs instruction.
int operator()()
Performs instruction.
static int get_add_overflow(byte res, byte rd, byte rr)
avr_op_SBI(word opcode, AvrDevice *c)
avr_op_EIJMP(word opcode, AvrDevice *c)
avr_op_RCALL(word opcode, AvrDevice *c)
avr_op_MUL(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
AddressExtensionRegister * rampz
RAMPZ address extension register.
unsigned GetRegZ(void)
Get value of Z register (16bit)
int operator()()
Performs instruction.
int operator()()
Performs instruction.
int operator()()
Performs instruction.
avr_op_BST(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
virtual unsigned char GetModifiedR() const
If this instruction modifies a R0-R31 register then return its number, otherwise -1.
avr_op_JMP(word opcode, AvrDevice *c)
avr_op_RETI(word opcode, AvrDevice *c)
static int get_A_5(word opcode)
avr_op_SLEEP(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
avr_op_SBCI(word opcode, AvrDevice *c)
avr_op_RJMP(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
int operator()()
Performs instruction.
avr_op_LDD_Y(word opcode, AvrDevice *c)
avr_op_INC(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
avr_op_LDI(word opcode, AvrDevice *c)
unsigned int ReadMemWord(unsigned int addr)
int operator()()
Performs instruction.
avr_op_COM(word opcode, AvrDevice *c)
bool flagJMPInstructions
CALL and JMP instructions are available (only on devices with bigger flash)
int operator()()
Performs instruction.
avr_op_DEC(word opcode, AvrDevice *c)
avr_op_ST_X_decr(word opcode, AvrDevice *c)
bool SetIORegBit(unsigned addr, unsigned bitaddr)
Set a bit value to lower IO register (without offset of 0x20!)
bool flagTiny10
core is a tiny4/5/9/10, change used clocks on some instructions and disables instructions ...
int operator()()
Performs instruction.
avr_op_ASR(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
int operator()()
Performs instruction.
avr_op_NEG(word opcode, AvrDevice *c)
bool SetRWMem(unsigned addr, unsigned char val)
Set a value to RW memory cell.
int operator()()
Performs instruction.
avr_op_SUBI(word opcode, AvrDevice *c)
bool ClearIORegBit(unsigned addr, unsigned bitaddr)
Clear a bit value to lower IO register (without offset of 0x20!)
int operator()()
Performs instruction.
avr_op_OR(word opcode, AvrDevice *c)
avr_op_BRBS(word opcode, AvrDevice *c)
avr_op_AND(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
static int n_bit_unsigned_to_signed(unsigned int val, int n)
avr_op_CPI(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
bool flagIJMPInstructions
ICALL and IJMP instructions are available (not on attiny1x devices)
bool flagLPMInstructions
LPM and SPM instructions are available (not on some tiny devices)
int operator()()
Performs instruction.
static int get_sreg_bit(word opcode)
int operator()()
Performs instruction.
virtual void Push(unsigned char val)=0
Pushs one byte to stack.
int operator()()
Performs instruction.
avr_op_ADC(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
avr_op_ELPM_Z(word opcode, AvrDevice *c)
static int get_compare_overflow(byte res, byte rd, byte rr)
static int get_rd_3(word opcode)
int operator()()
Performs instruction.
avr_op_SBRC(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
static byte get_K_6(word opcode)
avr_op_PUSH(word opcode, AvrDevice *c)
static int get_A_6(word opcode)
int operator()()
Performs instruction.
avr_op_NOP(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
avr_op_ESPM(word opcode, AvrDevice *c)
avr_op_LD_X(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
avr_op_FMUL(word opcode, AvrDevice *c)
unsigned char GetRegVal()
avr_op_BLD(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
int operator()()
Performs instruction.
avr_op_POP(word opcode, AvrDevice *c)
const unsigned int PC_size
avr_op_SBRS(word opcode, AvrDevice *c)
unsigned char GetRWMem(unsigned addr)
Get a value of RW memory cell.
avr_op_OUT(word opcode, AvrDevice *c)
avr_op_ST_Y_decr(word opcode, AvrDevice *c)
avr_op_RET(word opcode, AvrDevice *c)
std::vector< DecodedInstruction * > DecodedMem
int operator()()
Performs instruction.
static int get_rr_5(word opcode)
int operator()()
Performs instruction.
bool SetIOReg(unsigned addr, unsigned char val)
Set a value to IO register (without offset of 0x20!)
avr_op_ST_Y_incr(word opcode, AvrDevice *c)
avr_op_ADD(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
virtual unsigned char GetModifiedR() const
If this instruction modifies a R0-R31 register then return its number, otherwise -1.
avr_op_EOR(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
int operator()()
Performs instruction.
avr_op_FMULS(word opcode, AvrDevice *c)
avr_op_ROR(word opcode, AvrDevice *c)
avr_op_LPM_Z_incr(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
avr_op_ADIW(word opcode, AvrDevice *c)
bool flagIWInstructions
ADIW and SBIW instructions are available (not on most tiny's!)
bool flagTiny1x
core is a tiny1x (but not tiny10!), change used clocks on some instructions and disables instructions...
avr_op_ANDI(word opcode, AvrDevice *c)
avr_op_EICALL(word opcode, AvrDevice *c)
bool flagMULInstructions
(F)MULxx instructions are available
int operator()()
Performs instruction.
avr_op_IJMP(word opcode, AvrDevice *c)
avr_op_SBC(word opcode, AvrDevice *c)
virtual void PushAddr(unsigned long addr)=0
Pushs a address to stack.
int operator()()
Performs instruction.
int operator()()
Performs instruction.
virtual unsigned char GetModifiedR() const
If this instruction modifies a R0-R31 register then return its number, otherwise -1.
int operator()()
Performs instruction.
virtual unsigned char GetModifiedRHi() const
If this instruction modifies a pair of R0-R31 registers then ...
unsigned GetRegX(void)
Get value of X register (16bit)
int operator()()
Performs instruction.
Base class of core instruction.
avr_op_ELPM_Z_incr(word opcode, AvrDevice *c)
static int get_k_12(word opcode)
int operator()()
Performs instruction.
static int get_rr_3(word opcode)
int operator()()
Performs instruction.
avr_op_LD_Y_incr(word opcode, AvrDevice *c)
avr_op_BSET(word opcode, AvrDevice *c)
avr_op_BCLR(word opcode, AvrDevice *c)
bool flagXMega
core is a XMEGA device, change used clocks on some instructions
int operator()()
Performs instruction.
avr_op_CP(word opcode, AvrDevice *c)
static int get_rr_4(word opcode)
int operator()()
Performs instruction.
static int get_reg_bit(word opcode)
avr_op_FMULSU(word opcode, AvrDevice *c)
avr_op_STD_Z(word opcode, AvrDevice *c)
avr_op_LDD_Z(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
int operator()()
Performs instruction.
avr_op_ELPM(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
avr_op_SBIC(word opcode, AvrDevice *c)
unsigned char GetIOReg(unsigned addr)
Get a value from IO register (without offset of 0x20!)
int operator()()
Performs instruction.
int operator()()
Performs instruction.
int operator()()
Performs instruction.
virtual unsigned char Pop()=0
Pops one byte from stack.
virtual unsigned char GetModifiedR() const
If this instruction modifies a R0-R31 register then return its number, otherwise -1.
avr_op_STS(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
unsigned GetRegY(void)
Get value of Y register (16bit)
unsigned char ReadMem(unsigned int addr)
avr_op_BREAK(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
avr_op_MULSU(word opcode, AvrDevice *c)
virtual unsigned long PopAddr()=0
Pops a address from stack.
int operator()()
Performs instruction.
int operator()()
Performs instruction.
int operator()()
Performs instruction.
static int get_add_carry(byte res, byte rd, byte rr, int b)
avr_op_LSR(word opcode, AvrDevice *c)
avr_op_SUB(word opcode, AvrDevice *c)
avr_op_LDS(word opcode, AvrDevice *c)
avr_op_LD_X_decr(word opcode, AvrDevice *c)
static int get_rd_5(word opcode)
unsigned char GetCoreReg(unsigned addr)
Get a value from core register.
avr_op_CPSE(word opcode, AvrDevice *c)
static int get_k_22(word opcode)
int operator()()
Performs instruction.
avr_op_ILLEGAL(word opcode, AvrDevice *c)
avr_op_LPM_Z(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
DecodedInstruction * lookup_opcode(word opcode, AvrDevice *core)
Translates an opcode to a instance of DecodedInstruction.
int operator()()
Performs instruction.
avr_op_SBIS(word opcode, AvrDevice *c)
avr_op_LD_X_incr(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
int SPM_action(unsigned int data, unsigned int xaddr, unsigned int addr)
bool SetCoreReg(unsigned addr, unsigned char val)
Set a value to core register.
avr_op_ICALL(word opcode, AvrDevice *c)
virtual unsigned char GetModifiedR() const
If this instruction modifies a R0-R31 register then return its number, otherwise -1.
avr_op_ST_Z_decr(word opcode, AvrDevice *c)
static int get_rd_4(word opcode)
static int get_sub_carry(byte res, byte rd, byte rr, int b)
static int get_sub_overflow(byte res, byte rd, byte rr)
avr_op_ST_X(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
avr_op_LD_Z_decr(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
int operator()()
Performs instruction.
avr_op_IN(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
int operator()()
Performs instruction.
avr_op_WDR(word opcode, AvrDevice *c)
static int get_k_7(word opcode)
int operator()()
Performs instruction.
static int get_rd_2(word opcode)
int operator()()
Performs instruction.
int operator()()
Performs instruction.
avr_op_LD_Y_decr(word opcode, AvrDevice *c)
avr_op_LD_Z_incr(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
avr_op_MULS(word opcode, AvrDevice *c)
avr_op_ST_X_incr(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
avr_op_MOVW(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
AvrDevice * core
Link to device instance.
int operator()()
Performs instruction.
avr_op_CALL(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
int operator()()
Performs instruction.
AddressExtensionRegister * eind
EIND address extension register.
FlashProgramming * spmRegister
bool flagMOVWInstruction
MOVW instruction is available.
static int get_q(word opcode)
int operator()()
Performs instruction.
int operator()()
Performs instruction.
virtual unsigned char GetModifiedR() const
If this instruction modifies a R0-R31 register then return its number, otherwise -1.
static byte get_K_8(word opcode)
void SetRegVal(unsigned char val)
avr_op_SWAP(word opcode, AvrDevice *c)
int operator()()
Performs instruction.
virtual unsigned char GetModifiedR() const
If this instruction modifies a R0-R31 register then return its number, otherwise -1.
int operator()()
Performs instruction.
virtual unsigned char GetModifiedR() const
If this instruction modifies a R0-R31 register then return its number, otherwise -1.
int operator()()
Performs instruction.
int operator()()
Performs instruction.
avr_op_STD_Y(word opcode, AvrDevice *c)
avr_op_MOV(word opcode, AvrDevice *c)
bool flagELPMInstructions
ELPM instructions are available (only on devices with bigger flash)
void DebugOnJump()
When a call/jump/cond-jump instruction was executed. For debugging.