* [PATCH] Remove some write_register_bytes occurences from i386-tdep.c
@ 2002-08-18 10:18 Mark Kettenis
2002-08-18 10:46 ` Andrew Cagney
0 siblings, 1 reply; 6+ messages in thread
From: Mark Kettenis @ 2002-08-18 10:18 UTC (permalink / raw)
To: gdb-patches
This replaces two write_register_bytes invocations with
write_register_gen. The remaining occurences are in principle
legitimate calls to write_register_bytes, since the intent *is* a
partial update of a register. Of course I can "open code" these calls
if that's desirable.
Checked in.
Mark
Index: ChangeLog
from Mark Kettenis <kettenis@gnu.org>
* i386-tdep.c (i386_do_pop_frame, i386_store_return_value): Call
write_register_gen instead of write_register_bytes.
Index: i386-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/i386-tdep.c,v
retrieving revision 1.81
diff -u -p -r1.81 i386-tdep.c
--- i386-tdep.c 17 Aug 2002 11:39:38 -0000 1.81
+++ i386-tdep.c 18 Aug 2002 17:15:10 -0000
@@ -833,8 +833,7 @@ i386_do_pop_frame (struct frame_info *fr
if (addr)
{
read_memory (addr, regbuf, REGISTER_RAW_SIZE (regnum));
- write_register_bytes (REGISTER_BYTE (regnum), regbuf,
- REGISTER_RAW_SIZE (regnum));
+ write_register_gen (regnum, regbuf);
}
}
write_register (FP_REGNUM, read_memory_integer (fp, 4));
@@ -1003,8 +1002,7 @@ i386_store_return_value (struct type *ty
not exactly how it would happen on the target itself, but
it is the best we can do. */
convert_typed_floating (valbuf, type, buf, builtin_type_i387_ext);
- write_register_bytes (REGISTER_BYTE (FP0_REGNUM), buf,
- FPU_REG_RAW_SIZE);
+ write_register_gen (FP0_REGNUM, buf);
/* Set the top of the floating-point register stack to 7. The
actual value doesn't really matter, but 7 is what a normal
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] Remove some write_register_bytes occurences from i386-tdep.c 2002-08-18 10:18 [PATCH] Remove some write_register_bytes occurences from i386-tdep.c Mark Kettenis @ 2002-08-18 10:46 ` Andrew Cagney 2002-08-18 13:08 ` Andrew Cagney 0 siblings, 1 reply; 6+ messages in thread From: Andrew Cagney @ 2002-08-18 10:46 UTC (permalink / raw) To: Mark Kettenis; +Cc: gdb-patches > This replaces two write_register_bytes invocations with > write_register_gen. The remaining occurences are in principle > legitimate calls to write_register_bytes, since the intent *is* a > partial update of a register. Of course I can "open code" these calls > if that's desirable. > > Checked in. > > Mark > > Index: ChangeLog > from Mark Kettenis <kettenis@gnu.org> > * i386-tdep.c (i386_do_pop_frame, i386_store_return_value): Call > write_register_gen instead of write_register_bytes. Hmm, [change-request bug report] pop_frame and store_return_value are going to need the same treatment as was given to extract_return_value() -- add a regcache parameter so that the registers can be directly written to the register cache. This reduces the reliance on a single global register cache. As for write_register_bytes() can it be avoided? I've just posted ``regcache_cooked_write_with_offset_hack(). But I don't think that hack is right here. Perhaphs a single register read - modify - write function is needed? Andrew > Index: i386-tdep.c > =================================================================== > RCS file: /cvs/src/src/gdb/i386-tdep.c,v > retrieving revision 1.81 > diff -u -p -r1.81 i386-tdep.c > --- i386-tdep.c 17 Aug 2002 11:39:38 -0000 1.81 > +++ i386-tdep.c 18 Aug 2002 17:15:10 -0000 > @@ -833,8 +833,7 @@ i386_do_pop_frame (struct frame_info *fr > if (addr) > { > read_memory (addr, regbuf, REGISTER_RAW_SIZE (regnum)); > - write_register_bytes (REGISTER_BYTE (regnum), regbuf, > - REGISTER_RAW_SIZE (regnum)); > + write_register_gen (regnum, regbuf); > } > } > write_register (FP_REGNUM, read_memory_integer (fp, 4)); > @@ -1003,8 +1002,7 @@ i386_store_return_value (struct type *ty > not exactly how it would happen on the target itself, but > it is the best we can do. */ > convert_typed_floating (valbuf, type, buf, builtin_type_i387_ext); > - write_register_bytes (REGISTER_BYTE (FP0_REGNUM), buf, > - FPU_REG_RAW_SIZE); > + write_register_gen (FP0_REGNUM, buf); > > /* Set the top of the floating-point register stack to 7. The > actual value doesn't really matter, but 7 is what a normal > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Remove some write_register_bytes occurences from i386-tdep.c 2002-08-18 10:46 ` Andrew Cagney @ 2002-08-18 13:08 ` Andrew Cagney 2002-08-18 13:19 ` Mark Kettenis 0 siblings, 1 reply; 6+ messages in thread From: Andrew Cagney @ 2002-08-18 13:08 UTC (permalink / raw) To: Andrew Cagney; +Cc: Mark Kettenis, gdb-patches > As for write_register_bytes() can it be avoided? I've just posted ``regcache_cooked_write_with_offset_hack(). But I don't think that hack is right here. Perhaphs a single register read - modify - write function is needed? Hmm, I just hit a need for the same operation while implementing some pseudo registers. Just adding: regcache_raw_read_part(regcache,regnum,offset,length,buf) regcache_raw_write_part(regcache,regnum,offset,length,buf) Andrew ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Remove some write_register_bytes occurences from i386-tdep.c 2002-08-18 13:08 ` Andrew Cagney @ 2002-08-18 13:19 ` Mark Kettenis 2002-08-18 13:35 ` [PATCH] regcache raw read/write partial; Was: " Andrew Cagney 0 siblings, 1 reply; 6+ messages in thread From: Mark Kettenis @ 2002-08-18 13:19 UTC (permalink / raw) To: ac131313; +Cc: ac131313, gdb-patches Date: Sun, 18 Aug 2002 16:08:06 -0400 From: Andrew Cagney <ac131313@ges.redhat.com> > As for write_register_bytes() can it be avoided? I've just posted ``regcache_cooked_write_with_offset_hack(). But I don't think that hack is right here. Perhaphs a single register read - modify - write function is needed? Hmm, I just hit a need for the same operation while implementing some pseudo registers. Just adding: regcache_raw_read_part(regcache,regnum,offset,length,buf) regcache_raw_write_part(regcache,regnum,offset,length,buf) Where OFFSET would be the byte offset into the register I suppose. Seems like a good idea to me. Mark ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] regcache raw read/write partial; Was: [PATCH] Remove some write_register_bytes occurences from i386-tdep.c 2002-08-18 13:19 ` Mark Kettenis @ 2002-08-18 13:35 ` Andrew Cagney 2002-08-18 17:38 ` Andrew Cagney 0 siblings, 1 reply; 6+ messages in thread From: Andrew Cagney @ 2002-08-18 13:35 UTC (permalink / raw) To: Mark Kettenis, gdb-patches [-- Attachment #1: Type: text/plain, Size: 762 bytes --] > Date: Sun, 18 Aug 2002 16:08:06 -0400 > From: Andrew Cagney <ac131313@ges.redhat.com> > > > As for write_register_bytes() can it be avoided? I've just posted ``regcache_cooked_write_with_offset_hack(). But I don't think that hack is right here. Perhaphs a single register read - modify - write function is needed? > > Hmm, > > I just hit a need for the same operation while implementing some pseudo > registers. Just adding: > > regcache_raw_read_part(regcache,regnum,offset,length,buf) > regcache_raw_write_part(regcache,regnum,offset,length,buf) > > Where OFFSET would be the byte offset into the register I suppose. > > Seems like a good idea to me. Yes, something like the attached. I'll commit in a few hours, Andrew [-- Attachment #2: diffs --] [-- Type: text/plain, Size: 2813 bytes --] 2002-08-18 Andrew Cagney <ac131313@redhat.com> * regcache.c (regcache_raw_xfer_part): New function. * regcache.h (regcache_raw_read_part): Declare. (regcache_raw_write_part): Declare. Index: regcache.c =================================================================== RCS file: /cvs/src/src/gdb/regcache.c,v retrieving revision 1.53 diff -u -r1.53 regcache.c --- regcache.c 13 Aug 2002 23:06:40 -0000 1.53 +++ regcache.c 18 Aug 2002 20:27:18 -0000 @@ -916,6 +916,46 @@ } } +/* Perform a partial register transfer using a read, modify, write + operation. */ + +void +regcache_raw_xfer_part (struct regcache *regcache, int regnum, + int offset, int len, void *in, const void *out) +{ + struct regcache_descr *descr = regcache->descr; + bfd_byte *reg = alloca (descr->max_register_size); + gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers); + gdb_assert (offset >= 0 && offset < descr->sizeof_register[regnum]); + gdb_assert (len >= 0 && len + offset < descr->sizeof_register[regnum]); + /* Read (when needed) ... */ + if (in != NULL + || offset > 0 + || offset + len < descr->sizeof_register[regnum]) + regcache_raw_read (regcache, regnum, reg); + /* ... modify ... */ + if (in != NULL) + memcpy (in, reg + offset, len); + if (out != NULL) + memcpy (reg + offset, out, len); + /* ... write (when needed). */ + if (out != NULL) + regcache_raw_write (regcache, regnum, reg); +} + +void +regcache_raw_read_part (struct regcache *regcache, int regnum, + int offset, int len, void *buf) +{ + regcache_raw_xfer_part (regcache, regnum, offset, len, buf, NULL); +} + +void +regcache_raw_write_part (struct regcache *regcache, int regnum, + int offset, int len, const void *buf) +{ + regcache_raw_xfer_part (regcache, regnum, offset, len, NULL, buf); +} /* Return the contents of register REGNUM as an unsigned integer. */ Index: regcache.h =================================================================== RCS file: /cvs/src/src/gdb/regcache.h,v retrieving revision 1.14 diff -u -r1.14 regcache.h --- regcache.h 13 Aug 2002 14:32:28 -0000 1.14 +++ regcache.h 18 Aug 2002 20:27:18 -0000 @@ -44,6 +44,13 @@ int regnum, ULONGEST *val); int regcache_valid_p (struct regcache *regcache, int regnum); +/* Raw partial transfers. These perform read, modify, write style + operations. */ +void regcache_raw_read_part (struct regcache *regcache, int regnum, + int offset, int len, void *buf); +void regcache_raw_write_part (struct regcache *regcache, int regnum, + int offset, int len, const void *buf); + /* Transfer a cooked register [0..NUM_REGS+NUM_PSEUDO_REGS). */ void regcache_cooked_read (struct regcache *regcache, int rawnum, void *buf); void regcache_cooked_write (struct regcache *regcache, int rawnum, ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] regcache raw read/write partial; Was: [PATCH] Remove some write_register_bytes occurences from i386-tdep.c 2002-08-18 13:35 ` [PATCH] regcache raw read/write partial; Was: " Andrew Cagney @ 2002-08-18 17:38 ` Andrew Cagney 0 siblings, 0 replies; 6+ messages in thread From: Andrew Cagney @ 2002-08-18 17:38 UTC (permalink / raw) To: Andrew Cagney; +Cc: Mark Kettenis, gdb-patches [-- Attachment #1: Type: text/plain, Size: 61 bytes --] This is what I've checked in. Testing continues ... Andrew [-- Attachment #2: diffs --] [-- Type: text/plain, Size: 5065 bytes --] 2002-08-18 Andrew Cagney <ac131313@redhat.com> * regcache.c (regcache_xfer_part): New function. (regcache_raw_read_part): New function. (regcache_raw_write_part): New function. (regcache_cooked_read_part): New function. (regcache_cooked_write_part): New function. * regcache.h (regcache_raw_read_part): Declare. (regcache_raw_write_part): Declare. (regcache_cooked_read_part): Declare. (regcache_cooked_write_part): Declare. Index: regcache.c =================================================================== RCS file: /cvs/src/src/gdb/regcache.c,v retrieving revision 1.53 diff -u -r1.53 regcache.c --- regcache.c 13 Aug 2002 23:06:40 -0000 1.53 +++ regcache.c 19 Aug 2002 00:32:53 -0000 @@ -916,6 +916,86 @@ } } +/* Perform a partial register transfer using a read, modify, write + operation. */ + +typedef void (regcache_read_ftype) (struct regcache *regcache, int regnum, + void *buf); +typedef void (regcache_write_ftype) (struct regcache *regcache, int regnum, + const void *buf); + +void +regcache_xfer_part (struct regcache *regcache, int regnum, + int offset, int len, void *in, const void *out, + regcache_read_ftype *read, regcache_write_ftype *write) +{ + struct regcache_descr *descr = regcache->descr; + bfd_byte *reg = alloca (descr->max_register_size); + gdb_assert (offset >= 0 && offset <= descr->sizeof_register[regnum]); + gdb_assert (len >= 0 && offset + len <= descr->sizeof_register[regnum]); + /* Something to do? */ + if (offset + len == 0) + return; + /* Read (when needed) ... */ + if (in != NULL + || offset > 0 + || offset + len < descr->sizeof_register[regnum]) + { + gdb_assert (read != NULL); + read (regcache, regnum, reg); + } + /* ... modify ... */ + if (in != NULL) + memcpy (in, reg + offset, len); + if (out != NULL) + memcpy (reg + offset, out, len); + /* ... write (when needed). */ + if (out != NULL) + { + gdb_assert (write != NULL); + write (regcache, regnum, reg); + } +} + +void +regcache_raw_read_part (struct regcache *regcache, int regnum, + int offset, int len, void *buf) +{ + struct regcache_descr *descr = regcache->descr; + gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers); + regcache_xfer_part (regcache, regnum, offset, len, buf, NULL, + regcache_raw_read, regcache_raw_write); +} + +void +regcache_raw_write_part (struct regcache *regcache, int regnum, + int offset, int len, const void *buf) +{ + struct regcache_descr *descr = regcache->descr; + gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers); + regcache_xfer_part (regcache, regnum, offset, len, NULL, buf, + regcache_raw_read, regcache_raw_write); +} + +void +regcache_cooked_read_part (struct regcache *regcache, int regnum, + int offset, int len, void *buf) +{ + struct regcache_descr *descr = regcache->descr; + gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers); + regcache_xfer_part (regcache, regnum, offset, len, buf, NULL, + regcache_cooked_read, regcache_cooked_write); +} + +void +regcache_cooked_write_part (struct regcache *regcache, int regnum, + int offset, int len, const void *buf) +{ + struct regcache_descr *descr = regcache->descr; + gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers); + regcache_xfer_part (regcache, regnum, offset, len, NULL, buf, + regcache_cooked_read, regcache_cooked_write); +} /* Return the contents of register REGNUM as an unsigned integer. */ Index: regcache.h =================================================================== RCS file: /cvs/src/src/gdb/regcache.h,v retrieving revision 1.14 diff -u -r1.14 regcache.h --- regcache.h 13 Aug 2002 14:32:28 -0000 1.14 +++ regcache.h 19 Aug 2002 00:32:54 -0000 @@ -42,6 +42,15 @@ int regnum, LONGEST *val); extern void regcache_raw_read_unsigned (struct regcache *regcache, int regnum, ULONGEST *val); + +/* Partial transfer of a raw registers. These perform read, modify, + write style operations. */ + +void regcache_raw_read_part (struct regcache *regcache, int regnum, + int offset, int len, void *buf); +void regcache_raw_write_part (struct regcache *regcache, int regnum, + int offset, int len, const void *buf); + int regcache_valid_p (struct regcache *regcache, int regnum); /* Transfer a cooked register [0..NUM_REGS+NUM_PSEUDO_REGS). */ @@ -62,6 +71,14 @@ int regnum, LONGEST *val); extern void regcache_cooked_read_unsigned (struct regcache *regcache, int regnum, ULONGEST *val); + +/* Partial transfer of a cooked register. These perform read, modify, + write style operations. */ + +void regcache_cooked_read_part (struct regcache *regcache, int regnum, + int offset, int len, void *buf); +void regcache_cooked_write_part (struct regcache *regcache, int regnum, + int offset, int len, const void *buf); /* Transfer a raw register [0..NUM_REGS) between the regcache and the target. These functions are called by the target in response to a ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2002-08-19 0:38 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2002-08-18 10:18 [PATCH] Remove some write_register_bytes occurences from i386-tdep.c Mark Kettenis 2002-08-18 10:46 ` Andrew Cagney 2002-08-18 13:08 ` Andrew Cagney 2002-08-18 13:19 ` Mark Kettenis 2002-08-18 13:35 ` [PATCH] regcache raw read/write partial; Was: " Andrew Cagney 2002-08-18 17:38 ` Andrew Cagney
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox