RE: Misaligned read/write of memory by GDB
"Dave Brolley" <[email protected]>
| Newsgroups | gmane.comp.emulators.sid.devel |
|---|---|
| Organization | Red Hat Canada |
| Message-ID | <[email protected]> |
In response to Frank's comments, I have removed my previous patch and committed this one in its place. The cache component now handles misaligned accesses except those which cross a cache line boundary. For those it returns bus::misaligned The GDB component reverts to the byte-at-a-time method of access if bus::misaligned is returned from downstream. Dave
sid-gdbalign.ChangeLog
(application/octet-stream, 640 B) - not displayed
sid-gdbalign.patch.txt
(text/plain, 6.5 KB)
Index: sid/component/gdb/gdb.cxx
===================================================================
RCS file: /cvs/src/src/sid/component/gdb/gdb.cxx,v
retrieving revision 1.11
diff -c -p -r1.11 gdb.cxx
*** sid/component/gdb/gdb.cxx 22 Mar 2004 21:27:23 -0000 1.11
--- sid/component/gdb/gdb.cxx 1 Jul 2004 16:46:54 -0000
*************** gdb::process_get_exp_regs ()
*** 532,538 ****
// Helper functions
template <class Type>
! void
read_bus_word(gdbserv* gdbserv,
sid::bus* bus,
host_int_4 address,
--- 532,538 ----
// Helper functions
template <class Type>
! bus::status
read_bus_word(gdbserv* gdbserv,
sid::bus* bus,
host_int_4 address,
*************** read_bus_word(gdbserv* gdbserv,
*** 545,557 ****
for (unsigned i=0; i < sizeof(typename Type::value_type); i++)
gdbserv_output_byte (gdbserv, value.read_byte(i));
}
! else
gdbserv_output_string (gdbserv, "E05");
}
template <class Type>
! void
write_bus_word(gdbserv* gdbserv,
int binary,
sid::bus* bus,
--- 545,559 ----
for (unsigned i=0; i < sizeof(typename Type::value_type); i++)
gdbserv_output_byte (gdbserv, value.read_byte(i));
}
! // misaligned will be handled by the caller
! else if (s != bus::misaligned)
gdbserv_output_string (gdbserv, "E05");
+ return s;
}
template <class Type>
! bus::status
write_bus_word(gdbserv* gdbserv,
int binary,
sid::bus* bus,
*************** write_bus_word(gdbserv* gdbserv,
*** 572,581 ****
}
bus::status s = bus->write (address, value);
! if (s == bus::ok)
! ; // No response means "OK"
else
gdbserv_output_string (gdbserv, "E05");
}
--- 574,584 ----
}
bus::status s = bus->write (address, value);
! if (s == bus::ok || s == bus::misaligned)
! ; // No response means "OK" -- misaligned will be handled by the caller
else
gdbserv_output_string (gdbserv, "E05");
+ return s;
}
*************** gdb::process_get_mem (struct gdbserv_reg
*** 620,642 ****
}
host_int_4 addr = addr8; // truncate
if (len==1 && e==endian_big)
! read_bus_word (gdbserv, memory, addr, big_int_1());
else if (len==1 && e==endian_little)
! read_bus_word (gdbserv, memory, addr, little_int_1());
else if (len==2 && e==endian_big)
! read_bus_word (gdbserv, memory, addr, big_int_2());
else if (len==2 && e==endian_little)
! read_bus_word (gdbserv, memory, addr, little_int_2());
else if (len==4 && e==endian_big)
! read_bus_word (gdbserv, memory, addr, big_int_4());
else if (len==4 && e==endian_little)
! read_bus_word (gdbserv, memory, addr, little_int_4());
else if (len==8 && e==endian_big)
! read_bus_word (gdbserv, memory, addr, big_int_8());
else if (len==8 && e==endian_little)
! read_bus_word (gdbserv, memory, addr, little_int_8());
! else if (e==endian_little)
{
for (unsigned long i=0; i<len; i++)
read_bus_word (gdbserv, memory, addr + i, little_int_1());
--- 623,651 ----
}
host_int_4 addr = addr8; // truncate
+ bus::status b = bus::misaligned;
if (len==1 && e==endian_big)
! b = read_bus_word (gdbserv, memory, addr, big_int_1());
else if (len==1 && e==endian_little)
! b = read_bus_word (gdbserv, memory, addr, little_int_1());
else if (len==2 && e==endian_big)
! b = read_bus_word (gdbserv, memory, addr, big_int_2());
else if (len==2 && e==endian_little)
! b = read_bus_word (gdbserv, memory, addr, little_int_2());
else if (len==4 && e==endian_big)
! b = read_bus_word (gdbserv, memory, addr, big_int_4());
else if (len==4 && e==endian_little)
! b = read_bus_word (gdbserv, memory, addr, little_int_4());
else if (len==8 && e==endian_big)
! b = read_bus_word (gdbserv, memory, addr, big_int_8());
else if (len==8 && e==endian_little)
! b = read_bus_word (gdbserv, memory, addr, little_int_8());
!
! if (b != bus::misaligned)
! return;
!
! // Unaligned access or unsupported size.
! if (e==endian_little)
{
for (unsigned long i=0; i<len; i++)
read_bus_word (gdbserv, memory, addr + i, little_int_1());
*************** gdb::process_set_mem (struct gdbserv_reg
*** 700,722 ****
}
host_int_4 addr = addr8; // truncate
if (len==1 && e==endian_big)
! write_bus_word (gdbserv, binary, memory, addr, big_int_1());
! else if (len==1 && e==endian_little)
! write_bus_word (gdbserv, binary, memory, addr, little_int_1());
! else if (len==2 && e==endian_big)
! write_bus_word (gdbserv, binary, memory, addr, big_int_2());
! else if (len==2 && e==endian_little)
! write_bus_word (gdbserv, binary, memory, addr, little_int_2());
! else if (len==4 && e==endian_big)
! write_bus_word (gdbserv, binary, memory, addr, big_int_4());
! else if (len==4 && e==endian_little)
! write_bus_word (gdbserv, binary, memory, addr, little_int_4());
! else if (len==8 && e==endian_big)
! write_bus_word (gdbserv, binary, memory, addr, big_int_8());
! else if (len==8 && e==endian_little)
! write_bus_word (gdbserv, binary, memory, addr, little_int_8());
! else if (e==endian_little)
{
for (unsigned long i=0; i<len; i++)
write_bus_word (gdbserv, binary, memory, addr + i, little_int_1());
--- 709,737 ----
}
host_int_4 addr = addr8; // truncate
+ bus::status b = bus::misaligned;
if (len==1 && e==endian_big)
! b = write_bus_word (gdbserv, binary, memory, addr, big_int_1());
! if (len==1 && e==endian_little)
! b = write_bus_word (gdbserv, binary, memory, addr, little_int_1());
! if (len==2 && e==endian_big)
! b = write_bus_word (gdbserv, binary, memory, addr, big_int_2());
! if (len==2 && e==endian_little)
! b = write_bus_word (gdbserv, binary, memory, addr, little_int_2());
! if (len==4 && e==endian_big)
! b = write_bus_word (gdbserv, binary, memory, addr, big_int_4());
! if (len==4 && e==endian_little)
! b = write_bus_word (gdbserv, binary, memory, addr, little_int_4());
! if (len==8 && e==endian_big)
! b = write_bus_word (gdbserv, binary, memory, addr, big_int_8());
! if (len==8 && e==endian_little)
! b = write_bus_word (gdbserv, binary, memory, addr, little_int_8());
!
! if (b != bus::misaligned)
! return;
!
! // Unaligned access or unsupported size.
! if (e==endian_little)
{
for (unsigned long i=0; i<len; i++)
write_bus_word (gdbserv, binary, memory, addr + i, little_int_1());