@@ -89,7 +89,10 @@ void LXAEmulator::emulate(mcontext_t *cpu)
8989 }
9090
9191 addr <<= shift;
92- addr += cpu->gregs [b2];
92+ if (b2 != 0 )
93+ {
94+ addr += cpu->gregs [b2];
95+ }
9396 cpu->gregs [r1] = addr;
9497 }
9598
@@ -104,9 +107,9 @@ class BDEPGEmulator : public InstEmulator
104107
105108BDEPGEmulator::BDEPGEmulator (uint8_t *start)
106109 {
107- r1 = (start[3 ]& 0xF0 ) >> 4 ;
108- r2 = start[3 ]& 0x0F ;
109- r3 = (start[2 ]& 0xF0 ) >> 4 ;
110+ r1 = (start[3 ] & 0xF0 ) >> 4 ;
111+ r2 = start[3 ] & 0x0F ;
112+ r3 = (start[2 ] & 0xF0 ) >> 4 ;
110113 }
111114
112115void BDEPGEmulator::emulate (mcontext_t *cpu)
@@ -139,9 +142,9 @@ class BEXTGEmulator : public InstEmulator
139142
140143BEXTGEmulator::BEXTGEmulator (uint8_t *start)
141144 {
142- r1 = (start[3 ]& 0xF0 ) >> 4 ;
143- r2 = start[3 ]& 0x0F ;
144- r3 = (start[2 ]& 0xF0 ) >> 4 ;
145+ r1 = (start[3 ] & 0xF0 ) >> 4 ;
146+ r2 = start[3 ] & 0x0F ;
147+ r3 = (start[2 ] & 0xF0 ) >> 4 ;
145148 }
146149
147150void BEXTGEmulator::emulate (mcontext_t *cpu)
@@ -152,9 +155,9 @@ void BEXTGEmulator::emulate(mcontext_t *cpu)
152155
153156 for (int k = 0 ; mask; mask <<= 1 , val <<= 1 )
154157 {
155- if (mask & (1ULL << 63 ))
158+ if (mask & (1ULL << 63 ))
156159 {
157- res |= (val & (1ULL << 63 )) >> k;
160+ res |= (val & (1ULL << 63 )) >> k;
158161 k++;
159162 }
160163 }
@@ -173,8 +176,8 @@ class CLZGEmulator : public InstEmulator
173176
174177CLZGEmulator::CLZGEmulator (uint8_t *start)
175178 {
176- r1 = (start[3 ]& 0xF0 ) >> 4 ;
177- r2 = start[3 ]& 0x0F ;
179+ r1 = (start[3 ] & 0xF0 ) >> 4 ;
180+ r2 = start[3 ] & 0x0F ;
178181 }
179182
180183void CLZGEmulator::emulate (mcontext_t *cpu)
@@ -193,8 +196,8 @@ class CTZGEmulator : public InstEmulator
193196
194197CTZGEmulator::CTZGEmulator (uint8_t *start)
195198 {
196- r1 = (start[3 ]& 0xF0 ) >> 4 ;
197- r2 = start[3 ]& 0x0F ;
199+ r1 = (start[3 ] & 0xF0 ) >> 4 ;
200+ r2 = start[3 ] & 0x0F ;
198201 }
199202
200203void CTZGEmulator::emulate (mcontext_t *cpu)
@@ -204,7 +207,9 @@ void CTZGEmulator::emulate(mcontext_t *cpu)
204207
205208InstEmulator *InstEmulator::decode (uint8_t *pc)
206209 {
207- if (pc[-6 ] == 0xE3 && (pc[-1 ]&0xF0 ) == 0x60 && (pc[-1 ]&0x0F ) < 10 )
210+ // Checking the optcode in the first byte and last byte of the instruction to
211+ // see if it is LXA/LLXA instructions (Op-codes '0xE360' to '0xE369')
212+ if ((pc[-6 ] == 0xE3 ) && ((pc[-1 ] & 0xF0 ) == 0x60 ) && ((pc[-1 ] & 0x0F ) < 10 ))
208213 {
209214 return new LXAEmulator (pc-6 );
210215 }
0 commit comments