-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EEPROM tests for ATtiny2313 are failing #954
Comments
Looks like being an already reported SimulAVR issue: https://savannah.nongnu.org/bugs/?66044. I spent some time with GDB today. The problem is indeed with
In <+20>:
I did not notice any other problems. All registers are properly set, and |
I looked into the instruction decoder in the SimulAVR Git repo. Masking XYZ registers in LD/ST instructions is not supported. The following logic required by the "AVR Instruction Set Manual" is not implemented:
For illustration, this is a simple patch for SimulAVR that allows all eeprom tests to pass. So these failing tests is not an issue with AVR-LibC code. diff --git a/libsim/decoder.cpp b/libsim/decoder.cpp
index 3ea13a6..128e994 100644
--- a/libsim/decoder.cpp
+++ b/libsim/decoder.cpp
@@ -773,7 +773,7 @@ avr_op_LDD_Y::avr_op_LDD_Y(word opcode, AvrDevice *c):
int avr_op_LDD_Y::operator()() {
/* Y is R29:R28 */
- word Y = core->GetRegY();
+ word Y = core->dataAddressMask & core->GetRegY();
core->SetCoreReg(Rd, core->GetRWMem(Y + K));
@@ -787,7 +787,7 @@ avr_op_LDD_Z::avr_op_LDD_Z(word opcode, AvrDevice *c):
int avr_op_LDD_Z::operator()() {
/* Z is R31:R30 */
- word Z = core->GetRegZ();
+ word Z = core->dataAddressMask & core->GetRegZ();
core->SetCoreReg(Rd, core->GetRWMem(Z + K));
@@ -830,7 +830,7 @@ int avr_op_LD_X::operator()() {
/* X is R27:R26 */
word X = core->GetRegX();
- core->SetCoreReg(Rd, core->GetRWMem(X));
+ core->SetCoreReg(Rd, core->GetRWMem(X & core->dataAddressMask));
return (core->flagXMega || core->flagTiny10) ? 1 : 2;
}
@@ -847,9 +847,11 @@ int avr_op_LD_X_decr::operator()() {
/* Perform pre-decrement */
X--;
- core->SetCoreReg(Rd, core->GetRWMem(X));
+ core->SetCoreReg(Rd, core->GetRWMem(X & core->dataAddressMask));
core->SetCoreReg(26, X & 0xff);
- core->SetCoreReg(27, (X >> 8) & 0xff);
+ if (core->dataAddressMask > 0xff) {
+ core->SetCoreReg(27, (X >> 8) & 0xff);
+ }
return core->flagTiny10 ? 3 : 2;
}
@@ -865,10 +867,12 @@ int avr_op_LD_X_incr::operator()() {
avr_error( "Result of operation is undefined" );
/* Perform post-increment */
- core->SetCoreReg(Rd, core->GetRWMem(X));
+ core->SetCoreReg(Rd, core->GetRWMem(X & core->dataAddressMask));
X++;
core->SetCoreReg(26, X & 0xff);
- core->SetCoreReg(27, (X >> 8) & 0xff);
+ if (core->dataAddressMask > 0xff) {
+ core->SetCoreReg(27, (X >> 8) & 0xff);
+ }
return core->flagXMega ? 1 : 2;
}
@@ -885,9 +889,11 @@ int avr_op_LD_Y_decr::operator()() {
/* Perform pre-decrement */
Y--;
- core->SetCoreReg(Rd, core->GetRWMem(Y));
+ core->SetCoreReg(Rd, core->GetRWMem(Y & core->dataAddressMask));
core->SetCoreReg(28, Y & 0xff);
- core->SetCoreReg(29, (Y >> 8) & 0xff);
+ if (core->dataAddressMask > 0xff) {
+ core->SetCoreReg(29, (Y >> 8) & 0xff);
+ }
return core->flagTiny10 ? 3 : 2;
}
@@ -903,10 +909,12 @@ int avr_op_LD_Y_incr::operator()() {
avr_error( "Result of operation is undefined" );
/* Perform post-increment */
- core->SetCoreReg(Rd, core->GetRWMem(Y));
+ core->SetCoreReg(Rd, core->GetRWMem(Y & core->dataAddressMask));
Y++;
core->SetCoreReg(28, Y & 0xff);
- core->SetCoreReg(29, (Y >> 8) & 0xff);
+ if (core->dataAddressMask > 0xff) {
+ core->SetCoreReg(29, (Y >> 8) & 0xff);
+ }
return core->flagXMega ? 1 : 2;
}
@@ -922,10 +930,12 @@ int avr_op_LD_Z_incr::operator()() {
avr_error( "Result of operation is undefined" );
/* Perform post-increment */
- core->SetCoreReg(Rd, core->GetRWMem(Z));
+ core->SetCoreReg(Rd, core->GetRWMem(Z & core->dataAddressMask));
Z++;
core->SetCoreReg(30, Z & 0xff);
- core->SetCoreReg(31, (Z >> 8) & 0xff);
+ if (core->dataAddressMask > 0xff) {
+ core->SetCoreReg(31, (Z >> 8) & 0xff);
+ }
return core->flagXMega ? 1 : 2;
}
@@ -942,9 +952,11 @@ int avr_op_LD_Z_decr::operator()() {
/* Perform pre-decrement */
Z--;
- core->SetCoreReg(Rd, core->GetRWMem(Z));
+ core->SetCoreReg(Rd, core->GetRWMem(Z & core->dataAddressMask));
core->SetCoreReg(30, Z & 0xff);
- core->SetCoreReg(31, (Z >> 8) & 0xff);
+ if (core->dataAddressMask > 0xff) {
+ core->SetCoreReg(31, (Z >> 8) & 0xff);
+ }
return core->flagTiny10 ? 3 : 2;
}
@@ -1522,7 +1534,7 @@ avr_op_STD_Y::avr_op_STD_Y(word opcode, AvrDevice *c):
int avr_op_STD_Y::operator()() {
/* Y is R29:R28 */
- unsigned int Y = core->GetRegY();
+ unsigned int Y = core->dataAddressMask & core->GetRegY();
core->SetRWMem(Y + K, core->GetCoreReg(R1));
@@ -1536,7 +1548,7 @@ avr_op_STD_Z::avr_op_STD_Z(word opcode, AvrDevice *c):
int avr_op_STD_Z::operator()() {
/* Z is R31:R30 */
- int Z = core->GetRegZ();
+ int Z = core->dataAddressMask & core->GetRegZ();
core->SetRWMem(Z + K, core->GetCoreReg(R1));
@@ -1565,7 +1577,7 @@ int avr_op_ST_X::operator()() {
/* X is R27:R26 */
word X = core->GetRegX();
- core->SetRWMem(X, core->GetCoreReg(R1));
+ core->SetRWMem(X & core->dataAddressMask, core->GetCoreReg(R1));
return (core->flagXMega || core->flagTiny10) ? 1 : 2;
}
@@ -1583,8 +1595,10 @@ int avr_op_ST_X_decr::operator()() {
/* Perform pre-decrement */
X--;
core->SetCoreReg(26, X & 0xff);
- core->SetCoreReg(27, (X >> 8) & 0xff);
- core->SetRWMem(X, core->GetCoreReg(R1));
+ if (core->dataAddressMask > 0xff) {
+ core->SetCoreReg(27, (X >> 8) & 0xff);
+ }
+ core->SetRWMem(X & core->dataAddressMask, core->GetCoreReg(R1));
return 2;
}
@@ -1599,12 +1613,14 @@ int avr_op_ST_X_incr::operator()() {
if (R1 == 26 || R1 == 27)
avr_error( "Result of operation is undefined" );
- core->SetRWMem(X, core->GetCoreReg(R1));
+ core->SetRWMem(X & core->dataAddressMask, core->GetCoreReg(R1));
/* Perform post-increment */
X++;
core->SetCoreReg(26, X & 0xff);
- core->SetCoreReg(27, (X >> 8) & 0xff);
+ if (core->dataAddressMask > 0xff) {
+ core->SetCoreReg(27, (X >> 8) & 0xff);
+ }
return (core->flagXMega || core->flagTiny10) ? 1 : 2;
}
@@ -1622,8 +1638,10 @@ int avr_op_ST_Y_decr::operator()() {
/* Perform pre-decrement */
Y--;
core->SetCoreReg(28, Y & 0xff);
- core->SetCoreReg(29, (Y >> 8) & 0xff);
- core->SetRWMem(Y, core->GetCoreReg(R1));
+ if (core->dataAddressMask > 0xff) {
+ core->SetCoreReg(29, (Y >> 8) & 0xff);
+ }
+ core->SetRWMem(Y & core->dataAddressMask, core->GetCoreReg(R1));
return 2;
}
@@ -1638,12 +1656,14 @@ int avr_op_ST_Y_incr::operator()() {
if (R1 == 28 || R1 == 29)
avr_error( "Result of operation is undefined" );
- core->SetRWMem(Y, core->GetCoreReg(R1));
+ core->SetRWMem(Y & core->dataAddressMask, core->GetCoreReg(R1));
/* Perform post-increment */
Y++;
core->SetCoreReg(28, Y & 0xff);
- core->SetCoreReg(29, (Y >> 8) & 0xff);
+ if (core->dataAddressMask > 0xff) {
+ core->SetCoreReg(29, (Y >> 8) & 0xff);
+ }
return (core->flagXMega || core->flagTiny10) ? 1 : 2;
}
@@ -1661,8 +1681,10 @@ int avr_op_ST_Z_decr::operator()() {
/* Perform pre-decrement */
Z--;
core->SetCoreReg(30, Z & 0xff);
- core->SetCoreReg(31, (Z >> 8) & 0xff);
- core->SetRWMem(Z, core->GetCoreReg(R1));
+ if (core->dataAddressMask > 0xff) {
+ core->SetCoreReg(31, (Z >> 8) & 0xff);
+ }
+ core->SetRWMem(Z & core->dataAddressMask, core->GetCoreReg(R1));
return 2;
}
@@ -1677,12 +1699,14 @@ int avr_op_ST_Z_incr::operator()() {
if (R1 == 30 || R1 == 31)
avr_error( "Result of operation is undefined" );
- core->SetRWMem(Z, core->GetCoreReg(R1));
+ core->SetRWMem(Z & core->dataAddressMask, core->GetCoreReg(R1));
/* Perform post-increment */
Z++;
core->SetCoreReg(30, Z & 0xff);
- core->SetCoreReg(31, (Z >> 8) & 0xff);
+ if (core->dataAddressMask > 0xff) {
+ core->SetCoreReg(31, (Z >> 8) & 0xff);
+ }
return (core->flagXMega || core->flagTiny10) ? 1 : 2;
} |
I am getting fails from running the EEPROM tests for ATtiny2313, for example execute in
tests/simulate
:The fails are independent of compiler version, and they can be fixed by
etc.
This means the
eeprom_read_blraw
routine malfunctions whenXH
contains garbage. Maybe it is just a simulavr issue?Using SimulAVR v1.1.0.
The text was updated successfully, but these errors were encountered: